@telorun/sdk 0.7.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,3 @@
1
- ---
2
- description: "Node.js SDK: module interfaces, context types, and shared primitives; distinguishes operational vs domain failures via InvokeError"
3
- ---
4
-
5
1
  # Telo SDK (Node.js)
6
2
 
7
3
  The Node.js SDK provides the authoring surface for Telo modules. It defines the shared contracts (types and lifecycle interfaces) that modules use to plug into the kernel, so module code stays consistent across implementations.
@@ -59,6 +59,19 @@ export interface ResourceContext extends ControllerContext {
59
59
  * `runtime:`). Consumers should treat undefined as "auto."
60
60
  */
61
61
  getControllerPolicy(): ControllerPolicy | undefined;
62
+ /**
63
+ * URL of the entry manifest the kernel is running, or `undefined` if the
64
+ * kernel hasn't loaded a manifest yet. Stable for the lifetime of the
65
+ * kernel process once set; identical across every resource regardless of
66
+ * which imported library defined it. Controllers (and the controller-loader)
67
+ * anchor per-manifest install roots here so a single `node_modules` tree
68
+ * and one realpath for `@telorun/sdk` are shared by every controller in
69
+ * the process. The `undefined` case shows up only for callers that bypass
70
+ * `Kernel.load()` (e.g. early in test setup); resource controllers always
71
+ * see a defined value because their `init()` runs after `load()` has
72
+ * recorded it.
73
+ */
74
+ getEntryUrl(): string | undefined;
62
75
  /** Load a single module (its own file + `include`d partials). Use this when
63
76
  * you need just the declaring file's manifests. */
64
77
  loadModule(url: string, options?: LoadOptions): Promise<ResourceManifest[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"resource-context.d.ts","sourceRoot":"","sources":["../src/resource-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CA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,aAAa,CAAC;IACtF,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG,kBAAkB,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI,CAAC;IAC1C,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACjF;;;;OAIG;IACH,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAAC;IACpD;;;;;;;;;;;OAWG;IACH,WAAW,IAAI,MAAM,GAAG,SAAS,CAAC;IAClC;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,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"}
@@ -7,5 +7,5 @@ export interface RuntimeDiagnostic {
7
7
  code?: string;
8
8
  }
9
9
  /** Well-known kernel error codes. User-defined codes (e.g. from Type.JsonSchema rules) are also valid. */
10
- export type RuntimeErrorCode = "ERR_RESOURCE_NOT_FOUND" | "ERR_RESOURCE_NOT_RUNNABLE" | "ERR_CONTROLLER_NOT_FOUND" | "ERR_CONTROLLER_INVALID" | "ERR_RESOURCE_INITIALIZATION_FAILED" | "ERR_RESOURCE_NOT_INVOKABLE" | "ERR_RESOURCE_SCHEMA_VALIDATION_FAILED" | "ERR_DUPLICATE_RESOURCE" | "ERR_EXECUTION_FAILED" | "ERR_INVALID_VALUE" | "ERR_VISIBILITY_DENIED" | "ERR_MANIFEST_VALIDATION_FAILED" | "ERR_CIRCULAR_DEPENDENCY" | "ERR_SCOPE_RESOURCE_NOT_FOUND" | "ERR_TYPE_NOT_FOUND" | "ERR_TYPE_VALIDATION_FAILED" | (string & {});
10
+ export type RuntimeErrorCode = "ERR_RESOURCE_NOT_FOUND" | "ERR_RESOURCE_NOT_RUNNABLE" | "ERR_CONTROLLER_NOT_FOUND" | "ERR_CONTROLLER_INVALID" | "ERR_RESOURCE_INITIALIZATION_FAILED" | "ERR_RESOURCE_NOT_INVOKABLE" | "ERR_RESOURCE_SCHEMA_VALIDATION_FAILED" | "ERR_DUPLICATE_RESOURCE" | "ERR_EXECUTION_FAILED" | "ERR_INVALID_VALUE" | "ERR_VISIBILITY_DENIED" | "ERR_MANIFEST_VALIDATION_FAILED" | "ERR_CIRCULAR_DEPENDENCY" | "ERR_SCOPE_RESOURCE_NOT_FOUND" | "ERR_TYPE_NOT_FOUND" | "ERR_TYPE_VALIDATION_FAILED" | "ERR_KERNEL_STATE_INVALID" | (string & {});
11
11
  //# sourceMappingURL=runtime-error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-error.d.ts","sourceRoot":"","sources":["../src/runtime-error.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,0GAA0G;AAC1G,MAAM,MAAM,gBAAgB,GACxB,wBAAwB,GACxB,2BAA2B,GAC3B,0BAA0B,GAC1B,wBAAwB,GACxB,oCAAoC,GACpC,4BAA4B,GAC5B,uCAAuC,GACvC,wBAAwB,GACxB,sBAAsB,GACtB,mBAAmB,GACnB,uBAAuB,GACvB,gCAAgC,GAChC,yBAAyB,GACzB,8BAA8B,GAC9B,oBAAoB,GACpB,4BAA4B,GAC5B,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"runtime-error.d.ts","sourceRoot":"","sources":["../src/runtime-error.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,0GAA0G;AAC1G,MAAM,MAAM,gBAAgB,GACxB,wBAAwB,GACxB,2BAA2B,GAC3B,0BAA0B,GAC1B,wBAAwB,GACxB,oCAAoC,GACpC,4BAA4B,GAC5B,uCAAuC,GACvC,wBAAwB,GACxB,sBAAsB,GACtB,mBAAmB,GACnB,uBAAuB,GACvB,gCAAgC,GAChC,yBAAyB,GACzB,8BAA8B,GAC9B,oBAAoB,GACpB,4BAA4B,GAC5B,0BAA0B,GAC1B,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC"}
package/dist/stream.d.ts CHANGED
@@ -11,6 +11,18 @@
11
11
  * resulting value a real-class constructor that cel-js can register and
12
12
  * recognize, so `${{ steps.X.result.output }}` evaluations pass through cleanly.
13
13
  *
14
+ * Singleton across sdk copies: cel-js identifies registered types by
15
+ * constructor identity (`v.constructor === RegisteredCtor`). The kernel and
16
+ * any npm-loaded controller can — and routinely do — resolve `@telorun/sdk`
17
+ * to different installs (workspace vs `.telo/npm/<hash>/...`), so two `Stream`
18
+ * classes with the same shape but different identity would silently break
19
+ * stream-typed CEL evaluations with "Unsupported type: Stream". The first
20
+ * `@telorun/sdk` copy to load registers its `Stream` class on `globalThis`
21
+ * under a stable `Symbol.for("@telorun/sdk:Stream")` key; later copies discard
22
+ * their local declaration at export time and re-export the registered one.
23
+ * Every Stream value in the process shares one constructor regardless of
24
+ * install topology — no build artifact or `file:` symlink required.
25
+ *
14
26
  * The companion analyzer registers `Stream` as a CEL object type with no
15
27
  * fields — terminal access (passing the value through) succeeds, member access
16
28
  * (`result.output.text`, `result.output[0]`) raises a CEL error at runtime,
@@ -24,9 +36,14 @@
24
36
  * patterns work without unwrapping. Internally it forwards `Symbol.asyncIterator`
25
37
  * to the underlying iterable.
26
38
  */
27
- export declare class Stream<T = unknown> implements AsyncIterable<T> {
28
- private readonly source;
29
- constructor(source: AsyncIterable<T>);
30
- [Symbol.asyncIterator](): AsyncIterator<T>;
39
+ interface Stream<T = unknown> extends AsyncIterable<T> {
31
40
  }
41
+ declare const LocalStream: {
42
+ new <T = unknown>(source: AsyncIterable<T>): {
43
+ "__#private@#source": AsyncIterable<T>;
44
+ [Symbol.asyncIterator](): AsyncIterator<T>;
45
+ };
46
+ };
47
+ declare const Stream: typeof LocalStream;
48
+ export { Stream };
32
49
  //# sourceMappingURL=stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,MAAM,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;IAErD,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;CAG3C"}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,UAAU,MAAM,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAG;AAOzD,QAAA,MAAM,WAAW;SAAgB,CAAC,oBAMZ,aAAa,CAAC,CAAC,CAAC;8BAF3B,aAAa,CAAC,CAAC,CAAC;kCAMC,aAAa,CAAC,CAAC,CAAC;;CAG3C,CAAC;AAUF,QAAA,MAAM,MAAM,EAAE,OAAO,WAA0D,CAAC;AAMhF,OAAO,EAAE,MAAM,EAAE,CAAC"}
package/dist/stream.js CHANGED
@@ -11,6 +11,18 @@
11
11
  * resulting value a real-class constructor that cel-js can register and
12
12
  * recognize, so `${{ steps.X.result.output }}` evaluations pass through cleanly.
13
13
  *
14
+ * Singleton across sdk copies: cel-js identifies registered types by
15
+ * constructor identity (`v.constructor === RegisteredCtor`). The kernel and
16
+ * any npm-loaded controller can — and routinely do — resolve `@telorun/sdk`
17
+ * to different installs (workspace vs `.telo/npm/<hash>/...`), so two `Stream`
18
+ * classes with the same shape but different identity would silently break
19
+ * stream-typed CEL evaluations with "Unsupported type: Stream". The first
20
+ * `@telorun/sdk` copy to load registers its `Stream` class on `globalThis`
21
+ * under a stable `Symbol.for("@telorun/sdk:Stream")` key; later copies discard
22
+ * their local declaration at export time and re-export the registered one.
23
+ * Every Stream value in the process shares one constructor regardless of
24
+ * install topology — no build artifact or `file:` symlink required.
25
+ *
14
26
  * The companion analyzer registers `Stream` as a CEL object type with no
15
27
  * fields — terminal access (passing the value through) succeeds, member access
16
28
  * (`result.output.text`, `result.output[0]`) raises a CEL error at runtime,
@@ -24,12 +36,34 @@
24
36
  * patterns work without unwrapping. Internally it forwards `Symbol.asyncIterator`
25
37
  * to the underlying iterable.
26
38
  */
27
- export class Stream {
28
- source;
39
+ // Value binding (private): the class declaration that supplies the runtime
40
+ // implementation. Written as a named class expression so `.name === "Stream"`
41
+ // — debuggers, stack traces, and `Object.prototype.toString` all see "Stream",
42
+ // not the const name. The inner `Stream` identifier is only visible inside
43
+ // the class body (for self-reference); it does not shadow the outer interface.
44
+ const LocalStream = class Stream {
45
+ // ECMAScript private field rather than TS `private readonly` — the latter
46
+ // shows up in the inferred type signature, which TS then refuses to export
47
+ // through an anonymous class expression (TS4094).
48
+ #source;
29
49
  constructor(source) {
30
- this.source = source;
50
+ this.#source = source;
31
51
  }
32
52
  [Symbol.asyncIterator]() {
33
- return this.source[Symbol.asyncIterator]();
53
+ return this.#source[Symbol.asyncIterator]();
34
54
  }
35
- }
55
+ };
56
+ const STREAM_KEY = Symbol.for("@telorun/sdk:Stream");
57
+ const globalSlot = globalThis;
58
+ if (!(STREAM_KEY in globalSlot))
59
+ globalSlot[STREAM_KEY] = LocalStream;
60
+ // The exported value: whichever Stream class won the globalThis race (first
61
+ // sdk copy to import this module). Later copies discard their `LocalStream`
62
+ // at export time and route through the winner — keeping constructor identity
63
+ // stable across the kernel/controller realm boundary.
64
+ const Stream = globalSlot[STREAM_KEY];
65
+ // `export { Stream }` re-exports the value binding (the const above) and the
66
+ // type binding (the interface above) under the same name — TypeScript treats
67
+ // value/type as separate namespaces, so a consumer's `import { Stream }`
68
+ // receives both `new Stream(...)` and `Stream<T>`.
69
+ export { Stream };
package/dist/types.d.ts CHANGED
@@ -83,12 +83,48 @@ export interface ControllerInstance<TResource extends ResourceManifest = Resourc
83
83
  }
84
84
  export interface Kernel {
85
85
  load(url: string): Promise<void>;
86
+ /**
87
+ * Boot: initialize resources without running targets. Returns when every
88
+ * resource is initialized and the kernel is ready to accept `invoke()`
89
+ * calls. Throws ERR_KERNEL_STATE_INVALID if called twice or after teardown.
90
+ */
91
+ boot(): Promise<void>;
92
+ /**
93
+ * Run the manifest's `targets` (Telo.Service / Telo.Runnable instances).
94
+ * Throws ERR_KERNEL_STATE_INVALID if called before `boot()` completes, after
95
+ * teardown, or a second time.
96
+ */
97
+ runTargets(): Promise<void>;
98
+ /**
99
+ * Tear down every initialized resource. Idempotent — second call is a no-op
100
+ * and does not re-emit Kernel.Stopping / Kernel.Stopped. Tolerates partial
101
+ * state (a boot() that threw mid-init still cleans up).
102
+ */
103
+ teardown(): Promise<void>;
104
+ /**
105
+ * Invoke a Telo.Invocable resource by name. Throws ERR_KERNEL_STATE_INVALID
106
+ * if called before boot() or after teardown.
107
+ */
108
+ invoke<TInputs = any, TOutput = any>(ref: string | {
109
+ kind: string;
110
+ name: string;
111
+ }, inputs: TInputs): Promise<TOutput>;
112
+ /**
113
+ * Convenience: boot → runTargets → waitForIdle → teardown, with teardown
114
+ * always running via finally so init-time failures still tear down.
115
+ */
86
116
  start(): Promise<void>;
87
117
  acquireHold(reason?: string): () => void;
88
118
  waitForIdle(): Promise<void>;
119
+ /**
120
+ * Force-resolve a pending `waitForIdle()` even when holds are still active.
121
+ * Used by external signal handlers (SIGINT/SIGTERM) so graceful exit can
122
+ * proceed past `await kernel.waitForIdle()`. Does not tear down — call
123
+ * `teardown()` for cleanup.
124
+ */
125
+ forceIdle(): void;
89
126
  requestExit(code: number): void;
90
127
  readonly exitCode: number;
91
- shutdown(): void;
92
128
  }
93
129
  export declare class RuntimeError extends Error {
94
130
  code: RuntimeErrorCode;
@@ -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;CACh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AAC;IACvB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;IACzC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B;;;;;OAKG;IACH,SAAS,IAAI,IAAI,CAAC;IAClB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,YAAa,SAAQ,KAAK;IAE5B,IAAI,EAAE,gBAAgB;IAEtB,WAAW,CAAC,EAAE,iBAAiB,EAAE;gBAFjC,IAAI,EAAE,gBAAgB,EAC7B,OAAO,EAAE,MAAM,EACR,WAAW,CAAC,EAAE,iBAAiB,EAAE,YAAA;CAK3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/sdk",
3
- "version": "0.7.0",
3
+ "version": "0.11.1",
4
4
  "description": "Telo SDK - Public API for Telo module authors.",
5
5
  "keywords": [
6
6
  "telo",
@@ -70,6 +70,19 @@ export interface ResourceContext extends ControllerContext {
70
70
  * `runtime:`). Consumers should treat undefined as "auto."
71
71
  */
72
72
  getControllerPolicy(): ControllerPolicy | undefined;
73
+ /**
74
+ * URL of the entry manifest the kernel is running, or `undefined` if the
75
+ * kernel hasn't loaded a manifest yet. Stable for the lifetime of the
76
+ * kernel process once set; identical across every resource regardless of
77
+ * which imported library defined it. Controllers (and the controller-loader)
78
+ * anchor per-manifest install roots here so a single `node_modules` tree
79
+ * and one realpath for `@telorun/sdk` are shared by every controller in
80
+ * the process. The `undefined` case shows up only for callers that bypass
81
+ * `Kernel.load()` (e.g. early in test setup); resource controllers always
82
+ * see a defined value because their `init()` runs after `load()` has
83
+ * recorded it.
84
+ */
85
+ getEntryUrl(): string | undefined;
73
86
  /** Load a single module (its own file + `include`d partials). Use this when
74
87
  * you need just the declaring file's manifests. */
75
88
  loadModule(url: string, options?: LoadOptions): Promise<ResourceManifest[]>;
@@ -25,4 +25,5 @@ export type RuntimeErrorCode =
25
25
  | "ERR_SCOPE_RESOURCE_NOT_FOUND"
26
26
  | "ERR_TYPE_NOT_FOUND"
27
27
  | "ERR_TYPE_VALIDATION_FAILED"
28
+ | "ERR_KERNEL_STATE_INVALID"
28
29
  | (string & {});
package/src/stream.ts CHANGED
@@ -11,6 +11,18 @@
11
11
  * resulting value a real-class constructor that cel-js can register and
12
12
  * recognize, so `${{ steps.X.result.output }}` evaluations pass through cleanly.
13
13
  *
14
+ * Singleton across sdk copies: cel-js identifies registered types by
15
+ * constructor identity (`v.constructor === RegisteredCtor`). The kernel and
16
+ * any npm-loaded controller can — and routinely do — resolve `@telorun/sdk`
17
+ * to different installs (workspace vs `.telo/npm/<hash>/...`), so two `Stream`
18
+ * classes with the same shape but different identity would silently break
19
+ * stream-typed CEL evaluations with "Unsupported type: Stream". The first
20
+ * `@telorun/sdk` copy to load registers its `Stream` class on `globalThis`
21
+ * under a stable `Symbol.for("@telorun/sdk:Stream")` key; later copies discard
22
+ * their local declaration at export time and re-export the registered one.
23
+ * Every Stream value in the process shares one constructor regardless of
24
+ * install topology — no build artifact or `file:` symlink required.
25
+ *
14
26
  * The companion analyzer registers `Stream` as a CEL object type with no
15
27
  * fields — terminal access (passing the value through) succeeds, member access
16
28
  * (`result.output.text`, `result.output[0]`) raises a CEL error at runtime,
@@ -24,10 +36,43 @@
24
36
  * patterns work without unwrapping. Internally it forwards `Symbol.asyncIterator`
25
37
  * to the underlying iterable.
26
38
  */
27
- export class Stream<T = unknown> implements AsyncIterable<T> {
28
- constructor(private readonly source: AsyncIterable<T>) {}
39
+
40
+ // Type binding: `Stream<T>` as written by consumers (`let s: Stream<number>`)
41
+ // resolves to this interface. The class below also conforms to it.
42
+ interface Stream<T = unknown> extends AsyncIterable<T> {}
43
+
44
+ // Value binding (private): the class declaration that supplies the runtime
45
+ // implementation. Written as a named class expression so `.name === "Stream"`
46
+ // — debuggers, stack traces, and `Object.prototype.toString` all see "Stream",
47
+ // not the const name. The inner `Stream` identifier is only visible inside
48
+ // the class body (for self-reference); it does not shadow the outer interface.
49
+ const LocalStream = class Stream<T = unknown> implements AsyncIterable<T> {
50
+ // ECMAScript private field rather than TS `private readonly` — the latter
51
+ // shows up in the inferred type signature, which TS then refuses to export
52
+ // through an anonymous class expression (TS4094).
53
+ #source: AsyncIterable<T>;
54
+
55
+ constructor(source: AsyncIterable<T>) {
56
+ this.#source = source;
57
+ }
29
58
 
30
59
  [Symbol.asyncIterator](): AsyncIterator<T> {
31
- return this.source[Symbol.asyncIterator]();
60
+ return this.#source[Symbol.asyncIterator]();
32
61
  }
33
- }
62
+ };
63
+
64
+ const STREAM_KEY = Symbol.for("@telorun/sdk:Stream");
65
+ const globalSlot = globalThis as Record<symbol, unknown>;
66
+ if (!(STREAM_KEY in globalSlot)) globalSlot[STREAM_KEY] = LocalStream;
67
+
68
+ // The exported value: whichever Stream class won the globalThis race (first
69
+ // sdk copy to import this module). Later copies discard their `LocalStream`
70
+ // at export time and route through the winner — keeping constructor identity
71
+ // stable across the kernel/controller realm boundary.
72
+ const Stream: typeof LocalStream = globalSlot[STREAM_KEY] as typeof LocalStream;
73
+
74
+ // `export { Stream }` re-exports the value binding (the const above) and the
75
+ // type binding (the interface above) under the same name — TypeScript treats
76
+ // value/type as separate namespaces, so a consumer's `import { Stream }`
77
+ // receives both `new Stream(...)` and `Stream<T>`.
78
+ export { Stream };
package/src/types.ts CHANGED
@@ -94,15 +94,48 @@ export interface ControllerInstance<
94
94
 
95
95
  export interface Kernel {
96
96
  load(url: string): Promise<void>;
97
+ /**
98
+ * Boot: initialize resources without running targets. Returns when every
99
+ * resource is initialized and the kernel is ready to accept `invoke()`
100
+ * calls. Throws ERR_KERNEL_STATE_INVALID if called twice or after teardown.
101
+ */
102
+ boot(): Promise<void>;
103
+ /**
104
+ * Run the manifest's `targets` (Telo.Service / Telo.Runnable instances).
105
+ * Throws ERR_KERNEL_STATE_INVALID if called before `boot()` completes, after
106
+ * teardown, or a second time.
107
+ */
108
+ runTargets(): Promise<void>;
109
+ /**
110
+ * Tear down every initialized resource. Idempotent — second call is a no-op
111
+ * and does not re-emit Kernel.Stopping / Kernel.Stopped. Tolerates partial
112
+ * state (a boot() that threw mid-init still cleans up).
113
+ */
114
+ teardown(): Promise<void>;
115
+ /**
116
+ * Invoke a Telo.Invocable resource by name. Throws ERR_KERNEL_STATE_INVALID
117
+ * if called before boot() or after teardown.
118
+ */
119
+ invoke<TInputs = any, TOutput = any>(
120
+ ref: string | { kind: string; name: string },
121
+ inputs: TInputs,
122
+ ): Promise<TOutput>;
123
+ /**
124
+ * Convenience: boot → runTargets → waitForIdle → teardown, with teardown
125
+ * always running via finally so init-time failures still tear down.
126
+ */
97
127
  start(): Promise<void>;
98
128
  acquireHold(reason?: string): () => void;
99
129
  waitForIdle(): Promise<void>;
130
+ /**
131
+ * Force-resolve a pending `waitForIdle()` even when holds are still active.
132
+ * Used by external signal handlers (SIGINT/SIGTERM) so graceful exit can
133
+ * proceed past `await kernel.waitForIdle()`. Does not tear down — call
134
+ * `teardown()` for cleanup.
135
+ */
136
+ forceIdle(): void;
100
137
  requestExit(code: number): void;
101
138
  readonly exitCode: number;
102
- // teardownResource(module: string, kind: string, name: string): Promise<void>;
103
- // getSourceFiles(): string[];
104
- // reloadSource(sourcePath: string): Promise<void>;
105
- shutdown(): void;
106
139
  }
107
140
 
108
141
  export class RuntimeError extends Error {