11import type { Meta , StoryObj } from '@storybook/web-components-vite' ;
22import { html } from 'lit' ;
3-
43import { GoogleGenAI , Modality } from '@google/genai' ;
54import {
65 IgcChatComponent ,
@@ -118,11 +117,11 @@ const _messageActionsTemplate = (msg: any) => {
118117 : html `` ;
119118} ;
120119
121- const _typingIndicatorTemplate = html `< span > LOADING...</ span > ` ;
122- const _textInputTemplate = ( text : string ) =>
123- html `< igc-input placeholder ="Type text here... " .value =${ text } > </ igc-input > ` ;
124- const _textAreaActionsTemplate = ( ) =>
125- html `< igc-button @click =${ handleCustomSendClick } > Send</ igc-button > ` ;
120+ // const _typingIndicatorTemplate = html`<span>LOADING...</span>`;
121+ // const _textInputTemplate = (text: string) =>
122+ // html`<igc-input placeholder="Type text here..." .value=${text}></igc-input>`;
123+ // const _textAreaActionsTemplate = () =>
124+ // html`<igc-button @click=${handleCustomSendClick}>Send</igc-button>`;
126125const _textAreaAttachmentsTemplate = ( attachments : IgcMessageAttachment [ ] ) => {
127126 return html `< div >
128127 ${ attachments . map (
@@ -178,11 +177,11 @@ const chat_options = {
178177 // languages: ['typescript']
179178 // theme: 'github-dark'
180179 } ) ,
181- templates : {
182- messageActionsTemplate : _messageActionsTemplate ,
183- textAreaAttachmentsTemplate : _textAreaAttachmentsTemplate ,
184- textAreaActionsTemplate : _textAreaActionsTemplate ,
185- } ,
180+ // templates: {
181+ // messageActionsTemplate: _messageActionsTemplate,
182+ // textAreaAttachmentsTemplate: _textAreaAttachmentsTemplate,
183+ // textAreaActionsTemplate: _textAreaActionsTemplate,
184+ // },
186185} ;
187186
188187function handleCustomSendClick ( ) {
@@ -334,7 +333,6 @@ async function handleAIMessageSend(e: CustomEvent) {
334333
335334 chat . options = { ...ai_chat_options , suggestions : [ ] , isTyping : true } ;
336335 setTimeout ( async ( ) => {
337- chat . options = { ...ai_chat_options , suggestions : [ ] , isTyping : false } ;
338336 let response : any ;
339337 let responseText = '' ;
340338 const attachments : IgcMessageAttachment [ ] = [ ] ;
@@ -364,7 +362,7 @@ async function handleAIMessageSend(e: CustomEvent) {
364362
365363 if ( newMessage . text . includes ( 'image' ) ) {
366364 response = await ai . models . generateContent ( {
367- model : 'gemini-2.0 -flash-preview-image-generation' ,
365+ model : 'gemini-2.5 -flash-preview-image-generation' ,
368366 contents : userMessages ,
369367 config : {
370368 responseModalities : [ Modality . TEXT , Modality . IMAGE ] ,
@@ -401,11 +399,12 @@ async function handleAIMessageSend(e: CustomEvent) {
401399
402400 botResponse . text = responseText ;
403401 botResponse . attachments = attachments ;
402+ chat . options = { ...ai_chat_options , isTyping : false } ;
404403 chat . messages = [ ...chat . messages , botResponse ] ;
405404 } else {
406405 chat . messages = [ ...chat . messages , botResponse ] ;
407406 response = await ai . models . generateContentStream ( {
408- model : 'gemini-2.0 -flash' ,
407+ model : 'gemini-2.5 -flash' ,
409408 contents : userMessages ,
410409 config : {
411410 responseModalities : [ Modality . TEXT ] ,
@@ -423,10 +422,10 @@ async function handleAIMessageSend(e: CustomEvent) {
423422
424423 const messagesForSuggestions = [
425424 ...chat . messages ,
426- `Based on all my previous prompts give me 3 strings that would act like a suggestions for my next prompt. Don't repeat my previous prompts, I want just the suggestions in the format "suggestion1: ' ...' , suggestion2: ' ...' , suggestion3: ' ...' ` ,
425+ `Based on all my previous prompts give me 3 strings that would act like a suggestions for my next prompt. Don't repeat my previous prompts, I want just the suggestions in the format "suggestion1: *** ...*** , suggestion2: *** ...*** , suggestion3: *** ...*** ` ,
427426 ] ;
428427 const responseWithSuggestions = await ai . models . generateContent ( {
429- model : 'gemini-2.0 -flash' ,
428+ model : 'gemini-2.5 -flash' ,
430429 contents : messagesForSuggestions ,
431430 config : {
432431 responseModalities : [ Modality . TEXT ] ,
@@ -435,19 +434,20 @@ async function handleAIMessageSend(e: CustomEvent) {
435434 response = responseWithSuggestions ?. candidates ?. [ 0 ] ?. content ?. parts ;
436435 if ( response && response . length === 1 ) {
437436 const responseText = response [ 0 ] ?. text ?? '' ;
438- const regex : RegExp = / ' ( .* ?) ' / g;
439-
440- // Use String.prototype.matchAll() to get an iterator of all matches, including captured groups.
437+ const regex : RegExp = / \* \* \* ( .* ?) \* \* \* / g; // suggestions between *** and ***
441438 const matches : IterableIterator < RegExpMatchArray > =
442439 responseText . matchAll ( regex ) ;
443440
444- // Map the matches to an array, extracting the first capturing group (the content).
445441 const suggestions : string [ ] = Array . from (
446442 matches ,
447443 ( match : RegExpMatchArray ) => match [ 1 ]
448444 ) ;
449445
450- chat . options = { ...ai_chat_options , suggestions : suggestions } ;
446+ chat . options = {
447+ ...ai_chat_options ,
448+ suggestions : suggestions ,
449+ isTyping : false ,
450+ } ;
451451 }
452452 }
453453 } , 2000 ) ;
@@ -503,7 +503,6 @@ export const Chat_Templates: Story = {
503503 const chat = document . querySelector ( 'igc-chat' ) ;
504504 if ( chat ) {
505505 const actionsTemplate = ( ) => html `
506- <!-- ${ chat . defaultFileUploadButton } -->
507506 < igc-icon-button variant ="flat "> 🎤</ igc-icon-button >
508507 < div style ="margin-inline-start: auto; ">
509508 < igc-button @click =${ handleCustomSendClick } > Ask</ igc-button >
@@ -517,6 +516,7 @@ export const Chat_Templates: Story = {
517516 suggestions : [ 'Hello' , 'Hi' , 'Generate an image!' ] ,
518517 templates : {
519518 messageActionsTemplate : _messageActionsTemplate ,
519+ textAreaAttachmentsTemplate : _textAreaAttachmentsTemplate ,
520520 textAreaActionsTemplate : actionsTemplate ,
521521 suggestionPrefixTemplate : html `✨` ,
522522 } ,
0 commit comments