/* eslint-disable @typescript-eslint/no-inferrable-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ import { Message } from '@aws-sdk/client-bedrock-runtime/dist-types/models'; import { LitElement, html, css } from 'lit'; import { customElement, property, query, state } from 'lit/decorators.js'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; import { repeat } from 'lit/directives/repeat.js'; import { when } from 'lit/directives/when.js'; import { ModelClient } from './model-client'; import { AgentClient } from './agent-client'; import { userIcon, assistantIcon } from './assetPaths.js'; import DOMPurify from 'dompurify'; import { marked } from "marked"; import { awsCredentialsForAnonymousUser, awsCredentialsForAuthCognitoUser } from "./authentication"; export const defaultOptions = { bedrock: { modelId: "anthropic.claude-3-sonnet-20240229-v1:0", // inferenceConfig: { // maxTokens: 1024, // temperature: 0.5, // topP: 0.9, // } } } function deepMerge(target, source) { for (const key of Object.keys(source)) { if (source[key] instanceof Object && key in target) { Object.assign(source[key], deepMerge(target[key], source[key])); } } return { ...target, ...source }; } /** * An example element. * * @fires count-changed - Indicates when the count changes * @slot - This element has a slot * @csspart button - The button */ @customElement('br-chat') export class MyElement extends LitElement { @property({ type: Object, // converter: { // fromAttribute: (value: string) => { // try { // const parsedValue = JSON.parse(value); // // Use deep merge to combine default options with parsed value // return deepMerge(defaultOptions, parsedValue); // } catch (e) { // console.warn('Invalid JSON string:', value, e); // return defaultOptions; // Return default options if parsing fails // } // } // }, }) // config: any = defaultOptions; config: any = {}; // TODO: Check if prompt as a property has an impact on performances @property() prompt: string = ''; @property({ type: Array }) attachedFiles: any[] = []; @property({ type: Array }) messages: Message[] = []; // @state() protected isLoading: boolean = false; @query('.prompt form textarea') protected promptDOMElement!: HTMLTextAreaElement; private _bedrockClient: AgentClient | ModelClient | undefined; protected reunderWebExperience() { console.log("renderWebExperience"); return html`