@telorun/sdk 0.31.0 → 0.32.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/cancellation.d.ts +33 -0
- package/dist/cancellation.d.ts.map +1 -1
- package/dist/evaluation-context.d.ts +5 -1
- package/dist/evaluation-context.d.ts.map +1 -1
- package/dist/invoke-step.d.ts +1 -1
- package/dist/invoke-step.d.ts.map +1 -1
- package/dist/invoke-step.js +9 -1
- package/dist/resource-context.d.ts +8 -1
- package/dist/resource-context.d.ts.map +1 -1
- package/dist/resource-instance.d.ts +18 -0
- package/dist/resource-instance.d.ts.map +1 -1
- package/dist/resource-instance.js +24 -1
- package/package.json +1 -1
- package/src/cancellation.ts +30 -0
- package/src/evaluation-context.ts +5 -1
- package/src/invoke-step.ts +9 -2
- package/src/resource-context.ts +8 -1
- package/src/resource-instance.ts +33 -0
package/dist/cancellation.d.ts
CHANGED
|
@@ -43,6 +43,39 @@ export interface InvokeContext {
|
|
|
43
43
|
/** The {@link invocationId} of the invocation that dispatched this one, or
|
|
44
44
|
* `undefined` at a trace root. Reconstructs the call tree on the consumer. */
|
|
45
45
|
readonly parentInvocationId?: number;
|
|
46
|
+
/** The trace this invocation belongs to — minted at the root span and inherited
|
|
47
|
+
* by every descendant. Present only while tracing. Groups all spans of one
|
|
48
|
+
* trace the way OpenTelemetry's `trace_id` does (an exporter maps it directly),
|
|
49
|
+
* independent of the parent chain. */
|
|
50
|
+
readonly traceId?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Terminal status of a span — maps to OpenTelemetry span status. */
|
|
53
|
+
export type SpanOutcome = "ok" | "failed" | "rejected" | "cancelled";
|
|
54
|
+
/** Options for {@link ResourceContext.openSpan}. */
|
|
55
|
+
export interface OpenSpanOptions {
|
|
56
|
+
/** The resource the span is attributed to (an inbound transport's listener,
|
|
57
|
+
* e.g. the `Http.Api`). Becomes the span's `ref`. */
|
|
58
|
+
ref: {
|
|
59
|
+
kind: string;
|
|
60
|
+
name: string;
|
|
61
|
+
};
|
|
62
|
+
/** Human label for the span (e.g. `"POST /feedback"`). */
|
|
63
|
+
label?: string;
|
|
64
|
+
/** Structured attributes (e.g. `{ method, path }`). Map to OTel span attributes. */
|
|
65
|
+
attributes?: Record<string, unknown>;
|
|
66
|
+
/** Continue an upstream distributed trace instead of rooting a new one — e.g.
|
|
67
|
+
* seeded from a W3C `traceparent` header. */
|
|
68
|
+
inbound?: {
|
|
69
|
+
traceId: string;
|
|
70
|
+
parentSpanId?: number;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Handle returned by {@link ResourceContext.openSpan}. */
|
|
74
|
+
export interface OpenSpan {
|
|
75
|
+
/** Thread into `invokeResolved` so the handler nests under the span. */
|
|
76
|
+
readonly context: InvokeContext;
|
|
77
|
+
/** Close the span with an outcome (emits the span's `end` event). */
|
|
78
|
+
settle(outcome: SpanOutcome, detail?: Record<string, unknown>): Promise<void>;
|
|
46
79
|
}
|
|
47
80
|
export interface CancellationSource {
|
|
48
81
|
readonly token: CancellationToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancellation.d.ts","sourceRoot":"","sources":["../src/cancellation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC;yDACqD;IACrD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B;2CACuC;IACvC,WAAW,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACxE,kEAAkE;IAClE,gBAAgB,IAAI,IAAI,CAAC;CAC1B;AAED;;;;GAIG;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.js";
|
|
1
|
+
import type { InvokeContext, OpenSpan, OpenSpanOptions } from "./cancellation.js";
|
|
2
2
|
import type { ScopeHandle } from "./ref.js";
|
|
3
3
|
import type { ResourceInstance } from "./resource-instance.js";
|
|
4
4
|
import type { ResourceManifest } from "./resource-manifest.js";
|
|
@@ -13,6 +13,9 @@ export interface Tracer {
|
|
|
13
13
|
readonly enabled: boolean;
|
|
14
14
|
/** Mint the next monotonic invocation id (unique within the kernel run). */
|
|
15
15
|
next(): number;
|
|
16
|
+
/** Mint a fresh trace id (OTel-compatible 16-byte hex) for a new root trace.
|
|
17
|
+
* Children inherit it via {@link InvokeContext.traceId}. */
|
|
18
|
+
newTraceId(): string;
|
|
16
19
|
}
|
|
17
20
|
/** Four-stage resource lifecycle defined in resource-lifecycle.md */
|
|
18
21
|
export type LifecycleState = "Pending" | "Validated" | "Initialized" | "Draining" | "Teardown";
|
|
@@ -86,6 +89,7 @@ export interface EvaluationContext {
|
|
|
86
89
|
invoke<TInputs>(kind: string, name: string, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
|
|
87
90
|
invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
|
|
88
91
|
run(name: string, ctx?: InvokeContext): Promise<void>;
|
|
92
|
+
openSpan(base: InvokeContext | undefined, opts: OpenSpanOptions): Promise<OpenSpan>;
|
|
89
93
|
expand(value: unknown): unknown;
|
|
90
94
|
expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
|
|
91
95
|
expandPaths(value: Record<string, unknown>, paths: string[], excludePaths?: string[]): Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.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,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5B"}
|
package/dist/invoke-step.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
2
|
import type { KindRef, ScopeContext } from "./ref.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type ResourceInstance } from "./resource-instance.js";
|
|
4
4
|
/** Retry policy for a single invoke step, passed through to `ctx.invoke`. */
|
|
5
5
|
export interface InvokeStepRetry {
|
|
6
6
|
attempts?: number;
|
|
@@ -1 +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,
|
|
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,EAAkB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,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,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB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C,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,CAuCf"}
|
package/dist/invoke-step.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getRefIdentity } from "./resource-instance.js";
|
|
1
2
|
/**
|
|
2
3
|
* Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
|
|
3
4
|
* and invoke the target, then record `steps[step.name] = { result }`. Knows
|
|
@@ -12,7 +13,14 @@ export async function executeInvokeStep(step, ctx, state) {
|
|
|
12
13
|
const raw = step.invoke;
|
|
13
14
|
let result;
|
|
14
15
|
if (raw && typeof raw.invoke === "function") {
|
|
15
|
-
|
|
16
|
+
// A pre-injected live instance (a `!ref` resolved at Phase 5). Route it
|
|
17
|
+
// through the traced chokepoint using the identity the kernel stamped at
|
|
18
|
+
// injection, so the call is instrumented exactly like a by-name dispatch.
|
|
19
|
+
// A truly anonymous instance (no stamp) falls back to a direct call.
|
|
20
|
+
const identity = getRefIdentity(raw);
|
|
21
|
+
result = identity
|
|
22
|
+
? await ctx.invokeResolved(identity.kind, identity.name, raw, inputs)
|
|
23
|
+
: await raw.invoke(inputs);
|
|
16
24
|
}
|
|
17
25
|
else {
|
|
18
26
|
const ref = raw;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CancellationSource, InvokeContext } from "./cancellation.js";
|
|
1
|
+
import type { CancellationSource, InvokeContext, OpenSpan, OpenSpanOptions } from "./cancellation.js";
|
|
2
2
|
import { ControllerContext } from "./controller-context.js";
|
|
3
3
|
import { ControllerPolicy } from "./controller-policy.js";
|
|
4
4
|
import { EvaluationContext } from "./evaluation-context.js";
|
|
@@ -40,6 +40,13 @@ export interface ResourceContext extends ControllerContext {
|
|
|
40
40
|
* lambda budget). Pass `source.context` into `invokeResolved` to scope an
|
|
41
41
|
* invocation tree to it. */
|
|
42
42
|
createCancellationSource(): CancellationSource;
|
|
43
|
+
/** Open a trace span for an inbound boundary (an HTTP request, a queue message).
|
|
44
|
+
* Returns a child {@link InvokeContext} to thread into `invokeResolved` so the
|
|
45
|
+
* handler nests under this span, plus `settle` to close it with an outcome.
|
|
46
|
+
* The span roots a fresh trace unless `inbound` continues an upstream one
|
|
47
|
+
* (e.g. a W3C `traceparent`). A no-op (returns `base` unchanged) when tracing
|
|
48
|
+
* is off. */
|
|
49
|
+
openSpan(base: InvokeContext | undefined, opts: OpenSpanOptions): Promise<OpenSpan>;
|
|
43
50
|
invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
|
|
44
51
|
invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
|
|
45
52
|
run(kind: string, name: string): Promise<void>;
|
|
@@ -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,MAAM,mBAAmB,CAAC;
|
|
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,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE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vC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CACxC"}
|
|
@@ -7,4 +7,22 @@ export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Part
|
|
|
7
7
|
teardown?(): void | Promise<void>;
|
|
8
8
|
snapshot?(): Record<string, any> | Promise<Record<string, any>>;
|
|
9
9
|
};
|
|
10
|
+
/** The kind+name an instance was resolved from. */
|
|
11
|
+
export interface RefIdentity {
|
|
12
|
+
kind: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Non-enumerable identity tag the kernel stamps on a live instance when it
|
|
17
|
+
* injects a resolved `!ref` into a slot. A consumer that holds only the bare
|
|
18
|
+
* instance (an `executeInvokeStep` target whose `!ref` was pre-injected) can
|
|
19
|
+
* then recover the kind+name and dispatch through the traced chokepoint
|
|
20
|
+
* (`invokeResolved`) instead of calling `.invoke()` directly and escaping it.
|
|
21
|
+
*/
|
|
22
|
+
export declare const REF_IDENTITY: unique symbol;
|
|
23
|
+
/** Stamp the resolved kind+name onto an injected instance. Idempotent — an
|
|
24
|
+
* instance has exactly one identity, so re-injection into other slots is a no-op. */
|
|
25
|
+
export declare function stampRefIdentity(instance: object, kind: string, name: string): void;
|
|
26
|
+
/** Read the identity stamped by {@link stampRefIdentity}, if any. */
|
|
27
|
+
export declare function getRefIdentity(instance: object): RefIdentity | undefined;
|
|
10
28
|
//# sourceMappingURL=resource-instance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-instance.d.ts","sourceRoot":"","sources":["../src/resource-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,u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C,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjE,CAAC;AAEJ,mDAAmD;AACnD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,OAAO,MAAuC,CAAC;AAE1E;sFACsF;AACtF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CASnF;AAED,qEAAqE;AACrE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAExE"}
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Non-enumerable identity tag the kernel stamps on a live instance when it
|
|
3
|
+
* injects a resolved `!ref` into a slot. A consumer that holds only the bare
|
|
4
|
+
* instance (an `executeInvokeStep` target whose `!ref` was pre-injected) can
|
|
5
|
+
* then recover the kind+name and dispatch through the traced chokepoint
|
|
6
|
+
* (`invokeResolved`) instead of calling `.invoke()` directly and escaping it.
|
|
7
|
+
*/
|
|
8
|
+
export const REF_IDENTITY = Symbol.for("telo.refIdentity");
|
|
9
|
+
/** Stamp the resolved kind+name onto an injected instance. Idempotent — an
|
|
10
|
+
* instance has exactly one identity, so re-injection into other slots is a no-op. */
|
|
11
|
+
export function stampRefIdentity(instance, kind, name) {
|
|
12
|
+
if (!(REF_IDENTITY in instance)) {
|
|
13
|
+
Object.defineProperty(instance, REF_IDENTITY, {
|
|
14
|
+
value: { kind, name },
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: false,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Read the identity stamped by {@link stampRefIdentity}, if any. */
|
|
22
|
+
export function getRefIdentity(instance) {
|
|
23
|
+
return instance[REF_IDENTITY];
|
|
24
|
+
}
|
package/package.json
CHANGED
package/src/cancellation.ts
CHANGED
|
@@ -48,6 +48,36 @@ export interface InvokeContext {
|
|
|
48
48
|
/** The {@link invocationId} of the invocation that dispatched this one, or
|
|
49
49
|
* `undefined` at a trace root. Reconstructs the call tree on the consumer. */
|
|
50
50
|
readonly parentInvocationId?: number;
|
|
51
|
+
/** The trace this invocation belongs to — minted at the root span and inherited
|
|
52
|
+
* by every descendant. Present only while tracing. Groups all spans of one
|
|
53
|
+
* trace the way OpenTelemetry's `trace_id` does (an exporter maps it directly),
|
|
54
|
+
* independent of the parent chain. */
|
|
55
|
+
readonly traceId?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Terminal status of a span — maps to OpenTelemetry span status. */
|
|
59
|
+
export type SpanOutcome = "ok" | "failed" | "rejected" | "cancelled";
|
|
60
|
+
|
|
61
|
+
/** Options for {@link ResourceContext.openSpan}. */
|
|
62
|
+
export interface OpenSpanOptions {
|
|
63
|
+
/** The resource the span is attributed to (an inbound transport's listener,
|
|
64
|
+
* e.g. the `Http.Api`). Becomes the span's `ref`. */
|
|
65
|
+
ref: { kind: string; name: string };
|
|
66
|
+
/** Human label for the span (e.g. `"POST /feedback"`). */
|
|
67
|
+
label?: string;
|
|
68
|
+
/** Structured attributes (e.g. `{ method, path }`). Map to OTel span attributes. */
|
|
69
|
+
attributes?: Record<string, unknown>;
|
|
70
|
+
/** Continue an upstream distributed trace instead of rooting a new one — e.g.
|
|
71
|
+
* seeded from a W3C `traceparent` header. */
|
|
72
|
+
inbound?: { traceId: string; parentSpanId?: number };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Handle returned by {@link ResourceContext.openSpan}. */
|
|
76
|
+
export interface OpenSpan {
|
|
77
|
+
/** Thread into `invokeResolved` so the handler nests under the span. */
|
|
78
|
+
readonly context: InvokeContext;
|
|
79
|
+
/** Close the span with an outcome (emits the span's `end` event). */
|
|
80
|
+
settle(outcome: SpanOutcome, detail?: Record<string, unknown>): Promise<void>;
|
|
51
81
|
}
|
|
52
82
|
|
|
53
83
|
export interface CancellationSource {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InvokeContext } from "./cancellation.js";
|
|
1
|
+
import type { InvokeContext, OpenSpan, OpenSpanOptions } from "./cancellation.js";
|
|
2
2
|
import type { ScopeHandle } from "./ref.js";
|
|
3
3
|
import type { ResourceInstance } from "./resource-instance.js";
|
|
4
4
|
import type { ResourceManifest } from "./resource-manifest.js";
|
|
@@ -19,6 +19,9 @@ export interface Tracer {
|
|
|
19
19
|
readonly enabled: boolean;
|
|
20
20
|
/** Mint the next monotonic invocation id (unique within the kernel run). */
|
|
21
21
|
next(): number;
|
|
22
|
+
/** Mint a fresh trace id (OTel-compatible 16-byte hex) for a new root trace.
|
|
23
|
+
* Children inherit it via {@link InvokeContext.traceId}. */
|
|
24
|
+
newTraceId(): string;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/** Four-stage resource lifecycle defined in resource-lifecycle.md */
|
|
@@ -124,6 +127,7 @@ export interface EvaluationContext {
|
|
|
124
127
|
ctx?: InvokeContext,
|
|
125
128
|
): Promise<any>;
|
|
126
129
|
run(name: string, ctx?: InvokeContext): Promise<void>;
|
|
130
|
+
openSpan(base: InvokeContext | undefined, opts: OpenSpanOptions): Promise<OpenSpan>;
|
|
127
131
|
expand(value: unknown): unknown;
|
|
128
132
|
expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
|
|
129
133
|
expandPaths(
|
package/src/invoke-step.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
2
|
import type { KindRef, ScopeContext } from "./ref.js";
|
|
3
|
-
import type
|
|
3
|
+
import { getRefIdentity, type ResourceInstance } from "./resource-instance.js";
|
|
4
4
|
|
|
5
5
|
/** Retry policy for a single invoke step, passed through to `ctx.invoke`. */
|
|
6
6
|
export interface InvokeStepRetry {
|
|
@@ -94,7 +94,14 @@ export async function executeInvokeStep(
|
|
|
94
94
|
let result: unknown;
|
|
95
95
|
|
|
96
96
|
if (raw && typeof (raw as Invocable).invoke === "function") {
|
|
97
|
-
|
|
97
|
+
// A pre-injected live instance (a `!ref` resolved at Phase 5). Route it
|
|
98
|
+
// through the traced chokepoint using the identity the kernel stamped at
|
|
99
|
+
// injection, so the call is instrumented exactly like a by-name dispatch.
|
|
100
|
+
// A truly anonymous instance (no stamp) falls back to a direct call.
|
|
101
|
+
const identity = getRefIdentity(raw as object);
|
|
102
|
+
result = identity
|
|
103
|
+
? await ctx.invokeResolved(identity.kind, identity.name, raw as ResourceInstance, inputs)
|
|
104
|
+
: await (raw as Invocable).invoke(inputs);
|
|
98
105
|
} else {
|
|
99
106
|
const ref = raw as KindRef<Invocable>;
|
|
100
107
|
if (ref.alias && ref.alias !== "Self") {
|
package/src/resource-context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CancellationSource, InvokeContext } from "./cancellation.js";
|
|
1
|
+
import type { CancellationSource, InvokeContext, OpenSpan, OpenSpanOptions } from "./cancellation.js";
|
|
2
2
|
import { ControllerContext } from "./controller-context.js";
|
|
3
3
|
import { ControllerPolicy } from "./controller-policy.js";
|
|
4
4
|
import { EvaluationContext } from "./evaluation-context.js";
|
|
@@ -49,6 +49,13 @@ export interface ResourceContext extends ControllerContext {
|
|
|
49
49
|
* lambda budget). Pass `source.context` into `invokeResolved` to scope an
|
|
50
50
|
* invocation tree to it. */
|
|
51
51
|
createCancellationSource(): CancellationSource;
|
|
52
|
+
/** Open a trace span for an inbound boundary (an HTTP request, a queue message).
|
|
53
|
+
* Returns a child {@link InvokeContext} to thread into `invokeResolved` so the
|
|
54
|
+
* handler nests under this span, plus `settle` to close it with an outcome.
|
|
55
|
+
* The span roots a fresh trace unless `inbound` continues an upstream one
|
|
56
|
+
* (e.g. a W3C `traceparent`). A no-op (returns `base` unchanged) when tracing
|
|
57
|
+
* is off. */
|
|
58
|
+
openSpan(base: InvokeContext | undefined, opts: OpenSpanOptions): Promise<OpenSpan>;
|
|
52
59
|
invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
|
|
53
60
|
invokeResolved<TInputs>(
|
|
54
61
|
kind: string,
|
package/src/resource-instance.ts
CHANGED
|
@@ -12,3 +12,36 @@ export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Part
|
|
|
12
12
|
teardown?(): void | Promise<void>;
|
|
13
13
|
snapshot?(): Record<string, any> | Promise<Record<string, any>>;
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
/** The kind+name an instance was resolved from. */
|
|
17
|
+
export interface RefIdentity {
|
|
18
|
+
kind: string;
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Non-enumerable identity tag the kernel stamps on a live instance when it
|
|
24
|
+
* injects a resolved `!ref` into a slot. A consumer that holds only the bare
|
|
25
|
+
* instance (an `executeInvokeStep` target whose `!ref` was pre-injected) can
|
|
26
|
+
* then recover the kind+name and dispatch through the traced chokepoint
|
|
27
|
+
* (`invokeResolved`) instead of calling `.invoke()` directly and escaping it.
|
|
28
|
+
*/
|
|
29
|
+
export const REF_IDENTITY: unique symbol = Symbol.for("telo.refIdentity");
|
|
30
|
+
|
|
31
|
+
/** Stamp the resolved kind+name onto an injected instance. Idempotent — an
|
|
32
|
+
* instance has exactly one identity, so re-injection into other slots is a no-op. */
|
|
33
|
+
export function stampRefIdentity(instance: object, kind: string, name: string): void {
|
|
34
|
+
if (!(REF_IDENTITY in instance)) {
|
|
35
|
+
Object.defineProperty(instance, REF_IDENTITY, {
|
|
36
|
+
value: { kind, name } satisfies RefIdentity,
|
|
37
|
+
enumerable: false,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: false,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Read the identity stamped by {@link stampRefIdentity}, if any. */
|
|
45
|
+
export function getRefIdentity(instance: object): RefIdentity | undefined {
|
|
46
|
+
return (instance as Record<symbol, RefIdentity | undefined>)[REF_IDENTITY];
|
|
47
|
+
}
|