@telorun/sdk 0.2.4 → 0.2.6

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 (69) hide show
  1. package/README.md +3 -3
  2. package/dist/capabilities/invokable.d.ts +4 -0
  3. package/dist/capabilities/invokable.d.ts.map +1 -0
  4. package/dist/capabilities/invokable.js +1 -0
  5. package/dist/capabilities/provider.d.ts +4 -0
  6. package/dist/capabilities/provider.d.ts.map +1 -0
  7. package/dist/capabilities/provider.js +1 -0
  8. package/dist/capabilities/runnable.d.ts +4 -0
  9. package/dist/capabilities/runnable.d.ts.map +1 -0
  10. package/dist/capabilities/runnable.js +1 -0
  11. package/dist/capability-definition.d.ts +8 -0
  12. package/dist/capability-definition.d.ts.map +1 -0
  13. package/dist/capability-definition.js +21 -0
  14. package/dist/cel-environment.d.ts +3 -0
  15. package/dist/cel-environment.d.ts.map +1 -0
  16. package/dist/cel-environment.js +13 -0
  17. package/dist/compiled-value.d.ts +9 -0
  18. package/dist/compiled-value.d.ts.map +1 -0
  19. package/dist/compiled-value.js +3 -0
  20. package/dist/context-provider.d.ts +1 -0
  21. package/dist/context-provider.d.ts.map +1 -0
  22. package/dist/controller-context.d.ts +2 -2
  23. package/dist/controller-context.d.ts.map +1 -0
  24. package/dist/evaluation-context.d.ts +162 -0
  25. package/dist/evaluation-context.d.ts.map +1 -0
  26. package/dist/evaluation-context.js +394 -0
  27. package/dist/execution-context.d.ts +13 -0
  28. package/dist/execution-context.d.ts.map +1 -0
  29. package/dist/execution-context.js +13 -0
  30. package/dist/index.d.ts +17 -8
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +16 -8
  33. package/dist/module-context.d.ts +53 -0
  34. package/dist/module-context.d.ts.map +1 -0
  35. package/dist/module-context.js +177 -0
  36. package/dist/ref.d.ts +47 -0
  37. package/dist/ref.d.ts.map +1 -0
  38. package/dist/ref.js +11 -0
  39. package/dist/resource-context.d.ts +13 -4
  40. package/dist/resource-context.d.ts.map +1 -0
  41. package/dist/resource-instance.d.ts +5 -9
  42. package/dist/resource-instance.d.ts.map +1 -0
  43. package/dist/resource-manifest.d.ts +2 -1
  44. package/dist/resource-manifest.d.ts.map +1 -0
  45. package/dist/runtime-error.d.ts +8 -1
  46. package/dist/runtime-error.d.ts.map +1 -0
  47. package/dist/runtime-event.d.ts +1 -0
  48. package/dist/runtime-event.d.ts.map +1 -0
  49. package/dist/runtime-resource.d.ts +1 -0
  50. package/dist/runtime-resource.d.ts.map +1 -0
  51. package/dist/types.d.ts +70 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +10 -0
  54. package/package.json +2 -1
  55. package/src/capabilities/invokable.ts +3 -0
  56. package/src/capabilities/provider.ts +3 -0
  57. package/src/capabilities/runnable.ts +3 -0
  58. package/src/compiled-value.ts +11 -0
  59. package/src/controller-context.ts +4 -14
  60. package/src/evaluation-context.ts +519 -0
  61. package/src/execution-context.ts +21 -0
  62. package/src/index.ts +16 -8
  63. package/src/module-context.ts +215 -0
  64. package/src/ref.ts +61 -0
  65. package/src/resource-context.ts +13 -9
  66. package/src/resource-instance.ts +11 -14
  67. package/src/resource-manifest.ts +1 -1
  68. package/src/runtime-error.ts +21 -8
  69. package/src/types.ts +91 -0
@@ -0,0 +1,215 @@
1
+ import { Invocable } from "./capabilities/invokable.js";
2
+ import { EmitEvent, EvaluationContext, InstanceFactory } from "./evaluation-context.js";
3
+
4
+ /** Wraps process.env so that missing keys return null instead of throwing in CEL.
5
+ * cel-js uses Object.hasOwn(obj, key) before accessing obj[key], so we must
6
+ * intercept getOwnPropertyDescriptor to report every string key as "own". */
7
+ function lenientEnv(env: Record<string, string | undefined>): Record<string, string | null> {
8
+ return new Proxy(env as Record<string, string | null>, {
9
+ get(target, key) {
10
+ if (typeof key !== "string") return (target as any)[key];
11
+ return key in target ? (target[key] ?? null) : null;
12
+ },
13
+ has() {
14
+ return true;
15
+ },
16
+ getOwnPropertyDescriptor(target, key) {
17
+ if (typeof key !== "string") return Object.getOwnPropertyDescriptor(target, key);
18
+ const value = key in target ? (target[key] ?? null) : null;
19
+ return { configurable: true, enumerable: true, writable: true, value };
20
+ },
21
+ });
22
+ }
23
+
24
+ function collectSecretValues(secrets: Record<string, unknown>): Set<string> {
25
+ const values = new Set<string>();
26
+ for (const value of Object.values(secrets)) {
27
+ if (typeof value === "string" && value.length > 0) {
28
+ values.add(value);
29
+ }
30
+ }
31
+ return values;
32
+ }
33
+
34
+ /**
35
+ * Persistent, module-scoped context. Three reserved CEL namespaces:
36
+ * variables, secrets, resources.
37
+ *
38
+ * Unlike the base EvaluationContext, ModuleContext is stateful and mutable:
39
+ * variables/secrets/resources accumulate during multi-pass initialization and
40
+ * the context record is rebuilt on each mutation. Import aliases are tracked
41
+ * here for alias-prefixed kind resolution (e.g. MyImport.Http.Route).
42
+ *
43
+ * Imported modules are surfaced under resources.<alias> alongside local
44
+ * resources — no separate imports namespace needed.
45
+ */
46
+ export class ModuleContext extends EvaluationContext {
47
+ private _variables: Record<string, unknown>;
48
+ private _secrets: Record<string, unknown>;
49
+ private _resources: Record<string, unknown>;
50
+
51
+ /** Maps import alias → real module name for kind resolution. */
52
+ readonly importAliases = new Map<string, string>();
53
+
54
+ /** Maps import alias → allowed kind names. Absent entry = unrestricted (e.g. Kernel). */
55
+ private readonly importedKinds = new Map<string, Set<string>>();
56
+
57
+ constructor(
58
+ source: string,
59
+ variables: Record<string, unknown> = {},
60
+ secrets: Record<string, unknown> = {},
61
+ resources: Record<string, unknown> = {},
62
+ private targets: string[] = [],
63
+ createInstance: InstanceFactory = async () => null,
64
+ emit: EmitEvent,
65
+ private readonly _hostEnv?: Record<string, string | undefined>,
66
+ ) {
67
+ super(source, {}, createInstance, new Set(), emit);
68
+ this._variables = variables;
69
+ this._secrets = secrets;
70
+ this._resources = resources;
71
+ this._rebuildContext();
72
+ }
73
+
74
+ get variables(): Record<string, unknown> {
75
+ return this._variables;
76
+ }
77
+
78
+ get secrets(): Record<string, unknown> {
79
+ return this._secrets;
80
+ }
81
+
82
+ get resources(): Record<string, unknown> {
83
+ return this._resources;
84
+ }
85
+
86
+ setVariables(vars: Record<string, unknown>): void {
87
+ this._variables = vars;
88
+ this._rebuildContext();
89
+ }
90
+
91
+ setTargets(vars: string[]): void {
92
+ this.targets = vars;
93
+ }
94
+
95
+ setSecrets(secrets: Record<string, unknown>): void {
96
+ this._secrets = secrets;
97
+ this._rebuildContext();
98
+ }
99
+
100
+ setResource(name: string, props: Record<string, unknown>): void {
101
+ this._resources = { ...this._resources, [name]: props };
102
+ this._rebuildContext();
103
+ }
104
+
105
+ protected override onResourceSnapshotted(name: string, snap: Record<string, unknown>): void {
106
+ this.setResource(name, snap);
107
+ }
108
+
109
+ /**
110
+ * Register an imported module under the given alias, with the list of kind names
111
+ * it exports. An empty kinds array means no restriction (used for built-ins like Kernel).
112
+ */
113
+ registerImport(alias: string, targetModule: string, kinds: string[]): void {
114
+ this.importAliases.set(alias, targetModule);
115
+ if (kinds.length > 0) {
116
+ this.importedKinds.set(alias, new Set(kinds));
117
+ }
118
+ }
119
+
120
+ getInstance(name: string): unknown {
121
+ const entry = this.resourceInstances.get(name);
122
+ if (!entry) {
123
+ throw new Error(
124
+ `Resource '${name}' not found in module context. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`,
125
+ );
126
+ }
127
+ return entry?.instance;
128
+ }
129
+
130
+ getInvocable<TInput = Record<string, any>, TOutput = any>(
131
+ name: string,
132
+ ): Invocable<TInput, TOutput> {
133
+ const instance = this.getInstance(name);
134
+
135
+ if (
136
+ instance &&
137
+ typeof instance === "object" &&
138
+ "invoke" in instance &&
139
+ typeof instance.invoke !== "function"
140
+ ) {
141
+ throw new Error(`Resource '${name}' does not have an invoke() method.`);
142
+ }
143
+ return instance as Invocable<TInput, TOutput>;
144
+ }
145
+
146
+ /**
147
+ * Resolve a fully-qualified kind like "Http.Server" to its real kind "http-server.Server".
148
+ * Splits on the first dot, looks up the prefix in importAliases, validates against
149
+ * importedKinds (if set), and reconstructs the resolved kind.
150
+ * Throws with a clear message if the alias is unknown or the kind is not exported.
151
+ */
152
+ resolveKind(kind: string): string {
153
+ const dot = kind.indexOf(".");
154
+ if (dot === -1) {
155
+ throw new Error(`Kind '${kind}' must be fully qualified (e.g. 'Module.KindName')`);
156
+ }
157
+ const prefix = kind.slice(0, dot);
158
+ const suffix = kind.slice(dot + 1);
159
+ const realModule = this.importAliases.get(prefix);
160
+ if (!realModule) {
161
+ const known = [...this.importAliases.keys()].join(", ") || "(none)";
162
+ throw new Error(
163
+ `Kind '${kind}': no module imported with alias '${prefix}'. Known aliases: ${known}`,
164
+ );
165
+ }
166
+ const allowed = this.importedKinds.get(prefix);
167
+ if (allowed !== undefined && !allowed.has(suffix)) {
168
+ throw new Error(
169
+ `Kind '${suffix}' is not exported by module '${realModule}' (imported as '${prefix}'). ` +
170
+ `Exported kinds: ${[...allowed].join(", ")}`,
171
+ );
172
+ }
173
+ return `${realModule}.${suffix}`;
174
+ }
175
+
176
+ private _rebuildContext(): void {
177
+ this._context = {
178
+ variables: this._variables,
179
+ secrets: this._secrets,
180
+ resources: this._resources,
181
+ ...(this._hostEnv ? { env: lenientEnv(this._hostEnv) } : {}),
182
+ };
183
+ this._secretValues = collectSecretValues(this._secrets);
184
+ }
185
+
186
+ override async invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any> {
187
+ const result = await super.invoke(kind, name, inputs);
188
+ const entry = this.resourceInstances.get(name);
189
+ if (entry && typeof (entry.instance as any).snapshot === "function") {
190
+ const snap = await Promise.resolve((entry.instance as any).snapshot());
191
+ this.setResource(name, snap as Record<string, unknown>);
192
+ }
193
+ return result;
194
+ }
195
+
196
+ async run(name: string) {
197
+ const resource = this.resourceInstances.get(name);
198
+ if (!resource) {
199
+ throw new Error(
200
+ `Target resource ${name} not found in module context. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`,
201
+ );
202
+ }
203
+ if (typeof resource.instance.run === "function") {
204
+ await resource.instance.run();
205
+ } else {
206
+ throw new Error(`Target resource ${name} does not have a run() method.`);
207
+ }
208
+ }
209
+
210
+ async runTargets() {
211
+ for (const target of this.targets) {
212
+ await this.run(target);
213
+ }
214
+ }
215
+ }
package/src/ref.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { ResourceInstance } from "./resource-instance.js";
2
+
3
+ /** Marker type for x-telo-ref fields. Carries the live instance type at the TypeScript level;
4
+ * at runtime this field holds `{ kind, name }` until Phase 5 injection replaces it.
5
+ * T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance. */
6
+ export interface KindRef<T = ResourceInstance> {
7
+ readonly kind: string;
8
+ readonly name: string;
9
+ readonly __type?: T;
10
+ }
11
+
12
+ /** Marker type for x-telo-scope fields. Has no runtime value — used only as a discriminant
13
+ * for Injected<T> to transform the field to ScopeHandle. */
14
+ export interface ScopeRef {
15
+ readonly __scope: true;
16
+ }
17
+
18
+ /** Gives a controller access to the resources initialized within a scope. */
19
+ export interface ScopeContext {
20
+ /** Returns the initialized instance for the given name.
21
+ * Throws synchronously if the name was not declared in the scope —
22
+ * this is always a programming error; all scope members are statically
23
+ * validated in Phase 3 before the kernel ever reaches runtime. */
24
+ getInstance(name: string): ResourceInstance;
25
+ }
26
+
27
+ /** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
28
+ * The controller calls run() to open the scope, execute work, and tear it down. */
29
+ export interface ScopeHandle {
30
+ run<T>(fn: (scope: ScopeContext) => Promise<T>): Promise<T>;
31
+ }
32
+
33
+ /** Transforms the raw config shape into the controller's view:
34
+ * - KindRef<U> → U (live instance, injected by Phase 5)
35
+ * - KindRef<U>[] → U[] (live instances, injected by Phase 5)
36
+ * - ScopeRef → ScopeHandle
37
+ * - everything else is unchanged */
38
+ export type Injected<T> = {
39
+ [K in keyof T]: T[K] extends KindRef<infer U>
40
+ ? U
41
+ : T[K] extends KindRef<infer U>[]
42
+ ? U[]
43
+ : NonNullable<T[K]> extends ScopeRef
44
+ ? ScopeHandle | Exclude<T[K], ScopeRef>
45
+ : T[K];
46
+ };
47
+
48
+ /** Returns a schema node that emits `x-telo-ref` for buildReferenceFieldMap and carries
49
+ * KindRef<T> as its TypeScript type. For TypeBox schemas use Type.Unsafe<KindRef<T>>(Ref(...)).
50
+ *
51
+ * @param ref Canonical ref string: "namespace/module-name#TypeName" or "kernel#TypeName" */
52
+ export const Ref = <T = ResourceInstance>(ref: string): KindRef<T> =>
53
+ ({ "x-telo-ref": ref } as unknown as KindRef<T>);
54
+
55
+ /** Returns a schema node that emits `x-telo-scope` for buildReferenceFieldMap and carries
56
+ * ScopeRef as its TypeScript type. For TypeBox schemas use Type.Unsafe<ScopeRef>(Scope(...)).
57
+ *
58
+ * @param visibilityPath JSON Pointer(s) (RFC 6901) declaring where x-telo-ref slots within
59
+ * this field can resolve to scoped resources. */
60
+ export const Scope = (visibilityPath: string | string[]): ScopeRef =>
61
+ ({ "x-telo-scope": visibilityPath } as unknown as ScopeRef);
@@ -1,4 +1,6 @@
1
1
  import { ControllerContext } from "./controller-context.js";
2
+ import { EvaluationContext } from "./evaluation-context.js";
3
+ import { ModuleContext } from "./module-context.js";
2
4
  import { RuntimeResource } from "./runtime-resource.js";
3
5
 
4
6
  export interface DataValidator {
@@ -19,23 +21,25 @@ export class NoopValidator implements DataValidator {
19
21
  export interface ResourceContext extends ControllerContext {
20
22
  acquireHold(reason?: string): () => void;
21
23
  emitEvent(event: string, payload?: any): Promise<void>;
22
- invoke(kind: string, name: string, ...args: any[]): Promise<any>;
24
+ invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
25
+ run(kind: string, name: string): Promise<void>;
23
26
  getResources(kind: string): RuntimeResource[];
24
27
  getResourcesByName(kind: string, name: string): RuntimeResource | null;
25
28
  registerManifest(resource: any): void;
29
+ spawnChildContext(): EvaluationContext;
30
+ transientChild(context: Record<string, any>): EvaluationContext;
31
+ withManifests<T>(manifests: any[], fn: () => T): T;
26
32
  resolveChildren(resource: any, resourceName?: string): { kind: string; name: string };
27
33
  validateSchema(value: any, schema: any): void;
28
34
  createSchemaValidator(schema: any): DataValidator;
29
35
  registerSchema(name: string, schema: object): void;
30
36
  lookupSchema(name: string): object | undefined;
31
- registerController(
32
- moduleName: string,
33
- kindName: string,
34
- controllerInstance: any,
35
- ): Promise<void>;
37
+ registerController(moduleName: string, kindName: string, controllerInstance: any): Promise<void>;
36
38
  registerDefinition(definition: any): void;
37
- registerCapability(name: string, schema?: Record<string, any>): void;
38
- isCapabilityRegistered(name: string): boolean;
39
- getCapabilitySchema(name: string): Record<string, any> | null | undefined;
39
+ registerModuleImport(alias: string, targetModule: string, kinds: string[]): void;
40
40
  teardownResource(kind: string, name: string): Promise<void>;
41
+ moduleContext: ModuleContext;
42
+ stdin: NodeJS.ReadableStream;
43
+ stdout: NodeJS.WritableStream;
44
+ stderr: NodeJS.WritableStream;
41
45
  }
@@ -1,15 +1,12 @@
1
- import { ResourceContext } from "./resource-context.js";
1
+ import type { Invocable } from "./capabilities/invokable.js";
2
+ import type { Runnable } from "./capabilities/runnable.js";
3
+ import type { ResourceContext } from "./resource-context.js";
2
4
 
3
- export type ResourceInstance = {
4
- init?(ctx?: ResourceContext): Promise<void>;
5
- run?(): void | Promise<void>;
6
- invoke?(input: any): any | Promise<any>;
7
- teardown?(): void | Promise<void>;
8
-
9
- /**
10
- * Optional method for debugging/snapshots
11
- * Called when taking runtime state snapshots
12
- * Should return serializable state data specific to this resource
13
- */
14
- snapshot?(): Record<string, any> | Promise<Record<string, any>>;
15
- };
5
+ export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<
6
+ Invocable<TInput, TOutput>
7
+ > &
8
+ Partial<Runnable> & {
9
+ init?(ctx?: ResourceContext): Promise<void>;
10
+ teardown?(): void | Promise<void>;
11
+ snapshot?(): Record<string, any> | Promise<Record<string, any>>;
12
+ };
@@ -5,7 +5,7 @@ export interface ResourceManifest {
5
5
  kind: string;
6
6
  metadata: {
7
7
  name: string;
8
- module: string;
8
+ module?: string;
9
9
  [key: string]: any;
10
10
  };
11
11
  [key: string]: any;
@@ -1,9 +1,22 @@
1
+ export interface RuntimeDiagnostic {
2
+ severity?: "error" | "warning";
3
+ message: string;
4
+ resource?: string;
5
+ code?: string;
6
+ }
7
+
1
8
  export type RuntimeErrorCode =
2
- | 'ERR_RESOURCE_NOT_FOUND'
3
- | 'ERR_CONTROLLER_NOT_FOUND'
4
- | 'ERR_CONTROLLER_INVALID'
5
- | 'ERR_RESOURCE_NOT_INVOKABLE'
6
- | 'ERR_DUPLICATE_RESOURCE'
7
- | 'ERR_EXECUTION_FAILED'
8
- | 'ERR_INVALID_VALUE'
9
- | 'ERR_VISIBILITY_DENIED';
9
+ | "ERR_RESOURCE_NOT_FOUND"
10
+ | "ERR_RESOURCE_NOT_RUNNABLE"
11
+ | "ERR_CONTROLLER_NOT_FOUND"
12
+ | "ERR_CONTROLLER_INVALID"
13
+ | "ERR_RESOURCE_INITIALIZATION_FAILED"
14
+ | "ERR_RESOURCE_NOT_INVOKABLE"
15
+ | "ERR_RESOURCE_SCHEMA_VALIDATION_FAILED"
16
+ | "ERR_DUPLICATE_RESOURCE"
17
+ | "ERR_EXECUTION_FAILED"
18
+ | "ERR_INVALID_VALUE"
19
+ | "ERR_VISIBILITY_DENIED"
20
+ | "ERR_MANIFEST_VALIDATION_FAILED"
21
+ | "ERR_CIRCULAR_DEPENDENCY"
22
+ | "ERR_SCOPE_RESOURCE_NOT_FOUND";
package/src/types.ts ADDED
@@ -0,0 +1,91 @@
1
+ import { ControllerContext } from "./controller-context.js";
2
+ import { ResourceContext } from "./resource-context.js";
3
+ import { ResourceInstance } from "./resource-instance.js";
4
+ import { ResourceManifest } from "./resource-manifest.js";
5
+ import { RuntimeDiagnostic, RuntimeErrorCode } from "./runtime-error.js";
6
+ import { RuntimeResource } from "./runtime-resource.js";
7
+
8
+ export interface KernelContext {
9
+ kernel: Kernel;
10
+ }
11
+
12
+ export interface ExecContext {
13
+ execute(urn: string, input: any): Promise<any>;
14
+ [key: string]: any;
15
+ }
16
+
17
+ export interface ResourceDefinition {
18
+ kind: string;
19
+ metadata: {
20
+ name: string;
21
+ module: string;
22
+ };
23
+ /** JSON Schema for the resource's compile-time configuration fields. */
24
+ schema?: Record<string, any>;
25
+ capability?: string;
26
+ controllers?: Array<{
27
+ runtime: string;
28
+ entry: string;
29
+ }>;
30
+ }
31
+
32
+ /**
33
+ * Controller definition for a resource kind.
34
+ * Maps a fully-qualified resource kind to its controller implementation for a specific runtime.
35
+ */
36
+ export interface ControllerDefinition {
37
+ kind: string; // Fully-qualified kind (e.g., "Http.Route")
38
+ runtime: string; // Runtime selector (e.g., "node@>=20")
39
+ entry: string; // Path to controller implementation
40
+ controller?: any; // Lazy-loaded controller code
41
+ }
42
+
43
+ /**
44
+ * Controller instance - runtime representation of a controller that handles resource instances.
45
+ *
46
+ * TResource - the typed shape of the resource manifest (compile-time config)
47
+ * TInput - the typed shape of invoke() inputs (runtime)
48
+ * TOutput - the typed shape of invoke() outputs (runtime)
49
+ */
50
+ export interface ControllerInstance<
51
+ TResource extends ResourceManifest = ResourceManifest,
52
+ TInput = Record<string, any>,
53
+ TOutput = any,
54
+ > {
55
+ execute?(name: string, inputs: any, ctx: ExecContext): Promise<any>;
56
+ compile?(resource: TResource, ctx: ResourceContext): RuntimeResource | Promise<RuntimeResource>;
57
+ register?(ctx: ControllerContext): void | Promise<void>;
58
+ create?(
59
+ resource: TResource,
60
+ ctx: ResourceContext,
61
+ ): ResourceInstance<TInput, TOutput> | null | Promise<ResourceInstance<TInput, TOutput> | null>;
62
+ schema?: any;
63
+ /** JSON Schema for invoke() inputs — used for runtime validation and static analysis. */
64
+ inputSchema?: Record<string, any>;
65
+ /** JSON Schema for invoke() outputs — used for documentation and static analysis. */
66
+ outputSchema?: Record<string, any>;
67
+ }
68
+
69
+ export interface Kernel {
70
+ loadFromConfig(runtimeYamlPath: string): Promise<void>;
71
+ start(): Promise<void>;
72
+ acquireHold(reason?: string): () => void;
73
+ waitForIdle(): Promise<void>;
74
+ requestExit(code: number): void;
75
+ readonly exitCode: number;
76
+ // teardownResource(module: string, kind: string, name: string): Promise<void>;
77
+ // getSourceFiles(): string[];
78
+ // reloadSource(sourcePath: string): Promise<void>;
79
+ shutdown(): void;
80
+ }
81
+
82
+ export class RuntimeError extends Error {
83
+ constructor(
84
+ public code: RuntimeErrorCode,
85
+ message: string,
86
+ public diagnostics?: RuntimeDiagnostic[],
87
+ ) {
88
+ super(message);
89
+ this.name = "RuntimeError";
90
+ }
91
+ }