@telorun/kernel 0.2.4 → 0.2.5

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 (135) hide show
  1. package/dist/boot-context-registry.d.ts.map +1 -1
  2. package/dist/boot-context-registry.js +6 -6
  3. package/dist/boot-context-registry.js.map +1 -1
  4. package/dist/capabilities/capabilities/component.yaml +2 -1
  5. package/dist/capabilities/capabilities/executable.yaml +2 -1
  6. package/dist/capabilities/capabilities/handler.yaml +2 -1
  7. package/dist/capabilities/capabilities/listener.yaml +2 -1
  8. package/dist/capabilities/capabilities/provider.yaml +2 -1
  9. package/dist/capabilities/capabilities/template.yaml +2 -1
  10. package/dist/capabilities/capabilities/type.yaml +2 -1
  11. package/dist/capabilities/component.yaml +1 -1
  12. package/dist/capabilities/executable.yaml +1 -1
  13. package/dist/capabilities/handler.yaml +1 -1
  14. package/dist/capabilities/listener.yaml +1 -1
  15. package/dist/capabilities/provider.yaml +1 -1
  16. package/dist/capabilities/template.yaml +1 -1
  17. package/dist/capabilities/type.yaml +1 -1
  18. package/dist/controller-loader.d.ts +1 -1
  19. package/dist/controller-loader.d.ts.map +1 -1
  20. package/dist/controller-loader.js +4 -2
  21. package/dist/controller-loader.js.map +1 -1
  22. package/dist/controller-registry.d.ts +1 -2
  23. package/dist/controller-registry.d.ts.map +1 -1
  24. package/dist/controller-registry.js.map +1 -1
  25. package/dist/controllers/module/import-controller.d.ts +38 -0
  26. package/dist/controllers/module/import-controller.d.ts.map +1 -0
  27. package/dist/controllers/module/import-controller.js +119 -0
  28. package/dist/controllers/module/import-controller.js.map +1 -0
  29. package/dist/controllers/module/module-controller.d.ts +57 -11
  30. package/dist/controllers/module/module-controller.d.ts.map +1 -1
  31. package/dist/controllers/module/module-controller.js +46 -82
  32. package/dist/controllers/module/module-controller.js.map +1 -1
  33. package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -1
  34. package/dist/controllers/resource-definition/resource-definition-controller.js +12 -4
  35. package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -1
  36. package/dist/evaluation-context.d.ts +91 -0
  37. package/dist/evaluation-context.d.ts.map +1 -0
  38. package/dist/evaluation-context.js +220 -0
  39. package/dist/evaluation-context.js.map +1 -0
  40. package/dist/execution-context.d.ts +13 -0
  41. package/dist/execution-context.d.ts.map +1 -0
  42. package/dist/execution-context.js +14 -0
  43. package/dist/execution-context.js.map +1 -0
  44. package/dist/index.d.ts +0 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +0 -2
  47. package/dist/index.js.map +1 -1
  48. package/dist/kernel.d.ts +23 -31
  49. package/dist/kernel.d.ts.map +1 -1
  50. package/dist/kernel.js +212 -333
  51. package/dist/kernel.js.map +1 -1
  52. package/dist/loader.d.ts +2 -2
  53. package/dist/loader.d.ts.map +1 -1
  54. package/dist/loader.js +29 -9
  55. package/dist/loader.js.map +1 -1
  56. package/dist/manifest-adapters/local-file-adapter.d.ts.map +1 -1
  57. package/dist/manifest-adapters/local-file-adapter.js +21 -12
  58. package/dist/manifest-adapters/local-file-adapter.js.map +1 -1
  59. package/dist/manifest-schemas.d.ts +1 -25
  60. package/dist/manifest-schemas.d.ts.map +1 -1
  61. package/dist/manifest-schemas.js +3 -22
  62. package/dist/manifest-schemas.js.map +1 -1
  63. package/dist/module-context-registry.d.ts +48 -0
  64. package/dist/module-context-registry.d.ts.map +1 -0
  65. package/dist/module-context-registry.js +91 -0
  66. package/dist/module-context-registry.js.map +1 -0
  67. package/dist/module-context.d.ts +31 -0
  68. package/dist/module-context.d.ts.map +1 -0
  69. package/dist/module-context.js +67 -0
  70. package/dist/module-context.js.map +1 -0
  71. package/dist/registry.d.ts +1 -2
  72. package/dist/registry.d.ts.map +1 -1
  73. package/dist/registry.js +3 -3
  74. package/dist/registry.js.map +1 -1
  75. package/dist/resource-context.d.ts +25 -5
  76. package/dist/resource-context.d.ts.map +1 -1
  77. package/dist/resource-context.js +74 -28
  78. package/dist/resource-context.js.map +1 -1
  79. package/dist/schema-valiator.d.ts.map +1 -1
  80. package/dist/schema-valiator.js +3 -1
  81. package/dist/schema-valiator.js.map +1 -1
  82. package/dist/snapshot-serializer.d.ts +1 -2
  83. package/dist/snapshot-serializer.d.ts.map +1 -1
  84. package/dist/snapshot-serializer.js.map +1 -1
  85. package/dist/types.d.ts +3 -0
  86. package/dist/types.d.ts.map +1 -1
  87. package/dist/types.js.map +1 -1
  88. package/package.json +9 -6
  89. package/src/boot-context-registry.ts +169 -0
  90. package/src/capabilities/component.yaml +4 -0
  91. package/src/capabilities/executable.yaml +8 -0
  92. package/src/capabilities/handler.yaml +4 -0
  93. package/src/capabilities/listener.yaml +4 -0
  94. package/src/capabilities/provider.yaml +4 -0
  95. package/src/capabilities/template.yaml +4 -0
  96. package/src/capabilities/type.yaml +4 -0
  97. package/src/controller-loader.ts +298 -0
  98. package/src/controller-registry.ts +206 -0
  99. package/src/controllers/capability/capability-controller.ts +41 -0
  100. package/src/controllers/module/import-controller.ts +143 -0
  101. package/src/controllers/module/module-controller.ts +67 -0
  102. package/src/controllers/module/module.json +48 -0
  103. package/src/controllers/resource-definition/resource-definition-controller.ts +87 -0
  104. package/src/controllers/resource-definition/resource-definition.json +18 -0
  105. package/src/event-stream.ts +121 -0
  106. package/src/events.ts +99 -0
  107. package/src/index.ts +7 -0
  108. package/src/kernel.ts +558 -0
  109. package/src/loader.ts +245 -0
  110. package/src/manifest-adapters/http-adapter.ts +35 -0
  111. package/src/manifest-adapters/local-file-adapter.ts +69 -0
  112. package/src/manifest-adapters/manifest-adapter.ts +33 -0
  113. package/src/manifest-adapters/registry-adapter.ts +56 -0
  114. package/src/manifest-schemas.ts +49 -0
  115. package/src/registry.ts +137 -0
  116. package/src/resource-context.ts +266 -0
  117. package/src/resource-uri.ts +200 -0
  118. package/src/schema-valiator.ts +57 -0
  119. package/dist/cli.d.ts +0 -3
  120. package/dist/cli.d.ts.map +0 -1
  121. package/dist/cli.js +0 -109
  122. package/dist/cli.js.map +0 -1
  123. package/dist/expressions.d.ts +0 -20
  124. package/dist/expressions.d.ts.map +0 -1
  125. package/dist/expressions.js +0 -253
  126. package/dist/expressions.js.map +0 -1
  127. package/dist/template-definition.d.ts +0 -38
  128. package/dist/template-definition.d.ts.map +0 -1
  129. package/dist/template-definition.js +0 -26
  130. package/dist/template-definition.js.map +0 -1
  131. package/dist/template-expander.d.ts +0 -19
  132. package/dist/template-expander.d.ts.map +0 -1
  133. package/dist/template-expander.js +0 -425
  134. package/dist/template-expander.js.map +0 -1
  135. /package/{dist/src → src}/controllers/module/module.yaml +0 -0
@@ -0,0 +1,121 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as path from 'path';
3
+
4
+ /**
5
+ * Streaming event log for debugging and testing
6
+ * Records all events in JSONL format (one JSON object per line)
7
+ * Useful for observing runtime execution, testing, and debugging
8
+ */
9
+ export class EventStream {
10
+ private filePath: string;
11
+ private isEnabled: boolean = false;
12
+
13
+ constructor(filePath?: string) {
14
+ this.filePath = filePath || '';
15
+ this.isEnabled = !!filePath;
16
+ }
17
+
18
+ /**
19
+ * Enable event streaming to a file
20
+ */
21
+ async enable(filePath: string): Promise<void> {
22
+ this.filePath = filePath;
23
+ this.isEnabled = true;
24
+
25
+ // Ensure directory exists
26
+ const dir = path.dirname(filePath);
27
+ if (dir !== '.' && dir !== '') {
28
+ await fs.mkdir(dir, { recursive: true });
29
+ }
30
+
31
+ // Initialize file (truncate if exists)
32
+ await fs.writeFile(filePath, '', 'utf-8');
33
+ }
34
+
35
+ /**
36
+ * Log an event to the stream
37
+ */
38
+ async log(
39
+ event: string,
40
+ payload?: any,
41
+ metadata?: {
42
+ namespace?: string;
43
+ resource?: string;
44
+ kind?: string;
45
+ name?: string;
46
+ },
47
+ ): Promise<void> {
48
+ if (!this.isEnabled) {
49
+ return;
50
+ }
51
+
52
+ const logEntry = {
53
+ timestamp: new Date().toISOString(),
54
+ event,
55
+ payload,
56
+ ...metadata,
57
+ };
58
+
59
+ try {
60
+ const line = JSON.stringify(logEntry) + '\n';
61
+ await fs.appendFile(this.filePath, line, 'utf-8');
62
+ } catch (error) {
63
+ console.error('Failed to write event to stream:', error);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Read all events from the stream as an array
69
+ * Useful for testing
70
+ */
71
+ async readAll(): Promise<Array<Record<string, any>>> {
72
+ if (!this.isEnabled || !this.filePath) {
73
+ return [];
74
+ }
75
+
76
+ try {
77
+ const content = await fs.readFile(this.filePath, 'utf-8');
78
+ if (!content.trim()) {
79
+ return [];
80
+ }
81
+ return content
82
+ .trim()
83
+ .split('\n')
84
+ .map((line) => JSON.parse(line));
85
+ } catch (error) {
86
+ console.error('Failed to read event stream:', error);
87
+ return [];
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Filter events by type
93
+ */
94
+ async getEventsByType(
95
+ eventType: string,
96
+ ): Promise<Array<Record<string, any>>> {
97
+ const all = await this.readAll();
98
+ return all.filter((e) => e.event === eventType);
99
+ }
100
+
101
+ /**
102
+ * Get the file path for the event stream
103
+ */
104
+ getFilePath(): string {
105
+ return this.filePath;
106
+ }
107
+
108
+ /**
109
+ * Check if event streaming is enabled
110
+ */
111
+ isEnabledStream(): boolean {
112
+ return this.isEnabled;
113
+ }
114
+
115
+ /**
116
+ * Disable event streaming
117
+ */
118
+ disable(): void {
119
+ this.isEnabled = false;
120
+ }
121
+ }
package/src/events.ts ADDED
@@ -0,0 +1,99 @@
1
+ import { RuntimeEvent } from "@telorun/sdk";
2
+
3
+ type EventHandler = (payload?: any) => void | Promise<void>;
4
+
5
+ export class EventBus {
6
+ private handlers: Map<string, Set<EventHandler>> = new Map();
7
+
8
+ private validateEventName(event: string): void {
9
+ if (
10
+ event === "" ||
11
+ !/^(\*|[A-Za-z_][A-Za-z0-9_]*)(\.(\*|[A-Za-z_][A-Za-z0-9_]*))*$/.test(event)
12
+ ) {
13
+ throw new Error(`Invalid event name "${event}". Expected format "Text.Text" with no spaces.`);
14
+ }
15
+ }
16
+
17
+ private matchesPattern(pattern: string, event: string): boolean {
18
+ if (pattern === "*") {
19
+ return true;
20
+ }
21
+ if (pattern === event) {
22
+ return true;
23
+ }
24
+ if (!pattern.includes("*")) {
25
+ return false;
26
+ }
27
+ const patternParts = pattern.split(".");
28
+ const eventParts = event.split(".");
29
+ if (patternParts.length !== eventParts.length) {
30
+ return false;
31
+ }
32
+ for (let i = 0; i < patternParts.length; i += 1) {
33
+ const part = patternParts[i];
34
+ if (part === "*") {
35
+ continue;
36
+ }
37
+ if (part !== eventParts[i]) {
38
+ return false;
39
+ }
40
+ }
41
+ return true;
42
+ }
43
+
44
+ on(event: string, handler: EventHandler): void {
45
+ this.validateEventName(event);
46
+ const set = this.handlers.get(event) || new Set();
47
+ set.add(handler);
48
+ this.handlers.set(event, set);
49
+ }
50
+
51
+ once(event: string, handler: EventHandler): void {
52
+ this.validateEventName(event);
53
+ const wrapper: EventHandler = async (payload?: any) => {
54
+ this.off(event, wrapper);
55
+ await handler(payload);
56
+ };
57
+ this.on(event, wrapper);
58
+ }
59
+
60
+ off(event: string, handler: EventHandler): void {
61
+ this.validateEventName(event);
62
+ const set = this.handlers.get(event);
63
+ if (!set) {
64
+ return;
65
+ }
66
+ set.delete(handler);
67
+ if (set.size === 0) {
68
+ this.handlers.delete(event);
69
+ }
70
+ }
71
+
72
+ async emit(event: string, payload?: any, metadata?: any): Promise<void> {
73
+ const handlers: EventHandler[] = [];
74
+ for (const [pattern, set] of this.handlers.entries()) {
75
+ if (!this.matchesPattern(pattern, event)) {
76
+ continue;
77
+ }
78
+ for (const handler of set) {
79
+ handlers.push(handler);
80
+ }
81
+ }
82
+ if (handlers.length === 0) {
83
+ return;
84
+ }
85
+ const evt: RuntimeEvent = { name: event, payload, metadata };
86
+ for (const handler of handlers) {
87
+ await handler(evt);
88
+ }
89
+ }
90
+
91
+ hasHandlers(event: string): boolean {
92
+ for (const [pattern, set] of this.handlers.entries()) {
93
+ if (set.size > 0 && this.matchesPattern(pattern, event)) {
94
+ return true;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { ControllerRegistry } from "./controller-registry.js";
2
+ export { EventStream } from "./event-stream.js";
3
+ export { Kernel } from "./kernel.js";
4
+ export { Loader } from "./loader.js";
5
+ export { ManifestRegistry as Registry } from "./registry.js";
6
+ export { ResourceURI } from "./resource-uri.js";
7
+