@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.
@@ -1,140 +1,34 @@
1
- import { Path } from '@astrale-os/kernel-core/path';
2
- import { abortSignal, commandSignal, executionOutcome, executionStatus, uninstallOutput, } 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';
1
+ import { abortSignal, commandSignal, uninstallOutput, } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
5
2
  import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
6
- import { call as invocation } from '../client/index.js';
7
- import { ResponseError, TransportError } from '../errors/index.js';
8
- import { RETRY_REFUSALS, retry } from '../pacer/index.js';
9
- import { acceptOutput } from './admission.js';
10
- /** Attempts of one effect-free Execution read; the wait'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 starts with less time left than this before its deadline. */
15
- const MINIMUM_WAIT_MS = 1_000;
16
- /** The `K.Execution` Methods of one Execution, over one call capability; package-private. */
17
- export function executionMethods(call, options) {
18
- const value = async (id, method, input, request) => {
19
- const target = Path.instanceMethod(Path.id(id), MethodKey.of(method.owner, method.name));
20
- const result = await call(invocation(target, input), options(request));
21
- if (result.kind !== 'value')
22
- throw new TypeError('Execution Method returned a non-value result.');
23
- return result.value;
24
- };
25
- /**
26
- * An Execution read has no effect: one a process refused with a retry delay, or a gap with no
27
- * process on the port failed, is sent again through the pacer, each attempt within `deadline`.
28
- */
29
- const read = (deadline, request, work) => retry(() => work({ ...request, timeoutMs: Math.max(1, deadline - Date.now()) }), {
30
- maxAttempts: READ_ATTEMPTS,
31
- shouldRetry: (error, attempt) => Date.now() < deadline &&
32
- (error instanceof TransportError || RETRY_REFUSALS.shouldRetry(error, attempt)),
33
- retryAfter: RETRY_REFUSALS.retryAfter,
34
- });
35
- const status = async (id, accept, answer) => {
36
- const admitted = acceptOutput(executionStatus, await answer, 'Execution status');
37
- if (admitted.id !== id)
38
- throw new TypeError('Kernel returned the status of another Execution.');
39
- const outcome = admitted.outcome === undefined ? undefined : outcomeOf(admitted.outcome, accept);
40
- // A deleted Execution carries the outcome its lifecycle record keeps, whatever its kind.
41
- if (admitted.state !== 'deleted' &&
42
- (admitted.state === 'completed') !== (outcome?.kind === 'completed')) {
43
- throw new TypeError('Execution status and outcome disagree.');
44
- }
45
- if (admitted.state === 'deleted')
46
- return Object.freeze({ id, state: 'deleted', outcome: outcome });
47
- const { outcome: _outcome, ...rest } = admitted;
48
- return Object.freeze({ ...rest, ...(outcome === undefined ? {} : { outcome }) });
49
- };
50
- return Object.freeze({
51
- status: (id, accept, request) => status(id, accept, value(id, methods.status, {}, request)),
52
- async result(id, accept, wait = {}, request) {
53
- const answer = await value(id, methods.result, { ...wait }, request);
54
- return outcomeOf(acceptOutput(executionOutcome, answer, 'Execution outcome'), accept);
55
- },
56
- async signal(id, name, signalled, request) {
57
- await value(id, methods.signal, { name, value: signalled }, request);
58
- },
59
- cancel: (id, accept, input, request) => status(id, accept, value(id, methods.cancel, { ...input }, request)),
60
- resume: (id, accept, request) => status(id, accept, value(id, methods.resume, {}, request)),
61
- async delete(id, request) {
62
- await value(id, methods.delete, {}, request);
63
- },
64
- /** Admit what a durable call answers at once: the Execution it created or recovered. */
65
- async start(path, input, request) {
66
- const result = await call(invocation(path, input), options(request));
67
- if (result.kind !== 'execution')
68
- throw new TypeError('Schema syscall did not answer with an Execution.');
69
- return result.execution;
70
- },
71
- /**
72
- * Wait within the request deadline for the outcome. A wait that lapsed after waiting, while
73
- * time remains, waits again; a wait a closing process or a gap with no process failed is sent
74
- * again. Every other end of the wait, or its deadline, leaves the Execution as it is: its
75
- * status, read next, says where it is, so the caller never loses the Execution.
76
- */
77
- async settle(id, request) {
78
- const deadline = Date.now() + (options(request).timeoutMs ?? 0);
79
- while (deadline - Date.now() >= MINIMUM_WAIT_MS) {
80
- const started = Date.now();
81
- try {
82
- await read(deadline, request, (attempt) => value(id, methods.result, { waitMs: attempt.timeoutMs }, attempt));
83
- return;
84
- }
85
- catch (error) {
86
- const pending = error instanceof ResponseError && error.reason?.code === 'EXECUTION_PENDING';
87
- if (!pending || Date.now() - started < LAPSED_WAIT_MS)
88
- return;
89
- }
90
- }
91
- },
92
- /** The status after a wait, read again as `settle` sends its wait again, within the deadline. */
93
- observe(id, accept, request) {
94
- const deadline = Date.now() + (options(request).timeoutMs ?? 0);
95
- return read(deadline, request, (attempt) => status(id, accept, value(id, methods.status, {}, attempt)));
96
- },
97
- });
98
- }
3
+ import { acceptOutput, executionMethods } from '../execution/index.js';
99
4
  /** The install Methods: a completed outcome carries the result its Protocol owner admits. */
100
- export function createInstallation(executions) {
101
- const accept = (input) => {
102
- if (uninstallOutput.safeParse(input).success) {
103
- throw new TypeError('The Execution is an uninstall: read it through SchemaApi.uninstallation.');
104
- }
105
- return protocolSchema.installation.acceptResult(input);
106
- };
5
+ export function createInstallation(call) {
6
+ const { signal, ...methods } = executionMethods(call, acceptInstallResult);
107
7
  return Object.freeze({
108
- status: (execution, request) => executions.status(execution, accept, request),
109
- result: (execution, wait, request) => executions.result(execution, accept, wait, request),
110
- apply: async (execution, command, request) => executions.signal(execution, commandSignal(ordinal(command.index)), Object.freeze({
111
- kind: 'apply',
112
- ...(command.validation === undefined ? {} : { validation: command.validation }),
113
- }), request),
114
- abort: async (execution, attempt, request) => executions.signal(execution, abortSignal(ordinal(attempt)), Object.freeze({ kind: 'abort' }), request),
115
- cancel: (execution, input = {}, request) => executions.cancel(execution, accept, input, request),
116
- resume: (execution, request) => executions.resume(execution, accept, request),
117
- delete: (execution, request) => executions.delete(execution, request),
8
+ ...methods,
9
+ apply: async (execution, command, options) => signal(execution, {
10
+ name: commandSignal(ordinal(command.index)),
11
+ value: Object.freeze({
12
+ kind: 'apply',
13
+ ...(command.validation === undefined ? {} : { validation: command.validation }),
14
+ }),
15
+ }, options),
16
+ abort: async (execution, attempt, options) => signal(execution, { name: abortSignal(ordinal(attempt)), value: Object.freeze({ kind: 'abort' }) }, options),
118
17
  });
119
18
  }
120
19
  /** The uninstall Methods: a completed outcome carries the receipt Core's contract admits. */
121
- export function createUninstallation(executions) {
122
- const accept = acceptUninstallReceipt;
123
- return Object.freeze({
124
- status: (execution, request) => executions.status(execution, accept, request),
125
- result: (execution, wait, request) => executions.result(execution, accept, wait, request),
126
- cancel: (execution, input = {}, request) => executions.cancel(execution, accept, input, request),
127
- resume: (execution, request) => executions.resume(execution, accept, request),
128
- delete: (execution, request) => executions.delete(execution, request),
129
- });
20
+ export function createUninstallation(call) {
21
+ const { signal: _signal, ...methods } = executionMethods(call, acceptUninstallReceipt);
22
+ return Object.freeze(methods);
130
23
  }
131
- export function acceptUninstallReceipt(input) {
132
- return acceptOutput(uninstallOutput, input, 'uninstall receipt');
24
+ function acceptInstallResult(input) {
25
+ if (uninstallOutput.safeParse(input).success) {
26
+ throw new TypeError('The Execution is an uninstall: read it through SchemaApi.uninstallation.');
27
+ }
28
+ return protocolSchema.installation.acceptResult(input);
133
29
  }
134
- function outcomeOf(outcome, accept) {
135
- if (outcome.kind !== 'completed')
136
- return outcome;
137
- return Object.freeze({ kind: 'completed', value: accept(outcome.value) });
30
+ function acceptUninstallReceipt(input) {
31
+ return acceptOutput(uninstallOutput, input, 'uninstall receipt');
138
32
  }
139
33
  function ordinal(input) {
140
34
  if (!Number.isSafeInteger(input) || input < 1) {
@@ -1,32 +1,31 @@
1
1
  import type { Key } from '@astrale-os/kernel-dsl/v1';
2
- import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
2
+ import type * as protocolSchema from '@astrale-os/kernel-protocol/schema';
3
3
  import type { Call, Result } from '../client/index.js';
4
4
  import type { RequestOptions } from '../transport/index.js';
5
5
  import type { Installation, InstallRequest, Uninstallation, UninstallRequest } from './contracts.js';
6
6
  import { type InstallationApi, type UninstallationApi } from './installation.js';
7
7
  export type SchemaCall = (call: Call, options?: RequestOptions) => Promise<Result>;
8
8
  export interface SchemaOptions extends protocolSchema.installation.introspection.Limits {
9
- readonly lifecycleTimeoutMs?: number;
10
9
  }
11
10
  export type DomainInfo = protocolSchema.installation.introspection.DomainInfo;
12
11
  export type DomainBundle = protocolSchema.installation.introspection.DomainBundle;
13
12
  export type DomainDependencies = protocolSchema.installation.introspection.DomainDependencies;
14
13
  export type InstalledRelease = protocolSchema.installation.introspection.InstalledRelease;
15
14
  export type InstalledPin = protocolSchema.installation.introspection.InstalledPin;
16
- export type InstallResult = protocolSchema.installation.InstallResult;
17
15
  export interface SchemaApi {
18
16
  /**
19
- * Install Domains: start the durable Execution the install is, then, unless `wait` is false or
20
- * the mode is `maintenance`, wait within the request deadline for its outcome. The answer names
21
- * the Execution with its status; `result` is present once it completed. A rejected install is a
22
- * terminal `failed` status, never a failed call.
17
+ * Install Domains: start the durable Execution the install is, wait at most `waitMs` (110 s by
18
+ * default) for its outcome unless the mode is `maintenance`, and read its status. `timeoutMs`,
19
+ * when given, bounds the whole call. The answer names the Execution with its status; `result` is
20
+ * present once it completed. A rejected install is a terminal `failed` status, never a failed
21
+ * call.
23
22
  */
24
23
  install(request: InstallRequest, options?: RequestOptions): Promise<Installation>;
25
24
  /** The install executions and repair sessions, through their `K.Execution` Methods. */
26
25
  readonly installation: InstallationApi;
27
26
  /**
28
- * Uninstall Domains: start the durable Execution the uninstall is and wait within the request
29
- * deadline for its outcome. `result` is the receipt once it completed.
27
+ * Uninstall Domains: start the durable Execution the uninstall is, wait at most `waitMs` (110 s
28
+ * by default) for its outcome and read its status. `result` is the receipt once it completed.
30
29
  */
31
30
  uninstall(request: UninstallRequest, options?: RequestOptions): Promise<Uninstallation>;
32
31
  /** The uninstall executions, through their `K.Execution` Methods. */
@@ -36,6 +35,5 @@ export interface SchemaApi {
36
35
  dependencies(origin: Key.Origin, options?: RequestOptions): Promise<DomainDependencies>;
37
36
  installed(options?: RequestOptions): Promise<readonly InstalledRelease[]>;
38
37
  }
39
- export declare const DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS = 110000;
40
38
  /** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
41
39
  export declare function createSchema(call: SchemaCall, limits: SchemaOptions): SchemaApi;
@@ -1,41 +1,39 @@
1
1
  import { Path } from '@astrale-os/kernel-core/path';
2
2
  import { install, uninstall } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
3
- import * as protocolSchema from '@astrale-os/kernel-protocol/schema';
4
- import { acceptUninstallReceipt, createInstallation, createUninstallation, executionMethods, } from './installation.js';
3
+ import { call as invocation } from '../client/index.js';
4
+ import { acceptWait, deadlineOf, within } from '../execution/index.js';
5
+ import { createInstallation, createUninstallation, } from './installation.js';
5
6
  import { introspect } from './introspection.js';
6
7
  const INSTALL_PATH = Path.project(install).raw;
7
8
  const UNINSTALL_PATH = Path.project(uninstall).raw;
8
- export const DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS = 110_000;
9
+ /** How long an install or uninstall waits for its outcome unless its request says otherwise. */
10
+ const DEFAULT_LIFECYCLE_WAIT_MS = 110_000;
9
11
  /** Bind the canonical Schema lifecycle syscalls to one caller-scoped value-call capability. */
10
12
  export function createSchema(call, limits) {
11
13
  if (typeof call !== 'function')
12
14
  throw new TypeError('Schema call capability is invalid.');
13
15
  const admittedLimits = admitLimits(limits);
14
- const executions = executionMethods(call, (options) => lifecycleOptions(options, admittedLimits.lifecycleTimeoutMs));
15
- const installation = createInstallation(executions);
16
- const uninstallation = createUninstallation(executions);
16
+ const installation = createInstallation(call);
17
+ const uninstallation = createUninstallation(call);
17
18
  return Object.freeze({
18
19
  async install(request, options) {
19
- // `wait` is the Client's own: it never reaches the Kernel, so it is no part of the intent.
20
- const { wait, ...input } = request;
21
- const execution = await executions.start(INSTALL_PATH, input, options);
20
+ const { waitMs, ...input } = request;
21
+ const wait = lifecycleWait(waitMs);
22
22
  // A maintenance session awaits Root's commands: its outcome is not the call's to wait for.
23
- if (wait !== false && input.mode !== 'maintenance') {
24
- await executions.settle(execution, options);
25
- }
26
- const status = await executions.observe(execution, protocolSchema.installation.acceptResult, options);
27
- return admitInstallation(request, execution, status);
23
+ const started = await lifecycle(call, installation, INSTALL_PATH, input, input.mode === 'maintenance' ? 0 : wait, options);
24
+ return admitInstallation(request, started);
28
25
  },
29
26
  installation,
30
27
  async uninstall(request, options) {
28
+ const wait = lifecycleWait(request.waitMs);
31
29
  const snapshot = snapshotUninstallRequest(request);
32
- const execution = await executions.start(UNINSTALL_PATH, snapshot, options);
33
- await executions.settle(execution, options);
34
- const status = await executions.observe(execution, acceptUninstallReceipt, options);
30
+ const started = await lifecycle(call, uninstallation, UNINSTALL_PATH, snapshot, wait, options);
31
+ const answer = { execution: started.status.id, ...started };
32
+ const { status } = started;
35
33
  if (status.outcome?.kind !== 'completed')
36
- return Object.freeze({ execution, status });
34
+ return Object.freeze(answer);
37
35
  proveUninstallReceipt(snapshot, status.outcome.value);
38
- return Object.freeze({ execution, status, result: status.outcome.value });
36
+ return Object.freeze({ ...answer, result: status.outcome.value });
39
37
  },
40
38
  uninstallation,
41
39
  async inspect(origin, options) {
@@ -52,6 +50,28 @@ export function createSchema(call, limits) {
52
50
  },
53
51
  });
54
52
  }
53
+ /**
54
+ * One lifecycle syscall, before the call's deadline: start the durable Execution it is, wait at
55
+ * most `waitMs` for its outcome, and read its status. Any end of the wait leaves the status to say
56
+ * where the Execution is, so the caller never loses it.
57
+ */
58
+ async function lifecycle(call, executions, path, input, waitMs, options) {
59
+ const deadline = deadlineOf(options);
60
+ const started = await call(invocation(path, input), within(deadline, options));
61
+ if (started.kind !== 'execution') {
62
+ throw new TypeError('Schema syscall did not answer with an Execution.');
63
+ }
64
+ if (waitMs > 0) {
65
+ await executions
66
+ .result(started.execution, { waitMs }, within(deadline, options))
67
+ .catch(() => undefined);
68
+ }
69
+ const status = await executions.status(started.execution, within(deadline, options));
70
+ return started.replayed === undefined ? { status } : { status, replayed: started.replayed };
71
+ }
72
+ function lifecycleWait(waitMs) {
73
+ return acceptWait({ waitMs: waitMs ?? DEFAULT_LIFECYCLE_WAIT_MS });
74
+ }
55
75
  function snapshotUninstallRequest(request) {
56
76
  return Object.freeze({
57
77
  operation: request.operation,
@@ -76,12 +96,14 @@ function compare(left, right) {
76
96
  * The answer of one install, proved against its request: a completed status carries the result of
77
97
  * exactly this operation, admitted by its Protocol owner.
78
98
  */
79
- function admitInstallation(request, execution, status) {
99
+ function admitInstallation(request, started) {
100
+ const answer = { execution: started.status.id, ...started };
101
+ const { status } = started;
80
102
  if (status.outcome?.kind !== 'completed')
81
- return Object.freeze({ execution, status });
103
+ return Object.freeze(answer);
82
104
  const result = status.outcome.value;
83
105
  proveInstallResult(request, result);
84
- return Object.freeze({ execution, status, result });
106
+ return Object.freeze({ ...answer, result });
85
107
  }
86
108
  function proveInstallResult(request, result) {
87
109
  if (result.changed) {
@@ -98,22 +120,13 @@ function proveInstallResult(request, result) {
98
120
  }
99
121
  }
100
122
  function admitLimits(input) {
101
- const lifecycleTimeoutMs = input?.lifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS;
102
123
  if (input === null ||
103
124
  typeof input !== 'object' ||
104
125
  !Number.isSafeInteger(input.maximumReleaseBytes) ||
105
126
  input.maximumReleaseBytes < 1 ||
106
127
  !Number.isSafeInteger(input.maximumBundleBytes) ||
107
- input.maximumBundleBytes < 1 ||
108
- !Number.isSafeInteger(lifecycleTimeoutMs) ||
109
- lifecycleTimeoutMs < 1 ||
110
- lifecycleTimeoutMs > 2_147_483_647) {
128
+ input.maximumBundleBytes < 1) {
111
129
  throw new TypeError('Schema introspection limits are invalid.');
112
130
  }
113
- return Object.freeze({ ...input, lifecycleTimeoutMs });
114
- }
115
- function lifecycleOptions(options, timeoutMs) {
116
- if (options?.timeoutMs !== undefined)
117
- return options;
118
- return Object.freeze({ ...options, timeoutMs });
131
+ return Object.freeze({ ...input });
119
132
  }
@@ -1,5 +1,6 @@
1
1
  import type { IssuerId } from '@astrale-os/kernel-core/auth';
2
2
  import type { AuthApi } from '../auth/index.js';
3
+ import type { ExecutionApi } from '../execution/index.js';
3
4
  import type { SchemaApi } from '../schema/index.js';
4
5
  import type { ContentApi } from './content/index.js';
5
6
  import type { SessionControlOptions } from './context/index.js';
@@ -36,6 +37,7 @@ export interface BoundClientSession extends GraphApi {
36
37
  readonly kernel: IssuerId;
37
38
  readonly auth: AuthApi;
38
39
  readonly schema: SchemaApi;
40
+ readonly execution: ExecutionApi;
39
41
  readonly content: ContentApi;
40
42
  dispatch: ClientSession['dispatch'];
41
43
  call: ClientSession['call'];
@@ -1,5 +1,6 @@
1
1
  import { createAuth } from '../auth/auth.js';
2
2
  import { call as createCall, } from '../client/index.js';
3
+ import { createExecution } from '../execution/index.js';
3
4
  import { createGraph } from '../graph/index.js';
4
5
  /** Capture one Session into the ordinary graph, auth, and invocation Kernel journey. */
5
6
  export function bindSession(source, controls) {
@@ -65,12 +66,14 @@ export function bindSession(source, controls) {
65
66
  installed,
66
67
  });
67
68
  const graph = createGraph(call);
69
+ const execution = createExecution(dispatch);
68
70
  const auth = createAuth((target, input, options) => call(createCall(target, input), options), admit);
69
71
  return Object.freeze({
70
72
  ...graph,
71
73
  kernel: source.kernel,
72
74
  auth,
73
75
  schema,
76
+ execution,
74
77
  dispatch,
75
78
  call,
76
79
  invoke,
@@ -9,6 +9,6 @@ export type { ClientSessionOptions } from './options.js';
9
9
  export { ClientSession, connect, type ConnectOptions } from './session.js';
10
10
  export type { CallableReference, InputOfReference, InputModeOfReference, InstanceCallableReference, OutputOfReference, } from './reference.js';
11
11
  export { reference } from './reference.js';
12
- export { execution, type ExecutionOutcome, type ExecutionRef, type DeletedExecutionStatus, type ExecutionNodeStatus, type ExecutionState, type ExecutionStatus, } from './execution.js';
12
+ export type { DeletedExecutionStatus, ExecutionApi, ExecutionFailure, ExecutionNodeStatus, ExecutionOutcome, ExecutionRef, ExecutionState, ExecutionStatus, ExecutionTarget, ExecutionWait, } from '../execution/index.js';
13
13
  export type { ResolvedView, ViewCatalog } from './views/index.js';
14
14
  export type { DomainBinding } from '../graph/domain/index.js';
@@ -2,4 +2,3 @@ export { bindSession, } from './bound.js';
2
2
  export { credentials, } from './credential/index.js';
3
3
  export { ClientSession, connect } from './session.js';
4
4
  export { reference } from './reference.js';
5
- export { execution, } from './execution.js';
@@ -33,7 +33,6 @@ export interface ClientSessionOptions {
33
33
  readonly maximumBundleBytes?: number;
34
34
  readonly maximumResponseBytes?: number;
35
35
  readonly timeoutMs?: number;
36
- readonly schemaLifecycleTimeoutMs?: number;
37
36
  }
38
37
  /** The caller's options once admitted, defaulted and captured, ready for the Session to wire. */
39
38
  export interface SessionConfiguration {
@@ -45,7 +44,6 @@ export interface SessionConfiguration {
45
44
  readonly maximumBundleBytes: number;
46
45
  readonly maximumResponseBytes: number;
47
46
  readonly timeoutMs: number;
48
- readonly schemaLifecycleTimeoutMs: number;
49
47
  readonly websocketAvailable: boolean;
50
48
  /** Present when the Session created, and therefore closes, its own pool. */
51
49
  readonly ownedPool?: ClientPool;
@@ -1,6 +1,5 @@
1
1
  import { Client } from '../client/index.js';
2
2
  import { ClientPool } from '../pool/index.js';
3
- import { DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS } from '../schema/index.js';
4
3
  import { AutoTransport } from '../transport/auto/index.js';
5
4
  import { HttpTransport } from '../transport/http/index.js';
6
5
  import { WebSocketTransport } from '../transport/websocket/index.js';
@@ -30,7 +29,6 @@ export function acceptSessionOptions(options) {
30
29
  const maximumBundleBytes = positive(options.maximumBundleBytes ?? DEFAULT_MAXIMUM_BUNDLE_BYTES, 'maximumBundleBytes');
31
30
  const maximumResponseBytes = positive(options.maximumResponseBytes ?? DEFAULT_MAXIMUM_RESPONSE_BYTES, 'maximumResponseBytes');
32
31
  const timeoutMs = platformDuration(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, 'timeoutMs');
33
- const schemaLifecycleTimeoutMs = platformDuration(options.schemaLifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS, 'schemaLifecycleTimeoutMs');
34
32
  let ownedPool;
35
33
  let pool;
36
34
  if (options.pool === undefined) {
@@ -62,7 +60,6 @@ export function acceptSessionOptions(options) {
62
60
  maximumBundleBytes,
63
61
  maximumResponseBytes,
64
62
  timeoutMs,
65
- schemaLifecycleTimeoutMs,
66
63
  websocketAvailable: options.client !== undefined ||
67
64
  options.pool !== undefined ||
68
65
  options.websocket !== undefined ||
@@ -4,7 +4,7 @@ import type { MethodAddress } from '@astrale-os/kernel-dsl/v1/addressing';
4
4
  import type { MeaningFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprint';
5
5
  import { type Key as KeyType } from '@astrale-os/kernel-dsl/v1/addressing';
6
6
  import type { Binary, Input, Result } from '../client/index.js';
7
- import type { ExecutionRef } from './execution.js';
7
+ import type { ExecutionRef } from '../execution/index.js';
8
8
  /** Result kind a reference expects: a durable callable answers with its Execution. */
9
9
  type OutputMode = Exclude<Result['kind'], 'redirect'>;
10
10
  declare const REFERENCE_INPUT: unique symbol;
@@ -3,6 +3,7 @@ import type { PathLike } from '@astrale-os/kernel-core/path';
3
3
  import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
4
4
  import type { AuthApi } from '../auth/index.js';
5
5
  import type { Call, Input, Result } from '../client/index.js';
6
+ import type { ExecutionApi } from '../execution/index.js';
6
7
  import type { DomainBinding, GraphApi } from '../graph/index.js';
7
8
  import type { SchemaApi } from '../schema/index.js';
8
9
  import type { ContentApi } from './content/index.js';
@@ -22,6 +23,8 @@ export type ConnectOptions = Omit<ClientSessionOptions, 'kernel' | 'policy'> & {
22
23
  export declare class ClientSession {
23
24
  readonly kernel: IssuerId;
24
25
  readonly schema: SchemaApi;
26
+ /** The `K.Execution` Methods of any Execution, a durable call's or an install's. */
27
+ readonly execution: ExecutionApi;
25
28
  readonly graph: GraphApi;
26
29
  readonly auth: AuthApi;
27
30
  readonly content: ContentApi;
@@ -3,6 +3,7 @@ import { callableFingerprint } from '@astrale-os/kernel-dsl/v1/schema/fingerprin
3
3
  import { createAuth } from '../auth/auth.js';
4
4
  import { acceptCall } from '../client/index.js';
5
5
  import { SessionError } from '../errors/index.js';
6
+ import { createExecution } from '../execution/index.js';
6
7
  import { createDomainBinding } from '../graph/domain/binding.js';
7
8
  import { createGraph } from '../graph/index.js';
8
9
  import { createSchema } from '../schema/index.js';
@@ -20,6 +21,8 @@ const DEFAULT_SESSION_POLICY = Object.freeze({ maximumRouteAgeMs: 60_000 });
20
21
  export class ClientSession {
21
22
  kernel;
22
23
  schema;
24
+ /** The `K.Execution` Methods of any Execution, a durable call's or an install's. */
25
+ execution;
23
26
  graph;
24
27
  auth;
25
28
  content;
@@ -92,8 +95,8 @@ export class ClientSession {
92
95
  this.schema = createSchema((request, options) => this.dispatch(request, options), {
93
96
  maximumReleaseBytes,
94
97
  maximumBundleBytes,
95
- lifecycleTimeoutMs: settled.schemaLifecycleTimeoutMs,
96
98
  });
99
+ this.execution = createExecution((request, options) => this.dispatch(request, options));
97
100
  this.graph = createGraph((call, options) => this.call(call, options));
98
101
  this.auth = createAuth((target, input, options) => this.call({ target, input }, options), (call, options) => {
99
102
  const operation = this.operation(admitControlOptions(options));
@@ -166,7 +169,10 @@ export class ClientSession {
166
169
  case 'stream':
167
170
  return narrowed.stream;
168
171
  case 'execution':
169
- return Object.freeze({ id: narrowed.execution });
172
+ return Object.freeze({
173
+ id: narrowed.execution,
174
+ ...(narrowed.replayed === undefined ? {} : { replayed: narrowed.replayed }),
175
+ });
170
176
  default:
171
177
  return narrowed.value;
172
178
  }
@@ -4,7 +4,7 @@ import { K, KernelSchema } from '@astrale-os/kernel-core/schema';
4
4
  import { defineSchema, func, method, nodeClass, schema, valueSchema, } from '@astrale-os/kernel-dsl/v1';
5
5
  import { isBinaryInput } from '@astrale-os/kernel-dsl/v1/language';
6
6
  import { call } from '../client/index.js';
7
- import { ClientSession, credentials, execution, reference } from './index.js';
7
+ import { ClientSession, credentials, reference } from './index.js';
8
8
  void new ClientSession(options);
9
9
  void auth;
10
10
  void control;
@@ -189,12 +189,13 @@ const durableDomain = schema.resolve(defineSchema('client.durable.typecheck', {
189
189
  }));
190
190
  const remindReference = reference(durableDomain, durableDomain.classes.Invoice.methods.remind)(Path.id(NodeId('invoice-1')));
191
191
  const durableReturnsExecution = true;
192
+ const outcome = session.execution.result(run, { waitMs: 1_000 });
192
193
  const outcomeIsTyped = true;
194
+ const status = session.execution.status(run);
193
195
  const statusIsTyped = true;
194
- void session.invoke(execution.result(run), { waitMs: 1_000 });
195
- void session.invoke(execution.signal(run), { name: 'approval', value: { by: 'billing' } });
196
+ void session.execution.signal(run, { name: 'approval', value: { by: 'billing' } });
196
197
  // @ts-expect-error Force is the only cancellation option.
197
- void session.invoke(execution.cancel(run), { waitMs: 1_000 });
198
+ void session.execution.cancel(run, { waitMs: 1_000 });
198
199
  void durableReturnsExecution;
199
200
  void outcomeIsTyped;
200
201
  void statusIsTyped;
@@ -91,7 +91,12 @@ export async function admitResponse(response, requestId, context) {
91
91
  }
92
92
  requireLive(control);
93
93
  if ('execution' in envelope) {
94
- return { kind: 'execution', execution: envelope.execution, invocation: envelope.invocation };
94
+ return {
95
+ kind: 'execution',
96
+ execution: envelope.execution,
97
+ ...(envelope.replayed === undefined ? {} : { replayed: envelope.replayed }),
98
+ invocation: envelope.invocation,
99
+ };
95
100
  }
96
101
  return { kind: 'value', value: envelope.result, invocation: envelope.invocation };
97
102
  }
@@ -157,6 +157,7 @@ export class WebSocketExchange {
157
157
  this.complete({
158
158
  kind: 'execution',
159
159
  execution: response.execution,
160
+ ...(response.replayed === undefined ? {} : { replayed: response.replayed }),
160
161
  invocation: response.invocation,
161
162
  });
162
163
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",
@@ -65,13 +65,13 @@
65
65
  "access": "public"
66
66
  },
67
67
  "dependencies": {
68
- "@astrale-os/kernel-core": "1.0.0-beta.6",
68
+ "@astrale-os/kernel-core": "1.0.0-beta.8",
69
69
  "@astrale-os/kernel-dsl": "1.0.0-beta.3",
70
- "@astrale-os/kernel-protocol": "1.0.0-beta.6",
70
+ "@astrale-os/kernel-protocol": "1.0.0-beta.8",
71
71
  "@tanstack/pacer": "0.20.1"
72
72
  },
73
73
  "devDependencies": {
74
- "@astrale-os/kernel-server": "1.0.0-beta.6",
74
+ "@astrale-os/kernel-server": "1.0.0-beta.8",
75
75
  "@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
76
76
  "@types/node": "^22.0.0",
77
77
  "typescript": "7.0.2",
@@ -1,34 +0,0 @@
1
- import { Path } from '@astrale-os/kernel-core/path';
2
- import { execution as methods } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
3
- import { kernelReference } from './reference.js';
4
- const bound = {
5
- status: kernelReference(methods.status),
6
- result: kernelReference(methods.result),
7
- cancel: kernelReference(methods.cancel),
8
- signal: kernelReference(methods.signal),
9
- resume: kernelReference(methods.resume),
10
- delete: kernelReference(methods.delete),
11
- };
12
- function receiver(execution) {
13
- return Path.id(typeof execution === 'string' ? execution : execution.id);
14
- }
15
- /**
16
- * Typed references to the methods of one Execution, for `session.invoke`:
17
- *
18
- * ```ts
19
- * const run = await session.invoke(remind(invoice), { days: 3 })
20
- * const outcome = await session.invoke(execution.result(run), { waitMs: 10_000 })
21
- * ```
22
- */
23
- export const execution = Object.freeze({
24
- status: (target) => bound.status(receiver(target)),
25
- /** Outcome once terminal; fails `EXECUTION_PENDING` when `waitMs` elapses first. */
26
- result: (target) => bound.result(receiver(target)),
27
- /** Cooperative cancellation; `force` kills without compensation (owner Domain only). */
28
- cancel: (target) => bound.cancel(receiver(target)),
29
- /** Resolve a named durable promise once (owner Domain only). */
30
- signal: (target) => bound.signal(receiver(target)),
31
- resume: (target) => bound.resume(receiver(target)),
32
- /** Forget the Execution and stop its run (owner Domain only). */
33
- delete: (target) => bound.delete(receiver(target)),
34
- });