



























@@ -124,6 +124,7 @@ import {
124124} from "../../pi-embedded-helpers.js";
125125import { countActiveToolExecutions } from "../../pi-embedded-subscribe.handlers.tools.js";
126126import { subscribeEmbeddedPiSession } from "../../pi-embedded-subscribe.js";
127+import { isCoreToolResultMediaTrustedName } from "../../pi-embedded-subscribe.tools.js";
127128import { createPreparedEmbeddedPiSettingsManager } from "../../pi-project-settings.js";
128129import {
129130applyPiAutoCompactionGuard,
@@ -448,6 +449,35 @@ export {
448449resolveEmbeddedAgentStreamFn,
449450};
450451452+function collectTrustedPluginLocalMediaToolNames(params: {
453+tools: Array<{ name?: string }>;
454+}): Set<string> {
455+const trusted = new Set<string>();
456+for (const tool of params.tools) {
457+const toolName = tool.name?.trim();
458+if (!toolName) {
459+continue;
460+}
461+const meta = getPluginToolMeta(tool as Parameters<typeof getPluginToolMeta>[0]);
462+if (meta?.trustedLocalMedia === true) {
463+trusted.add(toolName);
464+}
465+}
466+return trusted;
467+}
468+469+function collectTrustedLocalMediaToolNames(params: {
470+coreBuiltinToolNames: ReadonlySet<string>;
471+trustedPluginToolNames: ReadonlySet<string>;
472+}): Set<string> {
473+return new Set([
474+ ...[...params.coreBuiltinToolNames].filter((toolName) =>
475+isCoreToolResultMediaTrustedName(toolName),
476+),
477+ ...params.trustedPluginToolNames,
478+]);
479+}
480+451481const MAX_BTW_SNAPSHOT_MESSAGES = 100;
452482const TOOL_SEARCH_CONTROL_ALLOWLIST_NAMES = [
453483TOOL_SEARCH_CODE_MODE_TOOL_NAME,
@@ -1651,6 +1681,11 @@ export async function runEmbeddedAttempt(
16511681modelApi: params.model.api,
16521682model: params.model,
16531683};
1684+const pluginMetadataSnapshot = getCurrentPluginMetadataSnapshot({
1685+config: params.config,
1686+env: process.env,
1687+workspaceDir: effectiveWorkspace,
1688+});
16541689const tools = normalizeAgentRuntimeTools({
16551690runtimePlan: params.runtimePlan,
16561691tools: toolsEnabled ? toolsRaw : [],
@@ -1721,6 +1756,9 @@ export async function runEmbeddedAttempt(
17211756senderE164: params.senderE164,
17221757warn: (message) => log.warn(message),
17231758});
1759+const trustedPluginLocalMediaToolNames = collectTrustedPluginLocalMediaToolNames({
1760+tools: toolsEnabled ? [...toolsRaw, ...filteredBundledTools] : [],
1761+});
17241762const normalizedBundledTools =
17251763filteredBundledTools.length > 0
17261764 ? normalizeAgentRuntimeTools({
@@ -2202,11 +2240,7 @@ export async function runEmbeddedAttempt(
22022240cwd: effectiveWorkspace,
22032241 agentDir,
22042242cfg: params.config,
2205-pluginMetadataSnapshot: getCurrentPluginMetadataSnapshot({
2206-config: params.config,
2207-env: process.env,
2208-workspaceDir: effectiveWorkspace,
2209-}),
2243+ pluginMetadataSnapshot,
22102244contextTokenBudget: params.contextTokenBudget,
22112245});
22122246const piAutoCompactionGuardArgs = {
@@ -2285,10 +2319,8 @@ export async function runEmbeddedAttempt(
22852319cfg: params.config,
22862320agentId: sessionAgentId,
22872321});
2288-// Exact raw names of every tool registered for this run, including
2289-// bundled/plugin tools. Used as the raw-name set for the trusted local
2290-// MEDIA: passthrough gate: a normalized alias is not sufficient — the
2291-// emitted tool name must match an exact registration of this run.
2322+// Exact raw names of every tool registered for this run. This remains
2323+// available for diagnostics; local MEDIA: trust is narrower below.
22922324const builtinToolNames = new Set(
22932325uncompactedEffectiveTools.flatMap((tool) => {
22942326const name = (tool.name ?? "").trim();
@@ -2304,6 +2336,10 @@ export async function runEmbeddedAttempt(
23042336isPluginTool: (tool) =>
23052337Boolean(getPluginToolMeta(tool as Parameters<typeof getPluginToolMeta>[0])),
23062338});
2339+const trustedLocalMediaToolNames = collectTrustedLocalMediaToolNames({
2340+ coreBuiltinToolNames,
2341+trustedPluginToolNames: trustedPluginLocalMediaToolNames,
2342+});
23072343const clientToolNameConflicts = findClientToolNameConflicts({
23082344tools: clientTools ?? [],
23092345existingToolNames: [...coreBuiltinToolNames, ...PI_RESERVED_TOOL_NAMES],
@@ -3303,6 +3339,7 @@ export async function runEmbeddedAttempt(
33033339sessionId: params.sessionId,
33043340agentId: sessionAgentId,
33053341 builtinToolNames,
3342+ trustedLocalMediaToolNames,
33063343internalEvents: params.internalEvents,
33073344}),
33083345);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。