mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 12:01:07 +00:00
fix: derive plugin media trust from metadata (#86410)
This commit is contained in:
committed by
GitHub
parent
75c72360ad
commit
e761eb8f3e
@@ -1364,8 +1364,11 @@ describe("resolvePluginTools optional tools", () => {
|
||||
expectResolvedToolNames(first, ["other_tool", "optional_tool"]);
|
||||
expectResolvedToolNames(second, ["other_tool", "optional_tool"]);
|
||||
expect(getPluginToolMeta(first[0])?.optional).toBe(false);
|
||||
expect(getPluginToolMeta(first[0])?.trustedLocalMedia).toBe(true);
|
||||
expect(getPluginToolMeta(first[1])?.optional).toBe(true);
|
||||
expect(getPluginToolMeta(first[1])?.trustedLocalMedia).toBe(true);
|
||||
expect(getPluginToolMeta(second[1])?.optional).toBe(true);
|
||||
expect(getPluginToolMeta(second[1])?.trustedLocalMedia).toBe(true);
|
||||
expect(factory).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ export {
|
||||
export type PluginToolMeta = {
|
||||
pluginId: string;
|
||||
optional: boolean;
|
||||
trustedLocalMedia?: boolean;
|
||||
};
|
||||
|
||||
type PluginToolFactoryTimingResult = "array" | "error" | "null" | "single";
|
||||
@@ -139,6 +140,16 @@ function isPluginToolOptional(params: {
|
||||
);
|
||||
}
|
||||
|
||||
function isTrustedManifestLocalMediaTool(params: {
|
||||
manifestPlugin: PluginManifestRecord | undefined;
|
||||
toolName: string;
|
||||
}): boolean {
|
||||
return (
|
||||
params.manifestPlugin?.origin === "bundled" &&
|
||||
params.manifestPlugin.contracts?.tools?.includes(params.toolName) === true
|
||||
);
|
||||
}
|
||||
|
||||
function isOptionalToolAllowed(params: {
|
||||
toolName: string;
|
||||
pluginId: string;
|
||||
@@ -530,6 +541,7 @@ function cachedDescriptorsCoverToolNames(params: {
|
||||
|
||||
function createCachedDescriptorPluginTool(params: {
|
||||
descriptor: CachedPluginToolDescriptor;
|
||||
plugin: PluginManifestRecord;
|
||||
ctx: OpenClawPluginToolContext;
|
||||
loadContext: ReturnType<typeof resolvePluginRuntimeLoadContext>;
|
||||
runtimeOptions: PluginLoadOptions["runtimeOptions"];
|
||||
@@ -601,6 +613,10 @@ function createCachedDescriptorPluginTool(params: {
|
||||
setPluginToolMeta(tool, {
|
||||
pluginId,
|
||||
optional: params.descriptor.optional,
|
||||
trustedLocalMedia: isTrustedManifestLocalMediaTool({
|
||||
manifestPlugin: params.plugin,
|
||||
toolName,
|
||||
}),
|
||||
});
|
||||
return tool;
|
||||
}
|
||||
@@ -728,6 +744,7 @@ function resolveCachedPluginTools(params: {
|
||||
pluginTools.push(
|
||||
createCachedDescriptorPluginTool({
|
||||
descriptor: cachedDescriptor,
|
||||
plugin,
|
||||
ctx: params.ctx,
|
||||
loadContext: params.loadContext,
|
||||
runtimeOptions: params.runtimeOptions,
|
||||
@@ -1195,6 +1212,10 @@ export function resolvePluginTools(params: {
|
||||
pluginToolMeta.set(tool, {
|
||||
pluginId: entry.pluginId,
|
||||
optional,
|
||||
trustedLocalMedia: isTrustedManifestLocalMediaTool({
|
||||
manifestPlugin,
|
||||
toolName: tool.name,
|
||||
}),
|
||||
});
|
||||
if (manifestPlugin) {
|
||||
const capturedDescriptors = capturedDescriptorsByPluginId.get(entry.pluginId) ?? [];
|
||||
|
||||
Reference in New Issue
Block a user