@nosana/node 1.1.73-dev.mr80.17351441846 → 1.1.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.env +1 -1
- package/dist/package.json +9 -10
- package/dist/packages/container-orchestrator/src/docker/createDockerRunOptions.d.ts +1 -1
- package/dist/packages/container-orchestrator/src/docker/dockerExtended/index.d.ts +1 -1
- package/dist/packages/container-orchestrator/src/docker/index.d.ts +1 -3
- package/dist/packages/container-orchestrator/src/docker/index.js +21 -16
- package/dist/packages/container-orchestrator/src/hooks.d.ts +2 -9
- package/dist/packages/container-orchestrator/src/hooks.js +0 -5
- package/dist/packages/container-orchestrator/src/index.d.ts +0 -1
- package/dist/packages/container-orchestrator/src/index.js +0 -1
- package/dist/packages/container-orchestrator/src/interface.d.ts +1 -4
- package/dist/packages/container-orchestrator/src/labels.d.ts +0 -2
- package/dist/packages/container-orchestrator/src/labels.js +0 -2
- package/dist/packages/container-orchestrator/src/podman/index.js +9 -4
- package/dist/packages/container-orchestrator/src/podman/utils/createPodmanRunOptions.d.ts +1 -1
- package/dist/packages/container-orchestrator/src/types.d.ts +5 -0
- package/dist/src/NodeManager/clients/hostManager/index.js +3 -3
- package/dist/src/NodeManager/clients/types.utils.d.ts +1 -0
- package/dist/src/NodeManager/configs/configs.d.ts +2 -1
- package/dist/src/NodeManager/configs/configs.js +1 -0
- package/dist/src/NodeManager/db/index.d.ts +44 -11
- package/dist/src/NodeManager/db/index.js +3 -5
- package/dist/src/NodeManager/errors/NodeNotQualifiedError.js +2 -2
- package/dist/src/NodeManager/index.js +14 -25
- package/dist/src/NodeManager/input/OperatorInput.d.ts +2 -0
- package/dist/src/NodeManager/jobs/index.d.ts +6 -1
- package/dist/src/NodeManager/jobs/index.js +45 -2
- package/dist/src/NodeManager/monitoring/log/NodeLog.d.ts +8 -6
- package/dist/src/NodeManager/monitoring/log/NodeLog.js +461 -38
- package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.d.ts +1 -0
- package/dist/src/NodeManager/monitoring/log/console/ConsoleLogger.js +5 -5
- package/dist/{packages/common/src → src/NodeManager/monitoring/proxy}/loggingProxy.d.ts +1 -0
- package/dist/{packages/common/src → src/NodeManager/monitoring/proxy}/loggingProxy.js +1 -0
- package/dist/src/NodeManager/monitoring/reportError.js +3 -2
- package/dist/src/NodeManager/monitoring/state/NodeState.d.ts +1 -1
- package/dist/src/NodeManager/monitoring/state/NodeState.js +29 -1
- package/dist/src/NodeManager/node/Node.d.ts +8 -28
- package/dist/src/NodeManager/node/Node.js +45 -81
- package/dist/src/NodeManager/node/api/ApiEventEmitter.d.ts +1 -0
- package/dist/src/NodeManager/node/api/ApiHandler.d.ts +7 -21
- package/dist/src/NodeManager/node/api/ApiHandler.js +46 -67
- package/dist/src/NodeManager/node/api/eventsource/index.d.ts +6 -0
- package/dist/src/NodeManager/node/api/middlewares/index.d.ts +1 -0
- package/dist/src/NodeManager/node/api/middlewares/index.js +2 -0
- package/dist/src/NodeManager/node/api/middlewares/rest/verifyJobOwnerSignatureMiddleware.d.ts +5 -0
- package/dist/src/NodeManager/node/api/middlewares/rest/verifyJobOwnerSignatureMiddleware.js +29 -0
- package/dist/src/NodeManager/node/api/middlewares/ws/verifyWSJobOwnerSignatureMiddleware.js +8 -6
- package/dist/src/NodeManager/node/api/routes/get/index.d.ts +7 -0
- package/dist/src/NodeManager/node/api/routes/get/index.js +7 -0
- package/dist/src/NodeManager/node/api/routes/get/job-definition.d.ts +5 -0
- package/dist/src/NodeManager/node/api/routes/get/job-definition.js +16 -0
- package/dist/src/NodeManager/node/api/routes/get/job-info/buildInfoObject.d.ts +17 -0
- package/dist/src/NodeManager/node/api/routes/get/job-info/buildInfoObject.js +15 -0
- package/dist/src/NodeManager/node/api/routes/get/job-info/job-info.d.ts +5 -0
- package/dist/src/NodeManager/node/api/routes/get/job-info/job-info.js +18 -0
- package/dist/src/NodeManager/node/api/routes/get/job-info/pollActiveJob.d.ts +6 -0
- package/dist/src/NodeManager/node/api/routes/get/job-info/pollActiveJob.js +42 -0
- package/dist/src/NodeManager/node/api/routes/get/job-operation-info.d.ts +28 -0
- package/dist/src/NodeManager/node/api/routes/get/job-operation-info.js +53 -0
- package/dist/src/NodeManager/node/api/routes/get/job-results.d.ts +5 -0
- package/dist/src/NodeManager/node/api/routes/get/job-results.js +15 -0
- package/dist/src/NodeManager/node/api/routes/get/job-stats-stream.d.ts +5 -0
- package/dist/{packages/job-runtime/src/api/routes/stats.js → src/NodeManager/node/api/routes/get/job-stats-stream.js} +5 -25
- package/dist/src/NodeManager/node/api/routes/get/job-stats.d.ts +5 -0
- package/dist/src/NodeManager/node/api/routes/get/job-stats.js +22 -0
- package/dist/src/NodeManager/node/api/routes/get/service-url.d.ts +5 -0
- package/dist/src/NodeManager/node/api/routes/get/service-url.js +27 -0
- package/dist/src/NodeManager/node/api/routes/index.d.ts +1 -0
- package/dist/src/NodeManager/node/api/routes/index.js +1 -0
- package/dist/src/NodeManager/node/api/routes/post/index.d.ts +4 -0
- package/dist/src/NodeManager/node/api/routes/post/index.js +4 -0
- package/dist/src/NodeManager/node/api/routes/post/job-definition.d.ts +6 -0
- package/dist/src/NodeManager/node/api/routes/post/job-definition.js +15 -0
- package/dist/src/NodeManager/node/api/routes/post/job-operation-actions.d.ts +20 -0
- package/dist/src/NodeManager/node/api/routes/post/job-operation-actions.js +63 -0
- package/dist/src/NodeManager/node/api/routes/post/service-stop.d.ts +5 -0
- package/dist/src/NodeManager/node/api/routes/post/service-stop.js +13 -0
- package/dist/src/NodeManager/node/api/routes/post/ssh-authorize.d.ts +17 -0
- package/dist/src/NodeManager/node/api/routes/post/ssh-authorize.js +53 -0
- package/dist/src/NodeManager/node/api/routes/wss/index.d.ts +2 -0
- package/dist/src/NodeManager/node/api/routes/wss/index.js +2 -0
- package/dist/src/NodeManager/node/api/routes/wss/log.d.ts +9 -0
- package/dist/src/NodeManager/node/api/routes/wss/log.js +55 -2
- package/dist/src/NodeManager/node/api/routes/wss/status.js +4 -2
- package/dist/{packages/job-runtime/src/api/terminal/terminalBridge.d.ts → src/NodeManager/node/api/routes/wss/terminal/terminal.d.ts} +7 -6
- package/dist/{packages/job-runtime/src/api/terminal/terminalBridge.js → src/NodeManager/node/api/routes/wss/terminal/terminal.js} +23 -15
- package/dist/{packages/job-runtime/src/api → src/NodeManager/node/api/routes/wss}/terminal/terminalAuthorization.d.ts +1 -0
- package/dist/{packages/job-runtime/src/api → src/NodeManager/node/api/routes/wss}/terminal/terminalAuthorization.js +3 -3
- package/dist/src/NodeManager/node/api/types/index.d.ts +2 -2
- package/dist/{packages/job-runtime/src/api → src/NodeManager/node/api/utils}/interval.d.ts +5 -2
- package/dist/{packages/job-runtime/src/api → src/NodeManager/node/api/utils}/interval.js +1 -1
- package/dist/src/NodeManager/node/balance/balanceHandler.d.ts +5 -4
- package/dist/src/NodeManager/node/balance/balanceHandler.js +5 -6
- package/dist/src/NodeManager/node/expiry/expiryHandler.d.ts +10 -2
- package/dist/src/NodeManager/node/expiry/expiryHandler.js +36 -8
- package/dist/src/NodeManager/node/grid/gridHandler.d.ts +13 -0
- package/dist/src/NodeManager/node/grid/gridHandler.js +35 -0
- package/dist/src/NodeManager/node/health/healthHandler.d.ts +4 -3
- package/dist/src/NodeManager/node/health/healthHandler.js +8 -5
- package/dist/src/NodeManager/node/job/JobRegistry.d.ts +6 -16
- package/dist/src/NodeManager/node/job/JobRegistry.js +22 -68
- package/dist/src/NodeManager/node/job/defination/JobDefinitionStrategy.d.ts +13 -0
- package/dist/src/NodeManager/node/job/defination/JobDefinitionStrategy.js +21 -0
- package/dist/src/NodeManager/node/job/defination/strategy/ApiJobDefinitionStrategy.d.ts +8 -0
- package/dist/{packages/job-runtime/src/logistics/definition → src/NodeManager/node/job/defination/strategy}/ApiJobDefinitionStrategy.js +5 -5
- package/dist/{packages/job-runtime/src/logistics/definition → src/NodeManager/node/job/defination/strategy}/ApiListenJobDefinitionStrategy.d.ts +3 -2
- package/dist/src/NodeManager/node/job/defination/strategy/IpfsJobDefinitionStrategy.d.ts +5 -0
- package/dist/src/NodeManager/node/job/defination/strategy/IpfsJobDefinitionStrategy.js +11 -0
- package/dist/src/NodeManager/node/job/jobExternalUtil.d.ts +10 -0
- package/dist/src/NodeManager/node/job/jobExternalUtil.js +96 -0
- package/dist/src/NodeManager/node/job/jobHandler.d.ts +14 -78
- package/dist/src/NodeManager/node/job/jobHandler.js +129 -224
- package/dist/src/NodeManager/node/job/result/ResultReturnStrategy.d.ts +13 -0
- package/dist/src/NodeManager/node/job/result/ResultReturnStrategy.js +21 -0
- package/dist/{packages/job-runtime/src/logistics/result → src/NodeManager/node/job/result/startegy}/ApiListenResultReturnStrategy.d.ts +2 -1
- package/dist/src/NodeManager/node/job/result/startegy/ApiResultReturnStrategy.d.ts +8 -0
- package/dist/{packages/job-runtime/src/logistics/result → src/NodeManager/node/job/result/startegy}/ApiResultReturnStrategy.js +5 -5
- package/dist/src/NodeManager/node/key/keyHandler.d.ts +9 -15
- package/dist/src/NodeManager/node/key/keyHandler.js +9 -18
- package/dist/src/NodeManager/node/market/benchmark.d.ts +4 -11
- package/dist/src/NodeManager/node/market/benchmark.js +40 -55
- package/dist/src/NodeManager/node/market/hostManager.d.ts +16 -14
- package/dist/src/NodeManager/node/market/hostManager.js +12 -0
- package/dist/src/NodeManager/node/market/marketAccess.d.ts +3 -9
- package/dist/src/NodeManager/node/market/marketAccess.js +9 -27
- package/dist/src/NodeManager/node/market/marketHandler.d.ts +7 -11
- package/dist/src/NodeManager/node/market/marketHandler.js +18 -33
- package/dist/src/NodeManager/node/register/index.js +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createResourceName.d.ts +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createResourceName.js +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createS3Args.d.ts +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createS3Args.js +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/isAuthGatedResource.d.ts +1 -1
- package/dist/src/NodeManager/node/resource/image/imageManager.d.ts +16 -12
- package/dist/src/NodeManager/node/resource/image/imageManager.js +35 -21
- package/dist/src/NodeManager/node/resource/resourceManager.d.ts +10 -26
- package/dist/src/NodeManager/node/resource/resourceManager.js +40 -48
- package/dist/src/NodeManager/node/resource/volume/volumeManager.d.ts +75 -11
- package/dist/src/NodeManager/node/resource/volume/volumeManager.js +347 -25
- package/dist/src/NodeManager/node/run/runHandler.d.ts +4 -17
- package/dist/src/NodeManager/node/run/runHandler.js +46 -69
- package/dist/src/NodeManager/node/stake/StakeHandler.d.ts +5 -18
- package/dist/src/NodeManager/node/stake/StakeHandler.js +24 -56
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/TaskManager.d.ts +47 -16
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/TaskManager.js +59 -20
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/createExecutionPlan.js +1 -0
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/createOperationMap.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/finalizeEnv.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/interpolateOperation.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setDefaults.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setDefaults.js +13 -10
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/stanatizeArrays.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/transformCollections.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/helpers/createDefaultOpState.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/helpers/createInitialFlow.d.ts +2 -2
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/loggers/StatsBuffer.d.ts +1 -1
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/enforceOperationTimeout.d.ts +1 -0
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/runTaskManagerOperation.d.ts +2 -2
- package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/runTaskManagerOperation.js +3 -2
- package/dist/{packages/job-runtime/src/resources/helpers → src/NodeManager/node/utils}/extractLogsAndResultsFromLogBuffer.d.ts +3 -1
- package/dist/{packages/job-runtime/src/resources/helpers → src/NodeManager/node/utils}/extractLogsAndResultsFromLogBuffer.js +2 -2
- package/dist/{packages/common/src → src/NodeManager/node/utils}/extractResultsFromLogs.d.ts +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/utils}/multiProgressBarReporter.d.ts +2 -4
- package/dist/src/NodeManager/node/utils/multiProgressBarReporter.js +22 -0
- package/dist/src/NodeManager/node/utils/poll.d.ts +1 -1
- package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/utils}/progressBarReporter.d.ts +2 -4
- package/dist/src/NodeManager/node/utils/progressBarReporter.js +28 -0
- package/dist/{packages/job-runtime/src → src/NodeManager}/provider/ContainerStateManager.d.ts +3 -10
- package/dist/{packages/job-runtime/src → src/NodeManager}/provider/ContainerStateManager.js +5 -23
- package/dist/{packages/job-runtime/src → src/NodeManager}/provider/ExposedPortHealthCheck.d.ts +5 -4
- package/dist/src/NodeManager/provider/Provider.d.ts +92 -69
- package/dist/src/NodeManager/provider/Provider.js +534 -205
- package/dist/{packages/job-runtime/src → src/NodeManager}/provider/SshAccessManager.d.ts +4 -4
- package/dist/src/NodeManager/provider/orchestrationHooks.js +2 -2
- package/dist/{packages/job-runtime/src → src/NodeManager}/provider/sshSidecar.d.ts +7 -7
- package/dist/{packages/job-runtime/src → src/NodeManager}/provider/sshSidecar.js +4 -2
- package/dist/src/NodeManager/provider/types.d.ts +9 -0
- package/dist/{packages/container-orchestrator/src → src/NodeManager/provider}/utils/parseBuffer.d.ts +3 -1
- package/dist/{packages/job-runtime/src/provider → src/NodeManager/provider/utils}/parseDockerStat.d.ts +1 -1
- package/dist/src/NodeManager/provider/webTerminal.d.ts +24 -0
- package/dist/{packages/job-runtime/src/api/runtime/terminal.js → src/NodeManager/provider/webTerminal.js} +9 -13
- package/dist/src/NodeManager/repository/NodeRepository.d.ts +41 -5
- package/dist/src/NodeManager/repository/NodeRepository.js +155 -8
- package/dist/src/NodeManager/sdk/index.d.ts +9 -6
- package/dist/src/NodeManager/sdk/index.js +94 -78
- package/dist/src/NodeManager/types/index.d.ts +9 -0
- package/dist/src/NodeManager/utils/expose-util.d.ts +14 -0
- package/dist/{packages/job-runtime/src/provider/expose.js → src/NodeManager/utils/expose-util.js} +39 -8
- package/dist/src/NodeManager/utils/jobDefinitionParser.d.ts +4 -0
- package/dist/src/NodeManager/utils/jobDefinitionParser.js +7 -1
- package/dist/src/NodeManager/utils/ops-util.d.ts +3 -0
- package/dist/src/NodeManager/utils/ops-util.js +19 -0
- package/dist/src/NodeManager/utils/tolerateBrokenStdio.d.ts +1 -0
- package/dist/src/NodeManager/utils/utils.d.ts +2 -1
- package/dist/src/NodeManager/utils/utils.js +4 -1
- package/dist/src/cli/commands/address/action.js +2 -3
- package/dist/src/cli/commands/run/action.d.ts +0 -5
- package/dist/src/cli/commands/run/action.js +18 -65
- package/dist/src/cli/commands/run/generateDeploymentEndpointsTable.d.ts +2 -2
- package/dist/src/cli/commands/run/generateDeploymentEndpointsTable.js +5 -6
- package/dist/src/cli/commands/sharedOptions/--api.d.ts +2 -0
- package/dist/src/cli/commands/sharedOptions/--api.js +2 -0
- package/dist/src/cli/commands/sharedOptions/--tee-runtime.js +1 -1
- package/dist/src/cli/commands/sharedOptions/--timeout.d.ts +2 -0
- package/dist/src/cli/commands/sharedOptions/--timeout.js +12 -0
- package/dist/src/cli/commands/start/action.d.ts +1 -0
- package/dist/src/cli/commands/start/action.js +1 -0
- package/dist/src/cli/createNosanaCli.js +4 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/ipfs/IpfsClient.d.ts +1 -3
- package/dist/src/ipfs/IpfsClient.js +1 -1
- package/dist/src/output-formatter/outputEvents.d.ts +1 -1
- package/dist/src/static/index.d.ts +1 -1
- package/npm-shrinkwrap.json +1466 -3257
- package/package.json +9 -10
- package/dist/packages/common/src/OperationError.d.ts +0 -14
- package/dist/packages/common/src/OperationError.js +0 -18
- package/dist/packages/common/src/expose-id.d.ts +0 -12
- package/dist/packages/common/src/expose-id.js +0 -23
- package/dist/packages/common/src/index.d.ts +0 -11
- package/dist/packages/common/src/index.js +0 -11
- package/dist/packages/common/src/jobPhaseLog.d.ts +0 -42
- package/dist/packages/common/src/jobPhaseLog.js +0 -207
- package/dist/packages/job-runtime/src/api/eventsource.d.ts +0 -6
- package/dist/packages/job-runtime/src/api/middlewares/verifyJobOwnerSignature.d.ts +0 -13
- package/dist/packages/job-runtime/src/api/middlewares/verifyJobOwnerSignature.js +0 -39
- package/dist/packages/job-runtime/src/api/middlewares/verifyWSSignatures.d.ts +0 -10
- package/dist/packages/job-runtime/src/api/middlewares/verifyWSSignatures.js +0 -34
- package/dist/packages/job-runtime/src/api/paths.d.ts +0 -52
- package/dist/packages/job-runtime/src/api/paths.js +0 -52
- package/dist/packages/job-runtime/src/api/router.d.ts +0 -10
- package/dist/packages/job-runtime/src/api/router.js +0 -64
- package/dist/packages/job-runtime/src/api/routes/definitionAndResults.d.ts +0 -8
- package/dist/packages/job-runtime/src/api/routes/definitionAndResults.js +0 -69
- package/dist/packages/job-runtime/src/api/routes/info.d.ts +0 -23
- package/dist/packages/job-runtime/src/api/routes/info.js +0 -69
- package/dist/packages/job-runtime/src/api/routes/operations.d.ts +0 -36
- package/dist/packages/job-runtime/src/api/routes/operations.js +0 -120
- package/dist/packages/job-runtime/src/api/routes/ssh.d.ts +0 -11
- package/dist/packages/job-runtime/src/api/routes/ssh.js +0 -83
- package/dist/packages/job-runtime/src/api/routes/stats.d.ts +0 -4
- package/dist/packages/job-runtime/src/api/runtime/terminal.d.ts +0 -15
- package/dist/packages/job-runtime/src/api/types.d.ts +0 -170
- package/dist/packages/job-runtime/src/api/wsClose.d.ts +0 -6
- package/dist/packages/job-runtime/src/api/wsClose.js +0 -10
- package/dist/packages/job-runtime/src/api/wsHandler.d.ts +0 -10
- package/dist/packages/job-runtime/src/api/wsHandler.js +0 -145
- package/dist/packages/job-runtime/src/chain.d.ts +0 -28
- package/dist/packages/job-runtime/src/chain.js +0 -72
- package/dist/packages/job-runtime/src/config.d.ts +0 -39
- package/dist/packages/job-runtime/src/config.js +0 -57
- package/dist/packages/job-runtime/src/host/HostClient.d.ts +0 -29
- package/dist/packages/job-runtime/src/host/HostClient.js +0 -91
- package/dist/packages/job-runtime/src/host/contract.d.ts +0 -171
- package/dist/packages/job-runtime/src/host/contract.js +0 -163
- package/dist/packages/job-runtime/src/host/hostPorts.d.ts +0 -7
- package/dist/packages/job-runtime/src/host/hostPorts.js +0 -13
- package/dist/packages/job-runtime/src/host/index.d.ts +0 -10
- package/dist/packages/job-runtime/src/host/index.js +0 -10
- package/dist/packages/job-runtime/src/logistics/JobDefinitionStrategy.d.ts +0 -21
- package/dist/packages/job-runtime/src/logistics/JobDefinitionStrategy.js +0 -27
- package/dist/packages/job-runtime/src/logistics/ResultReturnStrategy.d.ts +0 -21
- package/dist/packages/job-runtime/src/logistics/ResultReturnStrategy.js +0 -27
- package/dist/packages/job-runtime/src/logistics/definition/ApiJobDefinitionStrategy.d.ts +0 -11
- package/dist/packages/job-runtime/src/logistics/ports.d.ts +0 -10
- package/dist/packages/job-runtime/src/logistics/ports.js +0 -1
- package/dist/packages/job-runtime/src/logistics/result/ApiResultReturnStrategy.d.ts +0 -11
- package/dist/packages/job-runtime/src/main.d.ts +0 -1
- package/dist/packages/job-runtime/src/main.js +0 -83
- package/dist/packages/job-runtime/src/provider/ContainerProvider.d.ts +0 -82
- package/dist/packages/job-runtime/src/provider/ContainerProvider.js +0 -449
- package/dist/packages/job-runtime/src/provider/expose.d.ts +0 -12
- package/dist/packages/job-runtime/src/provider/gpu/gpuSampler.d.ts +0 -24
- package/dist/packages/job-runtime/src/provider/gpu/gpuSampler.js +0 -97
- package/dist/packages/job-runtime/src/provider/gpu/gpuStats.d.ts +0 -63
- package/dist/packages/job-runtime/src/provider/gpu/gpuStats.js +0 -144
- package/dist/packages/job-runtime/src/provider/ports.d.ts +0 -59
- package/dist/packages/job-runtime/src/provider/ports.js +0 -1
- package/dist/packages/job-runtime/src/resources/FileResourceRecords.d.ts +0 -21
- package/dist/packages/job-runtime/src/resources/FileResourceRecords.js +0 -53
- package/dist/packages/job-runtime/src/resources/ImageCache.d.ts +0 -35
- package/dist/packages/job-runtime/src/resources/ImageCache.js +0 -55
- package/dist/packages/job-runtime/src/resources/VolumeCache.d.ts +0 -110
- package/dist/packages/job-runtime/src/resources/VolumeCache.js +0 -359
- package/dist/packages/job-runtime/src/resources/index.d.ts +0 -13
- package/dist/packages/job-runtime/src/resources/index.js +0 -13
- package/dist/packages/job-runtime/src/resources/jobResources.d.ts +0 -12
- package/dist/packages/job-runtime/src/resources/jobResources.js +0 -88
- package/dist/packages/job-runtime/src/resources/multiProgressBarReporter.js +0 -12
- package/dist/packages/job-runtime/src/resources/progressBarReporter.js +0 -12
- package/dist/packages/job-runtime/src/resources/records.d.ts +0 -67
- package/dist/packages/job-runtime/src/resources/records.js +0 -6
- package/dist/packages/job-runtime/src/runtime/RuntimeLog.d.ts +0 -26
- package/dist/packages/job-runtime/src/runtime/RuntimeLog.js +0 -79
- package/dist/packages/job-runtime/src/runtime/retrieveJobDefinition.d.ts +0 -6
- package/dist/packages/job-runtime/src/runtime/retrieveJobDefinition.js +0 -19
- package/dist/packages/job-runtime/src/runtime/runJob.d.ts +0 -31
- package/dist/packages/job-runtime/src/runtime/runJob.js +0 -534
- package/dist/packages/job-runtime/src/runtime/streams.d.ts +0 -32
- package/dist/packages/job-runtime/src/runtime/streams.js +0 -81
- package/dist/packages/job-runtime/src/server.d.ts +0 -23
- package/dist/packages/job-runtime/src/server.js +0 -66
- package/dist/packages/job-runtime/src/store/FlowStore.d.ts +0 -62
- package/dist/packages/job-runtime/src/store/FlowStore.js +0 -170
- package/dist/packages/job-runtime/src/taskManager/index.d.ts +0 -11
- package/dist/packages/job-runtime/src/taskManager/index.js +0 -8
- package/dist/packages/job-runtime/src/taskManager/ports/FlowRepository.d.ts +0 -22
- package/dist/packages/job-runtime/src/taskManager/ports/FlowRepository.js +0 -1
- package/dist/packages/job-runtime/src/taskManager/ports/OrchestrationProvider.d.ts +0 -24
- package/dist/packages/job-runtime/src/taskManager/ports/OrchestrationProvider.js +0 -1
- package/dist/packages/job-runtime/src/taskManager/ports/TaskContext.d.ts +0 -9
- package/dist/packages/job-runtime/src/taskManager/ports/TaskContext.js +0 -1
- package/dist/packages/job-runtime/src/taskManager/ports/index.d.ts +0 -3
- package/dist/packages/job-runtime/src/taskManager/ports/index.js +0 -1
- package/dist/packages/job-runtime/src/taskManager/runtimeConfig.d.ts +0 -23
- package/dist/packages/job-runtime/src/taskManager/runtimeConfig.js +0 -14
- package/dist/packages/job-runtime/src/taskManager/stopReasons.d.ts +0 -10
- package/dist/packages/job-runtime/src/taskManager/stopReasons.js +0 -9
- package/dist/packages/job-runtime/src/taskManager/types.d.ts +0 -53
- package/dist/packages/job-runtime/src/taskManager/types.js +0 -3
- package/dist/packages/job-runtime/src/utils/abort.d.ts +0 -17
- package/dist/packages/job-runtime/src/utils/abort.js +0 -55
- package/dist/packages/job-runtime/src/utils/files.d.ts +0 -7
- package/dist/packages/job-runtime/src/utils/files.js +0 -19
- package/dist/src/NodeManager/node/api/jobRuntimeProxy.d.ts +0 -29
- package/dist/src/NodeManager/node/api/jobRuntimeProxy.js +0 -105
- package/dist/src/NodeManager/node/job/JobRuntimeHost.d.ts +0 -26
- package/dist/src/NodeManager/node/job/JobRuntimeHost.js +0 -87
- package/dist/src/NodeManager/node/job/JobRuntimeSession.d.ts +0 -91
- package/dist/src/NodeManager/node/job/JobRuntimeSession.js +0 -213
- package/dist/src/NodeManager/node/utils/subscription.d.ts +0 -8
- package/dist/src/NodeManager/node/utils/subscription.js +0 -37
- package/dist/src/cli/commands/run/jobRuntimeConsole.d.ts +0 -10
- package/dist/src/cli/commands/run/jobRuntimeConsole.js +0 -26
- /package/dist/{packages/job-runtime/src/api/eventsource.js → src/NodeManager/node/api/eventsource/index.js} +0 -0
- /package/dist/{packages/job-runtime/src/logistics/definition → src/NodeManager/node/job/defination/strategy}/ApiListenJobDefinitionStrategy.js +0 -0
- /package/dist/{packages/job-runtime/src/logistics/result → src/NodeManager/node/job/result/startegy}/ApiListenResultReturnStrategy.js +0 -0
- /package/dist/{packages/job-runtime/src/resources/helpers/nosanaBucket.d.ts → src/NodeManager/node/resource/definition/index.d.ts} +0 -0
- /package/dist/{packages/job-runtime/src/resources/helpers/nosanaBucket.js → src/NodeManager/node/resource/definition/index.js} +0 -0
- /package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createHFArgs.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createHFArgs.js +0 -0
- /package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createOllamaArgs.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/createOllamaArgs.js +0 -0
- /package/dist/{packages/job-runtime/src/resources → src/NodeManager/node/resource}/helpers/isAuthGatedResource.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/TaskManagerRegistry.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/TaskManagerRegistry.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/createDependencyMap.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/createDependencyMap.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/createExecutionPlan.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/createOperationMap.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/validateExecutionPlan.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/executions/validateExecutionPlan.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/finalizeEnv.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/getByPath.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/getByPath.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/index.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/index.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/interpolate.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/interpolate.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/interpolateOperation.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/resolveLiteralsInString.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/resolveLiteralsInString.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setContainerIp.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setContainerIp.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setHost.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setHost.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setResult.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setResult.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setResults.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/setResults.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/stanatizeArrays.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/globalStore/transformCollections.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/helpers/createDefaultOpState.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/helpers/createInitialFlow.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/loggers/StatsBuffer.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/loggers/logManager.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/loggers/logManager.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/loggers/statsManager.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/loggers/statsManager.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/enforceOperationTimeout.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/getOperationsInfos.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/getOperationsInfos.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/restartTaskManagerGroupOperation.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/restartTaskManagerGroupOperation.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/restartTaskManagerOperation.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/restartTaskManagerOperation.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/stopAllTaskManagerOperations.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/stopAllTaskManagerOperations.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/stopTaskManagerGroupOperation.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/stopTaskManagerGroupOperation.js +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/stopTaskManagerOperation.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/taskManager → src/NodeManager/node/task}/operations/stopTaskManagerOperation.js +0 -0
- /package/dist/{packages/job-runtime/src/resources/helpers → src/NodeManager/node/utils}/convertFromBytes.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/resources/helpers → src/NodeManager/node/utils}/convertFromBytes.js +0 -0
- /package/dist/{packages/common/src → src/NodeManager/node/utils}/extractResultsFromLogs.js +0 -0
- /package/dist/{packages/job-runtime/src → src/NodeManager}/provider/ExposedPortHealthCheck.js +0 -0
- /package/dist/{packages/job-runtime/src → src/NodeManager}/provider/SshAccessManager.js +0 -0
- /package/dist/{packages/job-runtime/src/api → src/NodeManager/provider}/types.js +0 -0
- /package/dist/{packages/container-orchestrator/src → src/NodeManager/provider}/utils/parseBuffer.js +0 -0
- /package/dist/{packages/job-runtime/src/provider → src/NodeManager/provider/utils}/parseDockerStat.js +0 -0
- /package/dist/{packages/common/src → src/NodeManager/utils}/formatTime.d.ts +0 -0
- /package/dist/{packages/common/src → src/NodeManager/utils}/formatTime.js +0 -0
- /package/dist/{packages/job-runtime/src/provider → src/NodeManager/utils}/timeoutPromiseWrapper.d.ts +0 -0
- /package/dist/{packages/job-runtime/src/provider → src/NodeManager/utils}/timeoutPromiseWrapper.js +0 -0
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import type { EventEmitter } from 'events';
|
|
2
|
-
import type { IncomingHttpHeaders } from 'http';
|
|
3
|
-
import type { Duplex } from 'stream';
|
|
4
|
-
import type WebSocket from 'ws';
|
|
5
|
-
import type { Request } from 'express';
|
|
6
|
-
import type { Address, Flow, FlowState } from '@nosana/kit';
|
|
7
|
-
/**
|
|
8
|
-
* The job-facing API surface, extracted behind ports so the same routes,
|
|
9
|
-
* middlewares and WebSocket protocol can be served by any composition host.
|
|
10
|
-
* The package never reaches into the host: everything it reads or drives
|
|
11
|
-
* arrives through {@link JobRuntimeDeps}. Paths are relative to wherever the host
|
|
12
|
-
* mounts the handler (the node mounts it at `/job/:jobId`).
|
|
13
|
-
*/
|
|
14
|
-
/** The minimal onchain job view auth needs: owner key + timeout for expiry,
|
|
15
|
-
* and the assigned node a terminal grant must name. */
|
|
16
|
-
export interface JobAccountView {
|
|
17
|
-
project: Address;
|
|
18
|
-
timeout: number;
|
|
19
|
-
node: string;
|
|
20
|
-
}
|
|
21
|
-
/** Read-only onchain job lookup (e.g. `kit.jobs`). Needs no keys. */
|
|
22
|
-
export interface JobChainResolver {
|
|
23
|
-
get(jobAddress: string): Promise<JobAccountView | null>;
|
|
24
|
-
}
|
|
25
|
-
/** Signature validation (the kit's `validate` and `validateHeaders`), against
|
|
26
|
-
* the signer's public key bytes. Validation-only — the server side never
|
|
27
|
-
* generates headers, so no wallet is required. Both throw on a header that is
|
|
28
|
-
* malformed, signed over another message or expired (`expiry` in seconds),
|
|
29
|
-
* and return whether the signature verifies. */
|
|
30
|
-
export interface AuthValidator {
|
|
31
|
-
validate(authHeader: string, publicKey: Uint8Array, options?: {
|
|
32
|
-
expected_message?: string;
|
|
33
|
-
}): boolean;
|
|
34
|
-
validateHeaders(headers: IncomingHttpHeaders, publicKey: Uint8Array, options: {
|
|
35
|
-
key: string;
|
|
36
|
-
expiry: number;
|
|
37
|
-
expected_message?: string;
|
|
38
|
-
}): boolean;
|
|
39
|
-
}
|
|
40
|
-
/** The job's flow records, read-only (the node's `NodeRepository`). */
|
|
41
|
-
export interface FlowReader {
|
|
42
|
-
getFlow(id: string): Flow | undefined;
|
|
43
|
-
getFlowState(id: string): FlowState | undefined;
|
|
44
|
-
}
|
|
45
|
-
import type { GpuFigures, LogType, TaskLog, TaskStat } from '../taskManager/types.js';
|
|
46
|
-
export type { GpuFigures, LogType, TaskLog, TaskStat };
|
|
47
|
-
type OperationsStatus = Record<string, string | null>;
|
|
48
|
-
/** The part of a running job's task manager the routes read and drive. */
|
|
49
|
-
export interface TaskView {
|
|
50
|
-
getOperationsStatus(): OperationsStatus;
|
|
51
|
-
getOperationStatus(opId: string): OperationsStatus | undefined;
|
|
52
|
-
getGroupStatus(group: string): OperationsStatus | undefined;
|
|
53
|
-
getCurrentGroupStatus(): OperationsStatus;
|
|
54
|
-
getCurrentGroup(): string | undefined;
|
|
55
|
-
getEventsEmitter(): EventEmitter;
|
|
56
|
-
subscribe(ws: WebSocket, matcher: (log: TaskLog) => boolean): void;
|
|
57
|
-
/** `limit`: at most this many of the newest lines; all without one. */
|
|
58
|
-
getLogsByOp(opId: string, limit?: number): TaskLog[];
|
|
59
|
-
getLogsByGroup(group: string, limit?: number): TaskLog[];
|
|
60
|
-
getAllLogs(limit?: number): TaskLog[];
|
|
61
|
-
queryStats(start?: number, end?: number, intervalMs?: number): TaskStat[];
|
|
62
|
-
getLatestStatPerOp(since: number): TaskStat[];
|
|
63
|
-
stopTaskManagerOperation(group: string, opId: string): Promise<void>;
|
|
64
|
-
stopTaskManagerGroupOperations(group: string): Promise<void>;
|
|
65
|
-
restartTaskManagerOperation(group: string, opId: string): Promise<void>;
|
|
66
|
-
restartTaskManagerGroupOperations(group: string): Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
/** Live task lookup (the shape of `TaskManagerRegistry`). */
|
|
69
|
-
export interface TaskSource {
|
|
70
|
-
get(jobId: string): TaskView | undefined;
|
|
71
|
-
}
|
|
72
|
-
/** A per-job WebSocket stream (log or state) the host feeds. */
|
|
73
|
-
export interface StreamSource {
|
|
74
|
-
subscribe(ws: WebSocket, jobId: string): void;
|
|
75
|
-
unsubscribe(ws: WebSocket): void;
|
|
76
|
-
}
|
|
77
|
-
/** A job's SSH key grant: the key, plus its ISO 8601 UTC expiry if it has one. */
|
|
78
|
-
export interface SshKeyGrantView {
|
|
79
|
-
sshPublicKey: string;
|
|
80
|
-
expiresAt?: string;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Key management for a job's SSH sidecars (the host's Provider). Errors
|
|
84
|
-
* carrying a numeric `status` (e.g. 404 inactive job, 503 SSH not enabled)
|
|
85
|
-
* are answered with it; any other error is a 502.
|
|
86
|
-
*/
|
|
87
|
-
export interface SshAccessPort {
|
|
88
|
-
authorize(jobId: string, sshPublicKey: string, expiresAt?: string): Promise<void>;
|
|
89
|
-
list(jobId: string): Promise<SshKeyGrantView[]>;
|
|
90
|
-
revoke(jobId: string, sshPublicKey: string): Promise<void>;
|
|
91
|
-
}
|
|
92
|
-
/** An interactive PTY exec in one of the job's containers. */
|
|
93
|
-
export interface JobTerminalSession {
|
|
94
|
-
stream: Duplex;
|
|
95
|
-
resize: (size: {
|
|
96
|
-
cols?: number;
|
|
97
|
-
rows?: number;
|
|
98
|
-
}) => Promise<void>;
|
|
99
|
-
inspectExitCode: () => Promise<number | null>;
|
|
100
|
-
close: () => void;
|
|
101
|
-
}
|
|
102
|
-
/** Opens a terminal session for a job (the host's Provider). `op` narrows it
|
|
103
|
-
* to one operation's container. */
|
|
104
|
-
export type JobTerminalPort = (jobId: string, options: {
|
|
105
|
-
op?: string;
|
|
106
|
-
cols?: number;
|
|
107
|
-
rows?: number;
|
|
108
|
-
}) => Promise<JobTerminalSession>;
|
|
109
|
-
/**
|
|
110
|
-
* Everything the job API needs from its composition host. Events carried on
|
|
111
|
-
* `events` (the api-listen flow + stop): 'job-definition' `{jobDefinition, id}`,
|
|
112
|
-
* 'job-result' `{id}`, 'stop-job' `id`.
|
|
113
|
-
*/
|
|
114
|
-
export interface JobRuntimeDeps {
|
|
115
|
-
flows: FlowReader;
|
|
116
|
-
tasks: TaskSource;
|
|
117
|
-
chainJobs: JobChainResolver;
|
|
118
|
-
auth: AuthValidator;
|
|
119
|
-
events: EventEmitter;
|
|
120
|
-
/** Backing stream for WS `/log`. Absent → `/log` subscriptions are refused. */
|
|
121
|
-
logStream?: StreamSource;
|
|
122
|
-
/** Backing stream for WS `/status`. Absent → `/status` refused. */
|
|
123
|
-
stateStream?: StreamSource;
|
|
124
|
-
/** Service tunnel status for `GET /endpoints`. Absent → 'UNKNOWN'. */
|
|
125
|
-
serviceStatus?: (jobId: string) => string;
|
|
126
|
-
/** SSH key management behind `/ssh/*`. Absent → 503. */
|
|
127
|
-
ssh?: SshAccessPort;
|
|
128
|
-
/** Web terminal behind WS `/terminal`. Absent → refused. */
|
|
129
|
-
terminal?: JobTerminalPort;
|
|
130
|
-
/** The cluster a terminal grant must name ('mainnet' | 'devnet'). Absent →
|
|
131
|
-
* WS `/terminal` refused. */
|
|
132
|
-
network?: string;
|
|
133
|
-
/** The node a terminal grant must name. Absent → the job's assigned node
|
|
134
|
-
* (`job.node`). */
|
|
135
|
-
nodeAddress?: string;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* The two route groups. `engine` needs the host's task manager and flow
|
|
139
|
-
* records (info, results, job definition, operations, endpoints, stop, node
|
|
140
|
-
* log and state streams); `runtime` needs only the container runtime (stats,
|
|
141
|
-
* container logs, terminal, SSH keys).
|
|
142
|
-
*/
|
|
143
|
-
export type JobRuntimeGroup = 'engine' | 'runtime';
|
|
144
|
-
export interface JobRuntimeGroupOptions {
|
|
145
|
-
/** The route groups to serve. Default: both. */
|
|
146
|
-
groups?: JobRuntimeGroup[];
|
|
147
|
-
}
|
|
148
|
-
/** Resolve which job a request addresses; `undefined` falls through to the
|
|
149
|
-
* host app's other routes. */
|
|
150
|
-
export type ResolveJobId = (req: Request) => string | undefined;
|
|
151
|
-
/** Express request with the job API context attached by the router. */
|
|
152
|
-
export type JobRuntimeRequest<Params = Record<string, string>, Body = object> = Request<Params, object, Body> & {
|
|
153
|
-
jobRuntime?: {
|
|
154
|
-
jobId: string;
|
|
155
|
-
deps: JobRuntimeDeps;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
/** Body of the WS subscribe message (`{path, header, body}` protocol). */
|
|
159
|
-
export type WSBody = {
|
|
160
|
-
jobAddress: string;
|
|
161
|
-
/** WS `/flog`: one group's logs. */
|
|
162
|
-
group?: string;
|
|
163
|
-
opId?: string;
|
|
164
|
-
type?: string;
|
|
165
|
-
/** WS `/flog`: only replay logs written after this epoch-millisecond mark. */
|
|
166
|
-
since?: number;
|
|
167
|
-
/** WS `/flog`: replay at most this many of the newest lines (default
|
|
168
|
-
* 5000). */
|
|
169
|
-
limit?: number;
|
|
170
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type WebSocket from 'ws';
|
|
2
|
-
/**
|
|
3
|
-
* A close reason is capped at 123 bytes on the wire; ws throws past that after
|
|
4
|
-
* already moving to CLOSING, which would leave the socket hanging.
|
|
5
|
-
*/
|
|
6
|
-
export declare function closeWith(ws: WebSocket, code: number, reason: string): void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A close reason is capped at 123 bytes on the wire; ws throws past that after
|
|
3
|
-
* already moving to CLOSING, which would leave the socket hanging.
|
|
4
|
-
*/
|
|
5
|
-
export function closeWith(ws, code, reason) {
|
|
6
|
-
let text = reason;
|
|
7
|
-
while (Buffer.byteLength(text, 'utf8') > 123)
|
|
8
|
-
text = text.slice(0, -1);
|
|
9
|
-
ws.close(code, text);
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { JobRuntimeDeps, JobRuntimeGroupOptions } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* The job API's WebSocket protocol, as a `wss.on('connection')` handler: the
|
|
5
|
-
* client sends `{path, header, body}` where `body.jobAddress` names the job
|
|
6
|
-
* and `header` carries the owner's signature, then the socket becomes the
|
|
7
|
-
* subscribed stream. Paths outside the served route groups (default: both)
|
|
8
|
-
* are refused like unknown ones.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createJobRuntimeWsConnectionHandler(deps: JobRuntimeDeps, { groups }?: JobRuntimeGroupOptions): (ws: WebSocket) => void;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { JOB_RUNTIME_WS_PATHS } from './paths.js';
|
|
3
|
-
import { ALL_JOB_RUNTIME_GROUPS } from './router.js';
|
|
4
|
-
import { verifyWSJobOwnerSignature } from './middlewares/verifyWSSignatures.js';
|
|
5
|
-
import { wssTerminalRoute } from './terminal/terminalBridge.js';
|
|
6
|
-
/**
|
|
7
|
-
* The lines of history a `/flog` client gets when it doesn't ask for a
|
|
8
|
-
* number. A service that has run for hours has more log than a viewer can
|
|
9
|
-
* use, and every line costs a frame, so the recent end is sent and the rest
|
|
10
|
-
* is left to `since`.
|
|
11
|
-
*/
|
|
12
|
-
const DEFAULT_REPLAY_LIMIT = 5000;
|
|
13
|
-
/** Which route group each WS path belongs to. */
|
|
14
|
-
const WS_PATH_GROUPS = {
|
|
15
|
-
[JOB_RUNTIME_WS_PATHS.log]: 'engine',
|
|
16
|
-
[JOB_RUNTIME_WS_PATHS.status]: 'engine',
|
|
17
|
-
[JOB_RUNTIME_WS_PATHS.flowLog]: 'runtime',
|
|
18
|
-
[JOB_RUNTIME_WS_PATHS.terminal]: 'runtime',
|
|
19
|
-
};
|
|
20
|
-
/** WS `/log`: the host's per-job log stream. */
|
|
21
|
-
function wssLogRoute(deps) {
|
|
22
|
-
return (ws, _, { jobAddress }) => {
|
|
23
|
-
if (!deps.logStream) {
|
|
24
|
-
ws.close(1011, 'log streaming unavailable');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
deps.logStream.subscribe(ws, jobAddress);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/** WS `/flog`: the task (container) log stream, with history replay. */
|
|
31
|
-
function wssTaskManagerLogRoute(deps) {
|
|
32
|
-
return async (ws, _, { jobAddress, group, opId, type, since, limit }) => {
|
|
33
|
-
const deadline = Date.now() + 30_000;
|
|
34
|
-
let task = deps.tasks.get(jobAddress);
|
|
35
|
-
// A run is visible on-chain before the host has finished loading the job
|
|
36
|
-
// definition and registering its TaskManager. Keep the authenticated
|
|
37
|
-
// socket open during that short startup window instead of forcing clients
|
|
38
|
-
// to race it.
|
|
39
|
-
while (!task &&
|
|
40
|
-
Date.now() < deadline &&
|
|
41
|
-
ws.readyState === WebSocket.OPEN) {
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
43
|
-
task = deps.tasks.get(jobAddress);
|
|
44
|
-
}
|
|
45
|
-
if (!task)
|
|
46
|
-
return ws.close(1008, 'Invalid job address');
|
|
47
|
-
task.subscribe(ws, (log) => {
|
|
48
|
-
return ((!group || log.group === group) &&
|
|
49
|
-
(!opId || log.opId === opId) &&
|
|
50
|
-
(!type || log.type === type));
|
|
51
|
-
});
|
|
52
|
-
const cap = typeof limit === 'number' && isFinite(limit) && limit > 0
|
|
53
|
-
? Math.floor(limit)
|
|
54
|
-
: DEFAULT_REPLAY_LIMIT;
|
|
55
|
-
// Historical logs are replayed before the socket returns to the event
|
|
56
|
-
// loop, so a live line can never land among them.
|
|
57
|
-
let logs = opId
|
|
58
|
-
? task.getLogsByOp(opId, cap)
|
|
59
|
-
: group
|
|
60
|
-
? task.getLogsByGroup(group, cap)
|
|
61
|
-
: task.getAllLogs(cap);
|
|
62
|
-
// `cap` took the newest lines first, so this can only trim that window
|
|
63
|
-
// further — never reach past it for more.
|
|
64
|
-
if (typeof since === 'number' && isFinite(since)) {
|
|
65
|
-
logs = logs.filter((log) => log.timestamp > since);
|
|
66
|
-
}
|
|
67
|
-
for (const log of logs) {
|
|
68
|
-
try {
|
|
69
|
-
ws.send(JSON.stringify({ path: 'flog', data: JSON.stringify(log) }));
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
// The client may disconnect while historical logs are being replayed.
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/** WS `/status`: the per-job state stream. */
|
|
78
|
-
function wssStatusRoute(deps) {
|
|
79
|
-
return (ws, _, { jobAddress }) => {
|
|
80
|
-
if (!deps.stateStream) {
|
|
81
|
-
ws.close(1011, 'state streaming unavailable');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
deps.stateStream.subscribe(ws, jobAddress);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* The job API's WebSocket protocol, as a `wss.on('connection')` handler: the
|
|
89
|
-
* client sends `{path, header, body}` where `body.jobAddress` names the job
|
|
90
|
-
* and `header` carries the owner's signature, then the socket becomes the
|
|
91
|
-
* subscribed stream. Paths outside the served route groups (default: both)
|
|
92
|
-
* are refused like unknown ones.
|
|
93
|
-
*/
|
|
94
|
-
export function createJobRuntimeWsConnectionHandler(deps, { groups = ALL_JOB_RUNTIME_GROUPS } = {}) {
|
|
95
|
-
const log = wssLogRoute(deps);
|
|
96
|
-
const flowLog = wssTaskManagerLogRoute(deps);
|
|
97
|
-
const status = wssStatusRoute(deps);
|
|
98
|
-
return (ws) => {
|
|
99
|
-
let keepAliveInterval;
|
|
100
|
-
let terminalActive = false;
|
|
101
|
-
ws.on('message', async (message) => {
|
|
102
|
-
// Once a terminal session has taken over the socket, the terminal
|
|
103
|
-
// route owns all subsequent frames (stdin/resize), so skip the generic
|
|
104
|
-
// JSON dispatch for them.
|
|
105
|
-
if (terminalActive)
|
|
106
|
-
return;
|
|
107
|
-
try {
|
|
108
|
-
const { path, header, body } = JSON.parse(message.toString());
|
|
109
|
-
// One per connection: a client sending many frames must not leave
|
|
110
|
-
// an interval behind for each.
|
|
111
|
-
keepAliveInterval ??= setInterval(() => {
|
|
112
|
-
ws.ping();
|
|
113
|
-
}, 30000);
|
|
114
|
-
switch (groups.includes(WS_PATH_GROUPS[path]) ? path : undefined) {
|
|
115
|
-
case JOB_RUNTIME_WS_PATHS.log:
|
|
116
|
-
await verifyWSJobOwnerSignature(deps, ws, header, body, log);
|
|
117
|
-
break;
|
|
118
|
-
case JOB_RUNTIME_WS_PATHS.flowLog:
|
|
119
|
-
await verifyWSJobOwnerSignature(deps, ws, header, body, flowLog);
|
|
120
|
-
break;
|
|
121
|
-
case JOB_RUNTIME_WS_PATHS.status:
|
|
122
|
-
await verifyWSJobOwnerSignature(deps, ws, header, body, status);
|
|
123
|
-
break;
|
|
124
|
-
case JOB_RUNTIME_WS_PATHS.terminal:
|
|
125
|
-
terminalActive = true;
|
|
126
|
-
await wssTerminalRoute(deps, ws, body);
|
|
127
|
-
break;
|
|
128
|
-
default:
|
|
129
|
-
ws.close(3003, 'Invalid Path');
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
ws.close(1011, 'Internal Server Error');
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
ws.on('close', () => {
|
|
138
|
-
if (keepAliveInterval) {
|
|
139
|
-
clearInterval(keepAliveInterval);
|
|
140
|
-
}
|
|
141
|
-
deps.logStream?.unsubscribe(ws);
|
|
142
|
-
deps.stateStream?.unsubscribe(ws);
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type Job } from '@nosana/kit';
|
|
2
|
-
import type { AuthValidator, JobChainResolver } from './api/types.js';
|
|
3
|
-
export type JobRuntimeNetwork = 'mainnet' | 'devnet';
|
|
4
|
-
/**
|
|
5
|
-
* A resolver that knows one job: any other address is "not found" without a
|
|
6
|
-
* lookup. The sidecar serves one job, and the owner check runs before auth,
|
|
7
|
-
* so this keeps an unauthenticated client from driving RPC calls (or the
|
|
8
|
-
* lookup cache) with addresses of its choosing.
|
|
9
|
-
*/
|
|
10
|
-
export declare function servesOneJob(jobAddress: string, jobs: JobChainResolver): JobChainResolver;
|
|
11
|
-
/** A resolver that answers from its last lookup of a job for the TTL. A
|
|
12
|
-
* lookup that fails or finds no job is not kept. */
|
|
13
|
-
export declare function cacheJobLookups(jobs: JobChainResolver, now?: () => number): JobChainResolver;
|
|
14
|
-
/**
|
|
15
|
-
* Read-only onchain lookups and signature validation: the sidecar never
|
|
16
|
-
* signs, so its client has no wallet (the kit loads none from the
|
|
17
|
-
* environment). `rpcUrl` overrides the network's default RPC, the way the
|
|
18
|
-
* node applies `--rpc`; without it mainnet uses the kit's default public RPC,
|
|
19
|
-
* so whoever starts the sidecar should pass the node's resolved RPC. A job
|
|
20
|
-
* address that is not one fails the lookup without an RPC call.
|
|
21
|
-
*/
|
|
22
|
-
export declare function createJobRuntimeChain(network: JobRuntimeNetwork, rpcUrl?: string): {
|
|
23
|
-
chainJobs: JobChainResolver;
|
|
24
|
-
auth: AuthValidator;
|
|
25
|
-
/** The job's full account, uncached: what the runtime resolves it from. A
|
|
26
|
-
* running job carries its run's node and start. */
|
|
27
|
-
getJob: (jobAddress: string) => Promise<Job>;
|
|
28
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { address, createNosanaClient, validate, validateHeaders, } from '@nosana/kit';
|
|
2
|
-
/**
|
|
3
|
-
* How long one onchain lookup of a job serves requests. Every request and
|
|
4
|
-
* socket resolves the job for its owner's key, and a poller would otherwise
|
|
5
|
-
* cost the RPC a call each time. What auth reads (owner, timeout, node) only
|
|
6
|
-
* changes on a timeout extension, which may show up this much later.
|
|
7
|
-
*/
|
|
8
|
-
const JOB_LOOKUP_TTL_MS = 30_000;
|
|
9
|
-
/**
|
|
10
|
-
* A resolver that knows one job: any other address is "not found" without a
|
|
11
|
-
* lookup. The sidecar serves one job, and the owner check runs before auth,
|
|
12
|
-
* so this keeps an unauthenticated client from driving RPC calls (or the
|
|
13
|
-
* lookup cache) with addresses of its choosing.
|
|
14
|
-
*/
|
|
15
|
-
export function servesOneJob(jobAddress, jobs) {
|
|
16
|
-
return {
|
|
17
|
-
get: (address) => address === jobAddress ? jobs.get(address) : Promise.resolve(null),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/** A resolver that answers from its last lookup of a job for the TTL. A
|
|
21
|
-
* lookup that fails or finds no job is not kept. */
|
|
22
|
-
export function cacheJobLookups(jobs, now = Date.now) {
|
|
23
|
-
const entries = new Map();
|
|
24
|
-
return {
|
|
25
|
-
get(jobAddress) {
|
|
26
|
-
const hit = entries.get(jobAddress);
|
|
27
|
-
if (hit && now() - hit.at < JOB_LOOKUP_TTL_MS)
|
|
28
|
-
return hit.job;
|
|
29
|
-
const job = jobs.get(jobAddress).then((found) => {
|
|
30
|
-
if (!found)
|
|
31
|
-
entries.delete(jobAddress);
|
|
32
|
-
return found;
|
|
33
|
-
}, (error) => {
|
|
34
|
-
entries.delete(jobAddress);
|
|
35
|
-
throw error;
|
|
36
|
-
});
|
|
37
|
-
entries.set(jobAddress, { at: now(), job });
|
|
38
|
-
return job;
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Read-only onchain lookups and signature validation: the sidecar never
|
|
44
|
-
* signs, so its client has no wallet (the kit loads none from the
|
|
45
|
-
* environment). `rpcUrl` overrides the network's default RPC, the way the
|
|
46
|
-
* node applies `--rpc`; without it mainnet uses the kit's default public RPC,
|
|
47
|
-
* so whoever starts the sidecar should pass the node's resolved RPC. A job
|
|
48
|
-
* address that is not one fails the lookup without an RPC call.
|
|
49
|
-
*/
|
|
50
|
-
export function createJobRuntimeChain(network, rpcUrl) {
|
|
51
|
-
// Only the kit's errors reach the job's log (its default on devnet is every
|
|
52
|
-
// debug line).
|
|
53
|
-
const kit = createNosanaClient(network, {
|
|
54
|
-
logLevel: 'error',
|
|
55
|
-
...(rpcUrl ? { solana: { rpcEndpoint: rpcUrl } } : {}),
|
|
56
|
-
});
|
|
57
|
-
const getJob = async (jobAddress) => kit.jobs.get(address(jobAddress));
|
|
58
|
-
return {
|
|
59
|
-
chainJobs: cacheJobLookups({
|
|
60
|
-
get: async (jobAddress) => {
|
|
61
|
-
const job = await getJob(jobAddress);
|
|
62
|
-
return {
|
|
63
|
-
project: job.project,
|
|
64
|
-
timeout: Number(job.timeout),
|
|
65
|
-
node: job.node,
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
}),
|
|
69
|
-
auth: { validate, validateHeaders },
|
|
70
|
-
getJob,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { JobRuntimeNetwork } from './chain.js';
|
|
2
|
-
import { type JobRuntimeConsole, type JobRuntimeKind } from './host/contract.js';
|
|
3
|
-
/**
|
|
4
|
-
* What the node tells the sidecar: the job, and the host the job runs on. An
|
|
5
|
-
* onchain job's definition, owner and node it resolves itself, onchain; an
|
|
6
|
-
* inline run's is in the seed the node wrote.
|
|
7
|
-
*/
|
|
8
|
-
export type JobRuntimeServerConfig = {
|
|
9
|
-
jobAddress: string;
|
|
10
|
-
kind: JobRuntimeKind;
|
|
11
|
-
/** The node the job runs on, stamped on every container the sidecar starts. */
|
|
12
|
-
nodeAddress: string;
|
|
13
|
-
network: JobRuntimeNetwork;
|
|
14
|
-
rpcUrl?: string;
|
|
15
|
-
/** The container runtime the node runs on, its socket in the sidecar, and
|
|
16
|
-
* the GPUs and TEE runtime the node offers its jobs. */
|
|
17
|
-
containerRuntime: 'docker' | 'podman';
|
|
18
|
-
dockerSocket: string;
|
|
19
|
-
gpu: string;
|
|
20
|
-
teeRuntime?: string;
|
|
21
|
-
/** Where the job's exposed ports are published, and the frpc image. */
|
|
22
|
-
frp: {
|
|
23
|
-
serverAddr: string;
|
|
24
|
-
serverPort: number;
|
|
25
|
-
containerImage: string;
|
|
26
|
-
};
|
|
27
|
-
/** The image that downloads remote resources into volumes. */
|
|
28
|
-
resourceManagerImage: string;
|
|
29
|
-
/** The node's own version, surfaced to workloads as %%global.version%%. */
|
|
30
|
-
nodeVersion: string;
|
|
31
|
-
/** The job's directory the node shares, its socket in it (see host/contract.ts). */
|
|
32
|
-
hostDir: string;
|
|
33
|
-
port: number;
|
|
34
|
-
dataDir: string;
|
|
35
|
-
/** What the console carries (see JobRuntimeConsole). */
|
|
36
|
-
console: JobRuntimeConsole;
|
|
37
|
-
};
|
|
38
|
-
/** The job runtime's configuration from its environment. Throws on a bad one. */
|
|
39
|
-
export declare function readJobRuntimeServerConfig(env: NodeJS.ProcessEnv): JobRuntimeServerConfig;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { JOB_RUNTIME_DATA_DIR, JOB_RUNTIME_HOST_DIR, JOB_RUNTIME_PORT, } from './host/contract.js';
|
|
2
|
-
function required(env, name) {
|
|
3
|
-
const value = env[name]?.trim();
|
|
4
|
-
if (!value)
|
|
5
|
-
throw new Error(`${name} is required`);
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
function port(value, name, fallback) {
|
|
9
|
-
const parsed = Number(value?.trim() || fallback);
|
|
10
|
-
if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
|
|
11
|
-
throw new Error(`${name} is not a port: ${value}`);
|
|
12
|
-
}
|
|
13
|
-
return parsed;
|
|
14
|
-
}
|
|
15
|
-
/** The job runtime's configuration from its environment. Throws on a bad one. */
|
|
16
|
-
export function readJobRuntimeServerConfig(env) {
|
|
17
|
-
const jobAddress = required(env, 'JOB_ADDRESS');
|
|
18
|
-
const nodeAddress = required(env, 'NODE_ADDRESS');
|
|
19
|
-
const kind = env.JOB_KIND?.trim() || 'onchain';
|
|
20
|
-
if (kind !== 'onchain' && kind !== 'inline') {
|
|
21
|
-
throw new Error(`JOB_KIND must be onchain or inline, not ${kind}`);
|
|
22
|
-
}
|
|
23
|
-
const network = env.NOSANA_NETWORK?.trim() || 'mainnet';
|
|
24
|
-
if (network !== 'mainnet' && network !== 'devnet') {
|
|
25
|
-
throw new Error(`NOSANA_NETWORK must be mainnet or devnet, not ${network}`);
|
|
26
|
-
}
|
|
27
|
-
const consoleOutput = env.JOB_RUNTIME_CONSOLE?.trim() || 'text';
|
|
28
|
-
if (consoleOutput !== 'text' && consoleOutput !== 'entries') {
|
|
29
|
-
throw new Error(`JOB_RUNTIME_CONSOLE must be text or entries, not ${consoleOutput}`);
|
|
30
|
-
}
|
|
31
|
-
const containerRuntime = env.CONTAINER_RUNTIME?.trim() || 'docker';
|
|
32
|
-
if (containerRuntime !== 'docker' && containerRuntime !== 'podman') {
|
|
33
|
-
throw new Error(`CONTAINER_RUNTIME must be docker or podman, not ${containerRuntime}`);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
jobAddress,
|
|
37
|
-
kind,
|
|
38
|
-
nodeAddress,
|
|
39
|
-
network,
|
|
40
|
-
rpcUrl: env.SOLANA_RPC?.trim() || undefined,
|
|
41
|
-
containerRuntime,
|
|
42
|
-
dockerSocket: env.DOCKER_SOCKET?.trim() || '/var/run/docker.sock',
|
|
43
|
-
gpu: env.GPU?.trim() || 'all',
|
|
44
|
-
teeRuntime: env.TEE_RUNTIME?.trim() || undefined,
|
|
45
|
-
frp: {
|
|
46
|
-
serverAddr: required(env, 'FRP_SERVER_ADDR'),
|
|
47
|
-
serverPort: port(env.FRP_SERVER_PORT, 'FRP_SERVER_PORT', 7000),
|
|
48
|
-
containerImage: required(env, 'FRP_SERVER_IMAGE'),
|
|
49
|
-
},
|
|
50
|
-
resourceManagerImage: required(env, 'RESOURCE_MANAGER_IMAGE'),
|
|
51
|
-
nodeVersion: env.NOSANA_NODE_VERSION?.trim() || '0.0.0',
|
|
52
|
-
hostDir: env.JOB_RUNTIME_HOST_DIR?.trim() || JOB_RUNTIME_HOST_DIR,
|
|
53
|
-
port: port(env.JOB_RUNTIME_PORT, 'JOB_RUNTIME_PORT', JOB_RUNTIME_PORT),
|
|
54
|
-
dataDir: env.JOB_RUNTIME_DATA_DIR?.trim() || JOB_RUNTIME_DATA_DIR,
|
|
55
|
-
console: consoleOutput,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { StopReason } from '../taskManager/stopReasons.js';
|
|
2
|
-
/** The node answered, with a failure: not something a retry fixes. */
|
|
3
|
-
export declare class HostRequestError extends Error {
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* The sidecar's side of the job runtime socket (see ./contract.ts). The node
|
|
7
|
-
* may restart while the job runs, so a request that cannot reach it is
|
|
8
|
-
* retried; one the node answered with a failure is not.
|
|
9
|
-
*/
|
|
10
|
-
export declare class HostClient {
|
|
11
|
-
private readonly socketPath;
|
|
12
|
-
private readonly retryDelayMs;
|
|
13
|
-
private readonly retryAttempts;
|
|
14
|
-
constructor(socketPath: string, options?: {
|
|
15
|
-
retryDelayMs?: number;
|
|
16
|
-
retryAttempts?: number;
|
|
17
|
-
});
|
|
18
|
-
/** An authorization header the node signed for the job address. */
|
|
19
|
-
signAuth(signal?: AbortSignal): Promise<string>;
|
|
20
|
-
/**
|
|
21
|
-
* Resolves with the reason once the node wants the job stopped. Waits out a
|
|
22
|
-
* node that is down for as long as it is down.
|
|
23
|
-
*/
|
|
24
|
-
waitForStop(signal?: AbortSignal): Promise<StopReason>;
|
|
25
|
-
/** Retries what could not reach the node; a node's own failure is final. */
|
|
26
|
-
private retry;
|
|
27
|
-
private request;
|
|
28
|
-
private json;
|
|
29
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
|
-
import { JOB_RUNTIME_HOST_PATHS, } from './contract.js';
|
|
3
|
-
import { abortError, retry, sleep } from '../utils/abort.js';
|
|
4
|
-
/** How long the sidecar keeps trying a node that does not answer (a restart). */
|
|
5
|
-
const DEFAULT_RETRY_DELAY_MS = 5_000;
|
|
6
|
-
const DEFAULT_RETRY_ATTEMPTS = 120;
|
|
7
|
-
/** The node answered, with a failure: not something a retry fixes. */
|
|
8
|
-
export class HostRequestError extends Error {
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The sidecar's side of the job runtime socket (see ./contract.ts). The node
|
|
12
|
-
* may restart while the job runs, so a request that cannot reach it is
|
|
13
|
-
* retried; one the node answered with a failure is not.
|
|
14
|
-
*/
|
|
15
|
-
export class HostClient {
|
|
16
|
-
constructor(socketPath, options = {}) {
|
|
17
|
-
this.socketPath = socketPath;
|
|
18
|
-
this.retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
19
|
-
this.retryAttempts = options.retryAttempts ?? DEFAULT_RETRY_ATTEMPTS;
|
|
20
|
-
}
|
|
21
|
-
/** An authorization header the node signed for the job address. */
|
|
22
|
-
async signAuth(signal) {
|
|
23
|
-
const body = await this.retry(() => this.json('GET', JOB_RUNTIME_HOST_PATHS.signAuth), signal);
|
|
24
|
-
if (!body.authorization) {
|
|
25
|
-
throw new HostRequestError('the node signed no authorization header');
|
|
26
|
-
}
|
|
27
|
-
return body.authorization;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Resolves with the reason once the node wants the job stopped. Waits out a
|
|
31
|
-
* node that is down for as long as it is down.
|
|
32
|
-
*/
|
|
33
|
-
async waitForStop(signal) {
|
|
34
|
-
for (;;) {
|
|
35
|
-
if (signal?.aborted)
|
|
36
|
-
throw abortError(signal);
|
|
37
|
-
try {
|
|
38
|
-
const { reason } = await this.json('GET', JOB_RUNTIME_HOST_PATHS.stop, undefined, signal);
|
|
39
|
-
return reason;
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
if (signal?.aborted)
|
|
43
|
-
throw abortError(signal);
|
|
44
|
-
await sleep(this.retryDelayMs, signal);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/** Retries what could not reach the node; a node's own failure is final. */
|
|
49
|
-
retry(attempt, signal) {
|
|
50
|
-
return retry(attempt, {
|
|
51
|
-
attempts: this.retryAttempts,
|
|
52
|
-
delayMs: this.retryDelayMs,
|
|
53
|
-
signal,
|
|
54
|
-
isFinal: (error) => error instanceof HostRequestError,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
request(method, path, body, signal) {
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
const payload = body === undefined ? undefined : JSON.stringify(body);
|
|
60
|
-
const req = http.request({
|
|
61
|
-
socketPath: this.socketPath,
|
|
62
|
-
path,
|
|
63
|
-
method,
|
|
64
|
-
signal,
|
|
65
|
-
headers: payload
|
|
66
|
-
? {
|
|
67
|
-
'content-type': 'application/json',
|
|
68
|
-
'content-length': Buffer.byteLength(payload),
|
|
69
|
-
}
|
|
70
|
-
: {},
|
|
71
|
-
}, resolve);
|
|
72
|
-
req.on('error', reject);
|
|
73
|
-
req.end(payload);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
async json(method, path, body, signal) {
|
|
77
|
-
const res = await this.request(method, path, body, signal);
|
|
78
|
-
let text = '';
|
|
79
|
-
for await (const chunk of res)
|
|
80
|
-
text += chunk;
|
|
81
|
-
if ((res.statusCode ?? 500) >= 400) {
|
|
82
|
-
let message = text || `HTTP ${res.statusCode}`;
|
|
83
|
-
try {
|
|
84
|
-
message = JSON.parse(text).error ?? message;
|
|
85
|
-
}
|
|
86
|
-
catch { }
|
|
87
|
-
throw new HostRequestError(`${method} ${path}: ${message}`);
|
|
88
|
-
}
|
|
89
|
-
return (text ? JSON.parse(text) : undefined);
|
|
90
|
-
}
|
|
91
|
-
}
|