Files
openclaw/src/agents/openclaw-tools.plugin-context.ts
2026-04-05 23:57:31 +01:00

70 lines
2.3 KiB
TypeScript

import type { OpenClawConfig } from "../config/config.js";
import { normalizeDeliveryContext } from "../utils/delivery-context.js";
import type { GatewayMessageChannel } from "../utils/message-channel.js";
import { resolveAgentWorkspaceDir, resolveSessionAgentId } from "./agent-scope.js";
import { resolveWorkspaceRoot } from "./workspace-dir.js";
export type OpenClawPluginToolOptions = {
agentSessionKey?: string;
agentChannel?: GatewayMessageChannel;
agentAccountId?: string;
agentTo?: string;
agentThreadId?: string | number;
agentDir?: string;
workspaceDir?: string;
config?: OpenClawConfig;
requesterSenderId?: string | null;
senderIsOwner?: boolean;
sessionId?: string;
sandboxBrowserBridgeUrl?: string;
allowHostBrowserControl?: boolean;
sandboxed?: boolean;
allowGatewaySubagentBinding?: boolean;
};
export function resolveOpenClawPluginToolInputs(params: {
options?: OpenClawPluginToolOptions;
resolvedConfig?: OpenClawConfig;
runtimeConfig?: OpenClawConfig;
}) {
const { options, resolvedConfig, runtimeConfig } = params;
const sessionAgentId = resolveSessionAgentId({
sessionKey: options?.agentSessionKey,
config: resolvedConfig,
});
const inferredWorkspaceDir =
options?.workspaceDir || !resolvedConfig
? undefined
: resolveAgentWorkspaceDir(resolvedConfig, sessionAgentId);
const workspaceDir = resolveWorkspaceRoot(options?.workspaceDir ?? inferredWorkspaceDir);
const deliveryContext = normalizeDeliveryContext({
channel: options?.agentChannel,
to: options?.agentTo,
accountId: options?.agentAccountId,
threadId: options?.agentThreadId,
});
return {
context: {
config: options?.config,
runtimeConfig,
workspaceDir,
agentDir: options?.agentDir,
agentId: sessionAgentId,
sessionKey: options?.agentSessionKey,
sessionId: options?.sessionId,
browser: {
sandboxBridgeUrl: options?.sandboxBrowserBridgeUrl,
allowHostControl: options?.allowHostBrowserControl,
},
messageChannel: options?.agentChannel,
agentAccountId: options?.agentAccountId,
deliveryContext,
requesterSenderId: options?.requesterSenderId ?? undefined,
senderIsOwner: options?.senderIsOwner ?? undefined,
sandboxed: options?.sandboxed,
},
allowGatewaySubagentBinding: options?.allowGatewaySubagentBinding,
};
}