@mininglamp-oss/octo-runtime 1.1.4 → 1.1.5

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 (117) hide show
  1. package/README.md +61 -37
  2. package/apps/cli/README.md +58 -22
  3. package/apps/cli/dist/build-info.json +2 -2
  4. package/apps/cli/dist/cli-entrypoint.d.ts +2 -0
  5. package/apps/cli/dist/cli-entrypoint.js +16 -0
  6. package/apps/cli/dist/command-tree.d.ts +20 -0
  7. package/apps/cli/dist/command-tree.js +402 -0
  8. package/apps/cli/dist/extra-command-config.d.ts +4 -0
  9. package/apps/cli/dist/extra-command-config.js +50 -0
  10. package/apps/cli/dist/extra-commands.d.ts +15 -0
  11. package/apps/cli/dist/extra-commands.js +275 -0
  12. package/apps/cli/dist/extras.js +14 -2
  13. package/apps/cli/dist/global-extras.d.ts +16 -0
  14. package/apps/cli/dist/global-extras.js +201 -0
  15. package/apps/cli/dist/help.d.ts +4 -1
  16. package/apps/cli/dist/help.js +31 -79
  17. package/apps/cli/dist/main.d.ts +2 -0
  18. package/apps/cli/dist/main.js +27 -63
  19. package/apps/cli/dist/manifest.json +48 -3
  20. package/apps/cli/dist/module-manifest.d.ts +1 -1
  21. package/apps/cli/dist/module-manifest.js +3 -2
  22. package/apps/cli/dist/output.js +13 -2
  23. package/apps/cli/dist/service-control.js +2 -2
  24. package/apps/cli/dist/state.js +48 -19
  25. package/dist/public/channel-gateway-commands.d.ts +1 -0
  26. package/dist/public/channel-gateway-commands.js +1 -0
  27. package/dist/public/channel-wecom-commands.d.ts +1 -0
  28. package/dist/public/channel-wecom-commands.js +1 -0
  29. package/dist/public/extra.d.ts +1 -0
  30. package/dist/public/extra.js +1 -0
  31. package/dist/public/host.d.ts +2 -4
  32. package/dist/public/host.js +1 -2
  33. package/dist/public/webui-commands.d.ts +1 -0
  34. package/dist/public/webui-commands.js +1 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +6 -0
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +16 -4
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  54. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  55. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.d.ts +2 -0
  56. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.js +16 -0
  57. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.d.ts +20 -0
  58. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +402 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.d.ts +4 -0
  60. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.js +50 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.d.ts +15 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.js +275 -0
  63. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +14 -2
  64. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.d.ts +16 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.js +201 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.d.ts +4 -1
  67. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +31 -79
  68. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
  69. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +27 -63
  70. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +48 -3
  71. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +1 -1
  72. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +3 -2
  73. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +13 -2
  74. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/service-control.js +2 -2
  75. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -19
  76. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +25 -24
  77. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  78. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  79. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  80. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +3 -3
  81. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.d.ts +4 -0
  82. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.js +124 -0
  83. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.d.ts +1 -1
  84. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -2
  85. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.d.ts +7 -0
  86. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +44 -3
  87. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +8 -5
  88. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +10 -6
  89. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.d.ts +4 -0
  90. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.js +128 -0
  91. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +9 -5
  92. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.d.ts +3 -0
  93. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.js +51 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +7 -3
  95. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.d.ts +70 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.js +16 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -3
  98. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +1 -2
  99. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +8 -4
  100. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  101. package/node_modules/commander/LICENSE +22 -0
  102. package/node_modules/commander/Readme.md +1172 -0
  103. package/node_modules/commander/index.js +21 -0
  104. package/node_modules/commander/lib/argument.js +147 -0
  105. package/node_modules/commander/lib/command.js +2790 -0
  106. package/node_modules/commander/lib/error.js +36 -0
  107. package/node_modules/commander/lib/help.js +731 -0
  108. package/node_modules/commander/lib/option.js +377 -0
  109. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  110. package/node_modules/commander/package-support.json +19 -0
  111. package/node_modules/commander/package.json +64 -0
  112. package/node_modules/commander/typings/index.d.ts +1113 -0
  113. package/package.json +41 -27
  114. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.d.ts +0 -15
  115. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.js +0 -22
  116. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.d.ts +0 -16
  117. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.js +0 -160
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Provider-neutral Agent runtime for unified execution through provider adapters",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,6 +57,18 @@
57
57
  "./protocol": {
58
58
  "types": "./dist/public/protocol.d.ts",
59
59
  "import": "./dist/public/protocol.js"
60
+ },
61
+ "./extras/channel-gateway/commands": {
62
+ "types": "./dist/public/channel-gateway-commands.d.ts",
63
+ "import": "./dist/public/channel-gateway-commands.js"
64
+ },
65
+ "./extras/channel-wecom/commands": {
66
+ "types": "./dist/public/channel-wecom-commands.d.ts",
67
+ "import": "./dist/public/channel-wecom-commands.js"
68
+ },
69
+ "./extras/webui/commands": {
70
+ "types": "./dist/public/webui-commands.d.ts",
71
+ "import": "./dist/public/webui-commands.js"
60
72
  }
61
73
  },
62
74
  "engines": {
@@ -74,31 +86,32 @@
74
86
  "access": "public"
75
87
  },
76
88
  "dependencies": {
77
- "@mininglamp-oss/octo-runtime-adapter-dsh": "1.1.4",
78
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4",
79
- "@mininglamp-oss/octo-runtime-protocol": "1.1.4",
89
+ "commander": "15.0.0",
90
+ "@mininglamp-oss/octo-runtime-adapter-dsh": "1.1.5",
91
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.5",
92
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.5",
80
93
  "import-meta-resolve": "4.2.0",
81
- "@mininglamp-oss/octo-runtime-extra-webui": "1.1.4",
82
- "@mininglamp-oss/octo-runtime-adapter-acp": "1.1.4",
83
- "@mininglamp-oss/octo-runtime-acp-client": "1.1.4",
84
- "@mininglamp-oss/octo-runtime-adapter-antigravity": "1.1.4",
85
- "@mininglamp-oss/octo-runtime-adapter-claude-code": "1.1.4",
86
- "@mininglamp-oss/octo-runtime-adapter-codebuddy": "1.1.4",
87
- "@mininglamp-oss/octo-runtime-adapter-codex": "1.1.4",
88
- "@mininglamp-oss/octo-runtime-adapter-hermes": "1.1.4",
89
- "@mininglamp-oss/octo-runtime-adapter-grok-build": "1.1.4",
90
- "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.4",
91
- "@mininglamp-oss/octo-runtime-executor-core": "1.1.4",
92
- "@mininglamp-oss/octo-runtime-adapter-kimi-code": "1.1.4",
93
- "@mininglamp-oss/octo-runtime-adapter-mcode": "1.1.4",
94
- "@mininglamp-oss/octo-runtime-adapter-openclaw": "1.1.4",
94
+ "@mininglamp-oss/octo-runtime-extra-webui": "1.1.5",
95
+ "@mininglamp-oss/octo-runtime-adapter-acp": "1.1.5",
96
+ "@mininglamp-oss/octo-runtime-acp-client": "1.1.5",
97
+ "@mininglamp-oss/octo-runtime-adapter-antigravity": "1.1.5",
98
+ "@mininglamp-oss/octo-runtime-adapter-claude-code": "1.1.5",
99
+ "@mininglamp-oss/octo-runtime-adapter-codebuddy": "1.1.5",
100
+ "@mininglamp-oss/octo-runtime-adapter-codex": "1.1.5",
101
+ "@mininglamp-oss/octo-runtime-adapter-hermes": "1.1.5",
102
+ "@mininglamp-oss/octo-runtime-adapter-grok-build": "1.1.5",
103
+ "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.5",
104
+ "@mininglamp-oss/octo-runtime-executor-core": "1.1.5",
105
+ "@mininglamp-oss/octo-runtime-adapter-kimi-code": "1.1.5",
106
+ "@mininglamp-oss/octo-runtime-adapter-mcode": "1.1.5",
107
+ "@mininglamp-oss/octo-runtime-adapter-openclaw": "1.1.5",
95
108
  "ws": "8.22.0",
96
- "@mininglamp-oss/octo-runtime-adapter-opencode": "1.1.4",
97
- "@mininglamp-oss/octo-runtime-adapter-qodercli": "1.1.4",
98
- "@mininglamp-oss/octo-runtime-adapter-qoderclicn": "1.1.4",
99
- "@mininglamp-oss/octo-runtime-adapter-zcode-gui": "1.1.4",
100
- "@mininglamp-oss/octo-runtime-extra-channel-gateway": "1.1.4",
101
- "@mininglamp-oss/octo-runtime-host-sdk": "1.1.4",
109
+ "@mininglamp-oss/octo-runtime-adapter-opencode": "1.1.5",
110
+ "@mininglamp-oss/octo-runtime-adapter-qodercli": "1.1.5",
111
+ "@mininglamp-oss/octo-runtime-adapter-qoderclicn": "1.1.5",
112
+ "@mininglamp-oss/octo-runtime-adapter-zcode-gui": "1.1.5",
113
+ "@mininglamp-oss/octo-runtime-extra-channel-gateway": "1.1.5",
114
+ "@mininglamp-oss/octo-runtime-host-sdk": "1.1.5",
102
115
  "mdast-util-from-markdown": "2.1.0",
103
116
  "@types/mdast": "4.0.4",
104
117
  "@types/unist": "3.0.3",
@@ -134,12 +147,13 @@
134
147
  "micromark-util-sanitize-uri": "2.0.1",
135
148
  "micromark-util-decode-string": "2.0.1",
136
149
  "unist-util-stringify-position": "4.0.0",
137
- "@mininglamp-oss/octo-runtime-cross-service": "1.1.4",
138
- "@mininglamp-oss/octo-runtime-extra-channel-wecom": "1.1.4",
139
- "@mininglamp-oss/octo-runtime-cli": "1.1.4",
150
+ "@mininglamp-oss/octo-runtime-cross-service": "1.1.5",
151
+ "@mininglamp-oss/octo-runtime-extra-channel-wecom": "1.1.5",
152
+ "@mininglamp-oss/octo-runtime-cli": "1.1.5",
140
153
  "json5": "2.2.3"
141
154
  },
142
155
  "bundleDependencies": [
156
+ "commander",
143
157
  "@mininglamp-oss/octo-runtime-adapter-dsh",
144
158
  "@mininglamp-oss/octo-runtime-adapter-sdk",
145
159
  "@mininglamp-oss/octo-runtime-protocol",
@@ -1,15 +0,0 @@
1
- /** Cleanup contract for explicitly configured external native executables. */
2
- export interface CleanupResult {
3
- complete: boolean;
4
- processExited: boolean;
5
- pendingResources: string[];
6
- errors: {
7
- code: string;
8
- component: string;
9
- }[];
10
- }
11
- export declare class ComponentStartError extends Error {
12
- readonly cleanup: CleanupResult;
13
- constructor(cause: unknown, cleanup: CleanupResult);
14
- }
15
- export declare function deadline<T>(operation: Promise<T>, timeoutMs: number, code: string): Promise<T>;
@@ -1,22 +0,0 @@
1
- export class ComponentStartError extends Error {
2
- cleanup;
3
- constructor(cause, cleanup) {
4
- super(cause instanceof Error ? cause.message : "COMPONENT_START_FAILED", { cause });
5
- this.cleanup = cleanup;
6
- this.name = "ComponentStartError";
7
- }
8
- }
9
- export async function deadline(operation, timeoutMs, code) {
10
- let timer;
11
- try {
12
- return await Promise.race([
13
- operation,
14
- new Promise((_, reject) => {
15
- timer = setTimeout(() => reject(new Error(code)), timeoutMs);
16
- })
17
- ]);
18
- }
19
- finally {
20
- clearTimeout(timer);
21
- }
22
- }
@@ -1,16 +0,0 @@
1
- import { type CleanupResult } from "./launch.js";
2
- export interface NativeComponentOptions {
3
- executable: string;
4
- argv: string[];
5
- cwd: string;
6
- configPath: string;
7
- endpoint: string;
8
- stop: "stdin-json" | "signal";
9
- readiness: "ipc" | "process";
10
- }
11
- /** 原生组件拥有独立进程树,参数始终按 argv 传递,不经过 shell。 */
12
- export declare function startNativeComponent(options: NativeComponentOptions): Promise<{
13
- ownership: "owned";
14
- pid: number;
15
- stop: () => Promise<CleanupResult>;
16
- }>;
@@ -1,160 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { randomUUID } from "node:crypto";
3
- import { isAbsolute } from "node:path";
4
- import { once } from "node:events";
5
- import net from "node:net";
6
- import { createProcessCleanup } from "@mininglamp-oss/octo-runtime-adapter-sdk/process-cleanup";
7
- import { readBoundedLines } from "@mininglamp-oss/octo-runtime-adapter-sdk";
8
- import { ComponentStartError, deadline } from "./launch.js";
9
- /** 原生组件拥有独立进程树,参数始终按 argv 传递,不经过 shell。 */
10
- export async function startNativeComponent(options) {
11
- for (const path of [options.executable, options.cwd, options.configPath])
12
- if (!isAbsolute(path))
13
- throw new Error("COMPONENT_PATH_INVALID");
14
- if (options.argv.some((arg) => /^--(?:config|endpoint)(?:=|$)/.test(arg)))
15
- throw new Error("COMPONENT_RESERVED_ARGUMENT");
16
- const child = spawn(options.executable, [...options.argv, "--config", options.configPath, "--endpoint", options.endpoint], {
17
- cwd: options.cwd,
18
- shell: false,
19
- stdio: ["pipe", "pipe", "ignore"],
20
- detached: process.platform !== "win32"
21
- });
22
- const cleanup = createProcessCleanup(child, {
23
- processGroup: process.platform !== "win32",
24
- processTree: true
25
- });
26
- let ack;
27
- child.stdin.on("error", () => ack?.reject(new Error("COMPONENT_INPUT_CLOSED")));
28
- child.on("error", () => ack?.reject(new Error("COMPONENT_EXITED")));
29
- child.once("exit", () => ack?.reject(new Error("COMPONENT_CLEANUP_UNCONFIRMED")));
30
- const stopInput = readBoundedLines(child.stdout, 4096, {
31
- onError: () => { },
32
- onTooLarge: () => { },
33
- onClose: () => { },
34
- onLine(line) {
35
- try {
36
- const value = JSON.parse(line);
37
- if (ack && value.type === "component.stopped" && value.request_id === ack.id) {
38
- if (value.complete === true)
39
- ack.resolve();
40
- else
41
- ack.reject(new Error("COMPONENT_CLEANUP_INCOMPLETE"));
42
- }
43
- }
44
- catch {
45
- /* 原生组件 stdout 不作诊断或业务数据来源。 */
46
- }
47
- }
48
- });
49
- let closing;
50
- const stop = () => (closing ??= (async () => {
51
- const errors = [];
52
- if (child.exitCode === null && child.signalCode === null) {
53
- try {
54
- if (options.stop === "stdin-json") {
55
- const pending = new Promise((resolve, reject) => {
56
- ack = { id: randomUUID(), resolve, reject };
57
- });
58
- void pending.catch(() => undefined);
59
- child.stdin.write(`${JSON.stringify({ type: "component.stop", request_id: ack.id })}\n`);
60
- await deadline(pending, 5000, "COMPONENT_STOP_TIMEOUT");
61
- }
62
- else {
63
- child.kill("SIGTERM");
64
- await deadline(once(child, "exit"), 5000, "COMPONENT_STOP_TIMEOUT");
65
- }
66
- }
67
- catch {
68
- errors.push({ component: options.executable, code: "COMPONENT_CLEANUP_INCOMPLETE" });
69
- }
70
- }
71
- else {
72
- errors.push({ component: options.executable, code: "COMPONENT_CLEANUP_UNCONFIRMED" });
73
- }
74
- try {
75
- await cleanup();
76
- }
77
- catch {
78
- errors.push({ component: options.executable, code: "PROCESS_CLEANUP_INCOMPLETE" });
79
- }
80
- finally {
81
- stopInput();
82
- }
83
- const processExited = child.exitCode !== null || child.signalCode !== null;
84
- return {
85
- complete: !errors.length && processExited,
86
- processExited,
87
- errors,
88
- pendingResources: errors.length ? ["native"] : []
89
- };
90
- })());
91
- try {
92
- await deadline(once(child, "spawn"), 5000, "COMPONENT_START_TIMEOUT");
93
- if (options.readiness === "ipc") {
94
- const until = Date.now() + 30_000;
95
- while (true) {
96
- if (child.exitCode !== null || child.signalCode !== null)
97
- throw new Error("COMPONENT_EXITED");
98
- try {
99
- await nativeStatus(options.endpoint, child.pid);
100
- break;
101
- }
102
- catch (error) {
103
- if (error instanceof Error && error.message === "COMPONENT_IDENTITY_MISMATCH")
104
- throw error;
105
- if (Date.now() >= until)
106
- throw new Error("COMPONENT_START_TIMEOUT", { cause: error });
107
- await new Promise((resolve) => setTimeout(resolve, 100));
108
- }
109
- }
110
- }
111
- }
112
- catch (error) {
113
- throw new ComponentStartError(error, await stop());
114
- }
115
- return { ownership: "owned", pid: child.pid, stop };
116
- }
117
- async function nativeStatus(endpoint, pid) {
118
- await new Promise((resolve, reject) => {
119
- const socket = net.createConnection(endpoint);
120
- const requestId = randomUUID();
121
- let bytes = "";
122
- socket.setTimeout(1000, () => {
123
- socket.destroy();
124
- reject(new Error("COMPONENT_UNAVAILABLE"));
125
- });
126
- socket.on("error", reject);
127
- socket.on("connect", () => socket.write(`${JSON.stringify({ jsonrpc: "2.0", id: requestId, method: "status", params: {} })}\n`));
128
- socket.on("data", (chunk) => {
129
- bytes += chunk.toString();
130
- if (bytes.length > 4096) {
131
- socket.destroy();
132
- reject(new Error("COMPONENT_STATUS_INVALID"));
133
- }
134
- if (bytes.includes("\n")) {
135
- try {
136
- const reply = JSON.parse(bytes.slice(0, bytes.indexOf("\n")));
137
- if (reply.jsonrpc !== "2.0" || reply.id !== requestId || !reply.result)
138
- throw new Error();
139
- if (typeof reply.result !== "object" ||
140
- !("pid" in reply.result) ||
141
- reply.result.pid !== pid) {
142
- socket.destroy();
143
- reject(new Error("COMPONENT_IDENTITY_MISMATCH"));
144
- return;
145
- }
146
- resolve();
147
- }
148
- catch {
149
- reject(new Error("COMPONENT_STATUS_INVALID"));
150
- }
151
- socket.destroy();
152
- }
153
- });
154
- socket.on("end", () => {
155
- if (!bytes.includes("\n"))
156
- reject(new Error("COMPONENT_UNAVAILABLE"));
157
- });
158
- socket.on("close", () => reject(new Error("COMPONENT_UNAVAILABLE")));
159
- });
160
- }