@graftland/plugin-remote 0.3.2 → 0.4.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 (326) hide show
  1. package/README.md +18 -54
  2. package/README.zh-CN.md +17 -51
  3. package/README.zh-TW.md +17 -51
  4. package/dist/Auth.d.ts.map +1 -1
  5. package/dist/Auth.js.map +1 -1
  6. package/dist/Config.d.ts +1151 -0
  7. package/dist/Config.d.ts.map +1 -0
  8. package/dist/Config.js +183 -0
  9. package/dist/Config.js.map +1 -0
  10. package/dist/Contract.d.ts +1 -1
  11. package/dist/Contract.d.ts.map +1 -1
  12. package/dist/Contract.js +32 -1
  13. package/dist/Contract.js.map +1 -1
  14. package/dist/Instance.d.ts.map +1 -1
  15. package/dist/Instance.js.map +1 -1
  16. package/dist/Testing.d.ts +1 -1
  17. package/dist/Testing.d.ts.map +1 -1
  18. package/dist/Testing.js.map +1 -1
  19. package/dist/Transport.d.ts +1 -1
  20. package/dist/Transport.d.ts.map +1 -1
  21. package/dist/Transport.js.map +1 -1
  22. package/dist/cli.d.ts +4 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +25 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/host/auth/bearer.d.ts +9 -1
  27. package/dist/host/auth/bearer.d.ts.map +1 -1
  28. package/dist/host/auth/bearer.js +4 -2
  29. package/dist/host/auth/bearer.js.map +1 -1
  30. package/dist/host/auth/jwt.d.ts +9 -1
  31. package/dist/host/auth/jwt.d.ts.map +1 -1
  32. package/dist/host/auth/jwt.js +4 -2
  33. package/dist/host/auth/jwt.js.map +1 -1
  34. package/dist/host/auth/mtls.d.ts +10 -7
  35. package/dist/host/auth/mtls.d.ts.map +1 -1
  36. package/dist/host/auth/mtls.js +13 -14
  37. package/dist/host/auth/mtls.js.map +1 -1
  38. package/dist/host/auth/none.d.ts +3 -1
  39. package/dist/host/auth/none.js +7 -5
  40. package/dist/host/auth/none.js.map +1 -1
  41. package/dist/host/command.d.ts +14 -1
  42. package/dist/host/command.d.ts.map +1 -1
  43. package/dist/host/command.js +11 -9
  44. package/dist/host/command.js.map +1 -1
  45. package/dist/host/local.d.ts +2 -1
  46. package/dist/host/local.d.ts.map +1 -1
  47. package/dist/host/local.js +9 -30
  48. package/dist/host/local.js.map +1 -1
  49. package/dist/host/unix.d.ts +6 -1
  50. package/dist/host/unix.d.ts.map +1 -1
  51. package/dist/host/unix.js +13 -9
  52. package/dist/host/unix.js.map +1 -1
  53. package/dist/host/websocket.d.ts +10 -1
  54. package/dist/host/websocket.d.ts.map +1 -1
  55. package/dist/host/websocket.js +11 -8
  56. package/dist/host/websocket.js.map +1 -1
  57. package/dist/host/worker.d.ts +3 -1
  58. package/dist/host/worker.d.ts.map +1 -1
  59. package/dist/host/worker.js +13 -9
  60. package/dist/host/worker.js.map +1 -1
  61. package/dist/index.d.ts +6 -8
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +30 -64
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/Certificates.js.map +1 -1
  66. package/dist/internal/FailureGroup.js +6 -6
  67. package/dist/internal/FailureGroup.js.map +1 -1
  68. package/dist/internal/Peer.js.map +1 -1
  69. package/dist/internal/{ServeLifecycle.js → RunnerLifecycle.js} +6 -6
  70. package/dist/internal/RunnerLifecycle.js.map +1 -0
  71. package/dist/internal/Supervisor.js.map +1 -1
  72. package/dist/internal/assembly.d.ts +3 -2
  73. package/dist/internal/assembly.js +8 -8
  74. package/dist/internal/assembly.js.map +1 -1
  75. package/dist/internal/auth/config.d.ts +27 -0
  76. package/dist/internal/auth/config.d.ts.map +1 -0
  77. package/dist/internal/auth/config.js +29 -0
  78. package/dist/internal/auth/config.js.map +1 -0
  79. package/dist/internal/auth/mtls.js.map +1 -1
  80. package/dist/internal/auth/token.js.map +1 -1
  81. package/dist/internal/auth/tokenCredentials.d.ts +2 -1
  82. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  83. package/dist/internal/auth/tokenCredentials.js +1 -1
  84. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  85. package/dist/internal/child.js +3 -3
  86. package/dist/internal/child.js.map +1 -1
  87. package/dist/internal/childMain.js +47 -0
  88. package/dist/internal/childMain.js.map +1 -0
  89. package/dist/internal/childRuntime.js +8 -8
  90. package/dist/internal/childRuntime.js.map +1 -1
  91. package/dist/internal/cleanup.js +3 -3
  92. package/dist/internal/cleanup.js.map +1 -1
  93. package/dist/internal/contract.js.map +1 -1
  94. package/dist/internal/credentials.d.ts +3 -2
  95. package/dist/internal/credentials.d.ts.map +1 -1
  96. package/dist/internal/credentials.js +1 -1
  97. package/dist/internal/credentials.js.map +1 -1
  98. package/dist/internal/directTransport.js.map +1 -1
  99. package/dist/internal/entry.d.ts +493 -3
  100. package/dist/internal/entry.d.ts.map +1 -1
  101. package/dist/internal/entry.js +22 -9
  102. package/dist/internal/entry.js.map +1 -1
  103. package/dist/internal/entryConfig.d.ts +2 -202
  104. package/dist/internal/entryConfig.js +2 -136
  105. package/dist/internal/entryConfig.js.map +1 -1
  106. package/dist/internal/execution.d.ts +4 -4
  107. package/dist/internal/execution.js +11 -11
  108. package/dist/internal/execution.js.map +1 -1
  109. package/dist/internal/follow.js +1 -1
  110. package/dist/internal/follow.js.map +1 -1
  111. package/dist/internal/forkTree.js.map +1 -1
  112. package/dist/internal/host/local.js.map +1 -1
  113. package/dist/internal/host/runner.js +4 -4
  114. package/dist/internal/host/runner.js.map +1 -1
  115. package/dist/internal/host.js +2 -2
  116. package/dist/internal/host.js.map +1 -1
  117. package/dist/internal/importer.js +1 -1
  118. package/dist/internal/importer.js.map +1 -1
  119. package/dist/internal/listenerStartup.js +1 -1
  120. package/dist/internal/listenerStartup.js.map +1 -1
  121. package/dist/internal/loadModule.js.map +1 -1
  122. package/dist/internal/platform.js +1 -9
  123. package/dist/internal/port.d.ts +1 -1
  124. package/dist/internal/port.js +2 -2
  125. package/dist/internal/port.js.map +1 -1
  126. package/dist/internal/runner/Bootstrap.js.map +1 -1
  127. package/dist/internal/runner/Connection.d.ts +3 -2
  128. package/dist/internal/runner/Connection.js +6 -6
  129. package/dist/internal/runner/Connection.js.map +1 -1
  130. package/dist/internal/runner/Execution.js +6 -6
  131. package/dist/internal/runner/Execution.js.map +1 -1
  132. package/dist/internal/runner/Local.js +1 -1
  133. package/dist/internal/runner/Local.js.map +1 -1
  134. package/dist/internal/runner/Lock.js.map +1 -1
  135. package/dist/internal/runner/Multiplex.js.map +1 -1
  136. package/dist/internal/runner/Packages.js.map +1 -1
  137. package/dist/internal/runner/ProcessObservation.js.map +1 -1
  138. package/dist/internal/runner/Processes.js.map +1 -1
  139. package/dist/internal/runner/Retention.js.map +1 -1
  140. package/dist/internal/runner/Store.js.map +1 -1
  141. package/dist/internal/runner/Supervisor.js +5 -5
  142. package/dist/internal/runner/Supervisor.js.map +1 -1
  143. package/dist/internal/runner/Watchdog.js.map +1 -1
  144. package/dist/internal/runner/Wire.d.ts +1 -1
  145. package/dist/internal/runner/Wire.js.map +1 -1
  146. package/dist/internal/runner/accept.js +2 -2
  147. package/dist/internal/runner/accept.js.map +1 -1
  148. package/dist/internal/runner/command.js +1 -1
  149. package/dist/internal/runner/command.js.map +1 -1
  150. package/dist/internal/runner/connectionEnded.js +1 -1
  151. package/dist/internal/runner/connectionEnded.js.map +1 -1
  152. package/dist/internal/runner/model.d.ts.map +1 -1
  153. package/dist/internal/runner/model.js.map +1 -1
  154. package/dist/internal/services.d.ts.map +1 -1
  155. package/dist/internal/services.js +1 -1
  156. package/dist/internal/services.js.map +1 -1
  157. package/dist/internal/socketChannel.js.map +1 -1
  158. package/dist/internal/stdioChannel.js.map +1 -1
  159. package/dist/internal/supervisorPlugin.js +48 -1
  160. package/dist/internal/supervisorPlugin.js.map +1 -1
  161. package/dist/internal/transportOptions.d.ts.map +1 -1
  162. package/dist/internal/watchdogMain.js +5 -3
  163. package/dist/internal/watchdogMain.js.map +1 -1
  164. package/dist/internal/websocket.js.map +1 -1
  165. package/dist/internal/websocketServer.js +1 -1
  166. package/dist/internal/websocketServer.js.map +1 -1
  167. package/dist/internal/workerChannel.js.map +1 -1
  168. package/dist/internal/workerMain.js +13 -6
  169. package/dist/internal/workerMain.js.map +1 -1
  170. package/dist/runner/auth/bearer.d.ts +8 -5
  171. package/dist/runner/auth/bearer.d.ts.map +1 -1
  172. package/dist/runner/auth/bearer.js +13 -11
  173. package/dist/runner/auth/bearer.js.map +1 -1
  174. package/dist/runner/auth/jwt.d.ts +30 -17
  175. package/dist/runner/auth/jwt.d.ts.map +1 -1
  176. package/dist/runner/auth/jwt.js +16 -28
  177. package/dist/runner/auth/jwt.js.map +1 -1
  178. package/dist/runner/auth/mtls.d.ts +8 -6
  179. package/dist/runner/auth/mtls.d.ts.map +1 -1
  180. package/dist/runner/auth/mtls.js +13 -29
  181. package/dist/runner/auth/mtls.js.map +1 -1
  182. package/dist/runner/auth/none.d.ts +7 -1
  183. package/dist/runner/auth/none.js +7 -5
  184. package/dist/runner/auth/none.js.map +1 -1
  185. package/dist/runner/index.d.ts +5 -1
  186. package/dist/runner/index.d.ts.map +1 -1
  187. package/dist/runner/index.js +62 -30
  188. package/dist/runner/index.js.map +1 -1
  189. package/dist/runner/stdio.d.ts +6 -1
  190. package/dist/runner/stdio.d.ts.map +1 -1
  191. package/dist/runner/stdio.js +11 -9
  192. package/dist/runner/stdio.js.map +1 -1
  193. package/dist/runner/unix.d.ts +6 -1
  194. package/dist/runner/unix.d.ts.map +1 -1
  195. package/dist/runner/unix.js +10 -8
  196. package/dist/runner/unix.js.map +1 -1
  197. package/dist/runner/websocket.d.ts +24 -1
  198. package/dist/runner/websocket.d.ts.map +1 -1
  199. package/dist/runner/websocket.js +12 -10
  200. package/dist/runner/websocket.js.map +1 -1
  201. package/package.json +14 -12
  202. package/schema.json +2269 -0
  203. package/src/Auth.ts +8 -2
  204. package/src/Config.ts +196 -0
  205. package/src/Contract.ts +12 -3
  206. package/src/Instance.ts +1 -0
  207. package/src/Testing.ts +6 -4
  208. package/src/Transport.ts +12 -3
  209. package/src/cli.ts +60 -0
  210. package/src/host/auth/bearer.ts +1 -0
  211. package/src/host/auth/jwt.ts +1 -0
  212. package/src/host/auth/mtls.ts +7 -12
  213. package/src/host/auth/none.ts +3 -1
  214. package/src/host/command.ts +8 -5
  215. package/src/host/local.ts +4 -2
  216. package/src/host/unix.ts +11 -7
  217. package/src/host/websocket.ts +10 -7
  218. package/src/host/worker.ts +8 -5
  219. package/src/index.ts +36 -23
  220. package/src/internal/Certificates.ts +1 -0
  221. package/src/internal/FailureGroup.ts +5 -3
  222. package/src/internal/Peer.ts +1 -0
  223. package/src/internal/{ServeLifecycle.ts → RunnerLifecycle.ts} +7 -5
  224. package/src/internal/Supervisor.ts +5 -4
  225. package/src/internal/assembly.ts +11 -9
  226. package/src/internal/auth/config.ts +44 -0
  227. package/src/internal/auth/mtls.ts +1 -0
  228. package/src/internal/auth/token.ts +1 -0
  229. package/src/internal/auth/tokenCredentials.ts +4 -2
  230. package/src/internal/child.ts +8 -6
  231. package/src/{bin.ts → internal/childMain.ts} +16 -61
  232. package/src/internal/childRuntime.ts +12 -10
  233. package/src/internal/cleanup.ts +3 -2
  234. package/src/internal/contract.ts +1 -0
  235. package/src/internal/credentials.ts +3 -1
  236. package/src/internal/directTransport.ts +9 -2
  237. package/src/internal/entry.ts +53 -16
  238. package/src/internal/entryConfig.ts +10 -132
  239. package/src/internal/execution.ts +17 -15
  240. package/src/internal/follow.ts +2 -1
  241. package/src/internal/forkTree.ts +2 -1
  242. package/src/internal/host/local.ts +1 -0
  243. package/src/internal/host/runner.ts +7 -5
  244. package/src/internal/host.ts +9 -8
  245. package/src/internal/importer.ts +3 -2
  246. package/src/internal/listenerStartup.ts +4 -2
  247. package/src/internal/loadModule.ts +1 -0
  248. package/src/internal/platform.ts +1 -12
  249. package/src/internal/port.ts +11 -6
  250. package/src/internal/runner/Bootstrap.ts +1 -0
  251. package/src/internal/runner/Connection.ts +13 -11
  252. package/src/internal/runner/Execution.ts +14 -13
  253. package/src/internal/runner/Local.ts +3 -2
  254. package/src/internal/runner/Lock.ts +1 -0
  255. package/src/internal/runner/Multiplex.ts +2 -1
  256. package/src/internal/runner/Packages.ts +7 -5
  257. package/src/internal/runner/ProcessObservation.ts +2 -1
  258. package/src/internal/runner/Processes.ts +3 -1
  259. package/src/internal/runner/Retention.ts +1 -0
  260. package/src/internal/runner/Store.ts +3 -2
  261. package/src/internal/runner/Supervisor.ts +22 -20
  262. package/src/internal/runner/Watchdog.ts +3 -1
  263. package/src/internal/runner/Wire.ts +13 -12
  264. package/src/internal/runner/accept.ts +6 -5
  265. package/src/internal/runner/command.ts +3 -2
  266. package/src/internal/runner/connectionEnded.ts +2 -1
  267. package/src/internal/runner/model.ts +5 -3
  268. package/src/internal/services.ts +9 -2
  269. package/src/internal/socketChannel.ts +2 -1
  270. package/src/internal/stdioChannel.ts +4 -2
  271. package/src/internal/supervisorPlugin.ts +10 -8
  272. package/src/internal/transportOptions.ts +1 -0
  273. package/src/internal/watchdogMain.ts +5 -3
  274. package/src/internal/websocket.ts +5 -2
  275. package/src/internal/websocketServer.ts +6 -4
  276. package/src/internal/workerChannel.ts +1 -0
  277. package/src/internal/workerMain.ts +21 -5
  278. package/src/runner/auth/bearer.ts +10 -6
  279. package/src/runner/auth/jwt.ts +10 -41
  280. package/src/runner/auth/mtls.ts +6 -3
  281. package/src/runner/auth/none.ts +3 -1
  282. package/src/runner/index.ts +102 -11
  283. package/src/runner/stdio.ts +15 -10
  284. package/src/runner/unix.ts +7 -4
  285. package/src/runner/websocket.ts +9 -7
  286. package/dist/Auth-BElTC9_X.js +0 -6
  287. package/dist/Bootstrap-H9gDsgsC.js +0 -9
  288. package/dist/ConfigDirectory-BCC6q2R4.js +0 -5
  289. package/dist/Contract-DsJtisvL.js +0 -83
  290. package/dist/Errors-DYhsGZcZ.js +0 -58
  291. package/dist/FailureGroup-BgT73AaR.js +0 -63
  292. package/dist/Framing-G9eSaeLb.js +0 -61
  293. package/dist/Graft-B71CPA2Y.js +0 -996
  294. package/dist/Packages-AgoCGotL.js +0 -108
  295. package/dist/Peer-DXeVrGBh.js +0 -342
  296. package/dist/ProcessObservation-gLgGirYv.js +0 -38
  297. package/dist/ServeLifecycle-Bd1FPJ6e.js +0 -24
  298. package/dist/Transport-DULzpsgR.js +0 -6
  299. package/dist/WatchdogProtocol-BZmVxrBP.js +0 -17
  300. package/dist/bin.js +0 -28276
  301. package/dist/bin.js.map +0 -1
  302. package/dist/childRuntime-Bm3iSg_N.js +0 -192
  303. package/dist/command-9zrHdbwT.js +0 -7
  304. package/dist/connectionEnded-BwcxQ7W8.js +0 -54
  305. package/dist/directTransport-DrexuPSm.js +0 -5
  306. package/dist/entry-psOpX3Bj.js +0 -736
  307. package/dist/importer-Cvf88eAY.js +0 -344
  308. package/dist/internal/ServeLifecycle.js.map +0 -1
  309. package/dist/internal/entryConfig.d.ts.map +0 -1
  310. package/dist/internal/platform.js.map +0 -1
  311. package/dist/internal/release.js +0 -25
  312. package/dist/internal/release.js.map +0 -1
  313. package/dist/internal/serve.js +0 -60
  314. package/dist/internal/serve.js.map +0 -1
  315. package/dist/port--3x2zJ4D.js +0 -285
  316. package/dist/release-DfZPuIcK.js +0 -23
  317. package/dist/rolldown-runtime-DYf_mQCB.js +0 -34
  318. package/dist/socketChannel-CJvL2DiB.js +0 -3658
  319. package/dist/supervisorPlugin-t6Z6PrhD.js +0 -733
  320. package/dist/token-CYBNNlhS.js +0 -17
  321. package/dist/tokenCredentials-CbCuk-Rt.js +0 -31
  322. package/dist/websocketServer-NQhODlEt.js +0 -60
  323. package/dist/workerChannel-C8hhBJzA.js +0 -27
  324. package/src/internal/release.ts +0 -72
  325. package/src/internal/serve.ts +0 -119
  326. /package/dist/{bin.d.ts → internal/childMain.d.ts} +0 -0
@@ -1,736 +0,0 @@
1
- import { c as isPlugin, i as plugin, l as make, o as fork, t as forks, u as optional } from "./Graft-B71CPA2Y.js";
2
- import { t as ConfigDirectory } from "./ConfigDirectory-BCC6q2R4.js";
3
- import { i as make$2, m as isSubtreeActive, n as ModuleInvalid, o as CurrentId, p as findSubtree, r as ModuleResolver, t as make$1 } from "./importer-Cvf88eAY.js";
4
- import { c as endpoint, n as UndeclaredFailure, o as endpoints, r as fromModule } from "./Contract-DsJtisvL.js";
5
- import { a as MissingInstance, c as RemoteError, i as LocalTerminationTimeout, l as RemoteWithdrawn, o as ProcessExited, r as CredentialsError, s as RemoteEntryError, t as AuthenticationFailed, u as TransportError } from "./Errors-DYhsGZcZ.js";
6
- import { n as WorkerTransport, t as LocalTransport } from "./directTransport-DrexuPSm.js";
7
- import { a as PositiveDuration, i as Supervisor, n as resolveEntry, r as verify } from "./Packages-AgoCGotL.js";
8
- import { E as make$3, _ as StateStorageError, a as ExecutionError, b as awaitTermination, c as PackageError, d as SessionAccessDenied, f as SessionConflict, g as StateDirectoryLocked, h as StaleSession, l as RemoteTerminationUnconfirmed, m as SessionStopped, n as Session, r as channel, s as LeaseExpired, t as Peer, u as RunnerClosing, x as childOf, y as TerminationUnconfirmed } from "./Peer-DXeVrGBh.js";
9
- import { n as Credentials, t as Authenticator } from "./Auth-BElTC9_X.js";
10
- import { n as Listener, t as Connector } from "./Transport-DULzpsgR.js";
11
- import { a as AlreadyLoaded, i as ActivationFailed, n as connectionEnded, o as ContractNotFound, r as prepare, s as ModuleImportFailed, t as closedNormally } from "./connectionEnded-BwcxQ7W8.js";
12
- import { t as ServeLifecycle } from "./ServeLifecycle-Bd1FPJ6e.js";
13
- import { n as children, r as cleanupCause, t as make$4 } from "./FailureGroup-BgT73AaR.js";
14
- import { n as make$5, o as defaults } from "./port--3x2zJ4D.js";
15
- import { n as close, t as ReleaseInterrupted } from "./release-DfZPuIcK.js";
16
- import { n as stdinExitTimeout } from "./ProcessObservation-gLgGirYv.js";
17
- import { Array, Cause, Context, Deferred, Duration, Effect, Exit, Fiber, Option, Path, PlatformError, Ref, References, Schema, Scope, Stream, String } from "effect";
18
- import { SecureRandom } from "effect/crypto";
19
- import { RpcClient, RpcClientError } from "effect/rpc";
20
- import { ChildProcessSpawner } from "effect/process";
21
- // packages/remote/src/internal/entryConfig.ts
22
- const Reference = Schema.Struct({
23
- name: Schema.String,
24
- config: Schema.optionalKey(Schema.Unknown)
25
- });
26
- const absent = Schema.optionalKey(Schema.Never);
27
- const authFields = {
28
- name: absent,
29
- config: absent,
30
- mtls: absent,
31
- bearer: absent,
32
- jwt: absent,
33
- none: absent
34
- };
35
- const Authentication = Schema.Union([
36
- Schema.Struct({
37
- ...authFields,
38
- name: Schema.String,
39
- config: Schema.optionalKey(Schema.Unknown)
40
- }),
41
- Schema.Struct({
42
- ...authFields,
43
- mtls: Schema.Unknown
44
- }),
45
- Schema.Struct({
46
- ...authFields,
47
- bearer: Schema.Unknown
48
- }),
49
- Schema.Struct({
50
- ...authFields,
51
- jwt: Schema.Unknown
52
- }),
53
- Schema.Struct({
54
- ...authFields,
55
- none: Schema.Unknown
56
- })
57
- ]);
58
- const transportFields = {
59
- url: absent,
60
- unix: absent,
61
- command: absent,
62
- stdio: absent,
63
- local: absent,
64
- worker: absent,
65
- transport: absent
66
- };
67
- const auth = Schema.optionalKey(Authentication);
68
- const common = {
69
- instance: Schema.optionalKey(Schema.String),
70
- lease: Schema.optionalKey(PositiveDuration),
71
- margin: Schema.optionalKey(PositiveDuration),
72
- expect: Schema.optionalKey(Schema.Struct({
73
- version: Schema.optionalKey(Schema.String),
74
- digest: Schema.optionalKey(Schema.String)
75
- }))
76
- };
77
- const network = {
78
- ...transportFields,
79
- ...common,
80
- auth,
81
- url: Schema.String,
82
- ca: Schema.optionalKey(Schema.String),
83
- servername: Schema.optionalKey(Schema.String)
84
- };
85
- const Connect = Schema.Union([
86
- Schema.Struct(network),
87
- Schema.Struct({
88
- ...transportFields,
89
- ...common,
90
- auth,
91
- unix: Schema.String
92
- }),
93
- Schema.Struct({
94
- ...transportFields,
95
- ...common,
96
- command: Schema.NonEmptyArray(Schema.String),
97
- auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
98
- cwd: Schema.optionalKey(Schema.String),
99
- env: Schema.optionalKey(Schema.Record(Schema.String, Schema.String))
100
- }),
101
- Schema.Struct({
102
- ...transportFields,
103
- auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
104
- local: Schema.Struct({ command: Schema.optionalKey(Schema.NonEmptyArray(Schema.String)) })
105
- }),
106
- Schema.Struct({
107
- ...transportFields,
108
- auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
109
- worker: Schema.Struct({ execArgv: Schema.optionalKey(Schema.Array(Schema.String)) })
110
- }),
111
- Schema.Struct({
112
- ...transportFields,
113
- ...common,
114
- auth,
115
- transport: Reference
116
- })
117
- ]);
118
- const Listen = Schema.Union([
119
- Schema.Struct({
120
- ...transportFields,
121
- auth,
122
- url: Schema.String,
123
- cert: Schema.optionalKey(Schema.String),
124
- key: Schema.optionalKey(Schema.String)
125
- }),
126
- Schema.Struct({
127
- ...transportFields,
128
- auth,
129
- unix: Schema.String
130
- }),
131
- Schema.Struct({
132
- ...transportFields,
133
- stdio: Schema.Literal(true),
134
- auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
135
- identity: Schema.optionalKey(Schema.String)
136
- }),
137
- Schema.Struct({
138
- ...transportFields,
139
- auth,
140
- transport: Reference
141
- })
142
- ]);
143
- const capability = (side, name, config) => ({
144
- name: `@graftland/plugin-remote/${side}/${name}`,
145
- config
146
- });
147
- const authentication = (side, input) => {
148
- if (input === void 0) return capability(side, "auth/none", {});
149
- if (input.name !== void 0) return input;
150
- if (input.mtls !== void 0) return capability(side, "auth/mtls", input.mtls);
151
- if (input.bearer !== void 0) return capability(side, "auth/bearer", input.bearer);
152
- if (input.jwt !== void 0) return capability(side, "auth/jwt", input.jwt);
153
- return capability(side, "auth/none", input.none);
154
- };
155
- const hostTransport = (input) => {
156
- if (input.transport !== void 0) return input.transport;
157
- if (input.url !== void 0) return capability("host", "websocket", {
158
- url: input.url,
159
- ...input.ca === void 0 ? {} : { ca: input.ca },
160
- ...input.servername === void 0 ? {} : { servername: input.servername }
161
- });
162
- if (input.unix !== void 0) return capability("host", "unix", { path: input.unix });
163
- return capability("host", "command", {
164
- argv: input.command,
165
- ..."cwd" in input && input.cwd !== void 0 ? { cwd: input.cwd } : {},
166
- ..."env" in input && input.env !== void 0 ? { env: input.env } : {}
167
- });
168
- };
169
- const runnerTransport = (input) => {
170
- if (input.transport !== void 0) return input.transport;
171
- if (input.url !== void 0) return capability("runner", "websocket", {
172
- url: input.url,
173
- ...input.cert === void 0 ? {} : { cert: input.cert },
174
- ...input.key === void 0 ? {} : { key: input.key }
175
- });
176
- if (input.unix !== void 0) return capability("runner", "unix", { path: input.unix });
177
- return capability("runner", "stdio", {});
178
- };
179
- const Host = Schema.Struct({
180
- contract: Schema.String,
181
- connect: Connect,
182
- config: Schema.Json.pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
183
- });
184
- const Runner = Schema.Struct({
185
- root: Schema.String,
186
- state: Schema.String,
187
- lease: Schema.optionalKey(PositiveDuration),
188
- grace: Schema.optionalKey(PositiveDuration),
189
- listen: Schema.Array(Listen)
190
- });
191
- const runnerAuthentication = (input) => input.stdio !== void 0 ? capability("runner", "auth/none", { identity: input.identity ?? "anonymous" }) : authentication("runner", input.auth);
192
- // packages/remote/src/internal/follow.ts
193
- /** Follow startup and later failures without changing the caller's error boundary. */
194
- const follow = Effect.fnUntraced(function* (fork$1, fail) {
195
- yield* fork$1.await.pipe(Effect.catchCause(fail));
196
- yield* fork(fork$1.state.pipe(Stream.runForEach((state) => state._tag === "Failed" ? fail(state.cause) : Effect.void)));
197
- });
198
- // packages/remote/src/internal/assembly.ts
199
- var ListenerConfigError = class extends Schema.TaggedError()("ListenerConfigError", { detail: Schema.String }) {
200
- get message() {
201
- return this.detail;
202
- }
203
- };
204
- var CapabilityContractError = class extends Schema.TaggedError()("CapabilityContractError", {
205
- plugin: Schema.String,
206
- key: Schema.String
207
- }) {
208
- get message() {
209
- return `Capability ${this.plugin} became active without providing ${this.key}`;
210
- }
211
- };
212
- var CapabilityCombinationError = class extends Schema.TaggedError()("CapabilityCombinationError", { detail: Schema.String }) {
213
- get message() {
214
- return this.detail;
215
- }
216
- };
217
- var CapabilityFailed = class extends Schema.TaggedError()("CapabilityFailed", { cause: Schema.Cause(Schema.Unknown, Schema.Unknown) }) {};
218
- /** Every failure class assembly raises; host error classification reads this list. */
219
- const errors = [
220
- ListenerConfigError,
221
- CapabilityContractError,
222
- CapabilityCombinationError,
223
- CapabilityFailed
224
- ];
225
- const definition = Schema.declare(isPlugin);
226
- /** Entries resolve capability modules before assembling their private providers. */
227
- const Invocation = Schema.Struct({
228
- plugin: definition,
229
- config: Schema.Unknown
230
- });
231
- const Input = Schema.Struct({
232
- transport: Invocation,
233
- auth: Invocation,
234
- consumer: definition,
235
- input: Schema.optionalKey(Schema.Unknown)
236
- });
237
- const failure = (tree) => tree.state._tag === "Failed" ? Effect.fail(CapabilityFailed.make({ cause: tree.state.cause })) : Effect.forEach(tree.children, failure, { discard: true });
238
- const probe = (name, key) => make({
239
- name: "remote-capability-contract",
240
- inject: [optional(key)],
241
- apply: Effect.fnUntraced(function* () {
242
- const value = yield* Effect.serviceOption(key);
243
- if (Option.isNone(value)) return yield* CapabilityContractError.make({
244
- plugin: name,
245
- key: key.key
246
- });
247
- })
248
- });
249
- /** Resolve the key in a fresh consumer after the provider subtree settles.
250
- * An optional consumer started earlier could still hold a pre-publication snapshot.
251
- */
252
- const watch = (provider, key) => fork(forks.pipe(Stream.map((trees) => findSubtree(trees, provider.id)), Stream.filter(Option.isSome), Stream.map((tree) => tree.value), Stream.tap(failure), Stream.map((tree) => ({
253
- name: tree.name,
254
- active: isSubtreeActive(tree)
255
- })), Stream.changesWith((left, right) => left.active === right.active), Stream.filter((tree) => tree.active), Stream.runForEach((tree) => Effect.scoped(plugin(probe(tree.name, key)).pipe(Effect.flatMap((fork) => fork.await))))));
256
- const assembly = (keys) => make({
257
- name: "remote-assembly",
258
- config: Input,
259
- apply: Effect.fnUntraced(function* (input) {
260
- yield* Effect.forEach([{
261
- invocation: input.transport,
262
- key: keys[0]
263
- }, {
264
- invocation: input.auth,
265
- key: keys[1]
266
- }], Effect.fnUntraced(function* ({ invocation, key }) {
267
- const provider = yield* plugin(invocation.plugin, invocation.config);
268
- yield* watch(provider, key);
269
- }));
270
- const consumer = yield* plugin(input.consumer, input.input);
271
- yield* consumer.state.pipe(Stream.filter((state) => state._tag !== "Loading" && (state._tag !== "Pending" || !Array.some(keys, (key) => Array.contains(state.missing, key.key)))), Stream.runHead);
272
- yield* follow(consumer, (cause) => Effect.fail(CapabilityFailed.make({ cause })));
273
- })
274
- });
275
- const hostAssembly = assembly([Connector, Credentials]);
276
- const runnerAssembly = assembly([Listener, Authenticator]);
277
- const host$1 = (input) => plugin(hostAssembly, input, { isolate: [Connector, Credentials] });
278
- const runner = (input, consumer = listenerConsumer) => plugin(runnerAssembly, {
279
- ...input,
280
- consumer
281
- }, { isolate: [Listener, Authenticator] });
282
- const compatible = (properties, kind) => {
283
- if (kind === "Certificate" && (properties.protocol !== "wss" || !properties.encrypted || !Array.contains(properties.carries, "certificate"))) return Effect.fail(CapabilityCombinationError.make({ detail: "Mutual TLS requires encrypted wss with certificate evidence" }));
284
- if (kind === "Authorization" && !Array.contains(properties.carries, "header")) return Effect.fail(CapabilityCombinationError.make({ detail: "This transport cannot carry Authorization headers" }));
285
- return Effect.void;
286
- };
287
- const kind = (auth) => auth._tag === "Mtls" ? "Certificate" : auth._tag === "Header" ? "Authorization" : "None";
288
- const warn = (properties, credentials, side) => Effect.all([properties.network && !properties.encrypted ? Effect.logWarning(credentials === "Authorization" ? `${properties.protocol}:// ${side === "host" ? "connection" : "listener"} is unencrypted; credentials are transmitted in plaintext` : `${properties.protocol}:// ${side === "host" ? "connection" : "listener"} is unencrypted`) : Effect.void, side === "runner" && properties.network && credentials === "None" ? Effect.logWarning("WebSocket listener has no authentication") : Effect.void], { discard: true });
289
- const directAuth = (properties, explicit) => explicit && (properties.protocol === "stdio" || properties.protocol === "command") ? Effect.fail(CapabilityCombinationError.make({ detail: `${properties.protocol} transports do not accept auth` })) : Effect.void;
290
- const connectWith = Effect.fnUntraced(function* (explicitAuth = false) {
291
- const connector = yield* Connector;
292
- const credentials = yield* Credentials;
293
- yield* directAuth(connector.properties, explicitAuth);
294
- yield* compatible(connector.properties, credentials.kind);
295
- yield* warn(connector.properties, credentials.kind, "host");
296
- const prepared = yield* credentials.read;
297
- return yield* connector.connect(prepared);
298
- });
299
- const accept = (auth, properties, session) => (handshake) => {
300
- return (auth._tag === "Header" ? auth.authenticate(handshake.authorization) : auth._tag === "Mtls" ? Option.match(handshake.certificate, {
301
- onNone: () => Effect.fail(AuthenticationFailed.make({ reason: "missing" })),
302
- onSome: auth.authenticate
303
- }) : (properties.network ? Effect.logWarning("WebSocket connection has no authentication") : Effect.void).pipe(Effect.as(auth.identity))).pipe(Effect.map(session));
304
- };
305
- const makeListenerConsumer = (prepare = () => Effect.void, ready = Effect.void) => make({
306
- name: "remote-listener-consumer",
307
- inject: [
308
- Listener,
309
- Authenticator,
310
- Supervisor,
311
- optional(ServeLifecycle)
312
- ],
313
- apply: Effect.fnUntraced(function* () {
314
- const listener = yield* Listener;
315
- const auth = yield* Authenticator;
316
- const supervisor = yield* Supervisor;
317
- const lifecycle = yield* Effect.serviceOption(ServeLifecycle);
318
- yield* prepare(listener.properties, auth);
319
- yield* compatible(listener.properties, kind(auth)).pipe(Effect.mapError((error) => ListenerConfigError.make({ detail: error.detail })));
320
- yield* warn(listener.properties, kind(auth), "runner");
321
- const serving = yield* listener.bind(auth._tag === "Mtls" ? Option.some(auth.tls) : Option.none());
322
- const running = yield* fork(serving.serve(accept(auth, listener.properties, (identity) => (channel) => supervisor.accept(channel).pipe(Effect.catchCause((cause) => listener.properties.protocol === "stdio" ? closedNormally(cause) ? Effect.void : Effect.failCause(cause) : connectionEnded(cause)), Effect.provideService(Peer, identity)))).pipe(Effect.onExit((exit) => listener.properties.protocol === "stdio" && Option.isSome(lifecycle) ? Deferred.done(lifecycle.value.ended, exit) : Effect.void)));
323
- yield* serving.ready.pipe(Effect.raceFirst(Fiber.join(running)));
324
- yield* ready;
325
- })
326
- });
327
- const listenerConsumer = makeListenerConsumer();
328
- connectWith();
329
- // packages/remote/src/internal/host/runner.ts
330
- const connect$1 = Effect.fnUntraced(function* (target, contractModule, options, resources, processScope) {
331
- const instance = target.instance;
332
- const margin = Duration.toMillis(target.margin ?? "5 seconds");
333
- const channel$1 = yield* connectWith(target.explicitAuth).pipe(Scope.provide(processScope));
334
- const mux = yield* make$3(channel$1).pipe(Scope.provide(resources));
335
- const control = yield* make$5(channel(mux, 0), {
336
- session: "session-v1",
337
- serve: {},
338
- call: { session: Session }
339
- }).pipe(Scope.provide(resources));
340
- const session = yield* RpcClient.make(Session).pipe(Effect.provideService(RpcClient.Protocol, control.clientProtocol("session")), Scope.provide(resources));
341
- const expectedGeneration = yield* session.HighWater({ instance });
342
- const record = yield* session.Open({
343
- instance,
344
- expectedGeneration,
345
- requestId: options.session,
346
- limits: defaults,
347
- ...target.lease === void 0 ? {} : { leaseMillis: Duration.toMillis(target.lease) }
348
- });
349
- const failures = yield* make$4().pipe(Scope.provide(resources));
350
- const finishStarted = yield* Ref.make(false);
351
- const terminate = yield* Effect.cached(Effect.gen(function* () {
352
- yield* Ref.set(finishStarted, true);
353
- const closed = yield* Effect.exit(failures.close);
354
- const result = yield* awaitTermination(record.handle, session.Dispose(record.handle), record.leaseMillis, margin);
355
- const { code, signal, stderr, cause } = result.exit;
356
- yield* Effect.logInfo("Remote execution terminated", {
357
- code,
358
- ...signal === null ? {} : { signal },
359
- ...stderr === void 0 || stderr === "" ? {} : { stderr },
360
- ...cause === void 0 || cause.reasons.length === 0 ? {} : { cause }
361
- }).pipe(Effect.annotateLogs({
362
- "remote.instance": record.handle.key.instance,
363
- "remote.generation": record.handle.generation,
364
- "remote.termination": result.kind
365
- }));
366
- const failure = Exit.isFailure(closed) ? Cause.combine(closed.cause, result.cause) : result.cause;
367
- if (failure.reasons.length > 0) return yield* Effect.failCause(cleanupCause(failure));
368
- }));
369
- yield* Scope.addFinalizer(processScope, Effect.gen(function* () {
370
- if (!(yield* Ref.get(finishStarted))) yield* terminate.pipe(Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))));
371
- }));
372
- const renewed = yield* Effect.forever(Effect.sleep(record.leaseMillis / 3).pipe(Effect.andThen(session.Renew(record.handle)))).pipe(Effect.forkIn(resources));
373
- const code = yield* session.Load({
374
- handle: record.handle,
375
- specifier: contractModule,
376
- digest: target.expect?.digest !== void 0
377
- });
378
- yield* verify(code, target.expect);
379
- const loaded = yield* session.Status(record.handle);
380
- const peer = yield* make$5(channel(mux, 1), {
381
- ...options,
382
- session: record.handle.token,
383
- limits: record.limits
384
- }).pipe(Scope.provide(resources));
385
- const report = (cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : failures.failCause(Cause.map(cause, (error) => TransportError.make({ cause: Cause.fail(error) })));
386
- yield* failures.await.pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : peer.fail(TransportError.make({ cause }))), Effect.forkIn(resources));
387
- yield* failures.run(Fiber.join(renewed).pipe(Effect.catchCause(Effect.fnUntraced(function* (cause) {
388
- if (Cause.hasInterruptsOnly(cause)) return;
389
- const status = yield* Effect.exit(session.Status(record.handle).pipe(Effect.timeout("5 seconds")));
390
- if (Exit.isSuccess(status) && status.value.phase === "Stopped") {
391
- const exit = status.value.termination.exit;
392
- yield* report(Cause.combine(cause, Cause.fail(ProcessExited.make({
393
- pid: Option.map(childOf(loaded), (child) => child.pid),
394
- exitCode: exit.code,
395
- stderr: exit.stderr ?? "",
396
- statusCause: exit.cause ?? Cause.empty
397
- }))));
398
- } else yield* report(Exit.isFailure(status) ? Cause.combine(cause, status.cause) : cause);
399
- }))));
400
- return {
401
- resources,
402
- pid: Option.map(childOf(loaded), (child) => child.pid),
403
- diagnostics: failures.cause,
404
- terminate: Effect.fnUntraced(function* () {
405
- yield* Fiber.interrupt(renewed);
406
- yield* terminate;
407
- }),
408
- transport: {
409
- ...peer,
410
- failure: peer.await,
411
- report
412
- }
413
- };
414
- });
415
- // packages/remote/src/internal/runner/Local.ts
416
- /** Direct execution observers stay alive until exit, including forced cleanup. */
417
- const connect = Effect.fnUntraced(function* (execution, options) {
418
- const failures = yield* make$4();
419
- const exited = yield* execution.exited.pipe(Effect.forkScoped);
420
- const peer = yield* make$5(execution.channel, options);
421
- yield* failures.run(Effect.raceFirst(peer.await, Fiber.join(exited).pipe(Effect.flatMap(Effect.fail))));
422
- const report = (cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : failures.fail(TransportError.make({ cause })).pipe(Effect.andThen(peer.fail(TransportError.make({ cause }))));
423
- yield* failures.run(execution.failure);
424
- return {
425
- ...peer,
426
- pid: execution.pid,
427
- ...execution.threadId === void 0 ? {} : { threadId: execution.threadId },
428
- exited,
429
- resources: yield* Effect.scope,
430
- transport: {
431
- ...peer,
432
- failure: failures.await,
433
- report
434
- },
435
- diagnostics: Fiber.await(exited).pipe(Effect.andThen(failures.cause)),
436
- terminate: Effect.fnUntraced(function* (graceful) {
437
- yield* failures.close;
438
- if (!graceful) return;
439
- const status = yield* peer.end.pipe(Effect.catchCauseIf(Cause.hasInterruptsOnly, () => Effect.void), Effect.andThen(Fiber.join(exited)), Effect.interruptible, Effect.timeoutOrElse({
440
- duration: stdinExitTimeout,
441
- orElse: () => LocalTerminationTimeout.make({
442
- ...Option.match(execution.pid, {
443
- onNone: () => ({}),
444
- onSome: (pid) => ({ pid })
445
- }),
446
- ...execution.threadId === void 0 ? {} : { threadId: execution.threadId }
447
- })
448
- }));
449
- if (status.exitCode !== 0 || status.statusCause.reasons.length > 0) return yield* status;
450
- })
451
- };
452
- });
453
- // packages/remote/src/internal/runner/Connection.ts
454
- var Connection = class extends Context.Service()("@graftland/plugin-remote/internal/runner/Connection") {};
455
- const connected = Connection.of;
456
- const Local = Effect.fnUntraced(function* (target, contractModule, options, resources, processScope) {
457
- const execution = yield* (yield* target._tag === "Local" ? LocalTransport : WorkerTransport).start({
458
- ...target,
459
- contractModule,
460
- session: options.session
461
- }).pipe(Scope.provide(processScope));
462
- return yield* connect(execution, options).pipe(Scope.provide(resources));
463
- });
464
- const reason = (exit) => Exit.isFailure(exit) ? exit.cause : Cause.empty;
465
- const finish = (causes) => {
466
- const cause = Array.reduce(causes, Cause.empty, Cause.combine);
467
- return cause.reasons.length === 0 ? Effect.void : Effect.failCause(cleanupCause(cause));
468
- };
469
- /** Close partially acquired resources too; the normal release observes exit before stopping readers. */
470
- const scopes = Effect.acquireRelease(Effect.all({
471
- resources: Scope.make(),
472
- process: Scope.make()
473
- }), Effect.fnUntraced(function* (scopes, exit) {
474
- const process = yield* Effect.exit(close(scopes.process, exit));
475
- const resources = yield* Effect.exit(close(scopes.resources, exit));
476
- yield* finish([reason(process), reason(resources)]);
477
- }));
478
- /** Setup supplies a concrete control lifecycle; release never reads a later-installed effect. */
479
- const acquire = Effect.fnUntraced(function* (target, contractModule, options, setup, dispose, timeout) {
480
- const owned = yield* scopes;
481
- const connection = yield* Effect.acquireRelease(Effect.gen(function* () {
482
- return target._tag === "Local" || target._tag === "Worker" ? yield* Local(target, contractModule, options, owned.resources, owned.process).pipe(Effect.map(connected)) : yield* connect$1(target, contractModule, options, owned.resources, owned.process);
483
- }).pipe(Effect.interruptible), Effect.fnUntraced(function* (connection, exit) {
484
- const process = yield* Effect.exit(close(owned.process, exit));
485
- yield* connection.diagnostics;
486
- const resources = yield* Effect.exit(close(owned.resources, exit));
487
- const diagnostics = yield* connection.diagnostics;
488
- yield* finish([
489
- reason(process),
490
- reason(resources),
491
- diagnostics
492
- ]);
493
- }));
494
- return yield* Effect.acquireRelease(setup.pipe(Effect.provideService(Connection, connection)), Effect.fnUntraced(function* (value) {
495
- const graceful = yield* dispose(value).pipe(Effect.interruptible, Effect.timeout(timeout), Effect.exit);
496
- const terminated = yield* Effect.exit(connection.terminate(Exit.isSuccess(graceful)));
497
- yield* finish([Exit.isSuccess(graceful) ? graceful.value : graceful.cause, reason(terminated)]);
498
- }));
499
- });
500
- // packages/remote/src/internal/host.ts
501
- const race = (connection, effect) => Effect.raceFirst(effect, connection.transport.failure);
502
- const forwardEvents = Effect.fnUntraced(function* (contract, client, connection) {
503
- const stopped = yield* Deferred.make();
504
- const remoteFailure = yield* make$4();
505
- return {
506
- stopped,
507
- remoteFailure,
508
- events: yield* race(connection, client.Events().pipe(Stream.runForEach((event) => {
509
- switch (event._tag) {
510
- case "Stopped": return Deferred.succeed(stopped, void 0);
511
- case "Withdrawing": return remoteFailure.fail(RemoteWithdrawn.make({}));
512
- case "Failed": return contract.decodeCause(event.cause).pipe(Effect.flatMap((cause) => remoteFailure.failCause(cause)));
513
- }
514
- }))).pipe(Effect.tapCause(connection.transport.report), Effect.forkIn(connection.resources))
515
- };
516
- });
517
- const forwardLogs = Effect.fnUntraced(function* (contract, client, connection) {
518
- const logsEnded = yield* Deferred.make();
519
- const reportedDrops = yield* Ref.make(0);
520
- yield* race(connection, client.Logs().pipe(Stream.runForEach(Effect.fnUntraced(function* (event) {
521
- const previous = yield* Ref.getAndSet(reportedDrops, event.dropped);
522
- if (event.dropped > previous) yield* Effect.logWarning("Remote logs were dropped").pipe(Effect.annotateLogs({
523
- ...Option.isSome(connection.pid) ? { "remote.pid": connection.pid.value } : {},
524
- "remote.logs.dropped": event.dropped - previous,
525
- "remote.logs.droppedTotal": event.dropped
526
- }));
527
- if (event._tag === "LogsEnded") {
528
- yield* Deferred.succeed(logsEnded, void 0);
529
- return;
530
- }
531
- const entry = event.entry;
532
- const cause = yield* contract.decodeCause(entry.cause);
533
- yield* Effect.logWithLevel(entry.level === "All" || entry.level === "None" ? "Info" : entry.level)(...Array.isArray(entry.message) ? entry.message : [entry.message], cause).pipe(Effect.annotateLogs({
534
- ...Option.isSome(connection.pid) ? { "remote.pid": connection.pid.value } : {},
535
- ...connection.threadId === void 0 ? {} : { "remote.threadId": connection.threadId },
536
- "remote.annotations": entry.annotations
537
- }));
538
- })))).pipe(Effect.tapCause(connection.transport.report), Effect.forkIn(connection.resources));
539
- return logsEnded;
540
- });
541
- const initialize = Effect.fnUntraced(function* (contract) {
542
- const connection = yield* Connection;
543
- const client = yield* RpcClient.make(contract.control).pipe(Effect.provideService(RpcClient.Protocol, connection.transport.clientProtocol(endpoint)), Scope.provide(connection.resources));
544
- for (const service of contract.inject) yield* service.serve(connection.transport).pipe(Effect.tapCause(connection.transport.report), Effect.forkIn(connection.resources));
545
- const events = yield* forwardEvents(contract, client, connection);
546
- const logsEnded = yield* forwardLogs(contract, client, connection);
547
- return {
548
- connection,
549
- client,
550
- ...events,
551
- logsEnded
552
- };
553
- });
554
- const load$1 = (active, input) => race(active.connection, Effect.raceFirst(active.client.Load({ input }).pipe(Effect.catchIf((cause) => Cause.isCause(cause), Effect.failCause)), active.remoteFailure.await));
555
- const dispose = Effect.fnUntraced(function* (active) {
556
- const result = yield* race(active.connection, active.client.Dispose().pipe(Effect.catchIf(Cause.isCause, Effect.succeed)));
557
- const cause = Cause.isCause(result) ? result : Cause.empty;
558
- yield* race(active.connection, Deferred.await(active.stopped).pipe(Effect.andThen(Deferred.await(active.logsEnded)))).pipe(Effect.onError(() => Effect.failCause(cleanupCause(cause))));
559
- return cause;
560
- });
561
- // packages/remote/src/internal/execution.ts
562
- const dependencies = (target) => target._tag === "Connector" ? [Connector, Credentials] : target._tag === "Local" ? [LocalTransport] : [WorkerTransport];
563
- /** One owned execution per activation, with explicitly mapped services. */
564
- const executionPlugin = (contract, options, configured, annotations = {}) => make({
565
- name: contract.name,
566
- inject: [
567
- SecureRandom.SecureRandom,
568
- ...dependencies(configured),
569
- ...Array.map(contract.inject, (service) => service.key)
570
- ],
571
- config: Schema.toEncoded(contract.config),
572
- apply: Effect.fnUntraced(function* (input) {
573
- const prepared = prepare(contract);
574
- const session = yield* (yield* SecureRandom.SecureRandom).uuidV4();
575
- const active = yield* acquire(configured, options.contractModule, {
576
- session,
577
- serve: endpoints(contract.inject),
578
- call: {
579
- ...endpoints(contract.provides),
580
- [endpoint]: prepared.control
581
- }
582
- }, initialize(prepared), dispose, options.shutdownTimeout ?? "5 seconds");
583
- yield* load$1(active, input);
584
- for (const service of contract.provides) yield* service.publish(active.connection.transport).pipe(Scope.provide(active.connection.resources));
585
- yield* fork(Effect.raceFirst(Fiber.join(active.events), active.remoteFailure.await).pipe(Effect.mapError((error) => publicError(contract.error, error))));
586
- return () => Effect.succeed(false);
587
- }, Effect.annotateLogs(annotations), Effect.mapError((error) => publicError(contract.error, error)))
588
- });
589
- /** Failures raised by the host machinery; a permissive declared schema must not claim them. */
590
- const internalErrors = [
591
- ProcessExited,
592
- TransportError,
593
- LocalTerminationTimeout,
594
- CredentialsError,
595
- AuthenticationFailed,
596
- RemoteEntryError,
597
- AlreadyLoaded,
598
- ContractNotFound,
599
- ModuleImportFailed,
600
- ActivationFailed,
601
- PackageError,
602
- SessionAccessDenied,
603
- StaleSession,
604
- LeaseExpired,
605
- SessionStopped,
606
- SessionConflict,
607
- StateStorageError,
608
- ExecutionError,
609
- TerminationUnconfirmed,
610
- RunnerClosing,
611
- StateDirectoryLocked,
612
- RemoteTerminationUnconfirmed,
613
- ReleaseInterrupted,
614
- RpcClientError.RpcClientError,
615
- ...errors
616
- ];
617
- const isInternal = (error) => Schema.isSchemaError(error) || PlatformError.isPlatformError(error) || Array.some(internalErrors, (Class) => error instanceof Class);
618
- const isPublic = (error) => Schema.is(UndeclaredFailure)(error) || Schema.is(RemoteWithdrawn)(error) || Schema.is(RemoteError)(error) || Schema.is(MissingInstance)(error);
619
- const publicError = (declared, error) => isPublic(error) ? error : !isInternal(error) && Schema.is(declared)(error) ? error : RemoteError.make({ cause: Cause.fail(error) });
620
- // packages/remote/src/internal/entry.ts
621
- const boundary = Effect.fnUntraced(function* (field) {
622
- const entry = yield* CurrentId;
623
- const directory = yield* ConfigDirectory;
624
- return (cause) => Effect.fail(RemoteEntryError.make({
625
- entry,
626
- directory,
627
- field,
628
- cause
629
- }));
630
- });
631
- const resolve = Effect.fnUntraced(function* (reference, field) {
632
- const existing = yield* Effect.serviceOption(ModuleResolver);
633
- const path = yield* Path.Path;
634
- const source = yield* ConfigDirectory;
635
- const directory = path.resolve(Option.getOrElse(source, () => "."));
636
- const resolver = yield* Option.match(existing, {
637
- onSome: Effect.succeed,
638
- onNone: Effect.fnUntraced(function* () {
639
- const importer = yield* make$1(directory);
640
- return yield* make$2({
641
- base: directory,
642
- importer: (specifier) => String.startsWith("@graftland/plugin-remote/")(specifier) ? import(specifier) : importer(specifier)
643
- });
644
- })
645
- });
646
- const fail = yield* boundary(field);
647
- return {
648
- plugin: yield* resolver.resolve(reference.name).pipe(Effect.catchCause(fail)),
649
- config: reference.config
650
- };
651
- });
652
- const loadContract = Effect.fnUntraced(function* (specifier) {
653
- const resolver = yield* ModuleResolver;
654
- const fail = yield* boundary("contract");
655
- return yield* resolver.importModule(specifier).pipe(Effect.flatMap((module) => Effect.fromOption(fromModule(module), () => ModuleInvalid.make({
656
- specifier,
657
- cause: "Expected a default or named remote contract"
658
- }))), Effect.catchCause(fail));
659
- });
660
- /** Direct execution installs only its execution capability in a private realm. */
661
- const direct = (provider, consumer, input, key) => plugin(make({
662
- name: "remote-direct",
663
- apply: Effect.fnUntraced(function* () {
664
- const capability = yield* plugin(provider);
665
- yield* follow(capability, (cause) => Effect.fail(CapabilityFailed.make({ cause })));
666
- const execution = yield* plugin(consumer, input);
667
- yield* follow(execution, (cause) => Effect.fail(CapabilityFailed.make({ cause })));
668
- })
669
- }), void 0, { isolate: [key] });
670
- const directTarget = Effect.fnUntraced(function* (contract, input, selected, annotations, options) {
671
- const path = yield* Path.Path;
672
- const source = yield* ConfigDirectory;
673
- const directory = path.resolve(Option.getOrElse(source, () => "."));
674
- const module = String.startsWith("file:")(input.contract) ? input.contract : yield* resolveEntry(directory, input.contract);
675
- const capability = yield* resolve({ name: selected._tag === "Local" ? "@graftland/plugin-remote/host/local" : "@graftland/plugin-remote/host/worker" }, "connect");
676
- return yield* direct(capability.plugin, executionPlugin(contract, {
677
- ...options,
678
- contractModule: module
679
- }, selected, annotations), input.config, selected._tag === "Local" ? LocalTransport : WorkerTransport);
680
- });
681
- const runnerTarget = Effect.fnUntraced(function* (contract, input, target, annotations, options, authOverride) {
682
- const instance = target.instance === void 0 ? yield* CurrentId : Option.some(target.instance);
683
- if (Option.isNone(instance)) return yield* MissingInstance.make({});
684
- const transport = yield* resolve(hostTransport(target), "connect.transport");
685
- const auth = authOverride ?? (yield* resolve(authentication("host", target.auth), "connect.auth"));
686
- const consumer = executionPlugin(contract, options, {
687
- _tag: "Connector",
688
- explicitAuth: target.auth !== void 0,
689
- instance: instance.value,
690
- ...target.lease === void 0 ? {} : { lease: target.lease },
691
- ...target.margin === void 0 ? {} : { margin: target.margin },
692
- ...target.expect === void 0 ? {} : { expect: target.expect }
693
- }, annotations);
694
- return yield* host$1({
695
- transport,
696
- auth,
697
- consumer,
698
- input: input.config
699
- });
700
- });
701
- const launch = Effect.fnUntraced(function* (contract, input, options, authOverride) {
702
- const annotations = yield* References.CurrentLogAnnotations;
703
- const connect = input.connect;
704
- const scope = yield* children;
705
- return yield* Effect.gen(function* () {
706
- if (connect.local !== void 0) return yield* directTarget(contract, input, {
707
- _tag: "Local",
708
- ...connect.local
709
- }, annotations, options);
710
- if (connect.worker !== void 0) return yield* directTarget(contract, input, {
711
- _tag: "Worker",
712
- ...connect.worker
713
- }, annotations, options);
714
- return yield* runnerTarget(contract, input, connect, annotations, options, authOverride);
715
- }).pipe(Scope.provide(scope));
716
- });
717
- const load = Effect.fnUntraced(function* (input) {
718
- const contract = yield* loadContract(input.contract);
719
- const failConfig = yield* boundary("config");
720
- yield* Schema.decodeEffect(contract.config)(input.config).pipe(Effect.catchCause(failConfig));
721
- const failConnect = yield* boundary("connect");
722
- const fork = yield* launch(contract, input, { contractModule: input.contract }).pipe(Effect.catchCause(failConnect));
723
- yield* follow(fork, failConnect);
724
- });
725
- const host = make({
726
- name: "remote",
727
- config: Host,
728
- inject: [
729
- SecureRandom.SecureRandom,
730
- ModuleResolver,
731
- Path.Path,
732
- ChildProcessSpawner.ChildProcessSpawner
733
- ],
734
- apply: load
735
- });
736
- export { publicError as a, directAuth as c, follow as d, Host as f, runnerTransport as h, resolve as i, makeListenerConsumer as l, runnerAuthentication as m, host as n, CapabilityCombinationError as o, Runner as p, launch as r, CapabilityFailed as s, boundary as t, runner as u };