@telorun/sdk 0.2.3 → 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 (56) hide show
  1. package/README.md +5 -5
  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/context-provider.d.ts +18 -0
  12. package/dist/context-provider.d.ts.map +1 -0
  13. package/dist/context-provider.js +11 -0
  14. package/dist/controller-context.d.ts +2 -2
  15. package/dist/controller-context.d.ts.map +1 -0
  16. package/dist/evaluation-context.d.ts +103 -0
  17. package/dist/evaluation-context.d.ts.map +1 -0
  18. package/dist/evaluation-context.js +256 -0
  19. package/dist/execution-context.d.ts +13 -0
  20. package/dist/execution-context.d.ts.map +1 -0
  21. package/dist/execution-context.js +13 -0
  22. package/dist/index.d.ts +15 -7
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +14 -7
  25. package/dist/module-context.d.ts +51 -0
  26. package/dist/module-context.d.ts.map +1 -0
  27. package/dist/module-context.js +150 -0
  28. package/dist/resource-context.d.ts +21 -1
  29. package/dist/resource-context.d.ts.map +1 -0
  30. package/dist/resource-instance.d.ts +1 -0
  31. package/dist/resource-instance.d.ts.map +1 -0
  32. package/dist/resource-manifest.d.ts +2 -1
  33. package/dist/resource-manifest.d.ts.map +1 -0
  34. package/dist/runtime-error.d.ts +2 -1
  35. package/dist/runtime-error.d.ts.map +1 -0
  36. package/dist/runtime-event.d.ts +1 -0
  37. package/dist/runtime-event.d.ts.map +1 -0
  38. package/dist/runtime-resource.d.ts +1 -0
  39. package/dist/runtime-resource.d.ts.map +1 -0
  40. package/dist/types.d.ts +62 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +8 -0
  43. package/package.json +5 -1
  44. package/src/capabilities/invokable.ts +3 -0
  45. package/src/capabilities/provider.ts +3 -0
  46. package/src/capabilities/runnable.ts +3 -0
  47. package/src/context-provider.ts +25 -0
  48. package/src/controller-context.ts +4 -14
  49. package/src/evaluation-context.ts +337 -0
  50. package/src/execution-context.ts +21 -0
  51. package/src/index.ts +14 -7
  52. package/src/module-context.ts +187 -0
  53. package/src/resource-context.ts +17 -5
  54. package/src/resource-manifest.ts +1 -1
  55. package/src/runtime-error.ts +11 -7
  56. package/src/types.ts +83 -0
@@ -0,0 +1,150 @@
1
+ import { EvaluationContext } from "./evaluation-context.js";
2
+ function collectSecretValues(secrets) {
3
+ const values = new Set();
4
+ for (const value of Object.values(secrets)) {
5
+ if (typeof value === "string" && value.length > 0) {
6
+ values.add(value);
7
+ }
8
+ }
9
+ return values;
10
+ }
11
+ /**
12
+ * Persistent, module-scoped context. Three reserved CEL namespaces:
13
+ * variables, secrets, resources.
14
+ *
15
+ * Unlike the base EvaluationContext, ModuleContext is stateful and mutable:
16
+ * variables/secrets/resources accumulate during multi-pass initialization and
17
+ * the context record is rebuilt on each mutation. Import aliases are tracked
18
+ * here for alias-prefixed kind resolution (e.g. MyImport.Http.Route).
19
+ *
20
+ * Imported modules are surfaced under resources.<alias> alongside local
21
+ * resources — no separate imports namespace needed.
22
+ */
23
+ export class ModuleContext extends EvaluationContext {
24
+ targets;
25
+ _variables;
26
+ _secrets;
27
+ _resources;
28
+ /** Maps import alias → real module name for kind resolution. */
29
+ importAliases = new Map();
30
+ /** Maps import alias → allowed kind names. Absent entry = unrestricted (e.g. Kernel). */
31
+ importedKinds = new Map();
32
+ constructor(source, variables = {}, secrets = {}, resources = {}, targets = [], createInstance = async () => null, emit) {
33
+ super(source, {}, createInstance, new Set(), emit);
34
+ this.targets = targets;
35
+ this._variables = variables;
36
+ this._secrets = secrets;
37
+ this._resources = resources;
38
+ this._rebuildContext();
39
+ }
40
+ get variables() {
41
+ return this._variables;
42
+ }
43
+ get secrets() {
44
+ return this._secrets;
45
+ }
46
+ get resources() {
47
+ return this._resources;
48
+ }
49
+ setVariables(vars) {
50
+ this._variables = vars;
51
+ this._rebuildContext();
52
+ }
53
+ setTargets(vars) {
54
+ this.targets = vars;
55
+ }
56
+ setSecrets(secrets) {
57
+ this._secrets = secrets;
58
+ this._rebuildContext();
59
+ }
60
+ setResource(name, props) {
61
+ this._resources = { ...this._resources, [name]: props };
62
+ this._rebuildContext();
63
+ }
64
+ /**
65
+ * Register an imported module under the given alias, with the list of kind names
66
+ * it exports. An empty kinds array means no restriction (used for built-ins like Kernel).
67
+ */
68
+ registerImport(alias, targetModule, kinds) {
69
+ this.importAliases.set(alias, targetModule);
70
+ if (kinds.length > 0) {
71
+ this.importedKinds.set(alias, new Set(kinds));
72
+ }
73
+ }
74
+ getInstance(name) {
75
+ const entry = this.resourceInstances.get(name);
76
+ if (!entry) {
77
+ throw new Error(`Resource '${name}' not found in module context. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`);
78
+ }
79
+ return entry?.instance;
80
+ }
81
+ getInvokable(name) {
82
+ const instance = this.getInstance(name);
83
+ if (instance &&
84
+ typeof instance === "object" &&
85
+ "invoke" in instance &&
86
+ typeof instance.invoke !== "function") {
87
+ throw new Error(`Resource '${name}' does not have an invoke() method.`);
88
+ }
89
+ return instance;
90
+ }
91
+ /**
92
+ * Resolve a fully-qualified kind like "Http.Server" to its real kind "http-server.Server".
93
+ * Splits on the first dot, looks up the prefix in importAliases, validates against
94
+ * importedKinds (if set), and reconstructs the resolved kind.
95
+ * Throws with a clear message if the alias is unknown or the kind is not exported.
96
+ */
97
+ resolveKind(kind) {
98
+ const dot = kind.indexOf(".");
99
+ if (dot === -1) {
100
+ throw new Error(`Kind '${kind}' must be fully qualified (e.g. 'Module.KindName')`);
101
+ }
102
+ const prefix = kind.slice(0, dot);
103
+ const suffix = kind.slice(dot + 1);
104
+ const realModule = this.importAliases.get(prefix);
105
+ if (!realModule) {
106
+ const known = [...this.importAliases.keys()].join(", ") || "(none)";
107
+ throw new Error(`Kind '${kind}': no module imported with alias '${prefix}'. Known aliases: ${known}`);
108
+ }
109
+ const allowed = this.importedKinds.get(prefix);
110
+ if (allowed !== undefined && !allowed.has(suffix)) {
111
+ throw new Error(`Kind '${suffix}' is not exported by module '${realModule}' (imported as '${prefix}'). ` +
112
+ `Exported kinds: ${[...allowed].join(", ")}`);
113
+ }
114
+ return `${realModule}.${suffix}`;
115
+ }
116
+ _rebuildContext() {
117
+ this._context = {
118
+ variables: this._variables,
119
+ secrets: this._secrets,
120
+ resources: this._resources,
121
+ };
122
+ this._secretValues = collectSecretValues(this._secrets);
123
+ }
124
+ async invoke(kind, name, ...args) {
125
+ const result = await super.invoke(kind, name, ...args);
126
+ const entry = this.resourceInstances.get(name);
127
+ if (entry && typeof entry.instance.snapshot === "function") {
128
+ const snap = await Promise.resolve(entry.instance.snapshot());
129
+ this.setResource(name, snap);
130
+ }
131
+ return result;
132
+ }
133
+ async run(name) {
134
+ const resource = this.resourceInstances.get(name);
135
+ if (!resource) {
136
+ throw new Error(`Target resource ${name} not found in module context. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`);
137
+ }
138
+ if (typeof resource.instance.run === "function") {
139
+ await resource.instance.run();
140
+ }
141
+ else {
142
+ throw new Error(`Target resource ${name} does not have a run() method.`);
143
+ }
144
+ }
145
+ async runTargets() {
146
+ for (const target of this.targets) {
147
+ await this.run(target);
148
+ }
149
+ }
150
+ }
@@ -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
  export interface DataValidator {
4
6
  validate(data: any): void;
@@ -12,12 +14,30 @@ export interface ResourceContext extends ControllerContext {
12
14
  acquireHold(reason?: string): () => void;
13
15
  emitEvent(event: string, payload?: any): Promise<void>;
14
16
  invoke(kind: string, name: string, ...args: any[]): Promise<any>;
17
+ run(kind: string, name: string): Promise<void>;
15
18
  getResources(kind: string): RuntimeResource[];
16
19
  getResourcesByName(kind: string, name: string): RuntimeResource | null;
17
20
  registerManifest(resource: any): void;
21
+ spawnChildContext(): EvaluationContext;
22
+ withManifests<T>(manifests: any[], fn: () => T): T;
23
+ resolveChildren(resource: any, resourceName?: string): {
24
+ kind: string;
25
+ name: string;
26
+ };
18
27
  validateSchema(value: any, schema: any): void;
19
28
  createSchemaValidator(schema: any): DataValidator;
20
- registerController(moduleName: string, resourceKind: string, controllerInstance: any): Promise<void>;
29
+ registerSchema(name: string, schema: object): void;
30
+ lookupSchema(name: string): object | undefined;
31
+ registerController(moduleName: string, kindName: string, controllerInstance: any): Promise<void>;
21
32
  registerDefinition(definition: any): void;
33
+ registerModuleImport(alias: string, targetModule: string, kinds: string[]): void;
34
+ registerCapability(name: string, schema?: Record<string, any>): void;
35
+ isCapabilityRegistered(name: string): boolean;
36
+ getCapabilitySchema(name: string): Record<string, any> | null | undefined;
22
37
  teardownResource(kind: string, name: string): Promise<void>;
38
+ moduleContext: ModuleContext;
39
+ stdin: NodeJS.ReadableStream;
40
+ stdout: NodeJS.WritableStream;
41
+ stderr: NodeJS.WritableStream;
23
42
  }
43
+ //# sourceMappingURL=resource-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-context.d.ts","sourceRoot":"","sources":["../src/resource-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,GA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IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACnD,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC/C,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG,kBAAkB,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI,CAAC;IAC1C,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACjF,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IACrE,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9C,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1E,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,aAAa,EAAE,aAAa,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CAC/B"}
@@ -11,3 +11,4 @@ export type ResourceInstance = {
11
11
  */
12
12
  snapshot?(): Record<string, any> | Promise<Record<string, any>>;
13
13
  };
14
+ //# sourceMappingURL=resource-instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-instance.d.ts","sourceRoot":"","sources":["../src/resource-instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,GAAG,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjE,CAAC"}
@@ -5,8 +5,9 @@ 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;
12
12
  }
13
+ //# sourceMappingURL=resource-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-manifest.d.ts","sourceRoot":"","sources":["../src/resource-manifest.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
@@ -1 +1,2 @@
1
- export type RuntimeErrorCode = 'ERR_RESOURCE_NOT_FOUND' | 'ERR_CONTROLLER_NOT_FOUND' | 'ERR_CONTROLLER_INVALID' | 'ERR_RESOURCE_NOT_INVOKABLE' | 'ERR_DUPLICATE_RESOURCE' | 'ERR_EXECUTION_FAILED' | 'ERR_INVALID_VALUE';
1
+ export type RuntimeErrorCode = "ERR_RESOURCE_NOT_FOUND" | "ERR_RESOURCE_NOT_RUNNABLE" | "ERR_CONTROLLER_NOT_FOUND" | "ERR_CONTROLLER_INVALID" | "ERR_RESOURCE_INITIALIZATION_FAILED" | "ERR_RESOURCE_NOT_INVOKABLE" | "ERR_RESOURCE_SCHEMA_VALIDATION_FAILED" | "ERR_DUPLICATE_RESOURCE" | "ERR_EXECUTION_FAILED" | "ERR_INVALID_VALUE" | "ERR_VISIBILITY_DENIED";
2
+ //# sourceMappingURL=runtime-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-error.d.ts","sourceRoot":"","sources":["../src/runtime-error.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,wBAAwB,GACxB,2BAA2B,GAC3B,0BAA0B,GAC1B,wBAAwB,GACxB,oCAAoC,GACpC,4BAA4B,GAC5B,uCAAuC,GACvC,wBAAwB,GACxB,sBAAsB,GACtB,mBAAmB,GACnB,uBAAuB,CAAC"}
@@ -3,3 +3,4 @@ export type RuntimeEvent = {
3
3
  payload?: any;
4
4
  metadata?: Record<string, any>;
5
5
  };
6
+ //# sourceMappingURL=runtime-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-event.d.ts","sourceRoot":"","sources":["../src/runtime-event.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,CAAC"}
@@ -6,3 +6,4 @@ export interface RuntimeResource {
6
6
  [key: string]: any;
7
7
  };
8
8
  }
9
+ //# sourceMappingURL=runtime-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-resource.d.ts","sourceRoot":"","sources":["../src/runtime-resource.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH"}
@@ -0,0 +1,62 @@
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 { RuntimeErrorCode } from "./runtime-error.js";
6
+ import { RuntimeResource } from "./runtime-resource.js";
7
+ export interface KernelContext {
8
+ kernel: Kernel;
9
+ }
10
+ export interface ExecContext {
11
+ execute(urn: string, input: any): Promise<any>;
12
+ [key: string]: any;
13
+ }
14
+ export type ResourceCapability = string;
15
+ export interface ResourceDefinition {
16
+ kind: string;
17
+ metadata: {
18
+ name: string;
19
+ module: string;
20
+ };
21
+ schema: Record<string, any>;
22
+ capabilities: ResourceCapability[];
23
+ events?: string[];
24
+ controllers?: Array<{
25
+ runtime: string;
26
+ entry: string;
27
+ }>;
28
+ }
29
+ /**
30
+ * Controller definition for a resource kind.
31
+ * Maps a fully-qualified resource kind to its controller implementation for a specific runtime.
32
+ */
33
+ export interface ControllerDefinition {
34
+ kind: string;
35
+ runtime: string;
36
+ entry: string;
37
+ controller?: any;
38
+ }
39
+ /**
40
+ * Controller instance - runtime representation of a controller that handles resource instances.
41
+ */
42
+ export interface ControllerInstance {
43
+ execute?(name: string, inputs: any, ctx: ExecContext): Promise<any>;
44
+ compile?(resource: ResourceManifest, ctx: ResourceContext): RuntimeResource | Promise<RuntimeResource>;
45
+ register?(ctx: ControllerContext): void | Promise<void>;
46
+ create?(resource: ResourceManifest, ctx: ResourceContext): ResourceInstance | null | Promise<ResourceInstance | null>;
47
+ schema: any;
48
+ }
49
+ export interface Kernel {
50
+ loadFromConfig(runtimeYamlPath: string): Promise<void>;
51
+ start(): Promise<void>;
52
+ acquireHold(reason?: string): () => void;
53
+ waitForIdle(): Promise<void>;
54
+ requestExit(code: number): void;
55
+ readonly exitCode: number;
56
+ shutdown(): void;
57
+ }
58
+ export declare class RuntimeError extends Error {
59
+ code: RuntimeErrorCode;
60
+ constructor(code: RuntimeErrorCode, message: string);
61
+ }
62
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAExC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,YAAY,EAAE,kBAAkB,EAAE,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB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CAClB;AAED,qBAAa,YAAa,SAAQ,KAAK;IAE5B,IAAI,EAAE,gBAAgB;gBAAtB,IAAI,EAAE,gBAAgB,EAC7B,OAAO,EAAE,MAAM;CAKlB"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ export class RuntimeError extends Error {
2
+ code;
3
+ constructor(code, message) {
4
+ super(message);
5
+ this.code = code;
6
+ this.name = "RuntimeError";
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@telorun/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
+ "source": "./src/index.ts",
9
10
  "bun": "./src/index.ts",
10
11
  "import": "./dist/index.js",
11
12
  "default": "./dist/index.js"
@@ -15,6 +16,9 @@
15
16
  "dist/**",
16
17
  "src/**"
17
18
  ],
19
+ "dependencies": {
20
+ "cel-js": "^0.8.2"
21
+ },
18
22
  "devDependencies": {
19
23
  "@types/node": "^20.0.0",
20
24
  "typescript": "^5.0.0"
@@ -0,0 +1,3 @@
1
+ export interface Invokable {
2
+ invoke(inputs: Record<string, any>): Promise<any>;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface Provider {
2
+ init(): Promise<void>;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface Runnable {
2
+ run(): Promise<void>;
3
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Optional interface that a ResourceInstance can implement to expose
3
+ * stable, boot-time key/value pairs into the shared CEL context.
4
+ *
5
+ * Values are captured once after init() completes and cached for the
6
+ * lifetime of the initialization phase. Do not return request-specific
7
+ * or mutable data — this is AOT (Ahead-of-Time) static context only.
8
+ */
9
+ export interface ContextProvider {
10
+ provideContext(): Record<string, unknown>;
11
+ }
12
+
13
+ /**
14
+ * Duck-type guard: returns true when `instance` has a callable `provideContext` method.
15
+ * The kernel uses this to detect providers without coupling to any concrete class,
16
+ * keeping the Core 100% generic.
17
+ */
18
+ export function isContextProvider(instance: unknown): instance is ContextProvider {
19
+ return (
20
+ typeof instance === 'object' &&
21
+ instance !== null &&
22
+ 'provideContext' in instance &&
23
+ typeof (instance as Record<string, unknown>)['provideContext'] === 'function'
24
+ );
25
+ }
@@ -1,21 +1,11 @@
1
- import { RuntimeEvent } from './runtime-event.js';
1
+ import { RuntimeEvent } from "./runtime-event.js";
2
2
 
3
3
  export interface ControllerContext {
4
- on(
5
- event: string,
6
- handler: (event: RuntimeEvent) => void | Promise<void>,
7
- ): void;
8
- once(
9
- event: string,
10
- handler: (event: RuntimeEvent) => void | Promise<void>,
11
- ): void;
12
- off(
13
- event: string,
14
- handler: (event: RuntimeEvent) => void | Promise<void>,
15
- ): void;
4
+ on(event: string, handler: (event: RuntimeEvent) => void | Promise<void>): void;
5
+ once(event: string, handler: (event: RuntimeEvent) => void | Promise<void>): void;
6
+ off(event: string, handler: (event: RuntimeEvent) => void | Promise<void>): void;
16
7
  emit(event: string, payload?: any, metadata?: Record<string, any>): void;
17
8
  acquireHold(reason?: string): () => void;
18
9
  requestExit(code: number): void;
19
- evaluateCel(expression: string, context: Record<string, any>): unknown;
20
10
  expandValue(value: any, context: Record<string, any>): any;
21
11
  }