mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:47:41 +00:00
refactor(agents): share sandboxed session tool context
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { callGateway } from "../../gateway/call.js";
|
||||
import { isAcpSessionKey, normalizeMainKey } from "../../routing/session-key.js";
|
||||
import {
|
||||
isAcpSessionKey,
|
||||
isSubagentSessionKey,
|
||||
normalizeMainKey,
|
||||
} from "../../routing/session-key.js";
|
||||
import { sanitizeUserFacingText } from "../pi-embedded-helpers.js";
|
||||
import {
|
||||
stripDowngradedToolCallText,
|
||||
@@ -69,6 +73,39 @@ export function resolveInternalSessionKey(params: { key: string; alias: string;
|
||||
return params.key;
|
||||
}
|
||||
|
||||
export function resolveSandboxSessionToolsVisibility(cfg: OpenClawConfig): "spawned" | "all" {
|
||||
return cfg.agents?.defaults?.sandbox?.sessionToolsVisibility ?? "spawned";
|
||||
}
|
||||
|
||||
export function resolveSandboxedSessionToolContext(params: {
|
||||
cfg: OpenClawConfig;
|
||||
agentSessionKey?: string;
|
||||
sandboxed?: boolean;
|
||||
}): {
|
||||
mainKey: string;
|
||||
alias: string;
|
||||
visibility: "spawned" | "all";
|
||||
requesterInternalKey: string | undefined;
|
||||
restrictToSpawned: boolean;
|
||||
} {
|
||||
const { mainKey, alias } = resolveMainSessionAlias(params.cfg);
|
||||
const visibility = resolveSandboxSessionToolsVisibility(params.cfg);
|
||||
const requesterInternalKey =
|
||||
typeof params.agentSessionKey === "string" && params.agentSessionKey.trim()
|
||||
? resolveInternalSessionKey({
|
||||
key: params.agentSessionKey,
|
||||
alias,
|
||||
mainKey,
|
||||
})
|
||||
: undefined;
|
||||
const restrictToSpawned =
|
||||
params.sandboxed === true &&
|
||||
visibility === "spawned" &&
|
||||
!!requesterInternalKey &&
|
||||
!isSubagentSessionKey(requesterInternalKey);
|
||||
return { mainKey, alias, visibility, requesterInternalKey, restrictToSpawned };
|
||||
}
|
||||
|
||||
export type AgentToAgentPolicy = {
|
||||
enabled: boolean;
|
||||
matchesAllow: (agentId: string) => boolean;
|
||||
|
||||
Reference in New Issue
Block a user