@di-code/coding-agent 0.1.7 → 0.1.9

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 (333) hide show
  1. package/README.md +54 -567
  2. package/compositions/base.yml +54 -0
  3. package/compositions/interactive.yml +14 -0
  4. package/compositions/json.yml +6 -0
  5. package/compositions/print.yml +5 -0
  6. package/compositions/rpc.yml +12 -0
  7. package/compositions/webui.yml +9 -0
  8. package/dist/cli.d.ts +22 -1
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +97 -3
  11. package/dist/cli.js.map +1 -1
  12. package/dist/composition-loader-entry.d.ts +11 -0
  13. package/dist/composition-loader-entry.d.ts.map +1 -0
  14. package/dist/composition-loader-entry.js +12 -0
  15. package/dist/composition-loader-entry.js.map +1 -0
  16. package/dist/compositions.d.ts +32 -0
  17. package/dist/compositions.d.ts.map +1 -0
  18. package/dist/compositions.js +173 -0
  19. package/dist/compositions.js.map +1 -0
  20. package/dist/core/session/session-manager.d.ts +9 -2
  21. package/dist/core/session/session-manager.d.ts.map +1 -1
  22. package/dist/core/session/session-manager.js +28 -0
  23. package/dist/core/session/session-manager.js.map +1 -1
  24. package/dist/core/session/session-storage.d.ts.map +1 -1
  25. package/dist/core/session/session-storage.js +20 -3
  26. package/dist/core/session/session-storage.js.map +1 -1
  27. package/dist/core/session/types.d.ts +11 -2
  28. package/dist/core/session/types.d.ts.map +1 -1
  29. package/dist/core/session/types.js.map +1 -1
  30. package/dist/core/session-tools.d.ts +5 -0
  31. package/dist/core/session-tools.d.ts.map +1 -0
  32. package/dist/core/session-tools.js +17 -0
  33. package/dist/core/session-tools.js.map +1 -0
  34. package/dist/core/session.d.ts +19 -7
  35. package/dist/core/session.d.ts.map +1 -1
  36. package/dist/core/session.js +71 -39
  37. package/dist/core/session.js.map +1 -1
  38. package/dist/core/tools/bash.d.ts +1 -38
  39. package/dist/core/tools/bash.d.ts.map +1 -1
  40. package/dist/core/tools/bash.js +1 -207
  41. package/dist/core/tools/bash.js.map +1 -1
  42. package/dist/core/tools/edit-diff.d.ts +1 -24
  43. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  44. package/dist/core/tools/edit-diff.js +1 -135
  45. package/dist/core/tools/edit-diff.js.map +1 -1
  46. package/dist/core/tools/edit.d.ts +1 -26
  47. package/dist/core/tools/edit.d.ts.map +1 -1
  48. package/dist/core/tools/edit.js +1 -140
  49. package/dist/core/tools/edit.js.map +1 -1
  50. package/dist/core/tools/file-mutation-queue.d.ts +1 -1
  51. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  52. package/dist/core/tools/file-mutation-queue.js +1 -23
  53. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  54. package/dist/core/tools/file-search.d.ts +1 -13
  55. package/dist/core/tools/file-search.d.ts.map +1 -1
  56. package/dist/core/tools/file-search.js +1 -98
  57. package/dist/core/tools/file-search.js.map +1 -1
  58. package/dist/core/tools/glob.d.ts +1 -10
  59. package/dist/core/tools/glob.d.ts.map +1 -1
  60. package/dist/core/tools/glob.js +1 -43
  61. package/dist/core/tools/glob.js.map +1 -1
  62. package/dist/core/tools/grep.d.ts +1 -12
  63. package/dist/core/tools/grep.d.ts.map +1 -1
  64. package/dist/core/tools/grep.js +1 -66
  65. package/dist/core/tools/grep.js.map +1 -1
  66. package/dist/core/tools/load-skill.d.ts +1 -9
  67. package/dist/core/tools/load-skill.d.ts.map +1 -1
  68. package/dist/core/tools/load-skill.js +1 -21
  69. package/dist/core/tools/load-skill.js.map +1 -1
  70. package/dist/core/tools/path-boundary.d.ts +1 -4
  71. package/dist/core/tools/path-boundary.d.ts.map +1 -1
  72. package/dist/core/tools/path-boundary.js +1 -65
  73. package/dist/core/tools/path-boundary.js.map +1 -1
  74. package/dist/core/tools/read.d.ts +1 -16
  75. package/dist/core/tools/read.d.ts.map +1 -1
  76. package/dist/core/tools/read.js +1 -131
  77. package/dist/core/tools/read.js.map +1 -1
  78. package/dist/core/tools/write.d.ts +1 -16
  79. package/dist/core/tools/write.d.ts.map +1 -1
  80. package/dist/core/tools/write.js +1 -44
  81. package/dist/core/tools/write.js.map +1 -1
  82. package/dist/entry.js +30 -28
  83. package/dist/entry.js.map +1 -1
  84. package/dist/index.d.ts +6 -3
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +6 -3
  87. package/dist/index.js.map +1 -1
  88. package/dist/interactive/builtin.d.ts +17 -0
  89. package/dist/interactive/builtin.d.ts.map +1 -0
  90. package/dist/interactive/builtin.js +47 -0
  91. package/dist/interactive/builtin.js.map +1 -0
  92. package/dist/interactive/controller.d.ts +85 -0
  93. package/dist/interactive/controller.d.ts.map +1 -0
  94. package/dist/interactive/controller.js +211 -0
  95. package/dist/interactive/controller.js.map +1 -0
  96. package/dist/interactive/index.d.ts +3 -0
  97. package/dist/interactive/index.d.ts.map +1 -0
  98. package/dist/interactive/index.js +3 -0
  99. package/dist/interactive/index.js.map +1 -0
  100. package/dist/interactive-host-entry.d.ts +7 -0
  101. package/dist/interactive-host-entry.d.ts.map +1 -0
  102. package/dist/interactive-host-entry.js +123 -0
  103. package/dist/interactive-host-entry.js.map +1 -0
  104. package/dist/interactive-profile.d.ts +18 -0
  105. package/dist/interactive-profile.d.ts.map +1 -0
  106. package/dist/interactive-profile.js +290 -0
  107. package/dist/interactive-profile.js.map +1 -0
  108. package/dist/interactive-resources-entry.d.ts +7 -0
  109. package/dist/interactive-resources-entry.d.ts.map +1 -0
  110. package/dist/interactive-resources-entry.js +42 -0
  111. package/dist/interactive-resources-entry.js.map +1 -0
  112. package/dist/legacy-main.d.ts +39 -0
  113. package/dist/legacy-main.d.ts.map +1 -0
  114. package/dist/legacy-main.js +611 -0
  115. package/dist/legacy-main.js.map +1 -0
  116. package/dist/main.d.ts +15 -34
  117. package/dist/main.d.ts.map +1 -1
  118. package/dist/main.js +130 -518
  119. package/dist/main.js.map +1 -1
  120. package/dist/mcp/entries.d.ts +42 -0
  121. package/dist/mcp/entries.d.ts.map +1 -0
  122. package/dist/mcp/entries.js +98 -0
  123. package/dist/mcp/entries.js.map +1 -0
  124. package/dist/mcp-client-entry.d.ts +5 -0
  125. package/dist/mcp-client-entry.d.ts.map +1 -0
  126. package/dist/mcp-client-entry.js +6 -0
  127. package/dist/mcp-client-entry.js.map +1 -0
  128. package/dist/mcp-config-entry.d.ts +5 -0
  129. package/dist/mcp-config-entry.d.ts.map +1 -0
  130. package/dist/mcp-config-entry.js +6 -0
  131. package/dist/mcp-config-entry.js.map +1 -0
  132. package/dist/mcp-tools-entry.d.ts +5 -0
  133. package/dist/mcp-tools-entry.d.ts.map +1 -0
  134. package/dist/mcp-tools-entry.js +6 -0
  135. package/dist/mcp-tools-entry.js.map +1 -0
  136. package/dist/mcp-transport-entry.d.ts +5 -0
  137. package/dist/mcp-transport-entry.d.ts.map +1 -0
  138. package/dist/mcp-transport-entry.js +6 -0
  139. package/dist/mcp-transport-entry.js.map +1 -0
  140. package/dist/modes/interactive-entry.d.ts +18 -0
  141. package/dist/modes/interactive-entry.d.ts.map +1 -0
  142. package/dist/modes/interactive-entry.js +21 -0
  143. package/dist/modes/interactive-entry.js.map +1 -0
  144. package/dist/modes/interactive.d.ts +16 -6
  145. package/dist/modes/interactive.d.ts.map +1 -1
  146. package/dist/modes/interactive.js +81 -32
  147. package/dist/modes/interactive.js.map +1 -1
  148. package/dist/modes/json-entry.d.ts +13 -0
  149. package/dist/modes/json-entry.d.ts.map +1 -0
  150. package/dist/modes/json-entry.js +14 -0
  151. package/dist/modes/json-entry.js.map +1 -0
  152. package/dist/modes/json.d.ts +4 -1
  153. package/dist/modes/json.d.ts.map +1 -1
  154. package/dist/modes/json.js +3 -3
  155. package/dist/modes/json.js.map +1 -1
  156. package/dist/modes/print-entry.d.ts +10 -0
  157. package/dist/modes/print-entry.d.ts.map +1 -0
  158. package/dist/modes/print-entry.js +11 -0
  159. package/dist/modes/print-entry.js.map +1 -0
  160. package/dist/modes/tree-selector.d.ts.map +1 -1
  161. package/dist/modes/tree-selector.js +4 -0
  162. package/dist/modes/tree-selector.js.map +1 -1
  163. package/dist/plugin-dump-composition.d.ts +6 -0
  164. package/dist/plugin-dump-composition.d.ts.map +1 -0
  165. package/dist/plugin-dump-composition.js +7 -0
  166. package/dist/plugin-dump-composition.js.map +1 -0
  167. package/dist/plugin-inventory.d.ts +7 -0
  168. package/dist/plugin-inventory.d.ts.map +1 -0
  169. package/dist/plugin-inventory.js +8 -0
  170. package/dist/plugin-inventory.js.map +1 -0
  171. package/dist/plugin-manager.d.ts +6 -0
  172. package/dist/plugin-manager.d.ts.map +1 -0
  173. package/dist/plugin-manager.js +7 -0
  174. package/dist/plugin-manager.js.map +1 -0
  175. package/dist/plugin-trace.d.ts +6 -0
  176. package/dist/plugin-trace.d.ts.map +1 -0
  177. package/dist/plugin-trace.js +7 -0
  178. package/dist/plugin-trace.js.map +1 -0
  179. package/dist/plugins/dynamic-broker.d.ts +76 -0
  180. package/dist/plugins/dynamic-broker.d.ts.map +1 -0
  181. package/dist/plugins/dynamic-broker.js +852 -0
  182. package/dist/plugins/dynamic-broker.js.map +1 -0
  183. package/dist/plugins/profile.d.ts +15 -0
  184. package/dist/plugins/profile.d.ts.map +1 -0
  185. package/dist/plugins/profile.js +34 -0
  186. package/dist/plugins/profile.js.map +1 -0
  187. package/dist/plugins/runtime-host.d.ts +37 -0
  188. package/dist/plugins/runtime-host.d.ts.map +1 -0
  189. package/dist/plugins/runtime-host.js +95 -0
  190. package/dist/plugins/runtime-host.js.map +1 -0
  191. package/dist/plugins/trust.d.ts +8 -0
  192. package/dist/plugins/trust.d.ts.map +1 -0
  193. package/dist/plugins/trust.js +59 -0
  194. package/dist/plugins/trust.js.map +1 -0
  195. package/dist/project-trust-entry.d.ts +15 -0
  196. package/dist/project-trust-entry.d.ts.map +1 -0
  197. package/dist/project-trust-entry.js +15 -0
  198. package/dist/project-trust-entry.js.map +1 -0
  199. package/dist/rpc/client.d.ts +78 -6
  200. package/dist/rpc/client.d.ts.map +1 -1
  201. package/dist/rpc/client.js +172 -4
  202. package/dist/rpc/client.js.map +1 -1
  203. package/dist/rpc/dispatcher.d.ts +121 -0
  204. package/dist/rpc/dispatcher.d.ts.map +1 -0
  205. package/dist/rpc/dispatcher.js +994 -0
  206. package/dist/rpc/dispatcher.js.map +1 -0
  207. package/dist/rpc/index.d.ts +2 -0
  208. package/dist/rpc/index.d.ts.map +1 -1
  209. package/dist/rpc/index.js +2 -0
  210. package/dist/rpc/index.js.map +1 -1
  211. package/dist/rpc/lifecycle.d.ts +6 -0
  212. package/dist/rpc/lifecycle.d.ts.map +1 -0
  213. package/dist/rpc/lifecycle.js +24 -0
  214. package/dist/rpc/lifecycle.js.map +1 -0
  215. package/dist/rpc/protocol.d.ts +112 -31
  216. package/dist/rpc/protocol.d.ts.map +1 -1
  217. package/dist/rpc/protocol.js +569 -117
  218. package/dist/rpc/protocol.js.map +1 -1
  219. package/dist/rpc/server-service.d.ts +7 -0
  220. package/dist/rpc/server-service.d.ts.map +1 -0
  221. package/dist/rpc/server-service.js +3 -0
  222. package/dist/rpc/server-service.js.map +1 -0
  223. package/dist/rpc/server.d.ts +16 -19
  224. package/dist/rpc/server.d.ts.map +1 -1
  225. package/dist/rpc/server.js +59 -115
  226. package/dist/rpc/server.js.map +1 -1
  227. package/dist/rpc-client-sdk-entry.d.ts +12 -0
  228. package/dist/rpc-client-sdk-entry.d.ts.map +1 -0
  229. package/dist/rpc-client-sdk-entry.js +11 -0
  230. package/dist/rpc-client-sdk-entry.js.map +1 -0
  231. package/dist/rpc-entry.js +50 -18
  232. package/dist/rpc-entry.js.map +1 -1
  233. package/dist/rpc-server-entry.d.ts +8 -0
  234. package/dist/rpc-server-entry.d.ts.map +1 -0
  235. package/dist/rpc-server-entry.js +67 -0
  236. package/dist/rpc-server-entry.js.map +1 -0
  237. package/dist/runtime/attachment-store.d.ts +13 -0
  238. package/dist/runtime/attachment-store.d.ts.map +1 -0
  239. package/dist/runtime/attachment-store.js +93 -0
  240. package/dist/runtime/attachment-store.js.map +1 -0
  241. package/dist/runtime/bootstrap.d.ts +14 -0
  242. package/dist/runtime/bootstrap.d.ts.map +1 -0
  243. package/dist/runtime/bootstrap.js +29 -0
  244. package/dist/runtime/bootstrap.js.map +1 -0
  245. package/dist/runtime/interactive-host-service.d.ts +22 -0
  246. package/dist/runtime/interactive-host-service.d.ts.map +1 -0
  247. package/dist/runtime/interactive-host-service.js +2 -0
  248. package/dist/runtime/interactive-host-service.js.map +1 -0
  249. package/dist/runtime/interactive-resource-service.d.ts +11 -0
  250. package/dist/runtime/interactive-resource-service.d.ts.map +1 -0
  251. package/dist/runtime/interactive-resource-service.js +3 -0
  252. package/dist/runtime/interactive-resource-service.js.map +1 -0
  253. package/dist/runtime/plugin-inventory-entry.d.ts +5 -0
  254. package/dist/runtime/plugin-inventory-entry.d.ts.map +1 -0
  255. package/dist/runtime/plugin-inventory-entry.js +18 -0
  256. package/dist/runtime/plugin-inventory-entry.js.map +1 -0
  257. package/dist/runtime/plugin-inventory-service.d.ts +8 -0
  258. package/dist/runtime/plugin-inventory-service.d.ts.map +1 -0
  259. package/dist/runtime/plugin-inventory-service.js +3 -0
  260. package/dist/runtime/plugin-inventory-service.js.map +1 -0
  261. package/dist/runtime/plugin-manager-entry.d.ts +20 -0
  262. package/dist/runtime/plugin-manager-entry.d.ts.map +1 -0
  263. package/dist/runtime/plugin-manager-entry.js +96 -0
  264. package/dist/runtime/plugin-manager-entry.js.map +1 -0
  265. package/dist/runtime/plugin-observability-entry.d.ts +12 -0
  266. package/dist/runtime/plugin-observability-entry.d.ts.map +1 -0
  267. package/dist/runtime/plugin-observability-entry.js +73 -0
  268. package/dist/runtime/plugin-observability-entry.js.map +1 -0
  269. package/dist/runtime/product-host.d.ts +91 -0
  270. package/dist/runtime/product-host.d.ts.map +1 -0
  271. package/dist/runtime/product-host.js +529 -0
  272. package/dist/runtime/product-host.js.map +1 -0
  273. package/dist/runtime/session-factory.d.ts +17 -0
  274. package/dist/runtime/session-factory.d.ts.map +1 -0
  275. package/dist/runtime/session-factory.js +75 -0
  276. package/dist/runtime/session-factory.js.map +1 -0
  277. package/dist/runtime/session-host.d.ts +152 -0
  278. package/dist/runtime/session-host.d.ts.map +1 -0
  279. package/dist/runtime/session-host.js +895 -0
  280. package/dist/runtime/session-host.js.map +1 -0
  281. package/dist/runtime-core-entry.d.ts +11 -0
  282. package/dist/runtime-core-entry.d.ts.map +1 -0
  283. package/dist/runtime-core-entry.js +9 -0
  284. package/dist/runtime-core-entry.js.map +1 -0
  285. package/dist/session-factory-entry.d.ts +7 -0
  286. package/dist/session-factory-entry.d.ts.map +1 -0
  287. package/dist/session-factory-entry.js +9 -0
  288. package/dist/session-factory-entry.js.map +1 -0
  289. package/dist/session-store-jsonl-entry.d.ts +7 -0
  290. package/dist/session-store-jsonl-entry.d.ts.map +1 -0
  291. package/dist/session-store-jsonl-entry.js +33 -0
  292. package/dist/session-store-jsonl-entry.js.map +1 -0
  293. package/dist/startup.d.ts +12 -1
  294. package/dist/startup.d.ts.map +1 -1
  295. package/dist/startup.js +106 -15
  296. package/dist/startup.js.map +1 -1
  297. package/dist/subagents/index.d.ts +2 -0
  298. package/dist/subagents/index.d.ts.map +1 -0
  299. package/dist/subagents/index.js +2 -0
  300. package/dist/subagents/index.js.map +1 -0
  301. package/dist/subagents/service.d.ts +50 -0
  302. package/dist/subagents/service.d.ts.map +1 -0
  303. package/dist/subagents/service.js +521 -0
  304. package/dist/subagents/service.js.map +1 -0
  305. package/dist/ui-host.d.ts +125 -0
  306. package/dist/ui-host.d.ts.map +1 -0
  307. package/dist/ui-host.js +275 -0
  308. package/dist/ui-host.js.map +1 -0
  309. package/dist/web/assets/index-BwfuGMvv.css +1 -0
  310. package/dist/web/assets/index-DPUaJqFJ.js +41 -0
  311. package/dist/web/assets/index-DPUaJqFJ.js.map +1 -0
  312. package/dist/web/index.html +14 -0
  313. package/dist/web-command.d.ts +11 -0
  314. package/dist/web-command.d.ts.map +1 -0
  315. package/dist/web-command.js +114 -0
  316. package/dist/web-command.js.map +1 -0
  317. package/dist/web-frontend.d.ts +73 -0
  318. package/dist/web-frontend.d.ts.map +1 -0
  319. package/dist/web-frontend.js +249 -0
  320. package/dist/web-frontend.js.map +1 -0
  321. package/dist/web.d.ts +254 -0
  322. package/dist/web.d.ts.map +1 -0
  323. package/dist/web.js +740 -0
  324. package/dist/web.js.map +1 -0
  325. package/dist/webui-entry.d.ts +3 -0
  326. package/dist/webui-entry.d.ts.map +1 -0
  327. package/dist/webui-entry.js +73 -0
  328. package/dist/webui-entry.js.map +1 -0
  329. package/dist/webui.d.ts +91 -0
  330. package/dist/webui.d.ts.map +1 -0
  331. package/dist/webui.js +882 -0
  332. package/dist/webui.js.map +1 -0
  333. package/package.json +89 -8
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/rpc/protocol.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAmD/C,MAAM,eAAe,GAA8B,IAAI,GAAG,CAAC;IAC1D,aAAa;IACb,iBAAiB;IACjB,qBAAqB;IACrB,kBAAkB;IAClB,gBAAgB;IAChB,MAAM;IACN,WAAW;IACX,WAAW;IACX,gBAAgB;IAChB,cAAc;CACd,CAAC,CAAC;AAEH,MAAM,eAAe,GAA2C,IAAI,GAAG,CAAC;IACvE,aAAa;IACb,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,aAAa;IACb,UAAU;IACV,sBAAsB;IACtB,oBAAoB;IACpB,WAAW;IACX,kBAAkB;IAClB,gBAAgB;IAChB,cAAc;CACd,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AA4B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H;YACC,OAAO,KAAK,CAAC;IACf,CAAC;AACF,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvC,OAAO,OAAO,CACb,KAAK;QACJ,IAAI;QACJ,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC;QAC9B,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC;QAC/B,iBAAiB,CAAC,KAAK,CAAC,SAAS,CAAC;QAClC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC;QACnC,iBAAiB,CAAC,KAAK,CAAC,WAAW,CAAC;QACpC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC;QAC7B,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC;QAC9B,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC;QACjC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC;QAClC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAC9B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACvD,OAAO;QACN,OAAO,EAAE,oBAAoB;QAC7B,IAAI,EAAE,UAAU;QAChB,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACjE,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;KACnD,CAAC;AACH,CAAC","sourcesContent":["import type { AssistantMessage } from \"@di-code/ai\";\nimport type { AgentSessionEvent } from \"../core/session.ts\";\n\nexport const RPC_PROTOCOL_VERSION = 1 as const;\nexport const RPC_MAX_ID_LENGTH = 128;\nexport const RPC_MAX_PROMPT_LENGTH = 1_000_000;\n\nexport type RpcMethod = \"prompt\" | \"cancel\" | \"get_state\";\n\nexport type RpcRequest =\n\t| {\n\t\t\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\t\t\treadonly kind: \"request\";\n\t\t\treadonly id: string;\n\t\t\treadonly method: \"prompt\";\n\t\t\treadonly params: { readonly message: string };\n\t }\n\t| {\n\t\t\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\t\t\treadonly kind: \"request\";\n\t\t\treadonly id: string;\n\t\t\treadonly method: \"cancel\";\n\t\t\treadonly params: { readonly requestId: string };\n\t }\n\t| {\n\t\t\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\t\t\treadonly kind: \"request\";\n\t\t\treadonly id: string;\n\t\t\treadonly method: \"get_state\";\n\t\t\treadonly params: Record<string, never>;\n\t };\n\nexport interface RpcSessionState {\n\treadonly sessionId: string;\n\treadonly modelId: string;\n\treadonly isStreaming: boolean;\n\treadonly messageCount: number;\n}\n\nexport type RpcSuccessResult =\n\t| { readonly method: \"prompt\"; readonly message: AssistantMessage }\n\t| { readonly method: \"cancel\"; readonly cancelled: boolean }\n\t| { readonly method: \"get_state\"; readonly state: RpcSessionState };\n\nexport type RpcErrorCode =\n\t| \"PARSE_ERROR\"\n\t| \"INVALID_REQUEST\"\n\t| \"UNSUPPORTED_VERSION\"\n\t| \"METHOD_NOT_FOUND\"\n\t| \"INVALID_PARAMS\"\n\t| \"BUSY\"\n\t| \"NOT_FOUND\"\n\t| \"CANCELLED\"\n\t| \"INTERNAL_ERROR\"\n\t| \"PROCESS_EXIT\";\n\nconst RPC_ERROR_CODES: ReadonlySet<RpcErrorCode> = new Set([\n\t\"PARSE_ERROR\",\n\t\"INVALID_REQUEST\",\n\t\"UNSUPPORTED_VERSION\",\n\t\"METHOD_NOT_FOUND\",\n\t\"INVALID_PARAMS\",\n\t\"BUSY\",\n\t\"NOT_FOUND\",\n\t\"CANCELLED\",\n\t\"INTERNAL_ERROR\",\n\t\"PROCESS_EXIT\",\n]);\n\nconst RPC_EVENT_TYPES: ReadonlySet<AgentSessionEvent[\"type\"]> = new Set([\n\t\"agent_start\",\n\t\"turn_start\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"turn_end\",\n\t\"tool_execution_start\",\n\t\"tool_execution_end\",\n\t\"agent_end\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"usage_update\",\n]);\n\nconst ASSISTANT_STOP_REASONS = new Set([\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\"]);\n\nexport interface RpcSuccessResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id: string;\n\treadonly ok: true;\n\treadonly result: RpcSuccessResult;\n}\n\nexport interface RpcErrorResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id?: string;\n\treadonly ok: false;\n\treadonly error: { readonly code: RpcErrorCode; readonly message: string };\n}\n\nexport interface RpcEventRecord {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"event\";\n\treadonly requestId: string;\n\treadonly event: AgentSessionEvent;\n}\n\nexport type RpcResponse = RpcSuccessResponse | RpcErrorResponse;\nexport type RpcServerMessage = RpcResponse | RpcEventRecord;\n\nexport class RpcProtocolError extends Error {\n\treadonly code: RpcErrorCode;\n\treadonly requestId?: string;\n\n\tconstructor(code: RpcErrorCode, message: string, requestId?: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RpcProtocolError\";\n\t\tthis.code = code;\n\t\tthis.requestId = requestId;\n\t}\n}\n\nfunction objectRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction requiredId(value: unknown, field: string, requestId?: string): string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_ID_LENGTH) {\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_REQUEST\",\n\t\t\t`${field} must be a non-empty string of at most ${RPC_MAX_ID_LENGTH} characters.`,\n\t\t\trequestId,\n\t\t);\n\t}\n\treturn value;\n}\n\nfunction parseJsonObject(line: string): Record<string, unknown> {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(line);\n\t} catch {\n\t\tthrow new RpcProtocolError(\"PARSE_ERROR\", \"RPC input must be valid JSON.\");\n\t}\n\tconst record = objectRecord(value);\n\tif (!record) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC input must be a JSON object.\");\n\treturn record;\n}\n\nfunction assertVersion(record: Record<string, unknown>, requestId?: string): void {\n\tif (record.version !== RPC_PROTOCOL_VERSION) {\n\t\tthrow new RpcProtocolError(\n\t\t\t\"UNSUPPORTED_VERSION\",\n\t\t\t`Unsupported RPC protocol version; expected ${RPC_PROTOCOL_VERSION}.`,\n\t\t\trequestId,\n\t\t);\n\t}\n}\n\nexport function parseRpcRequest(line: string): RpcRequest {\n\tconst record = parseJsonObject(line);\n\tconst candidateId = typeof record.id === \"string\" ? record.id : undefined;\n\tassertVersion(record, candidateId);\n\tif (record.kind !== \"request\") {\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC request kind must be \"request\".', candidateId);\n\t}\n\tconst id = requiredId(record.id, \"id\", candidateId);\n\tconst params = objectRecord(record.params);\n\tif (!params) throw new RpcProtocolError(\"INVALID_PARAMS\", \"RPC params must be an object.\", id);\n\n\tswitch (record.method) {\n\t\tcase \"prompt\": {\n\t\t\tconst message = params.message;\n\t\t\tif (typeof message !== \"string\" || message.trim().length === 0 || message.length > RPC_MAX_PROMPT_LENGTH) {\n\t\t\t\tthrow new RpcProtocolError(\n\t\t\t\t\t\"INVALID_PARAMS\",\n\t\t\t\t\t`prompt.message must be non-empty and at most ${RPC_MAX_PROMPT_LENGTH} characters.`,\n\t\t\t\t\tid,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { version: RPC_PROTOCOL_VERSION, kind: \"request\", id, method: \"prompt\", params: { message } };\n\t\t}\n\t\tcase \"cancel\":\n\t\t\treturn {\n\t\t\t\tversion: RPC_PROTOCOL_VERSION,\n\t\t\t\tkind: \"request\",\n\t\t\t\tid,\n\t\t\t\tmethod: \"cancel\",\n\t\t\t\tparams: { requestId: requiredId(params.requestId, \"cancel.requestId\", id) },\n\t\t\t};\n\t\tcase \"get_state\":\n\t\t\treturn { version: RPC_PROTOCOL_VERSION, kind: \"request\", id, method: \"get_state\", params: {} };\n\t\tdefault:\n\t\t\tthrow new RpcProtocolError(\"METHOD_NOT_FOUND\", \"Unknown RPC method.\", id);\n\t}\n}\n\nexport function parseRpcServerMessage(line: string): RpcServerMessage {\n\tconst record = parseJsonObject(line);\n\tassertVersion(record);\n\tif (record.kind === \"event\") {\n\t\trequiredId(record.requestId, \"requestId\");\n\t\tconst event = objectRecord(record.event);\n\t\tif (!event || typeof event.type !== \"string\" || !RPC_EVENT_TYPES.has(event.type as AgentSessionEvent[\"type\"])) {\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\t}\n\t\treturn record as unknown as RpcEventRecord;\n\t}\n\tif (record.kind !== \"response\") {\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC server message kind must be \"response\" or \"event\".');\n\t}\n\tif (record.ok === false) {\n\t\tconst error = objectRecord(record.error);\n\t\tif (\n\t\t\t!error ||\n\t\t\ttypeof error.code !== \"string\" ||\n\t\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\t\ttypeof error.message !== \"string\"\n\t\t) {\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error response has an invalid error object.\");\n\t\t}\n\t\tif (record.id !== undefined) requiredId(record.id, \"id\");\n\t\treturn record as unknown as RpcErrorResponse;\n\t}\n\tif (record.ok !== true) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC response ok must be a boolean.\");\n\trequiredId(record.id, \"id\");\n\tconst result = objectRecord(record.result);\n\tif (!result) {\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC success response must contain a result object.\");\n\t}\n\tassertSuccessResult(result);\n\treturn record as unknown as RpcSuccessResponse;\n}\n\nfunction assertSuccessResult(result: Record<string, unknown>): void {\n\tswitch (result.method) {\n\t\tcase \"prompt\": {\n\t\t\tconst message = objectRecord(result.message);\n\t\t\tif (\n\t\t\t\t!message ||\n\t\t\t\tmessage.role !== \"assistant\" ||\n\t\t\t\t!Array.isArray(message.content) ||\n\t\t\t\t!message.content.every(isAssistantContent) ||\n\t\t\t\ttypeof message.provider !== \"string\" ||\n\t\t\t\ttypeof message.model !== \"string\" ||\n\t\t\t\t!finiteNumber(message.timestamp) ||\n\t\t\t\ttypeof message.stopReason !== \"string\" ||\n\t\t\t\t!ASSISTANT_STOP_REASONS.has(message.stopReason) ||\n\t\t\t\t!isUsage(message.usage) ||\n\t\t\t\t(message.stopReason === \"error\" || message.stopReason === \"aborted\"\n\t\t\t\t\t? typeof message.errorMessage !== \"string\"\n\t\t\t\t\t: message.errorMessage !== undefined)\n\t\t\t) {\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC prompt response has an invalid message.\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"cancel\":\n\t\t\tif (typeof result.cancelled !== \"boolean\") {\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC cancel response has an invalid result.\");\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"get_state\": {\n\t\t\tconst state = objectRecord(result.state);\n\t\t\tif (\n\t\t\t\t!state ||\n\t\t\t\ttypeof state.sessionId !== \"string\" ||\n\t\t\t\tstate.sessionId.length === 0 ||\n\t\t\t\ttypeof state.modelId !== \"string\" ||\n\t\t\t\tstate.modelId.length === 0 ||\n\t\t\t\ttypeof state.isStreaming !== \"boolean\" ||\n\t\t\t\t!Number.isInteger(state.messageCount) ||\n\t\t\t\t(state.messageCount as number) < 0\n\t\t\t) {\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_state response has an invalid state.\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC success response has an unknown method.\");\n\t}\n}\n\nfunction finiteNumber(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isFinite(value);\n}\n\nfunction nonNegativeNumber(value: unknown): value is number {\n\treturn finiteNumber(value) && value >= 0;\n}\n\nfunction isAssistantContent(value: unknown): boolean {\n\tconst content = objectRecord(value);\n\tif (!content) return false;\n\tswitch (content.type) {\n\t\tcase \"text\":\n\t\t\treturn typeof content.text === \"string\";\n\t\tcase \"thinking\":\n\t\t\treturn typeof content.thinking === \"string\";\n\t\tcase \"tool_call\":\n\t\t\treturn (\n\t\t\t\ttypeof content.id === \"string\" &&\n\t\t\t\ttypeof content.name === \"string\" &&\n\t\t\t\tobjectRecord(content.arguments) !== undefined\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isUsage(value: unknown): boolean {\n\tconst usage = objectRecord(value);\n\tconst cost = objectRecord(usage?.cost);\n\treturn Boolean(\n\t\tusage &&\n\t\t\tcost &&\n\t\t\tnonNegativeNumber(usage.input) &&\n\t\t\tnonNegativeNumber(usage.output) &&\n\t\t\tnonNegativeNumber(usage.cacheRead) &&\n\t\t\tnonNegativeNumber(usage.cacheWrite) &&\n\t\t\tnonNegativeNumber(usage.totalTokens) &&\n\t\t\tnonNegativeNumber(cost.input) &&\n\t\t\tnonNegativeNumber(cost.output) &&\n\t\t\tnonNegativeNumber(cost.cacheRead) &&\n\t\t\tnonNegativeNumber(cost.cacheWrite) &&\n\t\t\tnonNegativeNumber(cost.total),\n\t);\n}\n\nexport function rpcErrorResponse(error: RpcProtocolError): RpcErrorResponse {\n\treturn {\n\t\tversion: RPC_PROTOCOL_VERSION,\n\t\tkind: \"response\",\n\t\t...(error.requestId === undefined ? {} : { id: error.requestId }),\n\t\tok: false,\n\t\terror: { code: error.code, message: error.message },\n\t};\n}\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/rpc/protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAC/C,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACxD,kHAAkH;AAClH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACxD,MAAM,gCAAgC,GAAG,IAAI,CAAC,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAErF,kGAAkG;AAClG,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,kBAAkB;IAClB,eAAe;IACf,eAAe;IACf,aAAa;IACb,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,UAAU;IACV,eAAe;IACf,OAAO;IACP,OAAO;IACP,eAAe;IACf,YAAY;IACZ,WAAW;IACX,aAAa;IACb,aAAa;IACb,oBAAoB;IACpB,SAAS;IACT,wBAAwB;IACxB,WAAW;IACX,aAAa;IACb,eAAe;IACf,mBAAmB;IACnB,gBAAgB;IAChB,cAAc;IACd,sBAAsB;IACtB,mBAAmB;IACnB,YAAY;IACZ,qBAAqB;IACrB,2BAA2B;IAC3B,OAAO;IACP,QAAQ;IACR,mBAAmB;IACnB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CAAC,OAAO,CAAC;QAC/B,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ;QACpC,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;QACjC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC;QACnC,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ;QACtC,CAAC,sBAAsB,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;QAE/C,MAAM,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,6CAA6C,CAAC,CAAC;AAC/F,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACvD,OAAO;QACN,OAAO,EAAE,oBAAoB;QAC7B,IAAI,EAAE,UAAU;QAChB,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACjE,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;KACnD,CAAC;AACH,CAAC","sourcesContent":["import type { AssistantMessage } from \"@di-code/ai\";\nimport { validateWebManifest } from \"@di-code/plugin-runtime\";\nimport type { AgentSessionEvent } from \"../core/session.ts\";\n\nexport const RPC_PROTOCOL_VERSION = 1 as const;\nexport const RPC_MAX_ID_LENGTH = 128;\nexport const RPC_MAX_PROMPT_LENGTH = 1_000_000;\nexport const RPC_MAX_ATTACHMENTS_PER_REQUEST = 4;\nexport const RPC_MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;\n/** Allows one JSONL user entry containing a maximum-sized base64 image to be read in a single transcript page. */\nexport const RPC_MAX_TRANSCRIPT_BYTES = 8 * 1024 * 1024;\nconst RPC_MAX_ATTACHMENT_BASE64_LENGTH = Math.ceil(RPC_MAX_ATTACHMENT_BYTES / 3) * 4;\n\n/** v1 grows only by methods and optional fields. Clients must negotiate extended events first. */\nexport const RPC_METHODS = [\n\t\"prompt\",\n\t\"cancel\",\n\t\"get_state\",\n\t\"get_capabilities\",\n\t\"resume_events\",\n\t\"list_sessions\",\n\t\"new_session\",\n\t\"open_session\",\n\t\"inspect_session\",\n\t\"rename_session\",\n\t\"delete_session\",\n\t\"branch_session\",\n\t\"get_transcript\",\n\t\"get_tree\",\n\t\"navigate_tree\",\n\t\"steer\",\n\t\"retry\",\n\t\"get_operation\",\n\t\"get_models\",\n\t\"set_model\",\n\t\"get_runtime\",\n\t\"set_runtime\",\n\t\"set_thinking_level\",\n\t\"compact\",\n\t\"set_compaction_enabled\",\n\t\"get_usage\",\n\t\"list_skills\",\n\t\"get_resources\",\n\t\"get_product_state\",\n\t\"list_providers\",\n\t\"get_settings\",\n\t\"set_default_provider\",\n\t\"set_default_model\",\n\t\"set_locale\",\n\t\"set_permission_mode\",\n\t\"configure_custom_provider\",\n\t\"login\",\n\t\"logout\",\n\t\"get_project_trust\",\n\t\"set_project_trust\",\n\t\"list_context_files\",\n\t\"list_mcp_servers\",\n\t\"configure_mcp_server\",\n\t\"remove_mcp_server\",\n\t\"reconnect_mcp_server\",\n\t\"list_plugins\",\n\t\"list_web_contributions\",\n\t\"list_commands\",\n\t\"run_command\",\n\t\"set_plugin_enabled\",\n\t\"create_attachment\",\n\t\"approve_tool\",\n] as const;\nexport type RpcMethod = (typeof RPC_METHODS)[number];\n\nexport interface RpcRequest {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"request\";\n\treadonly id: string;\n\treadonly method: RpcMethod;\n\treadonly params: Record<string, unknown>;\n}\n\nexport interface RpcSessionState {\n\treadonly sessionId: string;\n\treadonly modelId: string;\n\treadonly isStreaming: boolean;\n\treadonly messageCount: number;\n\treadonly sequence?: number;\n}\n\n/** Metadata for an opaque attachment handle kept only by its live RPC actor. */\nexport interface RpcAttachmentInfo {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly contentType: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\";\n\treadonly bytes: number;\n}\n\nexport interface RpcCapabilities {\n\treadonly methods: readonly RpcMethod[];\n\treadonly events: readonly RpcExtendedEventName[];\n\treadonly eventBufferSize: number;\n}\n\nexport type RpcExtendedEventName =\n\t| \"sequence\"\n\t| \"operation_update\"\n\t| \"snapshot_required\"\n\t| \"session_changed\"\n\t| \"tool_approval\"\n\t| \"product_audit\";\n\nexport interface RpcProductState {\n\treadonly projectTrusted: boolean;\n}\n\nexport interface RpcProviderSummary {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly models: readonly {\n\t\treadonly id: string;\n\t\treadonly name: string;\n\t\treadonly input: readonly string[];\n\t\t/** Omitted when the model does not expose selectable reasoning levels. */\n\t\treadonly reasoningEfforts?: readonly (\"low\" | \"medium\" | \"high\" | \"max\")[];\n\t}[];\n\treadonly configured: boolean;\n}\n\nexport interface RpcSettingsSnapshot {\n\treadonly providers: readonly (RpcProviderSummary & {\n\t\treadonly api: string;\n\t\treadonly baseUrl?: string;\n\t\treadonly apiKeySource: \"environment\" | \"settings\" | \"missing\";\n\t})[];\n\treadonly defaults: { readonly providerId?: string; readonly modelId?: string };\n\treadonly runtime: { readonly providerId: string; readonly modelId: string; readonly thinkingLevel?: string };\n\treadonly locale?: \"en\" | \"zh-CN\";\n\treadonly permissionMode: \"ask\" | \"allow\" | \"deny\";\n\treadonly sources: Readonly<Record<string, \"environment\" | \"settings\" | \"default\" | \"runtime\">>;\n}\n\nexport interface RpcContextFileInfo {\n\treadonly path: string;\n\treadonly scope: string;\n\treadonly bytes: number;\n}\n\n/** A user-invocable command projected from the active composition or Skill catalog. */\nexport interface RpcCommandInfo {\n\treadonly name: string;\n\treadonly description: string;\n\treadonly kind: \"command\" | \"skill\";\n}\n\n/** A WebUI operation requested by a registered command. */\nexport interface RpcCommandAction {\n\treadonly command: string;\n\treadonly args: string;\n}\n\nexport interface RpcMcpServerInfo {\n\treadonly id: string;\n\treadonly scope?: string;\n\treadonly state: \"configured\" | \"connected\" | \"failed\" | \"disconnected\";\n\treadonly tools: number;\n\treadonly resources: number;\n\treadonly prompts: number;\n\treadonly diagnostic?: string;\n}\n\nexport type OperationStatus = \"queued\" | \"running\" | \"completed\" | \"failed\" | \"cancelled\" | \"crashed\";\nexport interface OperationState {\n\treadonly requestId: string;\n\treadonly kind: RpcMethod;\n\treadonly status: OperationStatus;\n\treadonly sessionId?: string;\n\treadonly message?: AssistantMessage;\n\treadonly error?: { readonly code: RpcErrorCode; readonly message: string };\n}\n\n/** Method-specific result fields are validated at the wire boundary. */\nexport type RpcSuccessResult = { readonly method: RpcMethod; readonly [key: string]: unknown };\n\nexport type RpcErrorCode =\n\t| \"PARSE_ERROR\"\n\t| \"INVALID_REQUEST\"\n\t| \"UNSUPPORTED_VERSION\"\n\t| \"METHOD_NOT_FOUND\"\n\t| \"INVALID_PARAMS\"\n\t| \"BUSY\"\n\t| \"NOT_FOUND\"\n\t| \"CANCELLED\"\n\t| \"DISPOSED\"\n\t| \"SESSION_IN_USE\"\n\t| \"INVALID_WORKSPACE\"\n\t| \"UNAUTHORIZED\"\n\t| \"INTERNAL_ERROR\"\n\t| \"PROCESS_EXIT\";\n\nconst RPC_ERROR_CODES: ReadonlySet<RpcErrorCode> = new Set([\n\t\"PARSE_ERROR\",\n\t\"INVALID_REQUEST\",\n\t\"UNSUPPORTED_VERSION\",\n\t\"METHOD_NOT_FOUND\",\n\t\"INVALID_PARAMS\",\n\t\"BUSY\",\n\t\"NOT_FOUND\",\n\t\"CANCELLED\",\n\t\"DISPOSED\",\n\t\"SESSION_IN_USE\",\n\t\"INVALID_WORKSPACE\",\n\t\"UNAUTHORIZED\",\n\t\"INTERNAL_ERROR\",\n\t\"PROCESS_EXIT\",\n]);\nconst LEGACY_EVENT_TYPES: ReadonlySet<AgentSessionEvent[\"type\"]> = new Set([\n\t\"agent_start\",\n\t\"turn_start\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"turn_end\",\n\t\"tool_execution_start\",\n\t\"tool_execution_end\",\n\t\"agent_end\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"queue_update\",\n\t\"tree_navigated\",\n\t\"usage_update\",\n]);\nconst EXTENDED_EVENT_TYPES = new Set([\n\t\"snapshot_required\",\n\t\"operation_update\",\n\t\"session_changed\",\n\t\"tool_approval\",\n\t\"product_audit\",\n]);\nconst EXTENDED_EVENT_NAMES: ReadonlySet<RpcExtendedEventName> = new Set([\n\t\"sequence\",\n\t\"operation_update\",\n\t\"snapshot_required\",\n\t\"session_changed\",\n\t\"tool_approval\",\n\t\"product_audit\",\n]);\nconst ASSISTANT_STOP_REASONS = new Set([\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\"]);\n\nexport interface RpcSuccessResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id: string;\n\treadonly ok: true;\n\treadonly result: RpcSuccessResult;\n}\nexport interface RpcErrorResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id?: string;\n\treadonly ok: false;\n\treadonly error: { readonly code: RpcErrorCode; readonly message: string };\n}\nexport interface RpcEventRecord {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"event\";\n\treadonly requestId: string;\n\treadonly event:\n\t\t| AgentSessionEvent\n\t\t| {\n\t\t\t\treadonly type: \"product_audit\";\n\t\t\t\treadonly action:\n\t\t\t\t\t| \"login\"\n\t\t\t\t\t| \"logout\"\n\t\t\t\t\t| \"set_project_trust\"\n\t\t\t\t\t| \"configure_mcp_server\"\n\t\t\t\t\t| \"remove_mcp_server\"\n\t\t\t\t\t| \"reconnect_mcp_server\";\n\t\t\t\treadonly target?: string;\n\t\t\t\treadonly projectTrusted?: boolean;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: \"snapshot_required\" | \"operation_update\" | \"session_changed\" | \"tool_approval\";\n\t\t\t\treadonly [key: string]: unknown;\n\t\t };\n\treadonly sessionId?: string;\n\treadonly sequence?: number;\n}\nexport type RpcResponse = RpcSuccessResponse | RpcErrorResponse;\nexport type RpcServerMessage = RpcResponse | RpcEventRecord;\n\nexport class RpcProtocolError extends Error {\n\treadonly code: RpcErrorCode;\n\treadonly requestId?: string;\n\n\tconstructor(code: RpcErrorCode, message: string, requestId?: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RpcProtocolError\";\n\t\tthis.code = code;\n\t\tthis.requestId = requestId;\n\t}\n}\n\nfunction objectRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\nfunction requiredId(value: unknown, field: string, requestId?: string): string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_ID_LENGTH)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_REQUEST\",\n\t\t\t`${field} must be a non-empty string of at most ${RPC_MAX_ID_LENGTH} characters.`,\n\t\t\trequestId,\n\t\t);\n\treturn value;\n}\nfunction parseJsonObject(line: string): Record<string, unknown> {\n\ttry {\n\t\tconst result = objectRecord(JSON.parse(line));\n\t\tif (!result) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC input must be a JSON object.\");\n\t\treturn result;\n\t} catch (cause) {\n\t\tif (cause instanceof RpcProtocolError) throw cause;\n\t\tthrow new RpcProtocolError(\"PARSE_ERROR\", \"RPC input must be valid JSON.\");\n\t}\n}\nfunction assertVersion(record: Record<string, unknown>, requestId?: string): void {\n\tif (record.version !== RPC_PROTOCOL_VERSION)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"UNSUPPORTED_VERSION\",\n\t\t\t`Unsupported RPC protocol version; expected ${RPC_PROTOCOL_VERSION}.`,\n\t\t\trequestId,\n\t\t);\n}\nfunction stringParam(params: Record<string, unknown>, name: string, id: string, optional = false): void {\n\tconst value = params[name];\n\tif (optional && value === undefined) return;\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_PROMPT_LENGTH)\n\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", `${name} must be a non-empty string.`, id);\n}\nfunction booleanParam(params: Record<string, unknown>, name: string, id: string): void {\n\tif (typeof params[name] !== \"boolean\") throw new RpcProtocolError(\"INVALID_PARAMS\", `${name} must be a boolean.`, id);\n}\nfunction attachmentIdsParam(params: Record<string, unknown>, id: string): void {\n\tif (params.attachmentIds === undefined) return;\n\tif (\n\t\t!Array.isArray(params.attachmentIds) ||\n\t\tparams.attachmentIds.length > RPC_MAX_ATTACHMENTS_PER_REQUEST ||\n\t\t!params.attachmentIds.every(\n\t\t\t(value) => typeof value === \"string\" && value.length > 0 && value.length <= RPC_MAX_ID_LENGTH,\n\t\t)\n\t)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_PARAMS\",\n\t\t\t`attachmentIds must contain at most ${RPC_MAX_ATTACHMENTS_PER_REQUEST} attachment IDs.`,\n\t\t\tid,\n\t\t);\n}\nfunction attachmentDataParam(params: Record<string, unknown>, id: string): void {\n\tconst data = params.data;\n\tif (typeof data !== \"string\" || data.length === 0 || data.length > RPC_MAX_ATTACHMENT_BASE64_LENGTH)\n\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Attachment data exceeds the permitted size.\", id);\n}\n\n/** Parses every public v1 method before any dispatcher or transport observes it. */\nexport function parseRpcRequest(line: string): RpcRequest {\n\tconst record = parseJsonObject(line);\n\tconst candidateId = typeof record.id === \"string\" ? record.id : undefined;\n\tassertVersion(record, candidateId);\n\tif (record.kind !== \"request\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC request kind must be \"request\".', candidateId);\n\tconst id = requiredId(record.id, \"id\", candidateId);\n\tconst params = objectRecord(record.params);\n\tif (!params) throw new RpcProtocolError(\"INVALID_PARAMS\", \"RPC params must be an object.\", id);\n\tif (typeof record.method !== \"string\" || !RPC_METHODS.includes(record.method as RpcMethod))\n\t\tthrow new RpcProtocolError(\"METHOD_NOT_FOUND\", \"Unknown RPC method.\", id);\n\tconst method = record.method as RpcMethod;\n\tswitch (method) {\n\t\tcase \"prompt\":\n\t\tcase \"steer\":\n\t\t\tstringParam(params, \"message\", id);\n\t\t\tattachmentIdsParam(params, id);\n\t\t\tbreak;\n\t\tcase \"cancel\":\n\t\tcase \"get_operation\":\n\t\tcase \"open_session\":\n\t\tcase \"inspect_session\":\n\t\tcase \"rename_session\":\n\t\tcase \"delete_session\":\n\t\tcase \"navigate_tree\":\n\t\tcase \"set_model\":\n\t\tcase \"logout\":\n\t\tcase \"reconnect_mcp_server\":\n\t\t\tstringParam(\n\t\t\t\tparams,\n\t\t\t\tmethod === \"cancel\" || method === \"get_operation\"\n\t\t\t\t\t? \"requestId\"\n\t\t\t\t\t: method === \"open_session\"\n\t\t\t\t\t\t? \"sessionId\"\n\t\t\t\t\t\t: method === \"inspect_session\" || method === \"rename_session\" || method === \"delete_session\"\n\t\t\t\t\t\t\t? \"sessionId\"\n\t\t\t\t\t\t\t: method === \"navigate_tree\"\n\t\t\t\t\t\t\t\t? \"entryId\"\n\t\t\t\t\t\t\t\t: method === \"set_model\"\n\t\t\t\t\t\t\t\t\t? \"modelId\"\n\t\t\t\t\t\t\t\t\t: method === \"logout\"\n\t\t\t\t\t\t\t\t\t\t? \"providerId\"\n\t\t\t\t\t\t\t\t\t\t: \"serverId\",\n\t\t\t\tid,\n\t\t\t);\n\t\t\tif (method === \"rename_session\") stringParam(params, \"label\", id);\n\t\t\tif (method === \"delete_session\") stringParam(params, \"confirmation\", id);\n\t\t\tbreak;\n\t\tcase \"branch_session\":\n\t\t\tif (params.sessionId !== undefined) stringParam(params, \"sessionId\", id, true);\n\t\t\tif (params.entryId !== undefined) stringParam(params, \"entryId\", id, true);\n\t\t\tbreak;\n\t\tcase \"set_runtime\":\n\t\t\tstringParam(params, \"providerId\", id);\n\t\t\tstringParam(params, \"modelId\", id);\n\t\t\tbreak;\n\t\tcase \"run_command\":\n\t\t\tstringParam(params, \"name\", id);\n\t\t\tif (!/^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)?$/.test(params.name as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"run_command.name is invalid.\", id);\n\t\t\tif (params.args !== undefined && (typeof params.args !== \"string\" || params.args.length > RPC_MAX_PROMPT_LENGTH))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"args must be a string of at most 1,000,000 characters.\", id);\n\t\t\tbreak;\n\t\tcase \"set_default_provider\":\n\t\tcase \"set_default_model\":\n\t\tcase \"set_locale\":\n\t\tcase \"set_permission_mode\":\n\t\t\tstringParam(\n\t\t\t\tparams,\n\t\t\t\tmethod === \"set_default_provider\"\n\t\t\t\t\t? \"providerId\"\n\t\t\t\t\t: method === \"set_default_model\"\n\t\t\t\t\t\t? \"modelId\"\n\t\t\t\t\t\t: method === \"set_locale\"\n\t\t\t\t\t\t\t? \"locale\"\n\t\t\t\t\t\t\t: \"permissionMode\",\n\t\t\t\tid,\n\t\t\t);\n\t\t\tif (method === \"set_locale\" && params.locale !== \"en\" && params.locale !== \"zh-CN\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"locale must be en or zh-CN.\", id);\n\t\t\tif (\n\t\t\t\tmethod === \"set_permission_mode\" &&\n\t\t\t\tparams.permissionMode !== \"ask\" &&\n\t\t\t\tparams.permissionMode !== \"allow\" &&\n\t\t\t\tparams.permissionMode !== \"deny\"\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"permissionMode must be ask, allow, or deny.\", id);\n\t\t\tbreak;\n\t\tcase \"configure_custom_provider\":\n\t\t\tfor (const name of [\"api\", \"baseUrl\", \"apiKey\", \"modelId\"]) stringParam(params, name, id);\n\t\t\tif (![\"openai-responses\", \"openai-chat-completions\", \"anthropic-messages\"].includes(params.api as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Unsupported custom Provider API.\", id);\n\t\t\tbreak;\n\t\tcase \"set_thinking_level\":\n\t\t\tif (\n\t\t\t\tparams.level !== undefined &&\n\t\t\t\tparams.level !== \"low\" &&\n\t\t\t\tparams.level !== \"medium\" &&\n\t\t\t\tparams.level !== \"high\" &&\n\t\t\t\tparams.level !== \"max\"\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"set_thinking_level.level must be a valid thinking level.\", id);\n\t\t\tbreak;\n\t\tcase \"retry\":\n\t\t\tstringParam(params, \"targetRequestId\", id);\n\t\t\tbreak;\n\t\tcase \"login\":\n\t\t\tstringParam(params, \"providerId\", id);\n\t\t\tstringParam(params, \"apiKey\", id);\n\t\t\tif (params.modelId !== undefined) stringParam(params, \"modelId\", id, true);\n\t\t\tif (params.api !== undefined) stringParam(params, \"api\", id, true);\n\t\t\tbreak;\n\t\tcase \"configure_mcp_server\":\n\t\t\tstringParam(params, \"serverId\", id);\n\t\t\tstringParam(params, \"scope\", id);\n\t\t\tif (!objectRecord(params.config)) throw new RpcProtocolError(\"INVALID_PARAMS\", \"config must be an object.\", id);\n\t\t\tbreak;\n\t\tcase \"remove_mcp_server\":\n\t\t\tstringParam(params, \"serverId\", id);\n\t\t\tif (params.scope !== undefined) stringParam(params, \"scope\", id, true);\n\t\t\tbreak;\n\t\tcase \"set_plugin_enabled\":\n\t\t\tstringParam(params, \"pluginId\", id);\n\t\t\tbooleanParam(params, \"enabled\", id);\n\t\t\tbreak;\n\t\tcase \"set_compaction_enabled\":\n\t\tcase \"set_project_trust\":\n\t\t\tbooleanParam(params, method === \"set_compaction_enabled\" ? \"enabled\" : \"trusted\", id);\n\t\t\tbreak;\n\t\tcase \"get_capabilities\":\n\t\t\tif (\n\t\t\t\tparams.events !== undefined &&\n\t\t\t\t(!Array.isArray(params.events) || !params.events.every((item) => typeof item === \"string\"))\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"get_capabilities.events must be a string array.\", id);\n\t\t\tbreak;\n\t\tcase \"resume_events\":\n\t\t\tif (\n\t\t\t\tparams.lastSequence !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.lastSequence) || (params.lastSequence as number) < 0)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"resume_events.lastSequence must be a non-negative integer.\", id);\n\t\t\tbreak;\n\t\tcase \"create_attachment\":\n\t\t\tstringParam(params, \"name\", id);\n\t\t\tstringParam(params, \"contentType\", id);\n\t\t\tattachmentDataParam(params, id);\n\t\t\tif (![\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"].includes(params.contentType as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Attachment contentType is unsupported.\", id);\n\t\t\tbreak;\n\t\tcase \"get_transcript\":\n\t\t\tif (params.pageToken !== undefined) stringParam(params, \"pageToken\", id, true);\n\t\t\tif (\n\t\t\t\tparams.pageSize !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.pageSize) || (params.pageSize as number) < 1 || (params.pageSize as number) > 200)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"pageSize must be an integer between 1 and 200.\", id);\n\t\t\tif (\n\t\t\t\tparams.maxBytes !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.maxBytes) ||\n\t\t\t\t\t(params.maxBytes as number) < 1024 ||\n\t\t\t\t\t(params.maxBytes as number) > RPC_MAX_TRANSCRIPT_BYTES)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\n\t\t\t\t\t\"INVALID_PARAMS\",\n\t\t\t\t\t`maxBytes must be between 1024 and ${RPC_MAX_TRANSCRIPT_BYTES}.`,\n\t\t\t\t\tid,\n\t\t\t\t);\n\t\t\tbreak;\n\t\tcase \"approve_tool\":\n\t\t\tstringParam(params, \"approvalId\", id);\n\t\t\tbooleanParam(params, \"approved\", id);\n\t\t\tbreak;\n\t}\n\treturn { version: RPC_PROTOCOL_VERSION, kind: \"request\", id, method, params };\n}\n\nexport function parseRpcServerMessage(line: string): RpcServerMessage {\n\tconst record = parseJsonObject(line);\n\tassertVersion(record);\n\tif (record.kind === \"event\") {\n\t\trequiredId(record.requestId, \"requestId\");\n\t\tconst event = objectRecord(record.event);\n\t\tconst type = event?.type;\n\t\tif (\n\t\t\ttypeof type !== \"string\" ||\n\t\t\t(!LEGACY_EVENT_TYPES.has(type as AgentSessionEvent[\"type\"]) && !EXTENDED_EVENT_TYPES.has(type))\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\tif (!event) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\tif (record.sequence !== undefined && (!Number.isSafeInteger(record.sequence) || (record.sequence as number) < 0))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event sequence is invalid.\");\n\t\tassertEvent(event, type);\n\t\treturn record as unknown as RpcEventRecord;\n\t}\n\tif (record.kind !== \"response\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC server message kind must be \"response\" or \"event\".');\n\tif (record.ok === false) {\n\t\tconst error = objectRecord(record.error);\n\t\tif (\n\t\t\t!error ||\n\t\t\ttypeof error.code !== \"string\" ||\n\t\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\t\ttypeof error.message !== \"string\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error response has an invalid error object.\");\n\t\tif (record.id !== undefined) requiredId(record.id, \"id\");\n\t\treturn record as unknown as RpcErrorResponse;\n\t}\n\tif (record.ok !== true) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC response ok must be a boolean.\");\n\trequiredId(record.id, \"id\");\n\tconst result = objectRecord(record.result);\n\tif (!result || typeof result.method !== \"string\" || !RPC_METHODS.includes(result.method as RpcMethod))\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC success response has an unknown method.\");\n\tassertSuccessResult(result);\n\treturn record as unknown as RpcSuccessResponse;\n}\nfunction assertSuccessResult(result: Record<string, unknown>): void {\n\tswitch (result.method as RpcMethod) {\n\t\tcase \"prompt\":\n\t\tcase \"retry\":\n\t\t\tassertAssistantMessage(result.message);\n\t\t\treturn;\n\t\tcase \"cancel\":\n\t\t\tif (typeof result.cancelled !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC cancel result is invalid.\");\n\t\t\treturn;\n\t\tcase \"get_state\":\n\t\t\tassertState(result.state);\n\t\t\treturn;\n\t\tcase \"get_capabilities\":\n\t\t\tassertCapabilities(result);\n\t\t\treturn;\n\t\tcase \"resume_events\":\n\t\t\tif (typeof result.snapshotRequired !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC resume_events result is invalid.\");\n\t\t\treturn;\n\t\tcase \"get_operation\":\n\t\t\tassertOperationState(result.operation);\n\t\t\treturn;\n\t\tcase \"create_attachment\":\n\t\t\tassertAttachmentInfo(result.attachment);\n\t\t\treturn;\n\t\tcase \"get_product_state\":\n\t\t\tassertProductState(result.state);\n\t\t\treturn;\n\t\tcase \"get_project_trust\":\n\t\t\tif (typeof result.trusted !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_project_trust result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_sessions\":\n\t\t\tif (!Array.isArray(result.sessions))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC list_sessions result is invalid.\");\n\t\t\tfor (const session of result.sessions) assertSessionInfo(session);\n\t\t\treturn;\n\t\tcase \"new_session\":\n\t\tcase \"open_session\":\n\t\tcase \"rename_session\":\n\t\tcase \"branch_session\":\n\t\t\tassertSessionInfo(result.session);\n\t\t\treturn;\n\t\tcase \"inspect_session\":\n\t\t\tif (!objectRecord(result.snapshot))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session snapshot is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_providers\":\n\t\t\tif (!Array.isArray(result.providers))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC providers result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_context_files\":\n\t\t\tif (!Array.isArray(result.files))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC context files result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_mcp_servers\":\n\t\t\tif (!Array.isArray(result.servers)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC MCP result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_web_contributions\":\n\t\t\t{\n\t\t\t\tconst manifest = objectRecord(result.manifest);\n\t\t\t\tif (!manifest || !validateWebManifest(manifest))\n\t\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Web contribution manifest is invalid.\");\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"list_commands\":\n\t\t\tif (!Array.isArray(result.commands))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC commands result is invalid.\");\n\t\t\tfor (const command of result.commands) assertCommandInfo(command);\n\t\t\treturn;\n\t\tcase \"run_command\":\n\t\t\tif (typeof result.command !== \"string\" || !result.command)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command result is invalid.\");\n\t\t\tif (result.action !== undefined) assertCommandAction(result.action);\n\t\t\treturn;\n\t\tcase \"configure_mcp_server\":\n\t\tcase \"reconnect_mcp_server\":\n\t\t\tif (!objectRecord(result.server)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC MCP result is invalid.\");\n\t\t\treturn;\n\t\tcase \"login\":\n\t\t\tif (!objectRecord(result.provider)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC login result is invalid.\");\n\t\t\treturn;\n\t\tcase \"set_project_trust\":\n\t\t\tif (typeof result.trusted !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC trust result is invalid.\");\n\t\t\treturn;\n\t\tcase \"logout\":\n\t\tcase \"remove_mcp_server\":\n\t\t\treturn;\n\t\tcase \"get_settings\":\n\t\t\tif (!objectRecord(result.settings))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC settings result is invalid.\");\n\t\t\treturn;\n\t\tcase \"set_default_provider\":\n\t\tcase \"set_default_model\":\n\t\tcase \"set_locale\":\n\t\tcase \"set_permission_mode\":\n\t\tcase \"configure_custom_provider\":\n\t\t\treturn;\n\t}\n}\nfunction assertCapabilities(result: Record<string, unknown>): void {\n\tif (\n\t\t!Array.isArray(result.methods) ||\n\t\t!result.methods.every((method) => typeof method === \"string\" && RPC_METHODS.includes(method as RpcMethod)) ||\n\t\t!Array.isArray(result.events) ||\n\t\t!result.events.every(\n\t\t\t(event) => typeof event === \"string\" && EXTENDED_EVENT_NAMES.has(event as RpcExtendedEventName),\n\t\t) ||\n\t\t!Number.isSafeInteger(result.eventBufferSize) ||\n\t\t(result.eventBufferSize as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_capabilities result is invalid.\");\n}\nfunction assertSessionInfo(value: unknown): void {\n\tconst session = objectRecord(value);\n\tif (!session || typeof session.id !== \"string\" || !session.id || typeof session.label !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session result is invalid.\");\n\tif (session.modifiedAt !== undefined && !Number.isFinite(session.modifiedAt))\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session modifiedAt is invalid.\");\n}\nfunction assertCommandInfo(value: unknown): void {\n\tconst command = objectRecord(value);\n\tif (\n\t\t!command ||\n\t\ttypeof command.name !== \"string\" ||\n\t\t!command.name ||\n\t\ttypeof command.description !== \"string\" ||\n\t\t(command.kind !== \"command\" && command.kind !== \"skill\")\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command info is invalid.\");\n}\nfunction assertCommandAction(value: unknown): void {\n\tconst action = objectRecord(value);\n\tif (!action || typeof action.command !== \"string\" || !action.command || typeof action.args !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command action is invalid.\");\n}\nfunction assertOperationState(value: unknown): void {\n\tconst operation = objectRecord(value);\n\tif (\n\t\t!operation ||\n\t\ttypeof operation.requestId !== \"string\" ||\n\t\t!operation.requestId ||\n\t\ttypeof operation.kind !== \"string\" ||\n\t\t!RPC_METHODS.includes(operation.kind as RpcMethod) ||\n\t\ttypeof operation.status !== \"string\" ||\n\t\t![\"queued\", \"running\", \"completed\", \"failed\", \"cancelled\", \"crashed\"].includes(operation.status)\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC operation state is invalid.\");\n\tif (operation.sessionId !== undefined && typeof operation.sessionId !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC operation session ID is invalid.\");\n\tif (operation.message !== undefined) assertAssistantMessage(operation.message);\n\tif (operation.error !== undefined) assertError(operation.error);\n}\nfunction assertAttachmentInfo(value: unknown): void {\n\tconst attachment = objectRecord(value);\n\tif (\n\t\t!attachment ||\n\t\ttypeof attachment.id !== \"string\" ||\n\t\t!attachment.id ||\n\t\ttypeof attachment.name !== \"string\" ||\n\t\t!attachment.name ||\n\t\ttypeof attachment.contentType !== \"string\" ||\n\t\t![\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"].includes(attachment.contentType) ||\n\t\t!Number.isSafeInteger(attachment.bytes) ||\n\t\t(attachment.bytes as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC attachment result is invalid.\");\n}\nfunction assertProductState(value: unknown): void {\n\tconst state = objectRecord(value);\n\tif (!state || typeof state.projectTrusted !== \"boolean\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC product state is invalid.\");\n}\nfunction assertError(value: unknown): void {\n\tconst error = objectRecord(value);\n\tif (\n\t\t!error ||\n\t\ttypeof error.code !== \"string\" ||\n\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\ttypeof error.message !== \"string\"\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error result is invalid.\");\n}\nfunction assertEvent(event: Record<string, unknown>, type: string): void {\n\tif (type === \"operation_update\") {\n\t\tassertOperationState(event.operation);\n\t\treturn;\n\t}\n\tif (type === \"session_changed\") {\n\t\tif (event.session !== undefined) assertSessionInfo(event.session);\n\t\treturn;\n\t}\n\tif (type === \"snapshot_required\") return;\n\tif (type === \"tool_approval\") {\n\t\tif (typeof event.approvalId !== \"string\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool_approval event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"product_audit\") {\n\t\tif (\n\t\t\ttypeof event.action !== \"string\" ||\n\t\t\t![\n\t\t\t\t\"login\",\n\t\t\t\t\"logout\",\n\t\t\t\t\"set_project_trust\",\n\t\t\t\t\"configure_mcp_server\",\n\t\t\t\t\"remove_mcp_server\",\n\t\t\t\t\"reconnect_mcp_server\",\n\t\t\t].includes(event.action) ||\n\t\t\t(event.target !== undefined && typeof event.target !== \"string\") ||\n\t\t\t(event.projectTrusted !== undefined && typeof event.projectTrusted !== \"boolean\")\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC product_audit event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tool_execution_start\") {\n\t\tif (typeof event.toolCallId !== \"string\" || typeof event.toolName !== \"string\" || !objectRecord(event.arguments))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tool_execution_end\") {\n\t\tif (typeof event.toolCallId !== \"string\" || typeof event.toolName !== \"string\" || !objectRecord(event.result))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"message_start\" || type === \"message_end\") {\n\t\tif (!objectRecord(event.message)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC message event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"message_update\") {\n\t\tconst update = objectRecord(event.event);\n\t\tif (!update || typeof update.type !== \"string\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC message update event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"turn_end\") {\n\t\tif (!objectRecord(event.message) || !Array.isArray(event.toolResults))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC turn event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"agent_end\") {\n\t\tif (!Array.isArray(event.messages)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC agent event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"compaction_start\") {\n\t\tif (event.reason !== \"threshold\" && event.reason !== \"manual\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC compaction event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"compaction_end\") {\n\t\tif (\n\t\t\t(event.reason !== \"threshold\" && event.reason !== \"manual\") ||\n\t\t\ttypeof event.success !== \"boolean\" ||\n\t\t\t(event.errorMessage !== undefined && typeof event.errorMessage !== \"string\")\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC compaction event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"queue_update\") {\n\t\tif (!Array.isArray(event.steering) || !event.steering.every((item) => typeof item === \"string\"))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC queue event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tree_navigated\") {\n\t\tif (\n\t\t\ttypeof event.oldLeafId !== \"string\" ||\n\t\t\ttypeof event.newLeafId !== \"string\" ||\n\t\t\ttypeof event.selectedEntryId !== \"string\" ||\n\t\t\ttypeof event.restoredEditorText !== \"boolean\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tree event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"usage_update\" && !objectRecord(event.usage)) {\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC usage event is invalid.\");\n\t}\n}\nfunction assertState(value: unknown): void {\n\tconst state = objectRecord(value);\n\tif (\n\t\t!state ||\n\t\ttypeof state.sessionId !== \"string\" ||\n\t\t!state.sessionId ||\n\t\ttypeof state.modelId !== \"string\" ||\n\t\t!state.modelId ||\n\t\ttypeof state.isStreaming !== \"boolean\" ||\n\t\t!Number.isInteger(state.messageCount) ||\n\t\t(state.messageCount as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_state response has an invalid state.\");\n}\nfunction assertAssistantMessage(value: unknown): void {\n\tconst message = objectRecord(value);\n\tif (\n\t\t!message ||\n\t\tmessage.role !== \"assistant\" ||\n\t\t!Array.isArray(message.content) ||\n\t\ttypeof message.provider !== \"string\" ||\n\t\ttypeof message.model !== \"string\" ||\n\t\t!Number.isFinite(message.timestamp) ||\n\t\ttypeof message.stopReason !== \"string\" ||\n\t\t!ASSISTANT_STOP_REASONS.has(message.stopReason)\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC prompt response has an invalid message.\");\n}\nexport function rpcErrorResponse(error: RpcProtocolError): RpcErrorResponse {\n\treturn {\n\t\tversion: RPC_PROTOCOL_VERSION,\n\t\tkind: \"response\",\n\t\t...(error.requestId === undefined ? {} : { id: error.requestId }),\n\t\tok: false,\n\t\terror: { code: error.code, message: error.message },\n\t};\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /** Composition-owned RPC process service used by the thin RPC bootstrap. */
2
+ export interface RpcServerService {
3
+ readonly shutdown: () => Promise<void>;
4
+ readonly finished: () => Promise<void>;
5
+ }
6
+ export declare const rpcServerKey: import("@di-code/plugin-runtime").ServiceKey<RpcServerService>;
7
+ //# sourceMappingURL=server-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-service.d.ts","sourceRoot":"","sources":["../../src/rpc/server-service.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,eAAO,MAAM,YAAY,gEAAmD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { createServiceKey } from "@di-code/plugin-runtime";
2
+ export const rpcServerKey = createServiceKey("rpc-server");
3
+ //# sourceMappingURL=server-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-service.js","sourceRoot":"","sources":["../../src/rpc/server-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQ3D,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAmB,YAAY,CAAC,CAAC","sourcesContent":["import { createServiceKey } from \"@di-code/plugin-runtime\";\n\n/** Composition-owned RPC process service used by the thin RPC bootstrap. */\nexport interface RpcServerService {\n\treadonly shutdown: () => Promise<void>;\n\treadonly finished: () => Promise<void>;\n}\n\nexport const rpcServerKey = createServiceKey<RpcServerService>(\"rpc-server\");\n"]}
@@ -1,41 +1,38 @@
1
1
  import type { Readable, Writable } from "node:stream";
2
- import type { AssistantMessage, Message } from "@di-code/ai";
3
- import type { AgentSessionListener } from "../core/session.ts";
4
- export interface RpcSession {
5
- readonly sessionId: string;
6
- readonly modelId: string;
7
- readonly isStreaming: boolean;
8
- readonly transcript: readonly Message[];
9
- prompt(text: string, signal?: AbortSignal): Promise<AssistantMessage>;
10
- subscribeSession(listener: AgentSessionListener): () => void;
11
- }
12
- export interface RpcServerOptions {
13
- readonly session: RpcSession;
2
+ import { type RpcDispatcherOptions } from "./dispatcher.ts";
3
+ export type { RpcMethodCatalog, RpcSession } from "./dispatcher.ts";
4
+ /** JSONL process adapter. Protocol dispatch belongs to RpcDispatcher and is transport independent. */
5
+ export interface RpcServerOptions extends RpcDispatcherOptions {
14
6
  readonly input: Readable;
15
7
  readonly output: Writable;
16
- readonly onError?: (error: Error) => void;
17
8
  readonly maxLineBytes?: number;
18
9
  }
19
10
  export declare class RpcServer {
20
- private readonly session;
21
11
  private readonly input;
22
12
  private readonly output;
23
13
  private readonly onError;
24
14
  private readonly decoder;
25
- private readonly inFlightIds;
26
- private activePrompt?;
27
- private unsubscribeSession?;
15
+ private readonly dispatcher;
16
+ private readonly requests;
17
+ private readonly finishedPromise;
18
+ private resolveFinished?;
19
+ private unsubscribe?;
20
+ private shutdownPromise?;
28
21
  private started;
22
+ private shuttingDown;
23
+ private writeChain;
29
24
  constructor(options: RpcServerOptions);
25
+ finished(): Promise<void>;
30
26
  start(): void;
31
27
  stop(): void;
28
+ shutdown(): Promise<void>;
29
+ private finishShutdown;
32
30
  private readonly handleData;
33
31
  private readonly handleEnd;
34
32
  private readonly handleInputError;
35
33
  private acceptLine;
36
- private handleRequest;
37
- private handlePrompt;
38
34
  private writeError;
39
35
  private write;
36
+ private flush;
40
37
  }
41
38
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAY/D,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,M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AAI,CAAC;YAYX,cAAc;IAU5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CASzB;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAOxB;IACF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG/B;IACF,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,KAAK;CAKb"}
@@ -1,56 +1,74 @@
1
+ import { RpcDispatcher } from "./dispatcher.js";
1
2
  import { JsonlLineDecoder, serializeJsonLine } from "./jsonl.js";
2
- import { parseRpcRequest, RPC_PROTOCOL_VERSION, RpcProtocolError, rpcErrorResponse, } from "./protocol.js";
3
+ import { parseRpcRequest, RpcProtocolError, rpcErrorResponse } from "./protocol.js";
3
4
  function errorFrom(cause) {
4
5
  return cause instanceof Error ? cause : new Error(String(cause));
5
6
  }
6
7
  export class RpcServer {
7
- session;
8
8
  input;
9
9
  output;
10
10
  onError;
11
11
  decoder;
12
- inFlightIds = new Set();
13
- activePrompt;
14
- unsubscribeSession;
12
+ dispatcher;
13
+ requests = new Set();
14
+ finishedPromise;
15
+ resolveFinished;
16
+ unsubscribe;
17
+ shutdownPromise;
15
18
  started = false;
19
+ shuttingDown = false;
20
+ writeChain = Promise.resolve();
16
21
  constructor(options) {
17
- this.session = options.session;
18
22
  this.input = options.input;
19
23
  this.output = options.output;
20
24
  this.onError = options.onError ?? (() => undefined);
21
- this.decoder = new JsonlLineDecoder((line) => this.acceptLine(line), {
22
- maxLineBytes: options.maxLineBytes,
25
+ this.dispatcher = new RpcDispatcher(options);
26
+ this.decoder = new JsonlLineDecoder((line) => this.acceptLine(line), { maxLineBytes: options.maxLineBytes });
27
+ this.finishedPromise = new Promise((resolve) => {
28
+ this.resolveFinished = resolve;
23
29
  });
24
30
  }
31
+ finished() {
32
+ return this.finishedPromise;
33
+ }
25
34
  start() {
26
35
  if (this.started)
27
36
  throw new Error("RPC server is already started.");
28
37
  this.started = true;
29
- this.unsubscribeSession = this.session.subscribeSession(async (event) => {
30
- const active = this.activePrompt;
31
- if (!active)
32
- return;
33
- await this.write({
34
- version: RPC_PROTOCOL_VERSION,
35
- kind: "event",
36
- requestId: active.requestId,
37
- event,
38
- });
38
+ this.unsubscribe = this.dispatcher.subscribe((message) => {
39
+ if (!this.shuttingDown)
40
+ void this.write(message).catch(this.onError);
39
41
  });
40
42
  this.input.on("data", this.handleData);
41
43
  this.input.once("end", this.handleEnd);
42
44
  this.input.once("error", this.handleInputError);
43
45
  }
44
46
  stop() {
45
- if (!this.started)
46
- return;
47
+ void this.shutdown().catch(this.onError);
48
+ }
49
+ shutdown() {
50
+ if (this.shutdownPromise)
51
+ return this.shutdownPromise;
52
+ this.shuttingDown = true;
47
53
  this.started = false;
48
54
  this.input.off("data", this.handleData);
49
55
  this.input.off("end", this.handleEnd);
50
56
  this.input.off("error", this.handleInputError);
51
- this.unsubscribeSession?.();
52
- this.unsubscribeSession = undefined;
53
- this.activePrompt?.controller.abort();
57
+ this.unsubscribe?.();
58
+ this.unsubscribe = undefined;
59
+ this.shutdownPromise = this.finishShutdown();
60
+ return this.shutdownPromise;
61
+ }
62
+ async finishShutdown() {
63
+ try {
64
+ await this.dispatcher.dispose();
65
+ await Promise.allSettled([...this.requests]);
66
+ await this.flush();
67
+ }
68
+ finally {
69
+ this.resolveFinished?.();
70
+ this.resolveFinished = undefined;
71
+ }
54
72
  }
55
73
  handleData = (chunk) => {
56
74
  try {
@@ -70,117 +88,43 @@ export class RpcServer {
70
88
  catch (cause) {
71
89
  this.onError(errorFrom(cause));
72
90
  }
73
- this.stop();
91
+ void this.shutdown().catch(this.onError);
74
92
  };
75
93
  handleInputError = (cause) => {
76
94
  this.onError(cause);
77
- this.stop();
95
+ void this.shutdown().catch(this.onError);
78
96
  };
79
97
  acceptLine(line) {
98
+ if (this.shuttingDown)
99
+ return;
80
100
  let request;
81
101
  try {
82
102
  request = parseRpcRequest(line);
83
103
  }
84
104
  catch (cause) {
85
- const protocolError = cause instanceof RpcProtocolError
105
+ const error = cause instanceof RpcProtocolError
86
106
  ? cause
87
107
  : new RpcProtocolError("INVALID_REQUEST", "RPC request validation failed.");
88
- void this.write(rpcErrorResponse(protocolError)).catch(this.onError);
89
- return;
90
- }
91
- if (this.inFlightIds.has(request.id)) {
92
- void this.writeError(request.id, "INVALID_REQUEST", "RPC request id is already in flight.");
108
+ void this.write(rpcErrorResponse(error)).catch(this.onError);
93
109
  return;
94
110
  }
95
- this.inFlightIds.add(request.id);
96
- void this.handleRequest(request)
111
+ const work = this.dispatcher
112
+ .dispatch(request)
113
+ .then((response) => this.write(response))
97
114
  .catch((cause) => this.onError(errorFrom(cause)))
98
- .finally(() => this.inFlightIds.delete(request.id));
99
- }
100
- async handleRequest(request) {
101
- switch (request.method) {
102
- case "get_state":
103
- await this.write({
104
- version: RPC_PROTOCOL_VERSION,
105
- kind: "response",
106
- id: request.id,
107
- ok: true,
108
- result: {
109
- method: "get_state",
110
- state: {
111
- sessionId: this.session.sessionId,
112
- modelId: this.session.modelId,
113
- isStreaming: this.session.isStreaming,
114
- messageCount: this.session.transcript.length,
115
- },
116
- },
117
- });
118
- return;
119
- case "cancel": {
120
- const active = this.activePrompt;
121
- const cancelled = active?.requestId === request.params.requestId;
122
- if (cancelled)
123
- active.controller.abort();
124
- await this.write({
125
- version: RPC_PROTOCOL_VERSION,
126
- kind: "response",
127
- id: request.id,
128
- ok: true,
129
- result: { method: "cancel", cancelled },
130
- });
131
- return;
132
- }
133
- case "prompt":
134
- await this.handlePrompt(request);
135
- }
136
- }
137
- async handlePrompt(request) {
138
- if (this.activePrompt || this.session.isStreaming) {
139
- await this.writeError(request.id, "BUSY", "The RPC session is already processing a prompt.");
140
- return;
141
- }
142
- const active = { requestId: request.id, controller: new AbortController() };
143
- this.activePrompt = active;
144
- try {
145
- const message = await this.session.prompt(request.params.message, active.controller.signal);
146
- await this.write({
147
- version: RPC_PROTOCOL_VERSION,
148
- kind: "response",
149
- id: request.id,
150
- ok: true,
151
- result: { method: "prompt", message },
152
- });
153
- }
154
- catch (cause) {
155
- const error = errorFrom(cause);
156
- const aborted = active.controller.signal.aborted || error.name === "AbortError";
157
- await this.writeError(request.id, aborted ? "CANCELLED" : "INTERNAL_ERROR", aborted ? "The RPC prompt was cancelled." : "The RPC prompt failed.");
158
- if (!aborted)
159
- this.onError(error);
160
- }
161
- finally {
162
- if (this.activePrompt === active)
163
- this.activePrompt = undefined;
164
- }
115
+ .finally(() => this.requests.delete(work));
116
+ this.requests.add(work);
165
117
  }
166
118
  writeError(id, code, message) {
167
- return this.write({
168
- version: RPC_PROTOCOL_VERSION,
169
- kind: "response",
170
- ...(id === undefined ? {} : { id }),
171
- ok: false,
172
- error: { code, message },
173
- });
119
+ return this.write({ version: 1, kind: "response", ...(id ? { id } : {}), ok: false, error: { code, message } });
174
120
  }
175
121
  write(message) {
176
- return new Promise((resolve, reject) => {
177
- this.output.write(serializeJsonLine(message), (error) => {
178
- if (error)
179
- reject(error);
180
- else
181
- resolve();
182
- });
183
- });
122
+ const write = this.writeChain.then(() => new Promise((resolve, reject) => this.output.write(serializeJsonLine(message), (error) => (error ? reject(error) : resolve()))));
123
+ this.writeChain = write.catch(() => undefined);
124
+ return write;
125
+ }
126
+ flush() {
127
+ return this.writeChain.then(() => new Promise((resolve, reject) => this.output.write("", (error) => (error ? reject(error) : resolve()))));
184
128
  }
185
129
  }
186
130
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACN,eAAe,EACf,oBAAoB,EAEpB,gBAAgB,EAGhB,gBAAgB,GAChB,MAAM,eAAe,CAAC;AAwBvB,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAA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OAAO,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,wBAAwB,CACpE,CAAC;YACF,IAAI,CAAC,OAAO;gBAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;gBAAS,CAAC;YACV,IAAI,IAAI,CAAC,YAAY,KAAK,MAAM;gBAAE,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QACjE,CAAC;IACF,CAAC;IAEO,UAAU,CAAC,EAAsB,EAAE,IAAkB,EAAE,OAAe;QAC7E,OAAO,IAAI,CAAC,KAAK,CAAC;YACjB,OAAO,EAAE,oBAAoB;YAC7B,IAAI,EAAE,UAAU;YAChB,GAAG,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;YACnC,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;SACxB,CAAC,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,OAAyB;QACtC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvD,IAAI,KAAK;oBAAE,MAAM,CAAC,KAAK,CAAC,CAAC;;oBACpB,OAAO,EAAE,CAAC;YAChB,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { Readable, Writable } from \"node:stream\";\nimport type { AssistantMessage, Message } from \"@di-code/ai\";\nimport type { AgentSessionListener } from \"../core/session.ts\";\nimport { JsonlLineDecoder, serializeJsonLine } from \"./jsonl.ts\";\nimport {\n\tparseRpcRequest,\n\tRPC_PROTOCOL_VERSION,\n\ttype RpcErrorCode,\n\tRpcProtocolError,\n\ttype RpcRequest,\n\ttype RpcServerMessage,\n\trpcErrorResponse,\n} from \"./protocol.ts\";\n\nexport interface RpcSession {\n\treadonly sessionId: string;\n\treadonly modelId: string;\n\treadonly isStreaming: boolean;\n\treadonly transcript: readonly Message[];\n\tprompt(text: string, signal?: AbortSignal): Promise<AssistantMessage>;\n\tsubscribeSession(listener: AgentSessionListener): () => void;\n}\n\nexport interface RpcServerOptions {\n\treadonly session: RpcSession;\n\treadonly input: Readable;\n\treadonly output: Writable;\n\treadonly onError?: (error: Error) => void;\n\treadonly maxLineBytes?: number;\n}\n\ninterface ActivePrompt {\n\treadonly requestId: string;\n\treadonly controller: AbortController;\n}\n\nfunction errorFrom(cause: unknown): Error {\n\treturn cause instanceof Error ? cause : new Error(String(cause));\n}\n\nexport class RpcServer {\n\tprivate readonly session: RpcSession;\n\tprivate readonly input: Readable;\n\tprivate readonly output: Writable;\n\tprivate readonly onError: (error: Error) => void;\n\tprivate readonly decoder: JsonlLineDecoder;\n\tprivate readonly inFlightIds = new Set<string>();\n\tprivate activePrompt?: ActivePrompt;\n\tprivate unsubscribeSession?: () => void;\n\tprivate started = false;\n\n\tconstructor(options: RpcServerOptions) {\n\t\tthis.session = options.session;\n\t\tthis.input = options.input;\n\t\tthis.output = options.output;\n\t\tthis.onError = options.onError ?? (() => undefined);\n\t\tthis.decoder = new JsonlLineDecoder((line) => this.acceptLine(line), {\n\t\t\tmaxLineBytes: options.maxLineBytes,\n\t\t});\n\t}\n\n\tstart(): void {\n\t\tif (this.started) throw new Error(\"RPC server is already started.\");\n\t\tthis.started = true;\n\t\tthis.unsubscribeSession = this.session.subscribeSession(async (event) => {\n\t\t\tconst active = this.activePrompt;\n\t\t\tif (!active) return;\n\t\t\tawait this.write({\n\t\t\t\tversion: RPC_PROTOCOL_VERSION,\n\t\t\t\tkind: \"event\",\n\t\t\t\trequestId: active.requestId,\n\t\t\t\tevent,\n\t\t\t});\n\t\t});\n\t\tthis.input.on(\"data\", this.handleData);\n\t\tthis.input.once(\"end\", this.handleEnd);\n\t\tthis.input.once(\"error\", this.handleInputError);\n\t}\n\n\tstop(): void {\n\t\tif (!this.started) return;\n\t\tthis.started = false;\n\t\tthis.input.off(\"data\", this.handleData);\n\t\tthis.input.off(\"end\", this.handleEnd);\n\t\tthis.input.off(\"error\", this.handleInputError);\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = undefined;\n\t\tthis.activePrompt?.controller.abort();\n\t}\n\n\tprivate readonly handleData = (chunk: string | Buffer): void => {\n\t\ttry {\n\t\t\tthis.decoder.push(chunk);\n\t\t} catch (cause) {\n\t\t\tconst error = errorFrom(cause);\n\t\t\tthis.onError(error);\n\t\t\tvoid this.writeError(undefined, \"INVALID_REQUEST\", error.message);\n\t\t\tthis.stop();\n\t\t}\n\t};\n\n\tprivate readonly handleEnd = (): void => {\n\t\ttry {\n\t\t\tthis.decoder.end();\n\t\t} catch (cause) {\n\t\t\tthis.onError(errorFrom(cause));\n\t\t}\n\t\tthis.stop();\n\t};\n\n\tprivate readonly handleInputError = (cause: Error): void => {\n\t\tthis.onError(cause);\n\t\tthis.stop();\n\t};\n\n\tprivate acceptLine(line: string): void {\n\t\tlet request: RpcRequest;\n\t\ttry {\n\t\t\trequest = parseRpcRequest(line);\n\t\t} catch (cause) {\n\t\t\tconst protocolError =\n\t\t\t\tcause instanceof RpcProtocolError\n\t\t\t\t\t? cause\n\t\t\t\t\t: new RpcProtocolError(\"INVALID_REQUEST\", \"RPC request validation failed.\");\n\t\t\tvoid this.write(rpcErrorResponse(protocolError)).catch(this.onError);\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.inFlightIds.has(request.id)) {\n\t\t\tvoid this.writeError(request.id, \"INVALID_REQUEST\", \"RPC request id is already in flight.\");\n\t\t\treturn;\n\t\t}\n\t\tthis.inFlightIds.add(request.id);\n\t\tvoid this.handleRequest(request)\n\t\t\t.catch((cause) => this.onError(errorFrom(cause)))\n\t\t\t.finally(() => this.inFlightIds.delete(request.id));\n\t}\n\n\tprivate async handleRequest(request: RpcRequest): Promise<void> {\n\t\tswitch (request.method) {\n\t\t\tcase \"get_state\":\n\t\t\t\tawait this.write({\n\t\t\t\t\tversion: RPC_PROTOCOL_VERSION,\n\t\t\t\t\tkind: \"response\",\n\t\t\t\t\tid: request.id,\n\t\t\t\t\tok: true,\n\t\t\t\t\tresult: {\n\t\t\t\t\t\tmethod: \"get_state\",\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\tsessionId: this.session.sessionId,\n\t\t\t\t\t\t\tmodelId: this.session.modelId,\n\t\t\t\t\t\t\tisStreaming: this.session.isStreaming,\n\t\t\t\t\t\t\tmessageCount: this.session.transcript.length,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\tcase \"cancel\": {\n\t\t\t\tconst active = this.activePrompt;\n\t\t\t\tconst cancelled = active?.requestId === request.params.requestId;\n\t\t\t\tif (cancelled) active.controller.abort();\n\t\t\t\tawait this.write({\n\t\t\t\t\tversion: RPC_PROTOCOL_VERSION,\n\t\t\t\t\tkind: \"response\",\n\t\t\t\t\tid: request.id,\n\t\t\t\t\tok: true,\n\t\t\t\t\tresult: { method: \"cancel\", cancelled },\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"prompt\":\n\t\t\t\tawait this.handlePrompt(request);\n\t\t}\n\t}\n\n\tprivate async handlePrompt(request: Extract<RpcRequest, { method: \"prompt\" }>): Promise<void> {\n\t\tif (this.activePrompt || this.session.isStreaming) {\n\t\t\tawait this.writeError(request.id, \"BUSY\", \"The RPC session is already processing a prompt.\");\n\t\t\treturn;\n\t\t}\n\t\tconst active: ActivePrompt = { requestId: request.id, controller: new AbortController() };\n\t\tthis.activePrompt = active;\n\t\ttry {\n\t\t\tconst message = await this.session.prompt(request.params.message, active.controller.signal);\n\t\t\tawait this.write({\n\t\t\t\tversion: RPC_PROTOCOL_VERSION,\n\t\t\t\tkind: \"response\",\n\t\t\t\tid: request.id,\n\t\t\t\tok: true,\n\t\t\t\tresult: { method: \"prompt\", message },\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\tconst error = errorFrom(cause);\n\t\t\tconst aborted = active.controller.signal.aborted || error.name === \"AbortError\";\n\t\t\tawait this.writeError(\n\t\t\t\trequest.id,\n\t\t\t\taborted ? \"CANCELLED\" : \"INTERNAL_ERROR\",\n\t\t\t\taborted ? \"The RPC prompt was cancelled.\" : \"The RPC prompt failed.\",\n\t\t\t);\n\t\t\tif (!aborted) this.onError(error);\n\t\t} finally {\n\t\t\tif (this.activePrompt === active) this.activePrompt = undefined;\n\t\t}\n\t}\n\n\tprivate writeError(id: string | undefined, code: RpcErrorCode, message: string): Promise<void> {\n\t\treturn this.write({\n\t\t\tversion: RPC_PROTOCOL_VERSION,\n\t\t\tkind: \"response\",\n\t\t\t...(id === undefined ? {} : { id }),\n\t\t\tok: false,\n\t\t\terror: { code, message },\n\t\t});\n\t}\n\n\tprivate write(message: RpcServerMessage): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.output.write(serializeJsonLine(message), (error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t});\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAA6B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAyB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAW3G,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,OAAO,SAAS;IACJ,KAAK,CAAW;IAChB,MAAM,CAAW;IACjB,OAAO,CAA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AAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACjC,GAAG,EAAE,CACJ,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAC7F,CACF,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC;IACd,CAAC;IACO,KAAK;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAC1B,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAC7G,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { Readable, Writable } from \"node:stream\";\nimport { RpcDispatcher, type RpcDispatcherOptions } from \"./dispatcher.ts\";\nimport { JsonlLineDecoder, serializeJsonLine } from \"./jsonl.ts\";\nimport { parseRpcRequest, RpcProtocolError, type RpcServerMessage, rpcErrorResponse } from \"./protocol.ts\";\n\nexport type { RpcMethodCatalog, RpcSession } from \"./dispatcher.ts\";\n\n/** JSONL process adapter. Protocol dispatch belongs to RpcDispatcher and is transport independent. */\nexport interface RpcServerOptions extends RpcDispatcherOptions {\n\treadonly input: Readable;\n\treadonly output: Writable;\n\treadonly maxLineBytes?: number;\n}\n\nfunction errorFrom(cause: unknown): Error {\n\treturn cause instanceof Error ? cause : new Error(String(cause));\n}\n\nexport class RpcServer {\n\tprivate readonly input: Readable;\n\tprivate readonly output: Writable;\n\tprivate readonly onError: (error: Error) => void;\n\tprivate readonly decoder: JsonlLineDecoder;\n\tprivate readonly dispatcher: RpcDispatcher;\n\tprivate readonly requests = new Set<Promise<void>>();\n\tprivate readonly finishedPromise: Promise<void>;\n\tprivate resolveFinished?: () => void;\n\tprivate unsubscribe?: () => void;\n\tprivate shutdownPromise?: Promise<void>;\n\tprivate started = false;\n\tprivate shuttingDown = false;\n\tprivate writeChain = Promise.resolve();\n\n\tconstructor(options: RpcServerOptions) {\n\t\tthis.input = options.input;\n\t\tthis.output = options.output;\n\t\tthis.onError = options.onError ?? (() => undefined);\n\t\tthis.dispatcher = new RpcDispatcher(options);\n\t\tthis.decoder = new JsonlLineDecoder((line) => this.acceptLine(line), { maxLineBytes: options.maxLineBytes });\n\t\tthis.finishedPromise = new Promise((resolve) => {\n\t\t\tthis.resolveFinished = resolve;\n\t\t});\n\t}\n\n\tfinished(): Promise<void> {\n\t\treturn this.finishedPromise;\n\t}\n\tstart(): void {\n\t\tif (this.started) throw new Error(\"RPC server is already started.\");\n\t\tthis.started = true;\n\t\tthis.unsubscribe = this.dispatcher.subscribe((message) => {\n\t\t\tif (!this.shuttingDown) void this.write(message).catch(this.onError);\n\t\t});\n\t\tthis.input.on(\"data\", this.handleData);\n\t\tthis.input.once(\"end\", this.handleEnd);\n\t\tthis.input.once(\"error\", this.handleInputError);\n\t}\n\tstop(): void {\n\t\tvoid this.shutdown().catch(this.onError);\n\t}\n\tshutdown(): Promise<void> {\n\t\tif (this.shutdownPromise) return this.shutdownPromise;\n\t\tthis.shuttingDown = true;\n\t\tthis.started = false;\n\t\tthis.input.off(\"data\", this.handleData);\n\t\tthis.input.off(\"end\", this.handleEnd);\n\t\tthis.input.off(\"error\", this.handleInputError);\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t\tthis.shutdownPromise = this.finishShutdown();\n\t\treturn this.shutdownPromise;\n\t}\n\tprivate async finishShutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.dispatcher.dispose();\n\t\t\tawait Promise.allSettled([...this.requests]);\n\t\t\tawait this.flush();\n\t\t} finally {\n\t\t\tthis.resolveFinished?.();\n\t\t\tthis.resolveFinished = undefined;\n\t\t}\n\t}\n\tprivate readonly handleData = (chunk: string | Buffer): void => {\n\t\ttry {\n\t\t\tthis.decoder.push(chunk);\n\t\t} catch (cause) {\n\t\t\tconst error = errorFrom(cause);\n\t\t\tthis.onError(error);\n\t\t\tvoid this.writeError(undefined, \"INVALID_REQUEST\", error.message);\n\t\t\tthis.stop();\n\t\t}\n\t};\n\tprivate readonly handleEnd = (): void => {\n\t\ttry {\n\t\t\tthis.decoder.end();\n\t\t} catch (cause) {\n\t\t\tthis.onError(errorFrom(cause));\n\t\t}\n\t\tvoid this.shutdown().catch(this.onError);\n\t};\n\tprivate readonly handleInputError = (cause: Error): void => {\n\t\tthis.onError(cause);\n\t\tvoid this.shutdown().catch(this.onError);\n\t};\n\tprivate acceptLine(line: string): void {\n\t\tif (this.shuttingDown) return;\n\t\tlet request: import(\"./protocol.ts\").RpcRequest;\n\t\ttry {\n\t\t\trequest = parseRpcRequest(line);\n\t\t} catch (cause) {\n\t\t\tconst error =\n\t\t\t\tcause instanceof RpcProtocolError\n\t\t\t\t\t? cause\n\t\t\t\t\t: new RpcProtocolError(\"INVALID_REQUEST\", \"RPC request validation failed.\");\n\t\t\tvoid this.write(rpcErrorResponse(error)).catch(this.onError);\n\t\t\treturn;\n\t\t}\n\t\tconst work = this.dispatcher\n\t\t\t.dispatch(request)\n\t\t\t.then((response) => this.write(response))\n\t\t\t.catch((cause) => this.onError(errorFrom(cause)))\n\t\t\t.finally(() => this.requests.delete(work));\n\t\tthis.requests.add(work);\n\t}\n\tprivate writeError(id: string | undefined, code: \"INVALID_REQUEST\", message: string): Promise<void> {\n\t\treturn this.write({ version: 1, kind: \"response\", ...(id ? { id } : {}), ok: false, error: { code, message } });\n\t}\n\tprivate write(message: RpcServerMessage): Promise<void> {\n\t\tconst write = this.writeChain.then(\n\t\t\t() =>\n\t\t\t\tnew Promise<void>((resolve, reject) =>\n\t\t\t\t\tthis.output.write(serializeJsonLine(message), (error) => (error ? reject(error) : resolve())),\n\t\t\t\t),\n\t\t);\n\t\tthis.writeChain = write.catch(() => undefined);\n\t\treturn write;\n\t}\n\tprivate flush(): Promise<void> {\n\t\treturn this.writeChain.then(\n\t\t\t() => new Promise((resolve, reject) => this.output.write(\"\", (error) => (error ? reject(error) : resolve()))),\n\t\t);\n\t}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { type PluginDefinition } from "@di-code/plugin-runtime";
2
+ import { RpcClient, type RpcTransport } from "./rpc/client.ts";
3
+ export interface RpcClientSdk {
4
+ readonly create: (transport: RpcTransport) => RpcClient;
5
+ }
6
+ /** Public composition entry for the RPC client SDK; it owns no server or process lifecycle. */
7
+ export declare const apiVersion: 1;
8
+ export declare const name = "rpc-client-sdk";
9
+ export declare const version = "0.1.7";
10
+ export declare const rpcClientSdkKey: import("@di-code/plugin-runtime").ServiceKey<RpcClientSdk>;
11
+ export declare const apply: PluginDefinition["apply"];
12
+ //# sourceMappingURL=rpc-client-sdk-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client-sdk-entry.d.ts","sourceRoot":"","sources":["../src/rpc-client-sdk-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,YAAY,KAAK,SAAS,CAAC;CACxD;AAED,+FAA+F;AAC/F,eAAO,MAAM,UAAU,EAAG,CAAU,CAAC;AACrC,eAAO,MAAM,IAAI,mBAAmB,CAAC;AACrC,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,eAAe,4DAAmD,CAAC;AAChF,eAAO,MAAM,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAE3C,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { createServiceKey } from "@di-code/plugin-runtime";
2
+ import { RpcClient } from "./rpc/client.js";
3
+ /** Public composition entry for the RPC client SDK; it owns no server or process lifecycle. */
4
+ export const apiVersion = 1;
5
+ export const name = "rpc-client-sdk";
6
+ export const version = "0.1.7";
7
+ export const rpcClientSdkKey = createServiceKey("rpc-client-sdk");
8
+ export const apply = (context) => {
9
+ context.set(rpcClientSdkKey, { create: (transport) => new RpcClient(transport) });
10
+ };
11
+ //# sourceMappingURL=rpc-client-sdk-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client-sdk-entry.js","sourceRoot":"","sources":["../src/rpc-client-sdk-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAyB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAqB,MAAM,iBAAiB,CAAC;AAM/D,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAU,CAAC;AACrC,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAC;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAC/B,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAAe,gBAAgB,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,KAAK,GAA8B,CAAC,OAAO,EAAE,EAAE;IAC3D,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,CAAC,SAAuB,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACjG,CAAC,CAAC","sourcesContent":["import { createServiceKey, type PluginDefinition } from \"@di-code/plugin-runtime\";\nimport { RpcClient, type RpcTransport } from \"./rpc/client.ts\";\n\nexport interface RpcClientSdk {\n\treadonly create: (transport: RpcTransport) => RpcClient;\n}\n\n/** Public composition entry for the RPC client SDK; it owns no server or process lifecycle. */\nexport const apiVersion = 1 as const;\nexport const name = \"rpc-client-sdk\";\nexport const version = \"0.1.7\";\nexport const rpcClientSdkKey = createServiceKey<RpcClientSdk>(\"rpc-client-sdk\");\nexport const apply: PluginDefinition[\"apply\"] = (context) => {\n\tcontext.set(rpcClientSdkKey, { create: (transport: RpcTransport) => new RpcClient(transport) });\n};\n"]}