maka-agent 0.2.0-dev.14.20260902 → 0.2.0-dev.16.20260903
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.
- package/dist/cli-core.js +0 -1
- package/dist/pi-transcript.js +48 -0
- package/dist/pi-tui-form-interaction.js +497 -0
- package/dist/pi-tui-pickers.js +256 -55
- package/dist/pi-tui-runner.js +215 -12
- package/dist/runtime-host-cli.js +17 -42
- package/dist/runtime-host-lifecycle-transaction.js +31 -13
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -1
- package/dist/runtime-host-onboarding.js +3 -1
- package/dist/runtime-host-openrc-service.js +469 -0
- package/dist/runtime-host-run-command.js +6 -2
- package/dist/runtime-host-service-command.js +3 -3
- package/dist/runtime-host-service-management-command.js +43 -15
- package/dist/runtime-host-session-channel.js +3 -0
- package/dist/runtime-host-session-driver.js +21 -6
- package/dist/runtime-host-setup-command.js +30 -31
- package/dist/tui-context-refresh.js +103 -0
- package/dist/tui-copy-catalog.js +73 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/node_modules/@maka/core/dist/chat-model-choice.js +4 -0
- package/node_modules/@maka/core/dist/computer-use.js +27 -92
- package/node_modules/@maka/core/dist/interaction.js +577 -3
- package/node_modules/@maka/core/dist/llm-connections.js +4 -0
- package/node_modules/@maka/core/dist/local-memory.js +2 -2
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +3 -0
- package/node_modules/@maka/core/dist/model-metadata.js +26 -7
- package/node_modules/@maka/core/dist/model-thinking.js +17 -0
- package/node_modules/@maka/core/dist/provider-registry.js +1 -0
- package/node_modules/@maka/core/dist/runtime-event.js +23 -1
- package/node_modules/@maka/core/dist/scheduled-task.js +4 -0
- package/node_modules/@maka/core/dist/session.js +95 -2
- package/node_modules/@maka/core/dist/text-sanitize.js +19 -0
- package/node_modules/@maka/core/dist/usage-ledger-merge.js +3 -0
- package/node_modules/@maka/core/dist/usage-record-schema.js +11 -5
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +75 -9
- package/node_modules/@maka/core/dist/workhub-session-resolver.js +50 -0
- package/node_modules/@maka/core/package.json +2 -0
- package/node_modules/@maka/eval/dist/harbor-external-subject.js +2 -1
- package/node_modules/@maka/eval/dist/harness-executor.js +3 -2
- package/node_modules/@maka/eval/dist/install-preflight.js +39 -10
- package/node_modules/@maka/eval/dist/process-termination.js +83 -0
- package/node_modules/@maka/mcp/dist/sep-2243.js +3 -3
- package/node_modules/@maka/runtime/dist/agent-run.js +6 -3
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +332 -118
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction-contract.js +6 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +171 -341
- package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +3 -26
- package/node_modules/@maka/runtime/dist/bundled-skill-catalog.generated.js +1 -1
- package/node_modules/@maka/runtime/dist/computer-use-codec.js +1 -141
- package/node_modules/@maka/runtime/dist/computer-use-tools.js +23 -105
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +20 -26
- package/node_modules/@maka/runtime/dist/context-budget.js +18 -20
- package/node_modules/@maka/runtime/dist/conversation-copy.js +23 -19
- package/node_modules/@maka/runtime/dist/cua-frame-state.js +1 -69
- package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +267 -0
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +6 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +67 -23
- package/node_modules/@maka/runtime/dist/history-compact-summary-validation.js +11 -18
- package/node_modules/@maka/runtime/dist/history-compaction.js +66 -73
- package/node_modules/@maka/runtime/dist/interaction-authority.js +69 -0
- package/node_modules/@maka/runtime/dist/mcp-tools.js +13 -1
- package/node_modules/@maka/runtime/dist/memory-extraction.js +11 -11
- package/node_modules/@maka/runtime/dist/model-adapter.js +24 -6
- package/node_modules/@maka/runtime/dist/model-factory.js +14 -5
- package/node_modules/@maka/runtime/dist/oauth-provider-contracts.js +28 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +7 -6
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +29 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +11 -1
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +12 -11
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +51 -13
- package/node_modules/@maka/runtime/dist/scheduled-task-tools.js +3 -0
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +26 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +1 -0
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +16 -1
- package/node_modules/@maka/runtime/dist/stream-graph-projection.js +6 -0
- package/node_modules/@maka/runtime/dist/stream-graph-read-model.js +5 -0
- package/node_modules/@maka/runtime/dist/stream-usage-fallback-fetch.js +74 -0
- package/node_modules/@maka/runtime/dist/subscription-credentials.js +51 -4
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +47 -3
- package/node_modules/@maka/runtime/dist/system-prompt/main-session-prompt.js +20 -1
- package/node_modules/@maka/runtime/dist/test-connection.js +18 -11
- package/node_modules/@maka/runtime/dist/tool-runtime.js +183 -0
- package/node_modules/@maka/runtime/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +14 -0
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +84 -1
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +68 -51
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +8 -5
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +342 -36
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +60 -4
- package/node_modules/@maka/runtime-host/dist/peer-mesh/index.js +3 -3
- package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +48 -60
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +847 -431
- package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +33 -74
- package/node_modules/@maka/runtime-host/dist/peer-mesh/store.js +82 -69
- package/node_modules/@maka/runtime-host/dist/peer-reachability/index.js +21 -0
- package/node_modules/@maka/runtime-host/dist/peer-reachability/model.js +202 -0
- package/node_modules/@maka/runtime-host/dist/peer-reachability/owner.js +119 -0
- package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +245 -0
- package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +68 -0
- package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +15 -8
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +7 -23
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +47 -1
- package/node_modules/@maka/runtime-host/dist/protocol/oauth.js +25 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/peer-mesh.js +14 -31
- package/node_modules/@maka/runtime-host/dist/protocol/scheduled-task.js +19 -6
- package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +36 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-revision.js +11 -2
- package/node_modules/@maka/runtime-host/dist/protocol/usage-pricing.js +16 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +51 -2
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +35 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +12 -10
- package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +163 -30
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +38 -14
- package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +45 -22
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +78 -20
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-service.js +49 -28
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +3 -6
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +130 -27
- package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +30 -1
- package/node_modules/@maka/runtime-host/dist/server/listener-set.js +2 -4
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +16 -3
- package/node_modules/@maka/runtime-host/dist/server/oauth-coordinator.js +66 -3
- package/node_modules/@maka/runtime-host/dist/server/oauth-execution-authority.js +20 -3
- package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +8 -21
- package/node_modules/@maka/runtime-host/dist/server/peer-mesh-authority.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +6 -3
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +72 -12
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +48 -18
- package/node_modules/@maka/runtime-host/dist/server/session-turn-access-request-coordinator.js +43 -26
- package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +15 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +229 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +146 -8
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +32 -6
- package/node_modules/@maka/runtime-host/package.json +1 -0
- package/node_modules/@maka/storage/dist/agent-run-store.js +18 -5
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +14 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +5 -0
- package/node_modules/@maka/storage/dist/interaction-store.js +13 -1
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +9 -3
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +49 -19
- package/node_modules/@maka/storage/dist/runtime-policy/oauth-login-receipt-document.js +3 -1
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +13 -5
- package/node_modules/@maka/storage/dist/session-copy-cleanup.js +4 -2
- package/node_modules/@maka/storage/dist/session-store.js +39 -6
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +16 -9
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +30 -3
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +117 -0
- package/node_modules/@maka/storage/dist/sqlite-usage-store.js +29 -6
- package/node_modules/@maka/storage/dist/usage-stores.js +3 -1
- package/package.json +1 -1
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
|
-
import { CLIENT_CAPABILITY_MAX_RESULT_BYTES, CLIENT_CAPABILITY_RESULT_CHUNK_MAX_BYTES, decodeClientCapabilityReplaceInput, decodeClientCapabilityResult, } from '../protocol/index.js';
|
|
20
|
+
import { CLIENT_CAPABILITY_MAX_RESULT_BYTES, CLIENT_CAPABILITY_RESULT_CHUNK_MAX_BYTES, decodeClientCapabilityClientFrame, decodeClientCapabilityReplaceInput, decodeClientCapabilityResult, } from '../protocol/index.js';
|
|
21
21
|
/** Client-owned registration, reverse invocation, and teardown lifecycle. */
|
|
22
22
|
export class ClientCapabilityChannel {
|
|
23
23
|
#options;
|
|
@@ -110,6 +110,7 @@ export class ClientCapabilityChannel {
|
|
|
110
110
|
invocation.released = true;
|
|
111
111
|
invocation.controller.abort(new DOMException('Client Capability invocation was cancelled', 'AbortError'));
|
|
112
112
|
invocation.admission?.reject(capabilityInvocationAbortReason(invocation));
|
|
113
|
+
invocation.interaction?.reject(capabilityInvocationAbortReason(invocation));
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
115
116
|
case 'client.capability.release': {
|
|
@@ -119,6 +120,7 @@ export class ClientCapabilityChannel {
|
|
|
119
120
|
invocation.released = true;
|
|
120
121
|
invocation.controller.abort(new DOMException('Client Capability invocation was released', 'AbortError'));
|
|
121
122
|
invocation.admission?.reject(capabilityInvocationAbortReason(invocation));
|
|
123
|
+
invocation.interaction?.reject(capabilityInvocationAbortReason(invocation));
|
|
122
124
|
this.#invocations.delete(frame.invocationId);
|
|
123
125
|
return;
|
|
124
126
|
}
|
|
@@ -133,6 +135,16 @@ export class ClientCapabilityChannel {
|
|
|
133
135
|
}
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
138
|
+
case 'client.capability.interaction_result': {
|
|
139
|
+
const invocation = this.#invocations.get(frame.invocationId);
|
|
140
|
+
const interaction = invocation?.interaction;
|
|
141
|
+
if (!interaction ||
|
|
142
|
+
interaction.interactionId !== frame.interactionId ||
|
|
143
|
+
!interaction.resolve(frame.result)) {
|
|
144
|
+
throw new Error('Runtime Host returned an unmatched capability interaction result');
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
150
|
close(error) {
|
|
@@ -143,6 +155,7 @@ export class ClientCapabilityChannel {
|
|
|
143
155
|
invocation.released = true;
|
|
144
156
|
invocation.controller.abort(error);
|
|
145
157
|
invocation.admission?.reject(error);
|
|
158
|
+
invocation.interaction?.reject(error);
|
|
146
159
|
}
|
|
147
160
|
this.#invocations.clear();
|
|
148
161
|
const providers = new Set([...this.#registrations.values()].map((registration) => registration.provider));
|
|
@@ -254,13 +267,53 @@ export class ClientCapabilityChannel {
|
|
|
254
267
|
})
|
|
255
268
|
.catch((error) => this.#options.onFailure(asError(error)));
|
|
256
269
|
};
|
|
270
|
+
const requestInteraction = async (request) => {
|
|
271
|
+
if (!accepted) {
|
|
272
|
+
throw new Error('Client Capability interaction requires an admitted invocation');
|
|
273
|
+
}
|
|
274
|
+
if (invocation.released)
|
|
275
|
+
throw capabilityInvocationAbortReason(invocation);
|
|
276
|
+
if (invocation.interaction) {
|
|
277
|
+
throw new Error('Client Capability invocation already has a pending interaction');
|
|
278
|
+
}
|
|
279
|
+
const interactionId = randomUUID();
|
|
280
|
+
const frame = decodeClientCapabilityClientFrame({
|
|
281
|
+
kind: 'client.capability.interaction_request',
|
|
282
|
+
invocationId,
|
|
283
|
+
interactionId,
|
|
284
|
+
request,
|
|
285
|
+
});
|
|
286
|
+
if (frame.kind !== 'client.capability.interaction_request') {
|
|
287
|
+
throw new Error('Client Capability interaction request was not canonical');
|
|
288
|
+
}
|
|
289
|
+
const interaction = createClientCapabilityPendingInteraction(interactionId);
|
|
290
|
+
invocation.interaction = interaction;
|
|
291
|
+
try {
|
|
292
|
+
try {
|
|
293
|
+
await this.#options.write(frame);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
interaction.reject(error);
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
return await interaction.promise;
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
if (invocation.interaction === interaction)
|
|
303
|
+
invocation.interaction = undefined;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
257
306
|
const result = decodeClientCapabilityResult(await execute({
|
|
258
307
|
signal: invocation.controller.signal,
|
|
259
308
|
accept,
|
|
260
309
|
progress,
|
|
310
|
+
requestInteraction,
|
|
261
311
|
}));
|
|
262
312
|
if (invocation.released)
|
|
263
313
|
return;
|
|
314
|
+
if (invocation.interaction) {
|
|
315
|
+
throw new Error('Client Capability provider returned with a pending interaction');
|
|
316
|
+
}
|
|
264
317
|
await accept({ kind: 'none' });
|
|
265
318
|
await this.#sendResult(invocationId, result, invocation);
|
|
266
319
|
}
|
|
@@ -366,6 +419,36 @@ function createClientCapabilityAdmission() {
|
|
|
366
419
|
},
|
|
367
420
|
};
|
|
368
421
|
}
|
|
422
|
+
function createClientCapabilityPendingInteraction(interactionId) {
|
|
423
|
+
let state = 'pending';
|
|
424
|
+
let resolvePromise;
|
|
425
|
+
let rejectPromise;
|
|
426
|
+
const promise = new Promise((resolve, reject) => {
|
|
427
|
+
resolvePromise = resolve;
|
|
428
|
+
rejectPromise = reject;
|
|
429
|
+
});
|
|
430
|
+
// A buggy provider may start but not await the callback. The invocation still
|
|
431
|
+
// fails closed, while channel teardown must not create an unhandled rejection.
|
|
432
|
+
void promise.catch(() => undefined);
|
|
433
|
+
return {
|
|
434
|
+
interactionId,
|
|
435
|
+
promise,
|
|
436
|
+
resolve: (result) => {
|
|
437
|
+
if (state !== 'pending')
|
|
438
|
+
return false;
|
|
439
|
+
state = 'resolved';
|
|
440
|
+
resolvePromise(result);
|
|
441
|
+
return true;
|
|
442
|
+
},
|
|
443
|
+
reject: (error) => {
|
|
444
|
+
if (state !== 'pending')
|
|
445
|
+
return false;
|
|
446
|
+
state = 'rejected';
|
|
447
|
+
rejectPromise(error);
|
|
448
|
+
return true;
|
|
449
|
+
},
|
|
450
|
+
};
|
|
451
|
+
}
|
|
369
452
|
function capabilityInvocationAbortReason(invocation) {
|
|
370
453
|
return (invocation.controller.signal.reason ??
|
|
371
454
|
new DOMException('Client Capability invocation was released', 'AbortError'));
|
|
@@ -26,21 +26,19 @@ import { INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID, isCanonicalRuntimeHostWebSocke
|
|
|
26
26
|
import { connectRemoteRuntimeHost, connectRuntimeHostMessageTransport, normalizeRemoteRuntimeHostUrl, } from './connection.js';
|
|
27
27
|
import { FramedByteStreamTransport } from '../transport/framed-byte-stream-transport.js';
|
|
28
28
|
import { RuntimeHostPeerByteStream, RuntimeHostPeerError, readRuntimeHostPeerAuthenticationResult, writeRuntimeHostPeerAuthentication, } from '../transport/peer-native.js';
|
|
29
|
+
import { decodeSignedPeerReachabilityLease, isPeerReachabilityLeaseRecoverable, } from '../peer-reachability/model.js';
|
|
29
30
|
import { RuntimeHostPermanentReconnectError } from './reconnect-lifecycle.js';
|
|
30
31
|
import { RuntimeHostRemoteCompatibilityError } from './remote-compatibility-error.js';
|
|
31
32
|
import { normalizeRuntimeHostSshDestination, openRuntimeHostSshTunnel, } from './ssh-tunnel.js';
|
|
32
33
|
import { activateRuntimeHostSshOperator } from './ssh-operator-activation.js';
|
|
33
34
|
import { waitForRuntimeHostReady } from './wait-for-ready.js';
|
|
34
35
|
import { connectRuntimeHostWslEnvironment, normalizeRuntimeHostWslDistribution, normalizeRuntimeHostWslOperatorPath, } from './wsl-environment.js';
|
|
35
|
-
const PROFILE_SCHEMA_VERSION =
|
|
36
|
+
const PROFILE_SCHEMA_VERSION = 4;
|
|
36
37
|
const CLIENT_PROFILE_DOCUMENT_NAME = 'runtime-host-profiles.json';
|
|
37
38
|
const PROFILE_DOCUMENT_MAX_BYTES = 64 * 1024;
|
|
38
39
|
const PROFILE_COUNT_MAX = 32;
|
|
39
40
|
const PROFILE_NAME_MAX_BYTES = 128;
|
|
40
41
|
const PROFILE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
41
|
-
const PEER_ID_MAX_BYTES = 160;
|
|
42
|
-
const PEER_ADDRESS_MAX_BYTES = 2 * 1024;
|
|
43
|
-
const PEER_ROUTE_MAX = 16;
|
|
44
42
|
const DEFAULT_PEER_HANDSHAKE_TIMEOUT_MS = 5_000;
|
|
45
43
|
const PROFILE_CREDENTIAL_RECORD_PREFIX = 'maka-runtime-host-profile-credential-v1:';
|
|
46
44
|
const PROFILE_INCARNATION_ID_MAX_BYTES = 128;
|
|
@@ -72,8 +70,8 @@ export function sameRemoteRuntimeHostProfileTarget(left, right) {
|
|
|
72
70
|
}
|
|
73
71
|
export class RuntimeHostProfileConnectionError extends RuntimeHostPermanentReconnectError {
|
|
74
72
|
reason;
|
|
75
|
-
constructor(reason, message) {
|
|
76
|
-
super(message);
|
|
73
|
+
constructor(reason, message, options) {
|
|
74
|
+
super(message, options);
|
|
77
75
|
this.reason = reason;
|
|
78
76
|
this.name = 'RuntimeHostProfileConnectionError';
|
|
79
77
|
}
|
|
@@ -279,13 +277,42 @@ function requireConnectOnlySshEndpoint(transport) {
|
|
|
279
277
|
export async function connectPeerRuntimeHost(input) {
|
|
280
278
|
input.signal?.throwIfAborted();
|
|
281
279
|
const handshakeTimeoutMs = input.handshakeTimeoutMs ?? DEFAULT_PEER_HANDSHAKE_TIMEOUT_MS;
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
280
|
+
const peerId = input.transport.reachability.lease.peerId;
|
|
281
|
+
let reachability;
|
|
282
|
+
try {
|
|
283
|
+
reachability = input.peerClient.observeAuthenticatedReachability({
|
|
284
|
+
expectedPeerId: peerId,
|
|
285
|
+
value: input.transport.reachability,
|
|
286
|
+
allowHistorical: true,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
catch (cause) {
|
|
290
|
+
throw new RuntimeHostProfileConnectionError('target_mismatch', `Runtime Host profile ${input.profileId} contains invalid peer reachability evidence`, { cause });
|
|
291
|
+
}
|
|
292
|
+
const bootstrap = isPeerReachabilityLeaseRecoverable(reachability.lease, Date.now())
|
|
293
|
+
? reachability.lease
|
|
294
|
+
: undefined;
|
|
295
|
+
let stream;
|
|
296
|
+
try {
|
|
297
|
+
stream = await input.peerClient.connect({
|
|
298
|
+
peerId,
|
|
299
|
+
routeHints: bootstrap?.directRoutes ?? [],
|
|
300
|
+
coordinationRelays: bootstrap?.coordinationRoutes ?? [],
|
|
301
|
+
directDeadlineMs: Math.min(input.connectTimeoutMs ?? 40_000, 120_000),
|
|
302
|
+
...(input.refreshPeerRoutes === undefined
|
|
303
|
+
? {}
|
|
304
|
+
: { refreshRoutes: input.refreshPeerRoutes }),
|
|
305
|
+
}, input.signal, input.onConnectionPhase);
|
|
306
|
+
}
|
|
307
|
+
catch (cause) {
|
|
308
|
+
if (cause instanceof RuntimeHostPeerError && cause.code === 'peer_identity_mismatch') {
|
|
309
|
+
throw new RuntimeHostProfileConnectionError('target_mismatch', `Runtime Host profile ${input.profileId} resolved to a different peer identity`, { cause });
|
|
310
|
+
}
|
|
311
|
+
if (cause instanceof RuntimeHostPeerError && cause.code === 'peer_native_unavailable') {
|
|
312
|
+
throw runtimeHostPeerUnavailableError(cause);
|
|
313
|
+
}
|
|
314
|
+
throw cause;
|
|
315
|
+
}
|
|
289
316
|
const abort = () => stream.abort();
|
|
290
317
|
input.signal?.addEventListener('abort', abort, { once: true });
|
|
291
318
|
if (input.signal?.aborted)
|
|
@@ -312,8 +339,11 @@ export async function connectPeerRuntimeHost(input) {
|
|
|
312
339
|
handshakeTimeoutMs,
|
|
313
340
|
onHostStatus: (status) => {
|
|
314
341
|
const endpoint = status.peerEndpoint;
|
|
315
|
-
if (endpoint
|
|
316
|
-
input.peerClient.
|
|
342
|
+
if (endpoint) {
|
|
343
|
+
input.peerClient.observeAuthenticatedReachability({
|
|
344
|
+
value: endpoint,
|
|
345
|
+
expectedPeerId: peerId,
|
|
346
|
+
});
|
|
317
347
|
}
|
|
318
348
|
input.onHostStatus?.(status);
|
|
319
349
|
},
|
|
@@ -353,7 +383,10 @@ function notifyConnectionPhase(observer, phase) {
|
|
|
353
383
|
function requireRuntimeHostPeerClient(peerClient) {
|
|
354
384
|
if (peerClient)
|
|
355
385
|
return peerClient;
|
|
356
|
-
throw new RuntimeHostPeerError('peer_native_unavailable', 'Experimental direct peer requires a Client peer endpoint owner');
|
|
386
|
+
throw runtimeHostPeerUnavailableError(new RuntimeHostPeerError('peer_native_unavailable', 'Experimental direct peer requires a Client peer endpoint owner'));
|
|
387
|
+
}
|
|
388
|
+
function runtimeHostPeerUnavailableError(cause) {
|
|
389
|
+
return new RuntimeHostPermanentReconnectError('Runtime Host peer networking is unavailable in this Maka build', { cause });
|
|
357
390
|
}
|
|
358
391
|
export function remoteRuntimeHostUnavailableError(subject, reason) {
|
|
359
392
|
let message;
|
|
@@ -385,6 +418,7 @@ export function decodeRuntimeHostProfileDocument(value) {
|
|
|
385
418
|
]);
|
|
386
419
|
if (record.schemaVersion !== 1 &&
|
|
387
420
|
record.schemaVersion !== 2 &&
|
|
421
|
+
record.schemaVersion !== 3 &&
|
|
388
422
|
record.schemaVersion !== PROFILE_SCHEMA_VERSION) {
|
|
389
423
|
throw new Error('Runtime Host profile document has an unsupported schema');
|
|
390
424
|
}
|
|
@@ -397,10 +431,14 @@ export function decodeRuntimeHostProfileDocument(value) {
|
|
|
397
431
|
(profile.transport.kind === 'ssh' && profile.transport.activation !== undefined))) {
|
|
398
432
|
throw new Error('Runtime Host profile schema 1 cannot contain activation');
|
|
399
433
|
}
|
|
400
|
-
if (record.schemaVersion
|
|
434
|
+
if (record.schemaVersion < 3 &&
|
|
401
435
|
profiles.some((profile) => profile.kind === 'remote' && profile.access === 'session_guest')) {
|
|
402
436
|
throw new Error('Runtime Host profile schema 3 is required for restricted access');
|
|
403
437
|
}
|
|
438
|
+
if (record.schemaVersion < 4 &&
|
|
439
|
+
profiles.some((profile) => profile.kind === 'remote' && profile.transport.kind === 'libp2p-direct')) {
|
|
440
|
+
throw new Error('Runtime Host profile schema 4 is required for Direct peer reachability');
|
|
441
|
+
}
|
|
404
442
|
const ids = new Set();
|
|
405
443
|
for (const profile of profiles) {
|
|
406
444
|
if (ids.has(profile.id))
|
|
@@ -820,21 +858,16 @@ export function decodeRuntimeHostRemoteTransport(value) {
|
|
|
820
858
|
if (kind === 'libp2p-direct') {
|
|
821
859
|
const record = requireExactRecord(value, 'Runtime Host direct peer transport', [
|
|
822
860
|
'kind',
|
|
823
|
-
'
|
|
824
|
-
'routeHints',
|
|
825
|
-
'coordinationRelays',
|
|
861
|
+
'reachability',
|
|
826
862
|
]);
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
if (routeHints.length === 0 && coordinationRelays.length === 0) {
|
|
863
|
+
const reachability = decodeSignedPeerReachabilityLease(record.reachability);
|
|
864
|
+
if (reachability.lease.directRoutes.length === 0 &&
|
|
865
|
+
reachability.lease.coordinationRoutes.length === 0) {
|
|
831
866
|
throw new Error('Runtime Host direct peer transport requires at least one route');
|
|
832
867
|
}
|
|
833
868
|
return Object.freeze({
|
|
834
869
|
kind: 'libp2p-direct',
|
|
835
|
-
|
|
836
|
-
routeHints,
|
|
837
|
-
coordinationRelays,
|
|
870
|
+
reachability,
|
|
838
871
|
});
|
|
839
872
|
}
|
|
840
873
|
throw new Error('Runtime Host transport kind is invalid');
|
|
@@ -976,26 +1009,8 @@ function transportCredentialBinding(transport) {
|
|
|
976
1009
|
? `${transport.destination}\0${transport.sshPort ?? ''}\0activate\0${transport.activation.operatorPath}`
|
|
977
1010
|
: `${transport.destination}\0${transport.sshPort ?? ''}\0${transport.remotePort}\0${transport.websocketPath}`;
|
|
978
1011
|
case 'libp2p-direct':
|
|
979
|
-
return transport.peerId;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
function requirePeerAddresses(value, label) {
|
|
983
|
-
if (!Array.isArray(value) || value.length > PEER_ROUTE_MAX) {
|
|
984
|
-
throw new Error(`${label} must be an array with at most ${PEER_ROUTE_MAX} entries`);
|
|
985
|
-
}
|
|
986
|
-
const addresses = value.map((entry) => {
|
|
987
|
-
const address = requireString(entry, label);
|
|
988
|
-
if (!address.startsWith('/') ||
|
|
989
|
-
Buffer.byteLength(address, 'utf8') > PEER_ADDRESS_MAX_BYTES ||
|
|
990
|
-
/[\s\u0000-\u001f\u007f]/u.test(address)) {
|
|
991
|
-
throw new Error(`${label} contains an invalid multiaddr`);
|
|
992
|
-
}
|
|
993
|
-
return address;
|
|
994
|
-
});
|
|
995
|
-
if (new Set(addresses).size !== addresses.length) {
|
|
996
|
-
throw new Error(`${label} contains duplicates`);
|
|
1012
|
+
return transport.reachability.lease.peerId;
|
|
997
1013
|
}
|
|
998
|
-
return Object.freeze(addresses);
|
|
999
1014
|
}
|
|
1000
1015
|
function requireBoundedToken(value, label, maxBytes) {
|
|
1001
1016
|
const token = requireString(value, label);
|
|
@@ -1092,12 +1107,14 @@ function emptyProfileDocument() {
|
|
|
1092
1107
|
return Object.freeze({ schemaVersion: PROFILE_SCHEMA_VERSION, profiles: Object.freeze([]) });
|
|
1093
1108
|
}
|
|
1094
1109
|
async function writeProfileDocument(path, document) {
|
|
1095
|
-
const schemaVersion = document.profiles.some((profile) => profile.kind === 'remote' && profile.
|
|
1110
|
+
const schemaVersion = document.profiles.some((profile) => profile.kind === 'remote' && profile.transport.kind === 'libp2p-direct')
|
|
1096
1111
|
? PROFILE_SCHEMA_VERSION
|
|
1097
|
-
: document.profiles.some((profile) => profile.kind === '
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1112
|
+
: document.profiles.some((profile) => profile.kind === 'remote' && profile.access === 'session_guest')
|
|
1113
|
+
? 3
|
|
1114
|
+
: document.profiles.some((profile) => profile.kind === 'environment' ||
|
|
1115
|
+
(profile.transport.kind === 'ssh' && profile.transport.activation !== undefined))
|
|
1116
|
+
? 2
|
|
1117
|
+
: 1;
|
|
1101
1118
|
const encoded = `${JSON.stringify({ ...document, schemaVersion }, null, 2)}\n`;
|
|
1102
1119
|
if (Buffer.byteLength(encoded, 'utf8') > PROFILE_DOCUMENT_MAX_BYTES) {
|
|
1103
1120
|
throw new Error('Runtime Host profile document exceeds its size limit');
|
|
@@ -42,5 +42,5 @@ export { projectSessionCatalogSummary } from './session-catalog-summary.js';
|
|
|
42
42
|
export { consumeAccessCredentialDelivery } from '../control/access-credential-delivery.js';
|
|
43
43
|
export { decodeRuntimeHostOwnerConnectionCode, encodeRuntimeHostOwnerConnectionCode, issueRuntimeHostOwnerConnectionCode, REMOTE_DESKTOP_OWNER_ACCESS_POLICY, } from './owner-connection-code.js';
|
|
44
44
|
export { ensureRuntimeHostPeerIdentity } from '../transport/peer-native.js';
|
|
45
|
-
export { createRuntimeHostPeerClient, createRuntimeHostPeerClientFromEnvironment, } from './peer-client.js';
|
|
45
|
+
export { createRuntimeHostPeerClient, createRuntimeHostPeerClientFromEnvironment, RuntimeHostPeerReachabilityUnavailableError, } from './peer-client.js';
|
|
46
46
|
export { createOAuthPresentationClientProvider, } from './oauth-presentation.js';
|
|
@@ -20,7 +20,7 @@ import { z } from 'zod';
|
|
|
20
20
|
import { consumeAccessCredentialDelivery } from '../control/access-credential-delivery.js';
|
|
21
21
|
import { REMOTE_OWNER_OPERATION_GRANTS, requireHostRootId } from '../protocol/index.js';
|
|
22
22
|
import { decodeRuntimeHostRemoteTransport, RUNTIME_HOST_ACCESS_CREDENTIAL_MAX_BYTES, } from './host-profile.js';
|
|
23
|
-
const PREFIX = 'maka-runtime-host:connect:
|
|
23
|
+
const PREFIX = 'maka-runtime-host:connect:v2:';
|
|
24
24
|
const ENCODED_MAX_BYTES = 48 * 1024;
|
|
25
25
|
export const REMOTE_DESKTOP_OWNER_ACCESS_POLICY = Object.freeze({
|
|
26
26
|
principalKind: 'remote_owner',
|
|
@@ -35,7 +35,7 @@ const boundedString = (maxBytes) => z
|
|
|
35
35
|
const nameSchema = boundedString(128);
|
|
36
36
|
const payloadSchema = z
|
|
37
37
|
.object({
|
|
38
|
-
schemaVersion: z.literal(
|
|
38
|
+
schemaVersion: z.literal(2),
|
|
39
39
|
name: boundedString(128),
|
|
40
40
|
rootId: z.string().refine((value) => {
|
|
41
41
|
try {
|
|
@@ -61,10 +61,13 @@ export async function issueRuntimeHostOwnerConnectionCode(input) {
|
|
|
61
61
|
const endpoint = (await input.client.status()).peerEndpoint;
|
|
62
62
|
if (!endpoint)
|
|
63
63
|
throw new Error('Runtime Host Direct peer is not available');
|
|
64
|
-
if (input.expectedPeerId && endpoint.peerId !== input.expectedPeerId) {
|
|
64
|
+
if (input.expectedPeerId && endpoint.lease.peerId !== input.expectedPeerId) {
|
|
65
65
|
throw new Error('Runtime Host Direct peer identity changed');
|
|
66
66
|
}
|
|
67
|
-
const transport = requireDirectPeerTransport({
|
|
67
|
+
const transport = requireDirectPeerTransport({
|
|
68
|
+
kind: 'libp2p-direct',
|
|
69
|
+
reachability: endpoint,
|
|
70
|
+
});
|
|
68
71
|
const prepared = await input.client.request('access.credential.prepare', {
|
|
69
72
|
...REMOTE_DESKTOP_OWNER_ACCESS_POLICY,
|
|
70
73
|
principalId: input.principalId,
|
|
@@ -75,7 +78,7 @@ export async function issueRuntimeHostOwnerConnectionCode(input) {
|
|
|
75
78
|
}
|
|
76
79
|
export function encodeRuntimeHostOwnerConnectionCode(input) {
|
|
77
80
|
const transport = requireDirectPeerTransport(input.transport);
|
|
78
|
-
const payload = payloadSchema.parse({ schemaVersion:
|
|
81
|
+
const payload = payloadSchema.parse({ schemaVersion: 2, ...input, transport });
|
|
79
82
|
const encoded = Buffer.from(JSON.stringify(payload), 'utf8').toString('base64url');
|
|
80
83
|
if (Buffer.byteLength(encoded, 'utf8') > ENCODED_MAX_BYTES) {
|
|
81
84
|
throw new RangeError('Runtime Host connection code is too large');
|