@telorun/kernel 0.60.0 → 0.62.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.
Files changed (85) hide show
  1. package/dist/bundle/module-artifact.d.ts +28 -2
  2. package/dist/bundle/module-artifact.d.ts.map +1 -1
  3. package/dist/bundle/module-artifact.js +36 -9
  4. package/dist/bundle/module-artifact.js.map +1 -1
  5. package/dist/controller-loader.d.ts +7 -4
  6. package/dist/controller-loader.d.ts.map +1 -1
  7. package/dist/controller-loader.js.map +1 -1
  8. package/dist/controller-loaders/bundle-loader.d.ts.map +1 -1
  9. package/dist/controller-loaders/bundle-loader.js +9 -4
  10. package/dist/controller-loaders/bundle-loader.js.map +1 -1
  11. package/dist/controller-loaders/npm-loader.d.ts.map +1 -1
  12. package/dist/controller-loaders/npm-loader.js +62 -10
  13. package/dist/controller-loaders/npm-loader.js.map +1 -1
  14. package/dist/controllers/resource-definition/resource-inherited-controller.d.ts.map +1 -1
  15. package/dist/controllers/resource-definition/resource-inherited-controller.js +57 -10
  16. package/dist/controllers/resource-definition/resource-inherited-controller.js.map +1 -1
  17. package/dist/controllers/type/json-schema-controller.d.ts +8 -0
  18. package/dist/controllers/type/json-schema-controller.d.ts.map +1 -0
  19. package/dist/controllers/type/json-schema-controller.js +91 -0
  20. package/dist/controllers/type/json-schema-controller.js.map +1 -0
  21. package/dist/evaluation-context.d.ts +5 -0
  22. package/dist/evaluation-context.d.ts.map +1 -1
  23. package/dist/evaluation-context.js +63 -33
  24. package/dist/evaluation-context.js.map +1 -1
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/init-failure-diagnostics.d.ts +61 -0
  30. package/dist/init-failure-diagnostics.d.ts.map +1 -0
  31. package/dist/init-failure-diagnostics.js +141 -0
  32. package/dist/init-failure-diagnostics.js.map +1 -0
  33. package/dist/invocation-contract-binding.d.ts +105 -0
  34. package/dist/invocation-contract-binding.d.ts.map +1 -0
  35. package/dist/invocation-contract-binding.js +296 -0
  36. package/dist/invocation-contract-binding.js.map +1 -0
  37. package/dist/kernel.d.ts +17 -0
  38. package/dist/kernel.d.ts.map +1 -1
  39. package/dist/kernel.js +76 -25
  40. package/dist/kernel.js.map +1 -1
  41. package/dist/module-context.d.ts.map +1 -1
  42. package/dist/module-context.js +21 -0
  43. package/dist/module-context.js.map +1 -1
  44. package/dist/resource-context.d.ts +45 -0
  45. package/dist/resource-context.d.ts.map +1 -1
  46. package/dist/resource-context.js +79 -0
  47. package/dist/resource-context.js.map +1 -1
  48. package/dist/schema-compiled-values.d.ts +9 -1
  49. package/dist/schema-compiled-values.d.ts.map +1 -1
  50. package/dist/schema-compiled-values.js +55 -16
  51. package/dist/schema-compiled-values.js.map +1 -1
  52. package/dist/schema-validator.d.ts.map +1 -1
  53. package/dist/schema-validator.js +15 -1
  54. package/dist/schema-validator.js.map +1 -1
  55. package/dist/static-analysis-diagnostics.d.ts +19 -0
  56. package/dist/static-analysis-diagnostics.d.ts.map +1 -0
  57. package/dist/static-analysis-diagnostics.js +52 -0
  58. package/dist/static-analysis-diagnostics.js.map +1 -0
  59. package/dist/transports/oci/oci-transport.d.ts +17 -0
  60. package/dist/transports/oci/oci-transport.d.ts.map +1 -1
  61. package/dist/transports/oci/oci-transport.js +33 -8
  62. package/dist/transports/oci/oci-transport.js.map +1 -1
  63. package/dist/transports/transport-registry.d.ts +6 -4
  64. package/dist/transports/transport-registry.d.ts.map +1 -1
  65. package/dist/transports/transport-registry.js +6 -4
  66. package/dist/transports/transport-registry.js.map +1 -1
  67. package/package.json +4 -4
  68. package/src/bundle/module-artifact.ts +54 -12
  69. package/src/controller-loader.ts +7 -4
  70. package/src/controller-loaders/bundle-loader.ts +9 -4
  71. package/src/controller-loaders/npm-loader.ts +75 -13
  72. package/src/controllers/resource-definition/resource-inherited-controller.ts +69 -10
  73. package/src/controllers/type/json-schema-controller.ts +114 -0
  74. package/src/evaluation-context.ts +81 -32
  75. package/src/index.ts +3 -1
  76. package/src/init-failure-diagnostics.ts +169 -0
  77. package/src/invocation-contract-binding.ts +392 -0
  78. package/src/kernel.ts +95 -23
  79. package/src/module-context.ts +27 -0
  80. package/src/resource-context.ts +81 -0
  81. package/src/schema-compiled-values.ts +55 -15
  82. package/src/schema-validator.ts +15 -1
  83. package/src/static-analysis-diagnostics.ts +51 -0
  84. package/src/transports/oci/oci-transport.ts +34 -8
  85. package/src/transports/transport-registry.ts +6 -4
@@ -0,0 +1,296 @@
1
+ import { defaultBearingPaths, effectiveContractField, withStreamPropertiesSkipped, } from "@telorun/analyzer";
2
+ import { ERR_CONTRACT_UNRESOLVABLE, ERR_INPUT_INVALID, ERR_OUTPUT_INVALID, InvokeError, } from "@telorun/sdk";
3
+ const CONTRACT_ERROR = {
4
+ inputType: ERR_INPUT_INVALID,
5
+ outputType: ERR_OUTPUT_INVALID,
6
+ };
7
+ /**
8
+ * Resolve one direction of a resource's contract to a bound validator.
9
+ *
10
+ * The declaration is layered instance-manifest → nearest along `extends` (see
11
+ * `effectiveContractField` — nearest wins, contracts never merge), then compiled.
12
+ *
13
+ * A NAMED reference (`inputType: RequestShape`, or a `!ref` to a type) is
14
+ * compiled by name so it keeps the CEL `rules:` registered alongside it, which a
15
+ * plain schema copy would drop. Everything else is compiled from the resolved
16
+ * schema — inline `{kind, schema}` and raw forms carry no rules, and resolving
17
+ * first is what lets a `{ $ref: "telo://Self/X" }` contract compile at all
18
+ * (`resolveTypeSchema` follows it through the kernel's registry, which AJV
19
+ * cannot).
20
+ *
21
+ * The resolved schema is stripped of `x-telo-stream` properties first: a live
22
+ * `Stream` in a declared slot is not data to be traversed, the same defect as
23
+ * `stripCompiledValues` walking a live instance in a ref slot. Streams travel in
24
+ * both directions (`Codec.Encoder` marks `input` on its `inputType` and requires
25
+ * it), so the skip is not one-directional.
26
+ *
27
+ * WHICH declaration applies is decided here, at create time — that is a fact
28
+ * about the manifest. COMPILING it is deferred to first dispatch and memoized: a
29
+ * contract may reference a named `telo#Type` whose `Type.JsonSchema` resource
30
+ * initializes later in the same multi-pass loop, and resolving it eagerly would
31
+ * make every contract-declaring kind depend on type-registration order. Nothing
32
+ * can dispatch before the loop finishes, so first-use is always late enough.
33
+ */
34
+ /** True when a type field names a registered `telo#Type` — a bare name, or the
35
+ * `{kind, name}` object a `!ref` normalizes to. Only these carry CEL `rules:`,
36
+ * so only these are worth compiling by name rather than from their schema. */
37
+ function isNamedTypeReference(declared) {
38
+ if (typeof declared === "string")
39
+ return true;
40
+ if (!declared || typeof declared !== "object")
41
+ return false;
42
+ const ref = declared;
43
+ return typeof ref.name === "string" && !(ref.schema && typeof ref.schema === "object");
44
+ }
45
+ export function resolveBoundContract(direction, manifest, definition, resolveDef, factory) {
46
+ const own = manifest[direction];
47
+ const declared = own !== undefined && own !== null
48
+ ? own
49
+ : effectiveContractField(definition, resolveDef, direction);
50
+ if (declared === undefined || declared === null)
51
+ return undefined;
52
+ let compiled;
53
+ let paths;
54
+ const resolve = () => {
55
+ if (compiled !== undefined)
56
+ return compiled;
57
+ const schema = factory.schemaOf(declared);
58
+ if (!schema) {
59
+ // A declared contract that resolves to nothing is a manifest fault — a
60
+ // named type that never registered — and it MUST NOT degrade to
61
+ // "unvalidated". Silently disabling enforcement is the failure mode
62
+ // nobody notices: every later call passes because nothing is checking.
63
+ throw new InvokeError(ERR_CONTRACT_UNRESOLVABLE, `declared \`${direction}\` could not be resolved to a schema: ${describeDeclaration(declared)}. ` +
64
+ `The type is not registered, so the contract cannot be enforced.`);
65
+ }
66
+ const stripped = withStreamPropertiesSkipped(schema, factory.resolveRef);
67
+ paths = defaultBearingPaths(stripped, factory.resolveRef);
68
+ // Compile by NAME whenever the declaration is one, so the type's CEL
69
+ // `rules:` are composed in — including when a stream had to be stripped, in
70
+ // which case the stream-bearing properties are dropped from the schema the
71
+ // named validator sees rather than the reference being abandoned.
72
+ compiled = !isNamedTypeReference(declared)
73
+ ? factory(stripped)
74
+ : stripped === schema
75
+ ? factory(declared)
76
+ : factory.withRules(nameOf(declared), stripped);
77
+ return compiled;
78
+ };
79
+ return {
80
+ direction,
81
+ validate: (value) => resolve().validate(value),
82
+ defaultPaths: () => {
83
+ resolve();
84
+ return paths ?? [];
85
+ },
86
+ };
87
+ }
88
+ const nameOf = (declared) => typeof declared === "string"
89
+ ? declared
90
+ : declared?.name;
91
+ const describeDeclaration = (declared) => typeof declared === "string" ? `'${declared}'` : JSON.stringify(declared);
92
+ /**
93
+ * A copy of `value` deep along exactly the paths a default can be written to and
94
+ * shared everywhere else.
95
+ *
96
+ * A flat shallow copy would not do: AJV's `useDefaults` writes at every level it
97
+ * finds a default, so a nested default would mutate the structure the caller
98
+ * still holds. Bounded by the schema's defaults rather than by the size of the
99
+ * payload — a contract declaring no defaults copies one level and nothing more.
100
+ */
101
+ export function copyForDefaults(value, paths) {
102
+ if (!value || typeof value !== "object")
103
+ return value;
104
+ let out = shallowCopy(value);
105
+ for (const path of paths) {
106
+ // The leaf is what gets written; every CONTAINER above it is what must not
107
+ // be shared. An `[]` segment fans out: the default lands in each element, so
108
+ // the array and every element on the path have to be copied too — bailing
109
+ // there would leave `rows[0]` shared and let a fill mutate the caller's data.
110
+ out = copyAlong(out, path.slice(0, -1));
111
+ }
112
+ return out;
113
+ }
114
+ const shallowCopy = (value) => Array.isArray(value) ? [...value] : { ...value };
115
+ function copyAlong(node, segments) {
116
+ if (!node || typeof node !== "object")
117
+ return node;
118
+ if (segments.length === 0)
119
+ return node;
120
+ const [head, ...rest] = segments;
121
+ if (head === "[]") {
122
+ if (!Array.isArray(node))
123
+ return node;
124
+ return node.map((item) => item && typeof item === "object" ? copyAlong(shallowCopy(item), rest) : item);
125
+ }
126
+ const container = node;
127
+ const child = container[head];
128
+ if (!child || typeof child !== "object")
129
+ return node;
130
+ container[head] = copyAlong(shallowCopy(child), rest);
131
+ return node;
132
+ }
133
+ /**
134
+ * Raise a contract violation as a structured {@link InvokeError}.
135
+ *
136
+ * Structured rather than a plain error because the run engine assigns
137
+ * `INTERNAL_ERROR` to anything that is not an `InvokeError` — a contract
138
+ * violation would then reach a `catch` block indistinguishable from a crash, and
139
+ * an author could neither match it nor rethrow it faithfully. These are ambient
140
+ * kernel codes: catchable by name, and never counted against a kind's own
141
+ * `throws:` union.
142
+ *
143
+ * The message names the target, the direction, and the offending detail, because
144
+ * a caller several steps away otherwise cannot tell which boundary rejected the
145
+ * value or which side supplied it.
146
+ */
147
+ export function contractViolation(direction, describeTarget, cause) {
148
+ // A type's CEL `rules:` raise the author's OWN code — that is the whole point
149
+ // of declaring one, and `modules/type` documents rule codes as catchable.
150
+ // Only a structural schema failure is the ambient contract violation.
151
+ //
152
+ // Re-raised as a STRUCTURED error carrying that code: the rule itself throws a
153
+ // `RuntimeError`, which has a code but not the marker a catch block matches
154
+ // on, so it used to reach `catch` as the generic plain-failure code — the
155
+ // documented behaviour never actually worked. Wrapping preserves the code and
156
+ // makes it match.
157
+ const ruleCode = ruleViolationCode(cause);
158
+ if (ruleCode) {
159
+ return new InvokeError(ruleCode, cause.message, undefined, { cause });
160
+ }
161
+ const side = direction === "inputType" ? "inputs" : "result";
162
+ const detail = cause instanceof Error ? cause.message : String(cause);
163
+ return new InvokeError(CONTRACT_ERROR[direction], `${describeTarget()}: ${side} do not satisfy the declared ${direction}: ${detail}`, undefined, { cause });
164
+ }
165
+ /** Codes the validator itself raises for a STRUCTURAL failure. Anything else
166
+ * carrying a code came from a declared rule and belongs to its author. */
167
+ const STRUCTURAL_VALIDATION_CODES = new Set([
168
+ "ERR_RESOURCE_SCHEMA_VALIDATION_FAILED",
169
+ "ERR_TYPE_NOT_FOUND",
170
+ ]);
171
+ function ruleViolationCode(cause) {
172
+ const code = cause?.code;
173
+ if (typeof code !== "string" || code.length === 0)
174
+ return undefined;
175
+ return STRUCTURAL_VALIDATION_CODES.has(code) ? undefined : code;
176
+ }
177
+ /**
178
+ * Bind `invoke()` and `provide()` in place.
179
+ *
180
+ * `provide()` takes no caller arguments, so it has no input side, but it returns
181
+ * a value against a declared `outputType` and that result is validated exactly as
182
+ * an invocable's is — same path, same stream skip, same ambient error code.
183
+ * `run()` is bound to nothing: parameterless and void, there is nothing to fill
184
+ * defaults into and no result to validate, so it is guarded statically instead.
185
+ */
186
+ export function bindContract(instance, binding) {
187
+ const { input, output, describeTarget } = binding;
188
+ if (!input && !output)
189
+ return;
190
+ if (typeof instance.invoke === "function") {
191
+ const original = instance.invoke.bind(instance);
192
+ // EVERY argument is forwarded, not just `inputs`. `invoke(inputs, ctx)`
193
+ // carries the InvokeContext — cancellation, tracing — as its second
194
+ // parameter, and a wrapper that takes only `inputs` silently drops it: a
195
+ // detached body would then never see its cancellation token and a lease
196
+ // holding across it would never be released. The contract only concerns the
197
+ // first argument; the rest belong to the caller and the callee.
198
+ instance.invoke = async (inputs, ...rest) => {
199
+ let effective = inputs;
200
+ if (input) {
201
+ effective = copyForDefaults(inputs, input.defaultPaths());
202
+ // Validate a BIGINT-NORMALIZED view, not the values themselves. CEL
203
+ // evaluates an integer literal to a BigInt, which a JSON Schema
204
+ // validator does not recognise as `integer` — so every computed integer
205
+ // reaching a declared integer input would be rejected for a reason the
206
+ // author cannot act on. The dispatched values keep their BigInts, since
207
+ // a controller may need the full 64-bit range.
208
+ const view = withBigIntsAsNumbers(effective);
209
+ try {
210
+ input.validate(view);
211
+ }
212
+ catch (error) {
213
+ throw contractViolation("inputType", describeTarget, error);
214
+ }
215
+ // Defaults are additive, so anything the validator filled into the view
216
+ // is a key the caller omitted — copy exactly those back.
217
+ effective = mergeFilledDefaults(effective, view);
218
+ }
219
+ const result = await original(effective, ...rest);
220
+ if (output) {
221
+ try {
222
+ output.validate(withBigIntsAsNumbers(result));
223
+ }
224
+ catch (error) {
225
+ throw contractViolation("outputType", describeTarget, error);
226
+ }
227
+ }
228
+ return result;
229
+ };
230
+ }
231
+ if (output && typeof instance.provide === "function") {
232
+ const original = instance.provide.bind(instance);
233
+ instance.provide = async (...args) => {
234
+ const result = await original(...args);
235
+ try {
236
+ output.validate(withBigIntsAsNumbers(result));
237
+ }
238
+ catch (error) {
239
+ throw contractViolation("outputType", describeTarget, error);
240
+ }
241
+ return result;
242
+ };
243
+ }
244
+ }
245
+ /** A structural copy with every BigInt rendered as a Number, for validation
246
+ * only. A value beyond the safe-integer range loses precision in the VIEW,
247
+ * which can only affect a bound check at the extremes; the dispatched value is
248
+ * untouched. Non-plain objects (a live `Stream`, a resource instance) pass
249
+ * through by reference — they are not data to be walked. */
250
+ export function withBigIntsAsNumbers(value) {
251
+ if (typeof value === "bigint")
252
+ return Number(value);
253
+ if (Array.isArray(value)) {
254
+ let changed = false;
255
+ const items = value.map((item) => {
256
+ const next = withBigIntsAsNumbers(item);
257
+ if (next !== item)
258
+ changed = true;
259
+ return next;
260
+ });
261
+ return changed ? items : value;
262
+ }
263
+ if (!value || typeof value !== "object")
264
+ return value;
265
+ if (Object.getPrototypeOf(value) !== Object.prototype)
266
+ return value;
267
+ let changed = false;
268
+ const out = {};
269
+ for (const [key, item] of Object.entries(value)) {
270
+ const next = withBigIntsAsNumbers(item);
271
+ if (next !== item)
272
+ changed = true;
273
+ out[key] = next;
274
+ }
275
+ return changed ? out : value;
276
+ }
277
+ /** Copy keys the validator's default-fill added to `view` back onto `target`.
278
+ * Only ADDITIONS are taken: a key already present came from the caller and its
279
+ * original (possibly BigInt) value is the one to dispatch. */
280
+ function mergeFilledDefaults(target, view) {
281
+ if (target === view)
282
+ return target;
283
+ if (!target || typeof target !== "object" || Array.isArray(target))
284
+ return target;
285
+ if (!view || typeof view !== "object" || Array.isArray(view))
286
+ return target;
287
+ const out = target;
288
+ for (const [key, filled] of Object.entries(view)) {
289
+ if (!(key in out))
290
+ out[key] = filled;
291
+ else
292
+ out[key] = mergeFilledDefaults(out[key], filled);
293
+ }
294
+ return out;
295
+ }
296
+ //# sourceMappingURL=invocation-contract-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation-contract-binding.js","sourceRo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C,GAAG,IAAI,CAAC;IAClB,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/B,CAAC;AAED;;+DAE+D;AAC/D,SAAS,mBAAmB,CAAC,MAAe,EAAE,IAAa;IACzD,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IACnC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAClF,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IAC5E,MAAM,GAAG,GAAG,MAAiC,CAAC;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAA+B,CAAC,EAAE,CAAC;QAC5E,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;;YAChC,GAAG,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/kernel.d.ts CHANGED
@@ -297,6 +297,17 @@ export declare class Kernel implements IKernel {
297
297
  * is not yet registered (retry signal).
298
298
  */
299
299
  private _createInstance;
300
+ /**
301
+ * Resolve and bind both directions of a resource's invocation contract.
302
+ *
303
+ * The declaration is layered instance-manifest → nearest along `extends`;
304
+ * contracts never merge (a call signature is not additive the way construction
305
+ * config is), so a definition that declares one fully replaces its ancestor's.
306
+ * Resolution runs in the scope that DECLARED each definition — an `extends`
307
+ * alias is lexical, and a `telo#Type` reference goes through import aliases, so
308
+ * a chain crossing module boundaries re-scopes at every hop.
309
+ */
310
+ private bindInvocationContract;
300
311
  /**
301
312
  * Create phase for an inherited (concrete-`extends`) definition's parent: runs
302
313
  * the ordinary create pipeline (controller resolution + lazy load, schema
@@ -314,6 +325,12 @@ export declare class Kernel implements IKernel {
314
325
  * field map and replaces each {kind, name} reference value (outside scope visibility
315
326
  * paths) with the live ResourceInstance returned by getInstance(name). Fields within
316
327
  * scope paths are left as {kind, name} — the controller resolves them at runtime.
328
+ *
329
+ * `owner` is the context the resource belongs to, and the scope handle built for an
330
+ * `x-telo-scope` field hangs off it rather than off the root: a `with:` block's inline
331
+ * declarations name their kinds through the import aliases of the module that DECLARED
332
+ * the resource, so a library's scoped `kind: OAuth.RedirectListener` resolves against
333
+ * that library's imports — the root has never heard of the alias.
317
334
  */
318
335
  private _injectDependencies;
319
336
  }
@@ -1 +1 @@
1
- {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../src/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAOhB,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIL,MAAM,IAAI,OAAO,EAEjB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAEhB,YAAY,EAGZ,KAAK,iBAAiB,IAAI,kBAAkB,EAC5C,KAAK,aAAa,EAElB,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,aAAa,EAA6B,MAAM,6BAA6B,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAoB7D,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAmCrC,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,GAAG,CAAC,EAAE,MA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C,IAAI,CAAC;IAS5B;;;;;;;OAOG;IACH,SAAS,IAAI,IAAI;IAKjB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAI/E,OAAO,CAAC,uBAAuB;IAe/B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,qBAAqB;IAsB7B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA4B9B;;;;;OAKG;YACW,eAAe;IA2J7B;;;;;;;;;OASG;IACH,OAAO,CAAC,sBAAsB;IA+B9B;;;;;;;;OAQG;IACG,uBAAuB,CAC3B,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAKnC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,mBAAmB;CA0C5B"}
package/dist/kernel.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AnalysisRegistry, buildEvalPaths, flattenForAnalyzer, flattenLoadedModule, isModuleKind, Loader, StaticAnalyzer, } from "@telorun/analyzer";
2
+ import { bindContract, resolveBoundContract, } from "./invocation-contract-binding.js";
2
3
  import { createCancellationSource, RuntimeError, } from "@telorun/sdk";
3
4
  import { parseArgs } from "util";
4
5
  import { ControllerRegistry } from "./controller-registry.js";
@@ -22,6 +23,7 @@ import { defaultTransportRegistry } from "./transports/transport-registry.js";
22
23
  import { collectDeclaredEnvKeys, precompileApplicationEnvSchemas, precompileDefinitionSchemas, resolveApplicationEnv, } from "./application-env.js";
23
24
  import { policyFingerprint } from "./runtime-registry.js";
24
25
  import { SchemaValidator } from "./schema-validator.js";
26
+ import { staticDiagnosticToRuntime } from "./static-analysis-diagnostics.js";
25
27
  /** Walks up the EvaluationContext parent chain to the nearest enclosing
26
28
  * ModuleContext and returns its controller policy (or undefined). Used to
27
29
  * pick the right cache entry when a kind has been loaded under multiple
@@ -216,6 +218,10 @@ export class Kernel {
216
218
  // whether that module happened to be installed.
217
219
  this.controllers.registerController("Telo.ConsoleSink", await import("./controllers/logging/console-sink-controller.js"));
218
220
  this.controllers.registerController("Telo.FileSink", await import("./controllers/logging/file-sink-controller.js"));
221
+ // Data shapes are a kernel concern for the same reason: every kind with an
222
+ // invocation contract declares one, so `inputType:` must be writable without
223
+ // first importing a module.
224
+ this.controllers.registerController("Telo.JsonSchema", await import("./controllers/type/json-schema-controller.js"));
219
225
  }
220
226
  /**
221
227
  * Load a manifest by URL. The URL is dispatched through the registered
@@ -256,7 +262,7 @@ export class Kernel {
256
262
  // Initialize built-in Runtime definitions first
257
263
  await this.loadBuiltinDefinitions();
258
264
  // Phase 5: attach injection hook — fires between create() and init() for every resource
259
- this.rootContext.preInitHook = (resource, getInstance, isPending) => this._injectDependencies(resource, getInstance, isPending);
265
+ this.rootContext.preInitHook = (resource, getInstance, isPending, owner) => this._injectDependencies(resource, getInstance, isPending, owner);
260
266
  // Expose definition lookup so invoke()/invokeResolved() can check thrown
261
267
  // InvokeError.code against the declared throw union (rule 9). Propagates
262
268
  // through spawnChild() to module imports and scoped handles.
@@ -270,24 +276,31 @@ export class Kernel {
270
276
  if (analysisGraph.errors.length > 0) {
271
277
  throw analysisGraph.errors[0].error;
272
278
  }
279
+ // Recorded before the first throw below: the graph is what a renderer
280
+ // resolves a static failure's `origin` against, and a parse error is
281
+ // exactly the failure that most needs to name a line.
282
+ this._loadedGraph = analysisGraph;
273
283
  // A YAML parse failure yields a mangled manifest tree — fatal before any
274
284
  // controller sees it, and more fundamental than a version conflict.
275
285
  if (analysisGraph.parseDiagnostics.length > 0) {
276
- throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", analysisGraph.parseDiagnostics
286
+ throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED",
287
+ // The message keeps the whole failure for a consumer that only reads
288
+ // `error.message`; the diagnostics carry the same set structured, so a
289
+ // renderer can locate each one instead of re-parsing this text.
290
+ analysisGraph.parseDiagnostics
277
291
  .map((d) => {
278
292
  const filePath = d.data?.filePath;
279
293
  return filePath ? `${filePath}: ${d.message}` : d.message;
280
294
  })
281
- .join("\n"));
295
+ .join("\n"), analysisGraph.parseDiagnostics.map(staticDiagnosticToRuntime));
282
296
  }
283
- this._loadedGraph = analysisGraph;
284
297
  this.buildModuleArtifacts(analysisGraph, manifestsDir);
285
298
  // Version reconciliation: an incompatible major mismatch is fatal (the
286
299
  // hoist override would silently run the wrong major); a same-major hoist is
287
300
  // advisory — the override already redirects every importer to the winner.
288
301
  const versionConflicts = analysisGraph.versionDiagnostics.filter((d) => d.code === "MODULE_VERSION_CONFLICT");
289
302
  if (versionConflicts.length > 0) {
290
- throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", versionConflicts.map((d) => d.message).join("\n"));
303
+ throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", versionConflicts.map((d) => d.message).join("\n"), versionConflicts.map(staticDiagnosticToRuntime));
291
304
  }
292
305
  for (const d of analysisGraph.versionDiagnostics) {
293
306
  if (d.code === "MODULE_VERSION_HOISTED") {
@@ -324,14 +337,7 @@ export class Kernel {
324
337
  const skipValidation = stamp?.signature === analysisSignature;
325
338
  const errors = this.analyzer.analyzeErrors(staticManifests, { skipValidation }, this.registry);
326
339
  if (errors.length > 0) {
327
- throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", "Manifest validation failed", errors.map((d) => ({
328
- severity: "error",
329
- message: d.message,
330
- code: d.code !== undefined ? String(d.code) : undefined,
331
- resource: d.data?.resource
332
- ? `${d.data.resource.kind}.${d.data.resource.name}`
333
- : undefined,
334
- })));
340
+ throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", "Manifest validation failed", errors.map(staticDiagnosticToRuntime));
335
341
  }
336
342
  if (manifestsDir && writeCache && !skipValidation) {
337
343
  // Best-effort: stamp the verdict so subsequent loads hit the fast
@@ -531,14 +537,7 @@ export class Kernel {
531
537
  // Phase 3+4: reference validation, cycle detection, and topo sort
532
538
  const { diagnostics: refErrors, order, cycleError, } = this.analyzer.prepare(this.staticManifests, this.registry);
533
539
  if (refErrors.length > 0) {
534
- throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", "Manifest validation failed", refErrors.map((d) => ({
535
- severity: "error",
536
- message: d.message,
537
- code: d.code !== undefined ? String(d.code) : undefined,
538
- resource: d.data?.resource
539
- ? `${d.data.resource.kind}.${d.data.resource.name}`
540
- : undefined,
541
- })));
540
+ throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", "Manifest validation failed", refErrors.map(staticDiagnosticToRuntime));
542
541
  }
543
542
  if (cycleError) {
544
543
  throw new RuntimeError("ERR_CIRCULAR_DEPENDENCY", cycleError);
@@ -950,6 +949,18 @@ export class Kernel {
950
949
  const instance = await controller.create(processedResource, ctx);
951
950
  if (!instance)
952
951
  return null;
952
+ // Bind the resolved invocation contract to the instance, here at the kernel's
953
+ // single instance-production site — so every consumer holds an already
954
+ // enforcing instance, including the majority that read a Phase-5-injected ref
955
+ // straight off their own config and never reach a dispatch chokepoint.
956
+ //
957
+ // For a `base:` child this composes without a special case: the parent's
958
+ // instance was produced by a nested `_createInstance` (so it is already bound
959
+ // to the parent's contract), the inherited controller bound the `inputs:` /
960
+ // `result:` mapping onto it, and this call binds the child's own contract
961
+ // outermost. One dispatch then checks, in order: child inputs → mapping →
962
+ // parent inputs → controller → parent result → mapping → child result.
963
+ this.bindInvocationContract(instance, processedResource, resolvedKind, ctx);
953
964
  // Fold the resource's fire-and-forget drain into its own teardown: tearing
954
965
  // the resource down drains the background tasks it spawned (the kernel just
955
966
  // calls teardown() — it tracks no tasks itself). A drain with no pending
@@ -968,13 +979,47 @@ export class Kernel {
968
979
  // init() on the wrapper would be invisible to the original invoke(), which still
969
980
  // runs with `this === instance`. Mutating in place also preserves the prototype
970
981
  // chain — class-declared methods remain reachable.
982
+ // Every argument is forwarded: `invoke(inputs, ctx)` carries the
983
+ // InvokeContext (cancellation, tracing) as its second parameter, and a
984
+ // wrapper that declares only `inputs` silently drops it.
971
985
  const originalInvoke = instance.invoke.bind(instance);
972
- instance.invoke = async (inputs) => {
986
+ instance.invoke = async (inputs, ...rest) => {
973
987
  const expanded = evalContext.expandPaths(inputs, runtime);
974
- return originalInvoke(expanded);
988
+ return originalInvoke(expanded, ...rest);
975
989
  };
976
990
  return { instance, ctx, resource: processedResource };
977
991
  }
992
+ /**
993
+ * Resolve and bind both directions of a resource's invocation contract.
994
+ *
995
+ * The declaration is layered instance-manifest → nearest along `extends`;
996
+ * contracts never merge (a call signature is not additive the way construction
997
+ * config is), so a definition that declares one fully replaces its ancestor's.
998
+ * Resolution runs in the scope that DECLARED each definition — an `extends`
999
+ * alias is lexical, and a `telo#Type` reference goes through import aliases, so
1000
+ * a chain crossing module boundaries re-scopes at every hop.
1001
+ */
1002
+ bindInvocationContract(instance, resource, resolvedKind, ctx) {
1003
+ const definition = this.controllers.getDefinition(resolvedKind);
1004
+ if (!definition)
1005
+ return;
1006
+ const impl = ctx;
1007
+ const factory = Object.assign((typeRef) => impl.createTypeValidator(typeRef), {
1008
+ schemaOf: (typeRef) => impl.resolveTypeSchema(typeRef),
1009
+ resolveRef: (ref) => impl.lookupSchema(ref),
1010
+ withRules: (name, schema) => impl.createTypeValidatorWithRules(name, schema),
1011
+ });
1012
+ const resolveDef = (kind, from) => this.registry.resolveDefinitionIn(kind, from?.metadata?.module);
1013
+ const input = resolveBoundContract("inputType", resource, definition, resolveDef, factory);
1014
+ const output = resolveBoundContract("outputType", resource, definition, resolveDef, factory);
1015
+ if (!input && !output)
1016
+ return;
1017
+ bindContract(instance, {
1018
+ input,
1019
+ output,
1020
+ describeTarget: () => `${resolvedKind}/${resource.metadata?.name ?? "<unnamed>"}`,
1021
+ });
1022
+ }
978
1023
  /**
979
1024
  * Create phase for an inherited (concrete-`extends`) definition's parent: runs
980
1025
  * the ordinary create pipeline (controller resolution + lazy load, schema
@@ -995,8 +1040,14 @@ export class Kernel {
995
1040
  * field map and replaces each {kind, name} reference value (outside scope visibility
996
1041
  * paths) with the live ResourceInstance returned by getInstance(name). Fields within
997
1042
  * scope paths are left as {kind, name} — the controller resolves them at runtime.
1043
+ *
1044
+ * `owner` is the context the resource belongs to, and the scope handle built for an
1045
+ * `x-telo-scope` field hangs off it rather than off the root: a `with:` block's inline
1046
+ * declarations name their kinds through the import aliases of the module that DECLARED
1047
+ * the resource, so a library's scoped `kind: OAuth.RedirectListener` resolves against
1048
+ * that library's imports — the root has never heard of the alias.
998
1049
  */
999
- _injectDependencies(resource, getInstance, isPending) {
1050
+ _injectDependencies(resource, getInstance, isPending, owner) {
1000
1051
  this.registry.iterateFieldEntries(resource, (fieldPath) => injectAtPath(resource, fieldPath, getInstance, isPending), (fieldPath) => {
1001
1052
  const val = resource[fieldPath];
1002
1053
  if (Array.isArray(val)) {
@@ -1018,7 +1069,7 @@ export class Kernel {
1018
1069
  `such as 'targets:'.`);
1019
1070
  }
1020
1071
  }
1021
- resource[fieldPath] = this.rootContext.createScopeHandle(val);
1072
+ resource[fieldPath] = owner.createScopeHandle(val);
1022
1073
  }
1023
1074
  });
1024
1075
  }