@astrale-os/kernel-client 1.0.0-beta.6 → 1.0.0-beta.8

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.
@@ -23,9 +23,15 @@ export type StreamResult = Correlated<Extract<Callable, {
23
23
  export type BinaryResponse = Correlated<Extract<Callable, {
24
24
  readonly kind: 'binary';
25
25
  }>>;
26
- export type ExecutionResult = Correlated<Extract<Callable, {
26
+ /**
27
+ * A durable call's answer. `replayed` is absent when the Host does not say whether the call
28
+ * replayed its Execution.
29
+ */
30
+ export type ExecutionResult = Correlated<Omit<Extract<Callable, {
27
31
  readonly kind: 'execution';
28
- }>>;
32
+ }>, 'replayed'> & {
33
+ readonly replayed?: boolean;
34
+ }>;
29
35
  export interface RedirectResult {
30
36
  readonly kind: 'redirect';
31
37
  readonly redirect: protocol.Redirection;
@@ -7,6 +7,6 @@ interface OutputContract {
7
7
  readonly success: false;
8
8
  };
9
9
  }
10
- /** Admit one value result through its Core-owned syscall contract. */
11
- export declare function acceptOutput<T>(contract: OutputContract, input: unknown, what?: string): T;
10
+ /** Admit one value an Execution Method answered through its Core-owned contract. */
11
+ export declare function acceptOutput<T>(contract: OutputContract, input: unknown, what: string): T;
12
12
  export {};
@@ -1,6 +1,6 @@
1
1
  import * as portable from '@astrale-os/kernel-dsl/value';
2
- /** Admit one value result through its Core-owned syscall contract. */
3
- export function acceptOutput(contract, input, what = 'Schema result') {
2
+ /** Admit one value an Execution Method answered through its Core-owned contract. */
3
+ export function acceptOutput(contract, input, what) {
4
4
  const value = portable.accept(input);
5
5
  const parsed = contract.safeParse(value);
6
6
  if (!parsed.success)
@@ -1,7 +1,6 @@
1
1
  import type { NodeId } from '@astrale-os/kernel-core/graph/node';
2
2
  import type { SystemExecutionDetail } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
3
3
  import type { Value } from '@astrale-os/kernel-dsl/value';
4
- import type { CallableReference } from './reference.js';
5
4
  declare const EXECUTION_OUTPUT: unique symbol;
6
5
  /**
7
6
  * Immediate value of a durable call: the `K.Execution` it created or recovered. `Output` is the
@@ -9,19 +8,29 @@ declare const EXECUTION_OUTPUT: unique symbol;
9
8
  */
10
9
  export interface ExecutionRef<Output = unknown> {
11
10
  readonly id: NodeId;
11
+ /**
12
+ * Present on the reference a durable call answered when its Host says: false when that call
13
+ * created the Execution, true when its idempotency key already named it.
14
+ */
15
+ readonly replayed?: boolean;
12
16
  readonly [EXECUTION_OUTPUT]?: Output;
13
17
  }
18
+ /** An Execution, by its reference or by its NodeId. */
19
+ export type ExecutionTarget<Output = unknown> = ExecutionRef<Output> | NodeId;
20
+ /** The public failure an Execution ended with, such as `DATA_MIGRATION_REQUIRED`. */
21
+ export interface ExecutionFailure {
22
+ readonly code: string;
23
+ readonly message: string;
24
+ readonly family?: string;
25
+ readonly details?: Value;
26
+ }
27
+ /** A terminal Execution: its completed value, its failure, or its cancellation. */
14
28
  export type ExecutionOutcome<Output = unknown> = {
15
29
  readonly kind: 'completed';
16
30
  readonly value: Output;
17
31
  } | {
18
32
  readonly kind: 'failed';
19
- readonly error: {
20
- readonly code: string;
21
- readonly message: string;
22
- readonly family?: string;
23
- readonly details?: Value;
24
- };
33
+ readonly error: ExecutionFailure;
25
34
  } | {
26
35
  readonly kind: 'cancelled';
27
36
  };
@@ -40,6 +49,7 @@ export interface ExecutionNodeStatus<Output = unknown> {
40
49
  readonly createdAt: string;
41
50
  /** A system execution's step, progress and session state, as Core shapes it. */
42
51
  readonly detail?: SystemExecutionDetail;
52
+ /** Present exactly once the Execution is terminal. */
43
53
  readonly outcome?: ExecutionOutcome<Output>;
44
54
  }
45
55
  /**
@@ -56,33 +66,11 @@ export interface DeletedExecutionStatus<Output = unknown> {
56
66
  readonly createdAt?: never;
57
67
  readonly detail?: never;
58
68
  }
59
- type Empty = Readonly<Record<string, never>>;
60
- type ExecutionLike<Output> = ExecutionRef<Output> | NodeId;
61
69
  /**
62
- * Typed references to the methods of one Execution, for `session.invoke`:
63
- *
64
- * ```ts
65
- * const run = await session.invoke(remind(invoice), { days: 3 })
66
- * const outcome = await session.invoke(execution.result(run), { waitMs: 10_000 })
67
- * ```
70
+ * How long a call waits for the terminal outcome, in total, across as many `Execution.result`
71
+ * requests as it takes. Absent or `0`, the call answers what the Execution holds now.
68
72
  */
69
- export declare const execution: Readonly<{
70
- status: <Output>(target: ExecutionLike<Output>) => CallableReference<Empty, ExecutionStatus<Output>>;
71
- /** Outcome once terminal; fails `EXECUTION_PENDING` when `waitMs` elapses first. */
72
- result: <Output>(target: ExecutionLike<Output>) => CallableReference<{
73
- readonly waitMs?: number;
74
- }, ExecutionOutcome<Output>>;
75
- /** Cooperative cancellation; `force` kills without compensation (owner Domain only). */
76
- cancel: <Output>(target: ExecutionLike<Output>) => CallableReference<{
77
- readonly force?: boolean;
78
- }, ExecutionStatus<Output>>;
79
- /** Resolve a named durable promise once (owner Domain only). */
80
- signal: (target: ExecutionLike<unknown>) => CallableReference<{
81
- readonly name: string;
82
- readonly value: Value;
83
- }, Empty>;
84
- resume: <Output>(target: ExecutionLike<Output>) => CallableReference<Empty, ExecutionStatus<Output>>;
85
- /** Forget the Execution and stop its run (owner Domain only). */
86
- delete: (target: ExecutionLike<unknown>) => CallableReference<Empty, Empty>;
87
- }>;
73
+ export interface ExecutionWait {
74
+ readonly waitMs?: number;
75
+ }
88
76
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { RequestOptions } from '../transport/index.js';
2
+ /**
3
+ * The absolute deadline of one Client call, whatever number of Kernel requests it sends: its
4
+ * `timeoutMs` from now when given, otherwise none (`Infinity`), each request then taking its default.
5
+ */
6
+ export declare function deadlineOf(options: RequestOptions | undefined): number;
7
+ /** The options of the call's next request: the time left before its deadline, at least 1 ms. */
8
+ export declare function within(deadline: number, options: RequestOptions | undefined): RequestOptions | undefined;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The absolute deadline of one Client call, whatever number of Kernel requests it sends: its
3
+ * `timeoutMs` from now when given, otherwise none (`Infinity`), each request then taking its default.
4
+ */
5
+ export function deadlineOf(options) {
6
+ return options?.timeoutMs === undefined ? Infinity : Date.now() + options.timeoutMs;
7
+ }
8
+ /** The options of the call's next request: the time left before its deadline, at least 1 ms. */
9
+ export function within(deadline, options) {
10
+ if (deadline === Infinity)
11
+ return options;
12
+ return { ...options, timeoutMs: Math.max(1, deadline - Date.now()) };
13
+ }
@@ -0,0 +1,57 @@
1
+ import type { Value } from '@astrale-os/kernel-dsl/value';
2
+ import type { Call, Result } from '../client/index.js';
3
+ import type { RequestOptions } from '../transport/index.js';
4
+ import type { ExecutionOutcome, ExecutionStatus, ExecutionTarget, ExecutionWait } from './contracts.js';
5
+ /** The value-call capability the `K.Execution` Methods are sent through. */
6
+ export type ExecutionCall = (call: Call, options?: RequestOptions) => Promise<Result>;
7
+ /**
8
+ * The `K.Execution` Methods of any Execution. Observing and a cooperative cancel are the Domain's
9
+ * or the initiator's; signals, a forced cancel, resume and delete are the owner Domain's (Root's
10
+ * for an install). A completed value is typed by the reference alone.
11
+ */
12
+ export interface ExecutionApi {
13
+ status<Output>(execution: ExecutionTarget<Output>, options?: RequestOptions): Promise<ExecutionStatus<Output>>;
14
+ /**
15
+ * The terminal outcome, waiting at most `waitMs` for it in total; the Kernel's
16
+ * `EXECUTION_PENDING` once that wait lapses. Ending the wait never ends the Execution.
17
+ */
18
+ result<Output>(execution: ExecutionTarget<Output>, wait?: ExecutionWait, options?: RequestOptions): Promise<ExecutionOutcome<Output>>;
19
+ /** Resolve the named durable promise once. */
20
+ signal(execution: ExecutionTarget, signal: {
21
+ readonly name: string;
22
+ readonly value: Value;
23
+ }, options?: RequestOptions): Promise<void>;
24
+ /** A cooperative cancel; `force` kills the run without compensation. */
25
+ cancel<Output>(execution: ExecutionTarget<Output>, input?: {
26
+ readonly force?: boolean;
27
+ }, options?: RequestOptions): Promise<ExecutionStatus<Output>>;
28
+ /** Resume a paused Execution; a running one is unchanged. */
29
+ resume<Output>(execution: ExecutionTarget<Output>, options?: RequestOptions): Promise<ExecutionStatus<Output>>;
30
+ /** Delete the Execution, then kill and purge its run. */
31
+ delete(execution: ExecutionTarget, options?: RequestOptions): Promise<void>;
32
+ }
33
+ /** The `K.Execution` Methods of one kind of Execution, its completed value admitted as `Completed`. */
34
+ export interface ExecutionMethods<Completed> {
35
+ status(execution: ExecutionTarget, options?: RequestOptions): Promise<ExecutionStatus<Completed>>;
36
+ result(execution: ExecutionTarget, wait?: ExecutionWait, options?: RequestOptions): Promise<ExecutionOutcome<Completed>>;
37
+ signal(execution: ExecutionTarget, signal: {
38
+ readonly name: string;
39
+ readonly value: unknown;
40
+ }, options?: RequestOptions): Promise<void>;
41
+ cancel(execution: ExecutionTarget, input?: {
42
+ readonly force?: boolean;
43
+ }, options?: RequestOptions): Promise<ExecutionStatus<Completed>>;
44
+ resume(execution: ExecutionTarget, options?: RequestOptions): Promise<ExecutionStatus<Completed>>;
45
+ delete(execution: ExecutionTarget, options?: RequestOptions): Promise<void>;
46
+ }
47
+ /** Bind the `K.Execution` Methods to one call capability. */
48
+ export declare function createExecution(call: ExecutionCall): ExecutionApi;
49
+ /**
50
+ * The `K.Execution` Methods over one call capability, a completed value admitted by `accept`.
51
+ * Status and outcome are admitted against their Core contracts. The effect-free reads, `status`
52
+ * and `result`, are sent again through the pacer after a TransportError or a refusal that carries
53
+ * a retry delay, within the call's deadline; the other Methods are sent once.
54
+ */
55
+ export declare function executionMethods<Completed>(call: ExecutionCall, accept: (value: unknown) => Completed): ExecutionMethods<Completed>;
56
+ /** The wait an `ExecutionWait` asks for, in milliseconds. */
57
+ export declare function acceptWait(wait: ExecutionWait | undefined): number;
@@ -0,0 +1,121 @@
1
+ import { Path } from '@astrale-os/kernel-core/path';
2
+ import { executionOutcome, executionStatus, } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
3
+ import { execution as methods } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
4
+ import { MethodKey } from '@astrale-os/kernel-dsl/v1/addressing';
5
+ import { call as invocation } from '../client/index.js';
6
+ import { ResponseError, TransportError } from '../errors/index.js';
7
+ import { RETRY_REFUSALS, retry } from '../pacer/index.js';
8
+ import { acceptOutput } from './admission.js';
9
+ import { deadlineOf, within } from './deadline.js';
10
+ /** Attempts of one effect-free Execution read; the call's deadline bounds them too. */
11
+ const READ_ATTEMPTS = 8;
12
+ /** A pending answer sooner than this did not wait: the Kernel answers now, so waiting ends. */
13
+ const LAPSED_WAIT_MS = 1_000;
14
+ /** No wait is sent again with less time left than this. */
15
+ const MINIMUM_WAIT_MS = 1_000;
16
+ /** Bind the `K.Execution` Methods to one call capability. */
17
+ export function createExecution(call) {
18
+ // A completed value is the handler output, which only the reference types.
19
+ return executionMethods(call, (value) => value);
20
+ }
21
+ /**
22
+ * The `K.Execution` Methods over one call capability, a completed value admitted by `accept`.
23
+ * Status and outcome are admitted against their Core contracts. The effect-free reads, `status`
24
+ * and `result`, are sent again through the pacer after a TransportError or a refusal that carries
25
+ * a retry delay, within the call's deadline; the other Methods are sent once.
26
+ */
27
+ export function executionMethods(call, accept) {
28
+ const send = async (id, method, input, options) => {
29
+ const target = Path.instanceMethod(Path.id(id), MethodKey.of(method.owner, method.name));
30
+ const result = await call(invocation(target, input), options);
31
+ if (result.kind !== 'value')
32
+ throw new TypeError('Execution Method returned a non-value result.');
33
+ return result.value;
34
+ };
35
+ const read = (deadline, options, work) => retry(() => work(within(deadline, options)), {
36
+ maxAttempts: READ_ATTEMPTS,
37
+ shouldRetry: (error, attempt) => Date.now() < deadline &&
38
+ (error instanceof TransportError || RETRY_REFUSALS.shouldRetry(error, attempt)),
39
+ retryAfter: RETRY_REFUSALS.retryAfter,
40
+ });
41
+ const outcomeOf = (input) => {
42
+ const outcome = acceptOutput(executionOutcome, input, 'Execution outcome');
43
+ if (outcome.kind !== 'completed')
44
+ return outcome;
45
+ return Object.freeze({ kind: 'completed', value: accept(outcome.value) });
46
+ };
47
+ const statusOf = (id, input) => {
48
+ const admitted = acceptOutput(executionStatus, input, 'Execution status');
49
+ if (admitted.id !== id)
50
+ throw new TypeError('Kernel returned the status of another Execution.');
51
+ const outcome = admitted.outcome === undefined ? undefined : outcomeOf(admitted.outcome);
52
+ // A deleted Execution carries the outcome its lifecycle record keeps, whatever its kind.
53
+ if (admitted.state === 'deleted')
54
+ return Object.freeze({ id, state: 'deleted', outcome: outcome });
55
+ if ((admitted.state === 'completed') !== (outcome?.kind === 'completed')) {
56
+ throw new TypeError('Execution status and outcome disagree.');
57
+ }
58
+ const { outcome: _outcome, ...rest } = admitted;
59
+ return Object.freeze({ ...rest, ...(outcome === undefined ? {} : { outcome }) });
60
+ };
61
+ return Object.freeze({
62
+ async status(target, options) {
63
+ const id = idOf(target);
64
+ return read(deadlineOf(options), options, async (attempt) => statusOf(id, await send(id, methods.status, {}, attempt)));
65
+ },
66
+ /**
67
+ * Each request waits for the time left, which the Kernel bounds by its own request deadline. A
68
+ * wait that lapsed after waiting is sent again while time is left; any other end of the wait is
69
+ * the caller's.
70
+ */
71
+ async result(target, wait, options) {
72
+ const id = idOf(target);
73
+ const deadline = deadlineOf(options);
74
+ const end = Math.min(Date.now() + acceptWait(wait), deadline);
75
+ for (;;) {
76
+ const sent = Date.now();
77
+ try {
78
+ return await read(deadline, options, async (attempt) => outcomeOf(await send(id, methods.result, { waitMs: Math.max(0, end - Date.now()) }, attempt)));
79
+ }
80
+ catch (error) {
81
+ const lapsed = isPending(error) && Date.now() - sent >= LAPSED_WAIT_MS;
82
+ if (!lapsed || end - Date.now() < MINIMUM_WAIT_MS)
83
+ throw error;
84
+ }
85
+ }
86
+ },
87
+ async signal(target, signal, options) {
88
+ // The call admits the value as portable before it is sent.
89
+ const input = { name: signal.name, value: signal.value };
90
+ await send(idOf(target), methods.signal, input, options);
91
+ },
92
+ async cancel(target, input = {}, options) {
93
+ const id = idOf(target);
94
+ return statusOf(id, await send(id, methods.cancel, { ...input }, options));
95
+ },
96
+ async resume(target, options) {
97
+ const id = idOf(target);
98
+ return statusOf(id, await send(id, methods.resume, {}, options));
99
+ },
100
+ async delete(target, options) {
101
+ await send(idOf(target), methods.delete, {}, options);
102
+ },
103
+ });
104
+ }
105
+ /** The wait an `ExecutionWait` asks for, in milliseconds. */
106
+ export function acceptWait(wait) {
107
+ const waitMs = wait?.waitMs ?? 0;
108
+ if (!Number.isSafeInteger(waitMs) || waitMs < 0) {
109
+ throw new TypeError('An Execution wait is a nonnegative integer of milliseconds.');
110
+ }
111
+ return waitMs;
112
+ }
113
+ function idOf(target) {
114
+ const id = typeof target === 'string' ? target : target?.id;
115
+ if (typeof id !== 'string')
116
+ throw new TypeError('An Execution is named by its reference or NodeId.');
117
+ return id;
118
+ }
119
+ function isPending(error) {
120
+ return error instanceof ResponseError && error.reason?.code === 'EXECUTION_PENDING';
121
+ }
@@ -0,0 +1,4 @@
1
+ export type { DeletedExecutionStatus, ExecutionFailure, ExecutionNodeStatus, ExecutionOutcome, ExecutionRef, ExecutionState, ExecutionStatus, ExecutionTarget, ExecutionWait, } from './contracts.js';
2
+ export { acceptWait, createExecution, executionMethods, type ExecutionApi, type ExecutionCall, type ExecutionMethods, } from './execution.js';
3
+ export { acceptOutput } from './admission.js';
4
+ export { deadlineOf, within } from './deadline.js';
@@ -0,0 +1,3 @@
1
+ export { acceptWait, createExecution, executionMethods, } from './execution.js';
2
+ export { acceptOutput } from './admission.js';
3
+ export { deadlineOf, within } from './deadline.js';
@@ -1,24 +1,21 @@
1
1
  import type { NodeId } from '@astrale-os/kernel-core/graph/node';
2
2
  import type { installation } from '@astrale-os/kernel-core/schema';
3
3
  import type { AttemptReport, DomainRequest as CoreDomainRequest, InstallClass as CoreInstallClass, InstallInput, InstallMode as CoreInstallMode, InstallReceipt as CoreInstallReceipt, SystemExecutionDetail, UninstallInput, UninstallOutput, ValidationOptions } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
4
- import type { Value } from '@astrale-os/kernel-dsl/value';
5
4
  import type { schema as protocolSchema } from '@astrale-os/kernel-protocol';
6
- import type { ExecutionState } from '../session/execution.js';
5
+ import type { ExecutionOutcome, ExecutionStatus, ExecutionWait } from '../execution/index.js';
7
6
  export type OperationId = installation.OperationId;
8
7
  /** Canonical caller input accepted by the Kernel install syscall. */
9
8
  export type DomainRequest = CoreDomainRequest;
10
9
  /**
11
- * One install: its Kernel input, plus `wait`, which the Client alone reads: `false` answers at
12
- * once, otherwise the Client waits for the outcome within the request deadline. It is never sent,
13
- * so it is no part of the operation's intent.
10
+ * One install: its Kernel input, plus `waitMs`, how long the Client waits for its outcome (110 s
11
+ * by default; `0` answers at once). `waitMs` is the Client's own: it is never sent, so it is no
12
+ * part of the operation's intent.
14
13
  */
15
- export type InstallRequest = InstallInput & {
16
- readonly wait?: boolean;
17
- };
14
+ export type InstallRequest = InstallInput & ExecutionWait;
18
15
  /** Admitted terminal install receipt returned by the Kernel. */
19
16
  export type InstallReceipt = CoreInstallReceipt;
20
- /** The `K.Execution` an install or uninstall is; a repair session's id is its Execution's. */
21
- export type InstallExecutionId = NodeId;
17
+ /** The committed result of an install: its receipt, or the generations it proved unchanged. */
18
+ export type InstallResult = protocolSchema.installation.InstallResult;
22
19
  /** What an install does to the stored data: nothing, applied at once, or revalidated first. */
23
20
  export type InstallClass = CoreInstallClass;
24
21
  export type InstallMode = CoreInstallMode;
@@ -28,78 +25,45 @@ export type InstallValidationOptions = ValidationOptions;
28
25
  export type InstallAttemptReport = AttemptReport;
29
26
  /** What an install or session shows beside its engine state, as Core shapes it. */
30
27
  export type InstallDetail = SystemExecutionDetail;
31
- /** The public failure a rejected install ended with, such as `DATA_MIGRATION_REQUIRED`. */
32
- export interface InstallFailure {
33
- readonly code: string;
34
- readonly message: string;
35
- readonly family?: string;
36
- readonly details?: Value;
37
- }
38
28
  /** A terminal install: its committed result, its rejection, or its cancellation. */
39
- export type InstallOutcome = {
40
- readonly kind: 'completed';
41
- readonly value: protocolSchema.installation.InstallResult;
42
- } | {
43
- readonly kind: 'failed';
44
- readonly error: InstallFailure;
45
- } | {
46
- readonly kind: 'cancelled';
47
- };
48
- /**
49
- * The status of one install, uninstall or repair session: the engine `state` the CLI decides on,
50
- * and the Core `detail` (phase, class, progress, the next command index, the running attempt and
51
- * the last attempt report).
52
- */
53
- export type InstallStatus<Outcome = InstallOutcome> = InstallNodeStatus<Outcome> | DeletedInstallStatus<Outcome>;
54
- /** The status of an install, uninstall or session whose Execution node exists. */
55
- export interface InstallNodeStatus<Outcome = InstallOutcome> {
56
- readonly id: InstallExecutionId;
57
- readonly function: NodeId;
58
- readonly version: `sha256:${string}`;
59
- readonly state: ExecutionState;
60
- readonly createdAt: string;
61
- readonly detail?: InstallDetail;
62
- /** Present exactly once the Execution is terminal. */
63
- readonly outcome?: Outcome;
64
- }
29
+ export type InstallOutcome = ExecutionOutcome<InstallResult>;
65
30
  /**
66
- * What Root alone reads once the Execution node of an install, uninstall or session was deleted:
67
- * the outcome its lifecycle record keeps, under the explicit state `deleted`.
31
+ * The status of one install or repair session: the engine `state` the CLI decides on, and the
32
+ * Core `detail` (phase, class, progress, the next command index, the running attempt and the last
33
+ * attempt report).
68
34
  */
69
- export interface DeletedInstallStatus<Outcome = InstallOutcome> {
70
- readonly id: InstallExecutionId;
71
- readonly state: 'deleted';
72
- readonly outcome: Outcome;
73
- /** Absent: the node that recorded them is deleted. */
74
- readonly function?: never;
75
- readonly version?: never;
76
- readonly createdAt?: never;
77
- readonly detail?: never;
78
- }
35
+ export type InstallStatus = ExecutionStatus<InstallResult>;
79
36
  /** One admitted install answer: its Execution, its status, and its result once completed. */
80
37
  export interface Installation {
81
- readonly execution: InstallExecutionId;
38
+ readonly execution: NodeId;
39
+ /**
40
+ * True when the operation id already named this Execution, so the call replayed it and changed
41
+ * nothing; false when this call started it; absent when the Host does not say.
42
+ */
43
+ readonly replayed?: boolean;
82
44
  readonly status: InstallStatus;
83
45
  /** The committed result, present exactly when the status is completed. */
84
- readonly result?: protocolSchema.installation.InstallResult;
46
+ readonly result?: InstallResult;
85
47
  }
86
- /** Canonical caller input accepted by the Kernel uninstall syscall. */
87
- export type UninstallRequest = UninstallInput;
48
+ /**
49
+ * One uninstall: its Kernel input, plus `waitMs`, how long the Client waits for its outcome, as
50
+ * for an install, and never sent.
51
+ */
52
+ export type UninstallRequest = UninstallInput & ExecutionWait;
88
53
  /** Admitted terminal uninstall receipt returned by the Kernel. */
89
54
  export type UninstallReceipt = UninstallOutput;
90
55
  /** A terminal uninstall: its committed receipt, its rejection, or its cancellation. */
91
- export type UninstallOutcome = {
92
- readonly kind: 'completed';
93
- readonly value: UninstallReceipt;
94
- } | {
95
- readonly kind: 'failed';
96
- readonly error: InstallFailure;
97
- } | {
98
- readonly kind: 'cancelled';
99
- };
56
+ export type UninstallOutcome = ExecutionOutcome<UninstallReceipt>;
57
+ /** The status of one uninstall. */
58
+ export type UninstallStatus = ExecutionStatus<UninstallReceipt>;
100
59
  /** One admitted uninstall answer: its Execution, its status, and its receipt once completed. */
101
60
  export interface Uninstallation {
102
- readonly execution: InstallExecutionId;
103
- readonly status: InstallStatus<UninstallOutcome>;
61
+ readonly execution: NodeId;
62
+ /**
63
+ * True when the operation id already named this Execution; false when this call started it;
64
+ * absent when the Host does not say.
65
+ */
66
+ readonly replayed?: boolean;
67
+ readonly status: UninstallStatus;
104
68
  readonly result?: UninstallReceipt;
105
69
  }
@@ -1,4 +1,4 @@
1
- export { createSchema, DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS, type SchemaApi, type SchemaCall, type SchemaOptions, type DomainBundle, type DomainDependencies, type DomainInfo, type InstalledPin, type InstalledRelease, type InstallResult, } from './schema.js';
1
+ export { createSchema, type SchemaApi, type SchemaCall, type SchemaOptions, type DomainBundle, type DomainDependencies, type DomainInfo, type InstalledPin, type InstalledRelease, } from './schema.js';
2
2
  export { acceptOperationId, createOperationId } from './operation.js';
3
3
  export type { InstallationApi, UninstallationApi } from './installation.js';
4
- export type { DomainRequest, InstallAttemptReport, InstallClass, InstallDetail, InstallExecutionId, InstallFailure, InstallMode, InstallOutcome, InstallStatus, InstallNodeStatus, DeletedInstallStatus, InstallValidationOptions, Installation, InstallReceipt, InstallRequest, OperationId, Uninstallation, UninstallOutcome, UninstallReceipt, UninstallRequest, } from './contracts.js';
4
+ export type { DomainRequest, InstallAttemptReport, InstallClass, InstallDetail, InstallMode, InstallOutcome, InstallResult, InstallStatus, InstallValidationOptions, Installation, InstallReceipt, InstallRequest, OperationId, Uninstallation, UninstallOutcome, UninstallReceipt, UninstallRequest, UninstallStatus, } from './contracts.js';
@@ -1,2 +1,2 @@
1
- export { createSchema, DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS, } from './schema.js';
1
+ export { createSchema, } from './schema.js';
2
2
  export { acceptOperationId, createOperationId } from './operation.js';
@@ -1,8 +1,8 @@
1
- import type { PathLike } from '@astrale-os/kernel-core/path';
1
+ import type { NodeId } from '@astrale-os/kernel-core/graph/node';
2
2
  import type { InstallValidation } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
3
+ import type { ExecutionCall, ExecutionWait } from '../execution/index.js';
3
4
  import type { RequestOptions } from '../transport/index.js';
4
- import type { InstallExecutionId, InstallFailure, InstallOutcome, InstallStatus, UninstallOutcome, UninstallReceipt } from './contracts.js';
5
- import type { SchemaCall } from './schema.js';
5
+ import type { InstallOutcome, InstallStatus, UninstallOutcome, UninstallStatus } from './contracts.js';
6
6
  /**
7
7
  * The install executions of one Instance, through the `K.Execution` Methods of each. Observing
8
8
  * and a cooperative cancel are Root's or the initiator's; signals, a forced cancel, resume and
@@ -10,16 +10,14 @@ import type { SchemaCall } from './schema.js';
10
10
  */
11
11
  export interface InstallationApi {
12
12
  /** The status of one install or repair session. */
13
- status(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus>;
14
- /** The terminal outcome, waiting at most `waitMs`; `EXECUTION_PENDING` once it lapses. */
15
- result(execution: InstallExecutionId, wait?: {
16
- readonly waitMs?: number;
17
- }, options?: RequestOptions): Promise<InstallOutcome>;
13
+ status(execution: NodeId, options?: RequestOptions): Promise<InstallStatus>;
14
+ /** The terminal outcome, waiting at most `waitMs` in total; `EXECUTION_PENDING` once it lapses. */
15
+ result(execution: NodeId, wait?: ExecutionWait, options?: RequestOptions): Promise<InstallOutcome>;
18
16
  /**
19
17
  * A waiting repair session attempts its target: the `command:<index>` signal, `index` being
20
18
  * the `detail.command` its status announces. A signal already resolved is refused.
21
19
  */
22
- apply(execution: InstallExecutionId, command: {
20
+ apply(execution: NodeId, command: {
23
21
  readonly index: number;
24
22
  readonly validation?: InstallValidation;
25
23
  }, options?: RequestOptions): Promise<void>;
@@ -27,19 +25,22 @@ export interface InstallationApi {
27
25
  * Stop the attempt a repair session runs, `detail.attempt.number`, through its `abort:<attempt>`
28
26
  * signal; the session waits again.
29
27
  */
30
- abort(execution: InstallExecutionId, attempt: number, options?: RequestOptions): Promise<void>;
28
+ abort(execution: NodeId, attempt: number, options?: RequestOptions): Promise<void>;
31
29
  /**
32
30
  * A cooperative cancel ends an install before its point of no return with nothing changed, and
33
- * has a repair session attempt its source schema. `force` kills the run; a live session first
34
- * takes the break-glass exit (the Instance reopens on its source, marked `uncertified`).
31
+ * has a repair session attempt its source schema. `force` kills the run; a live session refuses
32
+ * it `EXECUTION_EXIT_REFUSED`: cancel it cooperatively or apply it.
35
33
  */
36
- cancel(execution: InstallExecutionId, input?: {
34
+ cancel(execution: NodeId, input?: {
37
35
  readonly force?: boolean;
38
36
  }, options?: RequestOptions): Promise<InstallStatus>;
39
37
  /** Resume a paused install or session; a running one is unchanged. */
40
- resume(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus>;
41
- /** Delete the Execution, then kill and purge its run; a live session exits by break-glass. */
42
- delete(execution: InstallExecutionId, options?: RequestOptions): Promise<void>;
38
+ resume(execution: NodeId, options?: RequestOptions): Promise<InstallStatus>;
39
+ /**
40
+ * Delete the Execution, then kill and purge its run; a live session refuses it
41
+ * `EXECUTION_EXIT_REFUSED`: cancel or apply it first.
42
+ */
43
+ delete(execution: NodeId, options?: RequestOptions): Promise<void>;
43
44
  }
44
45
  /**
45
46
  * The uninstall executions of one Instance, through the same `K.Execution` Methods: a completed
@@ -47,58 +48,19 @@ export interface InstallationApi {
47
48
  */
48
49
  export interface UninstallationApi {
49
50
  /** The status of one uninstall. */
50
- status(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus<UninstallOutcome>>;
51
- /** The terminal outcome, waiting at most `waitMs`; `EXECUTION_PENDING` once it lapses. */
52
- result(execution: InstallExecutionId, wait?: {
53
- readonly waitMs?: number;
54
- }, options?: RequestOptions): Promise<UninstallOutcome>;
51
+ status(execution: NodeId, options?: RequestOptions): Promise<UninstallStatus>;
52
+ /** The terminal outcome, waiting at most `waitMs` in total; `EXECUTION_PENDING` once it lapses. */
53
+ result(execution: NodeId, wait?: ExecutionWait, options?: RequestOptions): Promise<UninstallOutcome>;
55
54
  /** A cooperative cancel ends it before its point of no return; `force` kills the run. */
56
- cancel(execution: InstallExecutionId, input?: {
55
+ cancel(execution: NodeId, input?: {
57
56
  readonly force?: boolean;
58
- }, options?: RequestOptions): Promise<InstallStatus<UninstallOutcome>>;
57
+ }, options?: RequestOptions): Promise<UninstallStatus>;
59
58
  /** Resume a paused uninstall; a running one is unchanged. */
60
- resume(execution: InstallExecutionId, options?: RequestOptions): Promise<InstallStatus<UninstallOutcome>>;
59
+ resume(execution: NodeId, options?: RequestOptions): Promise<UninstallStatus>;
61
60
  /** Delete the Execution, then kill and purge its run. */
62
- delete(execution: InstallExecutionId, options?: RequestOptions): Promise<void>;
61
+ delete(execution: NodeId, options?: RequestOptions): Promise<void>;
63
62
  }
64
- /** Admit a completed outcome's value; anything else of the outcome is kept as admitted. */
65
- export type AcceptValue<Value> = (input: unknown) => Value;
66
- export type ExecutionOutcomeOf<Value> = {
67
- readonly kind: 'completed';
68
- readonly value: Value;
69
- } | {
70
- readonly kind: 'failed';
71
- readonly error: InstallFailure;
72
- } | {
73
- readonly kind: 'cancelled';
74
- };
75
- /** The `K.Execution` Methods of one Execution, over one call capability; package-private. */
76
- export declare function executionMethods(call: SchemaCall, options: (input: RequestOptions | undefined) => RequestOptions): Readonly<{
77
- status: <Value>(id: InstallExecutionId, accept: AcceptValue<Value>, request?: RequestOptions) => Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
78
- result<Value>(id: InstallExecutionId, accept: AcceptValue<Value>, wait?: {
79
- readonly waitMs?: number;
80
- }, request?: RequestOptions): Promise<ExecutionOutcomeOf<Value>>;
81
- signal(id: InstallExecutionId, name: string, signalled: unknown, request?: RequestOptions): Promise<void>;
82
- cancel: <Value>(id: InstallExecutionId, accept: AcceptValue<Value>, input: {
83
- readonly force?: boolean;
84
- }, request?: RequestOptions) => Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
85
- resume: <Value>(id: InstallExecutionId, accept: AcceptValue<Value>, request?: RequestOptions) => Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
86
- delete(id: InstallExecutionId, request?: RequestOptions): Promise<void>;
87
- /** Admit what a durable call answers at once: the Execution it created or recovered. */
88
- start(path: PathLike, input: unknown, request?: RequestOptions): Promise<InstallExecutionId>;
89
- /**
90
- * Wait within the request deadline for the outcome. A wait that lapsed after waiting, while
91
- * time remains, waits again; a wait a closing process or a gap with no process failed is sent
92
- * again. Every other end of the wait, or its deadline, leaves the Execution as it is: its
93
- * status, read next, says where it is, so the caller never loses the Execution.
94
- */
95
- settle(id: InstallExecutionId, request?: RequestOptions): Promise<void>;
96
- /** The status after a wait, read again as `settle` sends its wait again, within the deadline. */
97
- observe<Value>(id: InstallExecutionId, accept: AcceptValue<Value>, request?: RequestOptions): Promise<InstallStatus<ExecutionOutcomeOf<Value>>>;
98
- }>;
99
- export type ExecutionMethods = ReturnType<typeof executionMethods>;
100
63
  /** The install Methods: a completed outcome carries the result its Protocol owner admits. */
101
- export declare function createInstallation(executions: ExecutionMethods): InstallationApi;
64
+ export declare function createInstallation(call: ExecutionCall): InstallationApi;
102
65
  /** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
103
- export declare function createUninstallation(executions: ExecutionMethods): UninstallationApi;
104
- export declare function acceptUninstallReceipt(input: unknown): UninstallReceipt;
66
+ export declare function createUninstallation(call: ExecutionCall): UninstallationApi;