@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
package/dist/cjs/agentProto.d.ts
CHANGED
|
@@ -3,10 +3,20 @@ import * as grpc from "@grpc/grpc-js";
|
|
|
3
3
|
* gRPC contract shared by the entire agent fleet — the `serve()` server AND the
|
|
4
4
|
* relay client. `data`/`config`/`request` are carried as JSON strings so
|
|
5
5
|
* arbitrary payloads need no proto schema churn. `Execute` is server-streaming:
|
|
6
|
-
*
|
|
7
|
-
* by
|
|
6
|
+
* any number of `Progress` frames (driven by the agent's `onProgress`) and
|
|
7
|
+
* `Partial` frames (driven by its `onPartialResult`), followed by exactly one
|
|
8
|
+
* `Result` or `Error`.
|
|
8
9
|
*/
|
|
9
|
-
export declare const PROTO = "\nsyntax = \"proto3\";\npackage stackfactor.agent.v1;\n\nservice Agent {\n rpc Execute(ExecuteRequest) returns (stream Update);\n // Liveness/health probe served by serve() itself \u2014 no agent code required.\n // deep=true also exercises the StackFactor auth callback (BACKEND_URL).\n rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);\n}\n\nmessage ExecuteRequest {\n string content_type = 1;\n string data_json = 2;\n string config_json = 3;\n string request_json = 4;\n int32 event = 5;\n // Optional repo-relative module to run INSTEAD of the agent's main (e.g.\n // \"src/webhooks/inbound-sms.js\"). Empty -> main, which is every pre-webhook\n // caller, so this stays wire-compatible with agents built before it existed.\n // Set by the webhook receiver from the integration's webHooks[].code. Follows\n // the same untrusted-path rules as HealthCheck's check_code.\n string code = 6;\n}\n\nmessage HealthCheckRequest {\n // Optional JSON carrying { authToken } for the deep backend-callback check.\n string request_json = 1;\n bool deep = 2;\n // Deep check only: repo-relative path to the agent's self-check module to run\n // (e.g. \"src/check.js\"). Empty \u2192 fall back to the conventional \"src/check.js\".\n string check_code = 3;\n // Deep check only: JSON of the resolved agent config (constantsAndVars/\n // secrets) made available to the self-check as ctx.config. May be empty.\n string config_json = 4;\n}\n\n// One result row from the agent's self-check module. The agent owns only its\n// own checks; reachability/ingress/version-drift rows are synthesised backend-\n// side. severity is optional: \"warn\" marks a failing check as non-blocking;\n// empty or \"error\" is blocking.\nmessage CheckResult {\n string name = 1;\n bool ok = 2;\n string detail = 3;\n string severity = 4;\n}\n\nmessage HealthCheckResponse {\n bool ok = 1;\n bool backend_reachable = 2;\n string version = 3;\n string message = 4;\n repeated CheckResult checks = 5;\n}\n\nmessage Update {\n oneof payload {\n Progress progress = 1;\n Result result = 2;\n ErrorInfo error = 3;\n }\n}\n\nmessage Progress { int32 progress = 1; string message = 2; }\nmessage Result { string result_json = 1; }\nmessage ErrorInfo { int32 code = 1; string message = 2; }\n";
|
|
10
|
+
export declare const PROTO = "\nsyntax = \"proto3\";\npackage stackfactor.agent.v1;\n\nservice Agent {\n rpc Execute(ExecuteRequest) returns (stream Update);\n // Liveness/health probe served by serve() itself \u2014 no agent code required.\n // deep=true also exercises the StackFactor auth callback (BACKEND_URL).\n rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);\n}\n\nmessage ExecuteRequest {\n string content_type = 1;\n string data_json = 2;\n string config_json = 3;\n string request_json = 4;\n int32 event = 5;\n // Optional repo-relative module to run INSTEAD of the agent's main (e.g.\n // \"src/webhooks/inbound-sms.js\"). Empty -> main, which is every pre-webhook\n // caller, so this stays wire-compatible with agents built before it existed.\n // Set by the webhook receiver from the integration's webHooks[].code. Follows\n // the same untrusted-path rules as HealthCheck's check_code.\n string code = 6;\n}\n\nmessage HealthCheckRequest {\n // Optional JSON carrying { authToken } for the deep backend-callback check.\n string request_json = 1;\n bool deep = 2;\n // Deep check only: repo-relative path to the agent's self-check module to run\n // (e.g. \"src/check.js\"). Empty \u2192 fall back to the conventional \"src/check.js\".\n string check_code = 3;\n // Deep check only: JSON of the resolved agent config (constantsAndVars/\n // secrets) made available to the self-check as ctx.config. May be empty.\n string config_json = 4;\n}\n\n// One result row from the agent's self-check module. The agent owns only its\n// own checks; reachability/ingress/version-drift rows are synthesised backend-\n// side. severity is optional: \"warn\" marks a failing check as non-blocking;\n// empty or \"error\" is blocking.\nmessage CheckResult {\n string name = 1;\n bool ok = 2;\n string detail = 3;\n string severity = 4;\n}\n\nmessage HealthCheckResponse {\n bool ok = 1;\n bool backend_reachable = 2;\n string version = 3;\n string message = 4;\n repeated CheckResult checks = 5;\n}\n\nmessage Update {\n oneof payload {\n Progress progress = 1;\n Result result = 2;\n ErrorInfo error = 3;\n Partial partial = 4;\n }\n}\n\nmessage Progress { int32 progress = 1; string message = 2; string icon = 3; }\nmessage Partial { string item_json = 1; }\nmessage Result { string result_json = 1; }\nmessage ErrorInfo { int32 code = 1; string message = 2; }\n";
|
|
11
|
+
/**
|
|
12
|
+
* The `icon` of a `Progress` frame: the lucide icon name an agent sent with a
|
|
13
|
+
* progress update, for the progress dialog to show next to the message. The
|
|
14
|
+
* name is written by the agent's author, who may be a third party, so anything
|
|
15
|
+
* that is not shaped like an icon name is dropped at both ends of the stream.
|
|
16
|
+
* @param icon - What the agent passed as `icon`, if anything
|
|
17
|
+
* @returns The name, or "" when there is none or it is not an icon name
|
|
18
|
+
*/
|
|
19
|
+
export declare const progressIcon: (icon: unknown) => string;
|
|
10
20
|
/**
|
|
11
21
|
* Loads the Agent proto package. proto-loader reads from a file, so the embedded
|
|
12
22
|
* schema is written to a temp path — keeps the package self-contained across the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentProto.d.ts","sourceRoot":"","sources":["../../src/agentProto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAMtC
|
|
1
|
+
{"version":3,"file":"agentProto.d.ts","sourceRoot":"","sources":["../../src/agentProto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAMtC;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,o9EAqEjB,CAAC;AAOF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,OAAO,KAAG,MAKrC,CAAC;AAET;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAO,GAWnC,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,QAAO,IAAI,CAAC,iBACc,CAAC"}
|
package/dist/cjs/agentProto.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.loadAgentService = exports.loadAgentPackage = exports.PROTO = void 0;
|
|
36
|
+
exports.loadAgentService = exports.loadAgentPackage = exports.progressIcon = exports.PROTO = void 0;
|
|
37
37
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
38
|
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
39
39
|
const node_fs_1 = require("node:fs");
|
|
@@ -43,8 +43,9 @@ const node_os_1 = require("node:os");
|
|
|
43
43
|
* gRPC contract shared by the entire agent fleet — the `serve()` server AND the
|
|
44
44
|
* relay client. `data`/`config`/`request` are carried as JSON strings so
|
|
45
45
|
* arbitrary payloads need no proto schema churn. `Execute` is server-streaming:
|
|
46
|
-
*
|
|
47
|
-
* by
|
|
46
|
+
* any number of `Progress` frames (driven by the agent's `onProgress`) and
|
|
47
|
+
* `Partial` frames (driven by its `onPartialResult`), followed by exactly one
|
|
48
|
+
* `Result` or `Error`.
|
|
48
49
|
*/
|
|
49
50
|
exports.PROTO = `
|
|
50
51
|
syntax = "proto3";
|
|
@@ -107,13 +108,33 @@ message Update {
|
|
|
107
108
|
Progress progress = 1;
|
|
108
109
|
Result result = 2;
|
|
109
110
|
ErrorInfo error = 3;
|
|
111
|
+
Partial partial = 4;
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
message Progress { int32 progress = 1; string message = 2; }
|
|
115
|
+
message Progress { int32 progress = 1; string message = 2; string icon = 3; }
|
|
116
|
+
message Partial { string item_json = 1; }
|
|
114
117
|
message Result { string result_json = 1; }
|
|
115
118
|
message ErrorInfo { int32 code = 1; string message = 2; }
|
|
116
119
|
`;
|
|
120
|
+
// A lucide icon name: lowercase words and digits joined by hyphens ("globe",
|
|
121
|
+
// "file-search", "columns-2").
|
|
122
|
+
const ICON_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
123
|
+
const MAX_ICON_NAME_LENGTH = 64;
|
|
124
|
+
/**
|
|
125
|
+
* The `icon` of a `Progress` frame: the lucide icon name an agent sent with a
|
|
126
|
+
* progress update, for the progress dialog to show next to the message. The
|
|
127
|
+
* name is written by the agent's author, who may be a third party, so anything
|
|
128
|
+
* that is not shaped like an icon name is dropped at both ends of the stream.
|
|
129
|
+
* @param icon - What the agent passed as `icon`, if anything
|
|
130
|
+
* @returns The name, or "" when there is none or it is not an icon name
|
|
131
|
+
*/
|
|
132
|
+
const progressIcon = (icon) => typeof icon === "string" &&
|
|
133
|
+
icon.length <= MAX_ICON_NAME_LENGTH &&
|
|
134
|
+
ICON_NAME.test(icon)
|
|
135
|
+
? icon
|
|
136
|
+
: "";
|
|
137
|
+
exports.progressIcon = progressIcon;
|
|
117
138
|
/**
|
|
118
139
|
* Loads the Agent proto package. proto-loader reads from a file, so the embedded
|
|
119
140
|
* schema is written to a temp path — keeps the package self-contained across the
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Backoff {
|
|
2
|
+
/** The next delay in milliseconds; each call doubles the step. */
|
|
3
|
+
next(): number;
|
|
4
|
+
/** Start again from the minimum (call after a success). */
|
|
5
|
+
reset(): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A retry delay that doubles from `minMs` up to `maxMs`, with plus or minus
|
|
9
|
+
* 20 % jitter, never below `minMs`. The step is capped at `maxMs`; jitter is applied after,
|
|
10
|
+
* so capped delays still spread around the cap.
|
|
11
|
+
*/
|
|
12
|
+
export declare const backoff: ({ minMs, maxMs, }: {
|
|
13
|
+
minMs: number;
|
|
14
|
+
maxMs: number;
|
|
15
|
+
}) => Backoff;
|
|
16
|
+
export default backoff;
|
|
17
|
+
//# sourceMappingURL=backoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/backoff.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,kEAAkE;IAClE,IAAI,IAAI,MAAM,CAAC;IACf,2DAA2D;IAC3D,KAAK,IAAI,IAAI,CAAC;CACf;AAKD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,mBAGrB;IACD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,KAAG,OAaH,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.backoff = void 0;
|
|
4
|
+
/** Jitter as a fraction of the step: the delay lands within plus or minus 20 %. */
|
|
5
|
+
const JITTER = 0.2;
|
|
6
|
+
/**
|
|
7
|
+
* A retry delay that doubles from `minMs` up to `maxMs`, with plus or minus
|
|
8
|
+
* 20 % jitter, never below `minMs`. The step is capped at `maxMs`; jitter is applied after,
|
|
9
|
+
* so capped delays still spread around the cap.
|
|
10
|
+
*/
|
|
11
|
+
const backoff = ({ minMs, maxMs, }) => {
|
|
12
|
+
let step = minMs;
|
|
13
|
+
return {
|
|
14
|
+
next() {
|
|
15
|
+
const jittered = step * (1 + (Math.random() * 2 - 1) * JITTER);
|
|
16
|
+
const delay = Math.max(minMs, Math.round(jittered));
|
|
17
|
+
step = Math.min(maxMs, step * 2);
|
|
18
|
+
return delay;
|
|
19
|
+
},
|
|
20
|
+
reset() {
|
|
21
|
+
step = minMs;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.backoff = backoff;
|
|
26
|
+
exports.default = exports.backoff;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** What a run stopped by its caller fails with, in every place it stops. */
|
|
2
|
+
export declare const REQUEST_CANCELLED_MESSAGE = "Request cancelled by caller";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the active request was cancelled: its caller cancelled the call,
|
|
5
|
+
* or the call's stream broke (serve.ts aborts the request's signal on both).
|
|
6
|
+
* Always false outside a request.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isRequestCancelled: () => boolean;
|
|
9
|
+
/** The error a cancelled request stops with: a 400 carrying {@link REQUEST_CANCELLED_MESSAGE}. */
|
|
10
|
+
export declare const requestCancelledError: () => any;
|
|
11
|
+
/**
|
|
12
|
+
* Stops a cancelled request before it starts more work. A run whose caller
|
|
13
|
+
* is gone has nobody to answer: every model call and every Tavily call it
|
|
14
|
+
* still makes is paid for and thrown away, and a failure it then reports
|
|
15
|
+
* names the wrong cause. Production, 2026-11-13: the backend pod holding a
|
|
16
|
+
* skill generation was removed 10 minutes in; the agent ran 3.5 minutes
|
|
17
|
+
* more, its link checks failed at once on the aborted signal, were retried
|
|
18
|
+
* twice, and the run ended with "The cited links could not be checked".
|
|
19
|
+
* @throws The {@link requestCancelledError} when the request was cancelled
|
|
20
|
+
*/
|
|
21
|
+
export declare const throwIfRequestCancelled: () => void;
|
|
22
|
+
//# sourceMappingURL=cancellation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellation.d.ts","sourceRoot":"","sources":["../../src/cancellation.ts"],"names":[],"mappings":"AAIA,4EAA4E;AAC5E,eAAO,MAAM,yBAAyB,gCAAgC,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAAO,OAA6C,CAAC;AAEpF,kGAAkG;AAClG,eAAO,MAAM,qBAAqB,QAAO,GACgD,CAAC;AAE1F;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,QAAO,IAE1C,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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.throwIfRequestCancelled = exports.requestCancelledError = exports.isRequestCancelled = exports.REQUEST_CANCELLED_MESSAGE = void 0;
|
|
7
|
+
const const_js_1 = __importDefault(require("./const.js"));
|
|
8
|
+
const errorHandling_js_1 = __importDefault(require("./errorHandling.js"));
|
|
9
|
+
const runtimeContext_js_1 = require("./runtimeContext.js");
|
|
10
|
+
/** What a run stopped by its caller fails with, in every place it stops. */
|
|
11
|
+
exports.REQUEST_CANCELLED_MESSAGE = "Request cancelled by caller";
|
|
12
|
+
/**
|
|
13
|
+
* Whether the active request was cancelled: its caller cancelled the call,
|
|
14
|
+
* or the call's stream broke (serve.ts aborts the request's signal on both).
|
|
15
|
+
* Always false outside a request.
|
|
16
|
+
*/
|
|
17
|
+
const isRequestCancelled = () => (0, runtimeContext_js_1.getAbortSignal)()?.aborted === true;
|
|
18
|
+
exports.isRequestCancelled = isRequestCancelled;
|
|
19
|
+
/** The error a cancelled request stops with: a 400 carrying {@link REQUEST_CANCELLED_MESSAGE}. */
|
|
20
|
+
const requestCancelledError = () => errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.BAD_REQUEST, exports.REQUEST_CANCELLED_MESSAGE);
|
|
21
|
+
exports.requestCancelledError = requestCancelledError;
|
|
22
|
+
/**
|
|
23
|
+
* Stops a cancelled request before it starts more work. A run whose caller
|
|
24
|
+
* is gone has nobody to answer: every model call and every Tavily call it
|
|
25
|
+
* still makes is paid for and thrown away, and a failure it then reports
|
|
26
|
+
* names the wrong cause. Production, 2026-11-13: the backend pod holding a
|
|
27
|
+
* skill generation was removed 10 minutes in; the agent ran 3.5 minutes
|
|
28
|
+
* more, its link checks failed at once on the aborted signal, were retried
|
|
29
|
+
* twice, and the run ended with "The cited links could not be checked".
|
|
30
|
+
* @throws The {@link requestCancelledError} when the request was cancelled
|
|
31
|
+
*/
|
|
32
|
+
const throwIfRequestCancelled = () => {
|
|
33
|
+
if ((0, exports.isRequestCancelled)())
|
|
34
|
+
throw (0, exports.requestCancelledError)();
|
|
35
|
+
};
|
|
36
|
+
exports.throwIfRequestCancelled = throwIfRequestCancelled;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cjs/cli.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/**
|
|
8
|
+
* `agent-utils`: the command line of @stackfactor/agent-utils.
|
|
9
|
+
* `agent-utils daemon [flags]` runs the pool daemon (see the README).
|
|
10
|
+
*/
|
|
11
|
+
// First, before anything that loads client-api: see daemonEnv.ts.
|
|
12
|
+
const daemonEnv_js_1 = require("./daemonEnv.js");
|
|
13
|
+
const daemonConfig_js_1 = require("./daemonConfig.js");
|
|
14
|
+
const daemon_js_1 = __importDefault(require("./daemon.js"));
|
|
15
|
+
const const_js_1 = __importDefault(require("./const.js"));
|
|
16
|
+
const EXIT_USAGE = 64;
|
|
17
|
+
const { DAEMON } = const_js_1.default;
|
|
18
|
+
const USAGE = `Usage: agent-utils <command> [flags]
|
|
19
|
+
|
|
20
|
+
Commands:
|
|
21
|
+
daemon Run a pool daemon: register with the platform and report in.
|
|
22
|
+
|
|
23
|
+
Flags for daemon:
|
|
24
|
+
--backend <url> AGENT_POOL_BACKEND_URL (required, no default): the
|
|
25
|
+
StackFactor backend that issued the pool token
|
|
26
|
+
--installation-name <name> AGENT_POOL_INSTALLATION: 1-63 of a-z, 0-9 and -
|
|
27
|
+
--pool <token> AGENT_POOL_TOKEN: the pool token; prefer the variable,
|
|
28
|
+
a command-line argument is visible to other users
|
|
29
|
+
|
|
30
|
+
Environment (daemon):
|
|
31
|
+
AGENT_POOL_TOKEN required
|
|
32
|
+
AGENT_POOL_BACKEND_URL required
|
|
33
|
+
AGENT_POOL_CLOUD, AGENT_POOL_REGION, AGENT_POOL_ACCOUNT, AGENT_POOL_CLUSTER
|
|
34
|
+
override infrastructure detection;
|
|
35
|
+
AGENT_POOL_CLOUD=other sends no metadata probes
|
|
36
|
+
AGENT_POOL_REPORT_INFRASTRUCTURE=false
|
|
37
|
+
send the installation name only
|
|
38
|
+
A .env file is not read for any of these: only the flags and the environment.
|
|
39
|
+
|
|
40
|
+
Exit codes: 0 stopped by SIGTERM/SIGINT (a second signal stops waiting for the
|
|
41
|
+
deregister), 1 unexpected failure, 64 usage, 75 restart on a new version,
|
|
42
|
+
78 configuration or token refused.
|
|
43
|
+
`;
|
|
44
|
+
const main = async (argv, env) => {
|
|
45
|
+
const [command, ...rest] = argv;
|
|
46
|
+
if (command === "--help" || command === "-h" || command === "help") {
|
|
47
|
+
process.stdout.write(USAGE);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
if (command === "daemon") {
|
|
51
|
+
if (rest.includes("--help") || rest.includes("-h")) {
|
|
52
|
+
process.stdout.write(USAGE);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
let config;
|
|
56
|
+
try {
|
|
57
|
+
config = (0, daemonConfig_js_1.readDaemonConfig)(rest, env);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof daemonConfig_js_1.DaemonConfigError) {
|
|
61
|
+
process.stderr.write(`${error.message}\n`);
|
|
62
|
+
return DAEMON.EXIT_CONFIG;
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
for (const warning of config.warnings)
|
|
67
|
+
process.stderr.write(`Warning: ${warning}\n`);
|
|
68
|
+
// Held until the process exits: a signal that arrives after the daemon has
|
|
69
|
+
// let go of its own handlers must not kill the process before its exit code.
|
|
70
|
+
const held = () => undefined;
|
|
71
|
+
process.on("SIGTERM", held);
|
|
72
|
+
process.on("SIGINT", held);
|
|
73
|
+
return daemon_js_1.default.start({ config });
|
|
74
|
+
}
|
|
75
|
+
const shown = command !== undefined && /^[a-z][a-z-]*$/.test(command)
|
|
76
|
+
? `Unknown command ${command}.`
|
|
77
|
+
: command === undefined ? "No command." : "Unknown command.";
|
|
78
|
+
process.stderr.write(`${shown}\n\n${USAGE}`);
|
|
79
|
+
return EXIT_USAGE;
|
|
80
|
+
};
|
|
81
|
+
// process.exit, not exitCode: an abandoned in-flight call must not outlive the grace period.
|
|
82
|
+
main(process.argv.slice(2), daemonEnv_js_1.startEnv).then((code) => process.exit(code), (error) => {
|
|
83
|
+
process.stderr.write(`${error instanceof Error ? error.name : "Error"}: the daemon failed unexpectedly.\n`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -29,7 +29,18 @@ export interface CallAgentOptions {
|
|
|
29
29
|
onProgress?: (update: {
|
|
30
30
|
progress: number;
|
|
31
31
|
message: string;
|
|
32
|
+
/** The lucide icon the agent named for this step; absent when it named none. */
|
|
33
|
+
icon?: string;
|
|
32
34
|
}) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Called with the parsed item of each streamed `Partial` frame, in the order
|
|
37
|
+
* the agent sent them. A partial result is a piece of the answer delivered
|
|
38
|
+
* early; the final result must still repeat every item, so a caller that
|
|
39
|
+
* leaves this out loses nothing. A frame whose item is not valid JSON is
|
|
40
|
+
* logged and skipped, and a throw from this callback is logged: neither
|
|
41
|
+
* ends the call.
|
|
42
|
+
*/
|
|
43
|
+
onPartial?: (item: unknown) => void;
|
|
33
44
|
/** Abort the RPC (e.g. the frontend socket dropped) → stops the agent's LLM. */
|
|
34
45
|
signal?: AbortSignal;
|
|
35
46
|
/** Call deadline; defaults to 900s to match Cloud Run's max request timeout. */
|
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":"AAKA;;;;;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;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,gFAAgF;QAChF,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,KAAK,IAAI,CAAC;IACX;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,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,CA0FV,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
|
@@ -32,10 +32,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.checkAgent = exports.callAgent = void 0;
|
|
37
40
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
38
41
|
const agentProto_js_1 = require("./agentProto.js");
|
|
42
|
+
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
39
43
|
const messageLimits_js_1 = require("./messageLimits.js");
|
|
40
44
|
const DEFAULT_DEADLINE_MS = 900_000;
|
|
41
45
|
/**
|
|
@@ -118,11 +122,34 @@ const callAgent = (agentUrl, request, options = {}) => new Promise((resolve, rej
|
|
|
118
122
|
}
|
|
119
123
|
stream.on("data", (update) => {
|
|
120
124
|
if (update.progress) {
|
|
125
|
+
// An agent built before the frame had `icon`, or one that named none,
|
|
126
|
+
// sends "": the update then carries no `icon`, as it always has.
|
|
127
|
+
const icon = (0, agentProto_js_1.progressIcon)(update.progress.icon);
|
|
121
128
|
options.onProgress?.({
|
|
122
129
|
progress: update.progress.progress ?? 0,
|
|
123
130
|
message: update.progress.message ?? "",
|
|
131
|
+
...(icon ? { icon } : {}),
|
|
124
132
|
});
|
|
125
133
|
}
|
|
134
|
+
else if (update.partial) {
|
|
135
|
+
// One bad item must not cost the caller the rest of the stream or the
|
|
136
|
+
// result, so a parse failure skips the frame and a callback throw is
|
|
137
|
+
// contained.
|
|
138
|
+
let item;
|
|
139
|
+
try {
|
|
140
|
+
item = JSON.parse(update.partial.item_json);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
logger_js_1.default.log(null, logger_js_1.default.levels.warn, `callAgent: skipped a partial frame that is not JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
options.onPartial?.(item);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
logger_js_1.default.log(null, logger_js_1.default.levels.error, `callAgent: onPartial threw: ${error instanceof Error ? error.message : String(error)}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
126
153
|
else if (update.result) {
|
|
127
154
|
const result = safeParse(update.result.result_json, null);
|
|
128
155
|
settle(() => resolve(result));
|
package/dist/cjs/const.d.ts
CHANGED
|
@@ -13,6 +13,29 @@ declare const _default: {
|
|
|
13
13
|
UNSUPPORTED_MODEL: string;
|
|
14
14
|
QUOTA_EXHAUSTED: string;
|
|
15
15
|
};
|
|
16
|
+
/** The pool daemon (`npx @stackfactor/agent-utils daemon`). */
|
|
17
|
+
DAEMON: {
|
|
18
|
+
/** First retry delay after a failure. */
|
|
19
|
+
readonly BACKOFF_MIN_MS: 1000;
|
|
20
|
+
/** Retry delay cap: three failures fit inside the 90 s liveness window. */
|
|
21
|
+
readonly BACKOFF_MAX_MS: 15000;
|
|
22
|
+
/** How long to wait before asking again when the pool is disabled. */
|
|
23
|
+
readonly DISABLED_RETRY_MS: 60000;
|
|
24
|
+
/** A claim may take its poll time plus this long before the client gives up. */
|
|
25
|
+
readonly CLAIM_TIMEOUT_EXTRA_MS: 10000;
|
|
26
|
+
/** Bound on each cloud metadata probe. */
|
|
27
|
+
readonly DETECT_TIMEOUT_MS: 1000;
|
|
28
|
+
/** A shutdown is not held up by an unreachable platform. */
|
|
29
|
+
readonly DEREGISTER_TIMEOUT_MS: 5000;
|
|
30
|
+
/** Exit code asking the supervisor to restart on a new version. */
|
|
31
|
+
readonly EXIT_UPGRADE: 75;
|
|
32
|
+
/** sysexits EX_CONFIG: the token or configuration is wrong; restarting will not help. */
|
|
33
|
+
readonly EXIT_CONFIG: 78;
|
|
34
|
+
/** The runner this slice registers. */
|
|
35
|
+
readonly RUNNER: "subprocess";
|
|
36
|
+
/** Tasks the daemon takes at once (none until the worker exists). */
|
|
37
|
+
readonly CAPACITY: 0;
|
|
38
|
+
};
|
|
16
39
|
};
|
|
17
40
|
export default _default;
|
|
18
41
|
//# sourceMappingURL=const.d.ts.map
|
package/dist/cjs/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;IAiBE,+DAA+D;;QAE7D,yCAAyC;;QAEzC,2EAA2E;;QAE3E,sEAAsE;;QAEtE,gFAAgF;;QAEhF,0CAA0C;;QAE1C,4DAA4D;;QAE5D,mEAAmE;;QAEnE,yFAAyF;;QAEzF,uCAAuC;;QAEvC,qEAAqE;;;;AArCzE,wBAwCE"}
|
package/dist/cjs/const.js
CHANGED
|
@@ -15,4 +15,27 @@ exports.default = {
|
|
|
15
15
|
UNSUPPORTED_MODEL: "The specified model is not supported",
|
|
16
16
|
QUOTA_EXHAUSTED: "Agent session quota exhausted: no remaining budget for additional LLM calls.",
|
|
17
17
|
},
|
|
18
|
+
/** The pool daemon (`npx @stackfactor/agent-utils daemon`). */
|
|
19
|
+
DAEMON: {
|
|
20
|
+
/** First retry delay after a failure. */
|
|
21
|
+
BACKOFF_MIN_MS: 1000,
|
|
22
|
+
/** Retry delay cap: three failures fit inside the 90 s liveness window. */
|
|
23
|
+
BACKOFF_MAX_MS: 15000,
|
|
24
|
+
/** How long to wait before asking again when the pool is disabled. */
|
|
25
|
+
DISABLED_RETRY_MS: 60000,
|
|
26
|
+
/** A claim may take its poll time plus this long before the client gives up. */
|
|
27
|
+
CLAIM_TIMEOUT_EXTRA_MS: 10000,
|
|
28
|
+
/** Bound on each cloud metadata probe. */
|
|
29
|
+
DETECT_TIMEOUT_MS: 1000,
|
|
30
|
+
/** A shutdown is not held up by an unreachable platform. */
|
|
31
|
+
DEREGISTER_TIMEOUT_MS: 5000,
|
|
32
|
+
/** Exit code asking the supervisor to restart on a new version. */
|
|
33
|
+
EXIT_UPGRADE: 75,
|
|
34
|
+
/** sysexits EX_CONFIG: the token or configuration is wrong; restarting will not help. */
|
|
35
|
+
EXIT_CONFIG: 78,
|
|
36
|
+
/** The runner this slice registers. */
|
|
37
|
+
RUNNER: "subprocess",
|
|
38
|
+
/** Tasks the daemon takes at once (none until the worker exists). */
|
|
39
|
+
CAPACITY: 0,
|
|
40
|
+
},
|
|
18
41
|
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { agentPools } from "@stackfactor/client-api";
|
|
2
|
+
import { type DaemonConfig, type InfrastructureOverrides } from "./daemonConfig.js";
|
|
3
|
+
import { type Infrastructure } from "./infrastructure.js";
|
|
4
|
+
/**
|
|
5
|
+
* The pool daemon (design §7.2): it registers with its pool, then reports in
|
|
6
|
+
* through the claim every `pollSeconds`, and leaves on SIGTERM. In slice 2a
|
|
7
|
+
* it runs no task: every claim reports `capacity: 0` (R-C1).
|
|
8
|
+
*
|
|
9
|
+
* The pool token is never logged: messages carry the HTTP status, a network
|
|
10
|
+
* error's code, the platform's stated reason or a short message, never an
|
|
11
|
+
* error object or its config. Any text from outside is cut free of the token
|
|
12
|
+
* before it is clipped, and every line again before it is written (Review Focus 1).
|
|
13
|
+
*/
|
|
14
|
+
type DaemonRegistration = agentPools.DaemonRegistration;
|
|
15
|
+
type DaemonRegistered = agentPools.DaemonRegistered;
|
|
16
|
+
type DaemonClaim = agentPools.DaemonClaim;
|
|
17
|
+
type ClaimAnswer = agentPools.ClaimAnswer;
|
|
18
|
+
/** A bound on one call to the platform. */
|
|
19
|
+
export interface PoolCallBound {
|
|
20
|
+
timeoutMs: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* How the daemon reaches the platform's pool routes (design §5.1). The default
|
|
24
|
+
* is client-api's `agentPools`, called with the pool token and the configured
|
|
25
|
+
* backend URL. A call rejects with the platform's HTTP status on
|
|
26
|
+
* `error.response.status`, or with a network error's `code`.
|
|
27
|
+
*/
|
|
28
|
+
export interface PoolTransport {
|
|
29
|
+
register(body: DaemonRegistration, options: PoolCallBound): Promise<DaemonRegistered>;
|
|
30
|
+
claim(body: DaemonClaim, options: PoolCallBound): Promise<ClaimAnswer>;
|
|
31
|
+
deregister(daemonId: string, options: PoolCallBound): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/** A wait that ends early, without rejecting, when `signal` aborts. */
|
|
34
|
+
export type Sleep = (ms: number, signal: AbortSignal) => Promise<void>;
|
|
35
|
+
/** The levels the daemon writes at; each is one of the package logger's levels. */
|
|
36
|
+
export type DaemonLogLevel = "error" | "warn" | "info" | "debug";
|
|
37
|
+
/** Where the daemon's lines go; the default is the package's logger. */
|
|
38
|
+
export type DaemonLog = (level: DaemonLogLevel, message: string) => void;
|
|
39
|
+
export interface DaemonOptions {
|
|
40
|
+
/** What `readDaemonConfig` read from flags and environment. */
|
|
41
|
+
config: DaemonConfig;
|
|
42
|
+
/** Override how the platform is reached (e.g. in tests). Defaults to client-api's `agentPools`. */
|
|
43
|
+
transport?: PoolTransport;
|
|
44
|
+
/** Override waiting (e.g. in tests). Defaults to a timer that a signal ends at once. */
|
|
45
|
+
sleep?: Sleep;
|
|
46
|
+
/** Override the clock (e.g. in tests). Defaults to `Date.now`. */
|
|
47
|
+
now?: () => number;
|
|
48
|
+
/** Where SIGTERM and SIGINT arrive. Defaults to `process`; the handlers are removed when `start` resolves. */
|
|
49
|
+
signals?: NodeJS.EventEmitter;
|
|
50
|
+
/** Override logging (e.g. in tests). Defaults to the package's logger. */
|
|
51
|
+
log?: DaemonLog;
|
|
52
|
+
/** The hostname registered. Defaults to `os.hostname()`. */
|
|
53
|
+
hostname?: string;
|
|
54
|
+
/** The version registered and reported. Defaults to this package's version, written at build time. */
|
|
55
|
+
version?: string;
|
|
56
|
+
/** Override infrastructure detection (e.g. in tests). Defaults to `detectInfrastructure`. */
|
|
57
|
+
detect?: (overrides: InfrastructureOverrides) => Promise<Infrastructure>;
|
|
58
|
+
}
|
|
59
|
+
declare const STOPPED: unique symbol;
|
|
60
|
+
/**
|
|
61
|
+
* Settles with `call`, or with STOPPED as soon as `signal` aborts. The abort
|
|
62
|
+
* listener is removed when the call settles, so a signal that lives as long as
|
|
63
|
+
* the daemon holds on to nothing of the calls it guarded.
|
|
64
|
+
*/
|
|
65
|
+
export declare const unlessAborted: <T>(call: Promise<T>, signal: AbortSignal) => Promise<T | typeof STOPPED>;
|
|
66
|
+
/**
|
|
67
|
+
* Runs the pool daemon until it is stopped or told to stop, and resolves the
|
|
68
|
+
* process's exit code:
|
|
69
|
+
* - `0` after SIGTERM or SIGINT, at once even mid-wait or mid-claim, having
|
|
70
|
+
* deregistered (bounded by `DEREGISTER_TIMEOUT_MS`; a failure is logged; a
|
|
71
|
+
* second signal, a second or more after the first, stops waiting for it). A
|
|
72
|
+
* registration still in flight is waited for within the same bound, so the
|
|
73
|
+
* daemon it creates is deregistered too;
|
|
74
|
+
* - `EXIT_UPGRADE` (75) when a claim answers `upgradeTo`;
|
|
75
|
+
* - `EXIT_CONFIG` (78) when the platform answers 401 (the token is gone) or
|
|
76
|
+
* 400 (this daemon's request is refused), or, before any request, when the
|
|
77
|
+
* configuration names no http(s) backend (R-C10).
|
|
78
|
+
*
|
|
79
|
+
* Otherwise it keeps going: a 404 on a claim registers again under the same
|
|
80
|
+
* deployment (at once after a good claim; with backoff when the daemon was
|
|
81
|
+
* lost again before a claim got through), a 403 (the pool is disabled, or the
|
|
82
|
+
* request was refused before it reached the platform) waits `DISABLED_RETRY_MS`, and network errors and anything else back off from 1 s
|
|
83
|
+
* to 15 s, forever. Only a good claim resets the backoff. Registration's
|
|
84
|
+
* errors follow the same table.
|
|
85
|
+
* @param options - The configuration and, for tests or embedding callers, overrides.
|
|
86
|
+
*/
|
|
87
|
+
export declare const start: (options: DaemonOptions) => Promise<number>;
|
|
88
|
+
/** `start` runs the daemon; `readConfig` reads and checks its configuration from flags and environment. */
|
|
89
|
+
declare const daemon: {
|
|
90
|
+
start: (options: DaemonOptions) => Promise<number>;
|
|
91
|
+
readConfig: (argv: string[], env: NodeJS.ProcessEnv) => DaemonConfig;
|
|
92
|
+
};
|
|
93
|
+
export default daemon;
|
|
94
|
+
//# sourceMappingURL=daemon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../../src/daemon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIrD,OAAO,EAA4B,KAAK,YAAY,EAAE,KAAK,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGhF;;;;;;;;;GASG;AAEH,KAAK,kBAAkB,GAAG,UAAU,CAAC,kBAAkB,CAAC;AACxD,KAAK,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,CAAC;AACpD,KAAK,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;AAC1C,KAAK,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;AAK1C,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACtF,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACvE,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,uEAAuE;AACvE,MAAM,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvE,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEjE,wEAAwE;AACxE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAEzE,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,MAAM,EAAE,YAAY,CAAC;IACrB,mGAAmG;IACnG,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wFAAwF;IACxF,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,8GAA8G;IAC9G,OAAO,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC;IAC9B,0EAA0E;IAC1E,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,uBAAuB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CAC1E;AA2DD,QAAA,MAAM,OAAO,eAAoB,CAAC;AAGlC;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,WAAW,KAAG,OAAO,CAAC,CAAC,GAAG,OAAO,OAAO,CAU/F,CAAC;AA4IL;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,KAAK,GAAU,SAAS,aAAa,KAAG,OAAO,CAAC,MAAM,CAsTlE,CAAC;AAEF,2GAA2G;AAC3G,QAAA,MAAM,MAAM;qBAzTyB,aAAa,KAAG,OAAO,CAAC,MAAM,CAAC;;CAyTd,CAAC;AAEvD,eAAe,MAAM,CAAC"}
|