@stackfactor/agent-utils 1.13.4 → 1.33.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.
Files changed (252) hide show
  1. package/README.md +688 -23
  2. package/dist/cjs/agentProto.d.ts +13 -3
  3. package/dist/cjs/agentProto.d.ts.map +1 -1
  4. package/dist/cjs/agentProto.js +25 -4
  5. package/dist/cjs/backoff.d.ts +17 -0
  6. package/dist/cjs/backoff.d.ts.map +1 -0
  7. package/dist/cjs/backoff.js +26 -0
  8. package/dist/cjs/cancellation.d.ts +22 -0
  9. package/dist/cjs/cancellation.d.ts.map +1 -0
  10. package/dist/cjs/cancellation.js +36 -0
  11. package/dist/cjs/cli.d.ts +3 -0
  12. package/dist/cjs/cli.d.ts.map +1 -0
  13. package/dist/cjs/cli.js +85 -0
  14. package/dist/cjs/client.d.ts +11 -0
  15. package/dist/cjs/client.d.ts.map +1 -1
  16. package/dist/cjs/client.js +27 -0
  17. package/dist/cjs/const.d.ts +23 -0
  18. package/dist/cjs/const.d.ts.map +1 -1
  19. package/dist/cjs/const.js +23 -0
  20. package/dist/cjs/daemon.d.ts +94 -0
  21. package/dist/cjs/daemon.d.ts.map +1 -0
  22. package/dist/cjs/daemon.js +507 -0
  23. package/dist/cjs/daemonConfig.d.ts +45 -0
  24. package/dist/cjs/daemonConfig.d.ts.map +1 -0
  25. package/dist/cjs/daemonConfig.js +148 -0
  26. package/dist/cjs/daemonEnv.d.ts +10 -0
  27. package/dist/cjs/daemonEnv.d.ts.map +1 -0
  28. package/dist/cjs/daemonEnv.js +12 -0
  29. package/dist/cjs/durable/clientTool.d.ts +39 -0
  30. package/dist/cjs/durable/clientTool.d.ts.map +1 -0
  31. package/dist/cjs/durable/clientTool.js +90 -0
  32. package/dist/cjs/durable/index.d.ts +9 -0
  33. package/dist/cjs/durable/index.d.ts.map +1 -0
  34. package/dist/cjs/durable/index.js +16 -0
  35. package/dist/cjs/durable/journal.d.ts +218 -0
  36. package/dist/cjs/durable/journal.d.ts.map +1 -0
  37. package/dist/cjs/durable/journal.js +392 -0
  38. package/dist/cjs/durable/pause.d.ts +84 -0
  39. package/dist/cjs/durable/pause.d.ts.map +1 -0
  40. package/dist/cjs/durable/pause.js +241 -0
  41. package/dist/cjs/durable/resume.d.ts +27 -0
  42. package/dist/cjs/durable/resume.d.ts.map +1 -0
  43. package/dist/cjs/durable/resume.js +80 -0
  44. package/dist/cjs/durable/snapshotSaver.d.ts +38 -0
  45. package/dist/cjs/durable/snapshotSaver.d.ts.map +1 -0
  46. package/dist/cjs/durable/snapshotSaver.js +81 -0
  47. package/dist/cjs/durable/step.d.ts +28 -0
  48. package/dist/cjs/durable/step.d.ts.map +1 -0
  49. package/dist/cjs/durable/step.js +43 -0
  50. package/dist/cjs/index.d.ts +30 -7
  51. package/dist/cjs/index.d.ts.map +1 -1
  52. package/dist/cjs/index.js +28 -1
  53. package/dist/cjs/infrastructure.d.ts +50 -0
  54. package/dist/cjs/infrastructure.d.ts.map +1 -0
  55. package/dist/cjs/infrastructure.js +163 -0
  56. package/dist/cjs/langChain.d.ts +15 -3
  57. package/dist/cjs/langChain.d.ts.map +1 -1
  58. package/dist/cjs/langChain.js +986 -180
  59. package/dist/cjs/learningActivityMedia.d.ts +196 -0
  60. package/dist/cjs/learningActivityMedia.d.ts.map +1 -0
  61. package/dist/cjs/learningActivityMedia.js +861 -0
  62. package/dist/cjs/learningContentPlan.d.ts +117 -0
  63. package/dist/cjs/learningContentPlan.d.ts.map +1 -0
  64. package/dist/cjs/learningContentPlan.js +327 -0
  65. package/dist/cjs/learningContentThread.d.ts +213 -0
  66. package/dist/cjs/learningContentThread.d.ts.map +1 -0
  67. package/dist/cjs/learningContentThread.js +448 -0
  68. package/dist/cjs/logger.d.ts +1 -0
  69. package/dist/cjs/logger.d.ts.map +1 -1
  70. package/dist/cjs/logger.js +17 -3
  71. package/dist/cjs/modelRates.d.ts +40 -0
  72. package/dist/cjs/modelRates.d.ts.map +1 -0
  73. package/dist/cjs/modelRates.js +76 -0
  74. package/dist/cjs/referenceContext.d.ts +4 -145
  75. package/dist/cjs/referenceContext.d.ts.map +1 -1
  76. package/dist/cjs/referenceContext.js +16 -251
  77. package/dist/cjs/retry.d.ts +64 -0
  78. package/dist/cjs/retry.d.ts.map +1 -0
  79. package/dist/cjs/retry.js +138 -0
  80. package/dist/cjs/runtimeContext.d.ts +8 -1
  81. package/dist/cjs/runtimeContext.d.ts.map +1 -1
  82. package/dist/cjs/runtimeContext.js +3 -1
  83. package/dist/cjs/serve.d.ts +3 -2
  84. package/dist/cjs/serve.d.ts.map +1 -1
  85. package/dist/cjs/serve.js +32 -2
  86. package/dist/cjs/sourceStore.d.ts +378 -0
  87. package/dist/cjs/sourceStore.d.ts.map +1 -0
  88. package/dist/cjs/sourceStore.js +872 -0
  89. package/dist/cjs/stackfactorKnowledge.d.ts +91 -7
  90. package/dist/cjs/stackfactorKnowledge.d.ts.map +1 -1
  91. package/dist/cjs/stackfactorKnowledge.js +108 -44
  92. package/dist/cjs/tavily.d.ts +108 -4
  93. package/dist/cjs/tavily.d.ts.map +1 -1
  94. package/dist/cjs/tavily.js +242 -21
  95. package/dist/cjs/usage.d.ts.map +1 -1
  96. package/dist/cjs/usage.js +9 -15
  97. package/dist/cjs/version.d.ts +3 -0
  98. package/dist/cjs/version.d.ts.map +1 -0
  99. package/dist/cjs/version.js +5 -0
  100. package/dist/cjs/workflow/bookkeeping.d.ts +78 -0
  101. package/dist/cjs/workflow/bookkeeping.d.ts.map +1 -0
  102. package/dist/cjs/workflow/bookkeeping.js +75 -0
  103. package/dist/cjs/workflow/index.d.ts +13 -0
  104. package/dist/cjs/workflow/index.d.ts.map +1 -0
  105. package/dist/cjs/workflow/index.js +51 -0
  106. package/dist/cjs/workflow/limits.d.ts +52 -0
  107. package/dist/cjs/workflow/limits.d.ts.map +1 -0
  108. package/dist/cjs/workflow/limits.js +62 -0
  109. package/dist/cjs/workflow/platformTransport.d.ts +39 -0
  110. package/dist/cjs/workflow/platformTransport.d.ts.map +1 -0
  111. package/dist/cjs/workflow/platformTransport.js +115 -0
  112. package/dist/cjs/workflow/retrying.d.ts +44 -0
  113. package/dist/cjs/workflow/retrying.d.ts.map +1 -0
  114. package/dist/cjs/workflow/retrying.js +82 -0
  115. package/dist/cjs/workflow/run.d.ts +195 -0
  116. package/dist/cjs/workflow/run.d.ts.map +1 -0
  117. package/dist/cjs/workflow/run.js +858 -0
  118. package/dist/cjs/workflow/testing/index.d.ts +3 -0
  119. package/dist/cjs/workflow/testing/index.d.ts.map +1 -0
  120. package/dist/cjs/workflow/testing/index.js +6 -0
  121. package/dist/cjs/workflow/testing/memoryTransport.d.ts +203 -0
  122. package/dist/cjs/workflow/testing/memoryTransport.d.ts.map +1 -0
  123. package/dist/cjs/workflow/testing/memoryTransport.js +1171 -0
  124. package/dist/cjs/workflow/transport.d.ts +219 -0
  125. package/dist/cjs/workflow/transport.d.ts.map +1 -0
  126. package/dist/cjs/workflow/transport.js +19 -0
  127. package/dist/esm/agentProto.d.ts +13 -3
  128. package/dist/esm/agentProto.d.ts.map +1 -1
  129. package/dist/esm/agentProto.js +23 -3
  130. package/dist/esm/backoff.d.ts +17 -0
  131. package/dist/esm/backoff.d.ts.map +1 -0
  132. package/dist/esm/backoff.js +22 -0
  133. package/dist/esm/cancellation.d.ts +22 -0
  134. package/dist/esm/cancellation.d.ts.map +1 -0
  135. package/dist/esm/cancellation.js +27 -0
  136. package/dist/esm/cli.d.ts +3 -0
  137. package/dist/esm/cli.d.ts.map +1 -0
  138. package/dist/esm/cli.js +80 -0
  139. package/dist/esm/client.d.ts +11 -0
  140. package/dist/esm/client.d.ts.map +1 -1
  141. package/dist/esm/client.js +25 -1
  142. package/dist/esm/const.d.ts +23 -0
  143. package/dist/esm/const.d.ts.map +1 -1
  144. package/dist/esm/const.js +23 -0
  145. package/dist/esm/daemon.d.ts +94 -0
  146. package/dist/esm/daemon.d.ts.map +1 -0
  147. package/dist/esm/daemon.js +499 -0
  148. package/dist/esm/daemonConfig.d.ts +45 -0
  149. package/dist/esm/daemonConfig.d.ts.map +1 -0
  150. package/dist/esm/daemonConfig.js +142 -0
  151. package/dist/esm/daemonEnv.d.ts +10 -0
  152. package/dist/esm/daemonEnv.d.ts.map +1 -0
  153. package/dist/esm/daemonEnv.js +9 -0
  154. package/dist/esm/durable/clientTool.d.ts +39 -0
  155. package/dist/esm/durable/clientTool.d.ts.map +1 -0
  156. package/dist/esm/durable/clientTool.js +82 -0
  157. package/dist/esm/durable/index.d.ts +9 -0
  158. package/dist/esm/durable/index.d.ts.map +1 -0
  159. package/dist/esm/durable/index.js +8 -0
  160. package/dist/esm/durable/journal.d.ts +218 -0
  161. package/dist/esm/durable/journal.d.ts.map +1 -0
  162. package/dist/esm/durable/journal.js +374 -0
  163. package/dist/esm/durable/pause.d.ts +84 -0
  164. package/dist/esm/durable/pause.d.ts.map +1 -0
  165. package/dist/esm/durable/pause.js +226 -0
  166. package/dist/esm/durable/resume.d.ts +27 -0
  167. package/dist/esm/durable/resume.d.ts.map +1 -0
  168. package/dist/esm/durable/resume.js +72 -0
  169. package/dist/esm/durable/snapshotSaver.d.ts +38 -0
  170. package/dist/esm/durable/snapshotSaver.d.ts.map +1 -0
  171. package/dist/esm/durable/snapshotSaver.js +77 -0
  172. package/dist/esm/durable/step.d.ts +28 -0
  173. package/dist/esm/durable/step.d.ts.map +1 -0
  174. package/dist/esm/durable/step.js +36 -0
  175. package/dist/esm/index.d.ts +30 -7
  176. package/dist/esm/index.d.ts.map +1 -1
  177. package/dist/esm/index.js +20 -4
  178. package/dist/esm/infrastructure.d.ts +50 -0
  179. package/dist/esm/infrastructure.d.ts.map +1 -0
  180. package/dist/esm/infrastructure.js +156 -0
  181. package/dist/esm/langChain.d.ts +15 -3
  182. package/dist/esm/langChain.d.ts.map +1 -1
  183. package/dist/esm/langChain.js +984 -179
  184. package/dist/esm/learningActivityMedia.d.ts +196 -0
  185. package/dist/esm/learningActivityMedia.d.ts.map +1 -0
  186. package/dist/esm/learningActivityMedia.js +807 -0
  187. package/dist/esm/learningContentPlan.d.ts +117 -0
  188. package/dist/esm/learningContentPlan.d.ts.map +1 -0
  189. package/dist/esm/learningContentPlan.js +320 -0
  190. package/dist/esm/learningContentThread.d.ts +213 -0
  191. package/dist/esm/learningContentThread.d.ts.map +1 -0
  192. package/dist/esm/learningContentThread.js +403 -0
  193. package/dist/esm/logger.d.ts +1 -0
  194. package/dist/esm/logger.d.ts.map +1 -1
  195. package/dist/esm/logger.js +17 -3
  196. package/dist/esm/modelRates.d.ts +40 -0
  197. package/dist/esm/modelRates.d.ts.map +1 -0
  198. package/dist/esm/modelRates.js +68 -0
  199. package/dist/esm/referenceContext.d.ts +4 -145
  200. package/dist/esm/referenceContext.d.ts.map +1 -1
  201. package/dist/esm/referenceContext.js +16 -243
  202. package/dist/esm/retry.d.ts +64 -0
  203. package/dist/esm/retry.d.ts.map +1 -0
  204. package/dist/esm/retry.js +127 -0
  205. package/dist/esm/runtimeContext.d.ts +8 -1
  206. package/dist/esm/runtimeContext.d.ts.map +1 -1
  207. package/dist/esm/runtimeContext.js +3 -1
  208. package/dist/esm/serve.d.ts +3 -2
  209. package/dist/esm/serve.d.ts.map +1 -1
  210. package/dist/esm/serve.js +33 -3
  211. package/dist/esm/sourceStore.d.ts +378 -0
  212. package/dist/esm/sourceStore.d.ts.map +1 -0
  213. package/dist/esm/sourceStore.js +855 -0
  214. package/dist/esm/stackfactorKnowledge.d.ts +91 -7
  215. package/dist/esm/stackfactorKnowledge.d.ts.map +1 -1
  216. package/dist/esm/stackfactorKnowledge.js +101 -41
  217. package/dist/esm/tavily.d.ts +108 -4
  218. package/dist/esm/tavily.d.ts.map +1 -1
  219. package/dist/esm/tavily.js +237 -20
  220. package/dist/esm/usage.d.ts.map +1 -1
  221. package/dist/esm/usage.js +9 -15
  222. package/dist/esm/version.d.ts +3 -0
  223. package/dist/esm/version.d.ts.map +1 -0
  224. package/dist/esm/version.js +2 -0
  225. package/dist/esm/workflow/bookkeeping.d.ts +78 -0
  226. package/dist/esm/workflow/bookkeeping.d.ts.map +1 -0
  227. package/dist/esm/workflow/bookkeeping.js +67 -0
  228. package/dist/esm/workflow/index.d.ts +13 -0
  229. package/dist/esm/workflow/index.d.ts.map +1 -0
  230. package/dist/esm/workflow/index.js +10 -0
  231. package/dist/esm/workflow/limits.d.ts +52 -0
  232. package/dist/esm/workflow/limits.d.ts.map +1 -0
  233. package/dist/esm/workflow/limits.js +59 -0
  234. package/dist/esm/workflow/platformTransport.d.ts +39 -0
  235. package/dist/esm/workflow/platformTransport.d.ts.map +1 -0
  236. package/dist/esm/workflow/platformTransport.js +110 -0
  237. package/dist/esm/workflow/retrying.d.ts +44 -0
  238. package/dist/esm/workflow/retrying.d.ts.map +1 -0
  239. package/dist/esm/workflow/retrying.js +73 -0
  240. package/dist/esm/workflow/run.d.ts +195 -0
  241. package/dist/esm/workflow/run.d.ts.map +1 -0
  242. package/dist/esm/workflow/run.js +850 -0
  243. package/dist/esm/workflow/testing/index.d.ts +3 -0
  244. package/dist/esm/workflow/testing/index.d.ts.map +1 -0
  245. package/dist/esm/workflow/testing/index.js +2 -0
  246. package/dist/esm/workflow/testing/memoryTransport.d.ts +203 -0
  247. package/dist/esm/workflow/testing/memoryTransport.d.ts.map +1 -0
  248. package/dist/esm/workflow/testing/memoryTransport.js +1167 -0
  249. package/dist/esm/workflow/transport.d.ts +219 -0
  250. package/dist/esm/workflow/transport.d.ts.map +1 -0
  251. package/dist/esm/workflow/transport.js +16 -0
  252. package/package.json +8 -7
@@ -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
- * zero or more `Progress` frames (driven by the agent's `onProgress`) followed
7
- * by exactly one `Result` or `Error`.
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;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,y3EAmEjB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAO,GAWnC,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,QAAO,IAAI,CAAC,iBACc,CAAC"}
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"}
@@ -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
- * zero or more `Progress` frames (driven by the agent's `onProgress`) followed
47
- * by exactly one `Result` or `Error`.
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,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
@@ -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
+ });
@@ -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. */
@@ -1 +1 @@
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,E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AAU,GACrB,UAAU,MAAM,EAChB,UAAS,iBAAsB,KAC9B,OAAO,CAAC,WAAW,CA8ClB,CAAC"}
@@ -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));
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wBAiBE"}
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) => DaemonCon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