Skip to content
Merged
3 changes: 3 additions & 0 deletions oas_docs/output/kibana.serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62289,6 +62289,9 @@ components:
description: Message content.
example: Hello, how can I assist you today?
type: string
id:
$ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString'
description: Message id
isError:
description: Is error message.
example: false
Expand Down
3 changes: 3 additions & 0 deletions oas_docs/output/kibana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74838,6 +74838,9 @@ components:
description: Message content.
example: Hello, how can I assist you today?
type: string
id:
$ref: '#/components/schemas/Security_AI_Assistant_API_NonEmptyString'
description: Message id
isError:
description: Is error message.
example: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,9 @@ components:
description: Message content.
example: Hello, how can I assist you today?
type: string
id:
$ref: '#/components/schemas/NonEmptyString'
description: Message id
isError:
description: Is error message.
example: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,9 @@ components:
description: Message content.
example: Hello, how can I assist you today?
type: string
id:
$ref: '#/components/schemas/NonEmptyString'
description: Message id
isError:
description: Is error message.
example: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { z } from '@kbn/zod';

import { NonEmptyTimestamp, NonEmptyString, User } from '../common_attributes.gen';
import { NonEmptyString, NonEmptyTimestamp, User } from '../common_attributes.gen';

/**
* Trace Data
Expand Down Expand Up @@ -244,6 +244,10 @@ export const ConversationConfidenceEnum = ConversationConfidence.enum;
*/
export type Message = z.infer<typeof Message>;
export const Message = z.object({
/**
* Message id
*/
id: NonEmptyString.optional(),
/**
* Message content.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ components:
- 'content'
- 'role'
properties:
id:
description: Message id
$ref: '../common_attributes.schema.yaml#/components/schemas/NonEmptyString'
content:
type: string
description: Message content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { v4 as uuidv4 } from 'uuid';
import { randomBytes } from 'node:crypto';
import yargs from 'yargs/yargs';
import { ToolingLog } from '@kbn/tooling-log';
Expand Down Expand Up @@ -168,8 +169,8 @@ const getMockConversationContent = (): {
updated_at: timestamp,
'@timestamp': timestamp,
messages: [
{ content: 'Hello robot', role: 'user', '@timestamp': timestamp },
{ content: 'Hello human', role: 'assistant', '@timestamp': timestamp },
{ content: 'Hello robot', role: 'user', '@timestamp': timestamp, id: uuidv4() },
{ content: 'Hello human', role: 'assistant', '@timestamp': timestamp, id: uuidv4() },
],
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { v4 as uuidv4 } from 'uuid';
import type { estypes } from '@elastic/elasticsearch';
import type {
AppendConversationMessageRequestBody,
Expand Down Expand Up @@ -231,6 +232,7 @@ export const getEsCreateConversationSchemaMock = (
exclude_from_last_conversation_storage: false,
messages: [
{
id: uuidv4(),
content: 'test content',
role: 'user',
'@timestamp': '2019-12-13T16:40:33.400Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { v4 as uuidv4 } from 'uuid';
import type { ElasticsearchClient, Logger } from '@kbn/core/server';

import type { ConversationResponse, Message } from '@kbn/elastic-assistant-common';
Expand Down Expand Up @@ -57,6 +58,7 @@ export const appendConversationMessages = async ({
for (message in params.messages) {
def newMessage = [:];
newMessage['@timestamp'] = message['@timestamp'];
newMessage.id = message.id;
newMessage.content = message.content;
newMessage.is_error = message.is_error;
newMessage.reader = message.reader;
Expand Down Expand Up @@ -129,6 +131,7 @@ export const transformToUpdateScheme = (updatedAt: string, messages: Message[])
updated_at: updatedAt,
messages: messages?.map((message) => ({
'@timestamp': message.timestamp,
id: message.id ?? uuidv4(),
content: message.content,
is_error: message.isError,
reader: message.reader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const transformToCreateScheme = (
exclude_from_last_conversation_storage: excludeFromLastConversationStorage,
messages: messages?.map((message) => ({
'@timestamp': message.timestamp,
id: message.id ?? uuidv4(),
content: message.content,
is_error: message.isError,
reader: message.reader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const conversationsFieldMap: FieldMap = {
array: true,
required: false,
},
'messages.id': {
type: 'keyword',
array: false,
required: false,
},
'messages.@timestamp': {
type: 'date',
array: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('AIAssistantConversationsDataClient', () => {
messages: [
{
'@timestamp': '2019-12-13T16:40:33.400Z',
id: expect.any(String),
content: 'test content',
role: 'user',
trace_data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const transformESToConversation = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
conversationSchema.messages?.map((message: Record<string, any>) => ({
timestamp: message['@timestamp'],
...(message.id ? { id: message.id } : {}),
// always return anonymized data from the client
content: replaceOriginalValuesWithUuidValues({
messageContent: message.content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface EsConversationSchema {
category: ConversationCategory;
messages?: Array<{
'@timestamp': string;
id?: string;
content: string;
reader?: Reader;
role: MessageRole;
Expand Down Expand Up @@ -67,6 +68,7 @@ export interface CreateMessageSchema {
category: ConversationCategory;
messages?: Array<{
'@timestamp': string;
id: string;
content: string;
reader?: Reader;
role: MessageRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ describe('transformToUpdateScheme', () => {
...conversation,
messages: [
{
id: 'message-1',
content: 'Message 3',
role: 'user',
timestamp: '2011-10-05T14:48:00.000Z',
Expand All @@ -273,6 +274,7 @@ describe('transformToUpdateScheme', () => {
},
},
{
id: 'message-2',
content: 'Message 4',
role: 'user',
timestamp: '2011-10-06T14:48:00.000Z',
Expand All @@ -295,6 +297,7 @@ describe('transformToUpdateScheme', () => {
messages: [
{
'@timestamp': '2011-10-05T14:48:00.000Z',
id: 'message-1',
content: 'Message 3',
is_error: undefined,
reader: undefined,
Expand All @@ -316,6 +319,7 @@ describe('transformToUpdateScheme', () => {
},
{
'@timestamp': '2011-10-06T14:48:00.000Z',
id: 'message-2',
content: 'Message 4',
is_error: undefined,
reader: undefined,
Expand All @@ -337,6 +341,7 @@ describe('transformToUpdateScheme', () => {
id: conversation.id,
messages: [
{
id: 'message-3',
content: 'Message 3',
role: 'user',
timestamp: '2011-10-05T14:48:00.000Z',
Expand All @@ -353,6 +358,7 @@ describe('transformToUpdateScheme', () => {
messages: [
{
'@timestamp': '2011-10-05T14:48:00.000Z',
id: 'message-3',
content: 'Message 3',
is_error: undefined,
reader: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { v4 as uuidv4 } from 'uuid';
import type { AuthenticatedUser, Logger } from '@kbn/core/server';
import type {
ConversationResponse,
Expand All @@ -26,6 +27,7 @@ export interface UpdateConversationSchema {
title?: string;
messages?: Array<{
'@timestamp': string;
id: string;
content: string;
reader?: Reader;
role: MessageRole;
Expand Down Expand Up @@ -136,6 +138,7 @@ export const transformToUpdateScheme = (
? {
messages: messages.map((message) => ({
'@timestamp': message.timestamp,
id: message.id ?? uuidv4(),
content: message.content,
is_error: message.isError,
reader: message.reader,
Expand Down