@noopolis/daimon 0.1.1 → 0.2.0
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 +307 -45
- package/dist/contracts/attentionContract.d.ts +117 -0
- package/dist/contracts/attentionContract.d.ts.map +1 -0
- package/dist/contracts/attentionContract.js +14 -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/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 +765 -0
- package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
- package/dist/contracts/organizationRuntimeContract.js +121 -0
- package/dist/contracts/runtimeContractManifest.d.ts +1615 -0
- package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
- package/dist/contracts/runtimeContractManifest.js +181 -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/siblingBuildFreshness.d.ts +21 -0
- package/dist/core/siblingBuildFreshness.d.ts.map +1 -0
- package/dist/core/siblingBuildFreshness.js +25 -0
- package/dist/core/types.d.ts +10 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/examples/exampleCausalId.d.ts +3 -0
- package/dist/examples/exampleCausalId.d.ts.map +1 -0
- package/dist/examples/exampleCausalId.js +8 -0
- package/dist/examples/jungian-play-org.js +3 -2
- package/dist/examples/jungian-triad-org.js +3 -2
- package/dist/examples/jungianPlayAgent.d.ts +1 -1
- package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
- package/dist/examples/jungianPlayAgent.js +1 -1
- package/dist/examples/jungianProfiles.d.ts +1 -1
- package/dist/examples/jungianProfiles.d.ts.map +1 -1
- package/dist/examples/jungianTriadProfiles.d.ts +1 -1
- package/dist/examples/jungianTriadProfiles.d.ts.map +1 -1
- package/dist/examples/pi-agent.js +3 -2
- package/dist/examples/pi-memory-org.js +6 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/mcp/toolServer.d.ts +31 -0
- package/dist/mcp/toolServer.d.ts.map +1 -0
- package/dist/mcp/toolServer.js +145 -0
- package/dist/observability/causalEvents.d.ts +118 -0
- package/dist/observability/causalEvents.d.ts.map +1 -0
- package/dist/observability/causalEvents.js +223 -0
- package/dist/observability/controlCausal.d.ts +117 -0
- package/dist/observability/controlCausal.d.ts.map +1 -0
- package/dist/observability/controlCausal.js +107 -0
- package/dist/observability/emitCausalFixture.d.ts +25 -0
- package/dist/observability/emitCausalFixture.d.ts.map +1 -0
- package/dist/observability/emitCausalFixture.js +98 -0
- package/dist/observability/index.d.ts +2 -0
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +2 -0
- 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 +164 -0
- package/dist/pi/cliEnvironment.d.ts +12 -0
- package/dist/pi/cliEnvironment.d.ts.map +1 -0
- package/dist/pi/cliEnvironment.js +32 -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 +106 -0
- package/dist/pi/cliSession.d.ts.map +1 -0
- package/dist/pi/cliSession.js +379 -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/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 +57 -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/index.d.ts +5 -0
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +5 -0
- package/dist/pi/memoryTools.d.ts +55 -1
- package/dist/pi/memoryTools.d.ts.map +1 -1
- package/dist/pi/memoryTools.js +144 -24
- package/dist/pi/modelRegistry.d.ts +13 -0
- package/dist/pi/modelRegistry.d.ts.map +1 -0
- package/dist/pi/modelRegistry.js +19 -0
- package/dist/pi/piAgentHandle.d.ts +46 -0
- package/dist/pi/piAgentHandle.d.ts.map +1 -0
- package/dist/pi/piAgentHandle.js +351 -0
- package/dist/pi/piAgentWakeSupport.d.ts +103 -0
- package/dist/pi/piAgentWakeSupport.d.ts.map +1 -0
- package/dist/pi/piAgentWakeSupport.js +151 -0
- package/dist/pi/piHarness.d.ts +40 -5
- package/dist/pi/piHarness.d.ts.map +1 -1
- package/dist/pi/piHarness.js +151 -256
- package/dist/pi/prompts.d.ts +10 -0
- package/dist/pi/prompts.d.ts.map +1 -0
- package/dist/pi/prompts.js +63 -0
- package/dist/pi/rawTrainingCapture.d.ts +59 -0
- package/dist/pi/rawTrainingCapture.d.ts.map +1 -0
- package/dist/pi/rawTrainingCapture.js +175 -0
- package/dist/pi/turnCausal.d.ts +73 -0
- package/dist/pi/turnCausal.d.ts.map +1 -0
- package/dist/pi/turnCausal.js +75 -0
- package/dist/pi/turnTrace.d.ts +128 -0
- package/dist/pi/turnTrace.d.ts.map +1 -0
- package/dist/pi/turnTrace.js +138 -0
- package/dist/pi/wakeAcceptance.d.ts +49 -0
- package/dist/pi/wakeAcceptance.d.ts.map +1 -0
- package/dist/pi/wakeAcceptance.js +281 -0
- package/dist/pi/wakeAcceptanceFs.d.ts +44 -0
- package/dist/pi/wakeAcceptanceFs.d.ts.map +1 -0
- package/dist/pi/wakeAcceptanceFs.js +318 -0
- package/dist/pi/wakeAcceptanceSchema.d.ts +75 -0
- package/dist/pi/wakeAcceptanceSchema.d.ts.map +1 -0
- package/dist/pi/wakeAcceptanceSchema.js +265 -0
- package/dist/pi/wakeModes.d.ts +9 -0
- package/dist/pi/wakeModes.d.ts.map +1 -0
- package/dist/pi/wakeModes.js +19 -0
- package/dist/pi/worldNudge.d.ts +22 -0
- package/dist/pi/worldNudge.d.ts.map +1 -0
- package/dist/pi/worldNudge.js +62 -0
- package/dist/pi/worldToolProtocol.d.ts +13 -0
- package/dist/pi/worldToolProtocol.d.ts.map +1 -0
- package/dist/pi/worldToolProtocol.js +49 -0
- package/dist/pi/worldTools.d.ts +32 -0
- package/dist/pi/worldTools.d.ts.map +1 -0
- package/dist/pi/worldTools.js +373 -0
- package/dist/pi/worldTrajectory.d.ts +52 -0
- package/dist/pi/worldTrajectory.d.ts.map +1 -0
- package/dist/pi/worldTrajectory.js +131 -0
- 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 +21 -0
- package/dist/runtime/attention.d.ts.map +1 -0
- package/dist/runtime/attention.js +36 -0
- package/dist/runtime/attentionDispatcher.d.ts +66 -0
- package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
- package/dist/runtime/attentionDispatcher.js +271 -0
- package/dist/runtime/cli.d.ts +7 -0
- package/dist/runtime/cli.d.ts.map +1 -0
- package/dist/runtime/cli.js +251 -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 +30 -0
- package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCapabilities.js +59 -0
- package/dist/runtime/engineBrokerControlClient.d.ts +44 -0
- package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
- package/dist/runtime/engineBrokerControlClient.js +132 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts +10 -0
- package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
- package/dist/runtime/engineBrokerCredentialJournal.js +17 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts +52 -0
- package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts +160 -0
- package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpCallLog.js +219 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts +56 -0
- package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
- package/dist/runtime/engineBrokerMcpFacade.js +343 -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 +135 -0
- package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
- package/dist/runtime/engineBrokerProtocol.js +274 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
- package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
- package/dist/runtime/engineBrokerSealLedger.js +123 -0
- package/dist/runtime/engineBrokerService.d.ts +37 -0
- package/dist/runtime/engineBrokerService.d.ts.map +1 -0
- package/dist/runtime/engineBrokerService.js +138 -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 +50 -0
- package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
- package/dist/runtime/engineBrokerServiceConfig.js +92 -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 +158 -0
- package/dist/runtime/engineDispatcher.d.ts +36 -0
- package/dist/runtime/engineDispatcher.d.ts.map +1 -0
- package/dist/runtime/engineDispatcher.js +216 -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 +22 -0
- package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialAuthority.js +124 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts +5 -0
- package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
- package/dist/runtime/grokBrokerCredentialReader.js +37 -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 +106 -0
- package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProjection.js +94 -0
- package/dist/runtime/grokBrokerProxy.d.ts +55 -0
- package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxy.js +262 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts +30 -0
- package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
- package/dist/runtime/grokBrokerProxyRequest.js +74 -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/grokBrokerTurnMeter.d.ts +128 -0
- package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
- package/dist/runtime/grokBrokerTurnMeter.js +251 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts +86 -0
- package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
- package/dist/runtime/grokBrokerWorkerConfig.js +135 -0
- package/dist/runtime/grokEngineBroker.d.ts +48 -0
- package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
- package/dist/runtime/grokEngineBroker.js +114 -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 +58 -0
- package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
- package/dist/runtime/grokEngineBrokerTurn.js +165 -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 +82 -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 +170 -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 +30 -0
- package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
- package/dist/runtime/grokWorkerHomeAttestation.js +69 -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 +26 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +23 -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 +165 -0
- package/dist/runtime/organizationRuntime.d.ts.map +1 -0
- package/dist/runtime/organizationRuntime.js +3 -0
- package/dist/runtime/organizationRuntimeControl.d.ts +42 -0
- package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeControl.js +235 -0
- package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
- package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeHost.js +359 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
- package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeParsing.js +370 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
- package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
- package/dist/runtime/organizationRuntimeReadiness.js +59 -0
- package/dist/runtime/physicalReadiness.d.ts +47 -0
- package/dist/runtime/physicalReadiness.d.ts.map +1 -0
- package/dist/runtime/physicalReadiness.js +142 -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 +328 -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 +371 -0
- package/dist/runtime/storeCoordination.d.ts +23 -0
- package/dist/runtime/storeCoordination.d.ts.map +1 -0
- package/dist/runtime/storeCoordination.js +94 -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 +160 -0
- package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
- package/dist/runtime/turnRequestLedger.js +249 -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/wakeAcceptanceProcessIdentity.d.ts +17 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceProcessIdentity.js +50 -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 +23 -0
- package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRecord.js +56 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts +12 -0
- package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceRetention.js +12 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
- package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
- package/dist/runtime/wakeAcceptanceStore.js +558 -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 +69 -0
- package/dist/runtime/wakeFuse.d.ts.map +1 -0
- package/dist/runtime/wakeFuse.js +367 -0
- package/package.json +25 -17
- package/dist/examples/mixed-engine-org.d.ts +0 -2
- package/dist/examples/mixed-engine-org.d.ts.map +0 -1
- package/dist/examples/mixed-engine-org.js +0 -351
- package/dist/examples/mixedEngineCli.d.ts +0 -15
- package/dist/examples/mixedEngineCli.d.ts.map +0 -1
- package/dist/examples/mixedEngineCli.js +0 -174
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type EngineBrokerLimitReason, type EngineBrokerTurnLimits, type EngineBrokerTurnUsage } from "./engineBrokerTurnAccounting.js";
|
|
2
|
+
/**
|
|
3
|
+
* `estimated` marks a request whose response carried no valid usage and was
|
|
4
|
+
* charged {@link estimateGrokRequestUsage}. `toolCalls` are the tool-call names
|
|
5
|
+
* that request's response carried, names only ({@link parseGrokResponseToolNames});
|
|
6
|
+
* absent means the response could not be decoded, `[]` that it called nothing.
|
|
7
|
+
*/
|
|
8
|
+
export type GrokBrokerRequestTiming = Readonly<{
|
|
9
|
+
startedAt: string;
|
|
10
|
+
endedAt?: string;
|
|
11
|
+
usage?: EngineBrokerTurnUsage;
|
|
12
|
+
estimated?: true;
|
|
13
|
+
toolCalls?: readonly string[];
|
|
14
|
+
}>;
|
|
15
|
+
export type GrokBrokerTurnMeterSnapshot = Readonly<{
|
|
16
|
+
requests: number;
|
|
17
|
+
tokens: number;
|
|
18
|
+
limitReason: EngineBrokerLimitReason;
|
|
19
|
+
usage: EngineBrokerTurnUsage | null;
|
|
20
|
+
estimatedRequests: number;
|
|
21
|
+
timings: readonly GrokBrokerRequestTiming[];
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* The proxy's per-turn spend gate.
|
|
25
|
+
*
|
|
26
|
+
* Every forwarded model request of one turn passes through {@link admit}
|
|
27
|
+
* *before* a bearer is attached, so the checks are hard for requests and
|
|
28
|
+
* elapsed time and between-requests for tokens:
|
|
29
|
+
*
|
|
30
|
+
* - `maxRequests`: request `maxRequests + 1` is refused; upstream never sees it.
|
|
31
|
+
* - `timeoutMs`: a request arriving after the deadline is refused (the broker's
|
|
32
|
+
* own timer additionally kills a worker that is mid-request).
|
|
33
|
+
* - `maxTokens`: checked against the running total of upstream-reported usage
|
|
34
|
+
* of the requests already answered. A request is admitted while that total is
|
|
35
|
+
* still below the ceiling, so the overshoot is bounded by exactly one
|
|
36
|
+
* request's usage — the last admitted one. Usage counts total input
|
|
37
|
+
* *including* cached tokens (P0 observed an uncached replay at +55%).
|
|
38
|
+
*
|
|
39
|
+
* The first limit that fires is sticky: every later request is refused with
|
|
40
|
+
* the same reason, and `onLimit` runs once.
|
|
41
|
+
*
|
|
42
|
+
* The token bound is only a bound if no request can be admitted on a total
|
|
43
|
+
* that an in-flight request has not yet reported into. So a turn has at most
|
|
44
|
+
* ONE upstream request in flight: a second request arriving before the first
|
|
45
|
+
* settled is refused (`busy`, HTTP 429) without being counted or tripping a
|
|
46
|
+
* limit. Grok's headless loop is sequential — every live capture (P1
|
|
47
|
+
* live-round1, P2 live) shows each request ending before the next starts — so
|
|
48
|
+
* this refuses only a worker that is not behaving like Grok. Tripping a limit
|
|
49
|
+
* (including the broker's timer) aborts that in-flight upstream call through
|
|
50
|
+
* its own `AbortSignal` rather than letting it run to completion.
|
|
51
|
+
*/
|
|
52
|
+
export declare class GrokBrokerTurnMeter {
|
|
53
|
+
readonly limits: EngineBrokerTurnLimits;
|
|
54
|
+
private readonly onLimit;
|
|
55
|
+
private readonly now;
|
|
56
|
+
private readonly startedAt;
|
|
57
|
+
private readonly timings;
|
|
58
|
+
private tokens;
|
|
59
|
+
private reason;
|
|
60
|
+
private inFlight;
|
|
61
|
+
constructor(limits: EngineBrokerTurnLimits, onLimit?: (reason: Exclude<EngineBrokerLimitReason, "none">) => void, now?: () => number);
|
|
62
|
+
/** Returns the request index and its upstream abort signal when admitted, the limit that refused it, or `busy` while another request is in flight. */
|
|
63
|
+
admit(): Readonly<{
|
|
64
|
+
index: number;
|
|
65
|
+
signal: AbortSignal;
|
|
66
|
+
} | {
|
|
67
|
+
refused: Exclude<EngineBrokerLimitReason, "none">;
|
|
68
|
+
} | {
|
|
69
|
+
busy: true;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Records one admitted request's end, its usage, and the tool-call names its
|
|
73
|
+
* response carried. A response without valid usage (absent, malformed,
|
|
74
|
+
* implausible, or a failed/aborted call) is charged a conservative estimate
|
|
75
|
+
* from the request body size, so a missing `usage` can never silently disable
|
|
76
|
+
* the token ceiling. `toolCalls` is observation only: it never affects
|
|
77
|
+
* admission, the running total, or any limit.
|
|
78
|
+
*/
|
|
79
|
+
settle(index: number, usage: EngineBrokerTurnUsage | undefined, requestBytes: number, toolCalls?: readonly string[]): void;
|
|
80
|
+
/** Trips a limit from outside the request path (the broker's wall-clock timer). */
|
|
81
|
+
trip(reason: Exclude<EngineBrokerLimitReason, "none">): void;
|
|
82
|
+
/** Aborts the in-flight upstream call, if any (limit trip, or the broker ending the turn). */
|
|
83
|
+
abortInFlight(): void;
|
|
84
|
+
snapshot(): GrokBrokerTurnMeterSnapshot;
|
|
85
|
+
}
|
|
86
|
+
/** The charge for a request without valid usage: `ceil(bodyBytes / 2)` input plus a fixed output allowance. */
|
|
87
|
+
export declare const estimateGrokRequestUsage: (requestBytes: number) => EngineBrokerTurnUsage;
|
|
88
|
+
/**
|
|
89
|
+
* Upstream-reported usage of one chat-completions response, or `undefined`.
|
|
90
|
+
*
|
|
91
|
+
* The proxy buffers the whole upstream body, so the last `usage` object of an
|
|
92
|
+
* SSE stream (`stream_options.include_usage`) or of a JSON body is available
|
|
93
|
+
* before the body is returned to the worker. OpenAI-shaped `prompt_tokens`
|
|
94
|
+
* include cached tokens; they are split into disjoint buckets here, and any
|
|
95
|
+
* reasoning tokens reported outside `completion_tokens` (visible as
|
|
96
|
+
* `total_tokens` above prompt + completion) are folded into `output` so the
|
|
97
|
+
* total invariant holds. A malformed block, or one whose total exceeds
|
|
98
|
+
* `GROK_ENGINE_BROKER.turnLimits.requestUsageMaxTokens`, is invalid: never
|
|
99
|
+
* zero-filled and never added — the meter charges an estimate instead.
|
|
100
|
+
*/
|
|
101
|
+
export declare function parseGrokUpstreamUsage(body: Uint8Array, contentType: string | undefined): EngineBrokerTurnUsage | undefined;
|
|
102
|
+
/** At most this many names per request row; a longer list ends in {@link GROK_TOOL_CALL_TRUNCATED}. */
|
|
103
|
+
export declare const GROK_REQUEST_TOOL_CALLS_MAX = 16;
|
|
104
|
+
/** A `name` that is not a plain short identifier is counted, never passed through. */
|
|
105
|
+
export declare const GROK_TOOL_CALL_INVALID = "<invalid>";
|
|
106
|
+
export declare const GROK_TOOL_CALL_TRUNCATED = "<truncated>";
|
|
107
|
+
/**
|
|
108
|
+
* The tool-call NAMES one upstream response carried, and nothing else.
|
|
109
|
+
*
|
|
110
|
+
* Two live turns could not answer "did the model ever try `use_tool` or
|
|
111
|
+
* `search_tool`", because the per-request rows recorded timings and tokens but
|
|
112
|
+
* never an attempt. This is that answer, under four rules:
|
|
113
|
+
*
|
|
114
|
+
* - names only. No arguments, no message content, no tokens, no header. A
|
|
115
|
+
* `name` that is not a plain short identifier is recorded as
|
|
116
|
+
* {@link GROK_TOOL_CALL_INVALID} rather than passing provider bytes through;
|
|
117
|
+
* - bounded. At most {@link GROK_REQUEST_TOOL_CALLS_MAX} entries, the last being
|
|
118
|
+
* {@link GROK_TOOL_CALL_TRUNCATED} when the response carried more, so a
|
|
119
|
+
* pathological response cannot write an unbounded row;
|
|
120
|
+
* - absence stays absence. A decoded response that called nothing returns `[]`;
|
|
121
|
+
* a response that could not be decoded returns `undefined` and the row records
|
|
122
|
+
* no field at all;
|
|
123
|
+
* - one streaming call names itself in one delta and streams its arguments in
|
|
124
|
+
* the rest, so a repeat of the same `(choice, call)` index is that same call,
|
|
125
|
+
* not a second attempt.
|
|
126
|
+
*/
|
|
127
|
+
export declare function parseGrokResponseToolNames(body: Uint8Array, contentType: string | undefined): readonly string[] | undefined;
|
|
128
|
+
//# sourceMappingURL=grokBrokerTurnMeter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokBrokerTurnMeter.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerTurnMeter.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,uBAAuB,EAAE,KAAK,sBAAsB,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAElK;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC;AACxK,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,uBAAuB,CAAC;IAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,uBAAuB,EAAE,CAAA;CAAE,CAAC,CAAC;AAE5O;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,mBAAmB;IAMlB,QAAQ,CAAC,MAAM,EAAE,sBAAsB;IAAE,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAgF,OAAO,CAAC,QAAQ,CAAC,GAAG;IALjL,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiI;IACzJ,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,QAAQ,CAA6D;gBACxD,MAAM,EAAE,sBAAsB,EAAmB,OAAO,GAAE,CAAC,MAAM,EAAE,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,KAAK,IAAsB,EAAmB,GAAG,GAAE,MAAM,MAAiB;IAI1M,sJAAsJ;IACtJ,KAAK,IAAI,QAAQ,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;IAclI;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAW1H,mFAAmF;IACnF,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAAG,IAAI;IAO5D,8FAA8F;IAC9F,aAAa,IAAI,IAAI;IAErB,QAAQ,IAAI,2BAA2B;CAIxC;AAID,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,GAAI,cAAc,MAAM,KAAG,qBAG/D,CAAC;AAMF;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,qBAAqB,GAAG,SAAS,CAU3H;AA0BD,uGAAuG;AACvG,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,sFAAsF;AACtF,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAClD,eAAO,MAAM,wBAAwB,gBAAgB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CA2B3H"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
|
|
2
|
+
import { sumEngineBrokerTurnUsage } from "./engineBrokerTurnAccounting.js";
|
|
3
|
+
/**
|
|
4
|
+
* The proxy's per-turn spend gate.
|
|
5
|
+
*
|
|
6
|
+
* Every forwarded model request of one turn passes through {@link admit}
|
|
7
|
+
* *before* a bearer is attached, so the checks are hard for requests and
|
|
8
|
+
* elapsed time and between-requests for tokens:
|
|
9
|
+
*
|
|
10
|
+
* - `maxRequests`: request `maxRequests + 1` is refused; upstream never sees it.
|
|
11
|
+
* - `timeoutMs`: a request arriving after the deadline is refused (the broker's
|
|
12
|
+
* own timer additionally kills a worker that is mid-request).
|
|
13
|
+
* - `maxTokens`: checked against the running total of upstream-reported usage
|
|
14
|
+
* of the requests already answered. A request is admitted while that total is
|
|
15
|
+
* still below the ceiling, so the overshoot is bounded by exactly one
|
|
16
|
+
* request's usage — the last admitted one. Usage counts total input
|
|
17
|
+
* *including* cached tokens (P0 observed an uncached replay at +55%).
|
|
18
|
+
*
|
|
19
|
+
* The first limit that fires is sticky: every later request is refused with
|
|
20
|
+
* the same reason, and `onLimit` runs once.
|
|
21
|
+
*
|
|
22
|
+
* The token bound is only a bound if no request can be admitted on a total
|
|
23
|
+
* that an in-flight request has not yet reported into. So a turn has at most
|
|
24
|
+
* ONE upstream request in flight: a second request arriving before the first
|
|
25
|
+
* settled is refused (`busy`, HTTP 429) without being counted or tripping a
|
|
26
|
+
* limit. Grok's headless loop is sequential — every live capture (P1
|
|
27
|
+
* live-round1, P2 live) shows each request ending before the next starts — so
|
|
28
|
+
* this refuses only a worker that is not behaving like Grok. Tripping a limit
|
|
29
|
+
* (including the broker's timer) aborts that in-flight upstream call through
|
|
30
|
+
* its own `AbortSignal` rather than letting it run to completion.
|
|
31
|
+
*/
|
|
32
|
+
export class GrokBrokerTurnMeter {
|
|
33
|
+
limits;
|
|
34
|
+
onLimit;
|
|
35
|
+
now;
|
|
36
|
+
startedAt;
|
|
37
|
+
timings = [];
|
|
38
|
+
tokens = 0;
|
|
39
|
+
reason = "none";
|
|
40
|
+
inFlight;
|
|
41
|
+
constructor(limits, onLimit = () => undefined, now = Date.now) {
|
|
42
|
+
this.limits = limits;
|
|
43
|
+
this.onLimit = onLimit;
|
|
44
|
+
this.now = now;
|
|
45
|
+
this.startedAt = now();
|
|
46
|
+
}
|
|
47
|
+
/** Returns the request index and its upstream abort signal when admitted, the limit that refused it, or `busy` while another request is in flight. */
|
|
48
|
+
admit() {
|
|
49
|
+
if (this.reason === "none") {
|
|
50
|
+
if (this.now() - this.startedAt >= this.limits.timeoutMs)
|
|
51
|
+
this.trip("timeout");
|
|
52
|
+
else if (this.timings.length >= this.limits.maxRequests)
|
|
53
|
+
this.trip("requests");
|
|
54
|
+
else if (this.tokens >= this.limits.maxTokens)
|
|
55
|
+
this.trip("tokens");
|
|
56
|
+
}
|
|
57
|
+
if (this.reason !== "none")
|
|
58
|
+
return { refused: this.reason };
|
|
59
|
+
if (this.inFlight !== undefined)
|
|
60
|
+
return { busy: true };
|
|
61
|
+
this.timings.push({ startedAt: new Date(this.now()).toISOString() });
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
this.inFlight = { index: this.timings.length - 1, controller };
|
|
64
|
+
return { index: this.inFlight.index, signal: controller.signal };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Records one admitted request's end, its usage, and the tool-call names its
|
|
68
|
+
* response carried. A response without valid usage (absent, malformed,
|
|
69
|
+
* implausible, or a failed/aborted call) is charged a conservative estimate
|
|
70
|
+
* from the request body size, so a missing `usage` can never silently disable
|
|
71
|
+
* the token ceiling. `toolCalls` is observation only: it never affects
|
|
72
|
+
* admission, the running total, or any limit.
|
|
73
|
+
*/
|
|
74
|
+
settle(index, usage, requestBytes, toolCalls) {
|
|
75
|
+
const timing = this.timings[index];
|
|
76
|
+
if (timing === undefined || timing.endedAt !== undefined)
|
|
77
|
+
return;
|
|
78
|
+
if (this.inFlight?.index === index)
|
|
79
|
+
this.inFlight = undefined;
|
|
80
|
+
timing.endedAt = new Date(this.now()).toISOString();
|
|
81
|
+
if (usage === undefined) {
|
|
82
|
+
timing.usage = estimateGrokRequestUsage(requestBytes);
|
|
83
|
+
timing.estimated = true;
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
timing.usage = usage;
|
|
87
|
+
if (toolCalls !== undefined)
|
|
88
|
+
timing.toolCalls = toolCalls;
|
|
89
|
+
this.tokens += timing.usage.total;
|
|
90
|
+
}
|
|
91
|
+
/** Trips a limit from outside the request path (the broker's wall-clock timer). */
|
|
92
|
+
trip(reason) {
|
|
93
|
+
if (this.reason !== "none")
|
|
94
|
+
return;
|
|
95
|
+
this.reason = reason;
|
|
96
|
+
this.abortInFlight();
|
|
97
|
+
this.onLimit(reason);
|
|
98
|
+
}
|
|
99
|
+
/** Aborts the in-flight upstream call, if any (limit trip, or the broker ending the turn). */
|
|
100
|
+
abortInFlight() { this.inFlight?.controller.abort(); }
|
|
101
|
+
snapshot() {
|
|
102
|
+
const measured = this.timings.flatMap((timing) => timing.usage === undefined ? [] : [timing.usage]);
|
|
103
|
+
return { requests: this.timings.length, tokens: this.tokens, limitReason: this.reason, usage: sumEngineBrokerTurnUsage(measured), estimatedRequests: this.timings.filter((timing) => timing.estimated === true).length, timings: this.timings.map((timing) => Object.freeze({ ...timing })) };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const { requestUsageMaxTokens, missingUsageEstimate } = GROK_ENGINE_BROKER.turnLimits;
|
|
107
|
+
/** The charge for a request without valid usage: `ceil(bodyBytes / 2)` input plus a fixed output allowance. */
|
|
108
|
+
export const estimateGrokRequestUsage = (requestBytes) => {
|
|
109
|
+
const input = Math.ceil(Math.max(0, requestBytes) / missingUsageEstimate.inputBytesPerToken), output = missingUsageEstimate.outputTokens;
|
|
110
|
+
return { input, cacheRead: 0, cacheWrite: 0, output, total: input + output };
|
|
111
|
+
};
|
|
112
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
113
|
+
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Upstream-reported usage of one chat-completions response, or `undefined`.
|
|
116
|
+
*
|
|
117
|
+
* The proxy buffers the whole upstream body, so the last `usage` object of an
|
|
118
|
+
* SSE stream (`stream_options.include_usage`) or of a JSON body is available
|
|
119
|
+
* before the body is returned to the worker. OpenAI-shaped `prompt_tokens`
|
|
120
|
+
* include cached tokens; they are split into disjoint buckets here, and any
|
|
121
|
+
* reasoning tokens reported outside `completion_tokens` (visible as
|
|
122
|
+
* `total_tokens` above prompt + completion) are folded into `output` so the
|
|
123
|
+
* total invariant holds. A malformed block, or one whose total exceeds
|
|
124
|
+
* `GROK_ENGINE_BROKER.turnLimits.requestUsageMaxTokens`, is invalid: never
|
|
125
|
+
* zero-filled and never added — the meter charges an estimate instead.
|
|
126
|
+
*/
|
|
127
|
+
export function parseGrokUpstreamUsage(body, contentType) {
|
|
128
|
+
let found;
|
|
129
|
+
for (const candidate of decodeUpstreamResponse(body, contentType) ?? []) {
|
|
130
|
+
if (!isRecord(candidate) || !isRecord(candidate.usage))
|
|
131
|
+
continue;
|
|
132
|
+
// Last usage block wins even when invalid: an implausible final report
|
|
133
|
+
// must not fall back to an earlier, smaller block (the request is then
|
|
134
|
+
// charged the estimate instead).
|
|
135
|
+
found = decodeOpenAiUsage(candidate.usage);
|
|
136
|
+
}
|
|
137
|
+
return found;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Every decodable JSON object of one upstream response: each `data:` event of
|
|
141
|
+
* an SSE stream, or the single body of a JSON response.
|
|
142
|
+
*
|
|
143
|
+
* `undefined` means *nothing* decoded — an unparseable or non-JSON response.
|
|
144
|
+
* Callers must keep that distinct from a decoded response that said nothing,
|
|
145
|
+
* because the ledger never fabricates an observation it did not make.
|
|
146
|
+
*/
|
|
147
|
+
function decodeUpstreamResponse(body, contentType) {
|
|
148
|
+
const text = Buffer.from(body.buffer, body.byteOffset, body.byteLength).toString("utf8");
|
|
149
|
+
const candidates = [];
|
|
150
|
+
if (contentType?.includes("text/event-stream") === true || text.startsWith("data:")) {
|
|
151
|
+
for (const line of text.split(/\r?\n/u)) {
|
|
152
|
+
if (!line.startsWith("data:"))
|
|
153
|
+
continue;
|
|
154
|
+
const payload = line.slice(5).trim();
|
|
155
|
+
if (payload === "[DONE]" || payload.length === 0)
|
|
156
|
+
continue;
|
|
157
|
+
try {
|
|
158
|
+
candidates.push(JSON.parse(payload));
|
|
159
|
+
}
|
|
160
|
+
catch { /* a non-JSON event carries neither usage nor a tool call */ }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
try {
|
|
165
|
+
candidates.push(JSON.parse(text));
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return candidates.length === 0 ? undefined : candidates;
|
|
172
|
+
}
|
|
173
|
+
/** At most this many names per request row; a longer list ends in {@link GROK_TOOL_CALL_TRUNCATED}. */
|
|
174
|
+
export const GROK_REQUEST_TOOL_CALLS_MAX = 16;
|
|
175
|
+
/** A `name` that is not a plain short identifier is counted, never passed through. */
|
|
176
|
+
export const GROK_TOOL_CALL_INVALID = "<invalid>";
|
|
177
|
+
export const GROK_TOOL_CALL_TRUNCATED = "<truncated>";
|
|
178
|
+
const TOOL_CALL_NAME = /^[A-Za-z0-9_.-]{1,64}$/u;
|
|
179
|
+
/**
|
|
180
|
+
* The tool-call NAMES one upstream response carried, and nothing else.
|
|
181
|
+
*
|
|
182
|
+
* Two live turns could not answer "did the model ever try `use_tool` or
|
|
183
|
+
* `search_tool`", because the per-request rows recorded timings and tokens but
|
|
184
|
+
* never an attempt. This is that answer, under four rules:
|
|
185
|
+
*
|
|
186
|
+
* - names only. No arguments, no message content, no tokens, no header. A
|
|
187
|
+
* `name` that is not a plain short identifier is recorded as
|
|
188
|
+
* {@link GROK_TOOL_CALL_INVALID} rather than passing provider bytes through;
|
|
189
|
+
* - bounded. At most {@link GROK_REQUEST_TOOL_CALLS_MAX} entries, the last being
|
|
190
|
+
* {@link GROK_TOOL_CALL_TRUNCATED} when the response carried more, so a
|
|
191
|
+
* pathological response cannot write an unbounded row;
|
|
192
|
+
* - absence stays absence. A decoded response that called nothing returns `[]`;
|
|
193
|
+
* a response that could not be decoded returns `undefined` and the row records
|
|
194
|
+
* no field at all;
|
|
195
|
+
* - one streaming call names itself in one delta and streams its arguments in
|
|
196
|
+
* the rest, so a repeat of the same `(choice, call)` index is that same call,
|
|
197
|
+
* not a second attempt.
|
|
198
|
+
*/
|
|
199
|
+
export function parseGrokResponseToolNames(body, contentType) {
|
|
200
|
+
const candidates = decodeUpstreamResponse(body, contentType);
|
|
201
|
+
if (candidates === undefined)
|
|
202
|
+
return undefined;
|
|
203
|
+
const names = [], seen = new Set();
|
|
204
|
+
scan: for (const candidate of candidates) {
|
|
205
|
+
if (!isRecord(candidate) || !Array.isArray(candidate.choices))
|
|
206
|
+
continue;
|
|
207
|
+
for (const choice of candidate.choices) {
|
|
208
|
+
if (!isRecord(choice))
|
|
209
|
+
continue;
|
|
210
|
+
for (const source of [choice.delta, choice.message]) {
|
|
211
|
+
if (!isRecord(source) || !Array.isArray(source.tool_calls))
|
|
212
|
+
continue;
|
|
213
|
+
for (const call of source.tool_calls) {
|
|
214
|
+
if (!isRecord(call) || !isRecord(call.function))
|
|
215
|
+
continue;
|
|
216
|
+
const name = call.function.name;
|
|
217
|
+
// An arguments-only delta names nothing; it is not an attempt of its own.
|
|
218
|
+
if (typeof name !== "string" || name.length === 0)
|
|
219
|
+
continue;
|
|
220
|
+
if (typeof choice.index === "number" && typeof call.index === "number") {
|
|
221
|
+
const key = `${choice.index}:${call.index}`;
|
|
222
|
+
if (seen.has(key))
|
|
223
|
+
continue;
|
|
224
|
+
seen.add(key);
|
|
225
|
+
}
|
|
226
|
+
names.push(TOOL_CALL_NAME.test(name) ? name : GROK_TOOL_CALL_INVALID);
|
|
227
|
+
if (names.length > GROK_REQUEST_TOOL_CALLS_MAX)
|
|
228
|
+
break scan;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return names.length > GROK_REQUEST_TOOL_CALLS_MAX ? [...names.slice(0, GROK_REQUEST_TOOL_CALLS_MAX - 1), GROK_TOOL_CALL_TRUNCATED] : names;
|
|
234
|
+
}
|
|
235
|
+
function decodeOpenAiUsage(usage) {
|
|
236
|
+
const prompt = count(usage.prompt_tokens), completion = count(usage.completion_tokens);
|
|
237
|
+
if (prompt === undefined || completion === undefined)
|
|
238
|
+
return undefined;
|
|
239
|
+
const details = isRecord(usage.prompt_tokens_details) ? usage.prompt_tokens_details : {};
|
|
240
|
+
const cached = details.cached_tokens === undefined ? 0 : count(details.cached_tokens);
|
|
241
|
+
const reported = usage.total_tokens === undefined ? prompt + completion : count(usage.total_tokens);
|
|
242
|
+
if (cached === undefined || reported === undefined || cached > prompt)
|
|
243
|
+
return undefined;
|
|
244
|
+
const total = Math.max(reported, prompt + completion);
|
|
245
|
+
const completionDetails = isRecord(usage.completion_tokens_details) ? usage.completion_tokens_details : {};
|
|
246
|
+
const reasoning = count(completionDetails.reasoning_tokens);
|
|
247
|
+
const output = total - prompt;
|
|
248
|
+
if (total > requestUsageMaxTokens)
|
|
249
|
+
return undefined;
|
|
250
|
+
return { input: prompt - cached, cacheRead: cached, cacheWrite: 0, output, total, ...(reasoning === undefined || reasoning > output ? {} : { reasoning }) };
|
|
251
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type GrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
2
|
+
export { DAIMON_GROK_SYSTEM_PROMPT, GROK_WORKER_MAX_TURNS, GROK_WORKER_TOOL_IDS, GROK_WORKER_VISIBLE_TOOLS } from "../contracts/grokWorkerContract.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bundled skills shipped by Grok CLI 1.0.34. Names are version-specific:
|
|
5
|
+
* `[skills] disabled` removed all ~2.1k skill tokens in the P0 matrix, and a
|
|
6
|
+
* CLI bump must re-derive this list rather than inherit it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const GROK_1_0_34_BUNDLED_SKILLS: readonly ["build-with-ai", "code-review", "create-skill", "create-workflow", "design", "docx", "execute-plan", "game-animation-frames", "game-asset-core", "game-character-consistency", "game-tilesets", "game-ui-icons", "imagine", "implement", "learn", "long-running-background-tasks", "pdf", "pptx", "pr-babysit", "resume-claude", "resume-codex", "resume-cursor", "review", "skill-design-principles", "statusline"];
|
|
9
|
+
/** The worker's only model id; the argv selects it and the proxy never sees another. */
|
|
10
|
+
export declare const GROK_BROKER_WORKER_MODEL_ID: "daimon-broker-grok";
|
|
11
|
+
/**
|
|
12
|
+
* Grok 1.0.34 sends a `session_title` model request before every headless
|
|
13
|
+
* turn, and no config key or environment variable disables it
|
|
14
|
+
* (`features.title_refresh` governs only the later refresh; verified against a
|
|
15
|
+
* loopback stub). `[models] session_summary` does select the model it uses, so
|
|
16
|
+
* the title goes to a hidden model whose endpoint is the broker's own provider
|
|
17
|
+
* proxy with a placeholder key that can never be a turn capability (shorter
|
|
18
|
+
* than the 40-character capability alphabet). The proxy refuses it before any
|
|
19
|
+
* capability lookup, isolation guard, credential read, or upstream call, and
|
|
20
|
+
* Grok falls back to the truncated prompt as the title. The endpoint is always
|
|
21
|
+
* listening while a worker runs, so the refusal is bounded by one loopback
|
|
22
|
+
* round trip rather than by a connect timeout, and a prompt-derived title is
|
|
23
|
+
* never delivered anywhere but Daimon's own proxy.
|
|
24
|
+
*/
|
|
25
|
+
export declare const GROK_SESSION_TITLE_SINK_MODEL_ID: "daimon-session-title-disabled";
|
|
26
|
+
export declare const GROK_SESSION_TITLE_SINK_KEY: "session-title-disabled";
|
|
27
|
+
/**
|
|
28
|
+
* The turn-scoped proxy capability reaches the worker's only model through
|
|
29
|
+
* `env_key`, set by the native launcher. Grok 1.0.34 accepts
|
|
30
|
+
* `[auth_provider.<name>]` tables but never runs the helper for a custom model
|
|
31
|
+
* (verified against a loopback stub: no helper invocation and no Authorization
|
|
32
|
+
* header, with and without `args`, `api_backend`, `model_providers`, or a
|
|
33
|
+
* passwd-home config), while `env_key` attaches the bearer on every request.
|
|
34
|
+
* The capability is exactly as exposed as `DAIMON_MCP_CAPABILITY`: visible to
|
|
35
|
+
* the worker's own tool children, which run network-restricted, and revoked
|
|
36
|
+
* when the turn ends.
|
|
37
|
+
*/
|
|
38
|
+
export declare const GROK_BROKER_PROVIDER_CAPABILITY_ENV: "DAIMON_PROVIDER_CAPABILITY";
|
|
39
|
+
type WorkerEndpoints = Readonly<{
|
|
40
|
+
proxyPort: number;
|
|
41
|
+
mcpUrl: string;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Sections shared by every Grok worker Daimon configures, broker or direct.
|
|
45
|
+
*
|
|
46
|
+
* Each toggle is either measured (skills −2.1k tokens, workflows −314, the
|
|
47
|
+
* per-turn `session_title` model request) or behavioural hardening that P0
|
|
48
|
+
* showed to be token-neutral and warning-free on 1.0.34.
|
|
49
|
+
*/
|
|
50
|
+
export declare const renderGrokLeanBaseConfig: () => string;
|
|
51
|
+
/**
|
|
52
|
+
* `max_retries = 0` on the worker's own model, for the same reason its two
|
|
53
|
+
* siblings already carry it (the session-title sink above,
|
|
54
|
+
* `grokInferenceClientConfig.ts` for the evaluator): with Grok 1.0.34's
|
|
55
|
+
* default, a refused or failed request is retried with backoff **past 45 s**
|
|
56
|
+
* instead of failing in ~0.35 s, and the retries are blind — one live turn
|
|
57
|
+
* emitted the same refusal fifteen times over five minutes, spent $0, and died
|
|
58
|
+
* with no account of why. Only this model block was left on the default, so
|
|
59
|
+
* the one request path that spends money was also the only one that could
|
|
60
|
+
* stall a turn for minutes after its work was done. Daimon owns the retry
|
|
61
|
+
* decision here because the proxy is the thing being retried: a genuinely
|
|
62
|
+
* transient fault is already answered 503 and is the broker's to retry, and
|
|
63
|
+
* anything else is a refusal that repeating cannot fix. The worker instead
|
|
64
|
+
* fails fast and the turn reaches the host with a status.
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* The only source of broker worker `config.toml` bytes.
|
|
68
|
+
*
|
|
69
|
+
* Effort is declared here, not on the compiled launcher argv: the argv is one
|
|
70
|
+
* constant for every registration while effort is declared per deployment, and
|
|
71
|
+
* Grok 1.0.34 drops both `--reasoning-effort` and `[models]
|
|
72
|
+
* default_reasoning_effort` unless the model advertises effort support. A
|
|
73
|
+
* one-entry `reasoning_efforts` table makes the declared effort the model's
|
|
74
|
+
* default *and* its closed enum, so it reaches the request body and nothing
|
|
75
|
+
* else can be selected; the proxy then re-verifies it on every body.
|
|
76
|
+
*/
|
|
77
|
+
export declare function renderGrokBrokerWorkerConfig(policy?: Partial<GrokBrokerModelPolicy>): string;
|
|
78
|
+
/** Explicit-endpoint variant for the local live probe; production bytes come only from the function above. */
|
|
79
|
+
export declare function renderGrokBrokerWorkerConfigWith(policy: GrokBrokerModelPolicy, endpoints: WorkerEndpoints): string;
|
|
80
|
+
export declare const grokBrokerWorkerConfigSha256: (policy?: Partial<GrokBrokerModelPolicy>) => string;
|
|
81
|
+
/**
|
|
82
|
+
* TypeScript mirror of the argv compiled into `native/engineBrokerLauncherCore.inc`.
|
|
83
|
+
* `native/launcherArgv.test.ts` parses the C source and fails on any divergence.
|
|
84
|
+
*/
|
|
85
|
+
export declare const renderGrokBrokerWorkerArgs: (promptFile: string, cwd: string) => readonly string[];
|
|
86
|
+
//# sourceMappingURL=grokBrokerWorkerConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokBrokerWorkerConfig.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerWorkerConfig.ts"],"names":[],"mappings":"AAKA,OAAO,EAA8B,KAAK,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEpG,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAEvJ;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,gaAK5B,CAAC;AAEZ,wFAAwF;AACxF,eAAO,MAAM,2BAA2B,EAAG,oBAA6B,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,EAAG,+BAAwC,CAAC;AACzF,eAAO,MAAM,2BAA2B,EAAG,wBAAiC,CAAC;AAM7E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mCAAmC,EAAG,4BAAqC,CAAC;AAEzF,KAAK,eAAe,GAAG,QAAQ,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAMvE;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,QAAO,MAQhC,CAAC;AAEb;;;;;;;;;;;;;;GAcG;AACH;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,GAAE,OAAO,CAAC,qBAAqB,CAAM,GAAG,MAAM,CAEhG;AAED,8GAA8G;AAC9G,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,qBAAqB,EAAE,SAAS,EAAE,eAAe,GAAG,MAAM,CAgBlH;AAED,eAAO,MAAM,4BAA4B,GAAI,SAAQ,OAAO,CAAC,qBAAqB,CAAM,KAAG,MACV,CAAC;AAElF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GAAI,YAAY,MAAM,EAAE,KAAK,MAAM,KAAG,SAAS,MAAM,EAU3F,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
|
|
4
|
+
import { DAIMON_GROK_SYSTEM_PROMPT, GROK_WORKER_MAX_TURNS, GROK_WORKER_TOOL_IDS } from "../contracts/grokWorkerContract.js";
|
|
5
|
+
import { parseGrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
|
|
6
|
+
export { DAIMON_GROK_SYSTEM_PROMPT, GROK_WORKER_MAX_TURNS, GROK_WORKER_TOOL_IDS, GROK_WORKER_VISIBLE_TOOLS } from "../contracts/grokWorkerContract.js";
|
|
7
|
+
/**
|
|
8
|
+
* Bundled skills shipped by Grok CLI 1.0.34. Names are version-specific:
|
|
9
|
+
* `[skills] disabled` removed all ~2.1k skill tokens in the P0 matrix, and a
|
|
10
|
+
* CLI bump must re-derive this list rather than inherit it.
|
|
11
|
+
*/
|
|
12
|
+
export const GROK_1_0_34_BUNDLED_SKILLS = Object.freeze([
|
|
13
|
+
"build-with-ai", "code-review", "create-skill", "create-workflow", "design", "docx", "execute-plan",
|
|
14
|
+
"game-animation-frames", "game-asset-core", "game-character-consistency", "game-tilesets", "game-ui-icons",
|
|
15
|
+
"imagine", "implement", "learn", "long-running-background-tasks", "pdf", "pptx", "pr-babysit",
|
|
16
|
+
"resume-claude", "resume-codex", "resume-cursor", "review", "skill-design-principles", "statusline"
|
|
17
|
+
]);
|
|
18
|
+
/** The worker's only model id; the argv selects it and the proxy never sees another. */
|
|
19
|
+
export const GROK_BROKER_WORKER_MODEL_ID = "daimon-broker-grok";
|
|
20
|
+
/**
|
|
21
|
+
* Grok 1.0.34 sends a `session_title` model request before every headless
|
|
22
|
+
* turn, and no config key or environment variable disables it
|
|
23
|
+
* (`features.title_refresh` governs only the later refresh; verified against a
|
|
24
|
+
* loopback stub). `[models] session_summary` does select the model it uses, so
|
|
25
|
+
* the title goes to a hidden model whose endpoint is the broker's own provider
|
|
26
|
+
* proxy with a placeholder key that can never be a turn capability (shorter
|
|
27
|
+
* than the 40-character capability alphabet). The proxy refuses it before any
|
|
28
|
+
* capability lookup, isolation guard, credential read, or upstream call, and
|
|
29
|
+
* Grok falls back to the truncated prompt as the title. The endpoint is always
|
|
30
|
+
* listening while a worker runs, so the refusal is bounded by one loopback
|
|
31
|
+
* round trip rather than by a connect timeout, and a prompt-derived title is
|
|
32
|
+
* never delivered anywhere but Daimon's own proxy.
|
|
33
|
+
*/
|
|
34
|
+
export const GROK_SESSION_TITLE_SINK_MODEL_ID = "daimon-session-title-disabled";
|
|
35
|
+
export const GROK_SESSION_TITLE_SINK_KEY = "session-title-disabled";
|
|
36
|
+
const renderSessionTitleSink = (proxyPort) => [
|
|
37
|
+
`[model.${GROK_SESSION_TITLE_SINK_MODEL_ID}]`, 'model = "disabled"', `base_url = "http://127.0.0.1:${proxyPort}/v1"`, `api_key = "${GROK_SESSION_TITLE_SINK_KEY}"`,
|
|
38
|
+
"max_retries = 0", "hidden = true", ""
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* The turn-scoped proxy capability reaches the worker's only model through
|
|
42
|
+
* `env_key`, set by the native launcher. Grok 1.0.34 accepts
|
|
43
|
+
* `[auth_provider.<name>]` tables but never runs the helper for a custom model
|
|
44
|
+
* (verified against a loopback stub: no helper invocation and no Authorization
|
|
45
|
+
* header, with and without `args`, `api_backend`, `model_providers`, or a
|
|
46
|
+
* passwd-home config), while `env_key` attaches the bearer on every request.
|
|
47
|
+
* The capability is exactly as exposed as `DAIMON_MCP_CAPABILITY`: visible to
|
|
48
|
+
* the worker's own tool children, which run network-restricted, and revoked
|
|
49
|
+
* when the turn ends.
|
|
50
|
+
*/
|
|
51
|
+
export const GROK_BROKER_PROVIDER_CAPABILITY_ENV = "DAIMON_PROVIDER_CAPABILITY";
|
|
52
|
+
const PRODUCTION_ENDPOINTS = Object.freeze({
|
|
53
|
+
proxyPort: GROK_ENGINE_BROKER.providerProxy.port,
|
|
54
|
+
mcpUrl: `http://${GROK_ENGINE_BROKER.mcpFacade.host}:${GROK_ENGINE_BROKER.mcpFacade.port}${GROK_ENGINE_BROKER.mcpFacade.path}`
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Sections shared by every Grok worker Daimon configures, broker or direct.
|
|
58
|
+
*
|
|
59
|
+
* Each toggle is either measured (skills −2.1k tokens, workflows −314, the
|
|
60
|
+
* per-turn `session_title` model request) or behavioural hardening that P0
|
|
61
|
+
* showed to be token-neutral and warning-free on 1.0.34.
|
|
62
|
+
*/
|
|
63
|
+
export const renderGrokLeanBaseConfig = () => [
|
|
64
|
+
"[cli]", "auto_update = false", "use_leader = false", "show_tips = false", "",
|
|
65
|
+
"[features]", "telemetry = false", "title_refresh = false", "session_recap = false", "turn_summary = false",
|
|
66
|
+
"repo_status_in_system_prompt = false", "codebase_indexing = false", "backend_tools = false", "ask_user_question = false",
|
|
67
|
+
"image_gen = false", "video_gen = false", "web_fetch = false", "campaigns = false", "managed_config = false", "",
|
|
68
|
+
"[managed_mcps]", "enabled = false", "",
|
|
69
|
+
"[skills]", `disabled = [${GROK_1_0_34_BUNDLED_SKILLS.map((name) => JSON.stringify(name)).join(", ")}]`, "",
|
|
70
|
+
"[workflows]", "enabled = false", ""
|
|
71
|
+
].join("\n");
|
|
72
|
+
/**
|
|
73
|
+
* `max_retries = 0` on the worker's own model, for the same reason its two
|
|
74
|
+
* siblings already carry it (the session-title sink above,
|
|
75
|
+
* `grokInferenceClientConfig.ts` for the evaluator): with Grok 1.0.34's
|
|
76
|
+
* default, a refused or failed request is retried with backoff **past 45 s**
|
|
77
|
+
* instead of failing in ~0.35 s, and the retries are blind — one live turn
|
|
78
|
+
* emitted the same refusal fifteen times over five minutes, spent $0, and died
|
|
79
|
+
* with no account of why. Only this model block was left on the default, so
|
|
80
|
+
* the one request path that spends money was also the only one that could
|
|
81
|
+
* stall a turn for minutes after its work was done. Daimon owns the retry
|
|
82
|
+
* decision here because the proxy is the thing being retried: a genuinely
|
|
83
|
+
* transient fault is already answered 503 and is the broker's to retry, and
|
|
84
|
+
* anything else is a refusal that repeating cannot fix. The worker instead
|
|
85
|
+
* fails fast and the turn reaches the host with a status.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* The only source of broker worker `config.toml` bytes.
|
|
89
|
+
*
|
|
90
|
+
* Effort is declared here, not on the compiled launcher argv: the argv is one
|
|
91
|
+
* constant for every registration while effort is declared per deployment, and
|
|
92
|
+
* Grok 1.0.34 drops both `--reasoning-effort` and `[models]
|
|
93
|
+
* default_reasoning_effort` unless the model advertises effort support. A
|
|
94
|
+
* one-entry `reasoning_efforts` table makes the declared effort the model's
|
|
95
|
+
* default *and* its closed enum, so it reaches the request body and nothing
|
|
96
|
+
* else can be selected; the proxy then re-verifies it on every body.
|
|
97
|
+
*/
|
|
98
|
+
export function renderGrokBrokerWorkerConfig(policy = {}) {
|
|
99
|
+
return renderGrokBrokerWorkerConfigWith(parseGrokBrokerModelPolicy(policy), PRODUCTION_ENDPOINTS);
|
|
100
|
+
}
|
|
101
|
+
/** Explicit-endpoint variant for the local live probe; production bytes come only from the function above. */
|
|
102
|
+
export function renderGrokBrokerWorkerConfigWith(policy, endpoints) {
|
|
103
|
+
const declared = parseGrokBrokerModelPolicy(policy);
|
|
104
|
+
const { proxyPort, mcpUrl } = endpoints;
|
|
105
|
+
if (!Number.isInteger(proxyPort) || proxyPort < 1 || proxyPort > 65_535 || !/^http:\/\/127\.0\.0\.1:\d{1,5}\/mcp$/u.test(mcpUrl)) {
|
|
106
|
+
throw new TypeError("invalid Grok broker worker configuration");
|
|
107
|
+
}
|
|
108
|
+
const label = `${declared.reasoningEffort[0].toUpperCase()}${declared.reasoningEffort.slice(1)}`;
|
|
109
|
+
return [
|
|
110
|
+
renderGrokLeanBaseConfig(),
|
|
111
|
+
"[models]", `default = "${GROK_BROKER_WORKER_MODEL_ID}"`, `default_reasoning_effort = "${declared.reasoningEffort}"`, `session_summary = "${GROK_SESSION_TITLE_SINK_MODEL_ID}"`, "",
|
|
112
|
+
...renderSessionTitleSink(proxyPort),
|
|
113
|
+
`[model.${GROK_BROKER_WORKER_MODEL_ID}]`, `model = "${declared.model}"`, `base_url = "http://127.0.0.1:${proxyPort}/v1"`, `env_key = "${GROK_BROKER_PROVIDER_CAPABILITY_ENV}"`,
|
|
114
|
+
'api_backend = "chat_completions"', "context_window = 131072", "supports_backend_search = false", "max_retries = 0", "",
|
|
115
|
+
`[[model.${GROK_BROKER_WORKER_MODEL_ID}.reasoning_efforts]]`, `value = "${declared.reasoningEffort}"`, `label = "${label}"`, "default = true", "",
|
|
116
|
+
"[mcp_servers.daimon]", `url = "${mcpUrl}"`, 'bearer_token_env_var = "DAIMON_MCP_CAPABILITY"', ""
|
|
117
|
+
].join("\n");
|
|
118
|
+
}
|
|
119
|
+
export const grokBrokerWorkerConfigSha256 = (policy = {}) => createHash("sha256").update(renderGrokBrokerWorkerConfig(policy)).digest("hex");
|
|
120
|
+
/**
|
|
121
|
+
* TypeScript mirror of the argv compiled into `native/engineBrokerLauncherCore.inc`.
|
|
122
|
+
* `native/launcherArgv.test.ts` parses the C source and fails on any divergence.
|
|
123
|
+
*/
|
|
124
|
+
export const renderGrokBrokerWorkerArgs = (promptFile, cwd) => {
|
|
125
|
+
if (!path.posix.isAbsolute(promptFile) || !path.posix.isAbsolute(cwd))
|
|
126
|
+
throw new TypeError("invalid Grok broker worker path");
|
|
127
|
+
return [
|
|
128
|
+
"--sandbox", "daimon-strict", "--always-approve", "--no-subagents", "--prompt-file", promptFile,
|
|
129
|
+
"--no-memory", "--disable-web-search", "--no-plan", "--verbatim",
|
|
130
|
+
"--system-prompt-override", DAIMON_GROK_SYSTEM_PROMPT,
|
|
131
|
+
"--tools", GROK_WORKER_TOOL_IDS.join(","),
|
|
132
|
+
"--max-turns", String(GROK_WORKER_MAX_TURNS),
|
|
133
|
+
"--cwd", cwd, "--output-format", "streaming-messages-json", "--model", GROK_BROKER_WORKER_MODEL_ID
|
|
134
|
+
];
|
|
135
|
+
};
|