@stackfactor/agent-utils 1.13.1 → 1.13.2
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/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +2 -19
- package/dist/cjs/messageLimits.d.ts +21 -0
- package/dist/cjs/messageLimits.d.ts.map +1 -0
- package/dist/cjs/messageLimits.js +29 -0
- package/dist/cjs/serve.d.ts.map +1 -1
- package/dist/cjs/serve.js +4 -1
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +2 -19
- package/dist/esm/messageLimits.d.ts +21 -0
- package/dist/esm/messageLimits.d.ts.map +1 -0
- package/dist/esm/messageLimits.js +26 -0
- package/dist/esm/serve.d.ts.map +1 -1
- package/dist/esm/serve.js +4 -1
- package/package.json +1 -1
package/dist/cjs/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACrE,gFAAgF;IAChF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2CD;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GACpB,UAAU,MAAM,EAChB,SAAS,mBAAmB,EAC5B,UAAS,gBAAqB,KAC7B,OAAO,CAAC,GAAG,CA0DV,CAAC;AAEL,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,gFAAgF;IAChF,gBAAgB,EAAE,OAAO,CAAC;IAC1B,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,EAChB,UAAS,iBAAsB,KAC9B,OAAO,CAAC,WAAW,CA8ClB,CAAC"}
|
package/dist/cjs/client.js
CHANGED
|
@@ -36,30 +36,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.checkAgent = exports.callAgent = void 0;
|
|
37
37
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
38
|
const agentProto_js_1 = require("./agentProto.js");
|
|
39
|
+
const messageLimits_js_1 = require("./messageLimits.js");
|
|
39
40
|
const DEFAULT_DEADLINE_MS = 900_000;
|
|
40
|
-
/**
|
|
41
|
-
* gRPC-js defaults `grpc.max_receive_message_length` to 4 MiB. Agents stream
|
|
42
|
-
* their result inline in `result_json`, and image/avatar agents (GIA) routinely
|
|
43
|
-
* return payloads well above 4 MiB — a single PNG can be 5 MiB+ before the
|
|
44
|
-
* ~33% base64 inflation of embedding it in JSON — which trips
|
|
45
|
-
* `RESOURCE_EXHAUSTED: Received message larger than max`. Raise both limits to
|
|
46
|
-
* 64 MiB so large media responses pass. Override via the
|
|
47
|
-
* `STACKFACTOR_AGENT_MAX_MESSAGE_BYTES` env var if an even larger ceiling is
|
|
48
|
-
* needed. (-1 in gRPC-js means "unlimited", which we deliberately avoid so a
|
|
49
|
-
* runaway response can't exhaust memory.)
|
|
50
|
-
*/
|
|
51
|
-
const MAX_MESSAGE_BYTES = (() => {
|
|
52
|
-
const fromEnv = Number(process.env.STACKFACTOR_AGENT_MAX_MESSAGE_BYTES);
|
|
53
|
-
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : 64 * 1024 * 1024;
|
|
54
|
-
})();
|
|
55
41
|
/**
|
|
56
42
|
* Channel options applied to every agent gRPC client. Lifts the send/receive
|
|
57
43
|
* message-size caps off their 4 MiB defaults (see `MAX_MESSAGE_BYTES`).
|
|
58
44
|
*/
|
|
59
|
-
const CHANNEL_OPTIONS =
|
|
60
|
-
"grpc.max_receive_message_length": MAX_MESSAGE_BYTES,
|
|
61
|
-
"grpc.max_send_message_length": MAX_MESSAGE_BYTES,
|
|
62
|
-
};
|
|
45
|
+
const CHANNEL_OPTIONS = messageLimits_js_1.MESSAGE_SIZE_OPTIONS;
|
|
63
46
|
const safeParse = (value, fallback) => {
|
|
64
47
|
if (!value)
|
|
65
48
|
return fallback;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC-js defaults `grpc.max_receive_message_length` to 4 MiB. Agents stream
|
|
3
|
+
* their result inline in `result_json`, and image/avatar agents (GIA) routinely
|
|
4
|
+
* return payloads well above 4 MiB — a single PNG can be 5 MiB+ before the
|
|
5
|
+
* ~33% base64 inflation of embedding it in JSON — which trips
|
|
6
|
+
* `RESOURCE_EXHAUSTED: Received message larger than max`. Raise both limits to
|
|
7
|
+
* 64 MiB so large media responses pass — on the client channel AND on the
|
|
8
|
+
* agent's own gRPC server (`serve`), which would otherwise reject a large
|
|
9
|
+
* request before the handler runs. Override via the
|
|
10
|
+
* `STACKFACTOR_AGENT_MAX_MESSAGE_BYTES` env var if an even larger ceiling is
|
|
11
|
+
* needed. (-1 in gRPC-js means "unlimited", which we deliberately avoid so a
|
|
12
|
+
* runaway response can't exhaust memory.)
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAX_MESSAGE_BYTES: number;
|
|
15
|
+
/**
|
|
16
|
+
* gRPC options that lift the send/receive message-size caps off their 4 MiB
|
|
17
|
+
* defaults (see `MAX_MESSAGE_BYTES`). Used for the agent clients and for the
|
|
18
|
+
* agent's gRPC server.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MESSAGE_SIZE_OPTIONS: Record<string, number>;
|
|
21
|
+
//# sourceMappingURL=messageLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageLimits.d.ts","sourceRoot":"","sources":["../../src/messageLimits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,QAG1B,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGvD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MESSAGE_SIZE_OPTIONS = exports.MAX_MESSAGE_BYTES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* gRPC-js defaults `grpc.max_receive_message_length` to 4 MiB. Agents stream
|
|
6
|
+
* their result inline in `result_json`, and image/avatar agents (GIA) routinely
|
|
7
|
+
* return payloads well above 4 MiB — a single PNG can be 5 MiB+ before the
|
|
8
|
+
* ~33% base64 inflation of embedding it in JSON — which trips
|
|
9
|
+
* `RESOURCE_EXHAUSTED: Received message larger than max`. Raise both limits to
|
|
10
|
+
* 64 MiB so large media responses pass — on the client channel AND on the
|
|
11
|
+
* agent's own gRPC server (`serve`), which would otherwise reject a large
|
|
12
|
+
* request before the handler runs. Override via the
|
|
13
|
+
* `STACKFACTOR_AGENT_MAX_MESSAGE_BYTES` env var if an even larger ceiling is
|
|
14
|
+
* needed. (-1 in gRPC-js means "unlimited", which we deliberately avoid so a
|
|
15
|
+
* runaway response can't exhaust memory.)
|
|
16
|
+
*/
|
|
17
|
+
exports.MAX_MESSAGE_BYTES = (() => {
|
|
18
|
+
const fromEnv = Number(process.env.STACKFACTOR_AGENT_MAX_MESSAGE_BYTES);
|
|
19
|
+
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : 64 * 1024 * 1024;
|
|
20
|
+
})();
|
|
21
|
+
/**
|
|
22
|
+
* gRPC options that lift the send/receive message-size caps off their 4 MiB
|
|
23
|
+
* defaults (see `MAX_MESSAGE_BYTES`). Used for the agent clients and for the
|
|
24
|
+
* agent's gRPC server.
|
|
25
|
+
*/
|
|
26
|
+
exports.MESSAGE_SIZE_OPTIONS = {
|
|
27
|
+
"grpc.max_receive_message_length": exports.MAX_MESSAGE_BYTES,
|
|
28
|
+
"grpc.max_send_message_length": exports.MAX_MESSAGE_BYTES,
|
|
29
|
+
};
|
package/dist/cjs/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KA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AAC,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAE,CACN,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACpC;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AAEX,mFAAmF;AACnF,eAAO,MAAM,kBAAkB,GAAI,MAAK,MAAM,CAAC,UAAwB,KAAG,OACJ,CAAC;AAKvE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,GAAG,EAAE,SAAS,GAAG,KAAG,OAEhB,CAAC;AAKlD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,EAAE,SAAS,GAAG,KAAG,OAGN,CAAC;AAmKrD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,GAClB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,OAAO,CAAC,IAAI,CA8Id,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,IAAI,CAAC,MA2OP,CAAC"}
|
package/dist/cjs/serve.js
CHANGED
|
@@ -44,6 +44,7 @@ const node_url_1 = require("node:url");
|
|
|
44
44
|
const client_api_1 = require("@stackfactor/client-api");
|
|
45
45
|
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
46
46
|
const agentProto_js_1 = require("./agentProto.js");
|
|
47
|
+
const messageLimits_js_1 = require("./messageLimits.js");
|
|
47
48
|
const runtimeContext_js_1 = require("./runtimeContext.js");
|
|
48
49
|
const usage_js_1 = require("./usage.js");
|
|
49
50
|
// Genuine dynamic `import()` that survives TypeScript's CJS downlevelling (which
|
|
@@ -723,7 +724,9 @@ const serve = (main, options = {}) => {
|
|
|
723
724
|
respond(ok, backendReachable, message, checks);
|
|
724
725
|
})();
|
|
725
726
|
};
|
|
726
|
-
|
|
727
|
+
// Without options grpc-js rejects any request over 4 MiB (RESOURCE_EXHAUSTED)
|
|
728
|
+
// before the handler runs; use the same ceiling as the clients.
|
|
729
|
+
const server = new grpc.Server(messageLimits_js_1.MESSAGE_SIZE_OPTIONS);
|
|
727
730
|
server.addService((0, agentProto_js_1.loadAgentService)(), {
|
|
728
731
|
Execute: execute,
|
|
729
732
|
HealthCheck: healthCheck,
|
package/dist/esm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACrE,gFAAgF;IAChF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2CD;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GACpB,UAAU,MAAM,EAChB,SAAS,mBAAmB,EAC5B,UAAS,gBAAqB,KAC7B,OAAO,CAAC,GAAG,CA0DV,CAAC;AAEL,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,gFAAgF;IAChF,gBAAgB,EAAE,OAAO,CAAC;IAC1B,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,EAChB,UAAS,iBAAsB,KAC9B,OAAO,CAAC,WAAW,CA8ClB,CAAC"}
|
package/dist/esm/client.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { loadAgentPackage } from "./agentProto.js";
|
|
3
|
+
import { MESSAGE_SIZE_OPTIONS } from "./messageLimits.js";
|
|
3
4
|
const DEFAULT_DEADLINE_MS = 900_000;
|
|
4
|
-
/**
|
|
5
|
-
* gRPC-js defaults `grpc.max_receive_message_length` to 4 MiB. Agents stream
|
|
6
|
-
* their result inline in `result_json`, and image/avatar agents (GIA) routinely
|
|
7
|
-
* return payloads well above 4 MiB — a single PNG can be 5 MiB+ before the
|
|
8
|
-
* ~33% base64 inflation of embedding it in JSON — which trips
|
|
9
|
-
* `RESOURCE_EXHAUSTED: Received message larger than max`. Raise both limits to
|
|
10
|
-
* 64 MiB so large media responses pass. Override via the
|
|
11
|
-
* `STACKFACTOR_AGENT_MAX_MESSAGE_BYTES` env var if an even larger ceiling is
|
|
12
|
-
* needed. (-1 in gRPC-js means "unlimited", which we deliberately avoid so a
|
|
13
|
-
* runaway response can't exhaust memory.)
|
|
14
|
-
*/
|
|
15
|
-
const MAX_MESSAGE_BYTES = (() => {
|
|
16
|
-
const fromEnv = Number(process.env.STACKFACTOR_AGENT_MAX_MESSAGE_BYTES);
|
|
17
|
-
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : 64 * 1024 * 1024;
|
|
18
|
-
})();
|
|
19
5
|
/**
|
|
20
6
|
* Channel options applied to every agent gRPC client. Lifts the send/receive
|
|
21
7
|
* message-size caps off their 4 MiB defaults (see `MAX_MESSAGE_BYTES`).
|
|
22
8
|
*/
|
|
23
|
-
const CHANNEL_OPTIONS =
|
|
24
|
-
"grpc.max_receive_message_length": MAX_MESSAGE_BYTES,
|
|
25
|
-
"grpc.max_send_message_length": MAX_MESSAGE_BYTES,
|
|
26
|
-
};
|
|
9
|
+
const CHANNEL_OPTIONS = MESSAGE_SIZE_OPTIONS;
|
|
27
10
|
const safeParse = (value, fallback) => {
|
|
28
11
|
if (!value)
|
|
29
12
|
return fallback;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC-js defaults `grpc.max_receive_message_length` to 4 MiB. Agents stream
|
|
3
|
+
* their result inline in `result_json`, and image/avatar agents (GIA) routinely
|
|
4
|
+
* return payloads well above 4 MiB — a single PNG can be 5 MiB+ before the
|
|
5
|
+
* ~33% base64 inflation of embedding it in JSON — which trips
|
|
6
|
+
* `RESOURCE_EXHAUSTED: Received message larger than max`. Raise both limits to
|
|
7
|
+
* 64 MiB so large media responses pass — on the client channel AND on the
|
|
8
|
+
* agent's own gRPC server (`serve`), which would otherwise reject a large
|
|
9
|
+
* request before the handler runs. Override via the
|
|
10
|
+
* `STACKFACTOR_AGENT_MAX_MESSAGE_BYTES` env var if an even larger ceiling is
|
|
11
|
+
* needed. (-1 in gRPC-js means "unlimited", which we deliberately avoid so a
|
|
12
|
+
* runaway response can't exhaust memory.)
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAX_MESSAGE_BYTES: number;
|
|
15
|
+
/**
|
|
16
|
+
* gRPC options that lift the send/receive message-size caps off their 4 MiB
|
|
17
|
+
* defaults (see `MAX_MESSAGE_BYTES`). Used for the agent clients and for the
|
|
18
|
+
* agent's gRPC server.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MESSAGE_SIZE_OPTIONS: Record<string, number>;
|
|
21
|
+
//# sourceMappingURL=messageLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageLimits.d.ts","sourceRoot":"","sources":["../../src/messageLimits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,QAG1B,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGvD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC-js defaults `grpc.max_receive_message_length` to 4 MiB. Agents stream
|
|
3
|
+
* their result inline in `result_json`, and image/avatar agents (GIA) routinely
|
|
4
|
+
* return payloads well above 4 MiB — a single PNG can be 5 MiB+ before the
|
|
5
|
+
* ~33% base64 inflation of embedding it in JSON — which trips
|
|
6
|
+
* `RESOURCE_EXHAUSTED: Received message larger than max`. Raise both limits to
|
|
7
|
+
* 64 MiB so large media responses pass — on the client channel AND on the
|
|
8
|
+
* agent's own gRPC server (`serve`), which would otherwise reject a large
|
|
9
|
+
* request before the handler runs. Override via the
|
|
10
|
+
* `STACKFACTOR_AGENT_MAX_MESSAGE_BYTES` env var if an even larger ceiling is
|
|
11
|
+
* needed. (-1 in gRPC-js means "unlimited", which we deliberately avoid so a
|
|
12
|
+
* runaway response can't exhaust memory.)
|
|
13
|
+
*/
|
|
14
|
+
export const MAX_MESSAGE_BYTES = (() => {
|
|
15
|
+
const fromEnv = Number(process.env.STACKFACTOR_AGENT_MAX_MESSAGE_BYTES);
|
|
16
|
+
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : 64 * 1024 * 1024;
|
|
17
|
+
})();
|
|
18
|
+
/**
|
|
19
|
+
* gRPC options that lift the send/receive message-size caps off their 4 MiB
|
|
20
|
+
* defaults (see `MAX_MESSAGE_BYTES`). Used for the agent clients and for the
|
|
21
|
+
* agent's gRPC server.
|
|
22
|
+
*/
|
|
23
|
+
export const MESSAGE_SIZE_OPTIONS = {
|
|
24
|
+
"grpc.max_receive_message_length": MAX_MESSAGE_BYTES,
|
|
25
|
+
"grpc.max_send_message_length": MAX_MESSAGE_BYTES,
|
|
26
|
+
};
|
package/dist/esm/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAYtC,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAwPpB;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,GAAG,KACT,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,MAAM,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;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,EAAE,SAAS,GAAG,KAAG,OAGN,CAAC;AAmKrD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,GAClB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,OAAO,CAAC,IAAI,CA8Id,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,IAAI,CAAC,MA2OP,CAAC"}
|
package/dist/esm/serve.js
CHANGED
|
@@ -5,6 +5,7 @@ import { pathToFileURL } from "node:url";
|
|
|
5
5
|
import { integration as clientIntegration, session as clientSession, } from "@stackfactor/client-api";
|
|
6
6
|
import logger from "./logger.js";
|
|
7
7
|
import { loadAgentService } from "./agentProto.js";
|
|
8
|
+
import { MESSAGE_SIZE_OPTIONS } from "./messageLimits.js";
|
|
8
9
|
import { runWithContext, installGlobals } from "./runtimeContext.js";
|
|
9
10
|
import { UsageLedger, reportUsage, reportUsageWhileRunning, } from "./usage.js";
|
|
10
11
|
// Genuine dynamic `import()` that survives TypeScript's CJS downlevelling (which
|
|
@@ -680,7 +681,9 @@ export const serve = (main, options = {}) => {
|
|
|
680
681
|
respond(ok, backendReachable, message, checks);
|
|
681
682
|
})();
|
|
682
683
|
};
|
|
683
|
-
|
|
684
|
+
// Without options grpc-js rejects any request over 4 MiB (RESOURCE_EXHAUSTED)
|
|
685
|
+
// before the handler runs; use the same ceiling as the clients.
|
|
686
|
+
const server = new grpc.Server(MESSAGE_SIZE_OPTIONS);
|
|
684
687
|
server.addService(loadAgentService(), {
|
|
685
688
|
Execute: execute,
|
|
686
689
|
HealthCheck: healthCheck,
|