Skip to content

Commit bf9706a

Browse files
refactor(detection-emulation): thread savedObjectsClient into gates
Adds optional savedObjectsClient to CommandGatesContext and the factory handler destructure. When provided by the Agent Builder handler context, withCommandGates uses it directly for uiSettingsClient derivation rather than re-creating a scoped client via coreStart.savedObjects. This eliminates a redundant getScopedClient call (async hop) on every tool invocation while keeping backward compat (falls back to request-scoped creation when the field is absent).
1 parent 1179030 commit bf9706a

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

x-pack/solutions/security/plugins/security_solution/server/agent_builder/skills/detection_emulation/create_run_family_command_tool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function createRunFamilyCommandTool(
8888
},
8989
handler: async (
9090
rawParams: z.infer<typeof schema>,
91-
{ esClient, spaceId, request, runContext, callContext }: any
91+
{ esClient, spaceId, request, runContext, callContext, savedObjectsClient }: any
9292
) => {
9393
const { emulationId, agentType, command } = rawParams;
9494

@@ -118,6 +118,7 @@ export function createRunFamilyCommandTool(
118118
request,
119119
esClient,
120120
spaceId,
121+
savedObjectsClient,
121122
actorContext,
122123
},
123124
strictParseResult.data

x-pack/solutions/security/plugins/security_solution/server/agent_builder/skills/detection_emulation/with_command_gates.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import type { Logger, ElasticsearchClient, KibanaRequest } from '@kbn/core/server';
8+
import type { Logger, ElasticsearchClient, KibanaRequest, SavedObjectsClientContract } from '@kbn/core/server';
99
import { ToolResultType } from '@kbn/agent-builder-common';
1010
import type { RunEmulationCommandInput } from '../../../../common/detection_emulation/schemas';
1111
import type { ConfigType } from '../../../config';
@@ -54,6 +54,7 @@ export interface CommandGatesContext {
5454
request: KibanaRequest;
5555
esClient: { asCurrentUser: ElasticsearchClient };
5656
spaceId: string;
57+
savedObjectsClient?: SavedObjectsClientContract;
5758
actorContext?: ActorContext;
5859
}
5960

@@ -110,6 +111,7 @@ export const withCommandGates = async (
110111
request,
111112
esClient,
112113
spaceId,
114+
savedObjectsClient,
113115
actorContext,
114116
} = ctx;
115117
const { emulationId, agentType, endpointIds, command } = cmd;
@@ -162,7 +164,7 @@ export const withCommandGates = async (
162164

163165
// ── Per-request guardrail resolution ────────────────────────────────────
164166
const [coreStart] = await core.getStartServices();
165-
const soClient = coreStart.savedObjects.getScopedClient(request);
167+
const soClient = savedObjectsClient ?? coreStart.savedObjects.getScopedClient(request);
166168
const uiSettingsClient = coreStart.uiSettings.asScopedToClient(soClient);
167169
const { effectiveAllowlist, effectiveRateLimiter } = await resolveEffectiveConfig({
168170
uiSettingsClient,

0 commit comments

Comments
 (0)