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
|
@@ -25,7 +25,7 @@ import { emptyPlanSessionState } from '@maka/core/plan';
|
|
|
25
25
|
import { isDeepResearchSession, WORKHUB_COORDINATION_SESSION_ID, WORKHUB_COORDINATION_REPLACEMENT_SCHEMA_VERSION, } from '@maka/core/session';
|
|
26
26
|
import { AgentGraphCoordinator } from '@maka/runtime/stream-graph-coordinator';
|
|
27
27
|
import { AgentGraphSupervisorWakeCoordinator } from '@maka/runtime/agent-graph-supervisor-wake';
|
|
28
|
-
import { BackendRegistry, SessionManager, } from '@maka/runtime/session-manager';
|
|
28
|
+
import { BackendRegistry, SessionManager, workHubDirectStopAbortSource, } from '@maka/runtime/session-manager';
|
|
29
29
|
import { buildToolsForAgentDefinition } from '@maka/runtime/agent-catalog';
|
|
30
30
|
import { buildHistoryTools } from '@maka/runtime/history-tools';
|
|
31
31
|
import { createLocalContinuationSafetyInspector } from '@maka/runtime/continuation-safety';
|
|
@@ -41,6 +41,7 @@ import { renderAgentSwarmSupervisorWake, shouldWakeAgentSwarmSupervisor, } from
|
|
|
41
41
|
import { SessionActivityRegistry } from '@maka/runtime/goal-turn-lifecycle';
|
|
42
42
|
import { ShellRunProcessManager } from '@maka/runtime/shell-run-manager';
|
|
43
43
|
import { resolveShellPlan, resolveTurnShellPlan, validateShellPreference, } from '@maka/runtime/shell-detect';
|
|
44
|
+
import { isHostedExecutionTerminal } from './hosted-execution-authority.js';
|
|
44
45
|
import { createAgentGraphControlStore } from '@maka/storage/agent-graph-control-store';
|
|
45
46
|
import { createArtifactAttachmentResourceReader } from '@maka/storage/artifact-stores';
|
|
46
47
|
import { createReadImageSnapshotStore } from '@maka/storage/read-image-snapshot-store';
|
|
@@ -938,6 +939,7 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
938
939
|
? new SessionTurnAccessRequestCoordinator({
|
|
939
940
|
authority: context.sessionAccessAuthority,
|
|
940
941
|
startTurn: interactiveTurns.handlers['turn.start'],
|
|
942
|
+
regenerateTurn: interactiveTurns.handlers['turn.regenerate'],
|
|
941
943
|
hostEpoch: context.hostEpoch,
|
|
942
944
|
acquireResidency: () => context.acquireResidency('collaboration-turn-request'),
|
|
943
945
|
requestDrain: context.requestDrain,
|
|
@@ -1046,33 +1048,44 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1046
1048
|
if (disposition.kind === 'cancelled' || disposition.kind === 'shared_turn') {
|
|
1047
1049
|
return 'retired';
|
|
1048
1050
|
}
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1051
|
+
const identity = {
|
|
1052
|
+
sessionId: assignment.targetSessionId,
|
|
1053
|
+
turnId: disposition.turnId,
|
|
1054
|
+
runId: disposition.runId,
|
|
1055
|
+
};
|
|
1056
|
+
if (isActiveWorkHubRoot(coordinator, identity))
|
|
1057
|
+
return 'not_retired';
|
|
1058
|
+
// The same restart window as `stopOwnedWorkHubRoot`: an unregistered
|
|
1059
|
+
// root is not evidence that its work ended.
|
|
1060
|
+
const snapshot = await coordinator.read(identity);
|
|
1061
|
+
return isHostedExecutionTerminal(snapshot) ? 'retired' : 'recovering';
|
|
1055
1062
|
},
|
|
1056
|
-
retireDelegation: async (assignment) => {
|
|
1057
|
-
const disposition = await messages.cancelMessageIfPending(assignment.targetSessionId, assignment.targetMessageId);
|
|
1063
|
+
retireDelegation: async (assignment, retirement) => {
|
|
1064
|
+
const disposition = await messages.cancelMessageIfPending(assignment.targetSessionId, assignment.targetMessageId, retirement.cancellationClaimId);
|
|
1058
1065
|
if (disposition.kind === 'recovering') {
|
|
1059
|
-
|
|
1066
|
+
return { outcome: 'recovering' };
|
|
1067
|
+
}
|
|
1068
|
+
if (disposition.kind === 'cancelled') {
|
|
1069
|
+
return { outcome: 'already_terminal' };
|
|
1070
|
+
}
|
|
1071
|
+
if (disposition.kind === 'cancelled_pending') {
|
|
1072
|
+
return { outcome: 'cancelled_pending' };
|
|
1073
|
+
}
|
|
1074
|
+
if (disposition.kind === 'shared_turn') {
|
|
1075
|
+
return { outcome: 'not_owned', targetTurnId: disposition.turnId };
|
|
1060
1076
|
}
|
|
1061
|
-
if (disposition.kind === 'shared_turn')
|
|
1062
|
-
return;
|
|
1063
1077
|
if (disposition.kind === 'owned_root') {
|
|
1064
|
-
const
|
|
1065
|
-
if (rootState.kind !== 'active' ||
|
|
1066
|
-
rootState.turnId !== disposition.turnId ||
|
|
1067
|
-
rootState.runId !== disposition.runId) {
|
|
1068
|
-
return;
|
|
1069
|
-
}
|
|
1070
|
-
await coordinator.stopRoot({
|
|
1078
|
+
const identity = {
|
|
1071
1079
|
sessionId: assignment.targetSessionId,
|
|
1072
1080
|
turnId: disposition.turnId,
|
|
1073
1081
|
runId: disposition.runId,
|
|
1074
|
-
}
|
|
1082
|
+
};
|
|
1083
|
+
return retirement.cause === 'direct_stop'
|
|
1084
|
+
? stopOwnedWorkHubRoot(coordinator, identity, retirement.cancellationClaimId)
|
|
1085
|
+
: stopReplacedWorkHubRoot(coordinator, identity);
|
|
1075
1086
|
}
|
|
1087
|
+
disposition;
|
|
1088
|
+
throw new Error('Unhandled WorkHub Message retirement disposition');
|
|
1076
1089
|
},
|
|
1077
1090
|
assign: async (input) => {
|
|
1078
1091
|
const durable = await stores.sessionStore.readWorkHubAssignment(input.actionId);
|
|
@@ -1651,6 +1664,51 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
1651
1664
|
throw new AggregateError(errors, 'Unable to clean up Runtime Host execution composition');
|
|
1652
1665
|
}
|
|
1653
1666
|
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Confirmed direct stop. The action-derived abort source is written onto the
|
|
1669
|
+
* exact root Turn so a retry after a crash can tell WorkHub's own delivery
|
|
1670
|
+
* apart from an earlier or concurrent manual Stop.
|
|
1671
|
+
*/
|
|
1672
|
+
export async function stopOwnedWorkHubRoot(coordinator, identity, actionId) {
|
|
1673
|
+
if (isActiveWorkHubRoot(coordinator, identity)) {
|
|
1674
|
+
await coordinator.stopRoot(identity, {
|
|
1675
|
+
source: 'workhub_direct_stop',
|
|
1676
|
+
workHubActionId: actionId,
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
const terminal = await coordinator.read(identity);
|
|
1680
|
+
if (terminal.status === 'cancelled' &&
|
|
1681
|
+
terminal.abortSource === workHubDirectStopAbortSource(actionId)) {
|
|
1682
|
+
return { outcome: 'stop_delivered', targetTurnId: identity.turnId };
|
|
1683
|
+
}
|
|
1684
|
+
// Registration is in-memory, so between Host restart and execution recovery
|
|
1685
|
+
// this root looks inactive while it is still running. `already_terminal` is
|
|
1686
|
+
// committed as an immutable fact, so only a durably terminal snapshot may
|
|
1687
|
+
// claim it; anything else is still resolving.
|
|
1688
|
+
return isHostedExecutionTerminal(terminal)
|
|
1689
|
+
? { outcome: 'already_terminal', targetTurnId: identity.turnId }
|
|
1690
|
+
: { outcome: 'recovering', targetTurnId: identity.turnId };
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Route correction retiring the root it is replacing. It carries its own
|
|
1694
|
+
* cancellation claim, but it is not a direct stop: recording direct-stop
|
|
1695
|
+
* provenance here would let replay mistake a correction for one, so the
|
|
1696
|
+
* retirement keeps the neutral Stop source ordinary supersession has always
|
|
1697
|
+
* used.
|
|
1698
|
+
*/
|
|
1699
|
+
export async function stopReplacedWorkHubRoot(coordinator, identity) {
|
|
1700
|
+
if (!isActiveWorkHubRoot(coordinator, identity)) {
|
|
1701
|
+
return { outcome: 'already_terminal', targetTurnId: identity.turnId };
|
|
1702
|
+
}
|
|
1703
|
+
await coordinator.stopRoot(identity);
|
|
1704
|
+
return { outcome: 'stop_delivered', targetTurnId: identity.turnId };
|
|
1705
|
+
}
|
|
1706
|
+
function isActiveWorkHubRoot(coordinator, identity) {
|
|
1707
|
+
const rootState = coordinator.readRootState(identity.sessionId);
|
|
1708
|
+
return (rootState.kind === 'active' &&
|
|
1709
|
+
rootState.turnId === identity.turnId &&
|
|
1710
|
+
rootState.runId === identity.runId);
|
|
1711
|
+
}
|
|
1654
1712
|
function sessionExecutionConnectionRef(header) {
|
|
1655
1713
|
return header.llmConnectionId === undefined
|
|
1656
1714
|
? { kind: 'catalog_slug', connectionSlug: header.llmConnectionSlug }
|
|
@@ -87,11 +87,12 @@ export function createHostDailyReviewModel(input) {
|
|
|
87
87
|
const effectiveAbortSignal = AbortSignal.any([abortSignal, AbortSignal.timeout(60_000)]);
|
|
88
88
|
try {
|
|
89
89
|
const header = await readAuxiliaryPreflight(authority, effectiveAbortSignal, () => resolveDailyReviewHeader(authority.runtimePolicy, modelKey));
|
|
90
|
+
const callId = authority.newId();
|
|
90
91
|
const result = await runHostAuxiliaryModelCall(authority, {
|
|
91
|
-
transportContextId:
|
|
92
|
+
transportContextId: callId,
|
|
92
93
|
header,
|
|
93
94
|
callKind: 'daily_review',
|
|
94
|
-
callId: `daily_review_${
|
|
95
|
+
callId: `daily_review_${callId}`,
|
|
95
96
|
abortSignal: effectiveAbortSignal,
|
|
96
97
|
buildRequest: () => ({ prompt, maxOutputTokens: 2_048 }),
|
|
97
98
|
});
|
|
@@ -268,6 +269,7 @@ async function runHostAuxiliaryModelCall(authority, input) {
|
|
|
268
269
|
result = await readDuringBackendCreation(() => {
|
|
269
270
|
const providerOptions = buildProviderOptions(target.connection, target.model, input.header.thinkingLevel);
|
|
270
271
|
const model = getAIModel({
|
|
272
|
+
sessionId: input.transportContextId,
|
|
271
273
|
connection: target.connection,
|
|
272
274
|
apiKey,
|
|
273
275
|
modelId: target.model,
|
|
@@ -89,6 +89,7 @@ async function buildHostAiSdkBackend(input, target) {
|
|
|
89
89
|
requestHeaders: target.requestHeaders,
|
|
90
90
|
});
|
|
91
91
|
const resolveHistoryCompactModel = () => getAIModel({
|
|
92
|
+
sessionId: input.context.sessionId,
|
|
92
93
|
connection: target.connection,
|
|
93
94
|
apiKey,
|
|
94
95
|
modelId: target.model,
|
|
@@ -250,7 +251,7 @@ async function buildHostAiSdkBackend(input, target) {
|
|
|
250
251
|
: {}),
|
|
251
252
|
...(!input.context.tools && input.childAgents ? input.childAgents : {}),
|
|
252
253
|
providerOptions,
|
|
253
|
-
contextBudget: buildDefaultContextBudgetPolicy(
|
|
254
|
+
contextBudget: buildDefaultContextBudgetPolicy({
|
|
254
255
|
name: 'runtime-host-default-history-budget',
|
|
255
256
|
modelId: target.model,
|
|
256
257
|
}),
|
|
@@ -22,7 +22,8 @@ import { currentRuntimeHostProcessLaunch, tryAcquireRuntimeHostLaunch, } from '.
|
|
|
22
22
|
import { RuntimeHostKernel } from './host-kernel.js';
|
|
23
23
|
import { openRuntimeHostAccessAuthority } from './access-authority.js';
|
|
24
24
|
import { startRuntimeHostAuthenticatedListenerSet, } from './listener-set.js';
|
|
25
|
-
import {
|
|
25
|
+
import { openRuntimeHostPeerMeshComponent, } from '../peer-mesh/owner.js';
|
|
26
|
+
import { openRuntimeHostPeerEndpointOwner, } from '../peer-reachability/owner.js';
|
|
26
27
|
export class RuntimeHostRootAlreadyOwnedError extends Error {
|
|
27
28
|
rootPath;
|
|
28
29
|
code = 'root_already_owned';
|
|
@@ -46,31 +47,45 @@ export async function startExecutionRuntimeHostService(options, dependencies = {
|
|
|
46
47
|
if (!ownership)
|
|
47
48
|
throw new RuntimeHostRootAlreadyOwnedError(capability.canonicalPath);
|
|
48
49
|
const { owner } = ownership;
|
|
49
|
-
let
|
|
50
|
+
let peerEndpointOwner;
|
|
51
|
+
let peerMesh;
|
|
50
52
|
let host;
|
|
51
53
|
try {
|
|
52
|
-
if (options.peer
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
if (options.peer) {
|
|
55
|
+
peerEndpointOwner = await openRuntimeHostPeerEndpointOwner({
|
|
56
|
+
...options.peer,
|
|
57
|
+
dataRoot: options.peer.meshDataRoot ?? `${options.peer.keyPath}.state`,
|
|
58
|
+
onBackgroundReachabilityError: (error) => {
|
|
59
|
+
console.error('[runtime-host] peer reachability publication failed:', error);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
if (options.peer.meshDataRoot)
|
|
63
|
+
try {
|
|
64
|
+
peerMesh = await openRuntimeHostPeerMeshComponent({
|
|
65
|
+
dataRoot: options.peer.meshDataRoot,
|
|
66
|
+
endpoint: peerEndpointOwner,
|
|
67
|
+
endpointKind: 'host',
|
|
68
|
+
onBackgroundReconcileError: (error) => {
|
|
69
|
+
console.error('[runtime-host] Peer Mesh background synchronization failed:', error);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error('[runtime-host] Peer Mesh is unavailable; continuing with Direct peer:', error);
|
|
75
|
+
}
|
|
66
76
|
}
|
|
67
77
|
let peerTermination;
|
|
68
|
-
if (
|
|
78
|
+
if (peerEndpointOwner) {
|
|
69
79
|
const terminate = (error) => {
|
|
70
80
|
peerTermination ??= { error };
|
|
71
81
|
void host?.close().catch(() => undefined);
|
|
72
82
|
};
|
|
73
|
-
void
|
|
83
|
+
void peerEndpointOwner.closed.then(() => terminate(new Error('Runtime Host peer endpoint stopped unexpectedly')), terminate);
|
|
84
|
+
}
|
|
85
|
+
if (peerMesh) {
|
|
86
|
+
void peerMesh.closed.catch((error) => {
|
|
87
|
+
console.error('[runtime-host] Peer Mesh stopped; Direct peer remains available:', error);
|
|
88
|
+
});
|
|
74
89
|
}
|
|
75
90
|
const accessAuthority = await openRuntimeHostAccessAuthority(owner.controlDirectory);
|
|
76
91
|
host = await RuntimeHostKernel.start({
|
|
@@ -80,21 +95,25 @@ export async function startExecutionRuntimeHostService(options, dependencies = {
|
|
|
80
95
|
shutdownGraceMs: options.shutdownGraceMs,
|
|
81
96
|
composition,
|
|
82
97
|
accessAuthority,
|
|
83
|
-
...(
|
|
84
|
-
...(options.websocket ||
|
|
98
|
+
...(peerMesh ? { peerMesh: peerMesh.mesh } : {}),
|
|
99
|
+
...(options.websocket || peerEndpointOwner
|
|
85
100
|
? {
|
|
86
101
|
listenerSetFactory: (input) => startRuntimeHostAuthenticatedListenerSet(input, {
|
|
87
102
|
...(options.websocket
|
|
88
103
|
? { websocket: { ...options.websocket, accessAuthority } }
|
|
89
104
|
: {}),
|
|
90
|
-
...(
|
|
105
|
+
...(peerEndpointOwner
|
|
91
106
|
? {
|
|
92
|
-
peer:
|
|
93
|
-
|
|
94
|
-
:
|
|
107
|
+
peer: {
|
|
108
|
+
client: peerEndpointOwner.client,
|
|
109
|
+
reachability: peerEndpointOwner.reachability,
|
|
110
|
+
accessAuthority,
|
|
111
|
+
},
|
|
95
112
|
}
|
|
96
113
|
: {}),
|
|
97
|
-
}).then((listeners) =>
|
|
114
|
+
}).then((listeners) => peerEndpointOwner
|
|
115
|
+
? attachPeerOwnerCleanup(listeners, peerEndpointOwner, peerMesh)
|
|
116
|
+
: listeners),
|
|
98
117
|
}
|
|
99
118
|
: {}),
|
|
100
119
|
});
|
|
@@ -106,19 +125,21 @@ export async function startExecutionRuntimeHostService(options, dependencies = {
|
|
|
106
125
|
}
|
|
107
126
|
catch (error) {
|
|
108
127
|
await host?.close().catch(() => undefined);
|
|
109
|
-
await
|
|
128
|
+
await peerMesh?.close().catch(() => undefined);
|
|
129
|
+
await peerEndpointOwner?.close().catch(() => undefined);
|
|
110
130
|
if (!owner.closed)
|
|
111
131
|
await owner.close();
|
|
112
132
|
throw error;
|
|
113
133
|
}
|
|
114
134
|
}
|
|
115
|
-
export function attachPeerOwnerCleanup(listeners,
|
|
135
|
+
export function attachPeerOwnerCleanup(listeners, endpoint, mesh) {
|
|
116
136
|
return {
|
|
117
137
|
...listeners,
|
|
118
138
|
cleanup: async () => {
|
|
119
139
|
const errors = [];
|
|
120
140
|
await listeners.cleanup().catch((error) => errors.push(error));
|
|
121
|
-
await
|
|
141
|
+
await mesh?.close().catch((error) => errors.push(error));
|
|
142
|
+
await endpoint.close().catch((error) => errors.push(error));
|
|
122
143
|
if (errors.length === 1)
|
|
123
144
|
throw errors[0];
|
|
124
145
|
if (errors.length > 1) {
|
|
@@ -25,7 +25,7 @@ import { removeHostRegistration, writeHostRegistration } from '../control/regist
|
|
|
25
25
|
import { decodeClientFrame, encodeProtocolMessage, HOST_OPERATION_SPECS, negotiateProtocol, RUNTIME_HOST_COMPATIBILITY_EPOCH, RUNTIME_HOST_PROTOCOL_VERSION, RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION, requireHostGeneration, } from '../protocol/index.js';
|
|
26
26
|
import { RuntimeHostConnectionSession, } from './connection-session.js';
|
|
27
27
|
import { composeOperationHandlers, createUnavailableDomainOperationHandlers, } from './operation-dispatcher.js';
|
|
28
|
-
import { issueAccessCredential, acknowledgeCollaborationTurnRequest, createCollaborationTurnRequest, decideCollaborationTurnRequest, finalizeAccessCredential, prepareCollaborationInvitation, queryCollaborationTurnRequests, prepareAccessCredential, prepareAccessCredentialRotation, replaceAccessCredential, revokeAccessCredential, revokeAccessPrincipal, revokeAccessCredentialRotation, revokeCollaborationGrant, revokeCollaborationPrincipal, } from './access-authority.js';
|
|
28
|
+
import { issueAccessCredential, acknowledgeCollaborationTurnRequest, createCollaborationTurnRequest, decideCollaborationTurnRequest, withdrawCollaborationTurnRequest, finalizeAccessCredential, prepareCollaborationInvitation, queryCollaborationTurnRequests, prepareAccessCredential, prepareAccessCredentialRotation, replaceAccessCredential, revokeAccessCredential, revokeAccessPrincipal, revokeAccessCredentialRotation, revokeCollaborationGrant, revokeCollaborationPrincipal, } from './access-authority.js';
|
|
29
29
|
import { runtimeHostLogBuffer } from '../process-diagnostics.js';
|
|
30
30
|
import { startLocalRuntimeHostListenerSet, } from './listener-set.js';
|
|
31
31
|
import { HostResidencyRegistry } from './host-residency-registry.js';
|
|
@@ -556,6 +556,7 @@ export class RuntimeHostKernel {
|
|
|
556
556
|
principalKind: context.principalKind,
|
|
557
557
|
}, input),
|
|
558
558
|
'collaboration.turn-request.acknowledge': async (input, context) => this.#settleAccessCredentialMutation(acknowledgeCollaborationTurnRequest(this.#options.accessAuthority, context.principal, input)),
|
|
559
|
+
'collaboration.turn-request.withdraw': async (input, context) => this.#settleAccessCredentialMutation(withdrawCollaborationTurnRequest(this.#options.accessAuthority, context.principal, input)),
|
|
559
560
|
'collaboration.turn-request.decide': async (input, context) => this.#settleAccessCredentialMutation(decideCollaborationTurnRequest(this.#options.accessAuthority, context.principal, input)),
|
|
560
561
|
}, createPeerMeshOperationHandlers(this.#options.peerMesh, {
|
|
561
562
|
requestDrain: () => this.#requestDrain(),
|
|
@@ -580,11 +581,7 @@ export class RuntimeHostKernel {
|
|
|
580
581
|
activeResidencies: this.#residencies.activeCount,
|
|
581
582
|
...(peer
|
|
582
583
|
? {
|
|
583
|
-
peerEndpoint:
|
|
584
|
-
peerId: peer.peerId,
|
|
585
|
-
routeHints: peer.listenAddresses,
|
|
586
|
-
coordinationRelays: peer.coordinationRelays,
|
|
587
|
-
},
|
|
584
|
+
peerEndpoint: peer.reachability,
|
|
588
585
|
}
|
|
589
586
|
: {}),
|
|
590
587
|
};
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
20
|
import { isDeepStrictEqual } from 'node:util';
|
|
21
|
-
import { isInteractionAnswerValidForRequest, projectInteractionClientCapabilityRequest, projectInteractionSandboxBoundaryRequest, projectInteractionQuestionRequest, } from '@maka/core/interaction';
|
|
21
|
+
import { isInteractionAnswerValidForRequest, projectInteractionClientCapabilityRequest, projectInteractionSandboxBoundaryRequest, projectInteractionFormRequest, projectInteractionQuestionRequest, } from '@maka/core/interaction';
|
|
22
22
|
import { RuntimeInteractionAdmissionRejectedError, RuntimeInteractionFailStopError, RuntimeInteractionInvariantError, } from '@maka/runtime/interaction-authority';
|
|
23
23
|
import { authenticateInteractionStoreWriter, } from '@maka/storage/interaction-store';
|
|
24
24
|
import { INTERACTION_MAX_PENDING_PER_SESSION, } from '../protocol/index.js';
|
|
25
|
-
import { answerOutcome, clientCapabilityCanonicalOutcome, compareStoredInteractionRequests, projectInteractionRecord, projectSandboxBoundaryInteraction, projectSessionInteractions, questionCanonicalOutcome, runtimeQuestionOutcome, } from './interaction-projection.js';
|
|
25
|
+
import { answerOutcome, clientCapabilityCanonicalOutcome, compareStoredInteractionRequests, projectInteractionRecord, projectSandboxBoundaryInteraction, projectSessionInteractions, formCanonicalOutcome, questionCanonicalOutcome, runtimeQuestionOutcome, runtimeFormOutcome, } from './interaction-projection.js';
|
|
26
26
|
export class ClientCapabilityApprovalClosedError extends Error {
|
|
27
27
|
reason;
|
|
28
28
|
constructor(reason) {
|
|
@@ -83,6 +83,8 @@ export class HostInteractionCoordinator {
|
|
|
83
83
|
return Object.freeze({
|
|
84
84
|
...identity,
|
|
85
85
|
acceptUserQuestionRequest: (input) => this.#acceptUserQuestionRequest(run, input),
|
|
86
|
+
acceptFormRequest: (input) => this.#acceptFormRequest(run, input),
|
|
87
|
+
withdrawFormRequest: (requestId) => this.#withdrawFormRequest(run, requestId),
|
|
86
88
|
acceptSandboxBoundaryRequest: (input) => this.#acceptSandboxBoundaryRequest(run, input),
|
|
87
89
|
close: (reason) => this.#closeRun(run, reason),
|
|
88
90
|
release: () => this.#releaseRun(run),
|
|
@@ -276,6 +278,36 @@ export class HostInteractionCoordinator {
|
|
|
276
278
|
return rejected(error);
|
|
277
279
|
}
|
|
278
280
|
}
|
|
281
|
+
#acceptFormRequest(run, input) {
|
|
282
|
+
try {
|
|
283
|
+
this.#assertAcceptable(run, input.request, input.continuation);
|
|
284
|
+
let request;
|
|
285
|
+
try {
|
|
286
|
+
request = projectInteractionFormRequest({
|
|
287
|
+
toolUseId: input.request.toolUseId,
|
|
288
|
+
message: input.request.message,
|
|
289
|
+
requester: input.request.requester,
|
|
290
|
+
fields: input.request.fields,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return rejected(new RuntimeInteractionAdmissionRejectedError(input.continuation.requestId, 'invalid_request'));
|
|
295
|
+
}
|
|
296
|
+
return observed(this.#accept(run, {
|
|
297
|
+
kind: 'form',
|
|
298
|
+
request: {
|
|
299
|
+
...runIdentity(run),
|
|
300
|
+
requestId: input.continuation.requestId,
|
|
301
|
+
createdAt: input.request.ts,
|
|
302
|
+
request,
|
|
303
|
+
},
|
|
304
|
+
continuation: input.continuation,
|
|
305
|
+
}).then(() => undefined));
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
return rejected(error);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
279
311
|
#acceptSandboxBoundaryRequest(run, input) {
|
|
280
312
|
try {
|
|
281
313
|
this.#assertAcceptable(run, input.request, input.continuation);
|
|
@@ -372,9 +404,10 @@ export class HostInteractionCoordinator {
|
|
|
372
404
|
if (this.#live.has(input.request.requestId)) {
|
|
373
405
|
throw this.#poison(new RuntimeInteractionInvariantError(`Interaction ${input.request.requestId} was accepted twice`));
|
|
374
406
|
}
|
|
375
|
-
const
|
|
407
|
+
const storedInteractions = await this.#readPending({ sessionId: run.sessionId });
|
|
376
408
|
const sandboxBoundaries = await this.#readPendingSandboxBoundaries(run.sessionId);
|
|
377
|
-
if (
|
|
409
|
+
if (storedInteractions.length + sandboxBoundaries.length >=
|
|
410
|
+
INTERACTION_MAX_PENDING_PER_SESSION) {
|
|
378
411
|
throw new RuntimeInteractionAdmissionRejectedError(input.request.requestId, 'capacity_exceeded');
|
|
379
412
|
}
|
|
380
413
|
const candidate = {
|
|
@@ -388,7 +421,10 @@ export class HostInteractionCoordinator {
|
|
|
388
421
|
turnId: run.turnId,
|
|
389
422
|
runId: run.runId,
|
|
390
423
|
};
|
|
391
|
-
const projection = projectSessionInteractions(
|
|
424
|
+
const projection = projectSessionInteractions(storedInteractions, [
|
|
425
|
+
...sandboxBoundaries,
|
|
426
|
+
candidate,
|
|
427
|
+
]);
|
|
392
428
|
if (!(await this.#preflightSessionSnapshot(run.sessionId, projection, admission))) {
|
|
393
429
|
throw new RuntimeInteractionAdmissionRejectedError(input.request.requestId, 'capacity_exceeded');
|
|
394
430
|
}
|
|
@@ -449,7 +485,7 @@ export class HostInteractionCoordinator {
|
|
|
449
485
|
return interactionNotFound();
|
|
450
486
|
return record.request.request.kind === 'client_capability'
|
|
451
487
|
? this.#answerClientCapability(record, input.answer, admission)
|
|
452
|
-
: this.#
|
|
488
|
+
: this.#answerStoredInteraction(record, input.answer, admission);
|
|
453
489
|
}
|
|
454
490
|
const sandboxBoundary = await this.#readSandboxBoundary(input.sessionId, input.interactionId);
|
|
455
491
|
return sandboxBoundary
|
|
@@ -462,7 +498,7 @@ export class HostInteractionCoordinator {
|
|
|
462
498
|
throw this.#poison(error);
|
|
463
499
|
}));
|
|
464
500
|
}
|
|
465
|
-
async #
|
|
501
|
+
async #answerStoredInteraction(record, answer, admission) {
|
|
466
502
|
if (record.request.request.kind === 'sandbox_boundary') {
|
|
467
503
|
return record.outcome
|
|
468
504
|
? interactionAlreadyResolved()
|
|
@@ -470,14 +506,23 @@ export class HostInteractionCoordinator {
|
|
|
470
506
|
}
|
|
471
507
|
if (record.outcome)
|
|
472
508
|
return answerOutcome(recordWithOutcome(record), answer);
|
|
473
|
-
if (record.request.request.kind !== 'question'
|
|
509
|
+
if ((record.request.request.kind !== 'question' && record.request.request.kind !== 'form') ||
|
|
510
|
+
record.request.request.kind !== answer.kind) {
|
|
474
511
|
return operationConflict('Interaction answer does not match the pending request');
|
|
475
512
|
}
|
|
476
513
|
if (!isInteractionAnswerValidForRequest(record.request.request, answer)) {
|
|
477
514
|
return operationConflict('Interaction answer does not match the pending request');
|
|
478
515
|
}
|
|
479
|
-
const entry = this.#
|
|
480
|
-
const
|
|
516
|
+
const entry = this.#requireLiveStored(record.request);
|
|
517
|
+
const candidate = answer.kind === 'question'
|
|
518
|
+
? questionCanonicalOutcome(answer, this.#now())
|
|
519
|
+
: answer.kind === 'form'
|
|
520
|
+
? formCanonicalOutcome(answer, this.#now())
|
|
521
|
+
: undefined;
|
|
522
|
+
if (!candidate) {
|
|
523
|
+
return operationConflict('Interaction answer does not match the pending request');
|
|
524
|
+
}
|
|
525
|
+
const outcome = await this.#commitAnswer(entry, candidate, admission);
|
|
481
526
|
return answerOutcome({ request: record.request, outcome }, answer);
|
|
482
527
|
}
|
|
483
528
|
async #answerSandboxBoundary(request, answer, admission) {
|
|
@@ -564,6 +609,49 @@ export class HostInteractionCoordinator {
|
|
|
564
609
|
return rejected(error);
|
|
565
610
|
}
|
|
566
611
|
}
|
|
612
|
+
#withdrawFormRequest(run, requestId) {
|
|
613
|
+
try {
|
|
614
|
+
this.#assertOwnedRun(run);
|
|
615
|
+
this.#throwIfPoisoned();
|
|
616
|
+
if (run.released) {
|
|
617
|
+
throw this.#poison(new RuntimeInteractionInvariantError(`Released Interaction Run ${run.runId} cannot withdraw a form`));
|
|
618
|
+
}
|
|
619
|
+
return observed(this.#sessionAdmission.run(run.sessionId, async (admission) => {
|
|
620
|
+
this.#throwIfPoisoned();
|
|
621
|
+
// A whole-Run stop/terminal closure that already claimed ownership
|
|
622
|
+
// remains the reason for every still-pending Interaction in that Run.
|
|
623
|
+
if (run.closure)
|
|
624
|
+
return;
|
|
625
|
+
const record = await this.#readInteraction(requestId);
|
|
626
|
+
// Cancellation may win while admission is still proving publication.
|
|
627
|
+
// The producer will also observe its abort and must not publish afterward.
|
|
628
|
+
if (!record)
|
|
629
|
+
return;
|
|
630
|
+
if (!sameRun(record.request, run) || record.request.request.kind !== 'form') {
|
|
631
|
+
throw this.#poison(new RuntimeInteractionInvariantError(`Interaction Run ${run.runId} cannot withdraw form ${requestId}`));
|
|
632
|
+
}
|
|
633
|
+
// A canonical user answer or Run closure that won the Session admission
|
|
634
|
+
// race stays authoritative.
|
|
635
|
+
if (record.outcome)
|
|
636
|
+
return;
|
|
637
|
+
const entry = this.#requireLiveStored(record.request);
|
|
638
|
+
if (entry.kind !== 'form' || entry.run !== run) {
|
|
639
|
+
throw this.#poison(new RuntimeInteractionInvariantError(`Form ${requestId} is not owned by Interaction Run ${run.runId}`));
|
|
640
|
+
}
|
|
641
|
+
const outcome = await this.#commitOutcome(record.request, {
|
|
642
|
+
kind: 'closure',
|
|
643
|
+
reason: 'producer_cancelled',
|
|
644
|
+
committedAt: this.#now(),
|
|
645
|
+
});
|
|
646
|
+
await this.#refreshCanonicalContinuity(run.sessionId, admission);
|
|
647
|
+
this.#throwIfPoisoned();
|
|
648
|
+
await this.#applyAndDelete(entry, outcome);
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
return rejected(error);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
567
655
|
#claimRunClosure(run, reason) {
|
|
568
656
|
if (run.closure)
|
|
569
657
|
return run.closure;
|
|
@@ -607,9 +695,7 @@ export class HostInteractionCoordinator {
|
|
|
607
695
|
const pending = await this.#readPending(runIdentity(run));
|
|
608
696
|
const committed = [];
|
|
609
697
|
for (const request of pending.sort(compareStoredInteractionRequests)) {
|
|
610
|
-
const entry = request
|
|
611
|
-
? this.#requireLiveClientCapability(request)
|
|
612
|
-
: this.#requireLiveQuestion(request);
|
|
698
|
+
const entry = this.#requireLiveStored(request);
|
|
613
699
|
const closureOutcome = {
|
|
614
700
|
kind: 'closure',
|
|
615
701
|
reason: closure.reason,
|
|
@@ -688,29 +774,37 @@ export class HostInteractionCoordinator {
|
|
|
688
774
|
}
|
|
689
775
|
try {
|
|
690
776
|
const sessions = new Map();
|
|
691
|
-
const
|
|
777
|
+
const pendingInteractions = await this.#readPending();
|
|
692
778
|
const pendingSandboxBoundaries = await this.#readAllPendingSandboxBoundaries();
|
|
693
|
-
for (const request of
|
|
779
|
+
for (const request of pendingInteractions) {
|
|
694
780
|
const requests = sessions.get(request.sessionId);
|
|
695
781
|
if (requests)
|
|
696
|
-
requests.
|
|
697
|
-
else
|
|
698
|
-
sessions.set(request.sessionId, {
|
|
782
|
+
requests.storedInteractions.push(request);
|
|
783
|
+
else {
|
|
784
|
+
sessions.set(request.sessionId, {
|
|
785
|
+
storedInteractions: [request],
|
|
786
|
+
sandboxBoundaries: [],
|
|
787
|
+
});
|
|
788
|
+
}
|
|
699
789
|
}
|
|
700
790
|
for (const request of pendingSandboxBoundaries) {
|
|
701
791
|
const requests = sessions.get(request.sessionId);
|
|
702
792
|
if (requests)
|
|
703
793
|
requests.sandboxBoundaries.push(request);
|
|
704
|
-
else
|
|
705
|
-
sessions.set(request.sessionId, {
|
|
794
|
+
else {
|
|
795
|
+
sessions.set(request.sessionId, {
|
|
796
|
+
storedInteractions: [],
|
|
797
|
+
sandboxBoundaries: [request],
|
|
798
|
+
});
|
|
799
|
+
}
|
|
706
800
|
}
|
|
707
801
|
for (const [sessionId, requests] of sessions) {
|
|
708
|
-
if (requests.
|
|
802
|
+
if (requests.storedInteractions.length + requests.sandboxBoundaries.length >
|
|
709
803
|
INTERACTION_MAX_PENDING_PER_SESSION) {
|
|
710
804
|
throw new RuntimeInteractionInvariantError(`Session ${sessionId} exceeds the pending Interaction limit`);
|
|
711
805
|
}
|
|
712
806
|
await this.#sessionAdmission.run(sessionId, async (admission) => {
|
|
713
|
-
for (const request of requests.
|
|
807
|
+
for (const request of requests.storedInteractions.sort(compareStoredInteractionRequests)) {
|
|
714
808
|
const closure = {
|
|
715
809
|
kind: 'closure',
|
|
716
810
|
reason: 'host_restarted',
|
|
@@ -881,13 +975,21 @@ export class HostInteractionCoordinator {
|
|
|
881
975
|
return;
|
|
882
976
|
}
|
|
883
977
|
try {
|
|
884
|
-
const projected =
|
|
978
|
+
const projected = entry.kind === 'question'
|
|
979
|
+
? runtimeQuestionOutcome(outcome.outcome)
|
|
980
|
+
: runtimeFormOutcome(outcome.outcome);
|
|
885
981
|
if (projected.kind === 'closure') {
|
|
886
982
|
await entry.continuation.applyClosure(projected.reason);
|
|
887
983
|
}
|
|
888
|
-
else {
|
|
984
|
+
else if (entry.kind === 'question' && projected.kind === 'question_answer') {
|
|
985
|
+
await entry.continuation.applyAnswer(projected.answer);
|
|
986
|
+
}
|
|
987
|
+
else if (entry.kind === 'form' && projected.kind === 'form_answer') {
|
|
889
988
|
await entry.continuation.applyAnswer(projected.answer);
|
|
890
989
|
}
|
|
990
|
+
else {
|
|
991
|
+
throw new RuntimeInteractionInvariantError(`Stored Interaction ${entry.request.requestId} projected the wrong answer kind`);
|
|
992
|
+
}
|
|
891
993
|
}
|
|
892
994
|
catch (error) {
|
|
893
995
|
throw this.#poison(error);
|
|
@@ -925,13 +1027,14 @@ export class HostInteractionCoordinator {
|
|
|
925
1027
|
throw this.#poison(new RuntimeInteractionInvariantError(`Live sandbox boundary identity changed for ${entry.boundaryRequest.requestId}`));
|
|
926
1028
|
}
|
|
927
1029
|
}
|
|
928
|
-
#
|
|
1030
|
+
#requireLiveStored(request) {
|
|
929
1031
|
const entry = this.#live.get(request.requestId);
|
|
930
1032
|
if (!entry ||
|
|
931
|
-
entry.kind
|
|
1033
|
+
entry.kind === 'sandbox_boundary' ||
|
|
1034
|
+
entry.kind !== request.request.kind ||
|
|
932
1035
|
entry.phase !== 'live' ||
|
|
933
1036
|
!isDeepStrictEqual(entry.request, request)) {
|
|
934
|
-
throw this.#poison(new RuntimeInteractionInvariantError(`Pending
|
|
1037
|
+
throw this.#poison(new RuntimeInteractionInvariantError(`Pending stored Interaction ${request.requestId} has no exact live continuation`));
|
|
935
1038
|
}
|
|
936
1039
|
return entry;
|
|
937
1040
|
}
|