@telorun/sdk 0.18.0 → 0.21.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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Cooperative invocation cancellation — the standard source/token split.
3
+ *
4
+ * A {@link CancellationToken} is the read-only side handed to controllers as the
5
+ * `cancellation` member of the {@link InvokeContext} second argument: poll it
6
+ * (`isCancelled`), subscribe (`onCancelled`), bail (`throwIfCancelled`), or hand
7
+ * its `signal` to a Web API (`fetch`, `streamText`). The writable
8
+ * {@link CancellationSource} behind it — `cancel` / `cancelAt` / `cancelAfter` —
9
+ * is held only by the kernel, embedders, and trigger modules, never by the
10
+ * controllers that observe the token.
11
+ *
12
+ * A deadline is not a separate concept: `cancelAt(epochMs)` arms the token to
13
+ * trip at an instant, so any code holding a deadline schedules a cancellation
14
+ * and every honoring leaf gets timeout behavior for free. `cancelAt` (absolute)
15
+ * is the primitive; `cancelAfter(ms)` is sugar over it.
16
+ */
17
+ export declare const ERR_INVOKE_CANCELLED = "ERR_INVOKE_CANCELLED";
18
+ export interface CancellationToken {
19
+ /** Synchronous poll — `true` once the owning source has cancelled. */
20
+ readonly isCancelled: boolean;
21
+ /** Human-readable reason supplied to `cancel`/the deadline, if any. */
22
+ readonly reason: string | undefined;
23
+ /** `AbortSignal` escape hatch for handing off to Web APIs (`fetch`,
24
+ * `streamText`). Aborts when the source cancels. */
25
+ readonly signal: AbortSignal;
26
+ /** Subscribe to cancellation. Fires immediately if already cancelled.
27
+ * Returns an unsubscribe function. */
28
+ onCancelled(listener: (reason: string | undefined) => void): () => void;
29
+ /** Throw `ERR_INVOKE_CANCELLED` if cancelled; otherwise no-op. */
30
+ throwIfCancelled(): void;
31
+ }
32
+ /**
33
+ * The out-of-band second argument every `invoke()` receives. Intentionally an
34
+ * extensible object rather than a bare token so future per-invoke concerns
35
+ * (trace, idempotency) can join without a breaking signature change.
36
+ */
37
+ export interface InvokeContext {
38
+ readonly cancellation: CancellationToken;
39
+ }
40
+ export interface CancellationSource {
41
+ readonly token: CancellationToken;
42
+ /** The {@link InvokeContext} wrapping this source's token — pass to
43
+ * `invokeResolved(..., source.context)` to seed an invocation tree. */
44
+ readonly context: InvokeContext;
45
+ cancel(reason?: string): void;
46
+ /** Arm cancellation at an absolute epoch-millis instant (a deadline). */
47
+ cancelAt(epochMs: number): void;
48
+ /** Sugar over `cancelAt(now + ms)`. */
49
+ cancelAfter(ms: number): void;
50
+ /** Release a pending deadline timer and subscribers without cancelling.
51
+ * Triggers that arm `cancelAt` (lambda deadline, embedder `deadlineAt`) call
52
+ * this in a `finally` once the invoke settles, so an early finish doesn't pin
53
+ * the source + timer alive until the deadline. Idempotent. */
54
+ dispose(): void;
55
+ }
56
+ export declare function createCancellationSource(): CancellationSource;
57
+ /** A token that is never cancelled — the sentinel used by the kernel's hot
58
+ * dispatch path when no source has been seeded for an invocation tree. */
59
+ export declare const NEVER_CANCELLED: CancellationToken;
60
+ /** The shared {@link InvokeContext} carrying {@link NEVER_CANCELLED}. */
61
+ export declare const UNCANCELLABLE_CONTEXT: InvokeContext;
62
+ /** Recognizes the cancellation error by code, dual-realm safe (no `instanceof`). */
63
+ export declare function isCancellationError(err: unknown): boolean;
64
+ //# sourceMappingURL=cancellation.d.ts.map
@@ -0,0 +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;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC;4EACwE;IACxE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,uCAAuC;IACvC,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;;mEAG+D;IAC/D,OAAO,IAAI,IAAI,CAAC;CACjB;AAiFD,wBAAgB,wBAAwB,IAAI,kBAAkB,CAE7D;AAMD;2EAC2E;AAC3E,eAAO,MAAM,eAAe,EAAE,iBAU7B,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,EAAE,aAAiD,CAAC;AAEtF,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMzD"}
@@ -0,0 +1,122 @@
1
+ import { InvokeError } from "./invoke-error.js";
2
+ /**
3
+ * Cooperative invocation cancellation — the standard source/token split.
4
+ *
5
+ * A {@link CancellationToken} is the read-only side handed to controllers as the
6
+ * `cancellation` member of the {@link InvokeContext} second argument: poll it
7
+ * (`isCancelled`), subscribe (`onCancelled`), bail (`throwIfCancelled`), or hand
8
+ * its `signal` to a Web API (`fetch`, `streamText`). The writable
9
+ * {@link CancellationSource} behind it — `cancel` / `cancelAt` / `cancelAfter` —
10
+ * is held only by the kernel, embedders, and trigger modules, never by the
11
+ * controllers that observe the token.
12
+ *
13
+ * A deadline is not a separate concept: `cancelAt(epochMs)` arms the token to
14
+ * trip at an instant, so any code holding a deadline schedules a cancellation
15
+ * and every honoring leaf gets timeout behavior for free. `cancelAt` (absolute)
16
+ * is the primitive; `cancelAfter(ms)` is sugar over it.
17
+ */
18
+ export const ERR_INVOKE_CANCELLED = "ERR_INVOKE_CANCELLED";
19
+ class CancellationTokenSource {
20
+ #controller = new AbortController();
21
+ #cancelled = false;
22
+ #reason;
23
+ #listeners = new Set();
24
+ #timer;
25
+ token;
26
+ context;
27
+ constructor() {
28
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
29
+ const source = this;
30
+ this.token = {
31
+ get isCancelled() {
32
+ return source.#cancelled;
33
+ },
34
+ get reason() {
35
+ return source.#reason;
36
+ },
37
+ get signal() {
38
+ return source.#controller.signal;
39
+ },
40
+ onCancelled(listener) {
41
+ if (source.#cancelled) {
42
+ listener(source.#reason);
43
+ return () => { };
44
+ }
45
+ source.#listeners.add(listener);
46
+ return () => source.#listeners.delete(listener);
47
+ },
48
+ throwIfCancelled() {
49
+ if (source.#cancelled) {
50
+ throw new InvokeError(ERR_INVOKE_CANCELLED, source.#reason ?? "Invoke cancelled");
51
+ }
52
+ },
53
+ };
54
+ this.context = { cancellation: this.token };
55
+ }
56
+ cancel(reason) {
57
+ if (this.#cancelled)
58
+ return;
59
+ this.#cancelled = true;
60
+ this.#reason = reason;
61
+ if (this.#timer) {
62
+ clearTimeout(this.#timer);
63
+ this.#timer = undefined;
64
+ }
65
+ this.#controller.abort(reason);
66
+ const listeners = [...this.#listeners];
67
+ this.#listeners.clear();
68
+ for (const listener of listeners)
69
+ listener(reason);
70
+ }
71
+ cancelAt(epochMs) {
72
+ if (this.#cancelled)
73
+ return;
74
+ const delay = epochMs - Date.now();
75
+ if (delay <= 0) {
76
+ this.cancel("deadline-exceeded");
77
+ return;
78
+ }
79
+ if (this.#timer)
80
+ clearTimeout(this.#timer);
81
+ this.#timer = setTimeout(() => this.cancel("deadline-exceeded"), delay);
82
+ // Don't keep the process alive solely for a pending deadline timer.
83
+ this.#timer.unref?.();
84
+ }
85
+ cancelAfter(ms) {
86
+ this.cancelAt(Date.now() + ms);
87
+ }
88
+ dispose() {
89
+ if (this.#timer) {
90
+ clearTimeout(this.#timer);
91
+ this.#timer = undefined;
92
+ }
93
+ this.#listeners.clear();
94
+ }
95
+ }
96
+ export function createCancellationSource() {
97
+ return new CancellationTokenSource();
98
+ }
99
+ // Shared never-aborting signal for the sentinel token, so the common dispatch
100
+ // path allocates no AbortController for invokes that never touch cancellation.
101
+ const neverController = new AbortController();
102
+ /** A token that is never cancelled — the sentinel used by the kernel's hot
103
+ * dispatch path when no source has been seeded for an invocation tree. */
104
+ export const NEVER_CANCELLED = {
105
+ isCancelled: false,
106
+ reason: undefined,
107
+ get signal() {
108
+ return neverController.signal;
109
+ },
110
+ onCancelled() {
111
+ return () => { };
112
+ },
113
+ throwIfCancelled() { },
114
+ };
115
+ /** The shared {@link InvokeContext} carrying {@link NEVER_CANCELLED}. */
116
+ export const UNCANCELLABLE_CONTEXT = { cancellation: NEVER_CANCELLED };
117
+ /** Recognizes the cancellation error by code, dual-realm safe (no `instanceof`). */
118
+ export function isCancellationError(err) {
119
+ return (typeof err === "object" &&
120
+ err !== null &&
121
+ err.code === ERR_INVOKE_CANCELLED);
122
+ }
@@ -1,4 +1,12 @@
1
+ import type { InvokeContext } from "../cancellation.js";
1
2
  export interface Invocable<TInput = Record<string, any>, TOutput = any> {
2
- invoke(inputs: TInput): Promise<TOutput>;
3
+ /**
4
+ * @param inputs Caller-supplied invocation inputs.
5
+ * @param ctx Out-of-band per-invoke context carrying the cancellation token.
6
+ * Optional — controllers that ignore it keep working unchanged. The kernel
7
+ * always supplies it; a never-cancellable sentinel is passed when no source
8
+ * was seeded for the invocation tree.
9
+ */
10
+ invoke(inputs: TInput, ctx?: InvokeContext): Promise<TOutput>;
3
11
  }
4
12
  //# sourceMappingURL=invokable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invokable.d.ts","sourceRoot":"","sources":["../../src/capabilities/invokable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG;IACpE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C"}
1
+ {"version":3,"file":"invokable.d.ts","sourceRoot":"","sources":["../../src/capabilities/invokable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG;IACpE;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/D"}
@@ -1,4 +1,11 @@
1
+ import type { InvokeContext } from "../cancellation.js";
1
2
  export interface Runnable {
2
- run(): Promise<void>;
3
+ /**
4
+ * @param ctx Out-of-band per-run context carrying the cancellation token.
5
+ * Optional — runnables that ignore it keep working unchanged. Long-lived
6
+ * targets (servers, loops) observe `ctx.cancellation` to stop early when the
7
+ * boot run is cancelled (e.g. SIGINT).
8
+ */
9
+ run(ctx?: InvokeContext): Promise<void>;
3
10
  }
4
11
  //# sourceMappingURL=runnable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runnable.d.ts","sourceRoot":"","sources":["../../src/capabilities/runnable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB"}
1
+ {"version":3,"file":"runnable.d.ts","sourceRoot":"","sources":["../../src/capabilities/runnable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,GAAG,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC"}
@@ -5,7 +5,25 @@ export interface CompiledValue {
5
5
  readonly __compiled: true;
6
6
  /** Original expression source text (e.g. "env.PORT"), if available. */
7
7
  readonly source?: string;
8
+ /** For an interpolated string ("a ${{ x }} b"), the ordered literal
9
+ * fragments and embedded expression segments before they are joined into a
10
+ * single string by `call()`. Absent for a bare single expression. Consumers
11
+ * that need each interpolation as a separate value (e.g. SQL bind
12
+ * parameters) read this instead of the joined `call()` result. */
13
+ readonly parts?: ReadonlyArray<string | CompiledValue>;
8
14
  call(ctx: Record<string, unknown>): unknown;
9
15
  }
10
16
  export declare function isCompiledValue(v: unknown): v is CompiledValue;
17
+ /** The value a parameterized template (the `!sql` engine) evaluates to: literal
18
+ * text fragments plus the separately-evaluated value of each embedded `${{ }}`
19
+ * interpolation, with `fragments.length === values.length + 1`. A consumer emits
20
+ * its own placeholder between fragments and binds the values — never splicing
21
+ * them into the text. Single source of truth for the marker contract shared
22
+ * across the producing engine and any consuming controller. */
23
+ export interface ParameterizedSql {
24
+ readonly __teloParameterized: true;
25
+ readonly fragments: string[];
26
+ readonly values: unknown[];
27
+ }
28
+ export declare function isParameterizedSql(v: unknown): v is ParameterizedSql;
11
29
  //# sourceMappingURL=compiled-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiled-value.d.ts","sourceRoot":"","sources":["../src/compiled-value.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;CAC7C;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAE9D"}
1
+ {"version":3,"file":"compiled-value.d.ts","sourceRoot":"","sources":["../src/compiled-value.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAC/D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;uEAImE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;IACvD,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;CAC7C;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAE9D;AAED;;;;;gEAKgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,mBAAmB,EAAE,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,gBAAgB,CAIpE"}
@@ -1,3 +1,6 @@
1
1
  export function isCompiledValue(v) {
2
2
  return v !== null && typeof v === "object" && v.__compiled === true;
3
3
  }
4
+ export function isParameterizedSql(v) {
5
+ return (v !== null && typeof v === "object" && v.__teloParameterized === true);
6
+ }
@@ -1,3 +1,4 @@
1
+ import type { InvokeContext } from "./cancellation.js";
1
2
  import type { ScopeHandle } from "./ref.js";
2
3
  import type { ResourceInstance } from "./resource-instance.js";
3
4
  import type { ResourceManifest } from "./resource-manifest.js";
@@ -68,9 +69,9 @@ export interface EvaluationContext {
68
69
  createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
69
70
  teardownResources(): Promise<void>;
70
71
  transientChild(context: Record<string, any>): EvaluationContext;
71
- invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any>;
72
- invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs): Promise<any>;
73
- run(name: string): Promise<void>;
72
+ invoke<TInputs>(kind: string, name: string, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
73
+ invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
74
+ run(name: string, ctx?: InvokeContext): Promise<void>;
74
75
  expand(value: unknown): unknown;
75
76
  expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
76
77
  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,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,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/E,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,GAAG,UAAU,GAAG,UAAU,CAAC;AAE/F;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,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AAG,CAAC,GAAG,iBAAiB,CAAC;IAChE,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,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,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
@@ -1,3 +1,4 @@
1
+ export * from "./cancellation.js";
1
2
  export * from "./compiled-value.js";
2
3
  export * from "./capabilities/invokable.js";
3
4
  export * from "./ref.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,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,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,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,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,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./cancellation.js";
1
2
  export * from "./compiled-value.js";
2
3
  export * from "./capabilities/invokable.js";
3
4
  export * from "./ref.js";
@@ -1,4 +1,5 @@
1
1
  import type { Invocable } from "./capabilities/invokable.js";
2
+ import type { InvokeContext } from "./cancellation.js";
2
3
  import type { ControllerPolicy } from "./controller-policy.js";
3
4
  import type { EvaluationContext } from "./evaluation-context.js";
4
5
  import type { BootTarget } from "./invoke-step.js";
@@ -38,6 +39,6 @@ export interface ModuleContext extends EvaluationContext {
38
39
  getInstance(name: string): unknown;
39
40
  getInvocable<TInput = Record<string, any>, TOutput = any>(name: string): Invocable<TInput, TOutput>;
40
41
  resolveKind(kind: string): string;
41
- runTargets(): Promise<void>;
42
+ runTargets(ctx?: InvokeContext): Promise<void>;
42
43
  }
43
44
  //# sourceMappingURL=module-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"module-context.d.ts","sourceRoot":"","sources":["../src/module-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5C,4EAA4E;IAC5E,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAElC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAClD,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACrC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG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AC;IAC5F,4FAA4F;IAC5F,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IACnF,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,EACtD,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,UAAU,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD"}
@@ -1,3 +1,4 @@
1
+ import type { CancellationSource, InvokeContext } from "./cancellation.js";
1
2
  import { ControllerContext } from "./controller-context.js";
2
3
  import { ControllerPolicy } from "./controller-policy.js";
3
4
  import { EvaluationContext } from "./evaluation-context.js";
@@ -35,8 +36,12 @@ export interface ResourceContext extends ControllerContext {
35
36
  readonly args: ParsedArgs;
36
37
  acquireHold(reason?: string): () => void;
37
38
  emitEvent(event: string, payload?: any): Promise<void>;
39
+ /** Mint a writable cancellation source for a trigger to own (HTTP request,
40
+ * lambda budget). Pass `source.context` into `invokeResolved` to scope an
41
+ * invocation tree to it. */
42
+ createCancellationSource(): CancellationSource;
38
43
  invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
39
- invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs): Promise<any>;
44
+ invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
40
45
  run(kind: string, name: string): Promise<void>;
41
46
  getResourcesByName(kind: string, name: string): RuntimeResource | null;
42
47
  registerManifest(resource: any): void;
@@ -1 +1 @@
1
- {"version":3,"file":"resource-context.d.ts","sourceRoot":"","sources":["../src/resource-context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,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
@@ -7,6 +7,13 @@ import { RuntimeResource } from "./runtime-resource.js";
7
7
  export interface KernelContext {
8
8
  kernel: Kernel;
9
9
  }
10
+ /** Embedder-facing seed for an invocation tree's cancellation scope. Provide an
11
+ * external `AbortSignal` to cancel on, an absolute epoch-millis `deadlineAt`,
12
+ * or both. Omit to run uncancellable. */
13
+ export interface InvokeOptions {
14
+ signal?: AbortSignal;
15
+ deadlineAt?: number;
16
+ }
10
17
  export interface ExecContext {
11
18
  execute(urn: string, input: any): Promise<any>;
12
19
  [key: string]: any;
@@ -113,7 +120,7 @@ export interface Kernel {
113
120
  invoke<TInputs = any, TOutput = any>(ref: string | {
114
121
  kind: string;
115
122
  name: string;
116
- }, inputs: TInputs): Promise<TOutput>;
123
+ }, inputs: TInputs, opts?: InvokeOptions): Promise<TOutput>;
117
124
  /**
118
125
  * Convenience: boot → runTargets → waitForIdle → teardown, with teardown
119
126
  * always running via finally so init-time failures still tear down.
@@ -128,6 +135,13 @@ export interface Kernel {
128
135
  * `teardown()` for cleanup.
129
136
  */
130
137
  forceIdle(): void;
138
+ /**
139
+ * Cooperatively cancel the boot `targets` run. Not-yet-started targets are
140
+ * refused; long-lived runnables and in-flight invoke trees observe the
141
+ * cancellation token and stop early. Pairs with `forceIdle()` in signal
142
+ * handlers (cancel the work, then unblock the idle wait).
143
+ */
144
+ cancel(reason?: string): void;
131
145
  requestExit(code: number): void;
132
146
  readonly exitCode: number;
133
147
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d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EAC5C,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;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;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,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.18.0",
3
+ "version": "0.21.0",
4
4
  "description": "Telo SDK - Public API for Telo module authors.",
5
5
  "keywords": [
6
6
  "telo",
@@ -0,0 +1,174 @@
1
+ import { InvokeError } from "./invoke-error.js";
2
+
3
+ /**
4
+ * Cooperative invocation cancellation — the standard source/token split.
5
+ *
6
+ * A {@link CancellationToken} is the read-only side handed to controllers as the
7
+ * `cancellation` member of the {@link InvokeContext} second argument: poll it
8
+ * (`isCancelled`), subscribe (`onCancelled`), bail (`throwIfCancelled`), or hand
9
+ * its `signal` to a Web API (`fetch`, `streamText`). The writable
10
+ * {@link CancellationSource} behind it — `cancel` / `cancelAt` / `cancelAfter` —
11
+ * is held only by the kernel, embedders, and trigger modules, never by the
12
+ * controllers that observe the token.
13
+ *
14
+ * A deadline is not a separate concept: `cancelAt(epochMs)` arms the token to
15
+ * trip at an instant, so any code holding a deadline schedules a cancellation
16
+ * and every honoring leaf gets timeout behavior for free. `cancelAt` (absolute)
17
+ * is the primitive; `cancelAfter(ms)` is sugar over it.
18
+ */
19
+
20
+ export const ERR_INVOKE_CANCELLED = "ERR_INVOKE_CANCELLED";
21
+
22
+ export interface CancellationToken {
23
+ /** Synchronous poll — `true` once the owning source has cancelled. */
24
+ readonly isCancelled: boolean;
25
+ /** Human-readable reason supplied to `cancel`/the deadline, if any. */
26
+ readonly reason: string | undefined;
27
+ /** `AbortSignal` escape hatch for handing off to Web APIs (`fetch`,
28
+ * `streamText`). Aborts when the source cancels. */
29
+ readonly signal: AbortSignal;
30
+ /** Subscribe to cancellation. Fires immediately if already cancelled.
31
+ * Returns an unsubscribe function. */
32
+ onCancelled(listener: (reason: string | undefined) => void): () => void;
33
+ /** Throw `ERR_INVOKE_CANCELLED` if cancelled; otherwise no-op. */
34
+ throwIfCancelled(): void;
35
+ }
36
+
37
+ /**
38
+ * The out-of-band second argument every `invoke()` receives. Intentionally an
39
+ * extensible object rather than a bare token so future per-invoke concerns
40
+ * (trace, idempotency) can join without a breaking signature change.
41
+ */
42
+ export interface InvokeContext {
43
+ readonly cancellation: CancellationToken;
44
+ }
45
+
46
+ export interface CancellationSource {
47
+ readonly token: CancellationToken;
48
+ /** The {@link InvokeContext} wrapping this source's token — pass to
49
+ * `invokeResolved(..., source.context)` to seed an invocation tree. */
50
+ readonly context: InvokeContext;
51
+ cancel(reason?: string): void;
52
+ /** Arm cancellation at an absolute epoch-millis instant (a deadline). */
53
+ cancelAt(epochMs: number): void;
54
+ /** Sugar over `cancelAt(now + ms)`. */
55
+ cancelAfter(ms: number): void;
56
+ /** Release a pending deadline timer and subscribers without cancelling.
57
+ * Triggers that arm `cancelAt` (lambda deadline, embedder `deadlineAt`) call
58
+ * this in a `finally` once the invoke settles, so an early finish doesn't pin
59
+ * the source + timer alive until the deadline. Idempotent. */
60
+ dispose(): void;
61
+ }
62
+
63
+ class CancellationTokenSource implements CancellationSource {
64
+ readonly #controller = new AbortController();
65
+ #cancelled = false;
66
+ #reason: string | undefined;
67
+ readonly #listeners = new Set<(reason: string | undefined) => void>();
68
+ #timer: ReturnType<typeof setTimeout> | undefined;
69
+ readonly token: CancellationToken;
70
+ readonly context: InvokeContext;
71
+
72
+ constructor() {
73
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
74
+ const source = this;
75
+ this.token = {
76
+ get isCancelled() {
77
+ return source.#cancelled;
78
+ },
79
+ get reason() {
80
+ return source.#reason;
81
+ },
82
+ get signal() {
83
+ return source.#controller.signal;
84
+ },
85
+ onCancelled(listener) {
86
+ if (source.#cancelled) {
87
+ listener(source.#reason);
88
+ return () => {};
89
+ }
90
+ source.#listeners.add(listener);
91
+ return () => source.#listeners.delete(listener);
92
+ },
93
+ throwIfCancelled() {
94
+ if (source.#cancelled) {
95
+ throw new InvokeError(ERR_INVOKE_CANCELLED, source.#reason ?? "Invoke cancelled");
96
+ }
97
+ },
98
+ };
99
+ this.context = { cancellation: this.token };
100
+ }
101
+
102
+ cancel(reason?: string): void {
103
+ if (this.#cancelled) return;
104
+ this.#cancelled = true;
105
+ this.#reason = reason;
106
+ if (this.#timer) {
107
+ clearTimeout(this.#timer);
108
+ this.#timer = undefined;
109
+ }
110
+ this.#controller.abort(reason);
111
+ const listeners = [...this.#listeners];
112
+ this.#listeners.clear();
113
+ for (const listener of listeners) listener(reason);
114
+ }
115
+
116
+ cancelAt(epochMs: number): void {
117
+ if (this.#cancelled) return;
118
+ const delay = epochMs - Date.now();
119
+ if (delay <= 0) {
120
+ this.cancel("deadline-exceeded");
121
+ return;
122
+ }
123
+ if (this.#timer) clearTimeout(this.#timer);
124
+ this.#timer = setTimeout(() => this.cancel("deadline-exceeded"), delay);
125
+ // Don't keep the process alive solely for a pending deadline timer.
126
+ (this.#timer as { unref?: () => void }).unref?.();
127
+ }
128
+
129
+ cancelAfter(ms: number): void {
130
+ this.cancelAt(Date.now() + ms);
131
+ }
132
+
133
+ dispose(): void {
134
+ if (this.#timer) {
135
+ clearTimeout(this.#timer);
136
+ this.#timer = undefined;
137
+ }
138
+ this.#listeners.clear();
139
+ }
140
+ }
141
+
142
+ export function createCancellationSource(): CancellationSource {
143
+ return new CancellationTokenSource();
144
+ }
145
+
146
+ // Shared never-aborting signal for the sentinel token, so the common dispatch
147
+ // path allocates no AbortController for invokes that never touch cancellation.
148
+ const neverController = new AbortController();
149
+
150
+ /** A token that is never cancelled — the sentinel used by the kernel's hot
151
+ * dispatch path when no source has been seeded for an invocation tree. */
152
+ export const NEVER_CANCELLED: CancellationToken = {
153
+ isCancelled: false,
154
+ reason: undefined,
155
+ get signal() {
156
+ return neverController.signal;
157
+ },
158
+ onCancelled() {
159
+ return () => {};
160
+ },
161
+ throwIfCancelled() {},
162
+ };
163
+
164
+ /** The shared {@link InvokeContext} carrying {@link NEVER_CANCELLED}. */
165
+ export const UNCANCELLABLE_CONTEXT: InvokeContext = { cancellation: NEVER_CANCELLED };
166
+
167
+ /** Recognizes the cancellation error by code, dual-realm safe (no `instanceof`). */
168
+ export function isCancellationError(err: unknown): boolean {
169
+ return (
170
+ typeof err === "object" &&
171
+ err !== null &&
172
+ (err as { code?: unknown }).code === ERR_INVOKE_CANCELLED
173
+ );
174
+ }
@@ -1,3 +1,12 @@
1
+ import type { InvokeContext } from "../cancellation.js";
2
+
1
3
  export interface Invocable<TInput = Record<string, any>, TOutput = any> {
2
- invoke(inputs: TInput): Promise<TOutput>;
4
+ /**
5
+ * @param inputs Caller-supplied invocation inputs.
6
+ * @param ctx Out-of-band per-invoke context carrying the cancellation token.
7
+ * Optional — controllers that ignore it keep working unchanged. The kernel
8
+ * always supplies it; a never-cancellable sentinel is passed when no source
9
+ * was seeded for the invocation tree.
10
+ */
11
+ invoke(inputs: TInput, ctx?: InvokeContext): Promise<TOutput>;
3
12
  }
@@ -1,3 +1,11 @@
1
+ import type { InvokeContext } from "../cancellation.js";
2
+
1
3
  export interface Runnable {
2
- run(): Promise<void>;
4
+ /**
5
+ * @param ctx Out-of-band per-run context carrying the cancellation token.
6
+ * Optional — runnables that ignore it keep working unchanged. Long-lived
7
+ * targets (servers, loops) observe `ctx.cancellation` to stop early when the
8
+ * boot run is cancelled (e.g. SIGINT).
9
+ */
10
+ run(ctx?: InvokeContext): Promise<void>;
3
11
  }
@@ -5,9 +5,33 @@ export interface CompiledValue {
5
5
  readonly __compiled: true;
6
6
  /** Original expression source text (e.g. "env.PORT"), if available. */
7
7
  readonly source?: string;
8
+ /** For an interpolated string ("a ${{ x }} b"), the ordered literal
9
+ * fragments and embedded expression segments before they are joined into a
10
+ * single string by `call()`. Absent for a bare single expression. Consumers
11
+ * that need each interpolation as a separate value (e.g. SQL bind
12
+ * parameters) read this instead of the joined `call()` result. */
13
+ readonly parts?: ReadonlyArray<string | CompiledValue>;
8
14
  call(ctx: Record<string, unknown>): unknown;
9
15
  }
10
16
 
11
17
  export function isCompiledValue(v: unknown): v is CompiledValue {
12
18
  return v !== null && typeof v === "object" && (v as any).__compiled === true;
13
19
  }
20
+
21
+ /** The value a parameterized template (the `!sql` engine) evaluates to: literal
22
+ * text fragments plus the separately-evaluated value of each embedded `${{ }}`
23
+ * interpolation, with `fragments.length === values.length + 1`. A consumer emits
24
+ * its own placeholder between fragments and binds the values — never splicing
25
+ * them into the text. Single source of truth for the marker contract shared
26
+ * across the producing engine and any consuming controller. */
27
+ export interface ParameterizedSql {
28
+ readonly __teloParameterized: true;
29
+ readonly fragments: string[];
30
+ readonly values: unknown[];
31
+ }
32
+
33
+ export function isParameterizedSql(v: unknown): v is ParameterizedSql {
34
+ return (
35
+ v !== null && typeof v === "object" && (v as any).__teloParameterized === true
36
+ );
37
+ }
@@ -1,3 +1,4 @@
1
+ import type { InvokeContext } from "./cancellation.js";
1
2
  import type { ScopeHandle } from "./ref.js";
2
3
  import type { ResourceInstance } from "./resource-instance.js";
3
4
  import type { ResourceManifest } from "./resource-manifest.js";
@@ -87,14 +88,15 @@ export interface EvaluationContext {
87
88
  createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
88
89
  teardownResources(): Promise<void>;
89
90
  transientChild(context: Record<string, any>): EvaluationContext;
90
- invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any>;
91
+ invoke<TInputs>(kind: string, name: string, inputs: TInputs, ctx?: InvokeContext): Promise<any>;
91
92
  invokeResolved<TInputs>(
92
93
  kind: string,
93
94
  name: string,
94
95
  instance: ResourceInstance,
95
96
  inputs: TInputs,
97
+ ctx?: InvokeContext,
96
98
  ): Promise<any>;
97
- run(name: string): Promise<void>;
99
+ run(name: string, ctx?: InvokeContext): Promise<void>;
98
100
  expand(value: unknown): unknown;
99
101
  expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
100
102
  expandPaths(
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./cancellation.js";
1
2
  export * from "./compiled-value.js";
2
3
  export * from "./capabilities/invokable.js";
3
4
  export * from "./ref.js";
@@ -1,4 +1,5 @@
1
1
  import type { Invocable } from "./capabilities/invokable.js";
2
+ import type { InvokeContext } from "./cancellation.js";
2
3
  import type { ControllerPolicy } from "./controller-policy.js";
3
4
  import type { EvaluationContext } from "./evaluation-context.js";
4
5
  import type { BootTarget } from "./invoke-step.js";
@@ -41,5 +42,5 @@ export interface ModuleContext extends EvaluationContext {
41
42
  name: string,
42
43
  ): Invocable<TInput, TOutput>;
43
44
  resolveKind(kind: string): string;
44
- runTargets(): Promise<void>;
45
+ runTargets(ctx?: InvokeContext): Promise<void>;
45
46
  }
@@ -1,3 +1,4 @@
1
+ import type { CancellationSource, InvokeContext } from "./cancellation.js";
1
2
  import { ControllerContext } from "./controller-context.js";
2
3
  import { ControllerPolicy } from "./controller-policy.js";
3
4
  import { EvaluationContext } from "./evaluation-context.js";
@@ -44,12 +45,17 @@ export interface ResourceContext extends ControllerContext {
44
45
  readonly args: ParsedArgs;
45
46
  acquireHold(reason?: string): () => void;
46
47
  emitEvent(event: string, payload?: any): Promise<void>;
48
+ /** Mint a writable cancellation source for a trigger to own (HTTP request,
49
+ * lambda budget). Pass `source.context` into `invokeResolved` to scope an
50
+ * invocation tree to it. */
51
+ createCancellationSource(): CancellationSource;
47
52
  invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
48
53
  invokeResolved<TInputs>(
49
54
  kind: string,
50
55
  name: string,
51
56
  instance: ResourceInstance,
52
57
  inputs: TInputs,
58
+ ctx?: InvokeContext,
53
59
  ): Promise<any>;
54
60
  run(kind: string, name: string): Promise<void>;
55
61
  getResourcesByName(kind: string, name: string): RuntimeResource | null;
package/src/types.ts CHANGED
@@ -9,6 +9,14 @@ export interface KernelContext {
9
9
  kernel: Kernel;
10
10
  }
11
11
 
12
+ /** Embedder-facing seed for an invocation tree's cancellation scope. Provide an
13
+ * external `AbortSignal` to cancel on, an absolute epoch-millis `deadlineAt`,
14
+ * or both. Omit to run uncancellable. */
15
+ export interface InvokeOptions {
16
+ signal?: AbortSignal;
17
+ deadlineAt?: number;
18
+ }
19
+
12
20
  export interface ExecContext {
13
21
  execute(urn: string, input: any): Promise<any>;
14
22
  [key: string]: any;
@@ -124,6 +132,7 @@ export interface Kernel {
124
132
  invoke<TInputs = any, TOutput = any>(
125
133
  ref: string | { kind: string; name: string },
126
134
  inputs: TInputs,
135
+ opts?: InvokeOptions,
127
136
  ): Promise<TOutput>;
128
137
  /**
129
138
  * Convenience: boot → runTargets → waitForIdle → teardown, with teardown
@@ -139,6 +148,13 @@ export interface Kernel {
139
148
  * `teardown()` for cleanup.
140
149
  */
141
150
  forceIdle(): void;
151
+ /**
152
+ * Cooperatively cancel the boot `targets` run. Not-yet-started targets are
153
+ * refused; long-lived runnables and in-flight invoke trees observe the
154
+ * cancellation token and stop early. Pairs with `forceIdle()` in signal
155
+ * handlers (cancel the work, then unblock the idle wait).
156
+ */
157
+ cancel(reason?: string): void;
142
158
  requestExit(code: number): void;
143
159
  readonly exitCode: number;
144
160
  }