@actiondock/core 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +61 -68
  2. package/dist/catalog/action-catalog.d.ts +56 -0
  3. package/dist/catalog/action-catalog.js +202 -0
  4. package/dist/catalog/discovery.d.ts +60 -0
  5. package/dist/catalog/discovery.js +119 -0
  6. package/dist/catalog/graph.d.ts +190 -0
  7. package/dist/catalog/graph.js +589 -0
  8. package/dist/catalog/index.d.ts +5 -5
  9. package/dist/catalog/index.js +5 -5
  10. package/dist/catalog/resolve-action.d.ts +43 -0
  11. package/dist/catalog/resolve-action.js +119 -0
  12. package/dist/catalog/resolve-playbook.d.ts +26 -0
  13. package/dist/catalog/resolve-playbook.js +114 -0
  14. package/dist/doctor/checks/project.js +27 -8
  15. package/dist/doctor/checks/registry.js +2 -2
  16. package/dist/doctor/checks/runtime.js +34 -1
  17. package/dist/errors.d.ts +122 -10
  18. package/dist/errors.js +123 -10
  19. package/dist/execution/service.d.ts +18 -16
  20. package/dist/execution/service.js +183 -252
  21. package/dist/execution/types.d.ts +25 -69
  22. package/dist/execution/types.js +2 -1
  23. package/dist/filter/intent.d.ts +8 -9
  24. package/dist/filter/intent.js +49 -10
  25. package/dist/graph/index.d.ts +4 -0
  26. package/dist/graph/index.js +4 -0
  27. package/dist/host/host.d.ts +74 -32
  28. package/dist/host/host.js +585 -336
  29. package/dist/host/routing.d.ts +15 -48
  30. package/dist/host/routing.js +90 -153
  31. package/dist/host/types.d.ts +50 -17
  32. package/dist/index.d.ts +21 -22
  33. package/dist/index.js +19 -21
  34. package/dist/input/advice.d.ts +104 -0
  35. package/dist/input/advice.js +716 -0
  36. package/dist/input/describe.d.ts +106 -0
  37. package/dist/input/describe.js +176 -0
  38. package/dist/input/file-input.d.ts +54 -0
  39. package/dist/input/file-input.js +124 -0
  40. package/dist/input/flat-decode.d.ts +11 -0
  41. package/dist/input/flat-decode.js +13 -0
  42. package/dist/input/flat-errors.d.ts +71 -0
  43. package/dist/input/flat-errors.js +87 -0
  44. package/dist/input/flat-materializer.d.ts +29 -0
  45. package/dist/input/flat-materializer.js +177 -0
  46. package/dist/input/flat-parser.d.ts +50 -0
  47. package/dist/input/flat-parser.js +169 -0
  48. package/dist/input/flat-predicates.d.ts +34 -0
  49. package/dist/input/flat-predicates.js +50 -0
  50. package/dist/input/index.d.ts +14 -0
  51. package/dist/input/index.js +14 -0
  52. package/dist/input/input-resolver.d.ts +63 -0
  53. package/dist/input/input-resolver.js +254 -0
  54. package/dist/input/json-depth-scanner.d.ts +17 -0
  55. package/dist/input/json-depth-scanner.js +49 -0
  56. package/dist/input/metadata.d.ts +99 -0
  57. package/dist/input/metadata.js +99 -0
  58. package/dist/input/stdin-input.d.ts +26 -0
  59. package/dist/input/stdin-input.js +125 -0
  60. package/dist/input/utf8.d.ts +19 -0
  61. package/dist/input/utf8.js +36 -0
  62. package/dist/input/validation-mapper.d.ts +27 -0
  63. package/dist/input/validation-mapper.js +144 -0
  64. package/dist/invocation/index.d.ts +2 -0
  65. package/dist/invocation/index.js +2 -0
  66. package/dist/invocation/policy.d.ts +157 -0
  67. package/dist/invocation/policy.js +231 -0
  68. package/dist/invocation/types.d.ts +172 -0
  69. package/dist/invocation/types.js +97 -0
  70. package/dist/ipc/diagnostic.d.ts +0 -12
  71. package/dist/ipc/diagnostic.js +0 -21
  72. package/dist/ipc/host.d.ts +4 -4
  73. package/dist/ipc/host.js +44 -47
  74. package/dist/ipc/index.d.ts +1 -1
  75. package/dist/ipc/index.js +1 -1
  76. package/dist/ipc/service.d.ts +40 -0
  77. package/dist/ipc/service.js +349 -0
  78. package/dist/ipc/types.d.ts +21 -15
  79. package/dist/json/index.d.ts +1 -0
  80. package/dist/json/index.js +1 -0
  81. package/dist/json/value-validator.d.ts +88 -0
  82. package/dist/json/value-validator.js +330 -0
  83. package/dist/node/index.d.ts +1 -0
  84. package/dist/node/index.js +1 -0
  85. package/dist/node/module-loader.d.ts +63 -0
  86. package/dist/node/module-loader.js +112 -0
  87. package/dist/package/index.d.ts +23 -0
  88. package/dist/package/index.js +18 -0
  89. package/dist/{app/app.d.ts → package/runtime.d.ts} +41 -20
  90. package/dist/{app/app.js → package/runtime.js} +140 -95
  91. package/dist/{app → package}/static-index.js +58 -41
  92. package/dist/package/storage-view.d.ts +13 -0
  93. package/dist/package/storage-view.js +22 -0
  94. package/dist/{app → package}/types.d.ts +76 -57
  95. package/dist/package/types.js +22 -0
  96. package/dist/platform/index.d.ts +1 -1
  97. package/dist/platform/index.js +1 -1
  98. package/dist/platform/node.d.ts +48 -0
  99. package/dist/platform/node.js +96 -0
  100. package/dist/platform/types.d.ts +0 -9
  101. package/dist/process/control-arbiter.d.ts +2 -1
  102. package/dist/process/control-arbiter.js +1 -2
  103. package/dist/process/driver.d.ts +9 -8
  104. package/dist/process/driver.js +11 -22
  105. package/dist/process/index.d.ts +2 -0
  106. package/dist/process/index.js +2 -0
  107. package/dist/process/managed-record.d.ts +2 -2
  108. package/dist/process/process-driver.d.ts +109 -0
  109. package/dist/process/process-driver.js +650 -0
  110. package/dist/process/process-executor.d.ts +47 -0
  111. package/dist/process/process-executor.js +296 -0
  112. package/dist/process/process-manager.js +48 -26
  113. package/dist/process/run-executor.js +12 -12
  114. package/dist/profile/client-actions.js +2 -2
  115. package/dist/profile/client-health.js +3 -2
  116. package/dist/profile/client-query.js +5 -6
  117. package/dist/profile/client-transport.d.ts +19 -17
  118. package/dist/profile/client-transport.js +48 -80
  119. package/dist/profile/client.d.ts +2 -2
  120. package/dist/profile/client.js +1 -1
  121. package/dist/profile/index.d.ts +1 -0
  122. package/dist/profile/index.js +1 -0
  123. package/dist/profile/manager.d.ts +5 -0
  124. package/dist/profile/manager.js +41 -6
  125. package/dist/project/closure.js +2 -2
  126. package/dist/project/index.d.ts +8 -1
  127. package/dist/project/index.js +10 -1
  128. package/dist/project/init.js +2 -2
  129. package/dist/project/loader.d.ts +1 -1
  130. package/dist/project/loader.js +26 -29
  131. package/dist/project/transactions.js +5 -10
  132. package/dist/registry/index.d.ts +3 -1
  133. package/dist/registry/index.js +2 -1
  134. package/dist/registry/lock.d.ts +28 -7
  135. package/dist/registry/lock.js +136 -16
  136. package/dist/registry/registry.d.ts +1 -5
  137. package/dist/registry/registry.js +1 -53
  138. package/dist/registry/scan.d.ts +0 -15
  139. package/dist/registry/scan.js +0 -59
  140. package/dist/registry/store.d.ts +42 -0
  141. package/dist/registry/store.js +43 -0
  142. package/dist/registry/types.d.ts +0 -24
  143. package/dist/runtime/action-collection.d.ts +1 -1
  144. package/dist/runtime/action-registry.d.ts +0 -4
  145. package/dist/runtime/action-registry.js +0 -7
  146. package/dist/runtime/context.js +5 -11
  147. package/dist/runtime/events.js +3 -6
  148. package/dist/runtime/identity.d.ts +22 -0
  149. package/dist/runtime/identity.js +10 -0
  150. package/dist/runtime/index.d.ts +1 -2
  151. package/dist/runtime/index.js +1 -2
  152. package/dist/runtime/module-loader.d.ts +2 -34
  153. package/dist/runtime/module-loader.js +1 -16
  154. package/dist/runtime/process.d.ts +6 -24
  155. package/dist/runtime/process.js +1 -118
  156. package/dist/runtime/run-persistence.js +2 -5
  157. package/dist/runtime/runner.d.ts +33 -103
  158. package/dist/runtime/runner.js +142 -404
  159. package/dist/runtime/standalone.d.ts +37 -9
  160. package/dist/runtime/standalone.js +195 -136
  161. package/dist/schema/index.d.ts +1 -0
  162. package/dist/schema/index.js +1 -0
  163. package/dist/schema/validator.d.ts +10 -0
  164. package/dist/schema/validator.js +48 -54
  165. package/dist/server/body.d.ts +16 -8
  166. package/dist/server/body.js +33 -16
  167. package/dist/server/dispatcher.d.ts +6 -10
  168. package/dist/server/dispatcher.js +24 -32
  169. package/dist/server/http-server.d.ts +87 -0
  170. package/dist/server/http-server.js +304 -0
  171. package/dist/server/index.d.ts +11 -0
  172. package/dist/server/index.js +10 -0
  173. package/dist/server/mcp-endpoint.d.ts +61 -0
  174. package/dist/server/mcp-endpoint.js +118 -0
  175. package/dist/server/routes/actions.js +34 -28
  176. package/dist/server/routes/common.d.ts +10 -14
  177. package/dist/server/routes/common.js +32 -56
  178. package/dist/server/routes/config.js +54 -64
  179. package/dist/server/routes/doctor.d.ts +1 -1
  180. package/dist/server/routes/doctor.js +10 -18
  181. package/dist/server/routes/health.d.ts +1 -1
  182. package/dist/server/routes/health.js +2 -3
  183. package/dist/server/routes/info.d.ts +2 -2
  184. package/dist/server/routes/info.js +12 -13
  185. package/dist/server/routes/playbooks.js +16 -29
  186. package/dist/server/routes/runs.js +95 -117
  187. package/dist/server/routes/state.js +63 -62
  188. package/dist/server/server.d.ts +2 -2
  189. package/dist/server/server.js +43 -227
  190. package/dist/server/types.d.ts +8 -19
  191. package/dist/service/factory.d.ts +12 -0
  192. package/dist/service/factory.js +85 -0
  193. package/dist/{target → service}/index.d.ts +1 -1
  194. package/dist/{target → service}/index.js +1 -1
  195. package/dist/service/local.d.ts +27 -0
  196. package/dist/service/local.js +138 -0
  197. package/dist/{target → service}/remote-errors.d.ts +3 -6
  198. package/dist/service/remote-errors.js +38 -0
  199. package/dist/{target → service}/remote-polling.d.ts +2 -2
  200. package/dist/{target → service}/remote-polling.js +8 -8
  201. package/dist/service/remote.d.ts +34 -0
  202. package/dist/service/remote.js +634 -0
  203. package/dist/service/sse-stream.d.ts +24 -0
  204. package/dist/service/sse-stream.js +139 -0
  205. package/dist/service/types.d.ts +272 -0
  206. package/dist/service/types.js +32 -0
  207. package/dist/storage/data-dir-lock.js +10 -5
  208. package/dist/storage/driver.d.ts +2 -1
  209. package/dist/storage/driver.js +3 -52
  210. package/dist/storage/index.d.ts +1 -0
  211. package/dist/storage/index.js +1 -0
  212. package/dist/storage/lock-core.d.ts +2 -6
  213. package/dist/storage/lock-core.js +4 -17
  214. package/dist/storage/params.d.ts +2 -8
  215. package/dist/storage/params.js +2 -8
  216. package/dist/storage/sqlite-driver.d.ts +40 -0
  217. package/dist/storage/sqlite-driver.js +116 -0
  218. package/dist/storage/sqlite.js +21 -6
  219. package/dist/storage/types.d.ts +4 -4
  220. package/dist/storage/types.js +2 -2
  221. package/dist/utils/index.d.ts +53 -0
  222. package/dist/utils/index.js +99 -4
  223. package/dist/utils/process.d.ts +10 -0
  224. package/dist/utils/process.js +21 -0
  225. package/dist/version.d.ts +1 -1
  226. package/dist/version.js +1 -1
  227. package/package.json +41 -3
  228. package/dist/app/index.d.ts +0 -2
  229. package/dist/app/index.js +0 -2
  230. package/dist/app/types.js +0 -1
  231. package/dist/catalog/action-index.d.ts +0 -9
  232. package/dist/catalog/action-index.js +0 -95
  233. package/dist/catalog/action-resolver.d.ts +0 -20
  234. package/dist/catalog/action-resolver.js +0 -95
  235. package/dist/catalog/location-registry.d.ts +0 -15
  236. package/dist/catalog/location-registry.js +0 -138
  237. package/dist/catalog/package-catalog.d.ts +0 -7
  238. package/dist/catalog/package-catalog.js +0 -77
  239. package/dist/catalog/types.d.ts +0 -68
  240. package/dist/catalog/types.js +0 -1
  241. package/dist/export/index.d.ts +0 -1
  242. package/dist/export/index.js +0 -1
  243. package/dist/export/templates.d.ts +0 -71
  244. package/dist/export/templates.js +0 -623
  245. package/dist/ipc/target.d.ts +0 -74
  246. package/dist/ipc/target.js +0 -365
  247. package/dist/platform/default.d.ts +0 -38
  248. package/dist/platform/default.js +0 -78
  249. package/dist/project/resolver.d.ts +0 -116
  250. package/dist/project/resolver.js +0 -376
  251. package/dist/registry/resolve.d.ts +0 -62
  252. package/dist/registry/resolve.js +0 -195
  253. package/dist/runtime/execution-manager.d.ts +0 -48
  254. package/dist/runtime/execution-manager.js +0 -66
  255. package/dist/runtime/package-runner-factory.d.ts +0 -82
  256. package/dist/runtime/package-runner-factory.js +0 -186
  257. package/dist/target/local.d.ts +0 -53
  258. package/dist/target/local.js +0 -349
  259. package/dist/target/remote-errors.js +0 -51
  260. package/dist/target/remote.d.ts +0 -86
  261. package/dist/target/remote.js +0 -818
  262. package/dist/target/target.d.ts +0 -6
  263. package/dist/target/target.js +0 -37
  264. package/dist/target/types.d.ts +0 -261
  265. package/dist/target/types.js +0 -35
  266. /package/dist/{app → package}/static-index.d.ts +0 -0
  267. /package/dist/{target → service}/sse-parser.d.ts +0 -0
  268. /package/dist/{target → service}/sse-parser.js +0 -0
@@ -1,10 +1,11 @@
1
+ import { DOCTOR_ERROR, PACKAGE_NOT_ALLOWED } from "../../errors.js";
1
2
  import { runDoctorChecks } from "../../doctor/doctor.js";
2
3
  import { assertPackageAllowed, getSubPath, jsonResponse } from "./common.js";
3
4
  /**
4
- * 处理环境与依赖诊断接口(GET /api/v2/doctor、/doctor 与兼容别名 /api/v1/doctor)。
5
+ * 处理环境与依赖诊断接口(GET /api/v2/doctor 与 /doctor)。
5
6
  */
6
7
  export async function handleDoctorRoute(ctx) {
7
- const { req, url, pathname, corsHeaders, projectRoot, customHome, host, target, options } = ctx;
8
+ const { req, url, pathname, corsHeaders, projectRoot, customHome, service, options } = ctx;
8
9
  const subpath = getSubPath(pathname);
9
10
  if (subpath !== "/doctor" || req.method !== "GET") {
10
11
  return null;
@@ -16,7 +17,7 @@ export async function handleDoctorRoute(ctx) {
16
17
  return jsonResponse({
17
18
  ok: false,
18
19
  error: {
19
- code: "PACKAGE_NOT_ALLOWED",
20
+ code: PACKAGE_NOT_ALLOWED,
20
21
  message: "Global doctor check is forbidden when package allowlist is active. Please specify an allowed package.",
21
22
  },
22
23
  }, 403, corsHeaders);
@@ -27,18 +28,9 @@ export async function handleDoctorRoute(ctx) {
27
28
  }
28
29
  let packageRoot;
29
30
  if (targetPkg) {
30
- if (host) {
31
- packageRoot = host.getApp(targetPkg)?.packageRoot;
32
- }
33
- if (!packageRoot && target?.unwrap) {
34
- const inner = target.unwrap();
35
- if (inner && "getApp" in inner && typeof inner.getApp === "function") {
36
- packageRoot = inner.getApp(targetPkg)?.packageRoot;
37
- }
38
- else if (inner && "packageId" in inner && inner.packageId === targetPkg) {
39
- packageRoot = inner.packageRoot;
40
- }
41
- }
31
+ const pkgs = await service.discovery.listPackages();
32
+ const matched = pkgs.find((p) => p.id === targetPkg || p.packageRoot === targetPkg);
33
+ packageRoot = matched?.packageRoot;
42
34
  }
43
35
  const report = await runDoctorChecks({
44
36
  cwd: packageRoot || projectRoot || process.cwd(),
@@ -49,15 +41,15 @@ export async function handleDoctorRoute(ctx) {
49
41
  return jsonResponse({ ok: true, report }, 200, corsHeaders);
50
42
  }
51
43
  catch (err) {
52
- if (err.code === "PACKAGE_NOT_ALLOWED" || err.status === 403) {
44
+ if (err.code === PACKAGE_NOT_ALLOWED || err.status === 403) {
53
45
  return jsonResponse({
54
46
  ok: false,
55
47
  error: {
56
- code: "PACKAGE_NOT_ALLOWED",
48
+ code: PACKAGE_NOT_ALLOWED,
57
49
  message: err.message || "Package is not in the allowed package list",
58
50
  },
59
51
  }, 403, corsHeaders);
60
52
  }
61
- return jsonResponse({ ok: false, error: { code: "DOCTOR_ERROR", message: err.message } }, 500, corsHeaders);
53
+ return jsonResponse({ ok: false, error: { code: DOCTOR_ERROR, message: err.message } }, 500, corsHeaders);
62
54
  }
63
55
  }
@@ -1,5 +1,5 @@
1
1
  import { type RouteContext } from "./common.js";
2
2
  /**
3
- * 处理健康检查与就绪状态接口(支持 /api/v2/health、/health 与兼容别名 /api/v1/health)。
3
+ * 处理健康检查与就绪状态接口(支持 /api/v2/health 与 /health)。
4
4
  */
5
5
  export declare function handleHealthRoute(ctx: RouteContext): Promise<Response | null>;
@@ -3,13 +3,12 @@ import { UNAUTHORIZED } from "../../errors.js";
3
3
  import { verifyBearerToken } from "../security.js";
4
4
  import { jsonResponse } from "./common.js";
5
5
  /**
6
- * 处理健康检查与就绪状态接口(支持 /api/v2/health、/health 与兼容别名 /api/v1/health)。
6
+ * 处理健康检查与就绪状态接口(支持 /api/v2/health 与 /health)。
7
7
  */
8
8
  export async function handleHealthRoute(ctx) {
9
9
  const { req, pathname, corsHeaders, options, projectRoot } = ctx;
10
10
  if (pathname !== "/api/v2/health" &&
11
- pathname !== "/health" &&
12
- pathname !== "/api/v1/health") {
11
+ pathname !== "/health") {
13
12
  return null;
14
13
  }
15
14
  if (!verifyBearerToken(req, options.token, options)) {
@@ -1,7 +1,7 @@
1
1
  import { type RouteContext } from "./common.js";
2
2
  /**
3
3
  * 处理系统自省与包信息接口:
4
- * - GET /api/v2/info 与 GET /info -> 委托 target.info()
5
- * - GET /api/v2/packages 与 GET /packages -> 委托 host.info() 或 target.info()
4
+ * - GET /api/v2/info 与 GET /info -> 委托 service.info()
5
+ * - GET /api/v2/packages 与 GET /packages -> 委托 service.discovery.listPackages()
6
6
  */
7
7
  export declare function handleInfoRoute(ctx: RouteContext): Promise<Response | null>;
@@ -1,5 +1,5 @@
1
1
  import { filterWithFallbackInfo } from "../../filter/index.js";
2
- import { PACKAGE_NOT_FOUND } from "../../errors.js";
2
+ import { INFO_ERROR, PACKAGE_NOT_ALLOWED, PACKAGE_NOT_FOUND, PACKAGES_INFO_ERROR } from "../../errors.js";
3
3
  import { ACTIONDOCK_VERSION } from "../../version.js";
4
4
  import { sanitizeConfigDefinitions } from "../../storage/index.js";
5
5
  import { assertPackageAllowed, getSubPath, jsonResponse } from "./common.js";
@@ -18,11 +18,11 @@ function sanitizePackage(pkg, exposeDebugInfo) {
18
18
  }
19
19
  /**
20
20
  * 处理系统自省与包信息接口:
21
- * - GET /api/v2/info 与 GET /info -> 委托 target.info()
22
- * - GET /api/v2/packages 与 GET /packages -> 委托 host.info() 或 target.info()
21
+ * - GET /api/v2/info 与 GET /info -> 委托 service.info()
22
+ * - GET /api/v2/packages 与 GET /packages -> 委托 service.discovery.listPackages()
23
23
  */
24
24
  export async function handleInfoRoute(ctx) {
25
- const { req, url, pathname, corsHeaders, options, target, host, projectRoot } = ctx;
25
+ const { req, url, pathname, corsHeaders, options, service, projectRoot } = ctx;
26
26
  const subpath = getSubPath(pathname);
27
27
  // 1. Packages List: GET /api/v2/packages, /packages
28
28
  if ((subpath === "/packages" || pathname === "/api/v2/packages" || pathname === "/packages") && req.method === "GET") {
@@ -31,7 +31,7 @@ export async function handleInfoRoute(ctx) {
31
31
  if (targetPkg) {
32
32
  assertPackageAllowed(targetPkg, options);
33
33
  }
34
- const rawPackages = target ? await target.listPackages() : (host ? await host.info() : []);
34
+ const rawPackages = await service.discovery.listPackages();
35
35
  let packages = rawPackages.map((p) => sanitizePackage(p, options.exposeDebugInfo));
36
36
  if (options.packageAllowlist && Array.isArray(options.packageAllowlist) && options.packageAllowlist.length > 0) {
37
37
  packages = packages.filter((p) => p.id && options.packageAllowlist.includes(p.id));
@@ -42,18 +42,18 @@ export async function handleInfoRoute(ctx) {
42
42
  }, 200, corsHeaders);
43
43
  }
44
44
  catch (err) {
45
- if (err.code === "PACKAGE_NOT_ALLOWED" || err.status === 403) {
45
+ if (err.code === PACKAGE_NOT_ALLOWED || err.status === 403) {
46
46
  return jsonResponse({
47
47
  ok: false,
48
48
  error: {
49
- code: "PACKAGE_NOT_ALLOWED",
49
+ code: PACKAGE_NOT_ALLOWED,
50
50
  message: err.message || "Package is not in the allowed package list",
51
51
  },
52
52
  }, 403, corsHeaders);
53
53
  }
54
54
  return jsonResponse({
55
55
  ok: false,
56
- error: { code: "PACKAGES_INFO_ERROR", message: err.message },
56
+ error: { code: PACKAGES_INFO_ERROR, message: err.message },
57
57
  }, 500, corsHeaders);
58
58
  }
59
59
  }
@@ -66,8 +66,7 @@ export async function handleInfoRoute(ctx) {
66
66
  if (targetPkg) {
67
67
  assertPackageAllowed(targetPkg, options);
68
68
  }
69
- const targetInfo = await target.info();
70
- const rawPackages = targetInfo.packages || [];
69
+ const rawPackages = await service.info();
71
70
  let packages = rawPackages.map((p) => sanitizePackage(p, options.exposeDebugInfo));
72
71
  if (options.packageAllowlist && Array.isArray(options.packageAllowlist) && options.packageAllowlist.length > 0) {
73
72
  packages = packages.filter((p) => p.id && options.packageAllowlist.includes(p.id));
@@ -139,18 +138,18 @@ export async function handleInfoRoute(ctx) {
139
138
  }, 200, corsHeaders);
140
139
  }
141
140
  catch (err) {
142
- if (err.code === "PACKAGE_NOT_ALLOWED" || err.status === 403) {
141
+ if (err.code === PACKAGE_NOT_ALLOWED || err.status === 403) {
143
142
  return jsonResponse({
144
143
  ok: false,
145
144
  error: {
146
- code: "PACKAGE_NOT_ALLOWED",
145
+ code: PACKAGE_NOT_ALLOWED,
147
146
  message: err.message || "Package is not in the allowed package list",
148
147
  },
149
148
  }, 403, corsHeaders);
150
149
  }
151
150
  return jsonResponse({
152
151
  ok: false,
153
- error: { code: "INFO_ERROR", message: err.message },
152
+ error: { code: INFO_ERROR, message: err.message },
154
153
  }, 500, corsHeaders);
155
154
  }
156
155
  }
@@ -1,10 +1,11 @@
1
1
  import { filterByIntent } from "../../filter/index.js";
2
+ import { PACKAGE_NOT_ALLOWED, PLAYBOOK_NOT_FOUND, PLAYBOOKS_LIST_ERROR } from "../../errors.js";
2
3
  import { assertPackageAllowed, getSubPath, jsonResponse } from "./common.js";
3
4
  /**
4
5
  * 处理 Playbook 规程相关的 HTTP 路由(列表与 SOP 详情查询)。
5
6
  */
6
7
  export async function handlePlaybooksRoutes(ctx) {
7
- const { req, url, pathname, corsHeaders, target, host, options } = ctx;
8
+ const { req, url, pathname, corsHeaders, service, options } = ctx;
8
9
  const subpath = getSubPath(pathname);
9
10
  // 1. Playbooks List: GET /api/v2/playbooks, GET /playbooks
10
11
  if (subpath === "/playbooks" && req.method === "GET") {
@@ -14,7 +15,7 @@ export async function handlePlaybooksRoutes(ctx) {
14
15
  if (targetPkg) {
15
16
  assertPackageAllowed(targetPkg, options);
16
17
  }
17
- let pbs = await target.listPlaybooks({ intent, package: targetPkg });
18
+ let pbs = await service.discovery.listPlaybooks({ intent, package: targetPkg });
18
19
  if (targetPkg) {
19
20
  pbs = pbs.filter((p) => p.packageId === targetPkg);
20
21
  }
@@ -27,16 +28,16 @@ export async function handlePlaybooksRoutes(ctx) {
27
28
  return jsonResponse(pbs, 200, corsHeaders);
28
29
  }
29
30
  catch (err) {
30
- if (err.code === "PACKAGE_NOT_ALLOWED" || err.status === 403) {
31
+ if (err.code === PACKAGE_NOT_ALLOWED || err.status === 403) {
31
32
  return jsonResponse({
32
33
  ok: false,
33
34
  error: {
34
- code: "PACKAGE_NOT_ALLOWED",
35
+ code: PACKAGE_NOT_ALLOWED,
35
36
  message: err.message || "Package is not in the allowed package list",
36
37
  },
37
38
  }, 403, corsHeaders);
38
39
  }
39
- return jsonResponse({ ok: false, error: { code: "PLAYBOOKS_LIST_ERROR", message: err.message } }, 500, corsHeaders);
40
+ return jsonResponse({ ok: false, error: { code: PLAYBOOKS_LIST_ERROR, message: err.message } }, 500, corsHeaders);
40
41
  }
41
42
  }
42
43
  // 2. Multi-package Playbook Show: GET /api/v2/packages/:packageId/playbooks/:playbookId
@@ -51,21 +52,21 @@ export async function handlePlaybooksRoutes(ctx) {
51
52
  return jsonResponse({
52
53
  ok: false,
53
54
  error: {
54
- code: "PACKAGE_NOT_ALLOWED",
55
+ code: PACKAGE_NOT_ALLOWED,
55
56
  message: err.message || `Package '${packageId}' is not in the allowed package list`,
56
57
  },
57
58
  }, 403, corsHeaders);
58
59
  }
59
60
  const ref = `${packageId}/${playbookId}`;
60
61
  try {
61
- const pb = await target.describePlaybook(ref);
62
+ const pb = await service.discovery.describePlaybook(ref);
62
63
  return jsonResponse(pb, 200, corsHeaders);
63
64
  }
64
65
  catch (err) {
65
66
  return jsonResponse({
66
67
  ok: false,
67
68
  error: {
68
- code: "PLAYBOOK_NOT_FOUND",
69
+ code: PLAYBOOK_NOT_FOUND,
69
70
  message: err.message || `Playbook '${playbookId}' not found in package '${packageId}'`,
70
71
  },
71
72
  }, 404, corsHeaders);
@@ -84,31 +85,17 @@ export async function handlePlaybooksRoutes(ctx) {
84
85
  return jsonResponse({
85
86
  ok: false,
86
87
  error: {
87
- code: "PACKAGE_NOT_ALLOWED",
88
+ code: PACKAGE_NOT_ALLOWED,
88
89
  message: err.message || `Package '${pkgFromRef}' is not in the allowed package list`,
89
90
  },
90
91
  }, 403, corsHeaders);
91
92
  }
92
93
  }
93
94
  try {
94
- const pb = await target.describePlaybook(playbookId);
95
- const unwrapped = target.unwrap?.();
96
- let pkgId = pb.packageId || (unwrapped && "packageId" in unwrapped ? unwrapped.packageId : undefined);
97
- if (!pkgId && host) {
98
- for (const app of host.listApps()) {
99
- try {
100
- const map = app.getStaticPlaybookMap?.();
101
- const cleanId = playbookId.replace(/\.md$/, "");
102
- if (map?.has(cleanId) || map?.has(playbookId)) {
103
- pkgId = app.packageId;
104
- break;
105
- }
106
- }
107
- catch { }
108
- }
109
- }
95
+ const pb = await service.discovery.describePlaybook(playbookId);
96
+ let pkgId = pb.packageId;
110
97
  if (!pkgId) {
111
- const allPbs = await target.listPlaybooks().catch(() => []);
98
+ const allPbs = await service.discovery.listPlaybooks().catch(() => []);
112
99
  const matched = allPbs.find((p) => p.id === playbookId || p.id.endsWith(`/${playbookId}`));
113
100
  if (matched?.packageId) {
114
101
  pkgId = matched.packageId;
@@ -118,16 +105,16 @@ export async function handlePlaybooksRoutes(ctx) {
118
105
  return jsonResponse(pb, 200, corsHeaders);
119
106
  }
120
107
  catch (err) {
121
- if (err.code === "PACKAGE_NOT_ALLOWED" || err.status === 403) {
108
+ if (err.code === PACKAGE_NOT_ALLOWED || err.status === 403) {
122
109
  return jsonResponse({
123
110
  ok: false,
124
111
  error: {
125
- code: "PACKAGE_NOT_ALLOWED",
112
+ code: PACKAGE_NOT_ALLOWED,
126
113
  message: err.message || "Package is not in the allowed package list",
127
114
  },
128
115
  }, 403, corsHeaders);
129
116
  }
130
- return jsonResponse({ ok: false, error: { code: "PLAYBOOK_NOT_FOUND", message: err.message } }, 404, corsHeaders);
117
+ return jsonResponse({ ok: false, error: { code: PLAYBOOK_NOT_FOUND, message: err.message } }, 404, corsHeaders);
131
118
  }
132
119
  }
133
120
  return null;