@principal-ai/principal-view-core 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ConfigurationLoader.js +2 -1
- package/dist/ConfigurationLoader.js.map +1 -1
- package/dist/ConfigurationValidator.js.map +1 -1
- package/dist/EventProcessor.js.map +1 -1
- package/dist/EventRecorderService.js.map +1 -1
- package/dist/LibraryLoader.js.map +1 -1
- package/dist/PathBasedEventProcessor.js.map +1 -1
- package/dist/SessionManager.js +1 -1
- package/dist/SessionManager.js.map +1 -1
- package/dist/ValidationEngine.js.map +1 -1
- package/dist/cli/codegen.js.map +1 -1
- package/dist/codegen/type-generator.js.map +1 -1
- package/dist/codegen/usage-example.js.map +1 -1
- package/dist/helpers/GraphInstrumentationHelper.js +2 -2
- package/dist/helpers/GraphInstrumentationHelper.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/narrative/example.d.ts +11 -0
- package/dist/narrative/example.d.ts.map +1 -0
- package/dist/narrative/example.js +331 -0
- package/dist/narrative/example.js.map +1 -0
- package/dist/narrative/index.d.ts +12 -0
- package/dist/narrative/index.d.ts.map +1 -0
- package/dist/narrative/index.js +14 -0
- package/dist/narrative/index.js.map +1 -0
- package/dist/narrative/scenario-matcher.d.ts +87 -0
- package/dist/narrative/scenario-matcher.d.ts.map +1 -0
- package/dist/narrative/scenario-matcher.js +269 -0
- package/dist/narrative/scenario-matcher.js.map +1 -0
- package/dist/narrative/template-parser.d.ts +33 -0
- package/dist/narrative/template-parser.d.ts.map +1 -0
- package/dist/narrative/template-parser.js +288 -0
- package/dist/narrative/template-parser.js.map +1 -0
- package/dist/narrative/template-renderer.d.ts +18 -0
- package/dist/narrative/template-renderer.d.ts.map +1 -0
- package/dist/narrative/template-renderer.js +367 -0
- package/dist/narrative/template-renderer.js.map +1 -0
- package/dist/narrative/types.d.ts +268 -0
- package/dist/narrative/types.d.ts.map +1 -0
- package/dist/narrative/types.js +10 -0
- package/dist/narrative/types.js.map +1 -0
- package/dist/rules/config.js.map +1 -1
- package/dist/rules/engine.js.map +1 -1
- package/dist/rules/implementations/connection-type-references.js.map +1 -1
- package/dist/rules/implementations/dead-end-states.js.map +1 -1
- package/dist/rules/implementations/library-node-type-match.js.map +1 -1
- package/dist/rules/implementations/minimum-node-sources.js.map +1 -1
- package/dist/rules/implementations/no-unknown-fields.js.map +1 -1
- package/dist/rules/implementations/orphaned-edge-types.js.map +1 -1
- package/dist/rules/implementations/orphaned-node-types.js.map +1 -1
- package/dist/rules/implementations/required-metadata.js.map +1 -1
- package/dist/rules/implementations/state-transition-references.js.map +1 -1
- package/dist/rules/implementations/unreachable-states.js.map +1 -1
- package/dist/rules/implementations/valid-action-patterns.js.map +1 -1
- package/dist/rules/implementations/valid-color-format.js.map +1 -1
- package/dist/rules/implementations/valid-edge-types.js.map +1 -1
- package/dist/rules/implementations/valid-node-types.js.map +1 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/telemetry/coverage.js.map +1 -1
- package/dist/telemetry/event-validator.js.map +1 -1
- package/dist/types/audit.js.map +1 -1
- package/dist/types/canvas.js +5 -5
- package/dist/types/canvas.js.map +1 -1
- package/dist/types/otel.js.map +1 -1
- package/dist/types/resource-match.js.map +1 -1
- package/dist/utils/CanvasConverter.js.map +1 -1
- package/dist/utils/GraphConverter.js.map +1 -1
- package/dist/utils/LibraryConverter.js.map +1 -1
- package/dist/utils/PathMatcher.js.map +1 -1
- package/dist/utils/TraceToCanvas.js +7 -7
- package/dist/utils/TraceToCanvas.js.map +1 -1
- package/dist/utils/YamlParser.js.map +1 -1
- package/package.json +15 -15
- package/src/index.ts +31 -13
- package/src/narrative/README.md +381 -0
- package/src/narrative/__tests__/scenario-matcher.test.ts +368 -0
- package/src/narrative/__tests__/template-parser.test.ts +235 -0
- package/src/narrative/__tests__/template-renderer.test.ts +377 -0
- package/src/narrative/example.ts +349 -0
- package/src/narrative/index.ts +35 -0
- package/src/narrative/scenario-matcher.ts +331 -0
- package/src/narrative/template-parser.ts +298 -0
- package/src/narrative/template-renderer.ts +423 -0
- package/src/narrative/types.ts +368 -0
- package/src/utils/GraphConverter.test.ts +0 -79
- package/dist/utils/ExecutionFileDiscovery.d.ts +0 -206
- package/dist/utils/ExecutionFileDiscovery.d.ts.map +0 -1
- package/dist/utils/ExecutionFileDiscovery.js +0 -340
- package/dist/utils/ExecutionFileDiscovery.js.map +0 -1
- package/src/utils/ExecutionFileDiscovery.ts +0 -522
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Using the Narrative Template System
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the narrative renderer
|
|
5
|
+
* to transform OTEL events into human-readable narratives.
|
|
6
|
+
*/
|
|
7
|
+
import { renderNarrative } from './template-renderer';
|
|
8
|
+
// Example 1: Simple Success Scenario
|
|
9
|
+
function exampleSuccess() {
|
|
10
|
+
const template = {
|
|
11
|
+
version: '1.0.0',
|
|
12
|
+
canvas: 'example.otel.canvas',
|
|
13
|
+
name: 'Example Execution',
|
|
14
|
+
description: 'Simple execution narrative',
|
|
15
|
+
mode: 'span-tree',
|
|
16
|
+
scenarioSelection: 'first-match',
|
|
17
|
+
showLogsPerSpan: true,
|
|
18
|
+
scenarios: [
|
|
19
|
+
{
|
|
20
|
+
id: 'success',
|
|
21
|
+
priority: 1,
|
|
22
|
+
description: 'Successful execution',
|
|
23
|
+
condition: {
|
|
24
|
+
requires: ['execution.complete'],
|
|
25
|
+
assertions: { 'result.status': { $eq: 'success' } },
|
|
26
|
+
},
|
|
27
|
+
template: {
|
|
28
|
+
introduction: '✅ Execution Successful\n{"━".repeat(50)}',
|
|
29
|
+
span: '→ {span.name}',
|
|
30
|
+
children: 'recurse',
|
|
31
|
+
events: {
|
|
32
|
+
'execution.started': ' 🔄 Starting execution',
|
|
33
|
+
'execution.complete': ' ✅ Completed in {duration.ms}ms with {result.count} items',
|
|
34
|
+
},
|
|
35
|
+
logs: {
|
|
36
|
+
info: ' ℹ️ {log.body}',
|
|
37
|
+
debug: ' 🔍 {log.body}',
|
|
38
|
+
},
|
|
39
|
+
summary: '{"━".repeat(50)}\n\n✅ SUCCESS\n\nProcessed {result.count} items in {duration.ms}ms',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
const events = [
|
|
45
|
+
{
|
|
46
|
+
name: 'execution.started',
|
|
47
|
+
timestamp: 1000,
|
|
48
|
+
type: 'span',
|
|
49
|
+
spanId: 'span1',
|
|
50
|
+
traceId: 'trace1',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'log.info',
|
|
54
|
+
timestamp: 1100,
|
|
55
|
+
type: 'log',
|
|
56
|
+
spanId: 'span1',
|
|
57
|
+
traceId: 'trace1',
|
|
58
|
+
severityText: 'INFO',
|
|
59
|
+
severityNumber: 9,
|
|
60
|
+
body: 'Processing items...',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'execution.complete',
|
|
64
|
+
timestamp: 2000,
|
|
65
|
+
type: 'span',
|
|
66
|
+
spanId: 'span1',
|
|
67
|
+
traceId: 'trace1',
|
|
68
|
+
attributes: {
|
|
69
|
+
'result.status': 'success',
|
|
70
|
+
'result.count': 42,
|
|
71
|
+
'duration.ms': 1000,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
const result = renderNarrative(template, events);
|
|
76
|
+
console.log('=== Example 1: Success Scenario ===\n');
|
|
77
|
+
console.log(result.text);
|
|
78
|
+
console.log('\nMetadata:', result.metadata);
|
|
79
|
+
console.log('\n');
|
|
80
|
+
}
|
|
81
|
+
// Example 2: Multi-scenario with Violations
|
|
82
|
+
function exampleWithViolations() {
|
|
83
|
+
const template = {
|
|
84
|
+
version: '1.0.0',
|
|
85
|
+
canvas: 'validation.otel.canvas',
|
|
86
|
+
name: 'Validation Execution',
|
|
87
|
+
description: 'Validation with multiple scenarios',
|
|
88
|
+
mode: 'span-tree',
|
|
89
|
+
scenarioSelection: 'first-match',
|
|
90
|
+
scenarios: [
|
|
91
|
+
{
|
|
92
|
+
id: 'errors',
|
|
93
|
+
priority: 1,
|
|
94
|
+
description: 'Has error-level violations',
|
|
95
|
+
condition: {
|
|
96
|
+
requires: ['validation.complete'],
|
|
97
|
+
assertions: { 'result.errors': { $gt: 0 } },
|
|
98
|
+
},
|
|
99
|
+
template: {
|
|
100
|
+
introduction: '❌ Validation Failed\n{"━".repeat(50)}',
|
|
101
|
+
span: '→ {span.name}',
|
|
102
|
+
children: 'recurse',
|
|
103
|
+
events: {
|
|
104
|
+
'validation.started': ' 🔍 Validating configuration',
|
|
105
|
+
'validation.complete': ' ❌ Found {result.errors} errors and {result.warnings} warnings',
|
|
106
|
+
},
|
|
107
|
+
summary: '{"━".repeat(50)}\n\n❌ FAILED\n\nErrors: {result.errors}\nWarnings: {result.warnings}',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'warnings',
|
|
112
|
+
priority: 2,
|
|
113
|
+
description: 'Has warnings only',
|
|
114
|
+
condition: {
|
|
115
|
+
requires: ['validation.complete'],
|
|
116
|
+
assertions: {
|
|
117
|
+
'result.errors': { $eq: 0 },
|
|
118
|
+
'result.warnings': { $gt: 0 },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
template: {
|
|
122
|
+
introduction: '⚠️ Validation Passed with Warnings\n{"━".repeat(50)}',
|
|
123
|
+
span: '→ {span.name}',
|
|
124
|
+
children: 'recurse',
|
|
125
|
+
events: {
|
|
126
|
+
'validation.started': ' 🔍 Validating configuration',
|
|
127
|
+
'validation.complete': ' ⚠️ Found {result.warnings} warnings',
|
|
128
|
+
},
|
|
129
|
+
summary: '{"━".repeat(50)}\n\n⚠️ PASSED WITH WARNINGS\n\nWarnings: {result.warnings}',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 'success',
|
|
134
|
+
priority: 3,
|
|
135
|
+
description: 'All checks passed',
|
|
136
|
+
condition: {
|
|
137
|
+
requires: ['validation.complete'],
|
|
138
|
+
assertions: {
|
|
139
|
+
'result.errors': { $eq: 0 },
|
|
140
|
+
'result.warnings': { $eq: 0 },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
template: {
|
|
144
|
+
introduction: '✅ Validation Passed\n{"━".repeat(50)}',
|
|
145
|
+
span: '→ {span.name}',
|
|
146
|
+
children: 'recurse',
|
|
147
|
+
events: {
|
|
148
|
+
'validation.started': ' 🔍 Validating configuration',
|
|
149
|
+
'validation.complete': ' ✅ All checks passed',
|
|
150
|
+
},
|
|
151
|
+
summary: '{"━".repeat(50)}\n\n✅ SUCCESS\n\nNo violations found.',
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
// Scenario 1: Errors
|
|
157
|
+
const eventsWithErrors = [
|
|
158
|
+
{
|
|
159
|
+
name: 'validation.started',
|
|
160
|
+
timestamp: 1000,
|
|
161
|
+
type: 'span',
|
|
162
|
+
spanId: 'span1',
|
|
163
|
+
traceId: 'trace1',
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'validation.complete',
|
|
167
|
+
timestamp: 2000,
|
|
168
|
+
type: 'span',
|
|
169
|
+
spanId: 'span1',
|
|
170
|
+
traceId: 'trace1',
|
|
171
|
+
attributes: {
|
|
172
|
+
'result.errors': 3,
|
|
173
|
+
'result.warnings': 2,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
];
|
|
177
|
+
console.log('=== Example 2a: Validation with Errors ===\n');
|
|
178
|
+
const result1 = renderNarrative(template, eventsWithErrors);
|
|
179
|
+
console.log(result1.text);
|
|
180
|
+
console.log('\nSelected scenario:', result1.scenarioId);
|
|
181
|
+
console.log('\n');
|
|
182
|
+
// Scenario 2: Warnings only
|
|
183
|
+
const eventsWithWarnings = [
|
|
184
|
+
{
|
|
185
|
+
name: 'validation.started',
|
|
186
|
+
timestamp: 1000,
|
|
187
|
+
type: 'span',
|
|
188
|
+
spanId: 'span1',
|
|
189
|
+
traceId: 'trace1',
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'validation.complete',
|
|
193
|
+
timestamp: 2000,
|
|
194
|
+
type: 'span',
|
|
195
|
+
spanId: 'span1',
|
|
196
|
+
traceId: 'trace1',
|
|
197
|
+
attributes: {
|
|
198
|
+
'result.errors': 0,
|
|
199
|
+
'result.warnings': 5,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
console.log('=== Example 2b: Validation with Warnings ===\n');
|
|
204
|
+
const result2 = renderNarrative(template, eventsWithWarnings);
|
|
205
|
+
console.log(result2.text);
|
|
206
|
+
console.log('\nSelected scenario:', result2.scenarioId);
|
|
207
|
+
console.log('\n');
|
|
208
|
+
// Scenario 3: Success
|
|
209
|
+
const eventsSuccess = [
|
|
210
|
+
{
|
|
211
|
+
name: 'validation.started',
|
|
212
|
+
timestamp: 1000,
|
|
213
|
+
type: 'span',
|
|
214
|
+
spanId: 'span1',
|
|
215
|
+
traceId: 'trace1',
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'validation.complete',
|
|
219
|
+
timestamp: 2000,
|
|
220
|
+
type: 'span',
|
|
221
|
+
spanId: 'span1',
|
|
222
|
+
traceId: 'trace1',
|
|
223
|
+
attributes: {
|
|
224
|
+
'result.errors': 0,
|
|
225
|
+
'result.warnings': 0,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
];
|
|
229
|
+
console.log('=== Example 2c: Validation Success ===\n');
|
|
230
|
+
const result3 = renderNarrative(template, eventsSuccess);
|
|
231
|
+
console.log(result3.text);
|
|
232
|
+
console.log('\nSelected scenario:', result3.scenarioId);
|
|
233
|
+
console.log('\n');
|
|
234
|
+
}
|
|
235
|
+
// Example 3: Span Tree with Hierarchy
|
|
236
|
+
function exampleSpanTree() {
|
|
237
|
+
const template = {
|
|
238
|
+
version: '1.0.0',
|
|
239
|
+
canvas: 'hierarchy.otel.canvas',
|
|
240
|
+
name: 'Hierarchical Execution',
|
|
241
|
+
description: 'Demonstrates span tree rendering',
|
|
242
|
+
mode: 'span-tree',
|
|
243
|
+
scenarioSelection: 'first-match',
|
|
244
|
+
showLogsPerSpan: true,
|
|
245
|
+
scenarios: [
|
|
246
|
+
{
|
|
247
|
+
id: 'default',
|
|
248
|
+
priority: 1,
|
|
249
|
+
description: 'Default',
|
|
250
|
+
condition: { default: true },
|
|
251
|
+
template: {
|
|
252
|
+
introduction: '📋 Execution Trace\n{"━".repeat(50)}',
|
|
253
|
+
span: '→ {span.name}',
|
|
254
|
+
children: 'recurse',
|
|
255
|
+
logs: {
|
|
256
|
+
info: ' ℹ️ {log.body}',
|
|
257
|
+
error: ' ❌ {log.body}',
|
|
258
|
+
},
|
|
259
|
+
summary: '{"━".repeat(50)}\nComplete',
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
};
|
|
264
|
+
const events = [
|
|
265
|
+
{
|
|
266
|
+
name: 'root.operation',
|
|
267
|
+
timestamp: 1000,
|
|
268
|
+
type: 'span',
|
|
269
|
+
spanId: 'span1',
|
|
270
|
+
traceId: 'trace1',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'log.info',
|
|
274
|
+
timestamp: 1100,
|
|
275
|
+
type: 'log',
|
|
276
|
+
spanId: 'span1',
|
|
277
|
+
traceId: 'trace1',
|
|
278
|
+
severityText: 'INFO',
|
|
279
|
+
severityNumber: 9,
|
|
280
|
+
body: 'Root operation started',
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: 'child.operation',
|
|
284
|
+
timestamp: 1200,
|
|
285
|
+
type: 'span',
|
|
286
|
+
spanId: 'span2',
|
|
287
|
+
parentSpanId: 'span1',
|
|
288
|
+
traceId: 'trace1',
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: 'log.info',
|
|
292
|
+
timestamp: 1300,
|
|
293
|
+
type: 'log',
|
|
294
|
+
spanId: 'span2',
|
|
295
|
+
traceId: 'trace1',
|
|
296
|
+
severityText: 'INFO',
|
|
297
|
+
severityNumber: 9,
|
|
298
|
+
body: 'Processing child task',
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: 'grandchild.operation',
|
|
302
|
+
timestamp: 1400,
|
|
303
|
+
type: 'span',
|
|
304
|
+
spanId: 'span3',
|
|
305
|
+
parentSpanId: 'span2',
|
|
306
|
+
traceId: 'trace1',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: 'log.info',
|
|
310
|
+
timestamp: 1500,
|
|
311
|
+
type: 'log',
|
|
312
|
+
spanId: 'span3',
|
|
313
|
+
traceId: 'trace1',
|
|
314
|
+
severityText: 'INFO',
|
|
315
|
+
severityNumber: 9,
|
|
316
|
+
body: 'Executing grandchild task',
|
|
317
|
+
},
|
|
318
|
+
];
|
|
319
|
+
console.log('=== Example 3: Span Tree Hierarchy ===\n');
|
|
320
|
+
const result = renderNarrative(template, events);
|
|
321
|
+
console.log(result.text);
|
|
322
|
+
console.log('\n');
|
|
323
|
+
}
|
|
324
|
+
// Run all examples
|
|
325
|
+
if (import.meta.main) {
|
|
326
|
+
exampleSuccess();
|
|
327
|
+
exampleWithViolations();
|
|
328
|
+
exampleSpanTree();
|
|
329
|
+
}
|
|
330
|
+
export { exampleSuccess, exampleWithViolations, exampleSpanTree };
|
|
331
|
+
//# sourceMappingURL=example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/narrative/example.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,qCAAqC;AACrC,SAAS,cAAc;IACrB,MAAM,QAAQ,GAAsB;QAClC,OAA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AED,mBAAmB;AACnB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;IACpB,cAAc,EAAE,CAAC;IACjB,qBAAqB,EAAE,CAAC;IACxB,eAAe,EAAE,CAAC;CACnB;AAED,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrative Template System
|
|
3
|
+
*
|
|
4
|
+
* Transform OpenTelemetry event streams into human-readable execution narratives.
|
|
5
|
+
*
|
|
6
|
+
* @module narrative
|
|
7
|
+
*/
|
|
8
|
+
export type { NarrativeTemplate, NarrativeScenario, NarrativeMode, ScenarioCondition, ScenarioTemplate, Assertion, FlowDirective, LogTemplates, FormattingOptions, OtelEvent, OtelSignal, NarrativeContext, NarrativeResult, ScenarioMatchResult, SpanTreeNode, } from './types';
|
|
9
|
+
export { selectScenario, matchesCondition, hasEventMatching, computeAggregates, evaluateAssertion, getNestedValue, setNestedValue } from './scenario-matcher';
|
|
10
|
+
export { parseTemplate, evaluateExpression } from './template-parser';
|
|
11
|
+
export { renderNarrative } from './template-renderer';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/narrative/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG9J,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGtE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrative Template System
|
|
3
|
+
*
|
|
4
|
+
* Transform OpenTelemetry event streams into human-readable execution narratives.
|
|
5
|
+
*
|
|
6
|
+
* @module narrative
|
|
7
|
+
*/
|
|
8
|
+
// Scenario Matching
|
|
9
|
+
export { selectScenario, matchesCondition, hasEventMatching, computeAggregates, evaluateAssertion, getNestedValue, setNestedValue } from './scenario-matcher';
|
|
10
|
+
// Template Parsing
|
|
11
|
+
export { parseTemplate, evaluateExpression } from './template-parser';
|
|
12
|
+
// Template Rendering
|
|
13
|
+
export { renderNarrative } from './template-renderer';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/narrative/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAqBH,oBAAoB;AACpB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9J,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scenario Matching Logic
|
|
3
|
+
*
|
|
4
|
+
* Selects the appropriate narrative scenario based on which events occurred
|
|
5
|
+
* during execution. Uses priority-based, first-match-wins algorithm.
|
|
6
|
+
*/
|
|
7
|
+
import type { NarrativeTemplate, ScenarioCondition, Assertion, OtelEvent, ScenarioMatchResult } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Select the first matching scenario from a narrative template
|
|
10
|
+
*
|
|
11
|
+
* Scenarios are evaluated in priority order (lowest priority number first).
|
|
12
|
+
* Returns the first scenario whose conditions are met.
|
|
13
|
+
*
|
|
14
|
+
* @param template - Narrative template with scenarios
|
|
15
|
+
* @param events - Collected OTEL events
|
|
16
|
+
* @param attributes - Aggregated attributes (computed from events)
|
|
17
|
+
* @returns Matched scenario and metadata
|
|
18
|
+
* @throws Error if no scenario matches (template should have default fallback)
|
|
19
|
+
*/
|
|
20
|
+
export declare function selectScenario(template: NarrativeTemplate, events: OtelEvent[], attributes?: Record<string, unknown>): ScenarioMatchResult;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a scenario condition matches the given events and attributes
|
|
23
|
+
*
|
|
24
|
+
* @param condition - Scenario condition to evaluate
|
|
25
|
+
* @param events - Collected OTEL events
|
|
26
|
+
* @param attributes - Aggregated attributes
|
|
27
|
+
* @returns Match result with reason if not matched
|
|
28
|
+
*/
|
|
29
|
+
export declare function matchesCondition(condition: ScenarioCondition, events: OtelEvent[], attributes: Record<string, unknown>): {
|
|
30
|
+
matches: boolean;
|
|
31
|
+
reason?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Check if any event matches the given pattern (supports glob-style wildcards)
|
|
35
|
+
*
|
|
36
|
+
* Patterns:
|
|
37
|
+
* - Exact: "conversion.started" matches only that event
|
|
38
|
+
* - Wildcard suffix: "conversion.*" matches "conversion.started", "conversion.complete", etc.
|
|
39
|
+
* - Wildcard prefix: "*.error" matches "conversion.error", "rule.error", etc.
|
|
40
|
+
* - Wildcard middle: "log.*" matches any event starting with "log."
|
|
41
|
+
*
|
|
42
|
+
* @param events - Events to search
|
|
43
|
+
* @param pattern - Pattern to match (supports * wildcard)
|
|
44
|
+
* @returns True if any event matches the pattern
|
|
45
|
+
*/
|
|
46
|
+
export declare function hasEventMatching(events: OtelEvent[], pattern: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Evaluate an assertion against a value
|
|
49
|
+
*
|
|
50
|
+
* @param value - Value to test
|
|
51
|
+
* @param assertion - Assertion operators
|
|
52
|
+
* @returns Match result with reason if not matched
|
|
53
|
+
*/
|
|
54
|
+
export declare function evaluateAssertion(value: unknown, assertion: Assertion): {
|
|
55
|
+
matches: boolean;
|
|
56
|
+
reason?: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Get nested value from object using dot notation
|
|
60
|
+
*
|
|
61
|
+
* Supports both nested objects and flat keys with dots in them.
|
|
62
|
+
* First tries the path as a flat key, then tries nested lookup.
|
|
63
|
+
*
|
|
64
|
+
* @param obj - Object to search
|
|
65
|
+
* @param path - Dot-separated path (e.g., "result.violations.total")
|
|
66
|
+
* @returns Value at path, or undefined if not found
|
|
67
|
+
*/
|
|
68
|
+
export declare function getNestedValue(obj: Record<string, unknown>, path: string): unknown;
|
|
69
|
+
/**
|
|
70
|
+
* Set nested value in object using dot notation
|
|
71
|
+
*
|
|
72
|
+
* @param obj - Object to modify
|
|
73
|
+
* @param path - Dot-separated path (e.g., "result.violations.total")
|
|
74
|
+
* @param value - Value to set
|
|
75
|
+
*/
|
|
76
|
+
export declare function setNestedValue(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
77
|
+
/**
|
|
78
|
+
* Compute aggregate values from events
|
|
79
|
+
*
|
|
80
|
+
* Provides common aggregations like counts, totals, averages, etc.
|
|
81
|
+
* that can be used in scenario conditions and templates.
|
|
82
|
+
*
|
|
83
|
+
* @param events - Collected OTEL events
|
|
84
|
+
* @returns Aggregate values
|
|
85
|
+
*/
|
|
86
|
+
export declare function computeAggregates(events: OtelEvent[]): Record<string, unknown>;
|
|
87
|
+
//# sourceMappingURL=scenario-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario-matcher.d.ts","sourceRoot":"","sources":["../../src/narrative/scenario-matcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KA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