@telorun/kernel 0.2.5 → 0.2.7

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 (138) hide show
  1. package/dist/base-definition.d.ts +14 -0
  2. package/dist/base-definition.d.ts.map +1 -0
  3. package/dist/base-definition.js +17 -0
  4. package/dist/base-definition.js.map +1 -0
  5. package/dist/capabilities/component.d.ts +3 -0
  6. package/dist/capabilities/component.d.ts.map +1 -0
  7. package/dist/capabilities/component.js +4 -0
  8. package/dist/capabilities/component.js.map +1 -0
  9. package/dist/capabilities/executable.d.ts +3 -0
  10. package/dist/capabilities/executable.d.ts.map +1 -0
  11. package/dist/capabilities/executable.js +5 -0
  12. package/dist/capabilities/executable.js.map +1 -0
  13. package/dist/capabilities/handler.d.ts +3 -0
  14. package/dist/capabilities/handler.d.ts.map +1 -0
  15. package/dist/capabilities/handler.js +4 -0
  16. package/dist/capabilities/handler.js.map +1 -0
  17. package/dist/capabilities/invokable.d.ts +3 -0
  18. package/dist/capabilities/invokable.d.ts.map +1 -0
  19. package/dist/capabilities/invokable.js +5 -0
  20. package/dist/capabilities/invokable.js.map +1 -0
  21. package/dist/capabilities/listener.d.ts +3 -0
  22. package/dist/capabilities/listener.d.ts.map +1 -0
  23. package/dist/capabilities/listener.js +5 -0
  24. package/dist/capabilities/listener.js.map +1 -0
  25. package/dist/capabilities/mount.d.ts +3 -0
  26. package/dist/capabilities/mount.d.ts.map +1 -0
  27. package/dist/capabilities/mount.js +5 -0
  28. package/dist/capabilities/mount.js.map +1 -0
  29. package/dist/capabilities/provider.d.ts +3 -0
  30. package/dist/capabilities/provider.d.ts.map +1 -0
  31. package/dist/capabilities/provider.js +8 -0
  32. package/dist/capabilities/provider.js.map +1 -0
  33. package/dist/capabilities/runnable.d.ts +3 -0
  34. package/dist/capabilities/runnable.d.ts.map +1 -0
  35. package/dist/capabilities/runnable.js +5 -0
  36. package/dist/capabilities/runnable.js.map +1 -0
  37. package/dist/capabilities/service.d.ts +3 -0
  38. package/dist/capabilities/service.d.ts.map +1 -0
  39. package/dist/capabilities/service.js +5 -0
  40. package/dist/capabilities/service.js.map +1 -0
  41. package/dist/capabilities/template.d.ts +3 -0
  42. package/dist/capabilities/template.d.ts.map +1 -0
  43. package/dist/capabilities/template.js +5 -0
  44. package/dist/capabilities/template.js.map +1 -0
  45. package/dist/capabilities/type.d.ts +3 -0
  46. package/dist/capabilities/type.d.ts.map +1 -0
  47. package/dist/capabilities/type.js +5 -0
  48. package/dist/capabilities/type.js.map +1 -0
  49. package/dist/controller-loader.d.ts.map +1 -1
  50. package/dist/controller-loader.js +2 -1
  51. package/dist/controller-loader.js.map +1 -1
  52. package/dist/controller-registry.d.ts +0 -4
  53. package/dist/controller-registry.d.ts.map +1 -1
  54. package/dist/controller-registry.js +11 -22
  55. package/dist/controller-registry.js.map +1 -1
  56. package/dist/controllers/capability/capability-controller.d.ts +0 -5
  57. package/dist/controllers/capability/capability-controller.d.ts.map +1 -1
  58. package/dist/controllers/capability/capability-controller.js +1 -5
  59. package/dist/controllers/capability/capability-controller.js.map +1 -1
  60. package/dist/controllers/module/import-controller.d.ts +0 -3
  61. package/dist/controllers/module/import-controller.d.ts.map +1 -1
  62. package/dist/controllers/module/import-controller.js +21 -27
  63. package/dist/controllers/module/import-controller.js.map +1 -1
  64. package/dist/controllers/module/module-controller.d.ts +0 -59
  65. package/dist/controllers/module/module-controller.d.ts.map +1 -1
  66. package/dist/controllers/module/module-controller.js +0 -45
  67. package/dist/controllers/module/module-controller.js.map +1 -1
  68. package/dist/controllers/resource-definition/resource-definition-controller.d.ts +3 -4
  69. package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -1
  70. package/dist/controllers/resource-definition/resource-definition-controller.js +6 -8
  71. package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -1
  72. package/dist/controllers/resource-definition/resource-template-controller.d.ts +12 -0
  73. package/dist/controllers/resource-definition/resource-template-controller.d.ts.map +1 -0
  74. package/dist/controllers/resource-definition/resource-template-controller.js +112 -0
  75. package/dist/controllers/resource-definition/resource-template-controller.js.map +1 -0
  76. package/dist/index.d.ts +2 -2
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +0 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/kernel.d.ts +38 -24
  81. package/dist/kernel.d.ts.map +1 -1
  82. package/dist/kernel.js +296 -201
  83. package/dist/kernel.js.map +1 -1
  84. package/dist/loader.d.ts +9 -8
  85. package/dist/loader.d.ts.map +1 -1
  86. package/dist/loader.js +50 -132
  87. package/dist/loader.js.map +1 -1
  88. package/dist/manifest-adapters/http-adapter.d.ts.map +1 -1
  89. package/dist/manifest-adapters/http-adapter.js +3 -1
  90. package/dist/manifest-adapters/http-adapter.js.map +1 -1
  91. package/dist/manifest-adapters/local-file-adapter.d.ts +7 -5
  92. package/dist/manifest-adapters/local-file-adapter.d.ts.map +1 -1
  93. package/dist/manifest-adapters/local-file-adapter.js +21 -26
  94. package/dist/manifest-adapters/local-file-adapter.js.map +1 -1
  95. package/dist/manifest-adapters/manifest-adapter.d.ts +2 -0
  96. package/dist/manifest-adapters/manifest-adapter.d.ts.map +1 -1
  97. package/dist/manifest-adapters/registry-adapter.d.ts.map +1 -1
  98. package/dist/manifest-adapters/registry-adapter.js +3 -1
  99. package/dist/manifest-adapters/registry-adapter.js.map +1 -1
  100. package/dist/manifest-schemas.d.ts +61 -25
  101. package/dist/manifest-schemas.d.ts.map +1 -1
  102. package/dist/manifest-schemas.js +56 -16
  103. package/dist/manifest-schemas.js.map +1 -1
  104. package/dist/resource-context.d.ts +11 -10
  105. package/dist/resource-context.d.ts.map +1 -1
  106. package/dist/resource-context.js +70 -25
  107. package/dist/resource-context.js.map +1 -1
  108. package/dist/schema-valiator.d.ts +6 -1
  109. package/dist/schema-valiator.d.ts.map +1 -1
  110. package/dist/schema-valiator.js +76 -4
  111. package/dist/schema-valiator.js.map +1 -1
  112. package/package.json +6 -7
  113. package/src/controller-loader.ts +2 -1
  114. package/src/controller-registry.ts +11 -26
  115. package/src/controllers/module/import-controller.ts +30 -30
  116. package/src/controllers/module/module-controller.ts +0 -51
  117. package/src/controllers/resource-definition/resource-definition-controller.ts +14 -15
  118. package/src/controllers/resource-definition/resource-template-controller.ts +138 -0
  119. package/src/index.ts +2 -2
  120. package/src/kernel.ts +364 -226
  121. package/src/manifest-adapters/local-file-adapter.ts +24 -31
  122. package/src/manifest-adapters/manifest-adapter.ts +2 -0
  123. package/src/manifest-schemas.ts +60 -24
  124. package/src/resource-context.ts +90 -35
  125. package/src/schema-valiator.ts +90 -13
  126. package/src/capabilities/component.yaml +0 -4
  127. package/src/capabilities/executable.yaml +0 -8
  128. package/src/capabilities/handler.yaml +0 -4
  129. package/src/capabilities/listener.yaml +0 -4
  130. package/src/capabilities/provider.yaml +0 -4
  131. package/src/capabilities/template.yaml +0 -4
  132. package/src/capabilities/type.yaml +0 -4
  133. package/src/controllers/capability/capability-controller.ts +0 -41
  134. package/src/controllers/module/module.json +0 -48
  135. package/src/controllers/module/module.yaml +0 -32
  136. package/src/loader.ts +0 -245
  137. package/src/manifest-adapters/http-adapter.ts +0 -35
  138. package/src/manifest-adapters/registry-adapter.ts +0 -56
@@ -1,32 +0,0 @@
1
- type: 'object'
2
- properties:
3
- metadata:
4
- type: 'object'
5
- properties:
6
- name:
7
- type: 'string'
8
- required: ['name']
9
- source:
10
- type: 'string'
11
- description: 'Path to module directory (relative to runtime root)'
12
- imports:
13
- type: 'array'
14
- items:
15
- type: 'string'
16
- description: 'Paths to other modules to import'
17
- definitions:
18
- type: 'array'
19
- items:
20
- type: 'string'
21
- description: 'Paths to ResourceDefinition files'
22
- resources:
23
- type: 'array'
24
- items:
25
- oneOf:
26
- - type: 'string'
27
- - type: 'object'
28
- properties:
29
- path:
30
- type: 'string'
31
- description: 'Paths to resource instance files to load'
32
- required: ['metadata', 'source']
package/src/loader.ts DELETED
@@ -1,245 +0,0 @@
1
- import { ResourceManifest, RuntimeResource } from "@telorun/sdk";
2
- import { compile } from "@telorun/yaml-cel-templating";
3
- import * as path from "path";
4
- import { HttpAdapter } from "./manifest-adapters/http-adapter.js";
5
- import { LocalFileAdapter } from "./manifest-adapters/local-file-adapter.js";
6
- import type { ManifestAdapter, ManifestSourceData } from "./manifest-adapters/manifest-adapter.js";
7
- import { RegistryAdapter } from "./manifest-adapters/registry-adapter.js";
8
- import { formatAjvErrors, validateRuntimeResource } from "./manifest-schemas.js";
9
-
10
- /**
11
- * Loader: Ingests resolved YAML manifests from disk or remote URLs into memory
12
- */
13
- export class Loader {
14
- private static projectRoot: string | null = null;
15
-
16
- private readonly adapters: ManifestAdapter[] = [
17
- new HttpAdapter(),
18
- new RegistryAdapter(),
19
- new LocalFileAdapter(),
20
- ];
21
-
22
- private getAdapter(pathOrUrl: string): ManifestAdapter {
23
- const adapter = this.adapters.find((a) => a.supports(pathOrUrl));
24
- if (!adapter) {
25
- throw new Error(`No manifest adapter found for: ${pathOrUrl}`);
26
- }
27
- return adapter;
28
- }
29
-
30
- private static ensureProjectRoot(baseDir: string): void {
31
- if (!Loader.projectRoot) {
32
- Loader.projectRoot = path.resolve(baseDir);
33
- }
34
- }
35
-
36
- resolvePath(base: string, relative: string): string {
37
- return this.getAdapter(base).resolveRelative(base, relative);
38
- }
39
-
40
- async loadDirectory(pathOrUrl: string): Promise<ResourceManifest[]> {
41
- const files = await this.getAdapter(pathOrUrl).readAll(pathOrUrl);
42
- Loader.ensureProjectRoot(files[0]?.baseDir ?? process.cwd());
43
- const resources: RuntimeResource[] = [];
44
- for (const file of files) {
45
- await this.processFile(file, resources, { env: process.env });
46
- }
47
- return this.orderResourcesByKindDependencies(resources);
48
- }
49
-
50
- async loadManifest(
51
- pathOrUrl: string,
52
- baseUrl: string,
53
- compileContext: Record<string, unknown> = {},
54
- ): Promise<ResourceManifest[]> {
55
- if (!baseUrl) {
56
- throw new Error("Base URL is required to load target manifest");
57
- }
58
- const url = new URL(pathOrUrl, baseUrl).toString();
59
- const file = await this.getAdapter(url).read(url);
60
- if (!Loader.projectRoot) {
61
- Loader.ensureProjectRoot(file.baseDir);
62
- }
63
-
64
- const resolved: ResourceManifest[] = [];
65
- for (const rawDoc of file.documents) {
66
- let compiled: any;
67
- try {
68
- compiled = compile(rawDoc, { context: compileContext });
69
- } catch (error) {
70
- throw new Error(
71
- `Failed to compile manifest in ${file.source}: ${error instanceof Error ? error.message : String(error)}`,
72
- );
73
- }
74
- const compiledDocs = Array.isArray(compiled) ? compiled : [compiled];
75
- for (const manifest of compiledDocs) {
76
- if (manifest === null) {
77
- // Ignore empty documents
78
- continue;
79
- }
80
- const resource: ResourceManifest = {
81
- ...manifest,
82
- metadata: {
83
- ...manifest.metadata,
84
- source: file.source,
85
- },
86
- };
87
- resolved.push(resource);
88
- }
89
- }
90
-
91
- // Auto-assign metadata.module from the file's Kernel.Module declaration to
92
- // any resource that doesn't explicitly declare one. This matches the implicit
93
- // convention that resources in the same file belong to the declared module.
94
- const moduleName = resolved.find((m) => m.kind === "Kernel.Module")?.metadata?.name;
95
- if (moduleName) {
96
- for (const manifest of resolved) {
97
- if (manifest.kind !== "Kernel.Module" && !manifest.metadata?.module) {
98
- manifest.metadata = { ...manifest.metadata, module: moduleName };
99
- }
100
- }
101
- }
102
-
103
- return resolved;
104
- }
105
-
106
- private async processFile(
107
- file: ManifestSourceData,
108
- resources: RuntimeResource[],
109
- compileContext: Record<string, unknown> = {},
110
- ): Promise<void> {
111
- const documents = file.documents;
112
-
113
- for (const rawDoc of documents) {
114
- let compiled: any;
115
- try {
116
- compiled = compile(rawDoc, { context: compileContext });
117
- } catch (error) {
118
- throw new Error(
119
- `Failed to compile manifest in ${file.source}: ${error instanceof Error ? error.message : String(error)}`,
120
- );
121
- }
122
- const compiledDocs = Array.isArray(compiled) ? compiled : [compiled];
123
- for (const doc of compiledDocs) {
124
- const resource = this.normalizeResource(doc);
125
- if (!resource) {
126
- continue;
127
- }
128
- if (!validateRuntimeResource(resource)) {
129
- const kind = (resource as any).kind;
130
- const name = (resource as any).metadata?.name;
131
- throw new Error(
132
- `Resource validation failed for ${kind}.${name}: ${formatAjvErrors(validateRuntimeResource.errors)}`,
133
- );
134
- }
135
-
136
- const { kind, name } = resource.metadata;
137
- resource.metadata.source = file.source;
138
- resource.metadata.uri = `${file.uriBase}#${kind}.${name}`;
139
- resource.metadata.generationDepth = 0;
140
-
141
- resources.push(resource);
142
- }
143
- }
144
- }
145
-
146
- private normalizeResource(doc: any): RuntimeResource | null {
147
- if (!doc || typeof doc !== "object" || typeof doc.kind !== "string") {
148
- return null;
149
- }
150
-
151
- // Already in correct format
152
- if (doc.metadata && typeof doc.metadata === "object" && typeof doc.metadata.name === "string") {
153
- return doc as RuntimeResource;
154
- }
155
-
156
- return null;
157
- }
158
-
159
- // Validation handled by TypeBox + Ajv schemas.
160
-
161
- private orderResourcesByKindDependencies(resources: RuntimeResource[]): RuntimeResource[] {
162
- if (resources.length <= 1) {
163
- return resources;
164
- }
165
-
166
- const indicesByName = new Map<string, number[]>();
167
- for (let i = 0; i < resources.length; i += 1) {
168
- const name = resources[i]?.metadata?.name;
169
- if (!name) {
170
- continue;
171
- }
172
- const list = indicesByName.get(name);
173
- if (list) {
174
- list.push(i);
175
- } else {
176
- indicesByName.set(name, [i]);
177
- }
178
- }
179
-
180
- const edges = new Map<number, Set<number>>();
181
- const indegree = new Map<number, number>();
182
- for (let i = 0; i < resources.length; i += 1) {
183
- indegree.set(i, 0);
184
- }
185
-
186
- for (let i = 0; i < resources.length; i += 1) {
187
- const kind = resources[i]?.kind;
188
- if (!kind) {
189
- continue;
190
- }
191
- const definers = indicesByName.get(kind);
192
- if (!definers) {
193
- continue;
194
- }
195
- for (const definerIndex of definers) {
196
- if (definerIndex === i) {
197
- continue;
198
- }
199
- let set = edges.get(definerIndex);
200
- if (!set) {
201
- set = new Set();
202
- edges.set(definerIndex, set);
203
- }
204
- if (!set.has(i)) {
205
- set.add(i);
206
- indegree.set(i, (indegree.get(i) || 0) + 1);
207
- }
208
- }
209
- }
210
-
211
- const ready: number[] = [];
212
- for (let i = 0; i < resources.length; i += 1) {
213
- if ((indegree.get(i) || 0) === 0) {
214
- ready.push(i);
215
- }
216
- }
217
- ready.sort((a, b) => a - b);
218
-
219
- const ordered: RuntimeResource[] = [];
220
- while (ready.length > 0) {
221
- const index = ready.shift() as number;
222
- ordered.push(resources[index]);
223
- const next = edges.get(index);
224
- if (!next) {
225
- continue;
226
- }
227
- for (const dependent of next) {
228
- const count = (indegree.get(dependent) || 0) - 1;
229
- indegree.set(dependent, count);
230
- if (count === 0) {
231
- ready.push(dependent);
232
- }
233
- }
234
- if (ready.length > 1) {
235
- ready.sort((a, b) => a - b);
236
- }
237
- }
238
-
239
- if (ordered.length !== resources.length) {
240
- throw new Error("Resource dependency cycle detected");
241
- }
242
-
243
- return ordered;
244
- }
245
- }
@@ -1,35 +0,0 @@
1
- import * as yaml from "js-yaml";
2
- import type { ManifestAdapter, ManifestSourceData } from "./manifest-adapter.js";
3
-
4
- export class HttpAdapter implements ManifestAdapter {
5
- supports(pathOrUrl: string): boolean {
6
- return pathOrUrl.startsWith("http://") || pathOrUrl.startsWith("https://");
7
- }
8
-
9
- async read(url: string): Promise<ManifestSourceData> {
10
- return (await this.readAll(url))[0];
11
- }
12
-
13
- async readAll(url: string): Promise<ManifestSourceData[]> {
14
- const fetchUrl = url.includes(".yaml") ? url : url + "/module.yaml";
15
- const response = await fetch(fetchUrl);
16
- if (!response.ok) {
17
- throw new Error(
18
- `Failed to fetch manifest from ${fetchUrl}: ${response.status} ${response.statusText}`,
19
- );
20
- }
21
- return [
22
- {
23
- documents: yaml.loadAll(await response.text()),
24
- source: fetchUrl,
25
- baseDir: process.cwd(),
26
- uriBase: url,
27
- },
28
- ];
29
- }
30
-
31
- resolveRelative(base: string, relative: string): string {
32
- const baseWithSlash = base.endsWith("/") ? base : `${base}/`;
33
- return new URL(relative, baseWithSlash).href;
34
- }
35
- }
@@ -1,56 +0,0 @@
1
- import * as yaml from "js-yaml";
2
- import type { ManifestAdapter, ManifestSourceData } from "./manifest-adapter.js";
3
-
4
- const REGISTRY_BASE = "https://registry.telo.run";
5
-
6
- export class RegistryAdapter implements ManifestAdapter {
7
- supports(pathOrUrl: string): boolean {
8
- // Matches "owner/module@version" — has @ and /, but not an http/https URL or local path
9
- return (
10
- !pathOrUrl.startsWith("http://") &&
11
- !pathOrUrl.startsWith("https://") &&
12
- !pathOrUrl.startsWith("/") &&
13
- !pathOrUrl.startsWith(".") &&
14
- pathOrUrl.includes("@") &&
15
- pathOrUrl.includes("/")
16
- );
17
- }
18
-
19
- async read(moduleRef: string): Promise<ManifestSourceData> {
20
- return (await this.readAll(moduleRef))[0];
21
- }
22
-
23
- async readAll(moduleRef: string): Promise<ManifestSourceData[]> {
24
- const url = this.toRegistryUrl(moduleRef);
25
- const response = await fetch(url);
26
- if (!response.ok) {
27
- throw new Error(
28
- `Failed to fetch manifest ${moduleRef}: ${response.status} ${response.statusText}`,
29
- );
30
- }
31
- return [
32
- {
33
- documents: yaml.loadAll(await response.text()),
34
- source: url,
35
- baseDir: process.cwd(),
36
- uriBase: url.replace("/module.yaml", ""),
37
- },
38
- ];
39
- }
40
-
41
- resolveRelative(base: string, relative: string): string {
42
- const baseUrl = this.supports(base)
43
- ? this.toRegistryUrl(base).replace("/module.yaml", "")
44
- : base;
45
- const baseWithSlash = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
46
- return new URL(relative, baseWithSlash).href;
47
- }
48
-
49
- private toRegistryUrl(moduleRef: string): string {
50
- const atIdx = moduleRef.lastIndexOf("@");
51
- const path = moduleRef.slice(0, atIdx); // "example/module"
52
- const version = moduleRef.slice(atIdx + 1); // "1.2.3" or "v1.2.3"
53
- const versionSegment = version.startsWith("v") ? version.substring(1) : version;
54
- return `${REGISTRY_BASE}/${path}/${versionSegment}/module.yaml`;
55
- }
56
- }