@telorun/sdk 0.2.7 → 0.3.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 (41) hide show
  1. package/README.md +54 -0
  2. package/dist/compiled-value.d.ts +2 -0
  3. package/dist/compiled-value.d.ts.map +1 -1
  4. package/dist/evaluation-context.d.ts +16 -102
  5. package/dist/evaluation-context.d.ts.map +1 -1
  6. package/dist/evaluation-context.js +0 -390
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -0
  10. package/dist/invoke-error.d.ts +14 -0
  11. package/dist/invoke-error.d.ts.map +1 -0
  12. package/dist/invoke-error.js +34 -0
  13. package/dist/module-context.d.ts +12 -36
  14. package/dist/module-context.d.ts.map +1 -1
  15. package/dist/module-context.js +1 -177
  16. package/dist/ref.d.ts +1 -1
  17. package/dist/ref.d.ts.map +1 -1
  18. package/dist/ref.js +1 -1
  19. package/dist/resource-context.d.ts +17 -0
  20. package/dist/resource-context.d.ts.map +1 -1
  21. package/dist/types.d.ts +16 -0
  22. package/dist/types.d.ts.map +1 -1
  23. package/package.json +19 -1
  24. package/src/compiled-value.ts +2 -0
  25. package/src/evaluation-context.ts +45 -461
  26. package/src/index.ts +1 -0
  27. package/src/invoke-error.ts +39 -0
  28. package/src/module-context.ts +22 -203
  29. package/src/ref.ts +1 -1
  30. package/src/resource-context.ts +23 -0
  31. package/src/types.ts +18 -0
  32. package/dist/capability-definition.d.ts +0 -8
  33. package/dist/capability-definition.d.ts.map +0 -1
  34. package/dist/capability-definition.js +0 -21
  35. package/dist/cel-environment.d.ts +0 -3
  36. package/dist/cel-environment.d.ts.map +0 -1
  37. package/dist/cel-environment.js +0 -13
  38. package/dist/execution-context.d.ts +0 -13
  39. package/dist/execution-context.d.ts.map +0 -1
  40. package/dist/execution-context.js +0 -13
  41. package/src/execution-context.ts +0 -21
@@ -1,10 +1,7 @@
1
- import { isCompiledValue } from "./compiled-value.js";
2
- import type { ModuleContext } from "./module-context.js";
3
- import type { ScopeContext, ScopeHandle } from "./ref.js";
4
- import { ResourceInstance } from "./resource-instance.js";
5
- import { ResourceManifest } from "./resource-manifest.js";
6
- import { RuntimeDiagnostic } from "./runtime-error.js";
7
- import { RuntimeError } from "./types.js";
1
+ import type { ScopeHandle } from "./ref.js";
2
+ import type { ResourceInstance } from "./resource-instance.js";
3
+ import type { ResourceManifest } from "./resource-manifest.js";
4
+ import type { ResourceDefinition } from "./types.js";
8
5
 
9
6
  export type EmitEvent = (event: string, payload?: any) => void | Promise<void>;
10
7
 
@@ -25,7 +22,7 @@ export type CreatedResource = { instance: ResourceInstance; ctx: any };
25
22
  * init() separately in a second phase.
26
23
  */
27
24
  export type InstanceFactory = (
28
- moduleContext: ModuleContext,
25
+ context: EvaluationContext,
29
26
  resource: ResourceManifest,
30
27
  ) => Promise<CreatedResource | null>;
31
28
 
@@ -49,471 +46,58 @@ export function resourceKey(r: ResourceManifest): string {
49
46
  }
50
47
 
51
48
  /**
52
- * Base class for all evaluation contexts. Owns template
53
- * expansion, secrets redaction, and the generic resource lifecycle tree.
49
+ * Public contract for the base evaluation context.
54
50
  *
55
- * Every EvaluationContext node can:
56
- * - Hold its own resource instances (resourceInstances)
57
- * - Queue resources for initialization (pendingResources)
58
- * - Spawn child contexts (spawnChild) forming a lifecycle tree
59
- * - Run a multi-pass initialization loop (initializeResources)
60
- * - Cascade teardown depth-first through the tree (teardownResources)
51
+ * Owns template expansion, secrets redaction, and the generic resource lifecycle tree.
52
+ * The class implementation lives in `@telorun/kernel`.
61
53
  */
62
- export class EvaluationContext {
63
- readonly id = Math.random().toString(16).slice(2, 8);
64
- protected _context: Record<string, unknown>;
65
- protected _secretValues: Set<string>;
66
- protected _createInstance: InstanceFactory;
54
+ export interface EvaluationContext {
55
+ readonly id: string;
56
+ readonly source: string;
67
57
  readonly emit: EmitEvent;
68
58
 
69
- /** Position in the lifecycle tree. */
70
- parent: EvaluationContext | undefined = undefined;
71
- readonly children: EvaluationContext[] = [];
59
+ parent: EvaluationContext | undefined;
60
+ readonly children: EvaluationContext[];
72
61
 
73
- /** Current lifecycle state of this context node. */
74
- state: LifecycleState = "Pending";
62
+ state: LifecycleState;
75
63
 
76
- /** Resource instances owned by this context node, keyed by resourceKey(). */
77
- readonly resourceInstances = new Map<
64
+ readonly resourceInstances: Map<
78
65
  string,
79
66
  { resource: ResourceManifest; instance: ResourceInstance }
80
- >();
67
+ >;
81
68
 
82
- /** Resources that have been created but not yet initialized (between phases). */
83
- protected readonly createdInstances = new Map<
84
- string,
85
- { resource: ResourceManifest; instance: ResourceInstance; ctx: any }
86
- >();
87
-
88
- /** Resources queued for initialization on this context node. */
89
- private pendingResources: ResourceManifest[] = [];
90
-
91
- /**
92
- * Optional hook called between create() and init() for each resource.
93
- * Set by the kernel to inject live instances into reference fields.
94
- */
95
69
  preInitHook?: PreInitHook;
96
70
 
97
- constructor(
98
- readonly source: string,
99
- context: Record<string, unknown>,
100
- createInstance: InstanceFactory = async () => null,
101
- secretValues: Set<string>,
102
- emit: EmitEvent,
103
- ) {
104
- this._context = context;
105
- this._createInstance = createInstance;
106
- this._secretValues = secretValues ?? new Set();
107
- this.emit = emit;
108
- }
109
-
110
- get createInstance(): InstanceFactory {
111
- return this._createInstance;
112
- }
113
-
114
- /** Called after init() when a resource snapshot is available. Overridden by ModuleContext. */
115
- protected onResourceSnapshotted(_name: string, _snap: Record<string, unknown>): void {}
116
-
117
- get context(): Record<string, unknown> {
118
- return this._context;
119
- }
120
-
121
- get secretValues(): Set<string> {
122
- return this._secretValues;
123
- }
124
-
125
- /**
126
- * Reorder pending resources to match the given name sequence (topo order from Phase 4).
127
- * Resources not present in `names` are left at the end in their original order.
128
- * Call before initializeResources() so the create/init sub-phases run in dependency order,
129
- * guaranteeing that Phase 5 injection always finds initialized dependencies.
130
- */
131
- setInitOrder(names: string[]): void {
132
- const rank = new Map(names.map((n, i) => [n, i]));
133
- this.pendingResources.sort((a, b) => {
134
- const ra = rank.get(a.metadata.name as string) ?? Infinity;
135
- const rb = rank.get(b.metadata.name as string) ?? Infinity;
136
- return ra - rb;
137
- });
138
- }
139
-
140
- /**
141
- * Queue a resource manifest for initialization on this context.
142
- */
143
- hasManifest(name: string): boolean {
144
- return (
145
- this.resourceInstances.has(name) ||
146
- this.createdInstances.has(name) ||
147
- this.pendingResources.some((r) => r.metadata.name === name)
148
- );
149
- }
150
-
151
- registerManifest(resource: ResourceManifest): void {
152
- if (!resource.metadata) {
153
- resource.metadata = { name: `__unnamed_${Math.random().toString(16).slice(2, 8)}` };
154
- }
155
- const name = resource.metadata.name;
156
- if (this.hasManifest(name)) {
157
- throw new RuntimeError("ERR_DUPLICATE_RESOURCE", `Resource '${name}' is already registered`);
158
- }
159
- this.pendingResources.push(resource);
160
- }
161
-
162
- /**
163
- * Attach a child context to this node. The child's parent is set to this
164
- * context and the child is registered under the given name.
165
- */
166
- spawnChild<T extends EvaluationContext>(child: T): T {
167
- child.parent = this;
168
- this.children.push(child);
169
- // Propagate injection hook so all child contexts (module imports, scopes) participate
170
- // in Phase 5 injection. createScopeHandle overrides this with an extended version.
171
- if (this.preInitHook && !child.preInitHook) {
172
- child.preInitHook = this.preInitHook;
173
- }
174
- return child;
175
- }
176
-
177
- /**
178
- * Interleaved create/init loop.
179
- *
180
- * Each pass has two sub-phases run back-to-back:
181
- * 1. Create sub-phase: call controller.create() for each pending resource that
182
- * hasn't been created yet. Successful results go into createdInstances.
183
- * 2. Init sub-phase: call instance.init(ctx) for each created-but-not-inited
184
- * resource. Successful results go into resourceInstances.
185
- *
186
- * Interleaving is necessary because some resources' create() depends on effects
187
- * produced by other resources' init() (e.g. Kernel.Import.init() runs
188
- * child.initializeResources() which registers controllers needed by sibling
189
- * resources' create()). Running both sub-phases each pass lets those effects
190
- * propagate before the next create attempt.
191
- *
192
- * Each resource is created at most once and inited at most once.
193
- * ERR_VISIBILITY_DENIED is fatal and re-thrown immediately.
194
- * All other errors are tracked and retried until no progress is made.
195
- */
196
- async initializeResources(): Promise<void> {
197
- const MAX_PASSES = 10;
198
- const errors = new Map<string, string>();
199
-
200
- let pass = 1;
201
- do {
202
- let progress = false;
203
-
204
- // Create sub-phase
205
- for (const resource of [...this.pendingResources]) {
206
- const name = resource.metadata.name;
207
- if (this.createdInstances.has(name)) continue;
208
- try {
209
- // const expanded = this.expand(resource) as ResourceManifest;
210
- // FIXME: Cannot expand it for all resources, needs to be selective
211
- const created = await this._createInstance(this as any, resource);
212
- if (created) {
213
- this.createdInstances.set(name, {
214
- resource,
215
- instance: created.instance,
216
- ctx: created.ctx,
217
- });
218
- const idx = this.pendingResources.findIndex((m) => m.metadata.name === name);
219
- if (idx >= 0) this.pendingResources.splice(idx, 1);
220
- errors.delete(name);
221
- progress = true;
222
- }
223
- } catch (error) {
224
- if (error instanceof RuntimeError && error.code === "ERR_VISIBILITY_DENIED") throw error;
225
- errors.set(name, error instanceof Error ? error.message : String(error));
226
- }
227
- }
228
-
229
- // Init sub-phase
230
- for (const [name, { resource, instance, ctx }] of [...this.createdInstances]) {
231
- if (this.resourceInstances.has(name)) continue;
232
- try {
233
- if (this.preInitHook) {
234
- this.preInitHook(resource, (n) => this.resourceInstances.get(n)?.instance);
235
- }
236
- if (instance.init) await instance.init(ctx);
237
- if (instance.snapshot) {
238
- const snap = await Promise.resolve(instance.snapshot()).catch(() => ({}));
239
- this.onResourceSnapshotted(name, (snap as Record<string, unknown>) ?? {});
240
- }
241
- this.resourceInstances.set(name, { resource, instance });
242
- this.createdInstances.delete(name);
243
- errors.delete(name);
244
- progress = true;
245
- } catch (error) {
246
- if (error instanceof RuntimeError && error.code === "ERR_VISIBILITY_DENIED") throw error;
247
- errors.set(name, error instanceof Error ? error.message : String(error));
248
- }
249
- }
250
-
251
- pass++;
252
- if (!progress) break;
253
- } while (pass <= MAX_PASSES);
254
-
255
- if (this.pendingResources.length > 0 || this.createdInstances.size > 0) {
256
- const diagnostics: RuntimeDiagnostic[] = [
257
- ...this.pendingResources.map((r) => ({
258
- resource: r.metadata.name,
259
- message: errors.get(r.metadata.name) ?? "Unknown error",
260
- })),
261
- ...[...this.createdInstances.keys()].map((name) => ({
262
- resource: name,
263
- message: errors.get(name) ?? "Unknown error",
264
- })),
265
- ];
266
- throw new RuntimeError(
267
- "ERR_RESOURCE_INITIALIZATION_FAILED",
268
- "Unable to process resources",
269
- diagnostics,
270
- );
271
- }
272
-
273
- this.state = "Initialized";
274
- }
275
-
276
- withManifests<T>(manifests: any[], fn: () => T): T {
277
- const child = this.spawnChild(
278
- new EvaluationContext(
279
- this.source,
280
- this._context,
281
- this._createInstance,
282
- this._secretValues,
283
- this.emit,
284
- ),
285
- );
286
- try {
287
- for (const manifest of manifests) {
288
- child.registerManifest(manifest);
289
- }
290
- return fn();
291
- } finally {
292
- // Tear down child context and its resources immediately after fn() completes.
293
- // Note that this does NOT emit Kernel-level events (e.g. Teardown events) —
294
- // they remain the Kernel's responsibility.
295
- child.teardownResources();
296
- }
297
- }
298
-
299
- /**
300
- * Returns a ScopeHandle that initializes `manifests` in a fresh child context each time
301
- * `run()` is called, executes the callback with a ScopeContext, and tears down when done.
302
- *
303
- * The child inherits the parent's preInitHook (if any), extended so that `getInstance`
304
- * also checks the parent's already-initialized singleton instances. This lets scoped
305
- * resources hold x-telo-ref slots pointing to outer resources — those deps are already
306
- * live when the scope opens.
307
- */
308
- createScopeHandle(manifests: ResourceManifest[]): ScopeHandle {
309
- const parent = this;
310
- return {
311
- async run<T>(fn: (scope: ScopeContext) => Promise<T>): Promise<T> {
312
- const child = parent.spawnChild(
313
- new EvaluationContext(
314
- parent.source,
315
- parent._context,
316
- parent._createInstance,
317
- parent._secretValues,
318
- parent.emit,
319
- ),
320
- );
321
-
322
- // Propagate injection hook: extend getInstance to also resolve parent singleton instances.
323
- if (parent.preInitHook) {
324
- const parentHook = parent.preInitHook;
325
- child.preInitHook = (resource, childGetInstance) => {
326
- parentHook(
327
- resource,
328
- (name) => childGetInstance(name) ?? parent.resourceInstances.get(name)?.instance,
329
- );
330
- };
331
- }
332
-
333
- try {
334
- for (const manifest of manifests) {
335
- child.registerManifest(manifest);
336
- }
337
- await child.initializeResources();
338
- const scope: ScopeContext = {
339
- getInstance(name: string): ResourceInstance {
340
- const childEntry = child.resourceInstances.get(name);
341
- if (childEntry) return childEntry.instance;
342
- const parentEntry = parent.resourceInstances.get(name);
343
- if (parentEntry) return parentEntry.instance;
344
- throw new RuntimeError(
345
- "ERR_SCOPE_RESOURCE_NOT_FOUND",
346
- `Resource '${name}' not found in scope or outer context. Available scoped: ${[...child.resourceInstances.keys()].join(", ")}`,
347
- );
348
- },
349
- };
350
- return await fn(scope);
351
- } finally {
352
- await child.teardownResources();
353
- const idx = parent.children.indexOf(child);
354
- if (idx >= 0) parent.children.splice(idx, 1);
355
- }
356
- },
357
- };
358
- }
359
-
360
- /**
361
- * Cascade teardown depth-first through the tree:
362
- * 1. Tear down child contexts in reverse registration order.
363
- * 2. Tear down own resource instances in reverse registration order,
364
- * emitting a Teardown event for each via the injected emit callback.
365
- */
366
- async teardownResources(): Promise<void> {
367
- this.state = "Draining";
368
- for (const child of [...this.children].reverse()) {
369
- await child.teardownResources();
370
- }
371
- const entries = [...this.resourceInstances.entries()].reverse();
372
- for (const [key, { resource, instance }] of entries) {
373
- if (instance.teardown) await instance.teardown();
374
- await this.emit(`${resource.kind}.${resource.metadata.name}.Teardown`, {
375
- resource: { kind: resource.kind, name: resource.metadata.name },
376
- });
377
- this.resourceInstances.delete(key);
378
- }
379
- this.state = "Teardown";
380
- }
381
-
382
- transientChild(context: Record<string, any>): EvaluationContext {
383
- return new EvaluationContext(
384
- this.source,
385
- { ...this.context, ...context },
386
- this._createInstance,
387
- this._secretValues,
388
- this.emit,
389
- );
390
- }
391
-
392
- /**
393
- * Invoke a resource by kind and name within this context's resourceInstances.
394
- * Emits a scoped Invoked event via the injected emit callback after invocation.
395
- */
396
- async invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any> {
397
- const entry = this.resourceInstances.get(name);
398
-
399
- if (entry) {
400
- if (typeof entry.instance.invoke !== "function") {
401
- throw new RuntimeError(
402
- "ERR_RESOURCE_NOT_INVOKABLE",
403
- `Resource ${kind}.${name} does not have an invoke method`,
404
- );
405
- }
406
- const outputs = await entry.instance.invoke(inputs as any);
407
- await this.emit(`${kind}.${name}.Invoked`, { outputs });
408
- return outputs;
409
- }
410
-
411
- throw new RuntimeError(
412
- "ERR_RESOURCE_NOT_FOUND",
413
- `Resource not found for invocation: ${kind}.${name}. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`,
414
- );
415
- }
416
-
417
- async run(name: string): Promise<void> {
418
- const entry = this.resourceInstances.get(name);
419
- if (entry && typeof entry.instance.run === "function") {
420
- return entry.instance.run();
421
- }
422
- throw new RuntimeError(
423
- "ERR_RESOURCE_NOT_RUNNABLE",
424
- `Resource ${name} is not runnable or not found. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`,
425
- );
426
- }
427
-
428
- /**
429
- * Expand a value that may contain precompiled ${{ }} templates.
430
- * Works recursively over CompiledValues, arrays, and objects.
431
- */
432
- expand(value: unknown): unknown {
433
- if (isCompiledValue(value)) {
434
- return value.call(this._context);
435
- }
436
- if (Array.isArray(value)) {
437
- return value.map((entry) => this.expand(entry));
438
- }
439
- if (value !== null && typeof value === "object") {
440
- const resolved: Record<string, unknown> = {};
441
- for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
442
- resolved[key] = this.expand(entry);
443
- }
444
- return resolved;
445
- }
446
- return value;
447
- }
448
-
449
- /**
450
- * Expand a value using this context merged with additional properties.
451
- * Equivalent to merge(extraContext).expand(value) without allocating a context object.
452
- */
453
- expandWith(value: unknown, extraContext: Record<string, unknown>): unknown {
454
- const saved = this._context;
455
- this._context = Object.assign(Object.create(null), saved, extraContext) as Record<
456
- string,
457
- unknown
458
- >;
459
- try {
460
- return this.expand(value);
461
- } finally {
462
- this._context = saved;
463
- }
464
- }
465
-
466
- /**
467
- * Expand specific dot-paths within an object. '**' expands the entire object.
468
- * Paths listed in excludePaths are left untouched (runtime takes precedence).
469
- * Always throws if an expression cannot be resolved.
470
- */
71
+ /** Looks up a registered resource definition by fully-qualified kind.
72
+ * Set by the kernel; used for declared-throw-union checks. */
73
+ getDefinition?: (kind: string) => ResourceDefinition | undefined;
74
+
75
+ readonly createInstance: InstanceFactory;
76
+ readonly context: Record<string, unknown>;
77
+ readonly secretValues: Set<string>;
78
+
79
+ setInitOrder(names: string[]): void;
80
+ hasManifest(name: string): boolean;
81
+ registerManifest(resource: ResourceManifest): void;
82
+ spawnChild<T extends EvaluationContext>(child: T): T;
83
+ initializeResources(): Promise<void>;
84
+ withManifests<T>(manifests: any[], fn: () => T): T;
85
+ createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
86
+ teardownResources(): Promise<void>;
87
+ transientChild(context: Record<string, any>): EvaluationContext;
88
+ invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any>;
89
+ invokeResolved<TInputs>(
90
+ kind: string,
91
+ name: string,
92
+ instance: ResourceInstance,
93
+ inputs: TInputs,
94
+ ): Promise<any>;
95
+ run(name: string): Promise<void>;
96
+ expand(value: unknown): unknown;
97
+ expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
471
98
  expandPaths(
472
99
  value: Record<string, unknown>,
473
100
  paths: string[],
474
- excludePaths: string[] = [],
475
- ): Record<string, unknown> {
476
- if (paths.includes("**")) {
477
- const result: Record<string, unknown> = {};
478
- for (const [key, v] of Object.entries(value)) {
479
- result[key] = isExcluded(key, excludePaths) ? v : this.expand(v);
480
- }
481
- return result;
482
- }
483
- const result = { ...value };
484
- for (const path of paths) {
485
- if (isExcluded(path, excludePaths)) continue;
486
- const parts = path.split(".");
487
- const current = getNestedValue(result, parts);
488
- if (current !== undefined) {
489
- setNestedValue(result, parts, this.expand(current));
490
- }
491
- }
492
- return result;
493
- }
494
- }
495
-
496
- function isExcluded(path: string, excludePaths: string[]): boolean {
497
- return excludePaths.some(
498
- (ep) => ep === path || ep === "**" || path.startsWith(ep + ".") || ep.startsWith(path + "."),
499
- );
500
- }
501
-
502
- function getNestedValue(obj: Record<string, unknown>, parts: string[]): unknown {
503
- let current: unknown = obj;
504
- for (const part of parts) {
505
- if (current === null || typeof current !== "object") return undefined;
506
- current = (current as Record<string, unknown>)[part];
507
- }
508
- return current;
509
- }
510
-
511
- function setNestedValue(obj: Record<string, unknown>, parts: string[], value: unknown): void {
512
- let current: Record<string, unknown> = obj;
513
- for (let i = 0; i < parts.length - 1; i++) {
514
- const next = current[parts[i]];
515
- if (next === null || typeof next !== "object") return;
516
- current = next as Record<string, unknown>;
517
- }
518
- current[parts[parts.length - 1]] = value;
101
+ excludePaths?: string[],
102
+ ): Record<string, unknown>;
519
103
  }
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./module-context.js";
10
10
  export * from "./resource-context.js";
11
11
  export * from "./resource-instance.js";
12
12
  export * from "./resource-manifest.js";
13
+ export * from "./invoke-error.js";
13
14
  export * from "./runtime-error.js";
14
15
  export * from "./runtime-event.js";
15
16
  export * from "./runtime-resource.js";
@@ -0,0 +1,39 @@
1
+ const INVOKE_ERROR = Symbol.for("telo.InvokeError");
2
+
3
+ /**
4
+ * Structured, catchable error for invocables and runnables. Route handlers and
5
+ * Run.Sequence try/catch match on `code`; downstream renderers consume `data`.
6
+ *
7
+ * Use `isInvokeError` for recognition, not `instanceof` — dual-realm safe
8
+ * across pnpm hoist splits, registry modules, and future sandbox isolation.
9
+ */
10
+ export class InvokeError extends Error {
11
+ readonly code: string;
12
+ readonly data?: unknown;
13
+
14
+ constructor(code: string, message: string, data?: unknown) {
15
+ super(message);
16
+ this.name = "InvokeError";
17
+ this.code = code;
18
+ this.data = data;
19
+ // Set via defineProperty (not a class field initializer) so the marker is
20
+ // always present regardless of TS/runtime class-field semantics
21
+ // (useDefineForClassFields, Error-subclass quirks, etc.) and stays
22
+ // non-enumerable so JSON serialisation / CEL property access don't trip
23
+ // over it.
24
+ Object.defineProperty(this, INVOKE_ERROR, {
25
+ value: true,
26
+ enumerable: false,
27
+ writable: false,
28
+ configurable: false,
29
+ });
30
+ }
31
+ }
32
+
33
+ export function isInvokeError(err: unknown): err is InvokeError {
34
+ return (
35
+ typeof err === "object" &&
36
+ err !== null &&
37
+ (err as Record<PropertyKey, unknown>)[INVOKE_ERROR] === true
38
+ );
39
+ }