@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,349 +0,0 @@
1
- import { createGlobalStorage, isSecretConfigKey } from "../storage/index.js";
2
- import { ACTIONDOCK_PROTOCOL_VERSION, TargetError, CloseTimeoutError, TARGET_CAPABILITY_UNAVAILABLE, } from "./types.js";
3
- /**
4
- * 本地 ActionDockTarget 门面实现。
5
- * 内部包装 ActionDockHost 或 ActionDockApp,将统一调用直接转交给 Host 或 App。
6
- */
7
- export class LocalActionDockTarget {
8
- target;
9
- constructor(target) {
10
- this.target = target;
11
- }
12
- unwrap() {
13
- return this.target;
14
- }
15
- async info() {
16
- const packages = await this.listPackages();
17
- let id = "local-host";
18
- let name = "Local Host";
19
- if ("listApps" in this.target) {
20
- id = this.target.id || "local-host";
21
- name = this.target.name || "Local Host";
22
- }
23
- else {
24
- id = this.target.packageId;
25
- name = packages[0]?.name || this.target.packageId;
26
- }
27
- return {
28
- id,
29
- name,
30
- protocolVersion: ACTIONDOCK_PROTOCOL_VERSION,
31
- packages,
32
- capabilities: [
33
- "actions",
34
- "playbooks",
35
- "runs",
36
- "events",
37
- "management.config",
38
- "management.state",
39
- ],
40
- idempotencyPolicy: {
41
- retentionMs: 86400000,
42
- header: "x-request-id",
43
- },
44
- };
45
- }
46
- async listPackages() {
47
- if ("listApps" in this.target) {
48
- const apps = this.target.listApps();
49
- return Promise.all(apps.map((app) => app.info()));
50
- }
51
- else {
52
- return [await this.target.info()];
53
- }
54
- }
55
- async listActions(options) {
56
- return this.target.listActions(options);
57
- }
58
- async describeAction(ref) {
59
- if ("getApp" in this.target) {
60
- return this.target.describeAction(ref);
61
- }
62
- else {
63
- const actionId = typeof ref === "string" ? ref : ref.actionId;
64
- return this.target.describeAction(actionId);
65
- }
66
- }
67
- async listPlaybooks() {
68
- return this.target.listPlaybooks();
69
- }
70
- async describePlaybook(id) {
71
- return this.target.describePlaybook(id);
72
- }
73
- async runAction(ref, input, options) {
74
- if ("listApps" in this.target) {
75
- return this.target.runAction(ref, input, options);
76
- }
77
- const actionId = typeof ref === "string" ? (ref.includes(":") ? ref.split(":").pop() : ref) : ref.actionId;
78
- return this.target.runAction(actionId, input, options);
79
- }
80
- async startAction(ref, input, options) {
81
- if ("listApps" in this.target) {
82
- return this.target.startAction(ref, input, options);
83
- }
84
- const actionId = typeof ref === "string" ? (ref.includes(":") ? ref.split(":").pop() : ref) : ref.actionId;
85
- return this.target.startAction(actionId, input, options);
86
- }
87
- async listRuns(options) {
88
- if ("listApps" in this.target) {
89
- const apps = options?.packageId
90
- ? [this.target.getApp(options.packageId)].filter(Boolean)
91
- : this.target.listApps();
92
- const records = [];
93
- for (const app of apps) {
94
- // 状态过滤下推到存储层 SQL,避免先分页后过滤导致某包前 N 条非目标状态时贡献 0 条
95
- const recs = app.storage.listRuns({
96
- actionId: options?.actionId,
97
- status: options?.status,
98
- limit: options?.limit,
99
- });
100
- for (const r of recs) {
101
- records.push({
102
- ...r,
103
- packageId: r.packageId || app.packageId,
104
- });
105
- }
106
- }
107
- records.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());
108
- // 全局 limit 语义:合并后总条数不超过 limit,单处截断
109
- if (options?.limit && records.length > options.limit) {
110
- records.length = options.limit;
111
- }
112
- return records;
113
- }
114
- else {
115
- if (options?.packageId && options.packageId !== this.target.packageId) {
116
- return [];
117
- }
118
- // 状态过滤下推到存储层 SQL,单包场景由数据库直接返回目标状态记录
119
- return this.target.storage.listRuns({
120
- actionId: options?.actionId,
121
- status: options?.status,
122
- limit: options?.limit,
123
- });
124
- }
125
- }
126
- async clearRuns(options) {
127
- if ("listApps" in this.target) {
128
- const apps = options?.packageId
129
- ? [this.target.getApp(options.packageId)].filter(Boolean)
130
- : this.target.listApps();
131
- let total = 0;
132
- for (const app of apps) {
133
- total += app.storage.clearRuns({
134
- actionId: options?.actionId,
135
- status: options?.status,
136
- });
137
- }
138
- return total;
139
- }
140
- else {
141
- if (options?.packageId && options.packageId !== this.target.packageId) {
142
- return 0;
143
- }
144
- return this.target.storage.clearRuns({
145
- actionId: options?.actionId,
146
- status: options?.status,
147
- });
148
- }
149
- }
150
- async getRun(runId) {
151
- return this.target.getRun(runId);
152
- }
153
- async cancelRun(runId, reason) {
154
- return this.target.cancelRun(runId, reason);
155
- }
156
- events(runId, options) {
157
- return this.target.events(runId, options);
158
- }
159
- resolveApp(packageId) {
160
- if ("listApps" in this.target) {
161
- if (packageId) {
162
- return this.target.getApp(packageId);
163
- }
164
- const apps = this.target.listApps();
165
- return apps.length === 1 ? apps[0] : undefined;
166
- }
167
- else {
168
- if (!packageId || packageId === this.target.packageId) {
169
- return this.target;
170
- }
171
- return undefined;
172
- }
173
- }
174
- fallbackGlobalStorage;
175
- getGlobalStorage() {
176
- if ("globalStorage" in this.target && this.target.globalStorage) {
177
- return this.target.globalStorage;
178
- }
179
- const apps = "listApps" in this.target ? this.target.listApps() : [];
180
- for (const app of apps) {
181
- if (app.globalStorage)
182
- return app.globalStorage;
183
- }
184
- if (!this.fallbackGlobalStorage) {
185
- this.fallbackGlobalStorage = createGlobalStorage({
186
- dataDir: this.target.options?.dataDir,
187
- customHome: this.target.options?.customHome,
188
- });
189
- }
190
- return this.fallbackGlobalStorage;
191
- }
192
- findDeclaredConfigItem(key) {
193
- if ("listApps" in this.target) {
194
- let foundItem;
195
- for (const app of this.target.listApps()) {
196
- const item = app.projectConfig?.config?.[key];
197
- if (item) {
198
- if (item.secret)
199
- return item;
200
- foundItem = item;
201
- }
202
- }
203
- return foundItem;
204
- }
205
- else if ("projectConfig" in this.target) {
206
- return this.target.projectConfig?.config?.[key];
207
- }
208
- return undefined;
209
- }
210
- async getConfig(packageId, key) {
211
- if (packageId === "global") {
212
- const globalStorage = this.getGlobalStorage();
213
- const val = globalStorage.getConfig(key);
214
- const configured = val !== undefined;
215
- const declaredItem = this.findDeclaredConfigItem(key);
216
- const isSecret = isSecretConfigKey(key, declaredItem);
217
- return {
218
- key,
219
- configured,
220
- secret: isSecret,
221
- source: configured ? "global" : "default",
222
- value: !isSecret && configured ? val : undefined,
223
- };
224
- }
225
- const app = this.resolveApp(packageId);
226
- if (!app) {
227
- throw new Error(`Package '${packageId}' not found in target`);
228
- }
229
- return app.getConfig(key);
230
- }
231
- async setConfig(packageId, key, value) {
232
- if (packageId === "global") {
233
- await this.getGlobalStorage().setConfig(key, value);
234
- return;
235
- }
236
- const app = this.resolveApp(packageId);
237
- if (!app) {
238
- throw new Error(`Package '${packageId}' not found in target`);
239
- }
240
- await app.setConfig(key, value);
241
- }
242
- async deleteConfig(packageId, key) {
243
- if (packageId === "global") {
244
- return await this.getGlobalStorage().deleteConfig(key);
245
- }
246
- const app = this.resolveApp(packageId);
247
- if (!app) {
248
- throw new Error(`Package '${packageId}' not found in target`);
249
- }
250
- return await app.deleteConfig(key);
251
- }
252
- async listConfig(packageId) {
253
- if (packageId === "global") {
254
- const globalStorage = this.getGlobalStorage();
255
- const all = globalStorage.listConfig();
256
- return Object.entries(all).map(([key, val]) => {
257
- const declaredItem = this.findDeclaredConfigItem(key);
258
- const isSecret = isSecretConfigKey(key, declaredItem);
259
- return {
260
- key,
261
- configured: true,
262
- secret: isSecret,
263
- source: "global",
264
- value: isSecret ? undefined : val,
265
- };
266
- });
267
- }
268
- const app = this.resolveApp(packageId);
269
- if (!app) {
270
- throw new Error(`Package '${packageId}' not found in target`);
271
- }
272
- return app.listConfig();
273
- }
274
- async getState(packageId, actionId, key, options) {
275
- const app = this.resolveApp(packageId);
276
- if (!app) {
277
- throw new Error(`Package '${packageId}' not found in target`);
278
- }
279
- return app.getState(actionId, key, options);
280
- }
281
- async setState(packageId, actionId, key, value, options) {
282
- const app = this.resolveApp(packageId);
283
- if (!app) {
284
- throw new Error(`Package '${packageId}' not found in target`);
285
- }
286
- if (actionId) {
287
- await app.setActionState(actionId, key, value, options);
288
- }
289
- else {
290
- await app.setState(key, value, options);
291
- }
292
- }
293
- async deleteState(packageId, actionId, key, options) {
294
- const app = this.resolveApp(packageId);
295
- if (!app) {
296
- throw new Error(`Package '${packageId}' not found in target`);
297
- }
298
- return app.deleteState(actionId, key, options);
299
- }
300
- async listStateKeys(packageId, actionId, options) {
301
- const app = this.resolveApp(packageId);
302
- if (!app) {
303
- throw new Error(`Package '${packageId}' not found in target`);
304
- }
305
- return app.listStateKeys(actionId, options);
306
- }
307
- async clearState(packageId, actionId, options) {
308
- const app = this.resolveApp(packageId);
309
- if (!app) {
310
- throw new Error(`Package '${packageId}' not found in target`);
311
- }
312
- return app.clearState(actionId, options);
313
- }
314
- async listStateEntries(packageId, options) {
315
- const app = this.resolveApp(packageId);
316
- if (!app) {
317
- throw new TargetError(TARGET_CAPABILITY_UNAVAILABLE, `TARGET_CAPABILITY_UNAVAILABLE: Package '${packageId}' not found in target`);
318
- }
319
- if (!app.storage || typeof app.storage.listStateEntries !== "function") {
320
- throw new TargetError(TARGET_CAPABILITY_UNAVAILABLE, `TARGET_CAPABILITY_UNAVAILABLE: listStateEntries is not supported by package '${packageId}' storage`);
321
- }
322
- return app.storage.listStateEntries(options);
323
- }
324
- async close(options) {
325
- try {
326
- this.fallbackGlobalStorage?.close();
327
- }
328
- catch {
329
- // 忽略兜底全局存储关闭异常
330
- }
331
- this.fallbackGlobalStorage = undefined;
332
- if (options?.timeoutMs && options.timeoutMs > 0) {
333
- let timer;
334
- const timeoutPromise = new Promise((_, reject) => {
335
- timer = setTimeout(() => {
336
- reject(new CloseTimeoutError(`Target close operation timed out after ${options.timeoutMs}ms`));
337
- }, options.timeoutMs);
338
- });
339
- try {
340
- await Promise.race([this.target.close(), timeoutPromise]);
341
- }
342
- finally {
343
- clearTimeout(timer);
344
- }
345
- return;
346
- }
347
- return this.target.close();
348
- }
349
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * 远端通信错误翻译层。
3
- *
4
- * 职责单一:将 profile/client 传输层抛出的底层异常翻译为统一的
5
- * TargetError 结构化异常,供 RemoteActionDockTarget 各操作边界复用;
6
- * 优先读取传输层透传的结构化错误码,无法识别时原样透传。
7
- */
8
- import { STATE_KEY_NOT_FOUND } from "../errors.js";
9
- import { TARGET_CAPABILITY_UNAVAILABLE, TARGET_PROTOCOL_UNSUPPORTED, TARGET_RESULT_UNKNOWN, TargetError, } from "./types.js";
10
- /**
11
- * 将远端通信异常包装翻译为统一的 TargetError。
12
- *
13
- * 无法识别的异常按防御与透明原则原样抛出,严禁静默吞没。
14
- */
15
- export function wrapRemoteError(err) {
16
- const msg = String(err?.message || "");
17
- const code = err?.code || "";
18
- if (code === "CAPABILITY_UNAVAILABLE" ||
19
- code === "TARGET_CAPABILITY_UNAVAILABLE" ||
20
- msg.includes("CAPABILITY_UNAVAILABLE") ||
21
- msg.includes("TARGET_CAPABILITY_UNAVAILABLE") ||
22
- msg.includes("Management APIs are not enabled")) {
23
- throw new TargetError(TARGET_CAPABILITY_UNAVAILABLE, `TARGET_CAPABILITY_UNAVAILABLE: Management APIs are not enabled on remote target`, { originalMessage: msg });
24
- }
25
- if (code === "PROTOCOL_UNSUPPORTED" ||
26
- code === "TARGET_PROTOCOL_UNSUPPORTED" ||
27
- msg.includes("PROTOCOL_UNSUPPORTED") ||
28
- msg.includes("TARGET_PROTOCOL_UNSUPPORTED")) {
29
- throw new TargetError(TARGET_PROTOCOL_UNSUPPORTED, `TARGET_PROTOCOL_UNSUPPORTED: ${msg}`, { originalMessage: msg });
30
- }
31
- if (code === "TARGET_RESULT_UNKNOWN" ||
32
- code === "RESULT_UNKNOWN" ||
33
- msg.includes("TARGET_RESULT_UNKNOWN")) {
34
- throw new TargetError(TARGET_RESULT_UNKNOWN, `TARGET_RESULT_UNKNOWN: ${msg}`, { originalMessage: msg });
35
- }
36
- throw err;
37
- }
38
- /**
39
- * 判定远端状态键访问异常是否为键不存在。
40
- *
41
- * 优先读取传输层透传的结构化错误码(fetchRemoteJson 会将响应体 error.code
42
- * 附加到抛出异常的 code 字段),仅当旧版服务器未透传 code 时回退到
43
- * HTTP 状态与消息文本兼容嗅探。
44
- */
45
- export function isRemoteStateKeyNotFound(err) {
46
- if (err?.code === STATE_KEY_NOT_FOUND) {
47
- return true;
48
- }
49
- const msg = String(err?.message || "");
50
- return err?.status === 404 || msg.includes("404") || msg.includes("not found");
51
- }
@@ -1,86 +0,0 @@
1
- import type { ActionRef, ExecutionEvent, ExecutionResult, JsonValue, RunRecord } from "@actiondock/sdk";
2
- import type { ActionSpec, ActionSummary, ListActionsOptions, PackageInfo, PlaybookSpec, PlaybookSummary } from "../app/types.js";
3
- import type { CancelResult, ExecuteOptions, ExecutionTicket } from "../execution/types.js";
4
- import { type StateEntry } from "../storage/types.js";
5
- import { type ActionDockTarget, type ConfigValueView, type ListRunsOptions, type RemoteTargetOptions, type StateScopeOptions, type TargetInfo } from "./types.js";
6
- /**
7
- * 读取并解析远端 SSE 事件流。
8
- *
9
- * 候选路由依次尝试:v2 /events -> v2 /stream -> v1 /stream;
10
- * 全部候选均不可用(网络异常或非流式响应)时抛出携带各候选 URL 与
11
- * 失败原因的 REMOTE_STREAM_UNAVAILABLE 聚合错误,严禁以空流伪装正常。
12
- */
13
- export declare function streamRemoteEvents(serverUrl: string, runId: string, token?: string, options?: {
14
- after?: number | string;
15
- signal?: AbortSignal;
16
- maxQueueSize?: number;
17
- allowInsecureHttp?: boolean;
18
- insecure?: boolean;
19
- dispatcher?: unknown;
20
- }): AsyncIterable<ExecutionEvent>;
21
- /**
22
- * 远程 ActionDockTarget 门面实现。
23
- * 内部封装基于 HTTP/SSE 协议与远端 ActionDock 服务端的通信管道。
24
- */
25
- export declare class RemoteActionDockTarget implements ActionDockTarget {
26
- readonly serverUrl: string;
27
- readonly token?: string;
28
- readonly timeoutMs?: number;
29
- readonly baseTimeoutMs: number;
30
- readonly allowInsecureHttp?: boolean;
31
- readonly insecure?: boolean;
32
- readonly dispatcher?: unknown;
33
- private isClosed;
34
- constructor(options: RemoteTargetOptions);
35
- private assertNotClosed;
36
- info(): Promise<TargetInfo>;
37
- listPackages(): Promise<PackageInfo[]>;
38
- listActions(options?: ListActionsOptions): Promise<ActionSummary[]>;
39
- describeAction(ref: ActionRef | string): Promise<ActionSpec>;
40
- listPlaybooks(options?: {
41
- intent?: string;
42
- package?: string;
43
- }): Promise<PlaybookSummary[]>;
44
- describePlaybook(id: string): Promise<PlaybookSpec>;
45
- runAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionResult>;
46
- startAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionTicket>;
47
- /**
48
- * 等待远端运行抵达终态:优先监听 SSE 事件流,失败后按指数退避轮询运行详情。
49
- *
50
- * @param runId 运行标识
51
- * @param signal 外部取消信号
52
- * @param timeoutMs 运行自身声明的超时(等待上限取该值与默认上限中的较大者)
53
- */
54
- private waitForRunCompletion;
55
- /**
56
- * 指数退避轮询远端运行详情直至终态、取消或超时上限。
57
- */
58
- private pollRunCompletion;
59
- private formatTerminalRunResult;
60
- listRuns(options?: ListRunsOptions): Promise<RunRecord[]>;
61
- clearRuns(options?: {
62
- packageId?: string;
63
- actionId?: string;
64
- status?: string;
65
- }): Promise<number>;
66
- getRun(runId: string): Promise<RunRecord | undefined>;
67
- cancelRun(runId: string, reason?: string): Promise<CancelResult>;
68
- events(runId: string, options?: {
69
- after?: number | string;
70
- signal?: AbortSignal;
71
- maxQueueSize?: number;
72
- }): AsyncIterable<ExecutionEvent>;
73
- getConfig(packageId: string, key: string): Promise<ConfigValueView>;
74
- setConfig(packageId: string, key: string, value: JsonValue): Promise<void>;
75
- deleteConfig(packageId: string, key: string): Promise<boolean>;
76
- listConfig(packageId: string): Promise<ConfigValueView[]>;
77
- getState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<T | undefined>;
78
- setState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, value: T, options?: StateScopeOptions): Promise<void>;
79
- deleteState(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<boolean>;
80
- listStateKeys(packageId: string, actionId: string, options?: StateScopeOptions): Promise<string[]>;
81
- clearState(packageId: string, actionId: string, options?: StateScopeOptions): Promise<number>;
82
- listStateEntries(packageId: string, options?: any): Promise<StateEntry[]>;
83
- close(_options?: {
84
- timeoutMs?: number;
85
- }): Promise<void>;
86
- }