@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.
- package/README.md +3 -3
- package/dist/capabilities/invokable.d.ts +4 -0
- package/dist/capabilities/invokable.d.ts.map +1 -0
- package/dist/capabilities/invokable.js +1 -0
- package/dist/capabilities/provider.d.ts +4 -0
- package/dist/capabilities/provider.d.ts.map +1 -0
- package/dist/capabilities/provider.js +1 -0
- package/dist/capabilities/runnable.d.ts +4 -0
- package/dist/capabilities/runnable.d.ts.map +1 -0
- package/dist/capabilities/runnable.js +1 -0
- package/dist/capability-definition.d.ts +8 -0
- package/dist/capability-definition.d.ts.map +1 -0
- package/dist/capability-definition.js +21 -0
- package/dist/cel-environment.d.ts +3 -0
- package/dist/cel-environment.d.ts.map +1 -0
- package/dist/cel-environment.js +13 -0
- package/dist/compiled-value.d.ts +9 -0
- package/dist/compiled-value.d.ts.map +1 -0
- package/dist/compiled-value.js +3 -0
- package/dist/context-provider.d.ts +1 -0
- package/dist/context-provider.d.ts.map +1 -0
- package/dist/controller-context.d.ts +2 -2
- package/dist/controller-context.d.ts.map +1 -0
- package/dist/evaluation-context.d.ts +162 -0
- package/dist/evaluation-context.d.ts.map +1 -0
- package/dist/evaluation-context.js +394 -0
- package/dist/execution-context.d.ts +13 -0
- package/dist/execution-context.d.ts.map +1 -0
- package/dist/execution-context.js +13 -0
- package/dist/index.d.ts +17 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -8
- package/dist/module-context.d.ts +53 -0
- package/dist/module-context.d.ts.map +1 -0
- package/dist/module-context.js +177 -0
- package/dist/ref.d.ts +47 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +11 -0
- package/dist/resource-context.d.ts +13 -4
- package/dist/resource-context.d.ts.map +1 -0
- package/dist/resource-instance.d.ts +5 -9
- package/dist/resource-instance.d.ts.map +1 -0
- package/dist/resource-manifest.d.ts +2 -1
- package/dist/resource-manifest.d.ts.map +1 -0
- package/dist/runtime-error.d.ts +8 -1
- package/dist/runtime-error.d.ts.map +1 -0
- package/dist/runtime-event.d.ts +1 -0
- package/dist/runtime-event.d.ts.map +1 -0
- package/dist/runtime-resource.d.ts +1 -0
- package/dist/runtime-resource.d.ts.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/package.json +2 -1
- package/src/capabilities/invokable.ts +3 -0
- package/src/capabilities/provider.ts +3 -0
- package/src/capabilities/runnable.ts +3 -0
- package/src/compiled-value.ts +11 -0
- package/src/controller-context.ts +4 -14
- package/src/evaluation-context.ts +519 -0
- package/src/execution-context.ts +21 -0
- package/src/index.ts +16 -8
- package/src/module-context.ts +215 -0
- package/src/ref.ts +61 -0
- package/src/resource-context.ts +13 -9
- package/src/resource-instance.ts +11 -14
- package/src/resource-manifest.ts +1 -1
- package/src/runtime-error.ts +21 -8
- package/src/types.ts +91 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { EvaluationContext } from "./evaluation-context.js";
|
|
2
|
+
/** Wraps process.env so that missing keys return null instead of throwing in CEL.
|
|
3
|
+
* cel-js uses Object.hasOwn(obj, key) before accessing obj[key], so we must
|
|
4
|
+
* intercept getOwnPropertyDescriptor to report every string key as "own". */
|
|
5
|
+
function lenientEnv(env) {
|
|
6
|
+
return new Proxy(env, {
|
|
7
|
+
get(target, key) {
|
|
8
|
+
if (typeof key !== "string")
|
|
9
|
+
return target[key];
|
|
10
|
+
return key in target ? (target[key] ?? null) : null;
|
|
11
|
+
},
|
|
12
|
+
has() {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
getOwnPropertyDescriptor(target, key) {
|
|
16
|
+
if (typeof key !== "string")
|
|
17
|
+
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
|
+
function collectSecretValues(secrets) {
|
|
24
|
+
const values = new Set();
|
|
25
|
+
for (const value of Object.values(secrets)) {
|
|
26
|
+
if (typeof value === "string" && value.length > 0) {
|
|
27
|
+
values.add(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return values;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Persistent, module-scoped context. Three reserved CEL namespaces:
|
|
34
|
+
* variables, secrets, resources.
|
|
35
|
+
*
|
|
36
|
+
* Unlike the base EvaluationContext, ModuleContext is stateful and mutable:
|
|
37
|
+
* variables/secrets/resources accumulate during multi-pass initialization and
|
|
38
|
+
* the context record is rebuilt on each mutation. Import aliases are tracked
|
|
39
|
+
* here for alias-prefixed kind resolution (e.g. MyImport.Http.Route).
|
|
40
|
+
*
|
|
41
|
+
* Imported modules are surfaced under resources.<alias> alongside local
|
|
42
|
+
* resources — no separate imports namespace needed.
|
|
43
|
+
*/
|
|
44
|
+
export class ModuleContext extends EvaluationContext {
|
|
45
|
+
targets;
|
|
46
|
+
_hostEnv;
|
|
47
|
+
_variables;
|
|
48
|
+
_secrets;
|
|
49
|
+
_resources;
|
|
50
|
+
/** Maps import alias → real module name for kind resolution. */
|
|
51
|
+
importAliases = new Map();
|
|
52
|
+
/** Maps import alias → allowed kind names. Absent entry = unrestricted (e.g. Kernel). */
|
|
53
|
+
importedKinds = new Map();
|
|
54
|
+
constructor(source, variables = {}, secrets = {}, resources = {}, targets = [], createInstance = async () => null, emit, _hostEnv) {
|
|
55
|
+
super(source, {}, createInstance, new Set(), emit);
|
|
56
|
+
this.targets = targets;
|
|
57
|
+
this._hostEnv = _hostEnv;
|
|
58
|
+
this._variables = variables;
|
|
59
|
+
this._secrets = secrets;
|
|
60
|
+
this._resources = resources;
|
|
61
|
+
this._rebuildContext();
|
|
62
|
+
}
|
|
63
|
+
get variables() {
|
|
64
|
+
return this._variables;
|
|
65
|
+
}
|
|
66
|
+
get secrets() {
|
|
67
|
+
return this._secrets;
|
|
68
|
+
}
|
|
69
|
+
get resources() {
|
|
70
|
+
return this._resources;
|
|
71
|
+
}
|
|
72
|
+
setVariables(vars) {
|
|
73
|
+
this._variables = vars;
|
|
74
|
+
this._rebuildContext();
|
|
75
|
+
}
|
|
76
|
+
setTargets(vars) {
|
|
77
|
+
this.targets = vars;
|
|
78
|
+
}
|
|
79
|
+
setSecrets(secrets) {
|
|
80
|
+
this._secrets = secrets;
|
|
81
|
+
this._rebuildContext();
|
|
82
|
+
}
|
|
83
|
+
setResource(name, props) {
|
|
84
|
+
this._resources = { ...this._resources, [name]: props };
|
|
85
|
+
this._rebuildContext();
|
|
86
|
+
}
|
|
87
|
+
onResourceSnapshotted(name, snap) {
|
|
88
|
+
this.setResource(name, snap);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Register an imported module under the given alias, with the list of kind names
|
|
92
|
+
* it exports. An empty kinds array means no restriction (used for built-ins like Kernel).
|
|
93
|
+
*/
|
|
94
|
+
registerImport(alias, targetModule, kinds) {
|
|
95
|
+
this.importAliases.set(alias, targetModule);
|
|
96
|
+
if (kinds.length > 0) {
|
|
97
|
+
this.importedKinds.set(alias, new Set(kinds));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
getInstance(name) {
|
|
101
|
+
const entry = this.resourceInstances.get(name);
|
|
102
|
+
if (!entry) {
|
|
103
|
+
throw new Error(`Resource '${name}' not found in module context. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`);
|
|
104
|
+
}
|
|
105
|
+
return entry?.instance;
|
|
106
|
+
}
|
|
107
|
+
getInvocable(name) {
|
|
108
|
+
const instance = this.getInstance(name);
|
|
109
|
+
if (instance &&
|
|
110
|
+
typeof instance === "object" &&
|
|
111
|
+
"invoke" in instance &&
|
|
112
|
+
typeof instance.invoke !== "function") {
|
|
113
|
+
throw new Error(`Resource '${name}' does not have an invoke() method.`);
|
|
114
|
+
}
|
|
115
|
+
return instance;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Resolve a fully-qualified kind like "Http.Server" to its real kind "http-server.Server".
|
|
119
|
+
* Splits on the first dot, looks up the prefix in importAliases, validates against
|
|
120
|
+
* importedKinds (if set), and reconstructs the resolved kind.
|
|
121
|
+
* Throws with a clear message if the alias is unknown or the kind is not exported.
|
|
122
|
+
*/
|
|
123
|
+
resolveKind(kind) {
|
|
124
|
+
const dot = kind.indexOf(".");
|
|
125
|
+
if (dot === -1) {
|
|
126
|
+
throw new Error(`Kind '${kind}' must be fully qualified (e.g. 'Module.KindName')`);
|
|
127
|
+
}
|
|
128
|
+
const prefix = kind.slice(0, dot);
|
|
129
|
+
const suffix = kind.slice(dot + 1);
|
|
130
|
+
const realModule = this.importAliases.get(prefix);
|
|
131
|
+
if (!realModule) {
|
|
132
|
+
const known = [...this.importAliases.keys()].join(", ") || "(none)";
|
|
133
|
+
throw new Error(`Kind '${kind}': no module imported with alias '${prefix}'. Known aliases: ${known}`);
|
|
134
|
+
}
|
|
135
|
+
const allowed = this.importedKinds.get(prefix);
|
|
136
|
+
if (allowed !== undefined && !allowed.has(suffix)) {
|
|
137
|
+
throw new Error(`Kind '${suffix}' is not exported by module '${realModule}' (imported as '${prefix}'). ` +
|
|
138
|
+
`Exported kinds: ${[...allowed].join(", ")}`);
|
|
139
|
+
}
|
|
140
|
+
return `${realModule}.${suffix}`;
|
|
141
|
+
}
|
|
142
|
+
_rebuildContext() {
|
|
143
|
+
this._context = {
|
|
144
|
+
variables: this._variables,
|
|
145
|
+
secrets: this._secrets,
|
|
146
|
+
resources: this._resources,
|
|
147
|
+
...(this._hostEnv ? { env: lenientEnv(this._hostEnv) } : {}),
|
|
148
|
+
};
|
|
149
|
+
this._secretValues = collectSecretValues(this._secrets);
|
|
150
|
+
}
|
|
151
|
+
async invoke(kind, name, inputs) {
|
|
152
|
+
const result = await super.invoke(kind, name, inputs);
|
|
153
|
+
const entry = this.resourceInstances.get(name);
|
|
154
|
+
if (entry && typeof entry.instance.snapshot === "function") {
|
|
155
|
+
const snap = await Promise.resolve(entry.instance.snapshot());
|
|
156
|
+
this.setResource(name, snap);
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
async run(name) {
|
|
161
|
+
const resource = this.resourceInstances.get(name);
|
|
162
|
+
if (!resource) {
|
|
163
|
+
throw new Error(`Target resource ${name} not found in module context. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`);
|
|
164
|
+
}
|
|
165
|
+
if (typeof resource.instance.run === "function") {
|
|
166
|
+
await resource.instance.run();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error(`Target resource ${name} does not have a run() method.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async runTargets() {
|
|
173
|
+
for (const target of this.targets) {
|
|
174
|
+
await this.run(target);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
package/dist/ref.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
2
|
+
/** Marker type for x-telo-ref fields. Carries the live instance type at the TypeScript level;
|
|
3
|
+
* at runtime this field holds `{ kind, name }` until Phase 5 injection replaces it.
|
|
4
|
+
* T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance. */
|
|
5
|
+
export interface KindRef<T = ResourceInstance> {
|
|
6
|
+
readonly kind: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly __type?: T;
|
|
9
|
+
}
|
|
10
|
+
/** Marker type for x-telo-scope fields. Has no runtime value — used only as a discriminant
|
|
11
|
+
* for Injected<T> to transform the field to ScopeHandle. */
|
|
12
|
+
export interface ScopeRef {
|
|
13
|
+
readonly __scope: true;
|
|
14
|
+
}
|
|
15
|
+
/** Gives a controller access to the resources initialized within a scope. */
|
|
16
|
+
export interface ScopeContext {
|
|
17
|
+
/** Returns the initialized instance for the given name.
|
|
18
|
+
* Throws synchronously if the name was not declared in the scope —
|
|
19
|
+
* this is always a programming error; all scope members are statically
|
|
20
|
+
* validated in Phase 3 before the kernel ever reaches runtime. */
|
|
21
|
+
getInstance(name: string): ResourceInstance;
|
|
22
|
+
}
|
|
23
|
+
/** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
|
|
24
|
+
* The controller calls run() to open the scope, execute work, and tear it down. */
|
|
25
|
+
export interface ScopeHandle {
|
|
26
|
+
run<T>(fn: (scope: ScopeContext) => Promise<T>): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
/** Transforms the raw config shape into the controller's view:
|
|
29
|
+
* - KindRef<U> → U (live instance, injected by Phase 5)
|
|
30
|
+
* - KindRef<U>[] → U[] (live instances, injected by Phase 5)
|
|
31
|
+
* - ScopeRef → ScopeHandle
|
|
32
|
+
* - everything else is unchanged */
|
|
33
|
+
export type Injected<T> = {
|
|
34
|
+
[K in keyof T]: T[K] extends KindRef<infer U> ? U : T[K] extends KindRef<infer U>[] ? U[] : NonNullable<T[K]> extends ScopeRef ? ScopeHandle | Exclude<T[K], ScopeRef> : T[K];
|
|
35
|
+
};
|
|
36
|
+
/** Returns a schema node that emits `x-telo-ref` for buildReferenceFieldMap and carries
|
|
37
|
+
* KindRef<T> as its TypeScript type. For TypeBox schemas use Type.Unsafe<KindRef<T>>(Ref(...)).
|
|
38
|
+
*
|
|
39
|
+
* @param ref Canonical ref string: "namespace/module-name#TypeName" or "kernel#TypeName" */
|
|
40
|
+
export declare const Ref: <T = ResourceInstance>(ref: string) => KindRef<T>;
|
|
41
|
+
/** Returns a schema node that emits `x-telo-scope` for buildReferenceFieldMap and carries
|
|
42
|
+
* ScopeRef as its TypeScript type. For TypeBox schemas use Type.Unsafe<ScopeRef>(Scope(...)).
|
|
43
|
+
*
|
|
44
|
+
* @param visibilityPath JSON Pointer(s) (RFC 6901) declaring where x-telo-ref slots within
|
|
45
|
+
* this field can resolve to scoped resources. */
|
|
46
|
+
export declare const Scope: (visibilityPath: string | string[]) => ScopeRef;
|
|
47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6F;AAC7F,eAAO,MAAM,GAAG,GAAI,CAAC,GAAG,gBAAgB,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,CAAC,CACf,CAAC;AAEnD;;;;wEAIwE;AACxE,eAAO,MAAM,KAAK,GAAI,gBAAgB,MAAM,GAAG,MAAM,EAAE,KAAG,QACG,CAAC"}
|
package/dist/ref.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Returns a schema node that emits `x-telo-ref` for buildReferenceFieldMap and carries
|
|
2
|
+
* KindRef<T> as its TypeScript type. For TypeBox schemas use Type.Unsafe<KindRef<T>>(Ref(...)).
|
|
3
|
+
*
|
|
4
|
+
* @param ref Canonical ref string: "namespace/module-name#TypeName" or "kernel#TypeName" */
|
|
5
|
+
export const Ref = (ref) => ({ "x-telo-ref": ref });
|
|
6
|
+
/** Returns a schema node that emits `x-telo-scope` for buildReferenceFieldMap and carries
|
|
7
|
+
* ScopeRef as its TypeScript type. For TypeBox schemas use Type.Unsafe<ScopeRef>(Scope(...)).
|
|
8
|
+
*
|
|
9
|
+
* @param visibilityPath JSON Pointer(s) (RFC 6901) declaring where x-telo-ref slots within
|
|
10
|
+
* this field can resolve to scoped resources. */
|
|
11
|
+
export const Scope = (visibilityPath) => ({ "x-telo-scope": visibilityPath });
|
|
@@ -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;
|
|
@@ -11,10 +13,14 @@ export declare class NoopValidator implements DataValidator {
|
|
|
11
13
|
export interface ResourceContext extends ControllerContext {
|
|
12
14
|
acquireHold(reason?: string): () => void;
|
|
13
15
|
emitEvent(event: string, payload?: any): Promise<void>;
|
|
14
|
-
invoke(kind: string, name: string,
|
|
16
|
+
invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: 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
|
+
transientChild(context: Record<string, any>): EvaluationContext;
|
|
23
|
+
withManifests<T>(manifests: any[], fn: () => T): T;
|
|
18
24
|
resolveChildren(resource: any, resourceName?: string): {
|
|
19
25
|
kind: string;
|
|
20
26
|
name: string;
|
|
@@ -25,8 +31,11 @@ export interface ResourceContext extends ControllerContext {
|
|
|
25
31
|
lookupSchema(name: string): object | undefined;
|
|
26
32
|
registerController(moduleName: string, kindName: string, controllerInstance: any): Promise<void>;
|
|
27
33
|
registerDefinition(definition: any): void;
|
|
28
|
-
|
|
29
|
-
isCapabilityRegistered(name: string): boolean;
|
|
30
|
-
getCapabilitySchema(name: string): Record<string, any> | null | undefined;
|
|
34
|
+
registerModuleImport(alias: string, targetModule: string, kinds: string[]): void;
|
|
31
35
|
teardownResource(kind: string, name: string): Promise<void>;
|
|
36
|
+
moduleContext: ModuleContext;
|
|
37
|
+
stdin: NodeJS.ReadableStream;
|
|
38
|
+
stdout: NodeJS.WritableStream;
|
|
39
|
+
stderr: NodeJS.WritableStream;
|
|
32
40
|
}
|
|
41
|
+
//# 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,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AAE,CAAC;IACtF,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;IAC9C,qBAAqB,CAAC,MAAM,EAAE,GAAG,GAAG,aAAa,CAAC;IAClD,cAAc,CAAC,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,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"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
|
+
import type { Runnable } from "./capabilities/runnable.js";
|
|
3
|
+
import type { ResourceContext } from "./resource-context.js";
|
|
4
|
+
export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<Invocable<TInput, TOutput>> & Partial<Runnable> & {
|
|
3
5
|
init?(ctx?: ResourceContext): Promise<void>;
|
|
4
|
-
run?(): void | Promise<void>;
|
|
5
|
-
invoke?(input: any): any | Promise<any>;
|
|
6
6
|
teardown?(): void | Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Optional method for debugging/snapshots
|
|
9
|
-
* Called when taking runtime state snapshots
|
|
10
|
-
* Should return serializable state data specific to this resource
|
|
11
|
-
*/
|
|
12
7
|
snapshot?(): Record<string, any> | Promise<Record<string, any>>;
|
|
13
8
|
};
|
|
9
|
+
//# 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,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,CACjF,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3B,GACC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAClB,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjE,CAAC"}
|
|
@@ -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"}
|
package/dist/runtime-error.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface RuntimeDiagnostic {
|
|
2
|
+
severity?: "error" | "warning";
|
|
3
|
+
message: string;
|
|
4
|
+
resource?: string;
|
|
5
|
+
code?: string;
|
|
6
|
+
}
|
|
7
|
+
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" | "ERR_MANIFEST_VALIDATION_FAILED" | "ERR_CIRCULAR_DEPENDENCY" | "ERR_SCOPE_RESOURCE_NOT_FOUND";
|
|
8
|
+
//# 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,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,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,GACvB,gCAAgC,GAChC,yBAAyB,GACzB,8BAA8B,CAAC"}
|
package/dist/runtime-event.d.ts
CHANGED
|
@@ -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"}
|
|
@@ -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"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
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 interface ResourceDefinition {
|
|
15
|
+
kind: string;
|
|
16
|
+
metadata: {
|
|
17
|
+
name: string;
|
|
18
|
+
module: string;
|
|
19
|
+
};
|
|
20
|
+
/** JSON Schema for the resource's compile-time configuration fields. */
|
|
21
|
+
schema?: Record<string, any>;
|
|
22
|
+
capability?: string;
|
|
23
|
+
controllers?: Array<{
|
|
24
|
+
runtime: string;
|
|
25
|
+
entry: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Controller definition for a resource kind.
|
|
30
|
+
* Maps a fully-qualified resource kind to its controller implementation for a specific runtime.
|
|
31
|
+
*/
|
|
32
|
+
export interface ControllerDefinition {
|
|
33
|
+
kind: string;
|
|
34
|
+
runtime: string;
|
|
35
|
+
entry: string;
|
|
36
|
+
controller?: any;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Controller instance - runtime representation of a controller that handles resource instances.
|
|
40
|
+
*
|
|
41
|
+
* TResource - the typed shape of the resource manifest (compile-time config)
|
|
42
|
+
* TInput - the typed shape of invoke() inputs (runtime)
|
|
43
|
+
* TOutput - the typed shape of invoke() outputs (runtime)
|
|
44
|
+
*/
|
|
45
|
+
export interface ControllerInstance<TResource extends ResourceManifest = ResourceManifest, TInput = Record<string, any>, TOutput = any> {
|
|
46
|
+
execute?(name: string, inputs: any, ctx: ExecContext): Promise<any>;
|
|
47
|
+
compile?(resource: TResource, ctx: ResourceContext): RuntimeResource | Promise<RuntimeResource>;
|
|
48
|
+
register?(ctx: ControllerContext): void | Promise<void>;
|
|
49
|
+
create?(resource: TResource, ctx: ResourceContext): ResourceInstance<TInput, TOutput> | null | Promise<ResourceInstance<TInput, TOutput> | null>;
|
|
50
|
+
schema?: any;
|
|
51
|
+
/** JSON Schema for invoke() inputs — used for runtime validation and static analysis. */
|
|
52
|
+
inputSchema?: Record<string, any>;
|
|
53
|
+
/** JSON Schema for invoke() outputs — used for documentation and static analysis. */
|
|
54
|
+
outputSchema?: Record<string, any>;
|
|
55
|
+
}
|
|
56
|
+
export interface Kernel {
|
|
57
|
+
loadFromConfig(runtimeYamlPath: string): Promise<void>;
|
|
58
|
+
start(): Promise<void>;
|
|
59
|
+
acquireHold(reason?: string): () => void;
|
|
60
|
+
waitForIdle(): Promise<void>;
|
|
61
|
+
requestExit(code: number): void;
|
|
62
|
+
readonly exitCode: number;
|
|
63
|
+
shutdown(): void;
|
|
64
|
+
}
|
|
65
|
+
export declare class RuntimeError extends Error {
|
|
66
|
+
code: RuntimeErrorCode;
|
|
67
|
+
diagnostics?: RuntimeDiagnostic[] | undefined;
|
|
68
|
+
constructor(code: RuntimeErrorCode, message: string, diagnostics?: RuntimeDiagnostic[] | undefined);
|
|
69
|
+
}
|
|
70
|
+
//# 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,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzE,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,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,E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GAAG,CAAC,CAAC;IAClC,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;IACzC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAI1B,QAAQ,IAAI,IAAI,CAAC;CAClB;AAED,qBAAa,YAAa,SAAQ,KAAK;IAE5B,IAAI,EAAE,gBAAgB;IAEtB,WAAW,CAAC,EAAE,iBAAiB,EAAE;gBAFjC,IAAI,EAAE,gBAAgB,EAC7B,OAAO,EAAE,MAAM,EACR,WAAW,CAAC,EAAE,iBAAiB,EAAE,YAAA;CAK3C"}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
+
"source": "./src/index.ts",
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
10
|
"bun": "./src/index.ts",
|
|
10
11
|
"import": "./dist/index.js",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A precompiled template or expression produced by the analyzer.
|
|
2
|
+
* Replaces raw "${{ }}" strings in manifests at load time.
|
|
3
|
+
* The SDK has no knowledge of CEL — it only calls .call(). */
|
|
4
|
+
export interface CompiledValue {
|
|
5
|
+
readonly __compiled: true;
|
|
6
|
+
call(ctx: Record<string, unknown>): unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isCompiledValue(v: unknown): v is CompiledValue {
|
|
10
|
+
return v !== null && typeof v === "object" && (v as any).__compiled === true;
|
|
11
|
+
}
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import { RuntimeEvent } from
|
|
1
|
+
import { RuntimeEvent } from "./runtime-event.js";
|
|
2
2
|
|
|
3
3
|
export interface ControllerContext {
|
|
4
|
-
on(
|
|
5
|
-
|
|
6
|
-
|
|
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
|
}
|