@noopolis/daimon 0.1.2 → 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 +275 -51
- package/dist/contracts/attentionContract.d.ts +142 -0
- package/dist/contracts/attentionContract.d.ts.map +1 -0
- package/dist/contracts/attentionContract.js +21 -0
- package/dist/contracts/canonicalJson.d.ts +3 -0
- package/dist/contracts/canonicalJson.d.ts.map +1 -0
- package/dist/contracts/canonicalJson.js +54 -0
- 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/grokWorkerContract.d.ts +74 -0
- package/dist/contracts/grokWorkerContract.d.ts.map +1 -0
- package/dist/contracts/grokWorkerContract.js +88 -0
- package/dist/contracts/organizationRuntimeContract.d.ts +841 -0
- package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
- package/dist/contracts/organizationRuntimeContract.js +123 -0
- package/dist/contracts/runtimeContractManifest.d.ts +1822 -0
- package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
- package/dist/contracts/runtimeContractManifest.js +206 -0
- 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/credentialRedaction.d.ts +4 -0
- package/dist/core/credentialRedaction.d.ts.map +1 -0
- package/dist/core/credentialRedaction.js +28 -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/mcp/toolServer.d.ts +19 -2
- package/dist/mcp/toolServer.d.ts.map +1 -1
- package/dist/mcp/toolServer.js +57 -17
- package/dist/observability/causalEvents.d.ts +6 -6
- package/dist/observability/causalEvents.d.ts.map +1 -1
- package/dist/observability/causalEvents.js +107 -19
- package/dist/observability/orgObserver.d.ts.map +1 -1
- package/dist/observability/orgObserver.js +3 -3
- package/dist/pi/agyHeadlessResult.d.ts +60 -0
- package/dist/pi/agyHeadlessResult.d.ts.map +1 -0
- package/dist/pi/agyHeadlessResult.js +95 -0
- package/dist/pi/cliChildOutput.d.ts +67 -0
- package/dist/pi/cliChildOutput.d.ts.map +1 -0
- package/dist/pi/cliChildOutput.js +269 -0
- package/dist/pi/cliEngineRun.d.ts +16 -0
- package/dist/pi/cliEngineRun.d.ts.map +1 -0
- package/dist/pi/cliEngineRun.js +27 -0
- package/dist/pi/cliEngineSpawn.d.ts +55 -0
- package/dist/pi/cliEngineSpawn.d.ts.map +1 -0
- package/dist/pi/cliEngineSpawn.js +169 -0
- package/dist/pi/cliEnvironment.d.ts +12 -0
- package/dist/pi/cliEnvironment.d.ts.map +1 -0
- package/dist/pi/cliEnvironment.js +34 -0
- package/dist/pi/cliMcpRegistration.d.ts +61 -0
- package/dist/pi/cliMcpRegistration.d.ts.map +1 -0
- package/dist/pi/cliMcpRegistration.js +75 -0
- package/dist/pi/cliProcess.d.ts +7 -0
- package/dist/pi/cliProcess.d.ts.map +1 -0
- package/dist/pi/cliProcess.js +132 -0
- package/dist/pi/cliSession.d.ts +86 -24
- package/dist/pi/cliSession.d.ts.map +1 -1
- package/dist/pi/cliSession.js +251 -173
- 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/cliTurnMetering.d.ts +60 -0
- package/dist/pi/cliTurnMetering.d.ts.map +1 -0
- package/dist/pi/cliTurnMetering.js +60 -0
- package/dist/pi/codexFilesystemRules.d.ts +3 -0
- package/dist/pi/codexFilesystemRules.d.ts.map +1 -0
- package/dist/pi/codexFilesystemRules.js +28 -0
- package/dist/pi/codexHeadlessResult.d.ts +68 -0
- package/dist/pi/codexHeadlessResult.d.ts.map +1 -0
- package/dist/pi/codexHeadlessResult.js +122 -0
- package/dist/pi/codexRolloutUsage.d.ts +95 -0
- package/dist/pi/codexRolloutUsage.d.ts.map +1 -0
- package/dist/pi/codexRolloutUsage.js +221 -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/engineWakeLimits.d.ts +39 -0
- package/dist/pi/engineWakeLimits.d.ts.map +1 -0
- package/dist/pi/engineWakeLimits.js +55 -0
- package/dist/pi/grokHeadlessResult.d.ts +36 -0
- package/dist/pi/grokHeadlessResult.d.ts.map +1 -0
- package/dist/pi/grokHeadlessResult.js +118 -0
- package/dist/pi/grokHomeMcpRegistration.d.ts +21 -0
- package/dist/pi/grokHomeMcpRegistration.d.ts.map +1 -0
- package/dist/pi/grokHomeMcpRegistration.js +58 -0
- package/dist/pi/grokSandbox.d.ts +11 -0
- package/dist/pi/grokSandbox.d.ts.map +1 -0
- package/dist/pi/grokSandbox.js +216 -0
- package/dist/pi/grokStreamUsage.d.ts +31 -0
- package/dist/pi/grokStreamUsage.d.ts.map +1 -0
- package/dist/pi/grokStreamUsage.js +51 -0
- 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 +6 -3
- package/dist/pi/piAgentHandle.d.ts.map +1 -1
- package/dist/pi/piAgentHandle.js +42 -12
- package/dist/pi/piAgentWakeSupport.d.ts +35 -0
- package/dist/pi/piAgentWakeSupport.d.ts.map +1 -1
- package/dist/pi/piAgentWakeSupport.js +4 -0
- package/dist/pi/piHarness.d.ts +18 -3
- package/dist/pi/piHarness.d.ts.map +1 -1
- package/dist/pi/piHarness.js +83 -14
- package/dist/pi/prompts.d.ts +1 -0
- package/dist/pi/prompts.d.ts.map +1 -1
- package/dist/pi/prompts.js +24 -0
- 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/turnTrace.d.ts.map +1 -1
- package/dist/pi/turnTrace.js +5 -8
- 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/pi/worldTrajectory.d.ts +1 -1
- package/dist/pi/worldTrajectory.d.ts.map +1 -1
- package/dist/pi/worldTrajectory.js +3 -3
- package/dist/runtime/agySubscriptionBootstrap.d.ts +16 -0
- package/dist/runtime/agySubscriptionBootstrap.d.ts.map +1 -0
- package/dist/runtime/agySubscriptionBootstrap.js +80 -0
- package/dist/runtime/agySubscriptionRealm.d.ts +38 -0
- package/dist/runtime/agySubscriptionRealm.d.ts.map +1 -0
- package/dist/runtime/agySubscriptionRealm.js +242 -0
- package/dist/runtime/attention.d.ts +26 -0
- package/dist/runtime/attention.d.ts.map +1 -0
- package/dist/runtime/attention.js +49 -0
- package/dist/runtime/attentionDispatcher.d.ts +78 -0
- package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
- package/dist/runtime/attentionDispatcher.js +365 -0
- package/dist/runtime/cli.d.ts +7 -0
- package/dist/runtime/cli.d.ts.map +1 -0
- package/dist/runtime/cli.js +256 -0
- package/dist/runtime/codexSandboxProjection.d.ts +17 -0
- package/dist/runtime/codexSandboxProjection.d.ts.map +1 -0
- package/dist/runtime/codexSandboxProjection.js +40 -0
- package/dist/runtime/contract-manifest.json +1 -0
- package/dist/runtime/contract-manifest.sha256 +1 -0
- package/dist/runtime/contractManifest.d.ts +8 -0
- package/dist/runtime/contractManifest.d.ts.map +1 -0
- package/dist/runtime/contractManifest.js +4 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts +40 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCapabilities.js +69 -0
- package/dist/runtime/engineBrokerControlClient.d.ts +55 -0
- package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
- package/dist/runtime/engineBrokerControlClient.js +228 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts +12 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCredentialJournal.js +26 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts +53 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts +171 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpCallLog.js +231 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts +59 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpFacade.js +346 -0
- package/dist/runtime/engineBrokerNativeClient.d.ts +52 -0
- package/dist/runtime/engineBrokerNativeClient.d.ts.map +1 -0
- package/dist/runtime/engineBrokerNativeClient.js +151 -0
- package/dist/runtime/engineBrokerProtocol.d.ts +167 -0
- package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerProtocol.js +357 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
- package/dist/runtime/engineBrokerSealLedger.js +132 -0
- package/dist/runtime/engineBrokerService.d.ts +43 -0
- package/dist/runtime/engineBrokerService.d.ts.map +1 -0
- package/dist/runtime/engineBrokerService.js +196 -0
- package/dist/runtime/engineBrokerServiceCli.d.ts +5 -0
- package/dist/runtime/engineBrokerServiceCli.d.ts.map +1 -0
- package/dist/runtime/engineBrokerServiceCli.js +32 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts +55 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
- package/dist/runtime/engineBrokerServiceConfig.js +130 -0
- package/dist/runtime/engineBrokerSingleflight.d.ts +13 -0
- package/dist/runtime/engineBrokerSingleflight.d.ts.map +1 -0
- package/dist/runtime/engineBrokerSingleflight.js +24 -0
- package/dist/runtime/engineBrokerTurnAccounting.d.ts +76 -0
- package/dist/runtime/engineBrokerTurnAccounting.d.ts.map +1 -0
- package/dist/runtime/engineBrokerTurnAccounting.js +108 -0
- package/dist/runtime/engineBrokerTurnRegistry.d.ts +57 -0
- package/dist/runtime/engineBrokerTurnRegistry.d.ts.map +1 -0
- package/dist/runtime/engineBrokerTurnRegistry.js +159 -0
- package/dist/runtime/engineDispatcher.d.ts +38 -0
- package/dist/runtime/engineDispatcher.d.ts.map +1 -0
- package/dist/runtime/engineDispatcher.js +228 -0
- package/dist/runtime/engineReadiness.d.ts +23 -0
- package/dist/runtime/engineReadiness.d.ts.map +1 -0
- package/dist/runtime/engineReadiness.js +222 -0
- package/dist/runtime/grokAuthenticationError.d.ts +8 -0
- package/dist/runtime/grokAuthenticationError.d.ts.map +1 -0
- package/dist/runtime/grokAuthenticationError.js +20 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts +23 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialAuthority.js +150 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts +6 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialReader.js +38 -0
- package/dist/runtime/grokBrokerModelPolicy.d.ts +23 -0
- package/dist/runtime/grokBrokerModelPolicy.d.ts.map +1 -0
- package/dist/runtime/grokBrokerModelPolicy.js +28 -0
- package/dist/runtime/grokBrokerProjection.d.ts +114 -0
- package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProjection.js +101 -0
- 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 +69 -0
- package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxy.js +326 -0
- 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 +30 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxyRequest.js +85 -0
- package/dist/runtime/grokBrokerRealmLease.d.ts +4 -0
- package/dist/runtime/grokBrokerRealmLease.d.ts.map +1 -0
- package/dist/runtime/grokBrokerRealmLease.js +33 -0
- package/dist/runtime/grokBrokerRefresh.d.ts +2 -0
- package/dist/runtime/grokBrokerRefresh.d.ts.map +1 -0
- package/dist/runtime/grokBrokerRefresh.js +15 -0
- 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 +180 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
- package/dist/runtime/grokBrokerTurnMeter.js +337 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts +89 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
- package/dist/runtime/grokBrokerWorkerConfig.js +154 -0
- package/dist/runtime/grokEngineBroker.d.ts +88 -0
- package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
- package/dist/runtime/grokEngineBroker.js +202 -0
- package/dist/runtime/grokEngineBrokerLedger.d.ts +52 -0
- package/dist/runtime/grokEngineBrokerLedger.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerLedger.js +114 -0
- package/dist/runtime/grokEngineBrokerMetering.d.ts +51 -0
- package/dist/runtime/grokEngineBrokerMetering.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerMetering.js +34 -0
- package/dist/runtime/grokEngineBrokerTurn.d.ts +82 -0
- package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerTurn.js +348 -0
- 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/grokInferenceClientConfig.d.ts +41 -0
- package/dist/runtime/grokInferenceClientConfig.d.ts.map +1 -0
- package/dist/runtime/grokInferenceClientConfig.js +62 -0
- package/dist/runtime/grokInferenceGrants.d.ts +77 -0
- package/dist/runtime/grokInferenceGrants.d.ts.map +1 -0
- package/dist/runtime/grokInferenceGrants.js +116 -0
- package/dist/runtime/grokInferenceProxy.d.ts +29 -0
- package/dist/runtime/grokInferenceProxy.d.ts.map +1 -0
- package/dist/runtime/grokInferenceProxy.js +85 -0
- package/dist/runtime/grokInferenceProxyRequest.d.ts +23 -0
- package/dist/runtime/grokInferenceProxyRequest.d.ts.map +1 -0
- package/dist/runtime/grokInferenceProxyRequest.js +63 -0
- package/dist/runtime/grokSlotPreflightReceipt.d.ts +70 -0
- package/dist/runtime/grokSlotPreflightReceipt.d.ts.map +1 -0
- package/dist/runtime/grokSlotPreflightReceipt.js +101 -0
- package/dist/runtime/grokSubscriptionRealm.d.ts +4 -0
- package/dist/runtime/grokSubscriptionRealm.d.ts.map +1 -0
- package/dist/runtime/grokSubscriptionRealm.js +435 -0
- package/dist/runtime/grokSubscriptionRealmTypes.d.ts +26 -0
- package/dist/runtime/grokSubscriptionRealmTypes.d.ts.map +1 -0
- package/dist/runtime/grokSubscriptionRealmTypes.js +1 -0
- package/dist/runtime/grokWorkerAttestation.d.ts +175 -0
- package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerAttestation.js +266 -0
- package/dist/runtime/grokWorkerDenyPlacement.d.ts +80 -0
- package/dist/runtime/grokWorkerDenyPlacement.d.ts.map +1 -0
- package/dist/runtime/grokWorkerDenyPlacement.js +128 -0
- package/dist/runtime/grokWorkerHomeAttestation.d.ts +32 -0
- package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerHomeAttestation.js +75 -0
- package/dist/runtime/grokWorkerSandboxProfile.d.ts +27 -0
- package/dist/runtime/grokWorkerSandboxProfile.d.ts.map +1 -0
- package/dist/runtime/grokWorkerSandboxProfile.js +44 -0
- package/dist/runtime/grokWorkerTmpAttestation.d.ts +55 -0
- package/dist/runtime/grokWorkerTmpAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerTmpAttestation.js +63 -0
- package/dist/runtime/index.d.ts +31 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/inferenceUsageLedger.d.ts +38 -0
- package/dist/runtime/inferenceUsageLedger.d.ts.map +1 -0
- package/dist/runtime/inferenceUsageLedger.js +53 -0
- package/dist/runtime/mcpToolResult.d.ts +127 -0
- package/dist/runtime/mcpToolResult.d.ts.map +1 -0
- package/dist/runtime/mcpToolResult.js +214 -0
- package/dist/runtime/moltnetMachineRead.d.ts +97 -0
- package/dist/runtime/moltnetMachineRead.d.ts.map +1 -0
- package/dist/runtime/moltnetMachineRead.js +183 -0
- package/dist/runtime/native/daimon-engine-broker +0 -0
- package/dist/runtime/organizationRuntime.d.ts +168 -0
- package/dist/runtime/organizationRuntime.d.ts.map +1 -0
- package/dist/runtime/organizationRuntime.js +3 -0
- 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 +51 -0
- package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeControl.js +283 -0
- package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
- package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeHost.js +368 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeParsing.js +373 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeReadiness.js +67 -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 +59 -0
- package/dist/runtime/physicalReadiness.d.ts.map +1 -0
- package/dist/runtime/physicalReadiness.js +176 -0
- package/dist/runtime/portableCredentialAuth.d.ts +6 -0
- package/dist/runtime/portableCredentialAuth.d.ts.map +1 -0
- package/dist/runtime/portableCredentialAuth.js +70 -0
- package/dist/runtime/portableCredentialMaterial.d.ts +8 -0
- package/dist/runtime/portableCredentialMaterial.d.ts.map +1 -0
- package/dist/runtime/portableCredentialMaterial.js +169 -0
- package/dist/runtime/productionAgentTools.d.ts +5 -0
- package/dist/runtime/productionAgentTools.d.ts.map +1 -0
- package/dist/runtime/productionAgentTools.js +336 -0
- 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/runtimeHomeLayout.d.ts +48 -0
- package/dist/runtime/runtimeHomeLayout.d.ts.map +1 -0
- package/dist/runtime/runtimeHomeLayout.js +84 -0
- package/dist/runtime/schedule.d.ts +40 -0
- package/dist/runtime/schedule.d.ts.map +1 -0
- package/dist/runtime/schedule.js +376 -0
- package/dist/runtime/storeCoordination.d.ts +33 -0
- package/dist/runtime/storeCoordination.d.ts.map +1 -0
- package/dist/runtime/storeCoordination.js +117 -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/toolResultSpill.d.ts +152 -0
- package/dist/runtime/toolResultSpill.d.ts.map +1 -0
- package/dist/runtime/toolResultSpill.js +351 -0
- package/dist/runtime/turnRequestLedger.d.ts +155 -0
- package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
- package/dist/runtime/turnRequestLedger.js +251 -0
- package/dist/runtime/turnUsageLedger.d.ts +143 -0
- package/dist/runtime/turnUsageLedger.d.ts.map +1 -0
- package/dist/runtime/turnUsageLedger.js +203 -0
- 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 +25 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.js +54 -0
- package/dist/runtime/wakeAcceptanceReconciliation.d.ts +211 -0
- package/dist/runtime/wakeAcceptanceReconciliation.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceReconciliation.js +289 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts +25 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRecord.js +58 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts +36 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRetention.js +38 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceStore.js +561 -0
- package/dist/runtime/wakeAcceptanceTypes.d.ts +179 -0
- package/dist/runtime/wakeAcceptanceTypes.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceTypes.js +95 -0
- package/dist/runtime/wakeFuse.d.ts +124 -0
- package/dist/runtime/wakeFuse.d.ts.map +1 -0
- package/dist/runtime/wakeFuse.js +466 -0
- 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 +22 -11
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
|
|
3
|
+
import { GROK_INFERENCE_PROXY_BASE_URL } from "./engineBrokerInferenceProtocol.js";
|
|
4
|
+
import { parseGrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
5
|
+
import { GROK_SESSION_TITLE_SINK_KEY, GROK_SESSION_TITLE_SINK_MODEL_ID, renderGrokLeanBaseConfig } from "./grokBrokerWorkerConfig.js";
|
|
6
|
+
const SPEC = GROK_ENGINE_BROKER.inferenceGrants.client;
|
|
7
|
+
/** The evaluator CLI's only model id: Paideia passes `--model daimon-inference-grok`, never a catalog id. */
|
|
8
|
+
export const GROK_INFERENCE_CLIENT_MODEL_ID = SPEC.modelId;
|
|
9
|
+
/** The environment variable the evaluator CLI reads its grant token from. */
|
|
10
|
+
export const GROK_INFERENCE_GRANT_ENV = SPEC.envKey;
|
|
11
|
+
/**
|
|
12
|
+
* `config.toml` bytes for an evaluator Grok CLI (Paideia judge or optimizer,
|
|
13
|
+
* uid 2000) that reaches the broker proxy through an inference grant.
|
|
14
|
+
*
|
|
15
|
+
* Paideia writes it into a private `GROK_HOME` (`0700`, uid 2000) and sets the
|
|
16
|
+
* grant token in `envKey`; the CLI never holds the broker credential. Grok
|
|
17
|
+
* 1.0.34 ignores `[auth_provider.*]` helpers for a custom model, so the token
|
|
18
|
+
* travels through `env_key` exactly as the worker's turn capability does.
|
|
19
|
+
*
|
|
20
|
+
* It mirrors the worker renderer's lean settings: every bundled skill
|
|
21
|
+
* disabled, workflows off, the per-call `session_title` request pointed at a
|
|
22
|
+
* hidden model with a placeholder key the proxy refuses before any credential
|
|
23
|
+
* read or upstream call, and the declared effort as the model's single
|
|
24
|
+
* effort. There is no MCP server. `max_retries = 0`: with the default, a
|
|
25
|
+
* refused request (HTTP 503) is retried with backoff past a 45 s bound
|
|
26
|
+
* (live stub capture), so a gate refusal would hang the judge until its own
|
|
27
|
+
* timeout; with it the CLI fails in ~0.35 s and the caller's routed retry
|
|
28
|
+
* policy decides. HTTP 401 is never retried either way. `baseUrl` is the `baseUrl` of the grant (the
|
|
29
|
+
* loopback provider proxy); the manifest pins the sha256 for the production
|
|
30
|
+
* proxy URL and {@link GROK_INFERENCE_GRANT_ENV}.
|
|
31
|
+
*
|
|
32
|
+
* Paideia must also accept the init frame this produces: `apiKeySource` is
|
|
33
|
+
* `"user"` (not `"oauth"`), with `tools: []` and `mcp_servers: []` (live
|
|
34
|
+
* stub capture with the Paideia judge argv).
|
|
35
|
+
*/
|
|
36
|
+
export function renderGrokInferenceClientConfig(input) {
|
|
37
|
+
let declared;
|
|
38
|
+
try {
|
|
39
|
+
declared = parseGrokBrokerModelPolicy({ model: input.model, reasoningEffort: input.reasoningEffort });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new TypeError("invalid Grok inference client configuration");
|
|
43
|
+
}
|
|
44
|
+
if (declared.model !== input.model || declared.reasoningEffort !== input.reasoningEffort)
|
|
45
|
+
throw new TypeError("invalid Grok inference client configuration");
|
|
46
|
+
if (typeof input.baseUrl !== "string" || !/^http:\/\/127\.0\.0\.1:([1-9][0-9]{0,4})\/v1$/u.test(input.baseUrl) || Number(input.baseUrl.slice(17, -3)) > 65_535)
|
|
47
|
+
throw new TypeError("invalid Grok inference client configuration");
|
|
48
|
+
if (typeof input.envKey !== "string" || !/^[A-Z][A-Z0-9_]{2,63}$/u.test(input.envKey))
|
|
49
|
+
throw new TypeError("invalid Grok inference client configuration");
|
|
50
|
+
const label = `${declared.reasoningEffort[0].toUpperCase()}${declared.reasoningEffort.slice(1)}`;
|
|
51
|
+
return [
|
|
52
|
+
renderGrokLeanBaseConfig(),
|
|
53
|
+
"[models]", `default = "${GROK_INFERENCE_CLIENT_MODEL_ID}"`, `default_reasoning_effort = "${declared.reasoningEffort}"`, `session_summary = "${GROK_SESSION_TITLE_SINK_MODEL_ID}"`, "",
|
|
54
|
+
`[model.${GROK_SESSION_TITLE_SINK_MODEL_ID}]`, 'model = "disabled"', `base_url = "${input.baseUrl}"`, `api_key = "${GROK_SESSION_TITLE_SINK_KEY}"`, "max_retries = 0", "hidden = true", "",
|
|
55
|
+
`[model.${GROK_INFERENCE_CLIENT_MODEL_ID}]`, `model = "${declared.model}"`, `base_url = "${input.baseUrl}"`, `env_key = "${input.envKey}"`,
|
|
56
|
+
'api_backend = "chat_completions"', "context_window = 131072", "supports_backend_search = false", "max_retries = 0", "",
|
|
57
|
+
`[[model.${GROK_INFERENCE_CLIENT_MODEL_ID}.reasoning_efforts]]`, `value = "${declared.reasoningEffort}"`, `label = "${label}"`, "default = true", ""
|
|
58
|
+
].join("\n");
|
|
59
|
+
}
|
|
60
|
+
export const grokInferenceClientConfigSha256 = (input) => createHash("sha256").update(renderGrokInferenceClientConfig(input)).digest("hex");
|
|
61
|
+
/** The production bytes for a declared model/effort: the grant's proxy URL and the canonical env key. */
|
|
62
|
+
export const renderProductionGrokInferenceClientConfig = (policy) => renderGrokInferenceClientConfig({ baseUrl: GROK_INFERENCE_PROXY_BASE_URL, model: policy.model, reasoningEffort: policy.reasoningEffort, envKey: GROK_INFERENCE_GRANT_ENV });
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { EngineBrokerInferenceFailureCode } from "./engineBrokerInferenceProtocol.js";
|
|
2
|
+
import type { EngineBrokerTurnLimits, EngineBrokerTurnUsage } from "./engineBrokerTurnAccounting.js";
|
|
3
|
+
import { type GrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
4
|
+
import { GrokBrokerTurnMeter } from "./grokBrokerTurnMeter.js";
|
|
5
|
+
import { type GrokInferencePurpose, type InferenceUsageEntry } from "./inferenceUsageLedger.js";
|
|
6
|
+
/** One live evaluator grant as the proxy sees it. */
|
|
7
|
+
export type GrokInferenceGrant = Readonly<{
|
|
8
|
+
grantId: string;
|
|
9
|
+
purpose: GrokInferencePurpose;
|
|
10
|
+
policy: GrokBrokerModelPolicy;
|
|
11
|
+
expiresAt: number;
|
|
12
|
+
meter: GrokBrokerTurnMeter;
|
|
13
|
+
}>;
|
|
14
|
+
export type GrokInferenceGrantIssued = Readonly<{
|
|
15
|
+
grantId: string;
|
|
16
|
+
token: string;
|
|
17
|
+
purpose: GrokInferencePurpose;
|
|
18
|
+
policy: GrokBrokerModelPolicy;
|
|
19
|
+
expiresAt: number;
|
|
20
|
+
limits: EngineBrokerTurnLimits;
|
|
21
|
+
}>;
|
|
22
|
+
export type GrokInferenceGrantRequest = Readonly<{
|
|
23
|
+
model: unknown;
|
|
24
|
+
reasoningEffort: unknown;
|
|
25
|
+
purpose: unknown;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class GrokInferenceGrantRefused extends Error {
|
|
28
|
+
readonly code: EngineBrokerInferenceFailureCode;
|
|
29
|
+
constructor(code: EngineBrokerInferenceFailureCode);
|
|
30
|
+
}
|
|
31
|
+
export type GrokInferenceGrantsOptions = Readonly<{
|
|
32
|
+
now?: () => number;
|
|
33
|
+
/** Test seam: a fixed grant id proves grants never share a key space with turn capabilities. */
|
|
34
|
+
grantId?: () => string;
|
|
35
|
+
onSettled?: (entry: InferenceUsageEntry) => void;
|
|
36
|
+
ttlMs?: number;
|
|
37
|
+
maxLiveGrants?: number;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Evaluator inference grants: a distinct kind beside subject turn capabilities.
|
|
41
|
+
*
|
|
42
|
+
* Grants live in their own map keyed by a random grant id; turn capabilities
|
|
43
|
+
* (`engineBrokerCapabilities.ts`) are keyed by turn id and never consulted
|
|
44
|
+
* here, and grant tokens carry `inference_` so the proxy routes a bearer to
|
|
45
|
+
* exactly one of the two lookups. A grant has no worker isolation guard (it is
|
|
46
|
+
* issued only to the organization uid, the trusted evaluator side), but it
|
|
47
|
+
* carries the same spend gate as a subject turn: a {@link GrokBrokerTurnMeter}
|
|
48
|
+
* with one request in flight, the request ceiling, the between-requests token
|
|
49
|
+
* ceiling and the estimate for a response without usage. Its lifetime is the
|
|
50
|
+
* meter's time limit: past `expiresAt` it is gone from the map, and a request
|
|
51
|
+
* still in flight at expiry is aborted.
|
|
52
|
+
*
|
|
53
|
+
* At most `maxLiveGrants` grants exist at once; a caller frees a slot early
|
|
54
|
+
* with {@link release}. Nothing here is durable — a broker restart drops every
|
|
55
|
+
* grant, and callers request a new one.
|
|
56
|
+
*/
|
|
57
|
+
export declare class GrokInferenceGrants {
|
|
58
|
+
private readonly options;
|
|
59
|
+
private readonly grants;
|
|
60
|
+
private readonly now;
|
|
61
|
+
private readonly ttlMs;
|
|
62
|
+
private readonly maxLive;
|
|
63
|
+
constructor(options?: GrokInferenceGrantsOptions);
|
|
64
|
+
issue(request: GrokInferenceGrantRequest): GrokInferenceGrantIssued;
|
|
65
|
+
/** The live, unexpired grant a bearer names, or `undefined`. Never counts a request. */
|
|
66
|
+
authorize(token: string): GrokInferenceGrant | undefined;
|
|
67
|
+
/** Records one admitted request's end on the grant's meter and emits its ledger row. */
|
|
68
|
+
settle(grant: GrokInferenceGrant, index: number, usage: EngineBrokerTurnUsage | undefined, requestBytes: number): void;
|
|
69
|
+
/** Revokes a grant and aborts its in-flight request. Returns whether it was live. */
|
|
70
|
+
release(grantId: string): boolean;
|
|
71
|
+
live(): number;
|
|
72
|
+
close(): void;
|
|
73
|
+
private prune;
|
|
74
|
+
}
|
|
75
|
+
/** The broker's grants: every settled request is appended to the evaluator inference ledger and nowhere else. */
|
|
76
|
+
export declare const createLedgeredGrokInferenceGrants: (inferenceLedgerPath: string) => GrokInferenceGrants;
|
|
77
|
+
//# sourceMappingURL=grokInferenceGrants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokInferenceGrants.d.ts","sourceRoot":"","sources":["../../src/runtime/grokInferenceGrants.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAC3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAA8B,KAAK,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAiD,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAI/I,qDAAqD;AACrD,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,qBAAqB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAC5K,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,qBAAqB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC,CAAC;AACrM,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEjH,qBAAa,yBAA0B,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,gCAAgC;gBAAtC,IAAI,EAAE,gCAAgC;CAC5D;AAGD,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC;IAChD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,gGAAgG;IAChG,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,mBAAmB;IAKlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBACJ,OAAO,GAAE,0BAA+B;IAOrE,KAAK,CAAC,OAAO,EAAE,yBAAyB,GAAG,wBAAwB;IAiBnE,wFAAwF;IACxF,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAQxD,wFAAwF;IACxF,MAAM,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAStH,qFAAqF;IACrF,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOjC,IAAI,IAAI,MAAM;IAEd,KAAK,IAAI,IAAI;IAEb,OAAO,CAAC,KAAK;CAId;AAED,iHAAiH;AACjH,eAAO,MAAM,iCAAiC,GAAI,qBAAqB,MAAM,KAAG,mBAC+B,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
|
|
3
|
+
import { parseGrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
4
|
+
import { GrokBrokerTurnMeter } from "./grokBrokerTurnMeter.js";
|
|
5
|
+
import { GROK_INFERENCE_PURPOSES, recordInferenceUsage } from "./inferenceUsageLedger.js";
|
|
6
|
+
const SPEC = GROK_ENGINE_BROKER.inferenceGrants;
|
|
7
|
+
export class GrokInferenceGrantRefused extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code) {
|
|
10
|
+
super(`inference grant refused (${code})`);
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Evaluator inference grants: a distinct kind beside subject turn capabilities.
|
|
16
|
+
*
|
|
17
|
+
* Grants live in their own map keyed by a random grant id; turn capabilities
|
|
18
|
+
* (`engineBrokerCapabilities.ts`) are keyed by turn id and never consulted
|
|
19
|
+
* here, and grant tokens carry `inference_` so the proxy routes a bearer to
|
|
20
|
+
* exactly one of the two lookups. A grant has no worker isolation guard (it is
|
|
21
|
+
* issued only to the organization uid, the trusted evaluator side), but it
|
|
22
|
+
* carries the same spend gate as a subject turn: a {@link GrokBrokerTurnMeter}
|
|
23
|
+
* with one request in flight, the request ceiling, the between-requests token
|
|
24
|
+
* ceiling and the estimate for a response without usage. Its lifetime is the
|
|
25
|
+
* meter's time limit: past `expiresAt` it is gone from the map, and a request
|
|
26
|
+
* still in flight at expiry is aborted.
|
|
27
|
+
*
|
|
28
|
+
* At most `maxLiveGrants` grants exist at once; a caller frees a slot early
|
|
29
|
+
* with {@link release}. Nothing here is durable — a broker restart drops every
|
|
30
|
+
* grant, and callers request a new one.
|
|
31
|
+
*/
|
|
32
|
+
export class GrokInferenceGrants {
|
|
33
|
+
options;
|
|
34
|
+
grants = new Map();
|
|
35
|
+
now;
|
|
36
|
+
ttlMs;
|
|
37
|
+
maxLive;
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
this.options = options;
|
|
40
|
+
this.now = options.now ?? Date.now;
|
|
41
|
+
this.ttlMs = options.ttlMs ?? SPEC.ttlMs;
|
|
42
|
+
this.maxLive = options.maxLiveGrants ?? SPEC.maxLiveGrants;
|
|
43
|
+
if (!Number.isSafeInteger(this.ttlMs) || this.ttlMs < 1 || this.ttlMs > SPEC.ttlMs || !Number.isSafeInteger(this.maxLive) || this.maxLive < 1 || this.maxLive > SPEC.maxLiveGrants)
|
|
44
|
+
throw new TypeError("invalid inference grant policy");
|
|
45
|
+
}
|
|
46
|
+
issue(request) {
|
|
47
|
+
let policy;
|
|
48
|
+
try {
|
|
49
|
+
policy = parseGrokBrokerModelPolicy({ model: request.model, reasoningEffort: request.reasoningEffort });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new GrokInferenceGrantRefused("invalid_request");
|
|
53
|
+
}
|
|
54
|
+
// Nothing is defaulted: the model parser fills an absent member, a grant must name both.
|
|
55
|
+
if (request.model !== policy.model || request.reasoningEffort !== policy.reasoningEffort || !GROK_INFERENCE_PURPOSES.includes(request.purpose))
|
|
56
|
+
throw new GrokInferenceGrantRefused("invalid_request");
|
|
57
|
+
this.prune();
|
|
58
|
+
if (this.grants.size >= this.maxLive)
|
|
59
|
+
throw new GrokInferenceGrantRefused("grant_limit");
|
|
60
|
+
const grantId = this.options.grantId?.() ?? randomBytes(16).toString("hex");
|
|
61
|
+
if (!/^[a-f0-9]{32}$/u.test(grantId) || this.grants.has(grantId))
|
|
62
|
+
throw new GrokInferenceGrantRefused("grant_limit");
|
|
63
|
+
const limits = Object.freeze({ maxRequests: SPEC.limits.maxRequests, maxTokens: SPEC.limits.maxTokens, timeoutMs: this.ttlMs });
|
|
64
|
+
const token = `${SPEC.tokenPrefix}${randomBytes(32).toString("base64url")}`;
|
|
65
|
+
const grant = Object.freeze({ grantId, purpose: request.purpose, policy, expiresAt: this.now() + this.ttlMs, meter: new GrokBrokerTurnMeter(limits, () => undefined, this.now) });
|
|
66
|
+
const timer = setTimeout(() => this.release(grantId), this.ttlMs);
|
|
67
|
+
timer.unref?.();
|
|
68
|
+
this.grants.set(grantId, { grant, digest: digest(token), timer });
|
|
69
|
+
return Object.freeze({ grantId, token, purpose: grant.purpose, policy, expiresAt: grant.expiresAt, limits });
|
|
70
|
+
}
|
|
71
|
+
/** The live, unexpired grant a bearer names, or `undefined`. Never counts a request. */
|
|
72
|
+
authorize(token) {
|
|
73
|
+
if (!token.startsWith(SPEC.tokenPrefix))
|
|
74
|
+
return undefined;
|
|
75
|
+
this.prune();
|
|
76
|
+
const candidate = digest(token);
|
|
77
|
+
for (const entry of this.grants.values())
|
|
78
|
+
if (timingSafeEqual(entry.digest, candidate))
|
|
79
|
+
return entry.grant;
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/** Records one admitted request's end on the grant's meter and emits its ledger row. */
|
|
83
|
+
settle(grant, index, usage, requestBytes) {
|
|
84
|
+
const before = grant.meter.snapshot().timings[index];
|
|
85
|
+
if (before === undefined || before.endedAt !== undefined)
|
|
86
|
+
return;
|
|
87
|
+
grant.meter.settle(index, usage, requestBytes);
|
|
88
|
+
const timing = grant.meter.snapshot().timings[index];
|
|
89
|
+
if (timing?.usage === undefined || timing.endedAt === undefined)
|
|
90
|
+
return;
|
|
91
|
+
this.options.onSettled?.({ grant: grant.grantId, purpose: grant.purpose, model: grant.policy.model, request: index, usage: timing.usage, usageSource: timing.estimated === true ? "estimated" : "upstream", startedAt: timing.startedAt, endedAt: timing.endedAt });
|
|
92
|
+
}
|
|
93
|
+
/** Revokes a grant and aborts its in-flight request. Returns whether it was live. */
|
|
94
|
+
release(grantId) {
|
|
95
|
+
const entry = this.grants.get(grantId);
|
|
96
|
+
if (entry === undefined)
|
|
97
|
+
return false;
|
|
98
|
+
clearTimeout(entry.timer);
|
|
99
|
+
entry.grant.meter.trip("timeout");
|
|
100
|
+
entry.digest.fill(0);
|
|
101
|
+
this.grants.delete(grantId);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
live() { this.prune(); return this.grants.size; }
|
|
105
|
+
close() { for (const grantId of [...this.grants.keys()])
|
|
106
|
+
this.release(grantId); }
|
|
107
|
+
prune() {
|
|
108
|
+
const now = this.now();
|
|
109
|
+
for (const [grantId, entry] of this.grants)
|
|
110
|
+
if (entry.grant.expiresAt <= now)
|
|
111
|
+
this.release(grantId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** The broker's grants: every settled request is appended to the evaluator inference ledger and nowhere else. */
|
|
115
|
+
export const createLedgeredGrokInferenceGrants = (inferenceLedgerPath) => new GrokInferenceGrants({ onSettled: (entry) => { void recordInferenceUsage(inferenceLedgerPath, entry); } });
|
|
116
|
+
const digest = (value) => createHash("sha256").update(value).digest();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
import type { GrokBrokerCredentialAuthority, GrokBrokerUpstream } from "./grokBrokerProxy.js";
|
|
3
|
+
import type { GrokInferenceGrants } from "./grokInferenceGrants.js";
|
|
4
|
+
export type GrokInferenceProxyInput = Readonly<{
|
|
5
|
+
method: string;
|
|
6
|
+
pathname: string;
|
|
7
|
+
headers: Readonly<Record<string, string | undefined>>;
|
|
8
|
+
body: Buffer;
|
|
9
|
+
token: string;
|
|
10
|
+
}>;
|
|
11
|
+
/** HTTP 401 with a fixed code: the broker realm is stale, distinct from a generic 503 broker failure. */
|
|
12
|
+
export declare const GROK_INFERENCE_AUTH_STALE_BODY = "{\"error\":\"auth_stale\"}";
|
|
13
|
+
/**
|
|
14
|
+
* Serves one evaluator grant request; never throws.
|
|
15
|
+
*
|
|
16
|
+
* Order mirrors the subject path: the body is proven a grant-shaped request
|
|
17
|
+
* (declared model/effort, no tools) before the credential is read, the grant
|
|
18
|
+
* meter admits it before any upstream call, and exactly one ledger row is
|
|
19
|
+
* written once an admitted request settles. No worker isolation guard applies:
|
|
20
|
+
* grants are issued only to the organization uid.
|
|
21
|
+
*
|
|
22
|
+
* Stale realm: the grant shares the subject's credential authority, so a
|
|
23
|
+
* stale realm fails judges and subject turns alike (accepted shared fate). A
|
|
24
|
+
* grant request that finds the realm stale — before the upstream call or
|
|
25
|
+
* after a rejected refresh — is answered 401 `{"error":"auth_stale"}`, never
|
|
26
|
+
* the generic 503, so the evaluator can report it as a credential failure.
|
|
27
|
+
*/
|
|
28
|
+
export declare function serveGrokInferenceGrant(input: GrokInferenceProxyInput, response: ServerResponse, grants: GrokInferenceGrants, authority: GrokBrokerCredentialAuthority, upstream: GrokBrokerUpstream): Promise<void>;
|
|
29
|
+
//# sourceMappingURL=grokInferenceProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokInferenceProxy.d.ts","sourceRoot":"","sources":["../../src/runtime/grokInferenceProxy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,KAAK,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAGpE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEzK,yGAAyG;AACzG,eAAO,MAAM,8BAA8B,+BAA2B,CAAC;AAEvE;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,6BAA6B,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1N"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { GrokBrokerRunLimit } from "./grokBrokerRunBudget.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { GrokBrokerProxyRefusal } from "./grokBrokerProxy.js";
|
|
4
|
+
import { parseGrokUpstreamUsage } from "./grokBrokerTurnMeter.js";
|
|
5
|
+
import { authorizeGrokInferenceProxyRequest } from "./grokInferenceProxyRequest.js";
|
|
6
|
+
/** HTTP 401 with a fixed code: the broker realm is stale, distinct from a generic 503 broker failure. */
|
|
7
|
+
export const GROK_INFERENCE_AUTH_STALE_BODY = '{"error":"auth_stale"}';
|
|
8
|
+
/**
|
|
9
|
+
* Serves one evaluator grant request; never throws.
|
|
10
|
+
*
|
|
11
|
+
* Order mirrors the subject path: the body is proven a grant-shaped request
|
|
12
|
+
* (declared model/effort, no tools) before the credential is read, the grant
|
|
13
|
+
* meter admits it before any upstream call, and exactly one ledger row is
|
|
14
|
+
* written once an admitted request settles. No worker isolation guard applies:
|
|
15
|
+
* grants are issued only to the organization uid.
|
|
16
|
+
*
|
|
17
|
+
* Stale realm: the grant shares the subject's credential authority, so a
|
|
18
|
+
* stale realm fails judges and subject turns alike (accepted shared fate). A
|
|
19
|
+
* grant request that finds the realm stale — before the upstream call or
|
|
20
|
+
* after a rejected refresh — is answered 401 `{"error":"auth_stale"}`, never
|
|
21
|
+
* the generic 503, so the evaluator can report it as a credential failure.
|
|
22
|
+
*/
|
|
23
|
+
export async function serveGrokInferenceGrant(input, response, grants, authority, upstream) {
|
|
24
|
+
let settle;
|
|
25
|
+
try {
|
|
26
|
+
const grant = grants.authorize(input.token);
|
|
27
|
+
if (grant === undefined)
|
|
28
|
+
throw new GrokBrokerProxyRefusal("unknown_or_expired_grant");
|
|
29
|
+
let prepared;
|
|
30
|
+
try {
|
|
31
|
+
prepared = authorizeGrokInferenceProxyRequest(input, "pending", grant.policy);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw new GrokBrokerProxyRefusal("request_body_rejected");
|
|
35
|
+
}
|
|
36
|
+
let token = await authority.accessToken(false);
|
|
37
|
+
const rejectedDigest = createHash("sha256").update(token).digest("hex");
|
|
38
|
+
prepared = withBearer(prepared, token);
|
|
39
|
+
token = "";
|
|
40
|
+
const admission = grant.meter.admit();
|
|
41
|
+
if ("refused" in admission)
|
|
42
|
+
return json(response, 429, JSON.stringify({ error: "grant limit reached", limit: admission.refused }));
|
|
43
|
+
if ("busy" in admission)
|
|
44
|
+
return json(response, 429, '{"error":"grant request in flight"}');
|
|
45
|
+
settle = (usage) => { settle = undefined; grants.settle(grant, admission.index, usage, input.body.byteLength); };
|
|
46
|
+
let result = await upstream(prepared, admission.signal);
|
|
47
|
+
if (result.status === 401) {
|
|
48
|
+
token = authority.refreshAfterRejection ? await authority.refreshAfterRejection(rejectedDigest) : await authority.accessToken(true);
|
|
49
|
+
const refreshedDigest = createHash("sha256").update(token).digest("hex");
|
|
50
|
+
prepared = withBearer(prepared, token);
|
|
51
|
+
token = "";
|
|
52
|
+
result = await upstream(prepared, admission.signal);
|
|
53
|
+
if (result.status === 401)
|
|
54
|
+
await authority.markRejected(refreshedDigest);
|
|
55
|
+
}
|
|
56
|
+
settle?.(parseGrokUpstreamUsage(result.body, result.headers["content-type"]));
|
|
57
|
+
json(response, result.status, result.body, result.headers["content-type"]);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
settle?.(undefined);
|
|
61
|
+
if (error instanceof GrokBrokerRunLimit)
|
|
62
|
+
return json(response, 429, '{"error":"run_request_limit"}');
|
|
63
|
+
// Same rule as the subject path: a policy miss is non-retryable (400), because a
|
|
64
|
+
// retryable 503 makes the client re-send a request the broker will never accept,
|
|
65
|
+
// charging estimated usage for every attempt. 503 stays for transient faults only.
|
|
66
|
+
process.stderr.write(`[grok-proxy] inference refused: ${error instanceof GrokBrokerProxyRefusal ? error.reason : "broker_unavailable"}\n`);
|
|
67
|
+
if (authority.isStale?.() === true)
|
|
68
|
+
json(response, 401, GROK_INFERENCE_AUTH_STALE_BODY);
|
|
69
|
+
else if (error instanceof GrokBrokerProxyRefusal)
|
|
70
|
+
json(response, 400, JSON.stringify({ error: "broker refused this request", reason: error.reason }));
|
|
71
|
+
else
|
|
72
|
+
json(response, 503, '{"error":"broker unavailable"}');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const withBearer = (prepared, token) => {
|
|
76
|
+
if (!token || /[\r\n]/u.test(token))
|
|
77
|
+
throw new Error("broker credential authority unavailable");
|
|
78
|
+
return { ...prepared, headers: { ...prepared.headers, authorization: `Bearer ${token}` } };
|
|
79
|
+
};
|
|
80
|
+
function json(response, status, body, contentType = "application/json") {
|
|
81
|
+
if (response.headersSent)
|
|
82
|
+
return;
|
|
83
|
+
response.writeHead(status, { "content-type": contentType, "cache-control": "no-store" });
|
|
84
|
+
response.end(body);
|
|
85
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GrokBrokerProxyInput, GrokBrokerUpstreamRequest } from "./grokBrokerProxyRequest.js";
|
|
2
|
+
import { type GrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
3
|
+
/**
|
|
4
|
+
* Authorizes one evaluator grant request body and rebuilds it for the provider.
|
|
5
|
+
*
|
|
6
|
+
* The accepted shape is exactly what Grok CLI 1.0.34 sends for a Paideia
|
|
7
|
+
* judge/optimizer call (`--tools read_file --disallowed-tools
|
|
8
|
+
* read_file,search_tool,use_tool --max-turns 1`, with and without
|
|
9
|
+
* `--system-prompt-override` and `--json-schema`; live stub capture):
|
|
10
|
+
*
|
|
11
|
+
* - `stream: true` with `stream_options: {include_usage: true}` — the CLI never
|
|
12
|
+
* sends a non-streaming request, so none is accepted;
|
|
13
|
+
* - `model` and `reasoning_effort` equal to the grant's declaration;
|
|
14
|
+
* - `messages` of plain `{role, content}` string turns, roles system/user/assistant;
|
|
15
|
+
* - optional `response_format` `{type: "json_schema", json_schema: {name, schema, strict}}`;
|
|
16
|
+
* - no `tools` and no `tool_choice` member at all, not even an empty one. The
|
|
17
|
+
* CLI's per-call `session_title` request carries both and is refused here.
|
|
18
|
+
*
|
|
19
|
+
* The client version must be the pinned CLI, and the forwarded body is the
|
|
20
|
+
* re-serialized parse, never the caller's bytes.
|
|
21
|
+
*/
|
|
22
|
+
export declare function authorizeGrokInferenceProxyRequest(input: Omit<GrokBrokerProxyInput, "agentId" | "turnId">, bearer: string, policy: GrokBrokerModelPolicy): GrokBrokerUpstreamRequest;
|
|
23
|
+
//# sourceMappingURL=grokInferenceProxyRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokInferenceProxyRequest.d.ts","sourceRoot":"","sources":["../../src/runtime/grokInferenceProxyRequest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACnG,OAAO,EAA8B,KAAK,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAUpG;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,yBAAyB,CAcpL"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
|
|
2
|
+
import { parseGrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
3
|
+
const MAX_BODY = 2 * 1024 * 1024;
|
|
4
|
+
const SPEC = GROK_ENGINE_BROKER.inferenceGrants;
|
|
5
|
+
const BODY_MEMBERS = new Set(SPEC.bodyMembers);
|
|
6
|
+
const ROLES = new Set(SPEC.messageRoles);
|
|
7
|
+
const plain = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8
|
+
const rejected = () => new Error("inference grant request rejected");
|
|
9
|
+
/**
|
|
10
|
+
* Authorizes one evaluator grant request body and rebuilds it for the provider.
|
|
11
|
+
*
|
|
12
|
+
* The accepted shape is exactly what Grok CLI 1.0.34 sends for a Paideia
|
|
13
|
+
* judge/optimizer call (`--tools read_file --disallowed-tools
|
|
14
|
+
* read_file,search_tool,use_tool --max-turns 1`, with and without
|
|
15
|
+
* `--system-prompt-override` and `--json-schema`; live stub capture):
|
|
16
|
+
*
|
|
17
|
+
* - `stream: true` with `stream_options: {include_usage: true}` — the CLI never
|
|
18
|
+
* sends a non-streaming request, so none is accepted;
|
|
19
|
+
* - `model` and `reasoning_effort` equal to the grant's declaration;
|
|
20
|
+
* - `messages` of plain `{role, content}` string turns, roles system/user/assistant;
|
|
21
|
+
* - optional `response_format` `{type: "json_schema", json_schema: {name, schema, strict}}`;
|
|
22
|
+
* - no `tools` and no `tool_choice` member at all, not even an empty one. The
|
|
23
|
+
* CLI's per-call `session_title` request carries both and is refused here.
|
|
24
|
+
*
|
|
25
|
+
* The client version must be the pinned CLI, and the forwarded body is the
|
|
26
|
+
* re-serialized parse, never the caller's bytes.
|
|
27
|
+
*/
|
|
28
|
+
export function authorizeGrokInferenceProxyRequest(input, bearer, policy) {
|
|
29
|
+
const declared = parseGrokBrokerModelPolicy(policy);
|
|
30
|
+
if (input.method !== "POST" || input.pathname !== "/v1/chat/completions" || input.body.byteLength < 2 || input.body.byteLength > MAX_BODY)
|
|
31
|
+
throw rejected();
|
|
32
|
+
if (!bearer || /[\r\n]/u.test(bearer))
|
|
33
|
+
throw new Error("broker credential authority unavailable");
|
|
34
|
+
const clientVersion = input.headers["x-grok-client-version"];
|
|
35
|
+
if (clientVersion !== GROK_ENGINE_BROKER.grokCliVersion)
|
|
36
|
+
throw rejected();
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(Buffer.from(input.body).toString("utf8"), (key, value) => { if (key === "__proto__")
|
|
40
|
+
throw new Error(); return value; });
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw rejected();
|
|
44
|
+
}
|
|
45
|
+
if (!plain(parsed) || Object.keys(parsed).some((key) => !BODY_MEMBERS.has(key)))
|
|
46
|
+
throw rejected();
|
|
47
|
+
if (parsed.model !== declared.model || parsed.reasoning_effort !== declared.reasoningEffort || parsed.stream !== true)
|
|
48
|
+
throw rejected();
|
|
49
|
+
if (!plain(parsed.stream_options) || Object.keys(parsed.stream_options).length !== 1 || parsed.stream_options.include_usage !== true)
|
|
50
|
+
throw rejected();
|
|
51
|
+
if (!Array.isArray(parsed.messages) || parsed.messages.length === 0 || !parsed.messages.every(plainMessage))
|
|
52
|
+
throw rejected();
|
|
53
|
+
if (parsed.response_format !== undefined && !jsonSchemaFormat(parsed.response_format))
|
|
54
|
+
throw rejected();
|
|
55
|
+
return { url: "https://cli-chat-proxy.grok.com/v1/chat/completions", headers: { authorization: `Bearer ${bearer}`, "content-type": "application/json", "x-xai-token-auth": "xai-grok-cli", "x-grok-model-override": declared.model, "x-grok-client-version": clientVersion, "x-grok-client-identifier": "grok-shell" }, body: Buffer.from(JSON.stringify(parsed)) };
|
|
56
|
+
}
|
|
57
|
+
const plainMessage = (message) => plain(message) && Object.keys(message).length === 2 && ROLES.has(message.role) && typeof message.content === "string";
|
|
58
|
+
const jsonSchemaFormat = (value) => {
|
|
59
|
+
if (!plain(value) || Object.keys(value).length !== 2 || value.type !== "json_schema" || !plain(value.json_schema))
|
|
60
|
+
return false;
|
|
61
|
+
const schema = value.json_schema;
|
|
62
|
+
return Object.keys(schema).every((key) => key === "name" || key === "schema" || key === "strict") && typeof schema.name === "string" && plain(schema.schema) && (schema.strict === undefined || typeof schema.strict === "boolean");
|
|
63
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type OrganizationGrokBrokerProjection } from "./grokBrokerProjection.js";
|
|
3
|
+
export declare const GROK_SLOT_PREFLIGHT_VERSION: "noopolis.daimon.grok-slot-preflight.v2";
|
|
4
|
+
/**
|
|
5
|
+
* One denied-path canary: the root supervisor ran a real sandboxed read of
|
|
6
|
+
* `path` as the slot's worker uid (a stub-model turn under the attested
|
|
7
|
+
* profile) and the read was denied. Only denials are representable — a
|
|
8
|
+
* supervisor that observed a readable path writes no receipt at all.
|
|
9
|
+
*/
|
|
10
|
+
export declare const grokSlotPreflightCanarySchema: z.ZodObject<{
|
|
11
|
+
path: z.ZodString;
|
|
12
|
+
method: z.ZodLiteral<"sandboxed-read">;
|
|
13
|
+
result: z.ZodLiteral<"denied">;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
/**
|
|
16
|
+
* `noopolis.daimon.grok-slot-preflight.v2`: what the root slot supervisor (P5)
|
|
17
|
+
* writes after provisioning or recycling one broker slot, and what an
|
|
18
|
+
* evaluator (Paideia, P4) must hold before it runs a Grok subject turn in that
|
|
19
|
+
* slot. It binds the slot to one exact projection by digest, so any change to
|
|
20
|
+
* the model, limits, deny list, profile, worker config, or pinned executable
|
|
21
|
+
* invalidates it.
|
|
22
|
+
*
|
|
23
|
+
* The projection digest is identical across recycles of the same slot, so v1
|
|
24
|
+
* could not tell this recycle's receipt from an earlier one. v2 adds
|
|
25
|
+
* freshness: `generation` is the supervisor-owned per-slot counter, strictly
|
|
26
|
+
* increasing on every provision/recycle, and `nonce` echoes the 32 random
|
|
27
|
+
* bytes (hex) the evaluator passed in its recycle request. A v1 receipt is
|
|
28
|
+
* refused.
|
|
29
|
+
*/
|
|
30
|
+
export declare const grokSlotPreflightReceiptSchema: z.ZodObject<{
|
|
31
|
+
version: z.ZodLiteral<"noopolis.daimon.grok-slot-preflight.v2">;
|
|
32
|
+
slot: z.ZodNumber;
|
|
33
|
+
worker_uid: z.ZodNumber;
|
|
34
|
+
generation: z.ZodNumber;
|
|
35
|
+
nonce: z.ZodString;
|
|
36
|
+
projection_sha256: z.ZodString;
|
|
37
|
+
sandbox_profile_sha256: z.ZodString;
|
|
38
|
+
seccomp_profile_sha256: z.ZodString;
|
|
39
|
+
sandbox_runtime: z.ZodLiteral<"bubblewrap">;
|
|
40
|
+
grok_executable_sha256: z.ZodString;
|
|
41
|
+
canaries: z.ZodArray<z.ZodObject<{
|
|
42
|
+
path: z.ZodString;
|
|
43
|
+
method: z.ZodLiteral<"sandboxed-read">;
|
|
44
|
+
result: z.ZodLiteral<"denied">;
|
|
45
|
+
}, z.core.$strict>>;
|
|
46
|
+
created_at: z.ZodString;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type GrokSlotPreflightReceipt = z.infer<typeof grokSlotPreflightReceiptSchema>;
|
|
49
|
+
/** Strict parse: unknown members, off-contract values, or duplicate canaries throw. */
|
|
50
|
+
export declare function parseGrokSlotPreflightReceipt(value: unknown): GrokSlotPreflightReceipt;
|
|
51
|
+
/**
|
|
52
|
+
* What the evaluator knows about *this* recycle: the nonce it sent, and the
|
|
53
|
+
* lowest generation it will accept — one above the last generation it
|
|
54
|
+
* accepted for the slot (1 for a slot it has never seen).
|
|
55
|
+
*/
|
|
56
|
+
export type GrokSlotPreflightFreshness = Readonly<{
|
|
57
|
+
expectedNonce: string;
|
|
58
|
+
minGeneration: number;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Parse a receipt and require that it proves *this* projection's slot: same
|
|
62
|
+
* digest, slot, worker uid, profile and executable, and a denied canary for
|
|
63
|
+
* exactly every projected deny path (no more, no fewer), under the projected
|
|
64
|
+
* seccomp profile and sandbox runtime — and that it is *this* recycle's
|
|
65
|
+
* receipt: the caller's nonce, at or above the caller's minimum generation.
|
|
66
|
+
* A receipt replayed from an earlier recycle fails on the nonce, and one
|
|
67
|
+
* whose generation went backwards fails on the generation.
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifyGrokSlotPreflightReceipt(value: unknown, projection: OrganizationGrokBrokerProjection, freshness: GrokSlotPreflightFreshness): GrokSlotPreflightReceipt;
|
|
70
|
+
//# sourceMappingURL=grokSlotPreflightReceipt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokSlotPreflightReceipt.d.ts","sourceRoot":"","sources":["../../src/runtime/grokSlotPreflightReceipt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAA8B,KAAK,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAE9G,eAAO,MAAM,2BAA2B,0CAA0C,CAAC;AAMnF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B;;;;kBAIxC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;kBAqBzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAEtF,uFAAuF;AACvF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAItF;AAED;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEpG;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gCAAgC,EAAE,SAAS,EAAE,0BAA0B,GAAG,wBAAwB,CAgB5K"}
|