@telorun/sdk 0.12.0 → 0.16.0

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.
@@ -27,10 +27,12 @@ export type InstanceFactory = (context: EvaluationContext, resource: ResourceMan
27
27
  * fields of the resource config before the controller sees them in init().
28
28
  *
29
29
  * @param resource The resource manifest whose config fields may be mutated in-place.
30
- * @param getInstance Looks up an already-initialized instance by resource name.
30
+ * @param getInstance Looks up an already-initialized instance by resource name. With a
31
+ * non-`Self` `alias`, resolves a cross-module reference into that
32
+ * import's published exported instances instead of the local context.
31
33
  * Returns undefined when the named resource is not yet initialized.
32
34
  */
33
- export type PreInitHook = (resource: ResourceManifest, getInstance: (name: string) => ResourceInstance | undefined) => void;
35
+ export type PreInitHook = (resource: ResourceManifest, getInstance: (name: string, alias?: string) => ResourceInstance | undefined) => void;
34
36
  /** Canonical key for a resource instance: "<module>.<kind>.<name>" */
35
37
  export declare function resourceKey(r: ResourceManifest): string;
36
38
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/E,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,GAAG,UAAU,GAAG,UAAU,CAAC;AAE/F;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG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AAC,IAAI,CAAC,CAAC;IACnC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAAC;IAChE,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3E,cAAc,CAAC,OAAO,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,GAAG,CAAC,CAAC;IAChB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAChC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAC3E,WAAW,CACT,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,MAAM,EAAE,EACf,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5B"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./compiled-value.js";
2
2
  export * from "./capabilities/invokable.js";
3
3
  export * from "./ref.js";
4
+ export * from "./invoke-step.js";
4
5
  export * from "./capabilities/provider.js";
5
6
  export * from "./capabilities/runnable.js";
6
7
  export * from "./context-provider.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./compiled-value.js";
2
2
  export * from "./capabilities/invokable.js";
3
3
  export * from "./ref.js";
4
+ export * from "./invoke-step.js";
4
5
  export * from "./capabilities/provider.js";
5
6
  export * from "./capabilities/runnable.js";
6
7
  export * from "./context-provider.js";
@@ -0,0 +1,78 @@
1
+ import type { Invocable } from "./capabilities/invokable.js";
2
+ import type { KindRef, ScopeContext } from "./ref.js";
3
+ import type { ResourceInstance } from "./resource-instance.js";
4
+ /** Retry policy for a single invoke step, passed through to `ctx.invoke`. */
5
+ export interface InvokeStepRetry {
6
+ attempts?: number;
7
+ delay?: string;
8
+ }
9
+ /**
10
+ * The canonical leaf step shared by the kernel's boot `targets` runner and the
11
+ * `Run.Sequence` controller. `invoke` carries a resolved `{ kind, name }` ref
12
+ * (or a pre-resolved instance once Phase 5 injection / inline resolution ran).
13
+ */
14
+ export interface InvokeStep {
15
+ name: string;
16
+ when?: string;
17
+ invoke: KindRef<Invocable> | Invocable;
18
+ inputs?: Record<string, unknown>;
19
+ retry?: InvokeStepRetry;
20
+ }
21
+ /** An inline flat invoke step on an Application's `targets`. Same as an
22
+ * `InvokeStep` but `name` is optional (only needed for `steps.<name>.result`
23
+ * plumbing; the boot runner synthesizes one when omitted) and `retry` is not
24
+ * supported — the boot invoke path takes no retry options, so it is omitted
25
+ * from the surface rather than silently ignored. */
26
+ export interface InlineInvokeTarget {
27
+ name?: string;
28
+ when?: string;
29
+ invoke: KindRef<Invocable> | Invocable;
30
+ inputs?: Record<string, unknown>;
31
+ }
32
+ /** A single Application `targets` entry. The kernel boot runner dispatches by
33
+ * shape: a bare string or resolved `{ kind, name }` runs a Runnable/Service;
34
+ * `{ ref, when? }` is a guarded run (ref a bare name or a resolved `!ref`);
35
+ * `{ invoke, ... }` is an inline invoke step executed via `executeInvokeStep`. */
36
+ export type BootTarget = string | {
37
+ kind: string;
38
+ name: string;
39
+ } | {
40
+ ref: string | {
41
+ kind: string;
42
+ name: string;
43
+ };
44
+ when?: string;
45
+ } | InlineInvokeTarget;
46
+ /**
47
+ * The context methods the leaf composes. Satisfied structurally by
48
+ * `ResourceContext` (Run.Sequence) and by a kernel-side adapter over the root
49
+ * module context (boot `targets`). The leaf needs nothing else from the kernel.
50
+ */
51
+ export interface InvokeStepContext {
52
+ expandValue(value: any, context: Record<string, any>): any;
53
+ invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
54
+ invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs): Promise<any>;
55
+ /** Resolve a cross-module exported instance (`!ref Alias.name`) to its live instance.
56
+ * Optional — providers that pre-resolve cross-module refs before reaching the leaf
57
+ * (e.g. the boot-target runner) may omit it. */
58
+ resolveImportedInstance?(alias: string, name: string): ResourceInstance | undefined;
59
+ }
60
+ /**
61
+ * Per-run state threaded through the leaf. `steps` is the result accumulator
62
+ * (mutated in place); `cel` carries extra CEL variables (e.g. `error` inside a
63
+ * Run.Sequence catch) and is empty at boot; `scope` is present only inside a
64
+ * Run.Sequence `with:` scope.
65
+ */
66
+ export interface InvokeStepState {
67
+ steps: Record<string, unknown>;
68
+ cel?: Record<string, unknown>;
69
+ scope?: ScopeContext;
70
+ }
71
+ /**
72
+ * Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
73
+ * and invoke the target, then record `steps[step.name] = { result }`. Knows
74
+ * nothing about control flow — `if`/`while`/`switch`/`try` are the caller's
75
+ * concern.
76
+ */
77
+ export declare function executeInvokeStep(step: InvokeStep, ctx: InvokeStepContext, state: InvokeStepState): Promise<void>;
78
+ //# sourceMappingURL=invoke-step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-step.d.ts","sourceRoot":"","sources":["../src/invoke-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb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ACjD,uBAAuB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;CACrF;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,IAAI,CAAC,CAgCf"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
3
+ * and invoke the target, then record `steps[step.name] = { result }`. Knows
4
+ * nothing about control flow — `if`/`while`/`switch`/`try` are the caller's
5
+ * concern.
6
+ */
7
+ export async function executeInvokeStep(step, ctx, state) {
8
+ const cel = { steps: state.steps, ...state.cel };
9
+ if (step.when !== undefined && !ctx.expandValue(step.when, cel))
10
+ return;
11
+ const inputs = ctx.expandValue(step.inputs ?? {}, cel);
12
+ const raw = step.invoke;
13
+ let result;
14
+ if (raw && typeof raw.invoke === "function") {
15
+ result = await raw.invoke(inputs);
16
+ }
17
+ else {
18
+ const ref = raw;
19
+ if (ref.alias && ref.alias !== "Self") {
20
+ // Cross-module exported instance: resolve into the owning import's context and invoke
21
+ // the live instance directly — works whether or not the step runs inside a `with:`
22
+ // scope (a plain `steps` list has no scope, so name lookup in the local context fails).
23
+ const instance = ctx.resolveImportedInstance?.(ref.alias, ref.name);
24
+ if (!instance) {
25
+ throw new Error(`Cross-module reference '${ref.alias}.${ref.name}' did not resolve to an exported instance.`);
26
+ }
27
+ result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
28
+ }
29
+ else if (state.scope) {
30
+ const instance = state.scope.getInstance(ref.name);
31
+ result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
32
+ }
33
+ else {
34
+ result = await ctx.invoke(ref.kind, ref.name, inputs, { retry: step.retry });
35
+ }
36
+ }
37
+ state.steps[step.name] = { result };
38
+ }
@@ -1,6 +1,8 @@
1
1
  import type { Invocable } from "./capabilities/invokable.js";
2
2
  import type { ControllerPolicy } from "./controller-policy.js";
3
3
  import type { EvaluationContext } from "./evaluation-context.js";
4
+ import type { BootTarget } from "./invoke-step.js";
5
+ import type { ResourceInstance } from "./resource-instance.js";
4
6
  /**
5
7
  * Public contract for a persistent, module-scoped context.
6
8
  *
@@ -18,12 +20,21 @@ export interface ModuleContext extends EvaluationContext {
18
20
  /** True if `alias` was registered via `registerImport()` on this module. */
19
21
  hasImport(alias: string): boolean;
20
22
  setVariables(vars: Record<string, unknown>): void;
21
- setTargets(vars: string[]): void;
23
+ setTargets(vars: BootTarget[]): void;
22
24
  setSecrets(secrets: Record<string, unknown>): void;
23
25
  setResource(name: string, props: Record<string, unknown>): void;
24
26
  setControllerPolicy(policy: ControllerPolicy | undefined): void;
25
27
  getControllerPolicy(): ControllerPolicy | undefined;
26
28
  registerImport(alias: string, targetModule: string, kinds: string[]): void;
29
+ /** Resolve a cross-module exported-instance reference `Alias.name` to its `{kind, name}`
30
+ * ref (canonical kind), gated by the import's `exports.resources`. Returns undefined when
31
+ * the alias is unknown, the name isn't exported, or the import hasn't initialized yet. */
32
+ resolveImportedRef(alias: string, name: string): {
33
+ kind: string;
34
+ name: string;
35
+ } | undefined;
36
+ /** Resolve a cross-module exported-instance reference `Alias.name` to its live instance. */
37
+ resolveImportedInstance(alias: string, name: string): ResourceInstance | undefined;
27
38
  getInstance(name: string): unknown;
28
39
  getInvocable<TInput = Record<string, any>, TOutput = any>(name: string): Invocable<TInput, TOutput>;
29
40
  resolveKind(kind: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"module-context.d.ts","sourceRoot":"","sources":["../src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,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAChE,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAC;IAChE,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAAC;IAEpD,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3E;;+FAE2F;IAC3F,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC5F,4FAA4F;IAC5F,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IACnF,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,EACtD,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
package/dist/ref.d.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import type { ResourceInstance } from "./resource-instance.js";
2
2
  /** Marker type for x-telo-ref fields. Carries the live instance type at the TypeScript level;
3
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. */
4
+ * T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance.
5
+ *
6
+ * `alias` is set only for cross-module references resolved from `!ref Alias.name` against an
7
+ * imported library's `exports.resources`. It names the import alias whose child context owns
8
+ * the target instance, so Phase 5 injection can resolve into that context rather than the
9
+ * referencing resource's own. Absent (or `"Self"`) means a local reference. */
5
10
  export interface KindRef<T = ResourceInstance> {
6
11
  readonly kind: string;
7
12
  readonly name: string;
13
+ readonly alias?: string;
8
14
  readonly __type?: T;
9
15
  }
10
16
  /** Marker type for x-telo-scope fields. Has no runtime value — used only as a discriminant
@@ -14,11 +20,13 @@ export interface ScopeRef {
14
20
  }
15
21
  /** Gives a controller access to the resources initialized within a scope. */
16
22
  export interface ScopeContext {
17
- /** Returns the initialized instance for the given name.
23
+ /** Returns the initialized instance for the given name. With a non-`Self` `alias`,
24
+ * resolves a cross-module exported instance (`!ref Alias.name`) into the owning
25
+ * import's child context instead of the scope-local / outer resources.
18
26
  * Throws synchronously if the name was not declared in the scope —
19
27
  * this is always a programming error; all scope members are statically
20
28
  * validated in Phase 3 before the kernel ever reaches runtime. */
21
- getInstance(name: string): ResourceInstance;
29
+ getInstance(name: string, alias?: string): ResourceInstance;
22
30
  }
23
31
  /** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
24
32
  * The controller calls run() to open the scope, execute work, and tear it down. */
package/dist/ref.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;mGAEmG;AACnG,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,gBAAgB;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;CACrB;AAED;6DAC6D;AAC7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;CACxB;AAED,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B;;;uEAGmE;IACnE,WAAW,CA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K - Public API for Telo module authors.",
5
5
  "keywords": [
6
6
  "telo",
@@ -32,12 +32,14 @@ export type InstanceFactory = (
32
32
  * fields of the resource config before the controller sees them in init().
33
33
  *
34
34
  * @param resource The resource manifest whose config fields may be mutated in-place.
35
- * @param getInstance Looks up an already-initialized instance by resource name.
35
+ * @param getInstance Looks up an already-initialized instance by resource name. With a
36
+ * non-`Self` `alias`, resolves a cross-module reference into that
37
+ * import's published exported instances instead of the local context.
36
38
  * Returns undefined when the named resource is not yet initialized.
37
39
  */
38
40
  export type PreInitHook = (
39
41
  resource: ResourceManifest,
40
- getInstance: (name: string) => ResourceInstance | undefined,
42
+ getInstance: (name: string, alias?: string) => ResourceInstance | undefined,
41
43
  ) => void;
42
44
 
43
45
  /** Canonical key for a resource instance: "<module>.<kind>.<name>" */
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./compiled-value.js";
2
2
  export * from "./capabilities/invokable.js";
3
3
  export * from "./ref.js";
4
+ export * from "./invoke-step.js";
4
5
  export * from "./capabilities/provider.js";
5
6
  export * from "./capabilities/runnable.js";
6
7
  export * from "./context-provider.js";
@@ -0,0 +1,120 @@
1
+ import type { Invocable } from "./capabilities/invokable.js";
2
+ import type { KindRef, ScopeContext } from "./ref.js";
3
+ import type { ResourceInstance } from "./resource-instance.js";
4
+
5
+ /** Retry policy for a single invoke step, passed through to `ctx.invoke`. */
6
+ export interface InvokeStepRetry {
7
+ attempts?: number;
8
+ delay?: string;
9
+ }
10
+
11
+ /**
12
+ * The canonical leaf step shared by the kernel's boot `targets` runner and the
13
+ * `Run.Sequence` controller. `invoke` carries a resolved `{ kind, name }` ref
14
+ * (or a pre-resolved instance once Phase 5 injection / inline resolution ran).
15
+ */
16
+ export interface InvokeStep {
17
+ name: string;
18
+ when?: string;
19
+ invoke: KindRef<Invocable> | Invocable;
20
+ inputs?: Record<string, unknown>;
21
+ retry?: InvokeStepRetry;
22
+ }
23
+
24
+ /** An inline flat invoke step on an Application's `targets`. Same as an
25
+ * `InvokeStep` but `name` is optional (only needed for `steps.<name>.result`
26
+ * plumbing; the boot runner synthesizes one when omitted) and `retry` is not
27
+ * supported — the boot invoke path takes no retry options, so it is omitted
28
+ * from the surface rather than silently ignored. */
29
+ export interface InlineInvokeTarget {
30
+ name?: string;
31
+ when?: string;
32
+ invoke: KindRef<Invocable> | Invocable;
33
+ inputs?: Record<string, unknown>;
34
+ }
35
+
36
+ /** A single Application `targets` entry. The kernel boot runner dispatches by
37
+ * shape: a bare string or resolved `{ kind, name }` runs a Runnable/Service;
38
+ * `{ ref, when? }` is a guarded run (ref a bare name or a resolved `!ref`);
39
+ * `{ invoke, ... }` is an inline invoke step executed via `executeInvokeStep`. */
40
+ export type BootTarget =
41
+ | string
42
+ | { kind: string; name: string }
43
+ | { ref: string | { kind: string; name: string }; when?: string }
44
+ | InlineInvokeTarget;
45
+
46
+ /**
47
+ * The context methods the leaf composes. Satisfied structurally by
48
+ * `ResourceContext` (Run.Sequence) and by a kernel-side adapter over the root
49
+ * module context (boot `targets`). The leaf needs nothing else from the kernel.
50
+ */
51
+ export interface InvokeStepContext {
52
+ expandValue(value: any, context: Record<string, any>): any;
53
+ invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
54
+ invokeResolved<TInputs>(
55
+ kind: string,
56
+ name: string,
57
+ instance: ResourceInstance,
58
+ inputs: TInputs,
59
+ ): Promise<any>;
60
+ /** Resolve a cross-module exported instance (`!ref Alias.name`) to its live instance.
61
+ * Optional — providers that pre-resolve cross-module refs before reaching the leaf
62
+ * (e.g. the boot-target runner) may omit it. */
63
+ resolveImportedInstance?(alias: string, name: string): ResourceInstance | undefined;
64
+ }
65
+
66
+ /**
67
+ * Per-run state threaded through the leaf. `steps` is the result accumulator
68
+ * (mutated in place); `cel` carries extra CEL variables (e.g. `error` inside a
69
+ * Run.Sequence catch) and is empty at boot; `scope` is present only inside a
70
+ * Run.Sequence `with:` scope.
71
+ */
72
+ export interface InvokeStepState {
73
+ steps: Record<string, unknown>;
74
+ cel?: Record<string, unknown>;
75
+ scope?: ScopeContext;
76
+ }
77
+
78
+ /**
79
+ * Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
80
+ * and invoke the target, then record `steps[step.name] = { result }`. Knows
81
+ * nothing about control flow — `if`/`while`/`switch`/`try` are the caller's
82
+ * concern.
83
+ */
84
+ export async function executeInvokeStep(
85
+ step: InvokeStep,
86
+ ctx: InvokeStepContext,
87
+ state: InvokeStepState,
88
+ ): Promise<void> {
89
+ const cel = { steps: state.steps, ...state.cel };
90
+ if (step.when !== undefined && !ctx.expandValue(step.when, cel)) return;
91
+
92
+ const inputs = ctx.expandValue(step.inputs ?? {}, cel) as Record<string, unknown>;
93
+ const raw = step.invoke as unknown;
94
+ let result: unknown;
95
+
96
+ if (raw && typeof (raw as Invocable).invoke === "function") {
97
+ result = await (raw as Invocable).invoke(inputs);
98
+ } else {
99
+ const ref = raw as KindRef<Invocable>;
100
+ if (ref.alias && ref.alias !== "Self") {
101
+ // Cross-module exported instance: resolve into the owning import's context and invoke
102
+ // the live instance directly — works whether or not the step runs inside a `with:`
103
+ // scope (a plain `steps` list has no scope, so name lookup in the local context fails).
104
+ const instance = ctx.resolveImportedInstance?.(ref.alias, ref.name);
105
+ if (!instance) {
106
+ throw new Error(
107
+ `Cross-module reference '${ref.alias}.${ref.name}' did not resolve to an exported instance.`,
108
+ );
109
+ }
110
+ result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
111
+ } else if (state.scope) {
112
+ const instance = state.scope.getInstance(ref.name) as unknown as ResourceInstance;
113
+ result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
114
+ } else {
115
+ result = await ctx.invoke(ref.kind, ref.name, inputs, { retry: step.retry });
116
+ }
117
+ }
118
+
119
+ state.steps[step.name] = { result };
120
+ }
@@ -1,6 +1,8 @@
1
1
  import type { Invocable } from "./capabilities/invokable.js";
2
2
  import type { ControllerPolicy } from "./controller-policy.js";
3
3
  import type { EvaluationContext } from "./evaluation-context.js";
4
+ import type { BootTarget } from "./invoke-step.js";
5
+ import type { ResourceInstance } from "./resource-instance.js";
4
6
 
5
7
  /**
6
8
  * Public contract for a persistent, module-scoped context.
@@ -21,13 +23,19 @@ export interface ModuleContext extends EvaluationContext {
21
23
  hasImport(alias: string): boolean;
22
24
 
23
25
  setVariables(vars: Record<string, unknown>): void;
24
- setTargets(vars: string[]): void;
26
+ setTargets(vars: BootTarget[]): void;
25
27
  setSecrets(secrets: Record<string, unknown>): void;
26
28
  setResource(name: string, props: Record<string, unknown>): void;
27
29
  setControllerPolicy(policy: ControllerPolicy | undefined): void;
28
30
  getControllerPolicy(): ControllerPolicy | undefined;
29
31
 
30
32
  registerImport(alias: string, targetModule: string, kinds: string[]): void;
33
+ /** Resolve a cross-module exported-instance reference `Alias.name` to its `{kind, name}`
34
+ * ref (canonical kind), gated by the import's `exports.resources`. Returns undefined when
35
+ * the alias is unknown, the name isn't exported, or the import hasn't initialized yet. */
36
+ resolveImportedRef(alias: string, name: string): { kind: string; name: string } | undefined;
37
+ /** Resolve a cross-module exported-instance reference `Alias.name` to its live instance. */
38
+ resolveImportedInstance(alias: string, name: string): ResourceInstance | undefined;
31
39
  getInstance(name: string): unknown;
32
40
  getInvocable<TInput = Record<string, any>, TOutput = any>(
33
41
  name: string,
package/src/ref.ts CHANGED
@@ -2,10 +2,16 @@ import type { ResourceInstance } from "./resource-instance.js";
2
2
 
3
3
  /** Marker type for x-telo-ref fields. Carries the live instance type at the TypeScript level;
4
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. */
5
+ * T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance.
6
+ *
7
+ * `alias` is set only for cross-module references resolved from `!ref Alias.name` against an
8
+ * imported library's `exports.resources`. It names the import alias whose child context owns
9
+ * the target instance, so Phase 5 injection can resolve into that context rather than the
10
+ * referencing resource's own. Absent (or `"Self"`) means a local reference. */
6
11
  export interface KindRef<T = ResourceInstance> {
7
12
  readonly kind: string;
8
13
  readonly name: string;
14
+ readonly alias?: string;
9
15
  readonly __type?: T;
10
16
  }
11
17
 
@@ -17,11 +23,13 @@ export interface ScopeRef {
17
23
 
18
24
  /** Gives a controller access to the resources initialized within a scope. */
19
25
  export interface ScopeContext {
20
- /** Returns the initialized instance for the given name.
26
+ /** Returns the initialized instance for the given name. With a non-`Self` `alias`,
27
+ * resolves a cross-module exported instance (`!ref Alias.name`) into the owning
28
+ * import's child context instead of the scope-local / outer resources.
21
29
  * Throws synchronously if the name was not declared in the scope —
22
30
  * this is always a programming error; all scope members are statically
23
31
  * validated in Phase 3 before the kernel ever reaches runtime. */
24
- getInstance(name: string): ResourceInstance;
32
+ getInstance(name: string, alias?: string): ResourceInstance;
25
33
  }
26
34
 
27
35
  /** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
@@ -1,8 +0,0 @@
1
- import type { CapabilityDefinition } from "./types.js";
2
- /**
3
- * Factory that wires the declarative `expand` config on a CapabilityDefinition
4
- * into the `onManifest` and `onInvoke` lifecycle hooks. The kernel only ever
5
- * calls these hooks — it has no knowledge of the `expand` config.
6
- */
7
- export declare function createCapability(def: CapabilityDefinition): CapabilityDefinition;
8
- //# sourceMappingURL=capability-definition.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capability-definition.d.ts","sourceRoot":"","sources":["../src/capability-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGvD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,oBAAoB,GAAG,oBAAoB,CAwBhF"}
@@ -1,21 +0,0 @@
1
- /**
2
- * Factory that wires the declarative `expand` config on a CapabilityDefinition
3
- * into the `onManifest` and `onInvoke` lifecycle hooks. The kernel only ever
4
- * calls these hooks — it has no knowledge of the `expand` config.
5
- */
6
- export function createCapability(def) {
7
- const compile = def.expand?.compile ?? [];
8
- const runtime = def.expand?.runtime ?? [];
9
- return {
10
- ...def,
11
- onManifest: compile.length
12
- ? (manifest, ctx) => ctx.expandPaths(manifest, compile, runtime)
13
- : def.onManifest,
14
- onInvoke: runtime.length
15
- ? async (instance, inputs, ctx) => {
16
- const expanded = ctx.moduleContext.expandPaths(inputs, runtime);
17
- return instance.invoke(expanded);
18
- }
19
- : def.onInvoke,
20
- };
21
- }
@@ -1,3 +0,0 @@
1
- import { Environment } from "@marcbachmann/cel-js";
2
- export declare const celEnvironment: Environment;
3
- //# sourceMappingURL=cel-environment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cel-environment.d.ts","sourceRoot":"","sources":["../src/cel-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,eAAO,MAAM,cAAc,aAWvB,CAAC"}
@@ -1,13 +0,0 @@
1
- import { Environment } from "@marcbachmann/cel-js";
2
- export const celEnvironment = new Environment({ unlistedVariablesAreDyn: true })
3
- .registerFunction("join(list, string): string", (list, sep) => list.map(String).join(sep))
4
- .registerFunction("keys(map): list", (map) => {
5
- if (map instanceof Map)
6
- return [...map.keys()];
7
- return Object.keys(map);
8
- })
9
- .registerFunction("values(map): list", (map) => {
10
- if (map instanceof Map)
11
- return [...map.values()];
12
- return Object.values(map);
13
- });
@@ -1,13 +0,0 @@
1
- import { EvaluationContext } from "./evaluation-context.js";
2
- import { ModuleContext } from "./module-context.js";
3
- /**
4
- * The ephemeral, per-trigger context layer. Merges a ModuleContext with
5
- * arbitrary execution-time properties (e.g. { request, inputs } for HTTP;
6
- * any shape is valid — determined by the trigger type).
7
- *
8
- * Execution props overlay the module namespaces on key conflict.
9
- */
10
- export declare class ExecutionContext extends EvaluationContext {
11
- constructor(moduleCtx: ModuleContext, execProps: Record<string, unknown>);
12
- }
13
- //# sourceMappingURL=execution-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../src/execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB;gBACzC,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASzE"}
@@ -1,13 +0,0 @@
1
- import { EvaluationContext } from "./evaluation-context.js";
2
- /**
3
- * The ephemeral, per-trigger context layer. Merges a ModuleContext with
4
- * arbitrary execution-time properties (e.g. { request, inputs } for HTTP;
5
- * any shape is valid — determined by the trigger type).
6
- *
7
- * Execution props overlay the module namespaces on key conflict.
8
- */
9
- export class ExecutionContext extends EvaluationContext {
10
- constructor(moduleCtx, execProps) {
11
- super(moduleCtx.source, Object.assign(Object.create(null), moduleCtx.context, execProps), moduleCtx.createInstance, moduleCtx.secretValues, moduleCtx.emit);
12
- }
13
- }