@mininglamp-oss/octo-runtime 1.1.3 → 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.
- package/README.md +62 -38
- package/apps/cli/README.md +58 -22
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/cli-entrypoint.d.ts +2 -0
- package/apps/cli/dist/cli-entrypoint.js +16 -0
- package/apps/cli/dist/command-tree.d.ts +20 -0
- package/apps/cli/dist/command-tree.js +402 -0
- package/apps/cli/dist/extra-command-config.d.ts +4 -0
- package/apps/cli/dist/extra-command-config.js +50 -0
- package/apps/cli/dist/extra-commands.d.ts +15 -0
- package/apps/cli/dist/extra-commands.js +275 -0
- package/apps/cli/dist/extras.js +14 -2
- package/apps/cli/dist/global-extras.d.ts +16 -0
- package/apps/cli/dist/global-extras.js +201 -0
- package/apps/cli/dist/help.d.ts +4 -1
- package/apps/cli/dist/help.js +31 -75
- package/apps/cli/dist/main.d.ts +2 -0
- package/apps/cli/dist/main.js +53 -63
- package/apps/cli/dist/manifest.json +53 -3
- package/apps/cli/dist/module-manifest.d.ts +1 -1
- package/apps/cli/dist/module-manifest.js +3 -2
- package/apps/cli/dist/openclaw.js +32 -8
- package/apps/cli/dist/output.js +16 -2
- package/apps/cli/dist/playboard.d.ts +5 -0
- package/apps/cli/dist/playboard.js +41 -13
- package/apps/cli/dist/service-control.js +2 -2
- package/apps/cli/dist/state.js +48 -19
- package/dist/public/channel-gateway-commands.d.ts +1 -0
- package/dist/public/channel-gateway-commands.js +1 -0
- package/dist/public/channel-wecom-commands.d.ts +1 -0
- package/dist/public/channel-wecom-commands.js +1 -0
- package/dist/public/dsh.d.ts +2 -0
- package/dist/public/dsh.js +1 -0
- package/dist/public/executor-kernel.d.ts +1 -1
- package/dist/public/executor-kernel.js +1 -1
- package/dist/public/extra.d.ts +1 -0
- package/dist/public/extra.js +1 -0
- package/dist/public/host.d.ts +2 -4
- package/dist/public/host.js +1 -2
- package/dist/public/webui-commands.d.ts +1 -0
- package/dist/public/webui-commands.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +16 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.js +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.d.ts +20 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +402 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.js +50 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.js +275 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +14 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.d.ts +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.js +201 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +31 -75
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +53 -63
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +53 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +16 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/service-control.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -19
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +25 -23
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +152 -21
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +170 -28
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.js +124 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +19 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +44 -13
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +44 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +18 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +10 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.js +128 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +9 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.js +51 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +7 -3
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.d.ts +70 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.js +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -3
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +1 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +8 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/node_modules/commander/LICENSE +22 -0
- package/node_modules/commander/Readme.md +1172 -0
- package/node_modules/commander/index.js +21 -0
- package/node_modules/commander/lib/argument.js +147 -0
- package/node_modules/commander/lib/command.js +2790 -0
- package/node_modules/commander/lib/error.js +36 -0
- package/node_modules/commander/lib/help.js +731 -0
- package/node_modules/commander/lib/option.js +377 -0
- package/node_modules/commander/lib/suggestSimilar.js +99 -0
- package/node_modules/commander/package-support.json +19 -0
- package/node_modules/commander/package.json +64 -0
- package/node_modules/commander/typings/index.d.ts +1113 -0
- package/package.json +49 -29
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
- package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.d.ts +0 -15
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.js +0 -22
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.d.ts +0 -16
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.js +0 -160
|
@@ -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
|
-
}
|