@noopolis/daimon 0.2.0 → 0.2.1
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/README.md +6 -0
- package/dist/contracts/attentionContract.d.ts +25 -0
- package/dist/contracts/attentionContract.d.ts.map +1 -1
- package/dist/contracts/attentionContract.js +8 -1
- package/dist/contracts/grokBrokerTaskClock.d.ts +18 -0
- package/dist/contracts/grokBrokerTaskClock.d.ts.map +1 -0
- package/dist/contracts/grokBrokerTaskClock.js +16 -0
- package/dist/contracts/organizationRuntimeContract.d.ts +76 -0
- package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -1
- package/dist/contracts/organizationRuntimeContract.js +2 -0
- package/dist/contracts/runtimeContractManifest.d.ts +222 -15
- package/dist/contracts/runtimeContractManifest.d.ts.map +1 -1
- package/dist/contracts/runtimeContractManifest.js +35 -10
- package/dist/contracts/shellEnvironmentPolicy.d.ts +3 -0
- package/dist/contracts/shellEnvironmentPolicy.d.ts.map +1 -0
- package/dist/contracts/shellEnvironmentPolicy.js +5 -0
- package/dist/contracts/wakeMomentContract.d.ts +61 -0
- package/dist/contracts/wakeMomentContract.d.ts.map +1 -0
- package/dist/contracts/wakeMomentContract.js +27 -0
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/examples/jungianPlayAgent.d.ts +1 -0
- package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
- package/dist/examples/jungianPlayAgent.js +6 -2
- package/dist/observability/causalEvents.d.ts +3 -3
- package/dist/observability/causalEvents.d.ts.map +1 -1
- package/dist/observability/causalEvents.js +4 -4
- package/dist/pi/cliEngineSpawn.d.ts +2 -2
- package/dist/pi/cliEngineSpawn.d.ts.map +1 -1
- package/dist/pi/cliEngineSpawn.js +7 -2
- package/dist/pi/cliEnvironment.d.ts.map +1 -1
- package/dist/pi/cliEnvironment.js +2 -0
- package/dist/pi/cliMcpRegistration.d.ts +1 -1
- package/dist/pi/cliMcpRegistration.d.ts.map +1 -1
- package/dist/pi/cliMcpRegistration.js +1 -1
- package/dist/pi/cliSession.d.ts +2 -0
- package/dist/pi/cliSession.d.ts.map +1 -1
- package/dist/pi/cliSession.js +3 -80
- package/dist/pi/cliSessionMcp.d.ts +9 -0
- package/dist/pi/cliSessionMcp.d.ts.map +1 -0
- package/dist/pi/cliSessionMcp.js +80 -0
- package/dist/pi/engineTaskClock.d.ts +9 -0
- package/dist/pi/engineTaskClock.d.ts.map +1 -0
- package/dist/pi/engineTaskClock.js +28 -0
- package/dist/pi/grokHomeMcpRegistration.d.ts.map +1 -1
- package/dist/pi/grokHomeMcpRegistration.js +2 -1
- package/dist/pi/grokSandbox.js +1 -1
- package/dist/pi/memoryClock.d.ts +25 -0
- package/dist/pi/memoryClock.d.ts.map +1 -0
- package/dist/pi/memoryClock.js +18 -0
- package/dist/pi/piAgentHandle.d.ts +3 -1
- package/dist/pi/piAgentHandle.d.ts.map +1 -1
- package/dist/pi/piAgentHandle.js +5 -2
- package/dist/pi/piHarness.d.ts +8 -2
- package/dist/pi/piHarness.d.ts.map +1 -1
- package/dist/pi/piHarness.js +28 -12
- package/dist/pi/taskClockProcess.d.ts +6 -0
- package/dist/pi/taskClockProcess.d.ts.map +1 -0
- package/dist/pi/taskClockProcess.js +8 -0
- package/dist/pi/turnCausal.d.ts +4 -2
- package/dist/pi/turnCausal.d.ts.map +1 -1
- package/dist/pi/turnCausal.js +4 -4
- package/dist/pi/wakeAcceptance.d.ts +1 -1
- package/dist/pi/wakeAcceptance.d.ts.map +1 -1
- package/dist/pi/wakeAcceptance.js +2 -2
- package/dist/runtime/agySubscriptionBootstrap.js +1 -1
- package/dist/runtime/agySubscriptionRealm.js +1 -1
- package/dist/runtime/attention.d.ts +5 -0
- package/dist/runtime/attention.d.ts.map +1 -1
- package/dist/runtime/attention.js +14 -1
- package/dist/runtime/attentionDispatcher.d.ts +14 -2
- package/dist/runtime/attentionDispatcher.d.ts.map +1 -1
- package/dist/runtime/attentionDispatcher.js +127 -33
- package/dist/runtime/cli.js +5 -0
- package/dist/runtime/contract-manifest.json +1 -1
- package/dist/runtime/contract-manifest.sha256 +1 -1
- package/dist/runtime/engineBrokerCapabilities.d.ts +10 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -1
- package/dist/runtime/engineBrokerCapabilities.js +10 -0
- package/dist/runtime/engineBrokerControlClient.d.ts +12 -1
- package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -1
- package/dist/runtime/engineBrokerControlClient.js +139 -43
- package/dist/runtime/engineBrokerCredentialJournal.d.ts +2 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -1
- package/dist/runtime/engineBrokerCredentialJournal.js +9 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts +3 -2
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -1
- package/dist/runtime/engineBrokerInferenceProtocol.js +4 -4
- package/dist/runtime/engineBrokerMcpCallLog.d.ts +11 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -1
- package/dist/runtime/engineBrokerMcpCallLog.js +13 -1
- package/dist/runtime/engineBrokerMcpFacade.d.ts +5 -2
- package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -1
- package/dist/runtime/engineBrokerMcpFacade.js +5 -2
- package/dist/runtime/engineBrokerNativeClient.js +2 -2
- package/dist/runtime/engineBrokerProtocol.d.ts +42 -10
- package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -1
- package/dist/runtime/engineBrokerProtocol.js +97 -14
- package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -1
- package/dist/runtime/engineBrokerSealLedger.js +9 -0
- package/dist/runtime/engineBrokerService.d.ts +8 -2
- package/dist/runtime/engineBrokerService.d.ts.map +1 -1
- package/dist/runtime/engineBrokerService.js +95 -37
- package/dist/runtime/engineBrokerServiceCli.js +1 -1
- package/dist/runtime/engineBrokerServiceConfig.d.ts +5 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -1
- package/dist/runtime/engineBrokerServiceConfig.js +47 -9
- package/dist/runtime/engineBrokerTurnRegistry.d.ts +1 -1
- package/dist/runtime/engineBrokerTurnRegistry.d.ts.map +1 -1
- package/dist/runtime/engineBrokerTurnRegistry.js +7 -6
- package/dist/runtime/engineDispatcher.d.ts +2 -0
- package/dist/runtime/engineDispatcher.d.ts.map +1 -1
- package/dist/runtime/engineDispatcher.js +14 -2
- package/dist/runtime/engineReadiness.js +1 -1
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts +1 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -1
- package/dist/runtime/grokBrokerCredentialAuthority.js +48 -22
- package/dist/runtime/grokBrokerCredentialReader.d.ts +1 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -1
- package/dist/runtime/grokBrokerCredentialReader.js +2 -1
- package/dist/runtime/grokBrokerProjection.d.ts +9 -1
- package/dist/runtime/grokBrokerProjection.d.ts.map +1 -1
- package/dist/runtime/grokBrokerProjection.js +11 -4
- package/dist/runtime/grokBrokerProviderClock.d.ts +26 -0
- package/dist/runtime/grokBrokerProviderClock.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProviderClock.js +133 -0
- package/dist/runtime/grokBrokerProxy.d.ts +17 -3
- package/dist/runtime/grokBrokerProxy.d.ts.map +1 -1
- package/dist/runtime/grokBrokerProxy.js +73 -9
- package/dist/runtime/grokBrokerProxyJson.d.ts +10 -0
- package/dist/runtime/grokBrokerProxyJson.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxyJson.js +31 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -1
- package/dist/runtime/grokBrokerProxyRequest.js +17 -6
- package/dist/runtime/grokBrokerRealmLease.js +1 -1
- package/dist/runtime/grokBrokerRefresh.js +1 -1
- package/dist/runtime/grokBrokerRunBudget.d.ts +20 -0
- package/dist/runtime/grokBrokerRunBudget.d.ts.map +1 -0
- package/dist/runtime/grokBrokerRunBudget.js +85 -0
- package/dist/runtime/grokBrokerSlot.d.ts +6 -0
- package/dist/runtime/grokBrokerSlot.d.ts.map +1 -0
- package/dist/runtime/grokBrokerSlot.js +21 -0
- package/dist/runtime/grokBrokerTaskClock.d.ts +32 -0
- package/dist/runtime/grokBrokerTaskClock.d.ts.map +1 -0
- package/dist/runtime/grokBrokerTaskClock.js +120 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts +55 -3
- package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -1
- package/dist/runtime/grokBrokerTurnMeter.js +90 -4
- package/dist/runtime/grokBrokerWorkerConfig.d.ts +5 -2
- package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -1
- package/dist/runtime/grokBrokerWorkerConfig.js +22 -3
- package/dist/runtime/grokEngineBroker.d.ts +43 -3
- package/dist/runtime/grokEngineBroker.d.ts.map +1 -1
- package/dist/runtime/grokEngineBroker.js +159 -71
- package/dist/runtime/grokEngineBrokerTurn.d.ts +32 -8
- package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -1
- package/dist/runtime/grokEngineBrokerTurn.js +204 -21
- package/dist/runtime/grokEngineBrokerTurnEnd.d.ts +88 -0
- package/dist/runtime/grokEngineBrokerTurnEnd.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerTurnEnd.js +148 -0
- package/dist/runtime/grokInferenceProxy.d.ts.map +1 -1
- package/dist/runtime/grokInferenceProxy.js +3 -0
- package/dist/runtime/grokSubscriptionRealm.js +1 -1
- package/dist/runtime/grokWorkerAttestation.d.ts +9 -4
- package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -1
- package/dist/runtime/grokWorkerAttestation.js +2 -2
- package/dist/runtime/grokWorkerHomeAttestation.d.ts +4 -2
- package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -1
- package/dist/runtime/grokWorkerHomeAttestation.js +10 -4
- package/dist/runtime/index.d.ts +7 -2
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -1
- package/dist/runtime/native/daimon-engine-broker +0 -0
- package/dist/runtime/organizationRuntime.d.ts +3 -0
- package/dist/runtime/organizationRuntime.d.ts.map +1 -1
- package/dist/runtime/organizationRuntimeAdmission.d.ts +6 -0
- package/dist/runtime/organizationRuntimeAdmission.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeAdmission.js +22 -0
- package/dist/runtime/organizationRuntimeControl.d.ts +9 -0
- package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -1
- package/dist/runtime/organizationRuntimeControl.js +72 -24
- package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -1
- package/dist/runtime/organizationRuntimeHost.js +13 -4
- package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -1
- package/dist/runtime/organizationRuntimeParsing.js +4 -1
- package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -1
- package/dist/runtime/organizationRuntimeReadiness.js +8 -0
- package/dist/runtime/organizationRuntimeRecording.d.ts +7 -0
- package/dist/runtime/organizationRuntimeRecording.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeRecording.js +58 -0
- package/dist/runtime/physicalReadiness.d.ts +12 -0
- package/dist/runtime/physicalReadiness.d.ts.map +1 -1
- package/dist/runtime/physicalReadiness.js +43 -9
- package/dist/runtime/productionAgentTools.d.ts.map +1 -1
- package/dist/runtime/productionAgentTools.js +13 -5
- package/dist/runtime/relocateRuntimeConfig.d.ts +14 -0
- package/dist/runtime/relocateRuntimeConfig.d.ts.map +1 -0
- package/dist/runtime/relocateRuntimeConfig.js +38 -0
- package/dist/runtime/schedule.d.ts.map +1 -1
- package/dist/runtime/schedule.js +12 -7
- package/dist/runtime/storeCoordination.d.ts +10 -0
- package/dist/runtime/storeCoordination.d.ts.map +1 -1
- package/dist/runtime/storeCoordination.js +23 -0
- package/dist/runtime/taskClock.d.ts +42 -0
- package/dist/runtime/taskClock.d.ts.map +1 -0
- package/dist/runtime/taskClock.js +102 -0
- package/dist/runtime/taskClockProcess.d.ts +17 -0
- package/dist/runtime/taskClockProcess.d.ts.map +1 -0
- package/dist/runtime/taskClockProcess.js +58 -0
- package/dist/runtime/turnRequestLedger.d.ts +0 -5
- package/dist/runtime/turnRequestLedger.d.ts.map +1 -1
- package/dist/runtime/turnRequestLedger.js +23 -21
- package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts +34 -0
- package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceClaimDiagnostics.js +79 -0
- package/dist/runtime/wakeAcceptanceIndex.d.ts +55 -0
- package/dist/runtime/wakeAcceptanceIndex.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceIndex.js +158 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts +9 -1
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -1
- package/dist/runtime/wakeAcceptanceProcessIdentity.js +5 -1
- package/dist/runtime/wakeAcceptanceRecord.d.ts +2 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -1
- package/dist/runtime/wakeAcceptanceRecord.js +4 -2
- package/dist/runtime/wakeAcceptanceRetention.d.ts +25 -1
- package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -1
- package/dist/runtime/wakeAcceptanceRetention.js +28 -2
- package/dist/runtime/wakeAcceptanceStore.d.ts +8 -8
- package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -1
- package/dist/runtime/wakeAcceptanceStore.js +66 -63
- package/dist/runtime/wakeFuse.d.ts +58 -3
- package/dist/runtime/wakeFuse.d.ts.map +1 -1
- package/dist/runtime/wakeFuse.js +106 -7
- package/dist/runtime/wakeMomentFs.d.ts +27 -0
- package/dist/runtime/wakeMomentFs.d.ts.map +1 -0
- package/dist/runtime/wakeMomentFs.js +223 -0
- package/dist/runtime/wakeMomentHistory.d.ts +26 -0
- package/dist/runtime/wakeMomentHistory.d.ts.map +1 -0
- package/dist/runtime/wakeMomentHistory.js +109 -0
- package/dist/runtime/wakeMomentIo.d.ts +22 -0
- package/dist/runtime/wakeMomentIo.d.ts.map +1 -0
- package/dist/runtime/wakeMomentIo.js +114 -0
- package/dist/runtime/wakeMomentRecorder.d.ts +33 -0
- package/dist/runtime/wakeMomentRecorder.d.ts.map +1 -0
- package/dist/runtime/wakeMomentRecorder.js +81 -0
- package/dist/runtime/wakeMomentRetention.d.ts +7 -0
- package/dist/runtime/wakeMomentRetention.d.ts.map +1 -0
- package/dist/runtime/wakeMomentRetention.js +143 -0
- package/dist/runtime/wakeMomentRows.d.ts +8 -0
- package/dist/runtime/wakeMomentRows.d.ts.map +1 -0
- package/dist/runtime/wakeMomentRows.js +66 -0
- package/dist/runtime/wakeMomentSnapshot.d.ts +56 -0
- package/dist/runtime/wakeMomentSnapshot.d.ts.map +1 -0
- package/dist/runtime/wakeMomentSnapshot.js +248 -0
- package/package.json +4 -4
|
@@ -1,17 +1,27 @@
|
|
|
1
|
+
import { type BrokerClockObservation } from "./grokBrokerTaskClock.js";
|
|
1
2
|
import { type EngineBrokerInferenceRequest, type EngineBrokerInferenceResponse } from "./engineBrokerInferenceProtocol.js";
|
|
2
3
|
import { type EngineBrokerMcpCallObservation } from "./engineBrokerMcpCallLog.js";
|
|
3
4
|
import { type EngineBrokerTurnAccounting, type EngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
|
|
4
5
|
/**
|
|
5
|
-
* Control protocol
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* turns sealed before the upgrade keep replaying.
|
|
6
|
+
* Control protocol v4 adds slot routing and reset. Both ends ship in the same
|
|
7
|
+
* package; v1/v2/v3 frames are refused on the wire. Durable terminal adapters
|
|
8
|
+
* retain those record formats. A missing slot is allowed only for a unique
|
|
9
|
+
* agent registration (unclocked production compatibility).
|
|
10
10
|
*/
|
|
11
|
-
declare const VERSION: "noopolis.daimon.engine-broker.
|
|
12
|
-
export declare const ENGINE_BROKER_VERSION: "noopolis.daimon.engine-broker.
|
|
11
|
+
declare const VERSION: "noopolis.daimon.engine-broker.v4";
|
|
12
|
+
export declare const ENGINE_BROKER_VERSION: "noopolis.daimon.engine-broker.v4";
|
|
13
13
|
declare const V1: "noopolis.daimon.engine-broker.v1";
|
|
14
14
|
export declare const ENGINE_BROKER_MAX_FRAME_BYTES = 1048576;
|
|
15
|
+
/** Version refusal is independent of the incompatible operation's schema. */
|
|
16
|
+
export type EngineBrokerProtocolDiagnostic = Readonly<{
|
|
17
|
+
kind: "protocol_mismatch";
|
|
18
|
+
receivedVersion: string;
|
|
19
|
+
expectedVersion: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class EngineBrokerProtocolMismatch extends TypeError {
|
|
22
|
+
readonly diagnostic: EngineBrokerProtocolDiagnostic;
|
|
23
|
+
constructor(received: unknown, expected?: unknown);
|
|
24
|
+
}
|
|
15
25
|
export type EngineBrokerRequest = Readonly<{
|
|
16
26
|
version: typeof VERSION;
|
|
17
27
|
kind: "health";
|
|
@@ -21,16 +31,23 @@ export type EngineBrokerRequest = Readonly<{
|
|
|
21
31
|
kind: "start_turn";
|
|
22
32
|
requestId: string;
|
|
23
33
|
turnId: string;
|
|
34
|
+
slot?: number;
|
|
24
35
|
agentId: string;
|
|
25
36
|
wakeId: string;
|
|
26
37
|
prompt: string;
|
|
27
38
|
mcpEndpoint: string;
|
|
28
39
|
limits?: EngineBrokerTurnLimitOverrides;
|
|
40
|
+
processClock?: string;
|
|
29
41
|
}> | Readonly<{
|
|
30
42
|
version: typeof VERSION;
|
|
31
43
|
kind: "cancel_turn";
|
|
32
44
|
requestId: string;
|
|
33
45
|
turnId: string;
|
|
46
|
+
}> | Readonly<{
|
|
47
|
+
version: typeof VERSION;
|
|
48
|
+
kind: "reset_slot";
|
|
49
|
+
requestId: string;
|
|
50
|
+
slot: number;
|
|
34
51
|
}> | EngineBrokerInferenceRequest;
|
|
35
52
|
/**
|
|
36
53
|
* `reason` is the worker's own last words (`engineBrokerNativeClient.ts`),
|
|
@@ -52,6 +69,11 @@ export interface EngineBrokerFailureDiagnostic {
|
|
|
52
69
|
startTicks: string;
|
|
53
70
|
}
|
|
54
71
|
export declare const ENGINE_BROKER_MAX_DIAGNOSTIC_REASON_BYTES = 768;
|
|
72
|
+
/** Operational state after sealing; never raw filesystem errors or worker text. */
|
|
73
|
+
export declare const ENGINE_BROKER_TASK_CLOCK_RESET_FAILED = "task clock reset failed; slot fenced until restart";
|
|
74
|
+
export type EngineBrokerCleanupObservation = Readonly<{
|
|
75
|
+
cleanupDiagnostic?: typeof ENGINE_BROKER_TASK_CLOCK_RESET_FAILED;
|
|
76
|
+
}>;
|
|
55
77
|
export type EngineBrokerResponse = Readonly<{
|
|
56
78
|
version: typeof VERSION;
|
|
57
79
|
kind: "ready";
|
|
@@ -77,7 +99,7 @@ export type EngineBrokerResponse = Readonly<{
|
|
|
77
99
|
workerPid: number;
|
|
78
100
|
workerUid: number;
|
|
79
101
|
workerStartTime: string;
|
|
80
|
-
}> & EngineBrokerTurnAccounting) | (Readonly<{
|
|
102
|
+
}> & EngineBrokerTurnAccounting & BrokerClockObservation & EngineBrokerCleanupObservation) | (Readonly<{
|
|
81
103
|
version: typeof VERSION;
|
|
82
104
|
kind: "failed";
|
|
83
105
|
requestId: string;
|
|
@@ -85,7 +107,12 @@ export type EngineBrokerResponse = Readonly<{
|
|
|
85
107
|
code: EngineBrokerFailureCode;
|
|
86
108
|
diagnostic?: EngineBrokerFailureDiagnostic;
|
|
87
109
|
mcpCalls?: EngineBrokerMcpCallObservation;
|
|
88
|
-
}> & EngineBrokerTurnAccounting) |
|
|
110
|
+
}> & EngineBrokerTurnAccounting & BrokerClockObservation & EngineBrokerCleanupObservation) | Readonly<{
|
|
111
|
+
version: typeof VERSION;
|
|
112
|
+
kind: "slot_reset";
|
|
113
|
+
requestId: string;
|
|
114
|
+
slot: number;
|
|
115
|
+
}> | EngineBrokerInferenceResponse;
|
|
89
116
|
/**
|
|
90
117
|
* The one name for a fenced credential realm. The turn's failure code, the
|
|
91
118
|
* proxy's refusal reason on a worker request, and the grant path's 401 body
|
|
@@ -125,7 +152,12 @@ export declare function parseEngineBrokerResponse(value: unknown): EngineBrokerR
|
|
|
125
152
|
* the wire.
|
|
126
153
|
*/
|
|
127
154
|
export declare function parseEngineBrokerV1TerminalResponse(value: unknown): EngineBrokerV1TerminalResponse;
|
|
128
|
-
export declare function
|
|
155
|
+
export declare function parseEngineBrokerSlot(value: unknown): number;
|
|
156
|
+
/** v3 survives only in durable records. */
|
|
157
|
+
export declare function parseEngineBrokerV3TerminalResponse(value: unknown): EngineBrokerTerminalResponse;
|
|
158
|
+
/** v2 survives only in durable records. The wire always refuses it. */
|
|
159
|
+
export declare function parseEngineBrokerV2TerminalResponse(value: unknown): EngineBrokerTerminalResponse;
|
|
160
|
+
export declare function encodeEngineBrokerFrame(value: EngineBrokerRequest | EngineBrokerResponse | EngineBrokerProtocolDiagnostic): Buffer;
|
|
129
161
|
export declare class EngineBrokerFrameDecoder {
|
|
130
162
|
private buffered;
|
|
131
163
|
push(chunk: Uint8Array): unknown[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineBrokerProtocol.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkJ,KAAK,4BAA4B,EAAE,KAAK,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAC3Q,OAAO,EAAmI,KAAK,8BAA8B,EAAiF,MAAM,6BAA6B,CAAC;AAClS,OAAO,EAAwE,KAAK,0BAA0B,EAAE,KAAK,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAE7L
|
|
1
|
+
{"version":3,"file":"engineBrokerProtocol.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEhG,OAAO,EAAkJ,KAAK,4BAA4B,EAAE,KAAK,6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,CACrC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,GAAG,8BAA8B,GACjF,MAAM,CAIR;AAED,qBAAa,wBAAwB;IACnC,OAAO,CAAC,QAAQ,CAAmB;IACnC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,EAAE;IAYlC,MAAM,IAAI,IAAI;CACf"}
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
+
import { parseBrokerProcessClock } from "./grokBrokerTaskClock.js";
|
|
2
|
+
import { parseGrokBrokerProviderClockObservation } from "./grokBrokerProviderClock.js";
|
|
1
3
|
import { isEngineBrokerInferenceRequestKind, isEngineBrokerInferenceResponseKind, parseEngineBrokerInferenceRequest, parseEngineBrokerInferenceResponse } from "./engineBrokerInferenceProtocol.js";
|
|
2
4
|
import { ENGINE_BROKER_MCP_CALL_NAME, ENGINE_BROKER_MCP_OUTSTANDING_MAX, ENGINE_BROKER_MCP_REFUSAL_REASONS, ENGINE_BROKER_MCP_TUNNEL_MAX } from "./engineBrokerMcpCallLog.js";
|
|
3
5
|
import { parseEngineBrokerTurnAccounting, parseEngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
|
|
4
6
|
/**
|
|
5
|
-
* Control protocol
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* turns sealed before the upgrade keep replaying.
|
|
7
|
+
* Control protocol v4 adds slot routing and reset. Both ends ship in the same
|
|
8
|
+
* package; v1/v2/v3 frames are refused on the wire. Durable terminal adapters
|
|
9
|
+
* retain those record formats. A missing slot is allowed only for a unique
|
|
10
|
+
* agent registration (unclocked production compatibility).
|
|
10
11
|
*/
|
|
11
|
-
const VERSION = "noopolis.daimon.engine-broker.
|
|
12
|
+
const VERSION = "noopolis.daimon.engine-broker.v4";
|
|
12
13
|
export const ENGINE_BROKER_VERSION = VERSION;
|
|
13
14
|
const V1 = "noopolis.daimon.engine-broker.v1";
|
|
14
15
|
export const ENGINE_BROKER_MAX_FRAME_BYTES = 1_048_576;
|
|
16
|
+
const PROTOCOL_NAME = /^noopolis\.daimon\.engine-broker\.v[0-9]{1,6}$/u;
|
|
17
|
+
const boundedProtocol = (value) => typeof value === "string" && PROTOCOL_NAME.test(value) ? value : "<invalid>";
|
|
18
|
+
export class EngineBrokerProtocolMismatch extends TypeError {
|
|
19
|
+
diagnostic;
|
|
20
|
+
constructor(received, expected = VERSION) {
|
|
21
|
+
const receivedVersion = boundedProtocol(received);
|
|
22
|
+
const expectedVersion = boundedProtocol(expected);
|
|
23
|
+
super(`invalid broker frame: protocol version mismatch (received ${receivedVersion}; expected ${expectedVersion})`);
|
|
24
|
+
this.diagnostic = { kind: "protocol_mismatch", receivedVersion, expectedVersion };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
const ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
16
28
|
export const ENGINE_BROKER_MAX_DIAGNOSTIC_REASON_BYTES = 768;
|
|
29
|
+
/** Operational state after sealing; never raw filesystem errors or worker text. */
|
|
30
|
+
export const ENGINE_BROKER_TASK_CLOCK_RESET_FAILED = "task clock reset failed; slot fenced until restart";
|
|
17
31
|
/**
|
|
18
32
|
* The one name for a fenced credential realm. The turn's failure code, the
|
|
19
33
|
* proxy's refusal reason on a worker request, and the grant path's 401 body
|
|
@@ -39,8 +53,11 @@ const text = (value, maxBytes) => {
|
|
|
39
53
|
};
|
|
40
54
|
const id = (value) => { const result = text(value, 128); if (!ID.test(result))
|
|
41
55
|
throw new TypeError("invalid broker frame"); return result; };
|
|
42
|
-
const version = (value) => {
|
|
43
|
-
|
|
56
|
+
const version = (value) => {
|
|
57
|
+
if (value !== VERSION)
|
|
58
|
+
throw new EngineBrokerProtocolMismatch(value);
|
|
59
|
+
return VERSION;
|
|
60
|
+
};
|
|
44
61
|
export function parseEngineBrokerRequest(value) {
|
|
45
62
|
const input = record(value);
|
|
46
63
|
version(input.version);
|
|
@@ -50,7 +67,16 @@ export function parseEngineBrokerRequest(value) {
|
|
|
50
67
|
}
|
|
51
68
|
if (input.kind === "start_turn") {
|
|
52
69
|
const fields = ["version", "kind", "requestId", "turnId", "agentId", "wakeId", "prompt", "mcpEndpoint"];
|
|
53
|
-
exact(input, input.
|
|
70
|
+
exact(input, [...fields, ...(input.slot === undefined ? [] : ["slot"]), ...(input.limits === undefined ? [] : ["limits"]), ...(input.processClock === undefined ? [] : ["processClock"])]);
|
|
71
|
+
let processClock;
|
|
72
|
+
if (input.processClock !== undefined) {
|
|
73
|
+
try {
|
|
74
|
+
processClock = parseBrokerProcessClock(input.processClock);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new TypeError("invalid broker frame");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
54
80
|
const mcpEndpoint = text(input.mcpEndpoint, 2048);
|
|
55
81
|
const url = new URL(mcpEndpoint);
|
|
56
82
|
if (url.protocol !== "http:" || url.hostname !== "127.0.0.1" || url.pathname !== "/mcp")
|
|
@@ -64,7 +90,11 @@ export function parseEngineBrokerRequest(value) {
|
|
|
64
90
|
throw new TypeError("invalid broker frame");
|
|
65
91
|
}
|
|
66
92
|
}
|
|
67
|
-
return { version: VERSION, kind: "start_turn", requestId: id(input.requestId), turnId: id(input.turnId), agentId: id(input.agentId), wakeId: id(input.wakeId), prompt: text(input.prompt, 65_536), mcpEndpoint, ...(limits === undefined ? {} : { limits }) };
|
|
93
|
+
return { version: VERSION, kind: "start_turn", ...(input.slot === undefined ? {} : { slot: parseEngineBrokerSlot(input.slot) }), requestId: id(input.requestId), turnId: id(input.turnId), agentId: id(input.agentId), wakeId: id(input.wakeId), prompt: text(input.prompt, 65_536), mcpEndpoint, ...(limits === undefined ? {} : { limits }), ...(processClock === undefined ? {} : { processClock }) };
|
|
94
|
+
}
|
|
95
|
+
if (input.kind === "reset_slot") {
|
|
96
|
+
exact(input, ["version", "kind", "requestId", "slot"]);
|
|
97
|
+
return { version: VERSION, kind: "reset_slot", requestId: id(input.requestId), slot: parseEngineBrokerSlot(input.slot) };
|
|
68
98
|
}
|
|
69
99
|
if (input.kind === "cancel_turn") {
|
|
70
100
|
exact(input, ["version", "kind", "requestId", "turnId"]);
|
|
@@ -76,6 +106,14 @@ export function parseEngineBrokerRequest(value) {
|
|
|
76
106
|
}
|
|
77
107
|
export function parseEngineBrokerResponse(value) {
|
|
78
108
|
const input = record(value);
|
|
109
|
+
if (input.kind === "protocol_mismatch") {
|
|
110
|
+
exact(input, ["kind", "receivedVersion", "expectedVersion"]);
|
|
111
|
+
for (const field of [input.receivedVersion, input.expectedVersion]) {
|
|
112
|
+
if (field !== "<invalid>" && boundedProtocol(field) !== field)
|
|
113
|
+
throw new TypeError("invalid broker frame");
|
|
114
|
+
}
|
|
115
|
+
throw new EngineBrokerProtocolMismatch(input.receivedVersion, input.expectedVersion);
|
|
116
|
+
}
|
|
79
117
|
version(input.version);
|
|
80
118
|
if (input.kind === "ready") {
|
|
81
119
|
exact(input, ["version", "kind", "requestId", "brokerUid", "providerProxyPort", "mcpFacadePort", "registrations", "credentialStale", "realmLease", "workerIsolation"]);
|
|
@@ -83,6 +121,10 @@ export function parseEngineBrokerResponse(value) {
|
|
|
83
121
|
throw new TypeError("invalid broker frame");
|
|
84
122
|
return { version: VERSION, kind: "ready", requestId: id(input.requestId), brokerUid: 2100, providerProxyPort: 43123, mcpFacadePort: 43124, registrations: input.registrations, credentialStale: false, realmLease: true, workerIsolation: true };
|
|
85
123
|
}
|
|
124
|
+
if (input.kind === "slot_reset") {
|
|
125
|
+
exact(input, ["version", "kind", "requestId", "slot"]);
|
|
126
|
+
return { version: VERSION, kind: "slot_reset", requestId: id(input.requestId), slot: parseEngineBrokerSlot(input.slot) };
|
|
127
|
+
}
|
|
86
128
|
if (input.kind === "accepted") {
|
|
87
129
|
exact(input, ["version", "kind", "requestId", "turnId"]);
|
|
88
130
|
return { version: VERSION, kind: "accepted", requestId: id(input.requestId), turnId: id(input.turnId) };
|
|
@@ -104,21 +146,62 @@ export function parseEngineBrokerV1TerminalResponse(value) {
|
|
|
104
146
|
throw new TypeError("invalid broker frame");
|
|
105
147
|
return parseTerminal(input, V1);
|
|
106
148
|
}
|
|
149
|
+
export function parseEngineBrokerSlot(value) {
|
|
150
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
151
|
+
throw new TypeError("invalid broker slot");
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
/** v3 survives only in durable records. */
|
|
155
|
+
export function parseEngineBrokerV3TerminalResponse(value) {
|
|
156
|
+
const input = record(value);
|
|
157
|
+
if (input.version !== "noopolis.daimon.engine-broker.v3" || (input.kind !== "completed" && input.kind !== "failed"))
|
|
158
|
+
throw new TypeError("invalid broker frame");
|
|
159
|
+
return parseTerminal({ ...input, version: VERSION }, VERSION);
|
|
160
|
+
}
|
|
161
|
+
/** v2 survives only in durable records. The wire always refuses it. */
|
|
162
|
+
export function parseEngineBrokerV2TerminalResponse(value) {
|
|
163
|
+
const input = record(value);
|
|
164
|
+
if (input.version !== "noopolis.daimon.engine-broker.v2" ||
|
|
165
|
+
(input.kind !== "completed" && input.kind !== "failed") ||
|
|
166
|
+
Object.hasOwn(input, "shellClock") || Object.hasOwn(input, "providerClock") ||
|
|
167
|
+
Object.hasOwn(input, "cleanupDiagnostic")) {
|
|
168
|
+
throw new TypeError("invalid broker frame");
|
|
169
|
+
}
|
|
170
|
+
return parseTerminal({ ...input, version: VERSION }, VERSION);
|
|
171
|
+
}
|
|
107
172
|
function parseTerminal(input, expected) {
|
|
108
173
|
const accounting = expected === VERSION ? ACCOUNTING : [];
|
|
174
|
+
const shellClock = input.shellClock;
|
|
175
|
+
if (shellClock !== undefined && (expected !== VERSION || !["task", "real", "gap"].includes(shellClock)))
|
|
176
|
+
throw new TypeError("invalid broker frame");
|
|
177
|
+
if (input.providerClock !== undefined && expected !== VERSION)
|
|
178
|
+
throw new TypeError("invalid broker frame");
|
|
179
|
+
const cleanupDiagnostic = input.cleanupDiagnostic;
|
|
180
|
+
if (cleanupDiagnostic !== undefined &&
|
|
181
|
+
(expected !== VERSION || cleanupDiagnostic !== ENGINE_BROKER_TASK_CLOCK_RESET_FAILED)) {
|
|
182
|
+
throw new TypeError("invalid broker frame");
|
|
183
|
+
}
|
|
184
|
+
const observation = {
|
|
185
|
+
...(cleanupDiagnostic === undefined ? {} : { cleanupDiagnostic }),
|
|
186
|
+
...(shellClock === undefined ? {} : { shellClock: shellClock }),
|
|
187
|
+
...(input.providerClock === undefined ? {} : {
|
|
188
|
+
providerClock: parseGrokBrokerProviderClockObservation(input.providerClock)
|
|
189
|
+
})
|
|
190
|
+
};
|
|
191
|
+
const clockFields = Object.keys(observation);
|
|
109
192
|
if (input.kind === "completed") {
|
|
110
|
-
exact(input, ["version", "kind", "requestId", "turnId", "text", "workerPid", "workerUid", "workerStartTime", ...accounting]);
|
|
193
|
+
exact(input, ["version", "kind", "requestId", "turnId", "text", "workerPid", "workerUid", "workerStartTime", ...accounting, ...clockFields]);
|
|
111
194
|
if (!Number.isSafeInteger(input.workerPid) || input.workerPid < 1 || !Number.isSafeInteger(input.workerUid) || input.workerUid < 1)
|
|
112
195
|
throw new TypeError("invalid broker frame");
|
|
113
196
|
const base = { kind: "completed", requestId: id(input.requestId), turnId: id(input.turnId), text: text(input.text, 262_144), workerPid: input.workerPid, workerUid: input.workerUid, workerStartTime: id(input.workerStartTime) };
|
|
114
|
-
return expected === VERSION ? { version: VERSION, ...base, ...parseEngineBrokerTurnAccounting(input, "completed") } : { version: V1, ...base };
|
|
197
|
+
return expected === VERSION ? { version: VERSION, ...base, ...observation, ...parseEngineBrokerTurnAccounting(input, "completed") } : { version: V1, ...base };
|
|
115
198
|
}
|
|
116
199
|
// `mcpCalls` is the broker's own observation of the worker's tool calls
|
|
117
200
|
// (`engineBrokerMcpCallLog.ts`), additive in v2 and never part of a v1
|
|
118
201
|
// record, which predates the instrument entirely.
|
|
119
202
|
if (expected === V1 && input.mcpCalls !== undefined)
|
|
120
203
|
throw new TypeError("invalid broker frame");
|
|
121
|
-
const fields = ["version", "kind", "requestId", "turnId", "code", ...accounting, ...(input.diagnostic === undefined ? [] : ["diagnostic"]), ...(input.mcpCalls === undefined ? [] : ["mcpCalls"])];
|
|
204
|
+
const fields = ["version", "kind", "requestId", "turnId", "code", ...accounting, ...clockFields, ...(input.diagnostic === undefined ? [] : ["diagnostic"]), ...(input.mcpCalls === undefined ? [] : ["mcpCalls"])];
|
|
122
205
|
exact(input, fields);
|
|
123
206
|
const codes = expected === VERSION ? ENGINE_BROKER_FAILURE_CODES : ENGINE_BROKER_FAILURE_CODES.filter((code) => code !== "limit_exceeded");
|
|
124
207
|
if (!codes.includes(input.code))
|
|
@@ -142,7 +225,7 @@ function parseTerminal(input, expected) {
|
|
|
142
225
|
if ((input.code === "limit_exceeded") !== (accountingValue.limitReason !== "none"))
|
|
143
226
|
throw new TypeError("invalid broker frame");
|
|
144
227
|
const mcpCalls = input.mcpCalls === undefined ? undefined : parseMcpCallObservation(input.mcpCalls);
|
|
145
|
-
return { version: VERSION, ...base, ...(mcpCalls === undefined ? {} : { mcpCalls }), ...accountingValue };
|
|
228
|
+
return { version: VERSION, ...base, ...observation, ...(mcpCalls === undefined ? {} : { mcpCalls }), ...accountingValue };
|
|
146
229
|
}
|
|
147
230
|
/**
|
|
148
231
|
* Names and timings, bounded, and internally consistent: a report can never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineBrokerSealLedger.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerSealLedger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,wBAAwB,EAAG,8BAAuC,CAAC;AAEhF,iFAAiF;AACjF,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAEX,qHAAqH;AACrH,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAIxF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,UAAU,4BAA4B,EAAE,OAAO,mBAAmB,KAAG,
|
|
1
|
+
{"version":3,"file":"engineBrokerSealLedger.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerSealLedger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,wBAAwB,EAAG,8BAAuC,CAAC;AAEhF,iFAAiF;AACjF,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAEX,qHAAqH;AACrH,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAIxF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,UAAU,4BAA4B,EAAE,OAAO,mBAAmB,KAAG,MAkExG,CAAC"}
|
|
@@ -74,6 +74,15 @@ export const renderBrokerTurnSealLine = (terminal, entry) => `${JSON.stringify({
|
|
|
74
74
|
requests: terminal.requests,
|
|
75
75
|
model: terminal.model,
|
|
76
76
|
limit_reason: terminal.limitReason,
|
|
77
|
+
...(terminal.shellClock === undefined ? {} : { shell_clock: terminal.shellClock }),
|
|
78
|
+
...(terminal.providerClock === undefined ? {} : { provider_clock: {
|
|
79
|
+
requests: terminal.providerClock.requests,
|
|
80
|
+
linesRewritten: terminal.providerClock.linesRewritten,
|
|
81
|
+
requestsWithoutDateLine: terminal.providerClock.requestsWithoutDateLine,
|
|
82
|
+
...(terminal.providerClock.linesIgnored === undefined ? {} : { linesIgnored: terminal.providerClock.linesIgnored }),
|
|
83
|
+
injectedDate: terminal.providerClock.injectedDate,
|
|
84
|
+
taskDate: terminal.providerClock.taskDate
|
|
85
|
+
} }),
|
|
77
86
|
...(terminal.kind === "failed" ? { code: terminal.code } : {}),
|
|
78
87
|
...(terminal.kind === "failed" && terminal.diagnostic !== undefined
|
|
79
88
|
? {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { type BrokerClockObservation } from "./grokBrokerTaskClock.js";
|
|
2
|
+
import { type Socket } from "node:net";
|
|
3
|
+
import { type EngineBrokerCleanupObservation } from "./engineBrokerProtocol.js";
|
|
1
4
|
import type { EngineBrokerTurnAccounting, EngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
|
|
2
5
|
import { type GrokInferenceGrantIssued, type GrokInferenceGrantRequest } from "./grokInferenceGrants.js";
|
|
3
6
|
export interface EngineBrokerServiceEngine {
|
|
4
|
-
turn(agentId: string, wakeId: string, prompt: string, mcpEndpoint: string, signal?: AbortSignal, limits?: EngineBrokerTurnLimitOverrides): Promise<Readonly<{
|
|
7
|
+
turn(agentId: string, wakeId: string, prompt: string, mcpEndpoint: string, signal?: AbortSignal, limits?: EngineBrokerTurnLimitOverrides, processClock?: string, slot?: number): Promise<Readonly<{
|
|
5
8
|
text: string;
|
|
6
9
|
workerPid: number;
|
|
7
10
|
workerUid: number;
|
|
8
11
|
workerStartTime: string;
|
|
9
|
-
}> & EngineBrokerTurnAccounting>;
|
|
12
|
+
}> & EngineBrokerTurnAccounting & BrokerClockObservation & EngineBrokerCleanupObservation>;
|
|
10
13
|
readiness(): Readonly<{
|
|
11
14
|
providerProxyPort: number;
|
|
12
15
|
mcpFacadePort: number;
|
|
@@ -16,6 +19,7 @@ export interface EngineBrokerServiceEngine {
|
|
|
16
19
|
workerIsolation: boolean;
|
|
17
20
|
}>;
|
|
18
21
|
close(): Promise<void>;
|
|
22
|
+
resetSlot?(slot: number): Promise<void>;
|
|
19
23
|
/** Evaluator inference grants; an engine without them refuses every grant request as `unavailable`. Refusals throw {@link GrokInferenceGrantRefused}. */
|
|
20
24
|
requestInferenceGrant?(request: GrokInferenceGrantRequest): GrokInferenceGrantIssued;
|
|
21
25
|
releaseInferenceGrant?(grantId: string): boolean;
|
|
@@ -34,4 +38,6 @@ export declare function startEngineBrokerServiceWithIdentity(broker: EngineBroke
|
|
|
34
38
|
socketPath: string;
|
|
35
39
|
};
|
|
36
40
|
}>;
|
|
41
|
+
/** @internal The production connection handler, also exercised over an in-memory transport. */
|
|
42
|
+
export declare function serveEngineBrokerConnection(socket: Socket, broker: EngineBrokerServiceEngine, active?: Map<string, AbortController>): void;
|
|
37
43
|
//# sourceMappingURL=engineBrokerService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineBrokerService.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engineBrokerService.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerService.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAE/F,OAAO,EAA6B,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAEqB,KAAK,8BAA8B,EAC9D,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAGlH,OAAO,EAA6B,KAAK,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACpI,MAAM,WAAW,yBAAyB;IACxC,IAAI,CACF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EACpE,MAAM,CAAC,EAAE,WA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1
2
|
import { chmod, lstat, unlink } from "node:fs/promises";
|
|
2
3
|
import { createServer } from "node:net";
|
|
3
|
-
import { encodeEngineBrokerFrame, EngineBrokerFrameDecoder, parseEngineBrokerRequest } from "./engineBrokerProtocol.js";
|
|
4
|
+
import { encodeEngineBrokerFrame, EngineBrokerFrameDecoder, EngineBrokerProtocolMismatch, parseEngineBrokerRequest } from "./engineBrokerProtocol.js";
|
|
4
5
|
import { EngineBrokerTurnFailure } from "./grokEngineBroker.js";
|
|
5
6
|
import { GROK_INFERENCE_PROXY_BASE_URL } from "./engineBrokerInferenceProtocol.js";
|
|
6
7
|
import { GrokInferenceGrantRefused } from "./grokInferenceGrants.js";
|
|
@@ -12,7 +13,11 @@ export async function startEngineBrokerServiceWithIdentity(broker, socketPath, e
|
|
|
12
13
|
throw new Error("engine broker service requires broker identity");
|
|
13
14
|
await removeOwnedSocket(socketPath, expectedUid);
|
|
14
15
|
const active = new Map(), connections = new Set();
|
|
15
|
-
const server = createServer((socket) => {
|
|
16
|
+
const server = createServer((socket) => {
|
|
17
|
+
connections.add(socket);
|
|
18
|
+
socket.once("close", () => connections.delete(socket));
|
|
19
|
+
serveEngineBrokerConnection(socket, broker, active);
|
|
20
|
+
});
|
|
16
21
|
await listen(server, socketPath);
|
|
17
22
|
try {
|
|
18
23
|
await chmod(socketPath, 0o600);
|
|
@@ -48,43 +53,88 @@ export async function startEngineBrokerServiceWithIdentity(broker, socketPath, e
|
|
|
48
53
|
* reader has disconnected.
|
|
49
54
|
*/
|
|
50
55
|
function handleSocketError(socket, owned) { socket.on("error", () => { owned()?.controller.abort(); socket.destroy(); }); }
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
/** @internal The production connection handler, also exercised over an in-memory transport. */
|
|
57
|
+
export function serveEngineBrokerConnection(socket, broker, active = new Map()) {
|
|
58
|
+
const decoder = new EngineBrokerFrameDecoder();
|
|
59
|
+
let started = false;
|
|
60
|
+
let owned;
|
|
61
|
+
handleSocketError(socket, () => owned);
|
|
62
|
+
socket.once("close", () => owned?.controller.abort());
|
|
63
|
+
socket.on("data", (chunk) => {
|
|
64
|
+
try {
|
|
65
|
+
for (const value of decoder.push(chunk)) {
|
|
66
|
+
const request = parseEngineBrokerRequest(value);
|
|
67
|
+
if (request.kind === "health") {
|
|
68
|
+
if (started)
|
|
69
|
+
throw new Error();
|
|
70
|
+
started = true;
|
|
71
|
+
const ready = broker.readiness();
|
|
72
|
+
if (ready.providerProxyPort !== 43123 || ready.mcpFacadePort !== 43124 ||
|
|
73
|
+
ready.registrations < 1 || ready.credentialStale || !ready.realmLease || !ready.workerIsolation) {
|
|
74
|
+
throw new Error();
|
|
75
|
+
}
|
|
76
|
+
return send(socket, {
|
|
77
|
+
version: request.version, kind: "ready", requestId: request.requestId, brokerUid: 2100,
|
|
78
|
+
providerProxyPort: 43123, mcpFacadePort: 43124, registrations: ready.registrations,
|
|
79
|
+
credentialStale: false, realmLease: true, workerIsolation: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (request.kind === "cancel_turn") {
|
|
83
|
+
if (owned?.turnId !== request.turnId)
|
|
84
|
+
throw new Error("turn not owned by connection");
|
|
85
|
+
owned.controller.abort();
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (request.kind === "request_inference_grant" || request.kind === "release_inference_grant") {
|
|
89
|
+
if (started)
|
|
90
|
+
throw new Error();
|
|
91
|
+
started = true;
|
|
92
|
+
serveInferenceGrant(socket, broker, request);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (request.kind === "reset_slot") {
|
|
96
|
+
if (started || broker.resetSlot === undefined)
|
|
97
|
+
throw new Error();
|
|
98
|
+
started = true;
|
|
99
|
+
void broker.resetSlot(request.slot).then(() => send(socket, {
|
|
100
|
+
version: request.version, kind: "slot_reset", requestId: request.requestId, slot: request.slot
|
|
101
|
+
}), () => socket.destroy());
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const key = `${request.slot ?? request.agentId}:${request.turnId}`;
|
|
105
|
+
if (started || active.has(key))
|
|
106
|
+
throw new Error();
|
|
107
|
+
started = true;
|
|
108
|
+
const controller = new AbortController();
|
|
109
|
+
owned = { turnId: request.turnId, controller };
|
|
110
|
+
active.set(key, controller);
|
|
111
|
+
socket.write(encodeEngineBrokerFrame({
|
|
112
|
+
version: request.version, kind: "accepted", requestId: request.requestId, turnId: request.turnId
|
|
113
|
+
}));
|
|
114
|
+
void broker.turn(request.agentId, request.wakeId, request.prompt, request.mcpEndpoint, controller.signal, request.limits, request.processClock, request.slot).then((result) => send(socket, {
|
|
115
|
+
version: request.version, kind: "completed", requestId: request.requestId, turnId: request.turnId,
|
|
116
|
+
text: result.text, ...brokerClockObservation(result.shellClock, result.providerClock),
|
|
117
|
+
...(result.cleanupDiagnostic === undefined ? {} : { cleanupDiagnostic: result.cleanupDiagnostic }),
|
|
118
|
+
workerPid: result.workerPid, workerUid: result.workerUid, workerStartTime: result.workerStartTime,
|
|
119
|
+
outcome: "completed", usage: result.usage, model: result.model, requests: result.requests, limitReason: "none"
|
|
120
|
+
}), (error) => failed(socket, request, error, controller.signal.aborted)).finally(() => {
|
|
121
|
+
if (active.get(key) === controller)
|
|
122
|
+
active.delete(key);
|
|
123
|
+
owned = undefined;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
62
126
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error instanceof EngineBrokerProtocolMismatch && !socket.writableEnded) {
|
|
129
|
+
// Flush one small, closed diagnostic before FIN; destroy would lose it.
|
|
130
|
+
socket.pause();
|
|
131
|
+
socket.end(encodeEngineBrokerFrame(error.diagnostic));
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
socket.destroy();
|
|
66
135
|
}
|
|
67
|
-
|
|
68
|
-
if (started)
|
|
69
|
-
throw new Error();
|
|
70
|
-
started = true;
|
|
71
|
-
serveInferenceGrant(socket, broker, request);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (started || active.has(request.turnId))
|
|
75
|
-
throw new Error();
|
|
76
|
-
started = true;
|
|
77
|
-
const controller = new AbortController();
|
|
78
|
-
owned = { turnId: request.turnId, controller };
|
|
79
|
-
active.set(request.turnId, controller);
|
|
80
|
-
socket.write(encodeEngineBrokerFrame({ version: request.version, kind: "accepted", requestId: request.requestId, turnId: request.turnId }));
|
|
81
|
-
void broker.turn(request.agentId, request.wakeId, request.prompt, request.mcpEndpoint, controller.signal, request.limits).then((result) => send(socket, { version: request.version, kind: "completed", requestId: request.requestId, turnId: request.turnId, text: result.text, workerPid: result.workerPid, workerUid: result.workerUid, workerStartTime: result.workerStartTime, outcome: "completed", usage: result.usage, model: result.model, requests: result.requests, limitReason: "none" }), (error) => failed(socket, request, error, controller.signal.aborted)).finally(() => { if (active.get(request.turnId) === controller)
|
|
82
|
-
active.delete(request.turnId); owned = undefined; });
|
|
83
|
-
}
|
|
136
|
+
});
|
|
84
137
|
}
|
|
85
|
-
catch {
|
|
86
|
-
socket.destroy();
|
|
87
|
-
} }); }
|
|
88
138
|
/**
|
|
89
139
|
* Every failure the broker raises for a known registration carries its
|
|
90
140
|
* accounting (a wake that tried to raise a limit: `usage: null`, zero
|
|
@@ -99,7 +149,15 @@ function failed(socket, request, error, aborted) {
|
|
|
99
149
|
return;
|
|
100
150
|
}
|
|
101
151
|
const code = error instanceof EngineBrokerTurnFailure ? error.code : aborted ? "cancelled" : "engine_failed";
|
|
102
|
-
send(socket, {
|
|
152
|
+
send(socket, {
|
|
153
|
+
version: request.version, kind: "failed", requestId: request.requestId, turnId: request.turnId, code,
|
|
154
|
+
...(error instanceof EngineBrokerTurnFailure ? brokerClockObservation(error.shellClock, error.providerClock) : {}),
|
|
155
|
+
...(error instanceof EngineBrokerTurnFailure && error.diagnostic ? { diagnostic: error.diagnostic } : {}),
|
|
156
|
+
...(error instanceof EngineBrokerTurnFailure && error.mcpCalls ? { mcpCalls: error.mcpCalls } : {}),
|
|
157
|
+
...(error instanceof EngineBrokerTurnFailure && error.cleanupDiagnostic ? { cleanupDiagnostic: error.cleanupDiagnostic } : {}),
|
|
158
|
+
outcome: "failed", usage: accounting.usage, model: accounting.model,
|
|
159
|
+
requests: accounting.requests, limitReason: accounting.limitReason
|
|
160
|
+
});
|
|
103
161
|
}
|
|
104
162
|
/** One grant verb per connection, answered and closed; any failure becomes a closed-code refusal and never touches turn state. */
|
|
105
163
|
function serveInferenceGrant(socket, broker, request) {
|
|
@@ -10,7 +10,7 @@ export async function runEngineBrokerServiceCli() {
|
|
|
10
10
|
if (process.getuid?.() !== 2100)
|
|
11
11
|
throw new Error("engine broker service requires broker identity");
|
|
12
12
|
const config = parseEngineBrokerServiceConfig(await readRootConfig(ENGINE_BROKER_SERVICE_CONFIG));
|
|
13
|
-
const broker = await startGrokEngineBroker({ grokCommand: "/usr/local/bin/grok", nativeClient: "/opt/daimon/bin/daimon-engine-broker", credentialHome: config.credentialHome, turnStore: config.turnStore, registrations: config.registrations, ...(config.inferenceLedgerPath === undefined ? {} : { inferenceLedgerPath: config.inferenceLedgerPath }) });
|
|
13
|
+
const broker = await startGrokEngineBroker({ grokCommand: "/usr/local/bin/grok", nativeClient: "/opt/daimon/bin/daimon-engine-broker", credentialHome: config.credentialHome, turnStore: config.turnStore, registrations: config.registrations, maxRunRequests: config.maxRunRequests, runRequestStore: config.runRequestStore, ...(config.inferenceLedgerPath === undefined ? {} : { inferenceLedgerPath: config.inferenceLedgerPath }) });
|
|
14
14
|
const service = await startEngineBrokerService(broker);
|
|
15
15
|
let stopping;
|
|
16
16
|
const stop = () => { stopping ??= service.close(); return stopping; };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type EngineBrokerTurnLimits } from "./engineBrokerTurnAccounting.js";
|
|
2
2
|
import { type GrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
3
3
|
export declare const ENGINE_BROKER_SERVICE_V1: "noopolis.daimon.engine-broker-service.v1";
|
|
4
|
+
export declare const ENGINE_BROKER_SERVICE_V3: "noopolis.daimon.engine-broker-service.v3";
|
|
4
5
|
export declare const ENGINE_BROKER_SERVICE_V2: "noopolis.daimon.engine-broker-service.v2";
|
|
5
6
|
/** One root-provisioned broker slot. Every field is fixed at provisioning time; a wake can only lower `limits`. */
|
|
6
7
|
export type EngineBrokerServiceRegistration = Readonly<{
|
|
@@ -28,6 +29,8 @@ export type EngineBrokerServiceConfig = Readonly<{
|
|
|
28
29
|
turnStore: string;
|
|
29
30
|
registrations: readonly EngineBrokerServiceRegistration[];
|
|
30
31
|
inferenceLedgerPath?: string;
|
|
32
|
+
maxRunRequests?: number;
|
|
33
|
+
runRequestStore?: string;
|
|
31
34
|
}>;
|
|
32
35
|
/** The per-request stream written beside a registration's usage ledger. */
|
|
33
36
|
export declare const engineBrokerRequestLedgerPathFor: (usageLedgerPath: string) => string;
|
|
@@ -40,6 +43,8 @@ export declare const engineBrokerSealLedgerPathFor: (usageLedgerPath: string) =>
|
|
|
40
43
|
/**
|
|
41
44
|
* Strict `service.json` parser.
|
|
42
45
|
*
|
|
46
|
+
* v3 retains seven-field registrations and binds slotPolicies by slot; agent IDs
|
|
47
|
+
* may repeat, while worker UIDs, slots and ledger streams must be distinct.
|
|
43
48
|
* v2 requires every registration to declare its usage ledger, limits and model
|
|
44
49
|
* (`model.id`/`model.reasoningEffort` from the closed lists); unknown keys at
|
|
45
50
|
* any level are refused. v1 is still accepted and receives today's defaults:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineBrokerServiceConfig.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerServiceConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgE,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC5I,OAAO,EAAuF,KAAK,qBAAqB,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