mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 19:10:39 +00:00
* Gateway: resolve agent.wait for chat.send runs * Discord: harden ACP thread binding + listener timeout * ACPX: handle already-exited child wait * Gateway/Discord: address PR review findings * Discord: keep ACP error-state thread bindings on startup * gateway: make agent.wait dedupe bridge event-driven * discord: harden ACP probe classification and cap startup fan-out * discord: add cooperative timeout cancellation * discord: fix startup probe concurrency helper typing * plugin-sdk: avoid Windows root-alias shard timeout * plugin-sdk: keep root alias reflection path non-blocking * discord+gateway: resolve remaining PR review findings * gateway+discord: fix codex review regressions * Discord/Gateway: address Codex review findings * Gateway: keep agent.wait lifecycle active with shared run IDs * Discord: clean up status reactions on aborted runs * fix: add changelog note for ACP/Discord startup hardening (#33699) (thanks @dutifulbob) --------- Co-authored-by: Onur <2453968+osolmaz@users.noreply.github.com>
200 lines
5.0 KiB
JavaScript
200 lines
5.0 KiB
JavaScript
"use strict";
|
|
|
|
const path = require("node:path");
|
|
const fs = require("node:fs");
|
|
|
|
let monolithicSdk = null;
|
|
let jitiLoader = null;
|
|
|
|
function emptyPluginConfigSchema() {
|
|
function error(message) {
|
|
return { success: false, error: { issues: [{ path: [], message }] } };
|
|
}
|
|
|
|
return {
|
|
safeParse(value) {
|
|
if (value === undefined) {
|
|
return { success: true, data: undefined };
|
|
}
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return error("expected config object");
|
|
}
|
|
if (Object.keys(value).length > 0) {
|
|
return error("config must be empty");
|
|
}
|
|
return { success: true, data: value };
|
|
},
|
|
jsonSchema: {
|
|
type: "object",
|
|
additionalProperties: false,
|
|
properties: {},
|
|
},
|
|
};
|
|
}
|
|
|
|
function resolveCommandAuthorizedFromAuthorizers(params) {
|
|
const { useAccessGroups, authorizers } = params;
|
|
const mode = params.modeWhenAccessGroupsOff ?? "allow";
|
|
if (!useAccessGroups) {
|
|
if (mode === "allow") {
|
|
return true;
|
|
}
|
|
if (mode === "deny") {
|
|
return false;
|
|
}
|
|
const anyConfigured = authorizers.some((entry) => entry.configured);
|
|
if (!anyConfigured) {
|
|
return true;
|
|
}
|
|
return authorizers.some((entry) => entry.configured && entry.allowed);
|
|
}
|
|
return authorizers.some((entry) => entry.configured && entry.allowed);
|
|
}
|
|
|
|
function resolveControlCommandGate(params) {
|
|
const commandAuthorized = resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: params.useAccessGroups,
|
|
authorizers: params.authorizers,
|
|
modeWhenAccessGroupsOff: params.modeWhenAccessGroupsOff,
|
|
});
|
|
const shouldBlock = params.allowTextCommands && params.hasControlCommand && !commandAuthorized;
|
|
return { commandAuthorized, shouldBlock };
|
|
}
|
|
|
|
function getJiti() {
|
|
if (jitiLoader) {
|
|
return jitiLoader;
|
|
}
|
|
|
|
const { createJiti } = require("jiti");
|
|
jitiLoader = createJiti(__filename, {
|
|
interopDefault: true,
|
|
extensions: [".ts", ".tsx", ".mts", ".cts", ".mtsx", ".ctsx", ".js", ".mjs", ".cjs", ".json"],
|
|
});
|
|
return jitiLoader;
|
|
}
|
|
|
|
function loadMonolithicSdk() {
|
|
if (monolithicSdk) {
|
|
return monolithicSdk;
|
|
}
|
|
|
|
const jiti = getJiti();
|
|
|
|
const distCandidate = path.resolve(__dirname, "..", "..", "dist", "plugin-sdk", "index.js");
|
|
if (fs.existsSync(distCandidate)) {
|
|
try {
|
|
monolithicSdk = jiti(distCandidate);
|
|
return monolithicSdk;
|
|
} catch {
|
|
// Fall through to source alias if dist is unavailable or stale.
|
|
}
|
|
}
|
|
|
|
monolithicSdk = jiti(path.join(__dirname, "index.ts"));
|
|
return monolithicSdk;
|
|
}
|
|
|
|
function tryLoadMonolithicSdk() {
|
|
try {
|
|
return loadMonolithicSdk();
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
const fastExports = {
|
|
emptyPluginConfigSchema,
|
|
resolveControlCommandGate,
|
|
};
|
|
|
|
const rootProxy = new Proxy(fastExports, {
|
|
get(target, prop, receiver) {
|
|
if (prop === "__esModule") {
|
|
return true;
|
|
}
|
|
if (prop === "default") {
|
|
return rootProxy;
|
|
}
|
|
if (Reflect.has(target, prop)) {
|
|
return Reflect.get(target, prop, receiver);
|
|
}
|
|
return loadMonolithicSdk()[prop];
|
|
},
|
|
has(target, prop) {
|
|
if (prop === "__esModule" || prop === "default") {
|
|
return true;
|
|
}
|
|
if (Reflect.has(target, prop)) {
|
|
return true;
|
|
}
|
|
const monolithic = tryLoadMonolithicSdk();
|
|
return monolithic ? prop in monolithic : false;
|
|
},
|
|
ownKeys(target) {
|
|
const keys = new Set([...Reflect.ownKeys(target), "default", "__esModule"]);
|
|
// Keep Object.keys/property reflection fast and deterministic.
|
|
// Only expose monolithic keys if it was already loaded by direct access.
|
|
if (monolithicSdk) {
|
|
for (const key of Reflect.ownKeys(monolithicSdk)) {
|
|
keys.add(key);
|
|
}
|
|
}
|
|
return [...keys];
|
|
},
|
|
getOwnPropertyDescriptor(target, prop) {
|
|
if (prop === "__esModule") {
|
|
return {
|
|
configurable: true,
|
|
enumerable: false,
|
|
writable: false,
|
|
value: true,
|
|
};
|
|
}
|
|
if (prop === "default") {
|
|
return {
|
|
configurable: true,
|
|
enumerable: false,
|
|
writable: false,
|
|
value: rootProxy,
|
|
};
|
|
}
|
|
const own = Object.getOwnPropertyDescriptor(target, prop);
|
|
if (own) {
|
|
return own;
|
|
}
|
|
const monolithic = tryLoadMonolithicSdk();
|
|
if (!monolithic) {
|
|
return undefined;
|
|
}
|
|
const descriptor = Object.getOwnPropertyDescriptor(monolithic, prop);
|
|
if (!descriptor) {
|
|
return undefined;
|
|
}
|
|
if (descriptor.get || descriptor.set) {
|
|
return {
|
|
configurable: true,
|
|
enumerable: descriptor.enumerable ?? true,
|
|
get: descriptor.get
|
|
? function getLegacyValue() {
|
|
return descriptor.get.call(monolithic);
|
|
}
|
|
: undefined,
|
|
set: descriptor.set
|
|
? function setLegacyValue(value) {
|
|
return descriptor.set.call(monolithic, value);
|
|
}
|
|
: undefined,
|
|
};
|
|
}
|
|
return {
|
|
configurable: true,
|
|
enumerable: descriptor.enumerable ?? true,
|
|
value: descriptor.value,
|
|
writable: descriptor.writable,
|
|
};
|
|
},
|
|
});
|
|
|
|
module.exports = rootProxy;
|