@stackfactor/agent-utils 1.13.4 → 1.32.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 +667 -23
- package/dist/cjs/agentProto.d.ts +13 -3
- package/dist/cjs/agentProto.d.ts.map +1 -1
- package/dist/cjs/agentProto.js +25 -4
- package/dist/cjs/backoff.d.ts +17 -0
- package/dist/cjs/backoff.d.ts.map +1 -0
- package/dist/cjs/backoff.js +26 -0
- package/dist/cjs/cancellation.d.ts +22 -0
- package/dist/cjs/cancellation.d.ts.map +1 -0
- package/dist/cjs/cancellation.js +36 -0
- package/dist/cjs/cli.d.ts +3 -0
- package/dist/cjs/cli.d.ts.map +1 -0
- package/dist/cjs/cli.js +85 -0
- package/dist/cjs/client.d.ts +11 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +27 -0
- package/dist/cjs/const.d.ts +23 -0
- package/dist/cjs/const.d.ts.map +1 -1
- package/dist/cjs/const.js +23 -0
- package/dist/cjs/daemon.d.ts +94 -0
- package/dist/cjs/daemon.d.ts.map +1 -0
- package/dist/cjs/daemon.js +507 -0
- package/dist/cjs/daemonConfig.d.ts +45 -0
- package/dist/cjs/daemonConfig.d.ts.map +1 -0
- package/dist/cjs/daemonConfig.js +148 -0
- package/dist/cjs/daemonEnv.d.ts +10 -0
- package/dist/cjs/daemonEnv.d.ts.map +1 -0
- package/dist/cjs/daemonEnv.js +12 -0
- package/dist/cjs/durable/clientTool.d.ts +39 -0
- package/dist/cjs/durable/clientTool.d.ts.map +1 -0
- package/dist/cjs/durable/clientTool.js +90 -0
- package/dist/cjs/durable/index.d.ts +9 -0
- package/dist/cjs/durable/index.d.ts.map +1 -0
- package/dist/cjs/durable/index.js +16 -0
- package/dist/cjs/durable/journal.d.ts +218 -0
- package/dist/cjs/durable/journal.d.ts.map +1 -0
- package/dist/cjs/durable/journal.js +392 -0
- package/dist/cjs/durable/pause.d.ts +84 -0
- package/dist/cjs/durable/pause.d.ts.map +1 -0
- package/dist/cjs/durable/pause.js +241 -0
- package/dist/cjs/durable/resume.d.ts +27 -0
- package/dist/cjs/durable/resume.d.ts.map +1 -0
- package/dist/cjs/durable/resume.js +80 -0
- package/dist/cjs/durable/snapshotSaver.d.ts +38 -0
- package/dist/cjs/durable/snapshotSaver.d.ts.map +1 -0
- package/dist/cjs/durable/snapshotSaver.js +81 -0
- package/dist/cjs/durable/step.d.ts +28 -0
- package/dist/cjs/durable/step.d.ts.map +1 -0
- package/dist/cjs/durable/step.js +43 -0
- package/dist/cjs/index.d.ts +30 -7
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +28 -1
- package/dist/cjs/infrastructure.d.ts +50 -0
- package/dist/cjs/infrastructure.d.ts.map +1 -0
- package/dist/cjs/infrastructure.js +163 -0
- package/dist/cjs/langChain.d.ts +15 -3
- package/dist/cjs/langChain.d.ts.map +1 -1
- package/dist/cjs/langChain.js +986 -180
- package/dist/cjs/learningActivityMedia.d.ts +196 -0
- package/dist/cjs/learningActivityMedia.d.ts.map +1 -0
- package/dist/cjs/learningActivityMedia.js +861 -0
- package/dist/cjs/learningContentPlan.d.ts +105 -0
- package/dist/cjs/learningContentPlan.d.ts.map +1 -0
- package/dist/cjs/learningContentPlan.js +305 -0
- package/dist/cjs/learningContentThread.d.ts +184 -0
- package/dist/cjs/learningContentThread.d.ts.map +1 -0
- package/dist/cjs/learningContentThread.js +407 -0
- package/dist/cjs/logger.d.ts +1 -0
- package/dist/cjs/logger.d.ts.map +1 -1
- package/dist/cjs/logger.js +17 -3
- package/dist/cjs/modelRates.d.ts +40 -0
- package/dist/cjs/modelRates.d.ts.map +1 -0
- package/dist/cjs/modelRates.js +76 -0
- package/dist/cjs/referenceContext.d.ts +4 -145
- package/dist/cjs/referenceContext.d.ts.map +1 -1
- package/dist/cjs/referenceContext.js +16 -251
- package/dist/cjs/retry.d.ts +64 -0
- package/dist/cjs/retry.d.ts.map +1 -0
- package/dist/cjs/retry.js +138 -0
- package/dist/cjs/runtimeContext.d.ts +8 -1
- package/dist/cjs/runtimeContext.d.ts.map +1 -1
- package/dist/cjs/runtimeContext.js +3 -1
- package/dist/cjs/serve.d.ts +3 -2
- package/dist/cjs/serve.d.ts.map +1 -1
- package/dist/cjs/serve.js +32 -2
- package/dist/cjs/sourceStore.d.ts +378 -0
- package/dist/cjs/sourceStore.d.ts.map +1 -0
- package/dist/cjs/sourceStore.js +872 -0
- package/dist/cjs/stackfactorKnowledge.d.ts +91 -7
- package/dist/cjs/stackfactorKnowledge.d.ts.map +1 -1
- package/dist/cjs/stackfactorKnowledge.js +108 -44
- package/dist/cjs/tavily.d.ts +108 -4
- package/dist/cjs/tavily.d.ts.map +1 -1
- package/dist/cjs/tavily.js +242 -21
- package/dist/cjs/usage.d.ts.map +1 -1
- package/dist/cjs/usage.js +9 -15
- package/dist/cjs/version.d.ts +3 -0
- package/dist/cjs/version.d.ts.map +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/workflow/bookkeeping.d.ts +78 -0
- package/dist/cjs/workflow/bookkeeping.d.ts.map +1 -0
- package/dist/cjs/workflow/bookkeeping.js +75 -0
- package/dist/cjs/workflow/index.d.ts +13 -0
- package/dist/cjs/workflow/index.d.ts.map +1 -0
- package/dist/cjs/workflow/index.js +51 -0
- package/dist/cjs/workflow/limits.d.ts +52 -0
- package/dist/cjs/workflow/limits.d.ts.map +1 -0
- package/dist/cjs/workflow/limits.js +62 -0
- package/dist/cjs/workflow/platformTransport.d.ts +39 -0
- package/dist/cjs/workflow/platformTransport.d.ts.map +1 -0
- package/dist/cjs/workflow/platformTransport.js +115 -0
- package/dist/cjs/workflow/retrying.d.ts +44 -0
- package/dist/cjs/workflow/retrying.d.ts.map +1 -0
- package/dist/cjs/workflow/retrying.js +82 -0
- package/dist/cjs/workflow/run.d.ts +195 -0
- package/dist/cjs/workflow/run.d.ts.map +1 -0
- package/dist/cjs/workflow/run.js +858 -0
- package/dist/cjs/workflow/testing/index.d.ts +3 -0
- package/dist/cjs/workflow/testing/index.d.ts.map +1 -0
- package/dist/cjs/workflow/testing/index.js +6 -0
- package/dist/cjs/workflow/testing/memoryTransport.d.ts +203 -0
- package/dist/cjs/workflow/testing/memoryTransport.d.ts.map +1 -0
- package/dist/cjs/workflow/testing/memoryTransport.js +1171 -0
- package/dist/cjs/workflow/transport.d.ts +219 -0
- package/dist/cjs/workflow/transport.d.ts.map +1 -0
- package/dist/cjs/workflow/transport.js +19 -0
- package/dist/esm/agentProto.d.ts +13 -3
- package/dist/esm/agentProto.d.ts.map +1 -1
- package/dist/esm/agentProto.js +23 -3
- package/dist/esm/backoff.d.ts +17 -0
- package/dist/esm/backoff.d.ts.map +1 -0
- package/dist/esm/backoff.js +22 -0
- package/dist/esm/cancellation.d.ts +22 -0
- package/dist/esm/cancellation.d.ts.map +1 -0
- package/dist/esm/cancellation.js +27 -0
- package/dist/esm/cli.d.ts +3 -0
- package/dist/esm/cli.d.ts.map +1 -0
- package/dist/esm/cli.js +80 -0
- package/dist/esm/client.d.ts +11 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +25 -1
- package/dist/esm/const.d.ts +23 -0
- package/dist/esm/const.d.ts.map +1 -1
- package/dist/esm/const.js +23 -0
- package/dist/esm/daemon.d.ts +94 -0
- package/dist/esm/daemon.d.ts.map +1 -0
- package/dist/esm/daemon.js +499 -0
- package/dist/esm/daemonConfig.d.ts +45 -0
- package/dist/esm/daemonConfig.d.ts.map +1 -0
- package/dist/esm/daemonConfig.js +142 -0
- package/dist/esm/daemonEnv.d.ts +10 -0
- package/dist/esm/daemonEnv.d.ts.map +1 -0
- package/dist/esm/daemonEnv.js +9 -0
- package/dist/esm/durable/clientTool.d.ts +39 -0
- package/dist/esm/durable/clientTool.d.ts.map +1 -0
- package/dist/esm/durable/clientTool.js +82 -0
- package/dist/esm/durable/index.d.ts +9 -0
- package/dist/esm/durable/index.d.ts.map +1 -0
- package/dist/esm/durable/index.js +8 -0
- package/dist/esm/durable/journal.d.ts +218 -0
- package/dist/esm/durable/journal.d.ts.map +1 -0
- package/dist/esm/durable/journal.js +374 -0
- package/dist/esm/durable/pause.d.ts +84 -0
- package/dist/esm/durable/pause.d.ts.map +1 -0
- package/dist/esm/durable/pause.js +226 -0
- package/dist/esm/durable/resume.d.ts +27 -0
- package/dist/esm/durable/resume.d.ts.map +1 -0
- package/dist/esm/durable/resume.js +72 -0
- package/dist/esm/durable/snapshotSaver.d.ts +38 -0
- package/dist/esm/durable/snapshotSaver.d.ts.map +1 -0
- package/dist/esm/durable/snapshotSaver.js +77 -0
- package/dist/esm/durable/step.d.ts +28 -0
- package/dist/esm/durable/step.d.ts.map +1 -0
- package/dist/esm/durable/step.js +36 -0
- package/dist/esm/index.d.ts +30 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +20 -4
- package/dist/esm/infrastructure.d.ts +50 -0
- package/dist/esm/infrastructure.d.ts.map +1 -0
- package/dist/esm/infrastructure.js +156 -0
- package/dist/esm/langChain.d.ts +15 -3
- package/dist/esm/langChain.d.ts.map +1 -1
- package/dist/esm/langChain.js +984 -179
- package/dist/esm/learningActivityMedia.d.ts +196 -0
- package/dist/esm/learningActivityMedia.d.ts.map +1 -0
- package/dist/esm/learningActivityMedia.js +807 -0
- package/dist/esm/learningContentPlan.d.ts +105 -0
- package/dist/esm/learningContentPlan.d.ts.map +1 -0
- package/dist/esm/learningContentPlan.js +299 -0
- package/dist/esm/learningContentThread.d.ts +184 -0
- package/dist/esm/learningContentThread.d.ts.map +1 -0
- package/dist/esm/learningContentThread.js +364 -0
- package/dist/esm/logger.d.ts +1 -0
- package/dist/esm/logger.d.ts.map +1 -1
- package/dist/esm/logger.js +17 -3
- package/dist/esm/modelRates.d.ts +40 -0
- package/dist/esm/modelRates.d.ts.map +1 -0
- package/dist/esm/modelRates.js +68 -0
- package/dist/esm/referenceContext.d.ts +4 -145
- package/dist/esm/referenceContext.d.ts.map +1 -1
- package/dist/esm/referenceContext.js +16 -243
- package/dist/esm/retry.d.ts +64 -0
- package/dist/esm/retry.d.ts.map +1 -0
- package/dist/esm/retry.js +127 -0
- package/dist/esm/runtimeContext.d.ts +8 -1
- package/dist/esm/runtimeContext.d.ts.map +1 -1
- package/dist/esm/runtimeContext.js +3 -1
- package/dist/esm/serve.d.ts +3 -2
- package/dist/esm/serve.d.ts.map +1 -1
- package/dist/esm/serve.js +33 -3
- package/dist/esm/sourceStore.d.ts +378 -0
- package/dist/esm/sourceStore.d.ts.map +1 -0
- package/dist/esm/sourceStore.js +855 -0
- package/dist/esm/stackfactorKnowledge.d.ts +91 -7
- package/dist/esm/stackfactorKnowledge.d.ts.map +1 -1
- package/dist/esm/stackfactorKnowledge.js +101 -41
- package/dist/esm/tavily.d.ts +108 -4
- package/dist/esm/tavily.d.ts.map +1 -1
- package/dist/esm/tavily.js +237 -20
- package/dist/esm/usage.d.ts.map +1 -1
- package/dist/esm/usage.js +9 -15
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/workflow/bookkeeping.d.ts +78 -0
- package/dist/esm/workflow/bookkeeping.d.ts.map +1 -0
- package/dist/esm/workflow/bookkeeping.js +67 -0
- package/dist/esm/workflow/index.d.ts +13 -0
- package/dist/esm/workflow/index.d.ts.map +1 -0
- package/dist/esm/workflow/index.js +10 -0
- package/dist/esm/workflow/limits.d.ts +52 -0
- package/dist/esm/workflow/limits.d.ts.map +1 -0
- package/dist/esm/workflow/limits.js +59 -0
- package/dist/esm/workflow/platformTransport.d.ts +39 -0
- package/dist/esm/workflow/platformTransport.d.ts.map +1 -0
- package/dist/esm/workflow/platformTransport.js +110 -0
- package/dist/esm/workflow/retrying.d.ts +44 -0
- package/dist/esm/workflow/retrying.d.ts.map +1 -0
- package/dist/esm/workflow/retrying.js +73 -0
- package/dist/esm/workflow/run.d.ts +195 -0
- package/dist/esm/workflow/run.d.ts.map +1 -0
- package/dist/esm/workflow/run.js +850 -0
- package/dist/esm/workflow/testing/index.d.ts +3 -0
- package/dist/esm/workflow/testing/index.d.ts.map +1 -0
- package/dist/esm/workflow/testing/index.js +2 -0
- package/dist/esm/workflow/testing/memoryTransport.d.ts +203 -0
- package/dist/esm/workflow/testing/memoryTransport.d.ts.map +1 -0
- package/dist/esm/workflow/testing/memoryTransport.js +1167 -0
- package/dist/esm/workflow/transport.d.ts +219 -0
- package/dist/esm/workflow/transport.d.ts.map +1 -0
- package/dist/esm/workflow/transport.js +16 -0
- package/package.json +8 -7
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.start = exports.unlessAborted = void 0;
|
|
7
|
+
const node_os_1 = require("node:os");
|
|
8
|
+
const client_api_1 = require("@stackfactor/client-api");
|
|
9
|
+
const const_js_1 = __importDefault(require("./const.js"));
|
|
10
|
+
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
11
|
+
const backoff_js_1 = require("./backoff.js");
|
|
12
|
+
const daemonConfig_js_1 = require("./daemonConfig.js");
|
|
13
|
+
const infrastructure_js_1 = require("./infrastructure.js");
|
|
14
|
+
const version_js_1 = require("./version.js");
|
|
15
|
+
const { DAEMON } = const_js_1.default;
|
|
16
|
+
const DEFAULT_POLL_SECONDS = 30;
|
|
17
|
+
/** However short the pool's `pollSeconds`, the daemon waits at least this long between claims. */
|
|
18
|
+
const MIN_POLL_SECONDS = 1;
|
|
19
|
+
/**
|
|
20
|
+
* However long the pool's `pollSeconds`, the daemon claims at least this often
|
|
21
|
+
* (R-C11): inside the 90 s liveness window, and far below the ~2,147,483 s at
|
|
22
|
+
* which setTimeout overflows and fires at once.
|
|
23
|
+
*/
|
|
24
|
+
const MAX_POLL_SECONDS = 60;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a plain-http backend's host is this machine, so the token does not
|
|
27
|
+
* cross a network: localhost, the whole 127.0.0.0/8 range, and ::1. Not
|
|
28
|
+
* `*.localhost`: Node resolves it through the system resolver, which a search
|
|
29
|
+
* domain can send off the host.
|
|
30
|
+
*/
|
|
31
|
+
const isLoopback = (hostname) => hostname === "localhost" ||
|
|
32
|
+
hostname === "[::1]" ||
|
|
33
|
+
/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname);
|
|
34
|
+
/** What an `upgradeTo` must look like before it is put into a command for the operator. */
|
|
35
|
+
const RELEASE_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
36
|
+
/** A registration is answered at once; it is given the margin a claim gets beyond its poll. */
|
|
37
|
+
const REGISTER_TIMEOUT_MS = DAEMON.CLAIM_TIMEOUT_EXTRA_MS;
|
|
38
|
+
const CLOUDS = ["gcp", "aws", "azure", "other"];
|
|
39
|
+
/**
|
|
40
|
+
* What a claim asks the platform to wait for a task. None in this release: a
|
|
41
|
+
* daemon with no free slot is answered at once (design §5.1).
|
|
42
|
+
*/
|
|
43
|
+
const CLAIM_WAIT_SECONDS = 0;
|
|
44
|
+
/**
|
|
45
|
+
* A claim is allowed its wait plus the margin (design §7.2). With no wait that
|
|
46
|
+
* is the margin alone, so a platform that stops answering costs 10 s a try and
|
|
47
|
+
* three tries still fit inside the 90 s liveness window.
|
|
48
|
+
*/
|
|
49
|
+
const CLAIM_TIMEOUT_MS = CLAIM_WAIT_SECONDS * 1000 + DAEMON.CLAIM_TIMEOUT_EXTRA_MS;
|
|
50
|
+
/**
|
|
51
|
+
* A stop signal repeated inside this window is one keystroke delivered twice
|
|
52
|
+
* (a terminal's Ctrl-C reaches both npx and the daemon, and npx forwards it
|
|
53
|
+
* again), not the operator asking to leave without the deregister.
|
|
54
|
+
*/
|
|
55
|
+
const REPEAT_SIGNAL_MS = 1000;
|
|
56
|
+
const MESSAGE_MAX = 200;
|
|
57
|
+
/** The longest hostname the platform's registration accepts (the longest DNS allows); a longer one is a 400. */
|
|
58
|
+
const HOSTNAME_MAX = 253;
|
|
59
|
+
const STOPPED = Symbol("stopped");
|
|
60
|
+
const LATE = Symbol("late");
|
|
61
|
+
/**
|
|
62
|
+
* Settles with `call`, or with STOPPED as soon as `signal` aborts. The abort
|
|
63
|
+
* listener is removed when the call settles, so a signal that lives as long as
|
|
64
|
+
* the daemon holds on to nothing of the calls it guarded.
|
|
65
|
+
*/
|
|
66
|
+
const unlessAborted = (call, signal) => new Promise((resolve, reject) => {
|
|
67
|
+
if (signal.aborted) {
|
|
68
|
+
call.catch(() => undefined);
|
|
69
|
+
resolve(STOPPED);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const onAbort = () => resolve(STOPPED);
|
|
73
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
74
|
+
call.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
75
|
+
});
|
|
76
|
+
exports.unlessAborted = unlessAborted;
|
|
77
|
+
/** The default wait: a timer that the signal clears and ends at once. */
|
|
78
|
+
const abortableSleep = (ms, signal) => new Promise((resolve) => {
|
|
79
|
+
if (signal.aborted)
|
|
80
|
+
return resolve();
|
|
81
|
+
const done = () => {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
signal.removeEventListener("abort", done);
|
|
84
|
+
resolve();
|
|
85
|
+
};
|
|
86
|
+
const timer = setTimeout(done, ms);
|
|
87
|
+
signal.addEventListener("abort", done, { once: true });
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* client-api's `agentPools`, with the pool token and the configured backend
|
|
91
|
+
* URL on every call. Never client-api's own base URL (R-C10): that falls back to
|
|
92
|
+
* whatever `BACKEND_URL`, `REACT_APP_BACKEND_URL` or a `.env` names, or to localhost.
|
|
93
|
+
*/
|
|
94
|
+
const defaultTransport = (config) => {
|
|
95
|
+
const baseURL = config.backendUrl;
|
|
96
|
+
return {
|
|
97
|
+
register: (body, { timeoutMs }) => client_api_1.agentPools.registerDaemon(body, config.poolToken, { baseURL, timeoutMs }),
|
|
98
|
+
claim: (body, { timeoutMs }) => client_api_1.agentPools.claim(body, config.poolToken, { baseURL, timeoutMs }),
|
|
99
|
+
deregister: (daemonId, { timeoutMs }) => client_api_1.agentPools.deregisterDaemon(daemonId, config.poolToken, { baseURL, timeoutMs }),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/** The configured backend, or undefined when it is not an http(s) URL. */
|
|
103
|
+
const backendOf = (url) => {
|
|
104
|
+
if (typeof url !== "string" || url === "")
|
|
105
|
+
return undefined;
|
|
106
|
+
let parsed;
|
|
107
|
+
try {
|
|
108
|
+
parsed = new URL(url);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
114
|
+
return undefined;
|
|
115
|
+
return {
|
|
116
|
+
origin: parsed.origin,
|
|
117
|
+
cleartext: parsed.protocol === "http:" && !isLoopback(parsed.hostname),
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const defaultLog = (level, message) => logger_js_1.default.log(null, level, message);
|
|
121
|
+
/** Detection's answer in the wire shape (design §4.3: `orchestrator` is `{ kind }`, `cloud` one of four). */
|
|
122
|
+
const toWire = (found) => {
|
|
123
|
+
const wire = {
|
|
124
|
+
cloud: CLOUDS.find((cloud) => cloud === found.cloud) ?? "other",
|
|
125
|
+
orchestrator: { kind: found.orchestrator },
|
|
126
|
+
os: found.os,
|
|
127
|
+
arch: found.arch,
|
|
128
|
+
};
|
|
129
|
+
if (found.region !== undefined)
|
|
130
|
+
wire.region = found.region;
|
|
131
|
+
if (found.account !== undefined)
|
|
132
|
+
wire.account = found.account;
|
|
133
|
+
if (found.cluster !== undefined)
|
|
134
|
+
wire.cluster = found.cluster;
|
|
135
|
+
return wire;
|
|
136
|
+
};
|
|
137
|
+
/** The HTTP status a rejected call carries, if any. */
|
|
138
|
+
const statusOf = (error) => {
|
|
139
|
+
const status = error?.response?.status;
|
|
140
|
+
return typeof status === "number" ? status : undefined;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* What went wrong, for a log line: the HTTP status, else a network error's
|
|
144
|
+
* code, else the error's message through `clip`. Never the error object or its config.
|
|
145
|
+
*/
|
|
146
|
+
const describe = (error, clip) => {
|
|
147
|
+
const status = statusOf(error);
|
|
148
|
+
if (status !== undefined)
|
|
149
|
+
return `HTTP ${status}`;
|
|
150
|
+
const { code, message } = (error ?? {});
|
|
151
|
+
if (typeof code === "string" && code !== "")
|
|
152
|
+
return code;
|
|
153
|
+
if (typeof message === "string" && message !== "")
|
|
154
|
+
return clip(message);
|
|
155
|
+
return "unknown error";
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* The platform's own reason for refusing a call, through `clip`: the backend's
|
|
159
|
+
* `{ error }`, or a validation failure's `path: msg` pairs. A validation
|
|
160
|
+
* error's `value` is never repeated: it is what was refused.
|
|
161
|
+
*/
|
|
162
|
+
const platformSays = (error, clip) => {
|
|
163
|
+
const data = error?.response?.data;
|
|
164
|
+
if (!data || typeof data !== "object")
|
|
165
|
+
return undefined;
|
|
166
|
+
const body = data;
|
|
167
|
+
if (typeof body.error === "string" && body.error !== "")
|
|
168
|
+
return clip(body.error);
|
|
169
|
+
if (!Array.isArray(body.errors))
|
|
170
|
+
return undefined;
|
|
171
|
+
const fields = body.errors
|
|
172
|
+
.map((entry) => {
|
|
173
|
+
const { path, msg } = (entry ?? {});
|
|
174
|
+
if (typeof msg !== "string")
|
|
175
|
+
return undefined;
|
|
176
|
+
return typeof path === "string" && path !== "" ? `${path}: ${msg}` : msg;
|
|
177
|
+
})
|
|
178
|
+
.filter((field) => field !== undefined);
|
|
179
|
+
return fields.length > 0 ? clip(fields.join("; ")) : undefined;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Cuts the token out of a line: whole, then what follows `sfp_<poolId>_`, then
|
|
183
|
+
* the secret after `sfp_<poolId>_<credentialId>_` (base64url, so it may hold
|
|
184
|
+
* `_` itself), then its last `_` segment on its own. Parts under 8 characters
|
|
185
|
+
* are left alone.
|
|
186
|
+
*/
|
|
187
|
+
const redactor = (token) => {
|
|
188
|
+
const segments = token.split("_");
|
|
189
|
+
const parts = [
|
|
190
|
+
token,
|
|
191
|
+
token.slice((0, daemonConfig_js_1.poolOf)(token).length + 1),
|
|
192
|
+
segments.slice(3).join("_"),
|
|
193
|
+
segments[segments.length - 1],
|
|
194
|
+
].filter((part) => part.length >= 8);
|
|
195
|
+
return (line) => parts.reduce((text, part) => text.split(part).join("[pool token]"), line);
|
|
196
|
+
};
|
|
197
|
+
/** The pool's `pollSeconds`: 30 when missing or not a positive number, else bounded to 1-60. */
|
|
198
|
+
const pollSecondsOf = (settings) => {
|
|
199
|
+
const seconds = settings.pollSeconds;
|
|
200
|
+
if (typeof seconds !== "number" || !Number.isFinite(seconds) || seconds <= 0) {
|
|
201
|
+
return DEFAULT_POLL_SECONDS;
|
|
202
|
+
}
|
|
203
|
+
return Math.min(MAX_POLL_SECONDS, Math.max(MIN_POLL_SECONDS, seconds));
|
|
204
|
+
};
|
|
205
|
+
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
206
|
+
/**
|
|
207
|
+
* Runs the pool daemon until it is stopped or told to stop, and resolves the
|
|
208
|
+
* process's exit code:
|
|
209
|
+
* - `0` after SIGTERM or SIGINT, at once even mid-wait or mid-claim, having
|
|
210
|
+
* deregistered (bounded by `DEREGISTER_TIMEOUT_MS`; a failure is logged; a
|
|
211
|
+
* second signal, a second or more after the first, stops waiting for it). A
|
|
212
|
+
* registration still in flight is waited for within the same bound, so the
|
|
213
|
+
* daemon it creates is deregistered too;
|
|
214
|
+
* - `EXIT_UPGRADE` (75) when a claim answers `upgradeTo`;
|
|
215
|
+
* - `EXIT_CONFIG` (78) when the platform answers 401 (the token is gone) or
|
|
216
|
+
* 400 (this daemon's request is refused), or, before any request, when the
|
|
217
|
+
* configuration names no http(s) backend (R-C10).
|
|
218
|
+
*
|
|
219
|
+
* Otherwise it keeps going: a 404 on a claim registers again under the same
|
|
220
|
+
* deployment (at once after a good claim; with backoff when the daemon was
|
|
221
|
+
* lost again before a claim got through), a 403 (the pool is disabled, or the
|
|
222
|
+
* request was refused before it reached the platform) waits `DISABLED_RETRY_MS`, and network errors and anything else back off from 1 s
|
|
223
|
+
* to 15 s, forever. Only a good claim resets the backoff. Registration's
|
|
224
|
+
* errors follow the same table.
|
|
225
|
+
* @param options - The configuration and, for tests or embedding callers, overrides.
|
|
226
|
+
*/
|
|
227
|
+
const start = async (options) => {
|
|
228
|
+
const { config } = options;
|
|
229
|
+
const write = options.log ?? defaultLog;
|
|
230
|
+
if (typeof config?.poolToken !== "string" || config.poolToken === "") {
|
|
231
|
+
write("error", "no pool token in the configuration: read it with daemon.readConfig, which checks it");
|
|
232
|
+
return DAEMON.EXIT_CONFIG;
|
|
233
|
+
}
|
|
234
|
+
const redact = redactor(config.poolToken);
|
|
235
|
+
const clip = (text) => redact(text).slice(0, MESSAGE_MAX);
|
|
236
|
+
const say = (level, message) => write(level, redact(message));
|
|
237
|
+
const backend = backendOf(config.backendUrl);
|
|
238
|
+
if (!backend) {
|
|
239
|
+
say("error", "no usable backend URL: set AGENT_POOL_BACKEND_URL (or --backend) to the StackFactor backend, http or https. There is no default.");
|
|
240
|
+
return DAEMON.EXIT_CONFIG;
|
|
241
|
+
}
|
|
242
|
+
const transport = options.transport ?? defaultTransport(config);
|
|
243
|
+
const sleep = options.sleep ?? abortableSleep;
|
|
244
|
+
const now = options.now ?? Date.now;
|
|
245
|
+
const signals = options.signals ?? process;
|
|
246
|
+
const detect = options.detect ?? ((overrides) => (0, infrastructure_js_1.detectInfrastructure)(overrides));
|
|
247
|
+
const pool = (0, daemonConfig_js_1.poolOf)(config.poolToken);
|
|
248
|
+
const stop = new AbortController();
|
|
249
|
+
/** Aborted by a second signal: stop waiting for the deregister. */
|
|
250
|
+
const hurry = new AbortController();
|
|
251
|
+
/** Settles with the call, or with STOPPED as soon as a signal arrives. */
|
|
252
|
+
const unlessStopped = (call) => (0, exports.unlessAborted)(call, stop.signal);
|
|
253
|
+
let stoppedAt = 0;
|
|
254
|
+
const onSignal = (name) => {
|
|
255
|
+
if (!stop.signal.aborted) {
|
|
256
|
+
stoppedAt = now();
|
|
257
|
+
say("info", `${name} received: leaving the pool`);
|
|
258
|
+
stop.abort();
|
|
259
|
+
}
|
|
260
|
+
else if (!hurry.signal.aborted && now() - stoppedAt >= REPEAT_SIGNAL_MS) {
|
|
261
|
+
say("info", `${name} again: leaving at once, without waiting for the deregister`);
|
|
262
|
+
hurry.abort();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const onTerm = () => onSignal("SIGTERM");
|
|
266
|
+
const onInt = () => onSignal("SIGINT");
|
|
267
|
+
signals.on("SIGTERM", onTerm);
|
|
268
|
+
signals.on("SIGINT", onInt);
|
|
269
|
+
const state = { daemonId: null, settings: {}, queue: null, queueAt: null };
|
|
270
|
+
/** False once the token is refused: leaving would be refused too. */
|
|
271
|
+
let mayDeregister = true;
|
|
272
|
+
/**
|
|
273
|
+
* Settles with the call, or with LATE once `DEREGISTER_TIMEOUT_MS` has
|
|
274
|
+
* passed or a second signal hurries the daemon out. The timer never outlives it.
|
|
275
|
+
*/
|
|
276
|
+
const withinGrace = async (call) => {
|
|
277
|
+
const bound = new AbortController();
|
|
278
|
+
const hurried = () => bound.abort();
|
|
279
|
+
hurry.signal.addEventListener("abort", hurried, { once: true });
|
|
280
|
+
if (hurry.signal.aborted)
|
|
281
|
+
bound.abort();
|
|
282
|
+
try {
|
|
283
|
+
return await Promise.race([
|
|
284
|
+
call,
|
|
285
|
+
sleep(DAEMON.DEREGISTER_TIMEOUT_MS, bound.signal).then(() => LATE),
|
|
286
|
+
]);
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
bound.abort();
|
|
290
|
+
hurry.signal.removeEventListener("abort", hurried);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const leave = async (daemonId) => {
|
|
294
|
+
try {
|
|
295
|
+
const outcome = await withinGrace(transport.deregister(daemonId, { timeoutMs: DAEMON.DEREGISTER_TIMEOUT_MS }));
|
|
296
|
+
if (outcome !== LATE) {
|
|
297
|
+
say("info", `deregistered daemon ${daemonId}`);
|
|
298
|
+
}
|
|
299
|
+
else if (!hurry.signal.aborted) {
|
|
300
|
+
say("warn", `deregistering daemon ${daemonId} took over ${DAEMON.DEREGISTER_TIMEOUT_MS / 1000} s: leaving without it (the platform drops a silent daemon)`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (statusOf(error) === 404) {
|
|
305
|
+
say("info", `daemon ${daemonId} was already gone from the pool`);
|
|
306
|
+
}
|
|
307
|
+
else if (statusOf(error) === 403) {
|
|
308
|
+
// A disabled pool refuses the deregistration too (design §4.2).
|
|
309
|
+
say("warn", `the platform refused to deregister daemon ${daemonId} (HTTP 403: the pool is disabled): its record expires on the platform`);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
say("warn", `could not deregister daemon ${daemonId} (${describe(error, clip)}): the platform drops a silent daemon`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const run = async () => {
|
|
317
|
+
const version = options.version ?? version_js_1.VERSION;
|
|
318
|
+
say("info", `daemon for pool ${pool} (agent-utils ${version}) using the backend ${backend.origin}`);
|
|
319
|
+
if (backend.cleartext) {
|
|
320
|
+
say("warn", `the backend ${backend.origin} is plain http and not this host: the pool token travels in cleartext; use https`);
|
|
321
|
+
}
|
|
322
|
+
// The platform refuses a registration (400) whose hostname is empty or over
|
|
323
|
+
// HOSTNAME_MAX; the name is for display, so it is cut or stood in for instead.
|
|
324
|
+
const hostname = (options.hostname ?? (0, node_os_1.hostname)()).slice(0, HOSTNAME_MAX) || "unknown";
|
|
325
|
+
let infrastructure;
|
|
326
|
+
if (config.reportInfrastructure) {
|
|
327
|
+
const found = await unlessStopped(Promise.resolve()
|
|
328
|
+
.then(() => detect(config.overrides))
|
|
329
|
+
.then(toWire, () => {
|
|
330
|
+
say("warn", "could not detect the infrastructure: registering without it");
|
|
331
|
+
return undefined;
|
|
332
|
+
}));
|
|
333
|
+
if (found === STOPPED)
|
|
334
|
+
return 0;
|
|
335
|
+
infrastructure = found;
|
|
336
|
+
}
|
|
337
|
+
const registration = {
|
|
338
|
+
version,
|
|
339
|
+
runner: DAEMON.RUNNER,
|
|
340
|
+
schemes: [],
|
|
341
|
+
hostname,
|
|
342
|
+
};
|
|
343
|
+
if (config.deployment !== undefined)
|
|
344
|
+
registration.deployment = config.deployment;
|
|
345
|
+
if (infrastructure !== undefined)
|
|
346
|
+
registration.infrastructure = infrastructure;
|
|
347
|
+
const retry = (0, backoff_js_1.backoff)({ minMs: DAEMON.BACKOFF_MIN_MS, maxMs: DAEMON.BACKOFF_MAX_MS });
|
|
348
|
+
let failures = 0;
|
|
349
|
+
let failingSince = 0;
|
|
350
|
+
/** Whether a claim got through since the last registration. */
|
|
351
|
+
let claimedSinceRegistered = false;
|
|
352
|
+
/** Counts a failure and gives the next backoff delay. */
|
|
353
|
+
const failed = () => {
|
|
354
|
+
if (failures === 0)
|
|
355
|
+
failingSince = now();
|
|
356
|
+
failures++;
|
|
357
|
+
return retry.next();
|
|
358
|
+
};
|
|
359
|
+
/** A good claim: the loop is healthy again, and only now does the backoff start over. */
|
|
360
|
+
const recovered = () => {
|
|
361
|
+
if (failures > 0) {
|
|
362
|
+
const seconds = Math.round((now() - failingSince) / 1000);
|
|
363
|
+
say("info", `reached the platform again after ${plural(failures, "failed attempt")} (${seconds} s)`);
|
|
364
|
+
}
|
|
365
|
+
failures = 0;
|
|
366
|
+
retry.reset();
|
|
367
|
+
};
|
|
368
|
+
const inSeconds = (ms) => `${(ms / 1000).toFixed(1)} s`;
|
|
369
|
+
while (!stop.signal.aborted) {
|
|
370
|
+
const registering = state.daemonId === null;
|
|
371
|
+
try {
|
|
372
|
+
if (registering) {
|
|
373
|
+
const pending = transport.register(registration, { timeoutMs: REGISTER_TIMEOUT_MS });
|
|
374
|
+
const answer = await unlessStopped(pending);
|
|
375
|
+
if (answer === STOPPED) {
|
|
376
|
+
// The request may still land and leave a daemon registered: it is
|
|
377
|
+
// waited for, as long as a deregister is, so that daemon is deregistered too.
|
|
378
|
+
const landed = await withinGrace(pending.then((late) => late?.daemonId, () => undefined));
|
|
379
|
+
if (typeof landed === "string" && landed !== "")
|
|
380
|
+
state.daemonId = landed;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
if (typeof answer?.daemonId !== "string" || answer.daemonId === "") {
|
|
384
|
+
throw new Error("the registration answer carried no daemon id");
|
|
385
|
+
}
|
|
386
|
+
state.daemonId = answer.daemonId;
|
|
387
|
+
claimedSinceRegistered = false;
|
|
388
|
+
state.settings = answer.settings ?? state.settings;
|
|
389
|
+
say("info", `registered daemon ${answer.daemonId} in pool ${pool} (${clip(String(answer.pool?.kind ?? "unknown"))}), deployment ${config.deployment ?? "(none)"}`);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
const body = {
|
|
393
|
+
daemonId: state.daemonId,
|
|
394
|
+
running: 0,
|
|
395
|
+
capacity: DAEMON.CAPACITY,
|
|
396
|
+
version,
|
|
397
|
+
tasks: [],
|
|
398
|
+
waitSeconds: CLAIM_WAIT_SECONDS,
|
|
399
|
+
};
|
|
400
|
+
const answer = await unlessStopped(transport.claim(body, { timeoutMs: CLAIM_TIMEOUT_MS }));
|
|
401
|
+
if (answer === STOPPED)
|
|
402
|
+
break;
|
|
403
|
+
if (!answer || typeof answer !== "object")
|
|
404
|
+
throw new Error("the claim answer was empty");
|
|
405
|
+
recovered();
|
|
406
|
+
claimedSinceRegistered = true;
|
|
407
|
+
state.settings = answer.settings ?? state.settings;
|
|
408
|
+
if (answer.queue) {
|
|
409
|
+
state.queue = answer.queue;
|
|
410
|
+
state.queueAt = now();
|
|
411
|
+
}
|
|
412
|
+
if (answer.task) {
|
|
413
|
+
// The platform never hands a task to a capacity-0 daemon; if it does,
|
|
414
|
+
// the task is not run and not listed (the platform gives it back).
|
|
415
|
+
say("error", `the platform handed this daemon task ${clip(String(answer.task.batchJobId))}, but it takes none in this release: not run`);
|
|
416
|
+
}
|
|
417
|
+
if (Array.isArray(answer.drop) && answer.drop.length > 0) {
|
|
418
|
+
say("warn", `the platform asks to drop tasks this daemon does not hold: ${clip(answer.drop.join(", "))}`);
|
|
419
|
+
}
|
|
420
|
+
if (answer.upgradeTo) {
|
|
421
|
+
const target = String(answer.upgradeTo);
|
|
422
|
+
const restart = RELEASE_VERSION.test(target)
|
|
423
|
+
? `; restart it with: npx @stackfactor/agent-utils@${target} daemon`
|
|
424
|
+
: "";
|
|
425
|
+
say("info", `the pool runs agent-utils ${clip(target)} and this daemon ${version}: exiting ${DAEMON.EXIT_UPGRADE} to be restarted on it${restart}`);
|
|
426
|
+
return DAEMON.EXIT_UPGRADE;
|
|
427
|
+
}
|
|
428
|
+
if (stop.signal.aborted)
|
|
429
|
+
break;
|
|
430
|
+
await sleep(pollSecondsOf(state.settings) * 1000, stop.signal);
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
const status = statusOf(error);
|
|
434
|
+
const said = platformSays(error, clip);
|
|
435
|
+
/** `HTTP 401`, with the platform's own reason when it gave one. */
|
|
436
|
+
const why = (head) => (said ? `${head}: ${said}` : head);
|
|
437
|
+
const what = registering ? "registration" : "claim";
|
|
438
|
+
if (status === 401) {
|
|
439
|
+
mayDeregister = false;
|
|
440
|
+
say("error", `the platform refused the pool token for ${pool} (${why("HTTP 401")}): it was revoked or has expired, or its workspace is suspended; issue a new token in Agent pools and set AGENT_POOL_TOKEN`);
|
|
441
|
+
return DAEMON.EXIT_CONFIG;
|
|
442
|
+
}
|
|
443
|
+
if (status === 400) {
|
|
444
|
+
say("error", registering
|
|
445
|
+
? said
|
|
446
|
+
? `the platform refused this daemon's registration: ${said} (HTTP 400); restarting will not help`
|
|
447
|
+
: "the platform refused this daemon's registration (HTTP 400): check the installation name (--installation-name / AGENT_POOL_INSTALLATION: 1-63 of a-z, 0-9 and -; hosted and BYO pools need one)"
|
|
448
|
+
: `the platform refused this daemon's claim (${why("HTTP 400")}): restarting will not help; ${said ? "upgrade or report @stackfactor/agent-utils" : "this @stackfactor/agent-utils may not speak the platform's protocol; upgrade agent-utils"}`);
|
|
449
|
+
return DAEMON.EXIT_CONFIG;
|
|
450
|
+
}
|
|
451
|
+
if (status === 403) {
|
|
452
|
+
// The platform's own 403 says why (the pool is disabled, design §4.2).
|
|
453
|
+
// One without a reason came from something in front of it (a
|
|
454
|
+
// firewall, a proxy): not called a disabled pool, waited out the same.
|
|
455
|
+
say("warn", said
|
|
456
|
+
? `the pool is disabled (${why(`HTTP 403 on the ${what}`)}): asking again in ${DAEMON.DISABLED_RETRY_MS / 1000} s`
|
|
457
|
+
: `the ${what} was refused (HTTP 403) with no reason given: the pool may be disabled, or something in front of ${backend.origin} refuses this host; asking again in ${DAEMON.DISABLED_RETRY_MS / 1000} s`);
|
|
458
|
+
await sleep(DAEMON.DISABLED_RETRY_MS, stop.signal);
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (status === 404 && !registering) {
|
|
462
|
+
const lost = state.daemonId;
|
|
463
|
+
state.daemonId = null;
|
|
464
|
+
if (claimedSinceRegistered) {
|
|
465
|
+
say("warn", `the platform no longer knows daemon ${lost} (HTTP 404): registering again`);
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
// Lost again before one claim got through: back off, or a platform
|
|
469
|
+
// that keeps forgetting the daemon would be asked in a tight loop.
|
|
470
|
+
const delay = failed();
|
|
471
|
+
say("warn", `the platform lost daemon ${lost} before it could claim (HTTP 404): registering again in ${inSeconds(delay)}`);
|
|
472
|
+
await sleep(delay, stop.signal);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const delay = failed();
|
|
476
|
+
const unreached = status === undefined && typeof error?.code === "string";
|
|
477
|
+
let hint = "";
|
|
478
|
+
if (registering && status === 404) {
|
|
479
|
+
hint = `; no pool routes at ${backend.origin}: is AGENT_POOL_BACKEND_URL (--backend) the StackFactor backend?`;
|
|
480
|
+
}
|
|
481
|
+
else if (registering && unreached) {
|
|
482
|
+
hint = `; cannot reach ${backend.origin}: check AGENT_POOL_BACKEND_URL (--backend) and the network`;
|
|
483
|
+
}
|
|
484
|
+
else if (status !== undefined && status >= 300 && status < 400) {
|
|
485
|
+
hint = `; ${backend.origin} answered a redirect, which is never followed with the token: is AGENT_POOL_BACKEND_URL (--backend) the https URL of the StackFactor backend itself?`;
|
|
486
|
+
}
|
|
487
|
+
say("warn", `${what} failed (${describe(error, clip)}${hint}): trying again in ${inSeconds(delay)}`);
|
|
488
|
+
await sleep(delay, stop.signal);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return 0;
|
|
492
|
+
};
|
|
493
|
+
try {
|
|
494
|
+
const code = await run();
|
|
495
|
+
if (state.daemonId !== null && mayDeregister)
|
|
496
|
+
await leave(state.daemonId);
|
|
497
|
+
return code;
|
|
498
|
+
}
|
|
499
|
+
finally {
|
|
500
|
+
signals.off("SIGTERM", onTerm);
|
|
501
|
+
signals.off("SIGINT", onInt);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
exports.start = start;
|
|
505
|
+
/** `start` runs the daemon; `readConfig` reads and checks its configuration from flags and environment. */
|
|
506
|
+
const daemon = { start: exports.start, readConfig: daemonConfig_js_1.readDaemonConfig };
|
|
507
|
+
exports.default = daemon;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pool daemon's configuration, read from flags and environment.
|
|
3
|
+
* A flag wins over its variable. Junk is refused here, before any request.
|
|
4
|
+
* No message names more of the token than `sfp_<poolId>`.
|
|
5
|
+
*/
|
|
6
|
+
/** Thrown for a configuration the daemon must not start with. */
|
|
7
|
+
export declare class DaemonConfigError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export interface InfrastructureOverrides {
|
|
11
|
+
cloud?: string;
|
|
12
|
+
region?: string;
|
|
13
|
+
account?: string;
|
|
14
|
+
cluster?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DaemonConfig {
|
|
17
|
+
poolToken: string;
|
|
18
|
+
/**
|
|
19
|
+
* The installation's name (`--installation-name`). Sent to the platform as
|
|
20
|
+
* `deployment`, the protocol's name for it.
|
|
21
|
+
*/
|
|
22
|
+
deployment?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The StackFactor backend the pool token is sent to, http or https.
|
|
25
|
+
* Required, never defaulted (R-C10): a default could hand the token to
|
|
26
|
+
* whatever host a stray variable or `.env` names.
|
|
27
|
+
*/
|
|
28
|
+
backendUrl: string;
|
|
29
|
+
reportInfrastructure: boolean;
|
|
30
|
+
overrides: InfrastructureOverrides;
|
|
31
|
+
/** Things worth telling the operator that do not stop the daemon. */
|
|
32
|
+
warnings: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads the daemon's configuration.
|
|
36
|
+
* @throws DaemonConfigError for no token, a token not starting `sfp_` or
|
|
37
|
+
* holding a character no token has, a malformed installation name, no backend
|
|
38
|
+
* URL or one that is not a plain http(s) URL, an `AGENT_POOL_REPORT_INFRASTRUCTURE`
|
|
39
|
+
* that is neither true nor false, an unknown flag or a flag with no value.
|
|
40
|
+
*/
|
|
41
|
+
export declare const readDaemonConfig: (argv: string[], env: NodeJS.ProcessEnv) => DaemonConfig;
|
|
42
|
+
/** `sfp_<poolId>` for logs: never more of the token than that. */
|
|
43
|
+
export declare const poolOf: (token: string) => string;
|
|
44
|
+
export default readDaemonConfig;
|
|
45
|
+
//# sourceMappingURL=daemonConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemonConfig.d.ts","sourceRoot":"","sources":["../../src/daemonConfig.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iEAAiE;AACjE,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,SAAS,EAAE,uBAAuB,CAAC;IACnC,qEAAqE;IACrE,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAwDD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EAAE,EACd,KAAK,MAAM,CAAC,UAAU,KACrB,YA2FF,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,KAAG,MAGtC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|