From e2c581823bec0cbc18954f80af12fdb47cc0764d Mon Sep 17 00:00:00 2001 From: Steph Milovic Date: Mon, 5 Jun 2023 10:04:31 -0600 Subject: [PATCH] Changes for Patrick --- .../actions/server/lib/action_executor.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/actions/server/lib/action_executor.ts b/x-pack/plugins/actions/server/lib/action_executor.ts index dcbdd889f47d8..13d7ca9be7004 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.ts @@ -253,9 +253,12 @@ export class ActionExecutor { event.event = event.event || {}; + // start gen_ai extension // add event.kibana.action.execution.gen_ai to event log when GenerativeAi Connector is executed if (result.status === 'ok' && actionTypeId === '.gen-ai') { - const data = result.data as unknown as { usage: {} }; + const data = result.data as unknown as { + usage: { prompt_tokens: number; completion_tokens: number; total_tokens: number }; + }; event.kibana = event.kibana || {}; event.kibana.action = event.kibana.action || {}; event.kibana = { @@ -265,13 +268,20 @@ export class ActionExecutor { execution: { ...event.kibana.action.execution, gen_ai: { - usage: data.usage, + usage: { + total_tokens: data.usage.total_tokens, + prompt_tokens: data.usage.prompt_tokens, + completion_tokens: data.usage.completion_tokens, + }, }, }, }, }; } - const currentUser = await security?.authc.getCurrentUser(request); + // end gen_ai extension + + const currentUser = security?.authc.getCurrentUser(request); + event.user = event.user || {}; event.user.name = currentUser?.username; event.user.id = currentUser?.profile_uid;