@xrkseek/harness 0.4.8 → 0.4.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 (242) hide show
  1. package/node_modules/@xrkseek/cordis/LICENSE +21 -0
  2. package/node_modules/@xrkseek/cordis/README.md +14 -0
  3. package/node_modules/@xrkseek/cordis/bin.js +16 -0
  4. package/node_modules/@xrkseek/cordis/lib/index.js +1828 -0
  5. package/node_modules/@xrkseek/cordis/lib/types/context.d.ts +101 -0
  6. package/node_modules/@xrkseek/cordis/lib/types/context.d.ts.map +1 -0
  7. package/node_modules/@xrkseek/cordis/lib/types/events.d.ts +240 -0
  8. package/node_modules/@xrkseek/cordis/lib/types/events.d.ts.map +1 -0
  9. package/node_modules/@xrkseek/cordis/lib/types/fiber.d.ts +202 -0
  10. package/node_modules/@xrkseek/cordis/lib/types/fiber.d.ts.map +1 -0
  11. package/node_modules/@xrkseek/cordis/lib/types/index.d.ts +15 -0
  12. package/node_modules/@xrkseek/cordis/lib/types/index.d.ts.map +1 -0
  13. package/node_modules/@xrkseek/cordis/lib/types/logger.d.ts +105 -0
  14. package/node_modules/@xrkseek/cordis/lib/types/logger.d.ts.map +1 -0
  15. package/node_modules/@xrkseek/cordis/lib/types/reflect.d.ts +186 -0
  16. package/node_modules/@xrkseek/cordis/lib/types/reflect.d.ts.map +1 -0
  17. package/node_modules/@xrkseek/cordis/lib/types/registry.d.ts +201 -0
  18. package/node_modules/@xrkseek/cordis/lib/types/registry.d.ts.map +1 -0
  19. package/node_modules/@xrkseek/cordis/lib/types/service.d.ts +55 -0
  20. package/node_modules/@xrkseek/cordis/lib/types/service.d.ts.map +1 -0
  21. package/node_modules/@xrkseek/cordis/lib/types/utils.d.ts +62 -0
  22. package/node_modules/@xrkseek/cordis/lib/types/utils.d.ts.map +1 -0
  23. package/node_modules/@xrkseek/cordis/package.json +49 -0
  24. package/node_modules/@xrkseek/cordis/src/context.d.ts +101 -0
  25. package/node_modules/@xrkseek/cordis/src/context.d.ts.map +1 -0
  26. package/node_modules/@xrkseek/cordis/src/context.js +99 -0
  27. package/node_modules/@xrkseek/cordis/src/context.js.map +1 -0
  28. package/node_modules/@xrkseek/cordis/src/context.ts +146 -0
  29. package/node_modules/@xrkseek/cordis/src/events.d.ts +240 -0
  30. package/node_modules/@xrkseek/cordis/src/events.d.ts.map +1 -0
  31. package/node_modules/@xrkseek/cordis/src/events.js +199 -0
  32. package/node_modules/@xrkseek/cordis/src/events.js.map +1 -0
  33. package/node_modules/@xrkseek/cordis/src/events.ts +352 -0
  34. package/node_modules/@xrkseek/cordis/src/fiber.d.ts +202 -0
  35. package/node_modules/@xrkseek/cordis/src/fiber.d.ts.map +1 -0
  36. package/node_modules/@xrkseek/cordis/src/fiber.js +677 -0
  37. package/node_modules/@xrkseek/cordis/src/fiber.js.map +1 -0
  38. package/node_modules/@xrkseek/cordis/src/fiber.ts +754 -0
  39. package/node_modules/@xrkseek/cordis/src/index.d.ts +15 -0
  40. package/node_modules/@xrkseek/cordis/src/index.d.ts.map +1 -0
  41. package/node_modules/@xrkseek/cordis/src/index.js +15 -0
  42. package/node_modules/@xrkseek/cordis/src/index.js.map +1 -0
  43. package/node_modules/@xrkseek/cordis/src/index.ts +14 -0
  44. package/node_modules/@xrkseek/cordis/src/logger.d.ts +105 -0
  45. package/node_modules/@xrkseek/cordis/src/logger.d.ts.map +1 -0
  46. package/node_modules/@xrkseek/cordis/src/logger.js +193 -0
  47. package/node_modules/@xrkseek/cordis/src/logger.js.map +1 -0
  48. package/node_modules/@xrkseek/cordis/src/logger.ts +270 -0
  49. package/node_modules/@xrkseek/cordis/src/reflect.d.ts +186 -0
  50. package/node_modules/@xrkseek/cordis/src/reflect.d.ts.map +1 -0
  51. package/node_modules/@xrkseek/cordis/src/reflect.js +311 -0
  52. package/node_modules/@xrkseek/cordis/src/reflect.js.map +1 -0
  53. package/node_modules/@xrkseek/cordis/src/reflect.ts +418 -0
  54. package/node_modules/@xrkseek/cordis/src/registry.d.ts +201 -0
  55. package/node_modules/@xrkseek/cordis/src/registry.d.ts.map +1 -0
  56. package/node_modules/@xrkseek/cordis/src/registry.js +218 -0
  57. package/node_modules/@xrkseek/cordis/src/registry.js.map +1 -0
  58. package/node_modules/@xrkseek/cordis/src/registry.ts +337 -0
  59. package/node_modules/@xrkseek/cordis/src/service.d.ts +55 -0
  60. package/node_modules/@xrkseek/cordis/src/service.d.ts.map +1 -0
  61. package/node_modules/@xrkseek/cordis/src/service.js +113 -0
  62. package/node_modules/@xrkseek/cordis/src/service.js.map +1 -0
  63. package/node_modules/@xrkseek/cordis/src/service.ts +115 -0
  64. package/node_modules/@xrkseek/cordis/src/utils.d.ts +62 -0
  65. package/node_modules/@xrkseek/cordis/src/utils.d.ts.map +1 -0
  66. package/node_modules/@xrkseek/cordis/src/utils.js +271 -0
  67. package/node_modules/@xrkseek/cordis/src/utils.js.map +1 -0
  68. package/node_modules/@xrkseek/cordis/src/utils.ts +287 -0
  69. package/node_modules/@xrkseek/core-agent-loop/dist/index.d.ts.map +1 -1
  70. package/node_modules/@xrkseek/core-agent-loop/dist/index.js +39 -68
  71. package/node_modules/@xrkseek/core-agent-loop/dist/index.js.map +1 -1
  72. package/node_modules/@xrkseek/core-session/dist/compaction.d.ts +4 -3
  73. package/node_modules/@xrkseek/core-session/dist/compaction.d.ts.map +1 -1
  74. package/node_modules/@xrkseek/core-session/dist/compaction.js.map +1 -1
  75. package/node_modules/@xrkseek/core-tools/dist/subagent-prompt.d.ts.map +1 -1
  76. package/node_modules/@xrkseek/core-tools/dist/subagent-prompt.js +2 -1
  77. package/node_modules/@xrkseek/core-tools/dist/subagent-prompt.js.map +1 -1
  78. package/node_modules/@xrkseek/exec-image-gen/README.md +1 -1
  79. package/node_modules/@xrkseek/exec-image-gen/dist/catalog.d.ts +16 -0
  80. package/node_modules/@xrkseek/exec-image-gen/dist/catalog.d.ts.map +1 -0
  81. package/node_modules/@xrkseek/exec-image-gen/dist/catalog.js +152 -0
  82. package/node_modules/@xrkseek/exec-image-gen/dist/catalog.js.map +1 -0
  83. package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.d.ts +9 -0
  84. package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.d.ts.map +1 -0
  85. package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.js +21 -0
  86. package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.js.map +1 -0
  87. package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.d.ts +16 -0
  88. package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.d.ts.map +1 -0
  89. package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.js +189 -0
  90. package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.js.map +1 -0
  91. package/node_modules/@xrkseek/exec-image-gen/dist/index.d.ts +10 -5
  92. package/node_modules/@xrkseek/exec-image-gen/dist/index.d.ts.map +1 -1
  93. package/node_modules/@xrkseek/exec-image-gen/dist/index.js +174 -18
  94. package/node_modules/@xrkseek/exec-image-gen/dist/index.js.map +1 -1
  95. package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.d.ts +16 -0
  96. package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.d.ts.map +1 -0
  97. package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.js +144 -0
  98. package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.js.map +1 -0
  99. package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.d.ts +9 -0
  100. package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.d.ts.map +1 -0
  101. package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.js +21 -0
  102. package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.js.map +1 -0
  103. package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.d.ts +4 -1
  104. package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.d.ts.map +1 -1
  105. package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.js +7 -5
  106. package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.js.map +1 -1
  107. package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.d.ts +14 -0
  108. package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.d.ts.map +1 -0
  109. package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.js +117 -0
  110. package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.js.map +1 -0
  111. package/node_modules/@xrkseek/exec-image-gen/dist/tools.d.ts.map +1 -1
  112. package/node_modules/@xrkseek/exec-image-gen/dist/tools.js +43 -6
  113. package/node_modules/@xrkseek/exec-image-gen/dist/tools.js.map +1 -1
  114. package/node_modules/@xrkseek/exec-image-gen/dist/types.d.ts +1 -1
  115. package/node_modules/@xrkseek/exec-image-gen/dist/types.d.ts.map +1 -1
  116. package/node_modules/@xrkseek/exec-image-gen/dist/types.js.map +1 -1
  117. package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.d.ts +16 -0
  118. package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.d.ts.map +1 -0
  119. package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.js +137 -0
  120. package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.js.map +1 -0
  121. package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.d.ts +52 -0
  122. package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.d.ts.map +1 -0
  123. package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.js +216 -0
  124. package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.js.map +1 -0
  125. package/node_modules/@xrkseek/exec-memory/dist/index.d.ts +1 -0
  126. package/node_modules/@xrkseek/exec-memory/dist/index.d.ts.map +1 -1
  127. package/node_modules/@xrkseek/exec-memory/dist/index.js +1 -0
  128. package/node_modules/@xrkseek/exec-memory/dist/index.js.map +1 -1
  129. package/node_modules/@xrkseek/exec-memory/dist/tools.d.ts.map +1 -1
  130. package/node_modules/@xrkseek/exec-memory/dist/tools.js +20 -7
  131. package/node_modules/@xrkseek/exec-memory/dist/tools.js.map +1 -1
  132. package/node_modules/@xrkseek/exec-video-gen/README.md +1 -1
  133. package/node_modules/@xrkseek/exec-video-gen/dist/catalog.d.ts +14 -1
  134. package/node_modules/@xrkseek/exec-video-gen/dist/catalog.d.ts.map +1 -1
  135. package/node_modules/@xrkseek/exec-video-gen/dist/catalog.js +99 -1
  136. package/node_modules/@xrkseek/exec-video-gen/dist/catalog.js.map +1 -1
  137. package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.d.ts +9 -0
  138. package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.d.ts.map +1 -0
  139. package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.js +17 -0
  140. package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.js.map +1 -0
  141. package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.d.ts +14 -0
  142. package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.d.ts.map +1 -0
  143. package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.js +342 -0
  144. package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.js.map +1 -0
  145. package/node_modules/@xrkseek/exec-video-gen/dist/index.d.ts +8 -6
  146. package/node_modules/@xrkseek/exec-video-gen/dist/index.d.ts.map +1 -1
  147. package/node_modules/@xrkseek/exec-video-gen/dist/index.js +122 -19
  148. package/node_modules/@xrkseek/exec-video-gen/dist/index.js.map +1 -1
  149. package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.d.ts +4 -1
  150. package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.d.ts.map +1 -1
  151. package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.js +21 -15
  152. package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.js.map +1 -1
  153. package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.d.ts +9 -0
  154. package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.d.ts.map +1 -0
  155. package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.js +18 -0
  156. package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.js.map +1 -0
  157. package/node_modules/@xrkseek/exec-video-gen/dist/tools.d.ts.map +1 -1
  158. package/node_modules/@xrkseek/exec-video-gen/dist/tools.js +26 -6
  159. package/node_modules/@xrkseek/exec-video-gen/dist/tools.js.map +1 -1
  160. package/node_modules/@xrkseek/exec-video-gen/dist/types.d.ts +1 -1
  161. package/node_modules/@xrkseek/exec-video-gen/dist/types.d.ts.map +1 -1
  162. package/node_modules/@xrkseek/exec-video-gen/dist/types.js.map +1 -1
  163. package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.d.ts +18 -0
  164. package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.d.ts.map +1 -0
  165. package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.js +263 -0
  166. package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.js.map +1 -0
  167. package/node_modules/@xrkseek/preset-harness/dist/preset.d.ts.map +1 -1
  168. package/node_modules/@xrkseek/preset-harness/dist/preset.js +12 -3
  169. package/node_modules/@xrkseek/preset-harness/dist/preset.js.map +1 -1
  170. package/node_modules/@xrkseek/preset-harness/dist/tsconfig.tsbuildinfo +1 -1
  171. package/node_modules/@xrkseek/preset-minimal/dist/tsconfig.tsbuildinfo +1 -1
  172. package/node_modules/@xrkseek/preset-server/dist/tsconfig.tsbuildinfo +1 -1
  173. package/node_modules/@xrkseek/server-face/dist/agent-team-graph.d.ts +31 -0
  174. package/node_modules/@xrkseek/server-face/dist/agent-team-graph.d.ts.map +1 -1
  175. package/node_modules/@xrkseek/server-face/dist/agent-team-graph.js +125 -1
  176. package/node_modules/@xrkseek/server-face/dist/agent-team-graph.js.map +1 -1
  177. package/node_modules/@xrkseek/server-face/dist/context.d.ts +19 -1
  178. package/node_modules/@xrkseek/server-face/dist/context.d.ts.map +1 -1
  179. package/node_modules/@xrkseek/server-face/dist/index.d.ts +3 -3
  180. package/node_modules/@xrkseek/server-face/dist/index.d.ts.map +1 -1
  181. package/node_modules/@xrkseek/server-face/dist/index.js +1 -1
  182. package/node_modules/@xrkseek/server-face/dist/index.js.map +1 -1
  183. package/node_modules/@xrkseek/server-face/dist/mcp-oauth.d.ts.map +1 -1
  184. package/node_modules/@xrkseek/server-face/dist/mcp-oauth.js +25 -3
  185. package/node_modules/@xrkseek/server-face/dist/mcp-oauth.js.map +1 -1
  186. package/node_modules/@xrkseek/server-face/dist/ralph-tool.d.ts +2 -0
  187. package/node_modules/@xrkseek/server-face/dist/ralph-tool.d.ts.map +1 -1
  188. package/node_modules/@xrkseek/server-face/dist/ralph-tool.js +11 -5
  189. package/node_modules/@xrkseek/server-face/dist/ralph-tool.js.map +1 -1
  190. package/node_modules/@xrkseek/server-face/dist/runtime.d.ts.map +1 -1
  191. package/node_modules/@xrkseek/server-face/dist/runtime.js +1 -0
  192. package/node_modules/@xrkseek/server-face/dist/runtime.js.map +1 -1
  193. package/node_modules/@xrkseek/server-face/dist/session-status.d.ts +16 -0
  194. package/node_modules/@xrkseek/server-face/dist/session-status.d.ts.map +1 -1
  195. package/node_modules/@xrkseek/server-face/dist/session-status.js +44 -5
  196. package/node_modules/@xrkseek/server-face/dist/session-status.js.map +1 -1
  197. package/node_modules/@xrkseek/server-face/dist/settings-credentials.d.ts +9 -0
  198. package/node_modules/@xrkseek/server-face/dist/settings-credentials.d.ts.map +1 -1
  199. package/node_modules/@xrkseek/server-face/dist/settings-credentials.js +50 -0
  200. package/node_modules/@xrkseek/server-face/dist/settings-credentials.js.map +1 -1
  201. package/node_modules/@xrkseek/server-face/dist/settings-document.d.ts.map +1 -1
  202. package/node_modules/@xrkseek/server-face/dist/settings-document.js +40 -0
  203. package/node_modules/@xrkseek/server-face/dist/settings-document.js.map +1 -1
  204. package/node_modules/@xrkseek/server-face/dist/settings-schemas.d.ts.map +1 -1
  205. package/node_modules/@xrkseek/server-face/dist/settings-schemas.js +20 -4
  206. package/node_modules/@xrkseek/server-face/dist/settings-schemas.js.map +1 -1
  207. package/node_modules/@xrkseek/server-face/dist/subagent-tools.d.ts.map +1 -1
  208. package/node_modules/@xrkseek/server-face/dist/subagent-tools.js +191 -0
  209. package/node_modules/@xrkseek/server-face/dist/subagent-tools.js.map +1 -1
  210. package/node_modules/@xrkseek/server-face/dist/wire/rpc-error.d.ts.map +1 -1
  211. package/node_modules/@xrkseek/server-face/dist/wire/rpc-error.js +8 -0
  212. package/node_modules/@xrkseek/server-face/dist/wire/rpc-error.js.map +1 -1
  213. package/node_modules/@xrkseek/server-host/dist/index.d.ts.map +1 -1
  214. package/node_modules/@xrkseek/server-host/dist/index.js +135 -24
  215. package/node_modules/@xrkseek/server-host/dist/index.js.map +1 -1
  216. package/node_modules/@xrkseek/server-host/dist/sidebar-face-bridge.d.ts.map +1 -1
  217. package/node_modules/@xrkseek/server-host/dist/sidebar-face-bridge.js +6 -0
  218. package/node_modules/@xrkseek/server-host/dist/sidebar-face-bridge.js.map +1 -1
  219. package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.d.ts +32 -0
  220. package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.d.ts.map +1 -0
  221. package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.js +134 -0
  222. package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.js.map +1 -0
  223. package/node_modules/@xrkseek/server-host/package.json +2 -0
  224. package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-adapter.d.ts.map +1 -1
  225. package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-adapter.js +20 -0
  226. package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-adapter.js.map +1 -1
  227. package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-face-bridge.d.ts +10 -2
  228. package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-face-bridge.d.ts.map +1 -1
  229. package/node_modules/@xrkseek/xrk-workflow/README.i18n.yaml +6 -0
  230. package/node_modules/@xrkseek/xrk-workflow/README.md +73 -0
  231. package/node_modules/@xrkseek/xrk-workflow/README.zh.md +72 -0
  232. package/node_modules/@xrkseek/xrk-workflow/lib/types/index.d.ts +177 -0
  233. package/node_modules/@xrkseek/xrk-workflow/lib/types/index.js +730 -0
  234. package/node_modules/@xrkseek/xrk-workflow/lib/types/invariant.d.ts +13 -0
  235. package/node_modules/@xrkseek/xrk-workflow/lib/types/invariant.js +118 -0
  236. package/node_modules/@xrkseek/xrk-workflow/lib/types/runtime-types.d.ts +45 -0
  237. package/node_modules/@xrkseek/xrk-workflow/lib/types/runtime-types.js +9 -0
  238. package/node_modules/@xrkseek/xrk-workflow/lib/types/types.d.ts +118 -0
  239. package/node_modules/@xrkseek/xrk-workflow/lib/types/types.js +16 -0
  240. package/node_modules/@xrkseek/xrk-workflow/package.json +53 -0
  241. package/node_modules/@xrkseek/xrk-workflow/src/index.ts +947 -0
  242. package/package.json +5 -1
@@ -0,0 +1,677 @@
1
+ import { defineProperty, isNullable } from '@xrkseek/cosmokit';
2
+ import { Context } from "./context.js";
3
+ import { buildOuterStack, composeError, DisposableList, getTraceable, isConstructor, isObject, symbols } from "./utils.js";
4
+ const kValidationError = Symbol.for('ValidationError');
5
+ /** Error raised when plugin configuration fails standard-schema validation. */
6
+ export class ValidationError extends TypeError {
7
+ name = 'ValidationError';
8
+ /**
9
+ * Build the aggregated message from schema issues.
10
+ *
11
+ * @param issues — the standard-schema issues, one message line each.
12
+ */
13
+ constructor(issues) {
14
+ super(`invalid config:\n` + issues.map(issue => {
15
+ if (issue.path) {
16
+ return ` - ${issue.message} (at ${issue.path.join('.')})`;
17
+ }
18
+ else {
19
+ return ` - ${issue.message}`;
20
+ }
21
+ }).join('\n'));
22
+ }
23
+ }
24
+ Object.defineProperty(ValidationError.prototype, kValidationError, {
25
+ value: true,
26
+ });
27
+ /**
28
+ * Validate and normalize config for a plugin runtime before it starts.
29
+ *
30
+ * @param runtime — the plugin runtime whose `Config` schema to apply.
31
+ * @param config — the raw user config.
32
+ * @returns the validated config, or `config` unchanged if the runtime has no schema.
33
+ * @throws {ValidationError} when validation reports issues.
34
+ */
35
+ export function resolveConfig(runtime, config) {
36
+ if (!runtime.Config)
37
+ return config;
38
+ // TODO: async validation
39
+ const result = runtime.Config['~standard'].validate(config);
40
+ if ('then' in result) {
41
+ throw new TypeError('Async config validation is not supported');
42
+ }
43
+ if (result.issues) {
44
+ throw new ValidationError(result.issues);
45
+ }
46
+ else {
47
+ return result.value;
48
+ }
49
+ }
50
+ // Public effect disposers remain single-shot, but structural owners and outer
51
+ // effects must still be able to join a cleanup that another caller started.
52
+ const effectInertia = new WeakMap();
53
+ function runDisposable(dispose) {
54
+ const result = dispose();
55
+ return effectInertia.get(dispose)?.() ?? result;
56
+ }
57
+ /** Notify plugin teardown without allowing one observer to break ownership cleanup. */
58
+ function emitPluginDisposed(context, fiber) {
59
+ const args = ['internal/plugin', fiber];
60
+ let callbacks;
61
+ try {
62
+ callbacks = context.events.dispatch('emit', args);
63
+ }
64
+ catch (error) {
65
+ context.logger.error(error);
66
+ return;
67
+ }
68
+ for (const callback of callbacks) {
69
+ try {
70
+ const returned = callback(...args);
71
+ void Promise.resolve(returned).catch(error => context.logger.error(error));
72
+ }
73
+ catch (error) {
74
+ context.logger.error(error);
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * Lifecycle state for one plugin fiber.
80
+ *
81
+ * `PENDING` — waiting for required services; `LOADING` — the plugin callback
82
+ * is running; `ACTIVE` — loaded and providing; `FAILED` — the callback or its
83
+ * config threw; `UNLOADING` — disposers are running; `DISPOSED` — the fiber
84
+ * was removed and cannot restart.
85
+ */
86
+ export var FiberState;
87
+ (function (FiberState) {
88
+ FiberState[FiberState["PENDING"] = 0] = "PENDING";
89
+ FiberState[FiberState["LOADING"] = 1] = "LOADING";
90
+ FiberState[FiberState["ACTIVE"] = 2] = "ACTIVE";
91
+ FiberState[FiberState["FAILED"] = 3] = "FAILED";
92
+ FiberState[FiberState["DISPOSED"] = 4] = "DISPOSED";
93
+ FiberState[FiberState["UNLOADING"] = 5] = "UNLOADING";
94
+ })(FiberState || (FiberState = {}));
95
+ /** Framework error with a stable machine-readable code. */
96
+ export class CordisError extends Error {
97
+ code;
98
+ /**
99
+ * @param code — the stable error code; also the default message.
100
+ * @param message — optional human-readable override.
101
+ */
102
+ constructor(code, message) {
103
+ super(message ?? CordisError.Code[code]);
104
+ this.code = code;
105
+ }
106
+ }
107
+ /** Cordis error code definitions. */
108
+ (function (CordisError) {
109
+ CordisError.Code = {
110
+ INACTIVE_EFFECT: 'cannot create effect on inactive context',
111
+ };
112
+ })(CordisError || (CordisError = {}));
113
+ const INACTIVE = '__INACTIVE__';
114
+ /**
115
+ * Runtime instance of one plugin application.
116
+ *
117
+ * A fiber tracks dependency state, validated config, lifecycle effects, and
118
+ * cleanup for the plugin context returned by `ctx.plugin()`.
119
+ */
120
+ export class Fiber {
121
+ parent;
122
+ inject;
123
+ runtime;
124
+ /** Unique id within the registry; 0 for the root fiber, `null` once disposed. */
125
+ uid;
126
+ /** The context this fiber's plugin runs in (extends the parent context). */
127
+ ctx;
128
+ /** The validated plugin config (updated by `update()`). */
129
+ config;
130
+ /** The raw plugin config, re-resolved before each activation. */
131
+ _config;
132
+ /** Current lifecycle state; transitions emit `internal/status`. */
133
+ state = FiberState.PENDING;
134
+ /** Dispose this fiber: unload the plugin, then settle once cleanup finished. */
135
+ dispose;
136
+ /** Snapshot of required service implementations while loaded; `undefined` otherwise. */
137
+ store;
138
+ /** The in-flight load/unload transition, if one is currently running. */
139
+ inertia;
140
+ _hooks = Object.create(null);
141
+ _disposables = new DisposableList();
142
+ // Same as `this.ctx`, but with a more specific type.
143
+ context;
144
+ _error;
145
+ _runner;
146
+ _store = Object.create(null);
147
+ /**
148
+ * Create a fiber. Plugin authors normally obtain fibers from `ctx.plugin()`
149
+ * rather than constructing them directly.
150
+ *
151
+ * @param parent — the context the plugin was loaded from.
152
+ * @param config — raw config, validated against the runtime's schema.
153
+ * @param inject — resolved dependency map (service name → intercept config).
154
+ * @param runtime — the shared plugin runtime, or `null` for the root fiber.
155
+ * @param getOuterStack — captures the caller stack for effect diagnostics.
156
+ */
157
+ constructor(parent, config, inject, runtime, getOuterStack) {
158
+ this.parent = parent;
159
+ this.inject = inject;
160
+ this.runtime = runtime;
161
+ this._config = config;
162
+ const collect = (dispose) => {
163
+ this._disposables.push(dispose);
164
+ };
165
+ if (runtime) {
166
+ this.uid = parent.registry.counter;
167
+ this.ctx = this.context = parent.extend({ fiber: this });
168
+ const injectEntries = Object.entries(this.inject);
169
+ if (injectEntries.length) {
170
+ this.ctx[Context.intercept] = Object.create(parent[Context.intercept]);
171
+ for (const [name, config] of injectEntries) {
172
+ if (isNullable(config))
173
+ continue;
174
+ this.ctx[Context.intercept][name] = config;
175
+ }
176
+ }
177
+ this._runner = {
178
+ epoch: INACTIVE,
179
+ getOuterStack,
180
+ execute: function () {
181
+ if (isConstructor(runtime.callback)) {
182
+ // eslint-disable-next-line new-cap
183
+ const instance = new runtime.callback(this.ctx, this.config);
184
+ for (const hook of instance?.[symbols.initHooks] ?? []) {
185
+ hook();
186
+ }
187
+ return instance?.[symbols.init]?.();
188
+ }
189
+ else {
190
+ return runtime.callback(this.ctx, this.config);
191
+ }
192
+ },
193
+ collect,
194
+ };
195
+ this.dispose = parent.fiber.effect(() => {
196
+ const remove = runtime.fibers.push(this);
197
+ return async () => {
198
+ this.uid = null;
199
+ emitPluginDisposed(this.context, this);
200
+ if (this.ctx.registry.has(runtime.callback)) {
201
+ remove();
202
+ if (!runtime.fibers.length) {
203
+ this.ctx.registry.delete(runtime.callback);
204
+ }
205
+ }
206
+ this._setEpoch(INACTIVE);
207
+ // A PENDING fiber can already own effects registered by an
208
+ // internal/plugin observer. Its epoch is still INACTIVE, so
209
+ // _setEpoch() has no transition to drive; explicitly unload that
210
+ // pre-activation work before reporting disposal complete.
211
+ if (!this.inertia) {
212
+ this._updateState(() => {
213
+ this.inertia = this._unload();
214
+ return FiberState.UNLOADING;
215
+ });
216
+ }
217
+ // `this.inertia` itself should never reject — both `_reload` and
218
+ // `_unload` swallow their own work errors via `ctx.logger.error`.
219
+ // If it *does* reject, the only remaining cause is the logger
220
+ // itself failing, which we can't recover from in this exact spot
221
+ // (calling the logger again is what just failed). Let the
222
+ // rejection propagate; process-level crash is the honest outcome.
223
+ while (this.inertia) {
224
+ await this.inertia;
225
+ }
226
+ };
227
+ }, 'ctx.plugin()');
228
+ try {
229
+ // Publish only after the parent owns a fully assigned disposer. A
230
+ // synchronous observer may dispose either this fiber or its parent.
231
+ this.context.emit('internal/plugin', this);
232
+ }
233
+ catch (error) {
234
+ // Publication failed synchronously. The disposer removes the child
235
+ // from both the parent and runtime before control escapes.
236
+ void Promise.resolve(this.dispose()).catch(reason => this.ctx.logger.error(reason));
237
+ throw error;
238
+ }
239
+ // Keep the initial notification's historical PENDING view. The loader
240
+ // may also extend `inject` in that notification, so resolve dependencies
241
+ // only after publication. A reentrant parent unload makes the child
242
+ // disposer responsible for draining any PENDING effects instead.
243
+ if (this.uid !== null && parent.fiber.state !== FiberState.UNLOADING) {
244
+ for (const name of Object.keys(this.inject)) {
245
+ this._checkImpl(name);
246
+ }
247
+ this._refresh();
248
+ }
249
+ }
250
+ else {
251
+ this.uid = 0;
252
+ this.ctx = this.context = parent;
253
+ this.state = FiberState.ACTIVE;
254
+ this.store = Object.create(null);
255
+ this._runner = {
256
+ epoch: '',
257
+ getOuterStack,
258
+ execute: () => { },
259
+ collect,
260
+ };
261
+ this.dispose = () => this.restart();
262
+ }
263
+ }
264
+ /** The plugin's display name, inherited from the nearest named ancestor, else `'root'`. */
265
+ get name() {
266
+ let fiber = this;
267
+ do {
268
+ if (fiber.runtime?.name)
269
+ return fiber.runtime.name;
270
+ fiber = fiber.parent.fiber;
271
+ } while (fiber !== fiber.parent.fiber);
272
+ return 'root';
273
+ }
274
+ /**
275
+ * Throw if the fiber has already been disposed.
276
+ *
277
+ * @returns nothing when the fiber is still active.
278
+ * @throws {CordisError} `INACTIVE_EFFECT` when the fiber's uid has been cleared.
279
+ */
280
+ assertActive() {
281
+ if (this.uid !== null)
282
+ return;
283
+ throw new CordisError('INACTIVE_EFFECT');
284
+ }
285
+ _execute(runner) {
286
+ const oldEpoch = runner.epoch;
287
+ return composeError((info) => {
288
+ const safeCollect = (dispose) => {
289
+ if (typeof dispose === 'function') {
290
+ runner.collect(dispose);
291
+ }
292
+ else if (!isNullable(dispose)) {
293
+ throw new TypeError('Invalid effect');
294
+ }
295
+ };
296
+ const effect = runner.execute.call(this);
297
+ if (typeof effect === 'function') {
298
+ return runner.collect(effect);
299
+ }
300
+ else if (isNullable(effect)) {
301
+ // return
302
+ }
303
+ else if (!isObject(effect)) {
304
+ throw new TypeError('Invalid effect');
305
+ }
306
+ else if ('then' in effect) {
307
+ return effect.then(safeCollect);
308
+ }
309
+ else if (Symbol.iterator in effect) {
310
+ info.error = new Error();
311
+ const iter = effect[Symbol.iterator]();
312
+ while (true) {
313
+ const result = iter.next();
314
+ safeCollect(result.value);
315
+ if (result.done)
316
+ return;
317
+ }
318
+ }
319
+ else if (Symbol.asyncIterator in effect) {
320
+ const iter = effect[Symbol.asyncIterator]();
321
+ return (async () => {
322
+ // force async stack trace
323
+ await Promise.resolve();
324
+ info.error = new Error();
325
+ while (true) {
326
+ if (runner.epoch !== oldEpoch)
327
+ return;
328
+ const result = await iter.next();
329
+ safeCollect(result.value);
330
+ if (result.done)
331
+ return;
332
+ }
333
+ })();
334
+ }
335
+ else {
336
+ throw new TypeError('Invalid effect');
337
+ }
338
+ }, runner.getOuterStack);
339
+ }
340
+ effect(execute, label = 'anonymous') {
341
+ this.assertActive();
342
+ if (this.state === FiberState.UNLOADING) {
343
+ throw new CordisError('INACTIVE_EFFECT');
344
+ }
345
+ const disposables = [];
346
+ let disposing = false;
347
+ let disposalTask;
348
+ const dispose = () => {
349
+ if (disposing)
350
+ return disposalTask;
351
+ disposing = true;
352
+ let task;
353
+ for (const disposable of disposables.splice(0).reverse()) {
354
+ if (task) {
355
+ task = task.then(() => runDisposable(disposable));
356
+ }
357
+ else {
358
+ const result = runDisposable(disposable);
359
+ if (isObject(result) && 'then' in result) {
360
+ task = result;
361
+ }
362
+ }
363
+ }
364
+ return disposalTask = task;
365
+ };
366
+ const meta = { label, children: [] };
367
+ const runner = {
368
+ execute,
369
+ epoch: true,
370
+ collect: (dispose) => {
371
+ disposables.push(dispose);
372
+ this._disposables.delete(dispose);
373
+ if (dispose[symbols.effect]) {
374
+ meta.children.push(dispose[symbols.effect]);
375
+ }
376
+ },
377
+ getOuterStack: buildOuterStack(),
378
+ };
379
+ let task;
380
+ let executing = true;
381
+ let resolveSetup;
382
+ let rejectSetup;
383
+ let setupBarrier;
384
+ let setupFailed = false;
385
+ let inFlight;
386
+ let removeWrapper = () => false;
387
+ const waitForSetup = () => {
388
+ setupBarrier ??= new Promise((resolve, reject) => {
389
+ resolveSetup = resolve;
390
+ rejectSetup = reject;
391
+ });
392
+ return setupBarrier;
393
+ };
394
+ const disposeAfter = (setup) => {
395
+ return Promise.resolve(setup).then(() => dispose(), async (reason) => {
396
+ await dispose();
397
+ throw reason;
398
+ });
399
+ };
400
+ const finalizeDisposal = (callback) => {
401
+ let result;
402
+ try {
403
+ result = callback();
404
+ }
405
+ catch (error) {
406
+ removeWrapper();
407
+ throw error;
408
+ }
409
+ if (isObject(result) && 'then' in result) {
410
+ const pending = Promise.resolve(result).finally(() => {
411
+ removeWrapper();
412
+ if (inFlight === pending)
413
+ inFlight = undefined;
414
+ });
415
+ return inFlight = pending;
416
+ }
417
+ removeWrapper();
418
+ return result;
419
+ };
420
+ const wrapper = defineProperty(() => {
421
+ // A synchronous setup failure can race an owner unload that already
422
+ // captured this wrapper but has not invoked it yet. The failed effect is
423
+ // never returned publicly, so let that internal caller await rollback.
424
+ if (!runner.epoch)
425
+ return setupFailed ? inFlight : undefined;
426
+ runner.epoch = false;
427
+ return finalizeDisposal(() => {
428
+ if (executing)
429
+ return disposeAfter(waitForSetup());
430
+ return task ? disposeAfter(task) : dispose();
431
+ });
432
+ }, symbols.effect, meta);
433
+ effectInertia.set(wrapper, () => inFlight);
434
+ // Make the effect visible to a reentrant owner unload before execute()
435
+ // runs any plugin code. Async teardown stays owner-visible until it
436
+ // settles, allowing an outer effect to join cleanup another caller began.
437
+ removeWrapper = this._disposables.push(wrapper);
438
+ try {
439
+ task = this._execute(runner);
440
+ }
441
+ catch (reason) {
442
+ executing = false;
443
+ setupFailed = true;
444
+ runner.epoch = false;
445
+ let cleanup;
446
+ try {
447
+ cleanup = finalizeDisposal(dispose);
448
+ }
449
+ finally {
450
+ rejectSetup?.(reason);
451
+ }
452
+ if (isObject(cleanup) && 'then' in cleanup) {
453
+ cleanup.catch(error => this.ctx.logger.error(error));
454
+ }
455
+ throw reason;
456
+ }
457
+ executing = false;
458
+ if (setupBarrier) {
459
+ Promise.resolve(task).then(resolveSetup, rejectSetup);
460
+ }
461
+ // prevent unhandled rejection — both from `task` itself and from the
462
+ // disposer chain if it fails to settle cleanly.
463
+ task?.catch(() => {
464
+ if (!runner.epoch)
465
+ return dispose();
466
+ return finalizeDisposal(dispose);
467
+ }).catch((error) => this.ctx.logger.error(error));
468
+ const disposeAsync = () => {
469
+ if (!runner.epoch)
470
+ return;
471
+ runner.epoch = false;
472
+ return finalizeDisposal(dispose);
473
+ };
474
+ wrapper.then = async (onFulfilled, onRejected) => {
475
+ return Promise.resolve(task)
476
+ .then(() => disposeAsync)
477
+ .then(onFulfilled, onRejected);
478
+ };
479
+ return wrapper;
480
+ }
481
+ /**
482
+ * Return metadata for currently registered effects.
483
+ *
484
+ * @returns one {@link EffectMeta} tree per labeled live effect.
485
+ */
486
+ getEffects() {
487
+ return [...this._disposables]
488
+ .map(dispose => dispose[symbols.effect])
489
+ .filter(Boolean);
490
+ }
491
+ _getState() {
492
+ if (this.uid === null)
493
+ return FiberState.DISPOSED;
494
+ if (this._error)
495
+ return FiberState.FAILED;
496
+ if (this._runner.epoch !== INACTIVE)
497
+ return FiberState.ACTIVE;
498
+ return FiberState.PENDING;
499
+ }
500
+ _updateState(callback) {
501
+ const oldState = this.state;
502
+ this.state = callback() ?? this._getState();
503
+ if (oldState === this.state)
504
+ return;
505
+ // FIXME internal/fiber-info
506
+ this.context.emit('internal/status', this, oldState);
507
+ // only notify changes between ACTIVE and NON-ACTIVE states
508
+ if (oldState !== FiberState.ACTIVE && this.state !== FiberState.ACTIVE)
509
+ return;
510
+ for (const key of Reflect.ownKeys(this.ctx.reflect.store)) {
511
+ const impl = this.ctx.reflect.store[key];
512
+ if (impl.fiber !== this)
513
+ continue;
514
+ this.ctx.reflect.notify([impl.name]);
515
+ }
516
+ }
517
+ _checkImpl(name) {
518
+ const impl = this.ctx.reflect._getImpl(name, true);
519
+ if (!impl)
520
+ return delete this._store[name];
521
+ try {
522
+ if (impl.check && !impl.check.call(getTraceable(this.ctx, impl.value))) {
523
+ return delete this._store[name];
524
+ }
525
+ }
526
+ catch (error) {
527
+ impl.fiber.ctx.logger.error(error);
528
+ return delete this._store[name];
529
+ }
530
+ this._store[name] = impl;
531
+ }
532
+ _refresh() {
533
+ let epoch = false;
534
+ epoch = '';
535
+ for (const name of Object.keys(this.inject)) {
536
+ const impl = this._store[name];
537
+ if (!impl) {
538
+ epoch = INACTIVE;
539
+ break;
540
+ }
541
+ epoch += ':' + impl.fiber.uid;
542
+ }
543
+ this._setEpoch(epoch);
544
+ }
545
+ _setEpoch(epoch) {
546
+ const oldEpoch = this._runner.epoch;
547
+ if (epoch === oldEpoch)
548
+ return;
549
+ this._runner.epoch = epoch;
550
+ if (this.inertia)
551
+ return;
552
+ this._updateState(() => {
553
+ if (epoch !== INACTIVE && oldEpoch === INACTIVE) {
554
+ this.inertia = this._reload();
555
+ return FiberState.LOADING;
556
+ }
557
+ else {
558
+ this.inertia = this._unload();
559
+ return FiberState.UNLOADING;
560
+ }
561
+ });
562
+ }
563
+ _resolveConfig(config) {
564
+ config = this.context.waterfall(this, 'internal/config', config, () => config);
565
+ return this.runtime ? resolveConfig(this.runtime, config) : config;
566
+ }
567
+ async _reload() {
568
+ this.store = { ...this._store };
569
+ const oldEpoch = this._runner.epoch;
570
+ try {
571
+ await Promise.resolve();
572
+ // A disposer queued before this checkpoint may already have invalidated
573
+ // the load. Do not run plugin code for a stale epoch; the state update
574
+ // below will drain any effects collected while the fiber was PENDING.
575
+ if (this._runner.epoch === oldEpoch) {
576
+ this.config = this._resolveConfig(this._config);
577
+ await this._execute(this._runner);
578
+ this._error = undefined;
579
+ }
580
+ }
581
+ catch (reason) {
582
+ // impl guarantees that the error is non-null (?)
583
+ this.ctx.logger.error(reason);
584
+ this._error = reason;
585
+ this._runner.epoch = INACTIVE;
586
+ }
587
+ this._updateState(() => {
588
+ if (this._runner.epoch === oldEpoch) {
589
+ this.inertia = undefined;
590
+ }
591
+ else {
592
+ this.inertia = this._unload();
593
+ return FiberState.UNLOADING;
594
+ }
595
+ });
596
+ }
597
+ async _unload() {
598
+ await Promise.all(this._disposables.clear().map(async (dispose) => {
599
+ try {
600
+ await composeError(async (info) => {
601
+ await Promise.resolve();
602
+ info.error = new Error();
603
+ await runDisposable(dispose);
604
+ }, this._runner.getOuterStack);
605
+ }
606
+ catch (reason) {
607
+ this.ctx.logger.error(reason);
608
+ }
609
+ }));
610
+ this.store = undefined;
611
+ this._updateState(() => {
612
+ if (this._runner.epoch === INACTIVE) {
613
+ this.inertia = undefined;
614
+ }
615
+ else {
616
+ this.inertia = this._reload();
617
+ return FiberState.LOADING;
618
+ }
619
+ });
620
+ }
621
+ /**
622
+ * Wait for current lifecycle work and rethrow startup errors.
623
+ *
624
+ * @returns this fiber, once it has settled into a stable state.
625
+ * @throws the config-validation or plugin-startup error, if any.
626
+ */
627
+ async await() {
628
+ while (this.inertia) {
629
+ await this.inertia;
630
+ }
631
+ if (this._error)
632
+ throw this._error;
633
+ return this;
634
+ }
635
+ /**
636
+ * Dispose and immediately reload this plugin with its current config.
637
+ *
638
+ * @returns a promise resolving once the reload settled.
639
+ * @throws {CordisError} `INACTIVE_EFFECT` when the fiber is already disposed.
640
+ */
641
+ async restart() {
642
+ this.assertActive();
643
+ this._setEpoch(INACTIVE);
644
+ this._refresh();
645
+ await this.await();
646
+ }
647
+ /**
648
+ * Validate and apply new config, then restart the plugin.
649
+ *
650
+ * Runs the `internal/update` waterfall first, so update hooks (and HMR)
651
+ * can veto or replace the restart.
652
+ *
653
+ * @param config — the new raw config; validated before anything restarts.
654
+ * @param noSave — hint for persistence hooks not to write the change back.
655
+ * @returns the update waterfall result; the default restart returns a promise.
656
+ * @throws when validation, an update listener, or the restarted plugin fails.
657
+ */
658
+ update(config, noSave = false) {
659
+ this.assertActive();
660
+ this._config = config;
661
+ if (this.state !== FiberState.ACTIVE) {
662
+ // Config resolution may access injected services, so defer it until the
663
+ // fiber can activate.
664
+ this._error = undefined;
665
+ this._setEpoch(INACTIVE);
666
+ this._refresh();
667
+ return;
668
+ }
669
+ config = this._resolveConfig(config);
670
+ return this.context.waterfall(this, 'internal/update', config, noSave, () => {
671
+ this.config = config;
672
+ this._error = undefined;
673
+ return this.restart();
674
+ });
675
+ }
676
+ }
677
+ //# sourceMappingURL=fiber.js.map