@telorun/sdk 0.56.0 → 0.59.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.
- package/dist/dispatch-invoke-ref.d.ts +11 -1
- package/dist/dispatch-invoke-ref.d.ts.map +1 -1
- package/dist/dispatch-invoke-ref.js +11 -3
- package/dist/evaluation-context.d.ts +9 -0
- package/dist/evaluation-context.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/observed-state.d.ts +36 -0
- package/dist/observed-state.d.ts.map +1 -0
- package/dist/observed-state.js +59 -0
- package/dist/ref.d.ts +11 -0
- package/dist/ref.d.ts.map +1 -1
- package/dist/resolve-ref-instance.d.ts +10 -0
- package/dist/resolve-ref-instance.d.ts.map +1 -1
- package/dist/resolve-ref-instance.js +1 -1
- package/dist/resource-context.d.ts +21 -0
- package/dist/resource-context.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dispatch-invoke-ref.ts +22 -5
- package/src/evaluation-context.ts +9 -0
- package/src/index.ts +1 -0
- package/src/observed-state.ts +59 -0
- package/src/ref.ts +11 -0
- package/src/resolve-ref-instance.ts +11 -1
- package/src/resource-context.ts +21 -0
- package/src/types.ts +8 -0
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import type { InvokeContext } from "./cancellation.js";
|
|
2
2
|
import type { ModuleContext } from "./module-context.js";
|
|
3
|
+
import type { KindRef } from "./ref.js";
|
|
4
|
+
import { type RefResolveContext } from "./resolve-ref-instance.js";
|
|
3
5
|
import { type ResourceInstance } from "./resource-instance.js";
|
|
4
6
|
/** The context a decorator kind composes to dispatch its wrapped target. */
|
|
5
|
-
export interface DispatchContext {
|
|
7
|
+
export interface DispatchContext extends RefResolveContext {
|
|
6
8
|
invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs, ctx?: InvokeContext): Promise<unknown>;
|
|
7
9
|
readonly moduleContext: ModuleContext;
|
|
10
|
+
/**
|
|
11
|
+
* Normalize a slot value to a {@link KindRef}: a `!ref` sentinel, an inline
|
|
12
|
+
* definition, or an already-normalized ref. Optional only so a caller holding
|
|
13
|
+
* a hand-built context still satisfies the interface — supply it whenever the
|
|
14
|
+
* slot can hold a value Phase 2.5 did not rewrite, which is every slot inside
|
|
15
|
+
* an `x-telo-scope` array.
|
|
16
|
+
*/
|
|
17
|
+
ensureKindRef?(value: unknown): KindRef;
|
|
8
18
|
}
|
|
9
19
|
/**
|
|
10
20
|
* Resolve a decorator's `invoke:` field to a live invocable and return a thunk
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-invoke-ref.d.ts","sourceRoot":"","sources":["../src/dispatch-invoke-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatch-invoke-ref.d.ts","sourceRoot":"","sources":["../src/dispatch-invoke-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,4EAA4E;AAC5E,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,cAAc,CAAC,OAAO,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,OAAO,EACf,GAAG,CAAC,EAAE,aAAa,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC;;;;;;OAMG;IACH,aAAa,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,MAAM,MAAM,GACrB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAyBlF"}
|
|
@@ -12,10 +12,18 @@ import { getRefIdentity } from "./resource-instance.js";
|
|
|
12
12
|
* invocation context applies unchanged.
|
|
13
13
|
*/
|
|
14
14
|
export function resolveInvocableDispatcher(field, ctx, describe) {
|
|
15
|
-
|
|
15
|
+
// A `!ref` inside an `x-telo-scope` array is never rewritten by Phase 2.5, so it
|
|
16
|
+
// arrives as the raw sentinel — which has no `name` and would otherwise fail with
|
|
17
|
+
// a message pointing nowhere. `ensureKindRef` is the same rescue `ctx.resolveRef`
|
|
18
|
+
// performs; both resolution paths have to normalize, or a slot works only
|
|
19
|
+
// depending on which one its kind happens to use.
|
|
20
|
+
const normalized = ctx.ensureKindRef && field !== null && typeof field === "object" && !isInvocableInstance(field)
|
|
21
|
+
? ctx.ensureKindRef(field)
|
|
22
|
+
: field;
|
|
23
|
+
const target = resolveRefInstance(normalized, ctx, isInvocableInstance, () => `${describe()}: 'invoke'`, "Telo.Invocable");
|
|
16
24
|
// Dispatch through the traced chokepoint needs the target's kind+name: from
|
|
17
|
-
// the `!ref` identity the kernel stamped at injection, else from the
|
|
18
|
-
const id = getRefIdentity(target) ??
|
|
25
|
+
// the `!ref` identity the kernel stamped at injection, else from the ref.
|
|
26
|
+
const id = getRefIdentity(target) ?? normalized;
|
|
19
27
|
if (!id || typeof id.kind !== "string" || typeof id.name !== "string") {
|
|
20
28
|
return (inputs, invokeCtx) => target.invoke(inputs, invokeCtx);
|
|
21
29
|
}
|
|
@@ -114,6 +114,15 @@ export interface EvaluationContext {
|
|
|
114
114
|
initializeResources(): Promise<void>;
|
|
115
115
|
withManifests<T>(manifests: any[], fn: () => T): T;
|
|
116
116
|
createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
|
|
117
|
+
/** Re-read a resource's `snapshot()` and republish it, joined with whatever
|
|
118
|
+
* observed state the resource has reported. The publication path the
|
|
119
|
+
* post-init capture, the post-run publication, the post-invoke refresh and
|
|
120
|
+
* every `setStatus()` all share. */
|
|
121
|
+
publishSnapshot(name: string): Promise<void>;
|
|
122
|
+
/** Record what a resource observed (`ResourceContext.setStatus`) and
|
|
123
|
+
* republish. Validated against the kind's `status:`; replaces rather than
|
|
124
|
+
* merges; an error before the resource has started. */
|
|
125
|
+
setResourceStatus(name: string, status: Record<string, unknown>): Promise<void>;
|
|
117
126
|
teardownResources(): Promise<void>;
|
|
118
127
|
transientChild(context: Record<string, any>): EvaluationContext;
|
|
119
128
|
invoke<TInputs>(kind: string, name: string, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClF,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,CACtB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EA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E,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAChG,cAAc,CAAC,OAAO,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,OAAO,EACf,GAAG,CAAC,EAAE,aAAa,GAClB,OAAO,CAAC,GAAG,CAAC,CAAC;IAChB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpF;;6DAEyD;IACzD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,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
|
@@ -24,6 +24,7 @@ export * from "./log-sink.js";
|
|
|
24
24
|
export * from "./log-severity.js";
|
|
25
25
|
export * from "./logger.js";
|
|
26
26
|
export * from "./network-fetch.js";
|
|
27
|
+
export * from "./observed-state.js";
|
|
27
28
|
export * from "./runtime-error.js";
|
|
28
29
|
export * from "./runtime-event.js";
|
|
29
30
|
export * from "./runtime-resource.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,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,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,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,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,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,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export * from "./log-sink.js";
|
|
|
24
24
|
export * from "./log-severity.js";
|
|
25
25
|
export * from "./logger.js";
|
|
26
26
|
export * from "./network-fetch.js";
|
|
27
|
+
export * from "./observed-state.js";
|
|
27
28
|
export * from "./runtime-error.js";
|
|
28
29
|
export * from "./runtime-event.js";
|
|
29
30
|
export * from "./runtime-resource.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observed state — what a resource learns while it is running (a socket's
|
|
3
|
+
* actual port, a negotiated endpoint) as opposed to what its author configured.
|
|
4
|
+
*
|
|
5
|
+
* The two are reported through two different channels, because only one of them
|
|
6
|
+
* is derivable on demand:
|
|
7
|
+
*
|
|
8
|
+
* - **Configured state is pulled.** `snapshot()` returns it, and the kernel
|
|
9
|
+
* calls that whenever it needs the value; it is a function of the manifest,
|
|
10
|
+
* so re-deriving it is always correct.
|
|
11
|
+
* - **Observed state is pushed.** `ResourceContext.setStatus()` reports it at
|
|
12
|
+
* the moment it is learned, because nothing but the controller knows when
|
|
13
|
+
* that is. The kernel holds the last value reported and publishes it at
|
|
14
|
+
* `resources.<name>.{@link OBSERVED_STATE_KEY}.<field>`.
|
|
15
|
+
*
|
|
16
|
+
* Splitting them is what keeps each shape described in exactly one place: a
|
|
17
|
+
* controller never rebuilds observed state inside `snapshot()` from a field it
|
|
18
|
+
* stashed only for that purpose, and the two payloads can never collide.
|
|
19
|
+
*/
|
|
20
|
+
/** The CEL segment observed state is published under: `resources.<name>.status`. */
|
|
21
|
+
export declare const OBSERVED_STATE_KEY = "status";
|
|
22
|
+
/**
|
|
23
|
+
* Copy the plain containers out of a published value so what reaches CEL is a
|
|
24
|
+
* point-in-time reading rather than a live window into the controller.
|
|
25
|
+
*
|
|
26
|
+
* A controller that reported a structure it goes on to mutate would otherwise
|
|
27
|
+
* keep rewriting an already-published value — an accident no schema check can
|
|
28
|
+
* catch, because the shape never changes, only the contents.
|
|
29
|
+
*
|
|
30
|
+
* Plain objects and arrays are rebuilt; everything else — class instances (a
|
|
31
|
+
* `Stream`, a connection pool), functions, primitives — is passed through by
|
|
32
|
+
* reference, because those are not copyable in any meaningful sense and CEL
|
|
33
|
+
* cannot read into them anyway. Cycles resolve to the copy already made.
|
|
34
|
+
*/
|
|
35
|
+
export declare function detachSnapshotValue(value: unknown, seen?: Map<object, unknown>): unknown;
|
|
36
|
+
//# sourceMappingURL=observed-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observed-state.d.ts","sourceRoot":"","sources":["../src/observed-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,uBAA6B,GAAG,OAAO,CAsB9F"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observed state — what a resource learns while it is running (a socket's
|
|
3
|
+
* actual port, a negotiated endpoint) as opposed to what its author configured.
|
|
4
|
+
*
|
|
5
|
+
* The two are reported through two different channels, because only one of them
|
|
6
|
+
* is derivable on demand:
|
|
7
|
+
*
|
|
8
|
+
* - **Configured state is pulled.** `snapshot()` returns it, and the kernel
|
|
9
|
+
* calls that whenever it needs the value; it is a function of the manifest,
|
|
10
|
+
* so re-deriving it is always correct.
|
|
11
|
+
* - **Observed state is pushed.** `ResourceContext.setStatus()` reports it at
|
|
12
|
+
* the moment it is learned, because nothing but the controller knows when
|
|
13
|
+
* that is. The kernel holds the last value reported and publishes it at
|
|
14
|
+
* `resources.<name>.{@link OBSERVED_STATE_KEY}.<field>`.
|
|
15
|
+
*
|
|
16
|
+
* Splitting them is what keeps each shape described in exactly one place: a
|
|
17
|
+
* controller never rebuilds observed state inside `snapshot()` from a field it
|
|
18
|
+
* stashed only for that purpose, and the two payloads can never collide.
|
|
19
|
+
*/
|
|
20
|
+
/** The CEL segment observed state is published under: `resources.<name>.status`. */
|
|
21
|
+
export const OBSERVED_STATE_KEY = "status";
|
|
22
|
+
/**
|
|
23
|
+
* Copy the plain containers out of a published value so what reaches CEL is a
|
|
24
|
+
* point-in-time reading rather than a live window into the controller.
|
|
25
|
+
*
|
|
26
|
+
* A controller that reported a structure it goes on to mutate would otherwise
|
|
27
|
+
* keep rewriting an already-published value — an accident no schema check can
|
|
28
|
+
* catch, because the shape never changes, only the contents.
|
|
29
|
+
*
|
|
30
|
+
* Plain objects and arrays are rebuilt; everything else — class instances (a
|
|
31
|
+
* `Stream`, a connection pool), functions, primitives — is passed through by
|
|
32
|
+
* reference, because those are not copyable in any meaningful sense and CEL
|
|
33
|
+
* cannot read into them anyway. Cycles resolve to the copy already made.
|
|
34
|
+
*/
|
|
35
|
+
export function detachSnapshotValue(value, seen = new Map()) {
|
|
36
|
+
if (value === null || typeof value !== "object")
|
|
37
|
+
return value;
|
|
38
|
+
const existing = seen.get(value);
|
|
39
|
+
if (existing !== undefined)
|
|
40
|
+
return existing;
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
const copy = new Array(value.length);
|
|
43
|
+
seen.set(value, copy);
|
|
44
|
+
for (let i = 0; i < value.length; i++)
|
|
45
|
+
copy[i] = detachSnapshotValue(value[i], seen);
|
|
46
|
+
return copy;
|
|
47
|
+
}
|
|
48
|
+
// Only plain objects: a class instance's identity and behaviour are the point
|
|
49
|
+
// of returning it, and rebuilding one as a bare object would break it.
|
|
50
|
+
const proto = Object.getPrototypeOf(value);
|
|
51
|
+
if (proto !== Object.prototype && proto !== null)
|
|
52
|
+
return value;
|
|
53
|
+
const copy = {};
|
|
54
|
+
seen.set(value, copy);
|
|
55
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
56
|
+
copy[key] = detachSnapshotValue(entry, seen);
|
|
57
|
+
}
|
|
58
|
+
return copy;
|
|
59
|
+
}
|
package/dist/ref.d.ts
CHANGED
|
@@ -27,6 +27,17 @@ export interface ScopeContext {
|
|
|
27
27
|
* this is always a programming error; all scope members are statically
|
|
28
28
|
* validated in Phase 3 before the kernel ever reaches runtime. */
|
|
29
29
|
getInstance(name: string, alias?: string): ResourceInstance;
|
|
30
|
+
/** `run()` a scope-local resource through the kernel's dispatch chokepoint, so
|
|
31
|
+
* it is traced, records that it started, and publishes its snapshot — a bare
|
|
32
|
+
* `getInstance(name).run()` does none of that. Throws if the name was not
|
|
33
|
+
* declared in the scope or the instance is not runnable. */
|
|
34
|
+
run(name: string): Promise<void>;
|
|
35
|
+
/** The CEL `resources` map as seen from inside this scope: the enclosing
|
|
36
|
+
* module's published resources with the scope-local ones layered on top
|
|
37
|
+
* (scope-local names win, matching {@link getInstance}'s resolution order).
|
|
38
|
+
* Rebuilt per `ScopeHandle.run()`, so two concurrent runs of the same
|
|
39
|
+
* sequence never observe each other's scoped resources. */
|
|
40
|
+
readonly resources: Record<string, unknown>;
|
|
30
41
|
}
|
|
31
42
|
/** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
|
|
32
43
|
* 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;;;;;;;gFAOgF;AAChF,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,gBAAgB;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,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;;;;;uEAKmE;IACnE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;
|
|
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;;;;;;;gFAOgF;AAChF,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,gBAAgB;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;CACrB;AAED;6DAC6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G,QACG,CAAC"}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { ModuleContext } from "./module-context.js";
|
|
2
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
2
3
|
/** The slice of `ResourceContext` needed to resolve a reference. */
|
|
3
4
|
export interface RefResolveContext {
|
|
4
5
|
readonly moduleContext: ModuleContext;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve a bare name with the caller's own precedence — scope-local first,
|
|
8
|
+
* enclosing module as the fallback. Optional: a caller holding only a
|
|
9
|
+
* `{ moduleContext }` slice has no scope to prefer, and falls back to the
|
|
10
|
+
* module. Supplying it is what lets a `with:`-scoped resource reference a
|
|
11
|
+
* scoped sibling, and keeps `!ref` agreeing with the CEL `resources` layering
|
|
12
|
+
* about what a name means inside a scope.
|
|
13
|
+
*/
|
|
14
|
+
resolveLocalInstance?(name: string): ResourceInstance | undefined;
|
|
5
15
|
}
|
|
6
16
|
/**
|
|
7
17
|
* Resolve a `!ref` config field to a live instance of `T`. Controllers reach
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-ref-instance.d.ts","sourceRoot":"","sources":["../src/resolve-ref-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-ref-instance.d.ts","sourceRoot":"","sources":["../src/resolve-ref-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC;;;;;;;OAOG;IACH,oBAAoB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;CACnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,SAAS,IAAI,CAAC,EAC7C,QAAQ,EAAE,MAAM,MAAM,EACtB,OAAO,CAAC,EAAE,MAAM,GACf,CAAC,CAiCH"}
|
|
@@ -47,7 +47,7 @@ export function resolveRefInstance(value, ctx, guard, describe, expects) {
|
|
|
47
47
|
// it is an alias that crosses no import boundary.
|
|
48
48
|
const instance = ref.alias && ref.alias !== "Self"
|
|
49
49
|
? ctx.moduleContext.resolveImportedInstance(ref.alias, ref.name)
|
|
50
|
-
: ctx.moduleContext.getInstance(ref.name);
|
|
50
|
+
: (ctx.resolveLocalInstance?.(ref.name) ?? ctx.moduleContext.getInstance(ref.name));
|
|
51
51
|
if (!guard(instance)) {
|
|
52
52
|
const label = ref.alias ? `${ref.alias}.${ref.name}` : ref.name;
|
|
53
53
|
throw new RuntimeError("ERR_REF_UNRESOLVED", `${describe()} reference '${label}' did not resolve to a ${target}` +
|
|
@@ -45,6 +45,27 @@ export interface ResourceContext extends ControllerContext {
|
|
|
45
45
|
* collide and the children nest under their parent in a debug view. */
|
|
46
46
|
readonly ownerPrefix: string;
|
|
47
47
|
acquireHold(reason?: string): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Report this resource's **observed state** — what it has learned while
|
|
50
|
+
* running — publishing it at `resources.<name>.status.<field>`.
|
|
51
|
+
*
|
|
52
|
+
* Pushed rather than pulled because nothing but the controller knows when the
|
|
53
|
+
* value was learned. Configured state stays on `snapshot()`, which the kernel
|
|
54
|
+
* pulls whenever it needs it; the two never share a payload, so neither shape
|
|
55
|
+
* is described twice.
|
|
56
|
+
*
|
|
57
|
+
* - **Replaces**, never merges: this is the resource's observed state now. A
|
|
58
|
+
* field the kind declares but this call omits reads as missing, which is the
|
|
59
|
+
* truth — declare a sometimes-absent field with a nullable type and report
|
|
60
|
+
* it as `null`.
|
|
61
|
+
* - **Validated** against the kind's `status:` on every call.
|
|
62
|
+
* - **Illegal before the resource has started** (`ERR_OBSERVED_STATE_BEFORE_START`).
|
|
63
|
+
* `init()` performs no I/O, so there is nothing observed to report there.
|
|
64
|
+
* - **Sticky**: the last value reported stays published until the resource is
|
|
65
|
+
* torn down. A dispatch that reports nothing leaves the previous reading in
|
|
66
|
+
* place — a listener's bound address does not stop being true between calls.
|
|
67
|
+
*/
|
|
68
|
+
setStatus(status: Record<string, unknown>): Promise<void>;
|
|
48
69
|
emitEvent(event: string, payload?: any): Promise<void>;
|
|
49
70
|
/** Mint a writable cancellation source for a trigger to own (HTTP request,
|
|
50
71
|
* lambda budget). Pass `source.context` into `invokeResolved` to scope an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-context.d.ts","sourceRoot":"","sources":["../src/resource-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1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,CAAC;IAClC;;;;iEAI6D;IAC7D,cAAc,IAAI,MAAM,GAAG,SAAS,CAAC;IACrC;wDACoD;IACpD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC5E;;;sBAGkB;IAClB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACxD;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CACxC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -40,6 +40,14 @@ export interface ResourceDefinition {
|
|
|
40
40
|
};
|
|
41
41
|
/** JSON Schema for the resource's compile-time configuration fields. */
|
|
42
42
|
schema?: Record<string, any>;
|
|
43
|
+
/** JSON Schema for the observed state the resource reports while running —
|
|
44
|
+
* what it learns, not what it was configured with. Surfaces as its own CEL
|
|
45
|
+
* segment, `resources.<name>.status.<field>`, readable only from fields that
|
|
46
|
+
* resolve while the application runs. Declaring the block (even empty) opts
|
|
47
|
+
* the kind into typed `.status` reads. `required:` is rejected: every
|
|
48
|
+
* declared field is mandatory once the resource has run, and a genuinely
|
|
49
|
+
* sometimes-absent one is declared with a nullable type instead. */
|
|
50
|
+
status?: Record<string, any>;
|
|
43
51
|
capability?: string;
|
|
44
52
|
/** Alias-form reference to a Telo.Abstract this definition implements, e.g. "Ai.Model".
|
|
45
53
|
* Resolved against the declaring file's `Telo.Import` declarations — same pattern as
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +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;;0CAE0C;AAC1C,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;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,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,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AW,CAAC,EAAE,iBAAiB,EAAE,YAAA;CAK3C"}
|
package/package.json
CHANGED
|
@@ -2,11 +2,11 @@ import type { InvokeContext } from "./cancellation.js";
|
|
|
2
2
|
import type { Invocable } from "./capabilities/invokable.js";
|
|
3
3
|
import type { ModuleContext } from "./module-context.js";
|
|
4
4
|
import type { KindRef } from "./ref.js";
|
|
5
|
-
import { resolveRefInstance } from "./resolve-ref-instance.js";
|
|
5
|
+
import { resolveRefInstance, type RefResolveContext } from "./resolve-ref-instance.js";
|
|
6
6
|
import { getRefIdentity, type ResourceInstance } from "./resource-instance.js";
|
|
7
7
|
|
|
8
8
|
/** The context a decorator kind composes to dispatch its wrapped target. */
|
|
9
|
-
export interface DispatchContext {
|
|
9
|
+
export interface DispatchContext extends RefResolveContext {
|
|
10
10
|
invokeResolved<TInputs>(
|
|
11
11
|
kind: string,
|
|
12
12
|
name: string,
|
|
@@ -15,6 +15,14 @@ export interface DispatchContext {
|
|
|
15
15
|
ctx?: InvokeContext,
|
|
16
16
|
): Promise<unknown>;
|
|
17
17
|
readonly moduleContext: ModuleContext;
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a slot value to a {@link KindRef}: a `!ref` sentinel, an inline
|
|
20
|
+
* definition, or an already-normalized ref. Optional only so a caller holding
|
|
21
|
+
* a hand-built context still satisfies the interface — supply it whenever the
|
|
22
|
+
* slot can hold a value Phase 2.5 did not rewrite, which is every slot inside
|
|
23
|
+
* an `x-telo-scope` array.
|
|
24
|
+
*/
|
|
25
|
+
ensureKindRef?(value: unknown): KindRef;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
/**
|
|
@@ -33,16 +41,25 @@ export function resolveInvocableDispatcher(
|
|
|
33
41
|
ctx: DispatchContext,
|
|
34
42
|
describe: () => string,
|
|
35
43
|
): (inputs: Record<string, unknown>, invokeCtx?: InvokeContext) => Promise<unknown> {
|
|
44
|
+
// A `!ref` inside an `x-telo-scope` array is never rewritten by Phase 2.5, so it
|
|
45
|
+
// arrives as the raw sentinel — which has no `name` and would otherwise fail with
|
|
46
|
+
// a message pointing nowhere. `ensureKindRef` is the same rescue `ctx.resolveRef`
|
|
47
|
+
// performs; both resolution paths have to normalize, or a slot works only
|
|
48
|
+
// depending on which one its kind happens to use.
|
|
49
|
+
const normalized =
|
|
50
|
+
ctx.ensureKindRef && field !== null && typeof field === "object" && !isInvocableInstance(field)
|
|
51
|
+
? ctx.ensureKindRef(field)
|
|
52
|
+
: field;
|
|
36
53
|
const target = resolveRefInstance(
|
|
37
|
-
|
|
54
|
+
normalized,
|
|
38
55
|
ctx,
|
|
39
56
|
isInvocableInstance,
|
|
40
57
|
() => `${describe()}: 'invoke'`,
|
|
41
58
|
"Telo.Invocable",
|
|
42
59
|
);
|
|
43
60
|
// Dispatch through the traced chokepoint needs the target's kind+name: from
|
|
44
|
-
// the `!ref` identity the kernel stamped at injection, else from the
|
|
45
|
-
const id = getRefIdentity(target as object) ?? (
|
|
61
|
+
// the `!ref` identity the kernel stamped at injection, else from the ref.
|
|
62
|
+
const id = getRefIdentity(target as object) ?? (normalized as Partial<KindRef> | undefined);
|
|
46
63
|
if (!id || typeof id.kind !== "string" || typeof id.name !== "string") {
|
|
47
64
|
return (inputs, invokeCtx) => target.invoke(inputs, invokeCtx);
|
|
48
65
|
}
|
|
@@ -146,6 +146,15 @@ export interface EvaluationContext {
|
|
|
146
146
|
initializeResources(): Promise<void>;
|
|
147
147
|
withManifests<T>(manifests: any[], fn: () => T): T;
|
|
148
148
|
createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
|
|
149
|
+
/** Re-read a resource's `snapshot()` and republish it, joined with whatever
|
|
150
|
+
* observed state the resource has reported. The publication path the
|
|
151
|
+
* post-init capture, the post-run publication, the post-invoke refresh and
|
|
152
|
+
* every `setStatus()` all share. */
|
|
153
|
+
publishSnapshot(name: string): Promise<void>;
|
|
154
|
+
/** Record what a resource observed (`ResourceContext.setStatus`) and
|
|
155
|
+
* republish. Validated against the kind's `status:`; replaces rather than
|
|
156
|
+
* merges; an error before the resource has started. */
|
|
157
|
+
setResourceStatus(name: string, status: Record<string, unknown>): Promise<void>;
|
|
149
158
|
teardownResources(): Promise<void>;
|
|
150
159
|
transientChild(context: Record<string, any>): EvaluationContext;
|
|
151
160
|
invoke<TInputs>(kind: string, name: string, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from "./log-sink.js";
|
|
|
24
24
|
export * from "./log-severity.js";
|
|
25
25
|
export * from "./logger.js";
|
|
26
26
|
export * from "./network-fetch.js";
|
|
27
|
+
export * from "./observed-state.js";
|
|
27
28
|
export * from "./runtime-error.js";
|
|
28
29
|
export * from "./runtime-event.js";
|
|
29
30
|
export * from "./runtime-resource.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observed state — what a resource learns while it is running (a socket's
|
|
3
|
+
* actual port, a negotiated endpoint) as opposed to what its author configured.
|
|
4
|
+
*
|
|
5
|
+
* The two are reported through two different channels, because only one of them
|
|
6
|
+
* is derivable on demand:
|
|
7
|
+
*
|
|
8
|
+
* - **Configured state is pulled.** `snapshot()` returns it, and the kernel
|
|
9
|
+
* calls that whenever it needs the value; it is a function of the manifest,
|
|
10
|
+
* so re-deriving it is always correct.
|
|
11
|
+
* - **Observed state is pushed.** `ResourceContext.setStatus()` reports it at
|
|
12
|
+
* the moment it is learned, because nothing but the controller knows when
|
|
13
|
+
* that is. The kernel holds the last value reported and publishes it at
|
|
14
|
+
* `resources.<name>.{@link OBSERVED_STATE_KEY}.<field>`.
|
|
15
|
+
*
|
|
16
|
+
* Splitting them is what keeps each shape described in exactly one place: a
|
|
17
|
+
* controller never rebuilds observed state inside `snapshot()` from a field it
|
|
18
|
+
* stashed only for that purpose, and the two payloads can never collide.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** The CEL segment observed state is published under: `resources.<name>.status`. */
|
|
22
|
+
export const OBSERVED_STATE_KEY = "status";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Copy the plain containers out of a published value so what reaches CEL is a
|
|
26
|
+
* point-in-time reading rather than a live window into the controller.
|
|
27
|
+
*
|
|
28
|
+
* A controller that reported a structure it goes on to mutate would otherwise
|
|
29
|
+
* keep rewriting an already-published value — an accident no schema check can
|
|
30
|
+
* catch, because the shape never changes, only the contents.
|
|
31
|
+
*
|
|
32
|
+
* Plain objects and arrays are rebuilt; everything else — class instances (a
|
|
33
|
+
* `Stream`, a connection pool), functions, primitives — is passed through by
|
|
34
|
+
* reference, because those are not copyable in any meaningful sense and CEL
|
|
35
|
+
* cannot read into them anyway. Cycles resolve to the copy already made.
|
|
36
|
+
*/
|
|
37
|
+
export function detachSnapshotValue(value: unknown, seen = new Map<object, unknown>()): unknown {
|
|
38
|
+
if (value === null || typeof value !== "object") return value;
|
|
39
|
+
const existing = seen.get(value);
|
|
40
|
+
if (existing !== undefined) return existing;
|
|
41
|
+
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
const copy: unknown[] = new Array(value.length);
|
|
44
|
+
seen.set(value, copy);
|
|
45
|
+
for (let i = 0; i < value.length; i++) copy[i] = detachSnapshotValue(value[i], seen);
|
|
46
|
+
return copy;
|
|
47
|
+
}
|
|
48
|
+
// Only plain objects: a class instance's identity and behaviour are the point
|
|
49
|
+
// of returning it, and rebuilding one as a bare object would break it.
|
|
50
|
+
const proto = Object.getPrototypeOf(value);
|
|
51
|
+
if (proto !== Object.prototype && proto !== null) return value;
|
|
52
|
+
|
|
53
|
+
const copy: Record<string, unknown> = {};
|
|
54
|
+
seen.set(value, copy);
|
|
55
|
+
for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
|
|
56
|
+
copy[key] = detachSnapshotValue(entry, seen);
|
|
57
|
+
}
|
|
58
|
+
return copy;
|
|
59
|
+
}
|
package/src/ref.ts
CHANGED
|
@@ -30,6 +30,17 @@ export interface ScopeContext {
|
|
|
30
30
|
* this is always a programming error; all scope members are statically
|
|
31
31
|
* validated in Phase 3 before the kernel ever reaches runtime. */
|
|
32
32
|
getInstance(name: string, alias?: string): ResourceInstance;
|
|
33
|
+
/** `run()` a scope-local resource through the kernel's dispatch chokepoint, so
|
|
34
|
+
* it is traced, records that it started, and publishes its snapshot — a bare
|
|
35
|
+
* `getInstance(name).run()` does none of that. Throws if the name was not
|
|
36
|
+
* declared in the scope or the instance is not runnable. */
|
|
37
|
+
run(name: string): Promise<void>;
|
|
38
|
+
/** The CEL `resources` map as seen from inside this scope: the enclosing
|
|
39
|
+
* module's published resources with the scope-local ones layered on top
|
|
40
|
+
* (scope-local names win, matching {@link getInstance}'s resolution order).
|
|
41
|
+
* Rebuilt per `ScopeHandle.run()`, so two concurrent runs of the same
|
|
42
|
+
* sequence never observe each other's scoped resources. */
|
|
43
|
+
readonly resources: Record<string, unknown>;
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
/** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import type { ModuleContext } from "./module-context.js";
|
|
2
2
|
import type { KindRef } from "./ref.js";
|
|
3
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
3
4
|
import { RuntimeError } from "./types.js";
|
|
4
5
|
|
|
5
6
|
/** The slice of `ResourceContext` needed to resolve a reference. */
|
|
6
7
|
export interface RefResolveContext {
|
|
7
8
|
readonly moduleContext: ModuleContext;
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a bare name with the caller's own precedence — scope-local first,
|
|
11
|
+
* enclosing module as the fallback. Optional: a caller holding only a
|
|
12
|
+
* `{ moduleContext }` slice has no scope to prefer, and falls back to the
|
|
13
|
+
* module. Supplying it is what lets a `with:`-scoped resource reference a
|
|
14
|
+
* scoped sibling, and keeps `!ref` agreeing with the CEL `resources` layering
|
|
15
|
+
* about what a name means inside a scope.
|
|
16
|
+
*/
|
|
17
|
+
resolveLocalInstance?(name: string): ResourceInstance | undefined;
|
|
8
18
|
}
|
|
9
19
|
|
|
10
20
|
/**
|
|
@@ -67,7 +77,7 @@ export function resolveRefInstance<T>(
|
|
|
67
77
|
const instance =
|
|
68
78
|
ref.alias && ref.alias !== "Self"
|
|
69
79
|
? ctx.moduleContext.resolveImportedInstance(ref.alias, ref.name)
|
|
70
|
-
: ctx.moduleContext.getInstance(ref.name);
|
|
80
|
+
: (ctx.resolveLocalInstance?.(ref.name) ?? ctx.moduleContext.getInstance(ref.name));
|
|
71
81
|
|
|
72
82
|
if (!guard(instance)) {
|
|
73
83
|
const label = ref.alias ? `${ref.alias}.${ref.name}` : ref.name;
|
package/src/resource-context.ts
CHANGED
|
@@ -54,6 +54,27 @@ export interface ResourceContext extends ControllerContext {
|
|
|
54
54
|
* collide and the children nest under their parent in a debug view. */
|
|
55
55
|
readonly ownerPrefix: string;
|
|
56
56
|
acquireHold(reason?: string): () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Report this resource's **observed state** — what it has learned while
|
|
59
|
+
* running — publishing it at `resources.<name>.status.<field>`.
|
|
60
|
+
*
|
|
61
|
+
* Pushed rather than pulled because nothing but the controller knows when the
|
|
62
|
+
* value was learned. Configured state stays on `snapshot()`, which the kernel
|
|
63
|
+
* pulls whenever it needs it; the two never share a payload, so neither shape
|
|
64
|
+
* is described twice.
|
|
65
|
+
*
|
|
66
|
+
* - **Replaces**, never merges: this is the resource's observed state now. A
|
|
67
|
+
* field the kind declares but this call omits reads as missing, which is the
|
|
68
|
+
* truth — declare a sometimes-absent field with a nullable type and report
|
|
69
|
+
* it as `null`.
|
|
70
|
+
* - **Validated** against the kind's `status:` on every call.
|
|
71
|
+
* - **Illegal before the resource has started** (`ERR_OBSERVED_STATE_BEFORE_START`).
|
|
72
|
+
* `init()` performs no I/O, so there is nothing observed to report there.
|
|
73
|
+
* - **Sticky**: the last value reported stays published until the resource is
|
|
74
|
+
* torn down. A dispatch that reports nothing leaves the previous reading in
|
|
75
|
+
* place — a listener's bound address does not stop being true between calls.
|
|
76
|
+
*/
|
|
77
|
+
setStatus(status: Record<string, unknown>): Promise<void>;
|
|
57
78
|
emitEvent(event: string, payload?: any): Promise<void>;
|
|
58
79
|
/** Mint a writable cancellation source for a trigger to own (HTTP request,
|
|
59
80
|
* lambda budget). Pass `source.context` into `invokeResolved` to scope an
|
package/src/types.ts
CHANGED
|
@@ -46,6 +46,14 @@ export interface ResourceDefinition {
|
|
|
46
46
|
};
|
|
47
47
|
/** JSON Schema for the resource's compile-time configuration fields. */
|
|
48
48
|
schema?: Record<string, any>;
|
|
49
|
+
/** JSON Schema for the observed state the resource reports while running —
|
|
50
|
+
* what it learns, not what it was configured with. Surfaces as its own CEL
|
|
51
|
+
* segment, `resources.<name>.status.<field>`, readable only from fields that
|
|
52
|
+
* resolve while the application runs. Declaring the block (even empty) opts
|
|
53
|
+
* the kind into typed `.status` reads. `required:` is rejected: every
|
|
54
|
+
* declared field is mandatory once the resource has run, and a genuinely
|
|
55
|
+
* sometimes-absent one is declared with a nullable type instead. */
|
|
56
|
+
status?: Record<string, any>;
|
|
49
57
|
capability?: string;
|
|
50
58
|
/** Alias-form reference to a Telo.Abstract this definition implements, e.g. "Ai.Model".
|
|
51
59
|
* Resolved against the declaring file's `Telo.Import` declarations — same pattern as
|