// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import type { Conversation, ConversationMessage, } from '../../../ai/ConversationType'; import type { ListReturnValue } from '../../../runtime/client'; import { BaseClient, ClientInternalsGetter, ModelIntrospectionSchema, SchemaModel, } from '../../bridge-types'; import { listFactory } from '../operations/list'; import { convertItemToConversationMessage } from './convertItemToConversationMessage'; import { AiAction, getCustomUserAgentDetails, } from './getCustomUserAgentDetails'; export const createListMessagesFunction = ( client: BaseClient, modelIntrospection: ModelIntrospectionSchema, conversationId: string, conversationMessageModel: SchemaModel, getInternals: ClientInternalsGetter, ): Conversation['listMessages'] => async (input) => { const list = listFactory( client, modelIntrospection, conversationMessageModel, getInternals, false, getCustomUserAgentDetails(AiAction.ListMessages), ) as (args?: Record) => ListReturnValue; const { data, nextToken, errors } = await list({ ...input, filter: { conversationId: { eq: conversationId } }, }); return { data: data.map((item: any) => convertItemToConversationMessage(item)), nextToken, errors, }; };