@astrale-os/kernel-client 1.0.0-beta.25 → 1.0.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/client/admission.js +3 -1
  2. package/dist/client/client.d.ts +16 -3
  3. package/dist/client/client.js +36 -15
  4. package/dist/client/index.d.ts +2 -2
  5. package/dist/client/index.js +1 -1
  6. package/dist/client/routing-control.d.ts +11 -15
  7. package/dist/client/routing-control.js +21 -29
  8. package/dist/errors/query-input.js +2 -1
  9. package/dist/errors/stale-route-error.d.ts +1 -1
  10. package/dist/errors/stale-route-error.js +1 -1
  11. package/dist/graph/page-contract.d.ts +8 -3
  12. package/dist/graph/query.js +10 -4
  13. package/dist/graph/query.typecheck.js +1 -1
  14. package/dist/session/admission.js +4 -2
  15. package/dist/session/credential/credentials.js +32 -28
  16. package/dist/session/discovery/bundle.d.ts +9 -4
  17. package/dist/session/discovery/bundle.js +28 -35
  18. package/dist/session/discovery/discovery.d.ts +1 -1
  19. package/dist/session/discovery/discovery.js +7 -10
  20. package/dist/session/discovery/release.js +18 -28
  21. package/dist/session/discovery/transport.d.ts +35 -3
  22. package/dist/session/discovery/transport.js +40 -1
  23. package/dist/session/exchange/exchange.d.ts +3 -2
  24. package/dist/session/exchange/exchange.js +10 -7
  25. package/dist/session/exchange/index.d.ts +1 -1
  26. package/dist/session/exchange/index.js +1 -1
  27. package/dist/session/exchange/presentation.js +28 -10
  28. package/dist/session/exchange/source.d.ts +7 -7
  29. package/dist/session/exchange/source.js +26 -27
  30. package/dist/session/routing/auth.d.ts +9 -3
  31. package/dist/session/routing/auth.js +4 -3
  32. package/dist/session/routing/cache.d.ts +12 -5
  33. package/dist/session/routing/cache.js +56 -48
  34. package/dist/session/routing/dispatch.d.ts +2 -1
  35. package/dist/session/routing/dispatch.js +83 -61
  36. package/dist/session/routing/index.d.ts +1 -1
  37. package/dist/session/routing/recovery.d.ts +3 -6
  38. package/dist/session/routing/recovery.js +3 -14
  39. package/dist/session/routing/store.js +4 -5
  40. package/dist/session/views/kernel.d.ts +31 -0
  41. package/dist/session/views/kernel.js +30 -0
  42. package/dist/session/views/read.js +5 -10
  43. package/dist/session/views/view.js +1 -6
  44. package/dist/store/memory.d.ts +1 -3
  45. package/dist/store/memory.js +61 -112
  46. package/dist/store/shape.d.ts +33 -12
  47. package/dist/store/shape.js +125 -16
  48. package/dist/store/store.js +1 -1
  49. package/dist/transport/auto/decision.d.ts +26 -14
  50. package/dist/transport/auto/decision.js +35 -32
  51. package/dist/transport/auto/fallback.d.ts +1 -1
  52. package/dist/transport/auto/fallback.js +5 -10
  53. package/dist/transport/auto/transport.d.ts +0 -2
  54. package/dist/transport/auto/transport.js +24 -32
  55. package/dist/transport/failure.d.ts +28 -1
  56. package/dist/transport/failure.js +57 -1
  57. package/dist/transport/http/admission.js +2 -2
  58. package/dist/transport/http/binary.js +1 -1
  59. package/dist/transport/http/byte-stream.d.ts +2 -1
  60. package/dist/transport/http/byte-stream.js +10 -7
  61. package/dist/transport/http/stream.d.ts +8 -13
  62. package/dist/transport/http/stream.js +32 -79
  63. package/dist/transport/http/transport.js +11 -22
  64. package/dist/transport/stream.d.ts +52 -0
  65. package/dist/transport/stream.js +101 -0
  66. package/dist/transport/unary.d.ts +3 -2
  67. package/dist/transport/unary.js +3 -3
  68. package/dist/transport/websocket/connection.d.ts +7 -3
  69. package/dist/transport/websocket/connection.js +102 -85
  70. package/dist/transport/websocket/exchange.d.ts +10 -19
  71. package/dist/transport/websocket/exchange.js +72 -153
  72. package/dist/transport/websocket/transport.js +11 -19
  73. package/package.json +6 -5
@@ -6,20 +6,22 @@ export interface LearnedRoute {
6
6
  readonly credential?: string;
7
7
  readonly expiresAt: number;
8
8
  }
9
- /** One warm entry; `sealed` and `integrity` are present only when it can be persisted. */
9
+ /** One warm entry; `persisted` is present only when it can be persisted. */
10
10
  export interface CachedRoute {
11
11
  readonly learned: LearnedRoute;
12
12
  /** Separate from route age; derived only from a supported finite carrier expiry. */
13
13
  readonly credentialRefreshBoundary?: number;
14
- readonly sealed?: LearnedRoute;
15
- readonly integrity?: string;
14
+ /** The entry as it was sealed, with the HMAC binding it to its key. */
15
+ readonly persisted?: {
16
+ readonly sealed: LearnedRoute;
17
+ readonly integrity: string;
18
+ };
16
19
  }
17
20
  /** Confidential warm routing state owned by exactly one ClientSession. */
18
21
  export declare class RouteCache {
19
22
  private readonly maximumAgeMs;
20
23
  private readonly maximumSize;
21
24
  private readonly entries;
22
- private readonly keyTokens;
23
25
  private readonly store?;
24
26
  constructor(maximumAgeMs: number, maximumSize?: number, store?: SessionRouteStore);
25
27
  key(source: string, call: invocation.Call, auth: EffectiveAuth): Promise<string>;
@@ -28,8 +30,13 @@ export declare class RouteCache {
28
30
  delete(key: string): void;
29
31
  /** Clear this Session's memory without deleting caller-owned persistent state. */
30
32
  clear(): void;
31
- private invalidate;
33
+ /** Mark the key's entry most recently used. */
34
+ private touch;
35
+ /** Fence any check in flight on the key; its warm route, if any, stays usable in place. */
32
36
  private reserve;
37
+ /** Make the key the newest warm entry, evicting the least recently used beyond the bound. */
38
+ private warm;
39
+ private invalidate;
33
40
  private restore;
34
41
  private persist;
35
42
  }
@@ -7,7 +7,6 @@ export class RouteCache {
7
7
  maximumAgeMs;
8
8
  maximumSize;
9
9
  entries = new Map();
10
- keyTokens = new Map();
11
10
  store;
12
11
  constructor(maximumAgeMs, maximumSize = DEFAULT_MAXIMUM_ROUTES, store) {
13
12
  this.maximumAgeMs = maximumAgeMs;
@@ -16,27 +15,27 @@ export class RouteCache {
16
15
  this.restore();
17
16
  }
18
17
  async key(source, call, auth) {
19
- const credential = auth.credential === undefined ? 'anonymous' : await digestText(auth.credential);
20
- const delegate = auth.delegate === undefined
21
- ? 'anonymous'
22
- : await digestText(JSON.stringify({ ttlSeconds: auth.delegate.ttlSeconds }));
18
+ if (auth.kind === 'anonymous') {
19
+ return JSON.stringify([source, call.target, 'anonymous', 'anonymous']);
20
+ }
21
+ const credential = await digestText(auth.credential);
22
+ const delegate = await digestText(JSON.stringify({ ttlSeconds: auth.delegate.ttlSeconds }));
23
23
  return JSON.stringify([source, call.target, credential, delegate]);
24
24
  }
25
25
  async get(key, sourceCredential, now, operationDeadline) {
26
- const cached = this.entries.get(key);
27
- if (cached === undefined)
26
+ const entry = this.entries.get(key);
27
+ const cached = entry?.cached;
28
+ if (entry === undefined || cached === undefined)
28
29
  return undefined;
29
- const token = this.keyTokens.get(key);
30
30
  if (cached.learned.expiresAt <= (now ?? Date.now())) {
31
31
  this.invalidate(key);
32
32
  return undefined;
33
33
  }
34
- if (cached.integrity !== undefined) {
34
+ if (cached.persisted !== undefined) {
35
35
  const matches = sourceCredential !== undefined &&
36
- (await matchesIntegrity(sourceCredential, key, cached.sealed ?? cached.learned, cached.integrity));
37
- if (this.keyTokens.get(key) !== token || this.entries.get(key) !== cached) {
36
+ (await matchesIntegrity(sourceCredential, key, cached.persisted.sealed, cached.persisted.integrity));
37
+ if (this.entries.get(key) !== entry)
38
38
  return undefined;
39
- }
40
39
  if (!matches) {
41
40
  this.invalidate(key);
42
41
  return undefined;
@@ -53,91 +52,100 @@ export class RouteCache {
53
52
  // This operation needs a fresh carrier; a shorter concurrent operation may still reuse it.
54
53
  return undefined;
55
54
  }
56
- this.entries.delete(key);
57
- this.entries.set(key, cached);
55
+ this.touch(key, entry);
58
56
  return cached.learned;
59
57
  }
60
58
  async learn(key, route, credential, sourceCredential, now = Date.now()) {
61
59
  const expiry = credential === undefined ? undefined : credentialExpiry(credential);
62
60
  const credentialRefreshBoundary = expiry === undefined ? undefined : refreshBoundary(expiry);
63
61
  const expiresAt = Math.min(now + this.maximumAgeMs, refreshBoundary(expiry));
64
- const entry = Object.freeze({
62
+ const learned = Object.freeze({
65
63
  route,
66
64
  ...(credential === undefined ? {} : { credential }),
67
65
  expiresAt,
68
66
  });
69
67
  // A carrier with no supported finite expiry may be used for this follow, but never warmed.
70
68
  if (credential !== undefined && expiry === undefined)
71
- return entry;
69
+ return learned;
72
70
  if (expiresAt <= now)
73
- return entry;
74
- const token = this.reserve(key);
71
+ return learned;
72
+ const reserved = this.reserve(key);
75
73
  let integrity;
76
74
  if (this.store !== undefined && sourceCredential !== undefined) {
77
75
  try {
78
- integrity = await routeIntegrity(sourceCredential, key, entry);
76
+ integrity = await routeIntegrity(sourceCredential, key, learned);
79
77
  }
80
78
  catch {
81
79
  // Integrity support is a persistence optimization; the learned route remains usable in memory.
82
80
  }
83
81
  }
84
- if (this.keyTokens.get(key) !== token) {
85
- return entry;
86
- }
87
- this.entries.delete(key);
88
- while (this.entries.size >= this.maximumSize) {
89
- const oldest = this.entries.keys().next().value;
90
- if (oldest === undefined)
91
- break;
92
- this.entries.delete(oldest);
93
- this.keyTokens.delete(oldest);
94
- }
95
- this.entries.set(key, Object.freeze({
96
- learned: entry,
82
+ if (this.entries.get(key) !== reserved)
83
+ return learned;
84
+ this.warm(key, Object.freeze({
85
+ learned,
97
86
  ...(credentialRefreshBoundary === undefined ? {} : { credentialRefreshBoundary }),
98
- ...(integrity === undefined ? {} : { sealed: entry, integrity }),
87
+ ...(integrity === undefined
88
+ ? {}
89
+ : { persisted: Object.freeze({ sealed: learned, integrity }) }),
99
90
  }));
100
91
  this.persist();
101
- return entry;
92
+ return learned;
102
93
  }
103
94
  delete(key) {
104
95
  this.invalidate(key);
105
96
  }
106
97
  /** Clear this Session's memory without deleting caller-owned persistent state. */
107
98
  clear() {
108
- this.keyTokens.clear();
109
99
  this.entries.clear();
110
100
  }
111
- invalidate(key) {
112
- this.keyTokens.delete(key);
113
- if (this.entries.delete(key))
114
- this.persist();
101
+ /** Mark the key's entry most recently used. */
102
+ touch(key, entry) {
103
+ this.entries.delete(key);
104
+ this.entries.set(key, entry);
115
105
  }
106
+ /** Fence any check in flight on the key; its warm route, if any, stays usable in place. */
116
107
  reserve(key) {
117
- const token = Object.freeze({});
118
- this.keyTokens.set(key, token);
119
- return token;
108
+ const reserved = Object.freeze({ ...this.entries.get(key) });
109
+ this.entries.set(key, reserved);
110
+ return reserved;
111
+ }
112
+ /** Make the key the newest warm entry, evicting the least recently used beyond the bound. */
113
+ warm(key, cached) {
114
+ this.entries.delete(key);
115
+ const warmKeys = [...this.entries].flatMap(([other, entry]) => entry.cached === undefined ? [] : [other]);
116
+ while (warmKeys.length >= this.maximumSize) {
117
+ const oldest = warmKeys.shift();
118
+ if (oldest === undefined)
119
+ break;
120
+ this.entries.delete(oldest);
121
+ }
122
+ this.entries.set(key, Object.freeze({ cached }));
123
+ }
124
+ invalidate(key) {
125
+ const entry = this.entries.get(key);
126
+ this.entries.delete(key);
127
+ if (entry?.cached !== undefined)
128
+ this.persist();
120
129
  }
121
130
  restore(now = Date.now()) {
122
131
  if (this.store === undefined)
123
132
  return;
124
133
  try {
125
134
  const restored = restoreRoutes(this.store.read(), now, this.maximumAgeMs, this.maximumSize);
126
- for (const [key, entry] of restored) {
127
- this.reserve(key);
128
- this.entries.set(key, entry);
129
- }
135
+ for (const [key, cached] of restored)
136
+ this.entries.set(key, Object.freeze({ cached }));
130
137
  }
131
138
  catch {
132
- this.keyTokens.clear();
139
+ // An unreadable store restores nothing; the Session starts cold.
133
140
  this.entries.clear();
134
141
  }
135
142
  }
136
143
  persist() {
137
144
  if (this.store === undefined)
138
145
  return;
146
+ const warmRoutes = [...this.entries].flatMap(([key, entry]) => entry.cached === undefined ? [] : [[key, entry.cached]]);
139
147
  try {
140
- this.store.write(routeArtifact(this.entries));
148
+ this.store.write(routeArtifact(warmRoutes));
141
149
  }
142
150
  catch {
143
151
  // A cache-store outage must not turn a valid invocation into a product failure.
@@ -52,10 +52,11 @@ export declare class SessionDispatcher {
52
52
  * Dispatch a resolved Call. Sending it again presents the same principal and caller, which an
53
53
  * idempotency key needs to name the same Execution.
54
54
  */
55
- dispatchResolved(dispatch: ResolvedCall, options: SessionRequestOptions, operation: SessionOperation, streaming?: Streaming): Promise<Result>;
55
+ dispatchResolved(resolved: ResolvedCall, options: SessionRequestOptions, operation: SessionOperation, streaming?: Streaming): Promise<Result>;
56
56
  /** The cached route for this partition, evicted when it no longer passes delivery checks. */
57
57
  private warmRoute;
58
58
  private dispatchSource;
59
+ /** The source answers routing control only as the public error: it has no route to recover. */
59
60
  private followSource;
60
61
  private dispatchDestinationWithRecovery;
61
62
  private dispatchDestination;
@@ -1,10 +1,10 @@
1
- import { acceptCall, Client, dispatchInternal } from '../../client/index.js';
1
+ import { acceptCall, Client, dispatchInternal, isRoutingControl, routingControlError, } from '../../client/index.js';
2
2
  import { ClientError } from '../../errors/index.js';
3
3
  import { runSessionOperation, remainingSessionTime, sessionTransportOptions, allowEndpoint, } from '../context/index.js';
4
4
  import { resolveAuth } from './auth.js';
5
5
  import { selectEnvelope, selectEnvelopeTarget } from './envelope.js';
6
6
  import { releaseRoutesDeclaration } from './legacy/release-route.js';
7
- import { isRouteCompatibilityConflict, recoveryRefresh, routingControl } from './recovery.js';
7
+ import { isRouteCompatibilityConflict, recoveryRefresh } from './recovery.js';
8
8
  export class SessionDispatcher {
9
9
  state;
10
10
  constructor(state) {
@@ -35,86 +35,107 @@ export class SessionDispatcher {
35
35
  * Dispatch a resolved Call. Sending it again presents the same principal and caller, which an
36
36
  * idempotency key needs to name the same Execution.
37
37
  */
38
- async dispatchResolved(dispatch, options, operation, streaming) {
38
+ async dispatchResolved(resolved, options, operation, streaming) {
39
39
  this.state.requireOpen();
40
- const learned = await this.warmRoute(dispatch, operation, streaming);
41
- if (learned !== undefined) {
42
- return this.dispatchDestinationWithRecovery(learned, dispatch, options, operation, undefined, streaming);
43
- }
44
- const result = await this.dispatchSource(dispatch, undefined, options, operation, streaming);
45
- return this.followSource(result, dispatch, options, operation, streaming);
40
+ const attempt = Object.freeze({
41
+ resolved,
42
+ options,
43
+ operation,
44
+ ...(streaming === undefined ? {} : { streaming }),
45
+ });
46
+ const learned = await this.warmRoute(attempt);
47
+ if (learned !== undefined)
48
+ return this.dispatchDestinationWithRecovery(learned, attempt);
49
+ const result = await this.dispatchSource(attempt, undefined);
50
+ return this.followSource(result, attempt);
46
51
  }
47
52
  /** The cached route for this partition, evicted when it no longer passes delivery checks. */
48
- async warmRoute(state, operation, streaming) {
49
- const learned = await runSessionOperation(operation, () => this.state.cache.get(state.cacheKey, state.auth.credential, undefined, operation.deadline));
53
+ async warmRoute(attempt) {
54
+ const { resolved, operation, streaming } = attempt;
55
+ const learned = await runSessionOperation(operation, () => this.state.cache.get(resolved.cacheKey, presentedCredential(resolved.auth), undefined, operation.deadline));
50
56
  if (learned === undefined)
51
57
  return undefined;
52
58
  try {
53
- requireLearnedRoute(learned, state.source, state.call.target);
59
+ requireLearnedRoute(learned, resolved.source, resolved.call.target);
54
60
  selectEnvelopeTarget(learned.route.endpoint, streaming === undefined ? this.state.envelopeTransport : 'http', this.state.websocketAvailable, this.state.policy);
55
61
  return learned;
56
62
  }
57
63
  catch {
58
- this.state.cache.delete(state.cacheKey);
64
+ this.state.cache.delete(resolved.cacheKey);
59
65
  return undefined;
60
66
  }
61
67
  }
62
- async dispatchSource(state, routing, options, operation, streaming) {
68
+ async dispatchSource(attempt, routing) {
69
+ const { resolved, options, operation, streaming } = attempt;
63
70
  this.state.requireOpen();
64
71
  remainingSessionTime(operation);
65
72
  allowEndpoint(this.state.sourceEndpoint, this.state.policy);
66
73
  const client = streaming === undefined
67
74
  ? this.state.pool.clientFor(Object.freeze({ transport: 'http', url: this.state.sourceEndpoint }))
68
75
  : this.streamingClientFor(this.state.sourceEndpoint);
69
- return runSessionOperation(operation, () => send(client, state.auth.credential, state.call, {
70
- ...transportOptions(operation, options, streaming),
71
- ...(state.auth.delegate === undefined ? {} : { delegate: state.auth.delegate }),
72
- ...(routing === undefined ? {} : { routing }),
73
- // The guard is the source Kernel's: a routed destination request never carries it.
74
- ...(options.maintenance === undefined ? {} : { maintenance: options.maintenance }),
75
- }, streaming?.body));
76
+ return sendWithin(operation, client, {
77
+ credential: presentedCredential(resolved.auth),
78
+ call: resolved.call,
79
+ options: {
80
+ ...transportOptions(attempt),
81
+ ...(resolved.auth.kind === 'anonymous' ? {} : { delegate: resolved.auth.delegate }),
82
+ ...(routing === undefined ? {} : { routing }),
83
+ // The guard is the source Kernel's: a routed destination request never carries it.
84
+ ...(options.maintenance === undefined ? {} : { maintenance: options.maintenance }),
85
+ },
86
+ body: streaming?.body,
87
+ });
76
88
  }
77
- async followSource(result, state, options, operation, streaming) {
89
+ /** The source answers routing control only as the public error: it has no route to recover. */
90
+ async followSource(result, attempt) {
91
+ if (isRoutingControl(result))
92
+ throw routingControlError(result);
78
93
  if (result.kind !== 'redirect')
79
94
  return result;
95
+ const { resolved, operation, streaming } = attempt;
80
96
  requireResendable(streaming, 'follow a Redirect');
81
97
  const redirect = result.redirect;
82
- if (redirect.route.via.issuer !== state.source) {
98
+ if (redirect.route.via.issuer !== resolved.source) {
83
99
  throw new ClientError('Redirect issuer differs from the session-pinned source Kernel identity.');
84
100
  }
85
- requireRouteForTarget(redirect.route, state.call.target);
86
- const learned = await runSessionOperation(operation, () => this.state.cache.learn(state.cacheKey, redirect.route, redirect.credential, state.auth.credential));
87
- return this.dispatchDestinationWithRecovery(learned, state, options, operation, redirect.trace, streaming);
101
+ requireRouteForTarget(redirect.route, resolved.call.target);
102
+ const learned = await runSessionOperation(operation, () => this.state.cache.learn(resolved.cacheKey, redirect.route, redirect.credential, presentedCredential(resolved.auth)));
103
+ return this.dispatchDestinationWithRecovery(learned, attempt, redirect.trace);
88
104
  }
89
- async dispatchDestinationWithRecovery(learned, state, options, operation, trace, streaming) {
105
+ async dispatchDestinationWithRecovery(learned, attempt, trace) {
106
+ const { resolved, operation, streaming } = attempt;
107
+ let result;
90
108
  try {
91
- return await this.dispatchDestination(learned, state.call, options, operation, state.source, trace, streaming);
109
+ result = await this.dispatchDestination(learned, attempt, trace);
92
110
  }
93
111
  catch (cause) {
94
- const control = routingControl(cause);
95
- if (control === undefined) {
96
- if (isRouteCompatibilityConflict(cause))
97
- this.state.cache.delete(state.cacheKey);
98
- throw cause;
99
- }
100
- this.state.cache.delete(state.cacheKey);
101
- if (!operation.claimRecovery())
102
- throw cause;
103
- requireResendable(streaming, 'recover its route', cause);
104
- const routing = recoveryRefresh(control, learned);
105
- const refreshed = await this.dispatchSource(state, routing, options, operation, streaming);
106
- return this.followSource(refreshed, state, options, operation, streaming);
112
+ if (isRouteCompatibilityConflict(cause))
113
+ this.state.cache.delete(resolved.cacheKey);
114
+ throw cause;
107
115
  }
116
+ if (!isRoutingControl(result))
117
+ return result;
118
+ this.state.cache.delete(resolved.cacheKey);
119
+ const failure = routingControlError(result);
120
+ if (!operation.claimRecovery())
121
+ throw failure;
122
+ requireResendable(streaming, 'recover its route', failure);
123
+ const refreshed = await this.dispatchSource(attempt, recoveryRefresh(result, learned));
124
+ return this.followSource(refreshed, attempt);
108
125
  }
109
- async dispatchDestination(learned, call, options, operation, source, trace, streaming) {
126
+ async dispatchDestination(learned, attempt, trace) {
127
+ const { resolved, operation, streaming } = attempt;
110
128
  remainingSessionTime(operation);
111
- requireLearnedRoute(learned, source, call.target);
129
+ requireLearnedRoute(learned, resolved.source, resolved.call.target);
112
130
  const client = this.destinationClient(learned, streaming);
113
- const request = {
114
- ...transportOptions(operation, options, streaming),
115
- routing: learned.route.via,
116
- };
117
- const result = await runSessionOperation(operation, () => send(client, learned.credential, call, request, streaming?.body, trace));
131
+ const options = { ...transportOptions(attempt), routing: learned.route.via };
132
+ const result = await sendWithin(operation, client, {
133
+ credential: learned.credential,
134
+ call: resolved.call,
135
+ options,
136
+ trace,
137
+ body: streaming?.body,
138
+ });
118
139
  if (result.kind === 'redirect') {
119
140
  throw new ClientError('A destination redirect is invalid; only the source Kernel may redirect.');
120
141
  }
@@ -142,8 +163,21 @@ export class SessionDispatcher {
142
163
  });
143
164
  }
144
165
  }
166
+ /**
167
+ * Send one request within the operation. Routing control that answers an interrupted operation
168
+ * yields its interruption, exactly as a failure inside the operation does: it is never recovered.
169
+ */
170
+ async function sendWithin(operation, client, dispatch) {
171
+ const result = await runSessionOperation(operation, () => dispatchInternal(client, dispatch));
172
+ // Re-entering the operation is its own interruption check; it adds no work.
173
+ return isRoutingControl(result) ? runSessionOperation(operation, () => result) : result;
174
+ }
175
+ /** The credential a Call presents to the source Kernel; an anonymous Call presents none. */
176
+ function presentedCredential(auth) {
177
+ return auth.kind === 'anonymous' ? undefined : auth.credential;
178
+ }
145
179
  /** A body-carrying streaming call omits the idempotency key; every other call keeps it. */
146
- function transportOptions(operation, options, streaming) {
180
+ function transportOptions({ operation, options, streaming }) {
147
181
  return streaming?.body === undefined
148
182
  ? sessionTransportOptions(operation, options.idempotencyKey)
149
183
  : sessionTransportOptions(operation);
@@ -171,15 +205,3 @@ function requireRouteForTarget(route, target) {
171
205
  if (!routes)
172
206
  throw new ClientError('Resolved route does not name the Target declaration.');
173
207
  }
174
- /**
175
- * Send one call, presenting the Trace only on the attempt that carries it. A call with a body goes
176
- * through the package-private path, which sends the admitted body: the public Client refuses a
177
- * stream, because only this routing refuses to resend it. A body-carrying call is always sent by a
178
- * Client this routing created.
179
- */
180
- function send(client, credential, call, options, body, trace) {
181
- if (trace !== undefined || body !== undefined) {
182
- return dispatchInternal(client, credential, call, options, trace, body);
183
- }
184
- return (credential === undefined ? client : client.as(credential)).dispatch(call, options);
185
- }
@@ -1,4 +1,4 @@
1
- export { admitSessionAuth, resolveAuth, type Auth, type AuthExchange, type EffectiveAuth, type SessionAuth, } from './auth.js';
1
+ export { admitSessionAuth, resolveAuth, type Auth, type Authenticated, type AuthExchange, type EffectiveAuth, type SessionAuth, } from './auth.js';
2
2
  export { RouteCache, type LearnedRoute } from './cache.js';
3
3
  export { SessionDispatcher, type SessionDispatcherOptions } from './dispatch.js';
4
4
  export { type ClientPoolCapability, type EnvelopeSelection } from './envelope.js';
@@ -1,16 +1,13 @@
1
1
  import type * as invocation from '@astrale-os/kernel-protocol/invocation';
2
+ import type { RoutingControl } from '../../client/index.js';
2
3
  import type { LearnedRoute } from './cache.js';
3
- /** The privately witnessed pre-handler control a destination failure carries, if any. */
4
- export type RoutingControl = 'stale' | 'miss' | 'retired';
5
- /** The routing control a destination failure witnesses, if any. */
6
- export declare function routingControl(input: unknown): RoutingControl | undefined;
7
4
  /**
8
5
  * The Refresh a recovery source hop carries. A stale or retired route names the release the
9
6
  * destination no longer serves; a miss names a Path, so the source receives no digest for it.
10
7
  */
11
8
  export declare function recoveryRefresh(control: RoutingControl, learned: LearnedRoute): invocation.Refresh | undefined;
12
9
  /**
13
- * A failure that proves the warm route can no longer serve this call without witnessing a
14
- * pre-handler control: the route is evicted for later calls, but the invocation is never replayed.
10
+ * A failure that proves the warm route can no longer serve this call without carrying routing
11
+ * control: the route is evicted for later calls, but the invocation is never replayed.
15
12
  */
16
13
  export declare function isRouteCompatibilityConflict(input: unknown): boolean;
@@ -1,22 +1,11 @@
1
1
  import * as invocationProtocol from '@astrale-os/kernel-protocol/invocation';
2
- import { isAdmittedDeploymentRetiredError, isAdmittedMissError, isAdmittedStaleRouteError, } from '../../client/index.js';
3
2
  import { ResponseError } from '../../errors/index.js';
4
- /** The routing control a destination failure witnesses, if any. */
5
- export function routingControl(input) {
6
- if (isAdmittedStaleRouteError(input))
7
- return 'stale';
8
- if (isAdmittedMissError(input))
9
- return 'miss';
10
- if (isAdmittedDeploymentRetiredError(input))
11
- return 'retired';
12
- return undefined;
13
- }
14
3
  /**
15
4
  * The Refresh a recovery source hop carries. A stale or retired route names the release the
16
5
  * destination no longer serves; a miss names a Path, so the source receives no digest for it.
17
6
  */
18
7
  export function recoveryRefresh(control, learned) {
19
- if (control === 'miss')
8
+ if (control.kind === 'miss')
20
9
  return undefined;
21
10
  return Object.freeze({
22
11
  kind: 'refresh',
@@ -24,8 +13,8 @@ export function recoveryRefresh(control, learned) {
24
13
  });
25
14
  }
26
15
  /**
27
- * A failure that proves the warm route can no longer serve this call without witnessing a
28
- * pre-handler control: the route is evicted for later calls, but the invocation is never replayed.
16
+ * A failure that proves the warm route can no longer serve this call without carrying routing
17
+ * control: the route is evicted for later calls, but the invocation is never replayed.
29
18
  */
30
19
  export function isRouteCompatibilityConflict(input) {
31
20
  if (!(input instanceof ResponseError))
@@ -46,14 +46,14 @@ export function restoreRoutes(input, now, maximumAgeMs, maximumSize) {
46
46
  }
47
47
  /** The artifact persisting every integrity-bound entry, as it was sealed. */
48
48
  export function routeArtifact(entries) {
49
- const persisted = Object.fromEntries([...entries].flatMap(([key, cached]) => cached.integrity === undefined
49
+ const persisted = Object.fromEntries([...entries].flatMap(([key, cached]) => cached.persisted === undefined
50
50
  ? []
51
51
  : [
52
52
  [
53
53
  key,
54
54
  Object.freeze({
55
- ...(cached.sealed ?? cached.learned),
56
- integrity: cached.integrity,
55
+ ...cached.persisted.sealed,
56
+ integrity: cached.persisted.integrity,
57
57
  }),
58
58
  ],
59
59
  ]));
@@ -88,8 +88,7 @@ function admitStoredEntry(input, now, maximumAgeMs) {
88
88
  ...(sealed.credential === undefined ? {} : { credential: sealed.credential }),
89
89
  expiresAt,
90
90
  }),
91
- sealed,
92
- integrity: value.integrity,
91
+ persisted: Object.freeze({ sealed, integrity: value.integrity }),
93
92
  ...(expiry === undefined ? {} : { credentialRefreshBoundary: refreshBoundary(expiry) }),
94
93
  });
95
94
  }
@@ -0,0 +1,31 @@
1
+ /** The Kernel `View` Class. */
2
+ export declare const VIEW_CLASS: Readonly<{
3
+ origin: 'kernel.astrale.ai';
4
+ kind: 'class';
5
+ name: "View";
6
+ }>;
7
+ /** The Kernel `of_domain` Edge Class, which only projection writes. */
8
+ export declare const OF_DOMAIN_CLASS: Readonly<{
9
+ origin: 'kernel.astrale.ai';
10
+ kind: 'class';
11
+ name: "of_domain";
12
+ }>;
13
+ /** The Kernel `Domain` Class. */
14
+ export declare const DOMAIN_CLASS: Readonly<{
15
+ origin: 'kernel.astrale.ai';
16
+ kind: 'class';
17
+ name: "Domain";
18
+ }>;
19
+ export declare const VIEW: "kernel.astrale.ai:class.View";
20
+ export declare const OF_DOMAIN: "kernel.astrale.ai:class.of_domain";
21
+ export declare const DOMAIN: "kernel.astrale.ai:class.Domain";
22
+ /** `View.placement`: where and how a Shell mounts the View. */
23
+ export declare const PLACEMENT: "kernel.astrale.ai:class.View.property.placement";
24
+ /** `of_domain.member`: the member name under which a Domain declares the Node. */
25
+ export declare const MEMBER: "kernel.astrale.ai:class.of_domain.property.member";
26
+ /** `Domain.origin`. */
27
+ export declare const ORIGIN: "kernel.astrale.ai:class.Domain.property.origin";
28
+ /** `Descriptable.description`. */
29
+ export declare const DESCRIPTION: "kernel.astrale.ai:class.Descriptable.property.description";
30
+ /** `Identity.iss`. */
31
+ export declare const ISSUER: "kernel.astrale.ai:class.Identity.property.iss";
@@ -0,0 +1,30 @@
1
+ import { ClassKey, PropertyKey } from '@astrale-os/kernel-dsl/v1/addressing';
2
+ // The Kernel Classes a View read names, by their coordinates. `K` is built by the DSL builder when
3
+ // its module loads, and the Session must not resolve the Kernel Schema on loading, so these are
4
+ // written out here and the tests hold them equal to `K`.
5
+ function kernelClass(name) {
6
+ return Object.freeze({
7
+ origin: 'kernel.astrale.ai',
8
+ kind: 'class',
9
+ name,
10
+ });
11
+ }
12
+ /** The Kernel `View` Class. */
13
+ export const VIEW_CLASS = kernelClass('View');
14
+ /** The Kernel `of_domain` Edge Class, which only projection writes. */
15
+ export const OF_DOMAIN_CLASS = kernelClass('of_domain');
16
+ /** The Kernel `Domain` Class. */
17
+ export const DOMAIN_CLASS = kernelClass('Domain');
18
+ export const VIEW = ClassKey.of(VIEW_CLASS);
19
+ export const OF_DOMAIN = ClassKey.of(OF_DOMAIN_CLASS);
20
+ export const DOMAIN = ClassKey.of(DOMAIN_CLASS);
21
+ /** `View.placement`: where and how a Shell mounts the View. */
22
+ export const PLACEMENT = PropertyKey.of(VIEW_CLASS, 'placement');
23
+ /** `of_domain.member`: the member name under which a Domain declares the Node. */
24
+ export const MEMBER = PropertyKey.of(OF_DOMAIN_CLASS, 'member');
25
+ /** `Domain.origin`. */
26
+ export const ORIGIN = PropertyKey.of(DOMAIN_CLASS, 'origin');
27
+ /** `Descriptable.description`. */
28
+ export const DESCRIPTION = PropertyKey.of(kernelClass('Descriptable'), 'description');
29
+ /** `Identity.iss`. */
30
+ export const ISSUER = PropertyKey.of(kernelClass('Identity'), 'iss');
@@ -1,15 +1,10 @@
1
1
  import { equal } from '@astrale-os/kernel-core/graph/properties';
2
2
  import { Query } from '@astrale-os/kernel-core/graph/query';
3
3
  import { Path } from '@astrale-os/kernel-core/path';
4
- import { K } from '@astrale-os/kernel-core/schema';
5
4
  import { patterns } from '@astrale-os/kernel-dsl/v1/addressing';
6
5
  import { ClientError } from '../../errors/index.js';
6
+ import { DOMAIN, MEMBER, OF_DOMAIN, OF_DOMAIN_CLASS, ORIGIN, PLACEMENT, VIEW_CLASS, } from './kernel.js';
7
7
  import { declaredView } from './view.js';
8
- const OF_DOMAIN = K.classes.of_domain.key;
9
- const MEMBER = K.classes.of_domain.properties.member.key;
10
- const DOMAIN = K.classes.Domain.key;
11
- const ORIGIN = K.classes.Domain.properties.origin.key;
12
- const PLACEMENT = K.classes.View.properties.placement.key;
13
8
  /** Reads of one answer before giving up, the bound View.resolve put on its Registry reads. */
14
9
  const ATTEMPTS = 3;
15
10
  /** Selected Edges per page: one of_domain Edge per View the Domain declares. */
@@ -127,15 +122,15 @@ async function readAnswer(reader, ast, operation) {
127
122
  /** The of_domain Edge from the View a Path reaches to the Domain that declares it, if any. */
128
123
  function declarationQuery(target) {
129
124
  const declared = Query.from({ nodes: [target] })
130
- .filter({ class: K.classes.View.ref })
131
- .expand({ via: [K.classes.of_domain.ref], direction: 'outgoing' });
125
+ .filter({ class: VIEW_CLASS })
126
+ .expand({ via: [OF_DOMAIN_CLASS], direction: 'outgoing' });
132
127
  return declared.select({ kind: 'graph', binding: declared.edge });
133
128
  }
134
129
  /** The of_domain Edges that reach a Domain from its Views, with both endpoints. */
135
130
  function domainViewsQuery(origin) {
136
131
  const views = Query.from({ nodes: [Path.domain(origin)] })
137
- .expand({ via: [K.classes.of_domain.ref], direction: 'incoming' })
138
- .filter({ class: K.classes.View.ref });
132
+ .expand({ via: [OF_DOMAIN_CLASS], direction: 'incoming' })
133
+ .filter({ class: VIEW_CLASS });
139
134
  return views.select({ kind: 'graph', binding: views.edge });
140
135
  }
141
136
  /** The origin of a Domain, named by itself or by its exact Domain Path. */