diff --git a/cli/magic-create.ts b/cli/magic-create.ts index df2380c88..558d2ab79 100644 --- a/cli/magic-create.ts +++ b/cli/magic-create.ts @@ -248,7 +248,7 @@ async function processCreateOptions(options: any): Promise { }, ]; const answers: any = await enquirer.prompt(questions); - const kendraExternal = []; + const kendraExternal: any[] = []; let newKendra = answers.enableRag && answers.kendra; const existingKendraIndices = Array.from(options.kendraExternal || []); while (newKendra === true) { diff --git a/lib/chatbot-api/functions/resolvers/subscribe-resolver.js b/lib/chatbot-api/functions/resolvers/subscribe-resolver.js index dcb10309c..ddd56a54d 100644 --- a/lib/chatbot-api/functions/resolvers/subscribe-resolver.js +++ b/lib/chatbot-api/functions/resolvers/subscribe-resolver.js @@ -7,7 +7,12 @@ export function request(ctx) { } export function response(ctx) { - const filter = { and: [{ userId: { eq: ctx.identity.sub } }] }; + const filter = { + and: [ + { userId: { eq: ctx.identity.sub } }, + { sessionId: { eq: ctx.args.sessionId } }, + ], + }; extensions.setSubscriptionFilter(util.transform.toSubscriptionFilter(filter)); return null; } diff --git a/lib/user-interface/react-app/src/components/chatbot/multi-chat.tsx b/lib/user-interface/react-app/src/components/chatbot/multi-chat.tsx index aa7854cee..68ad12320 100644 --- a/lib/user-interface/react-app/src/components/chatbot/multi-chat.tsx +++ b/lib/user-interface/react-app/src/components/chatbot/multi-chat.tsx @@ -56,7 +56,7 @@ export interface ChatSession { loading: boolean; running: boolean; messageHistory: ChatBotHistoryItem[]; - subscription?: Promise; + subscription?: ZenObservable.Subscription; } function createNewSession(): ChatSession { @@ -153,7 +153,7 @@ export default function MultiChat() { return () => { refChatSessions.current.forEach((session) => { console.log(`Unsubscribing from ${session.id}`); - session.subscription?.then((s) => s.unsubscribe()); + session.subscription?.unsubscribe(); }); refChatSessions.current = []; }; @@ -226,11 +226,9 @@ export default function MultiChat() { }); }; - async function subscribe(sessionId: string) { + function subscribe(sessionId: string): ZenObservable.Subscription { console.log("Subscribing to AppSync"); - const sub = await API.graphql< - GraphQLSubscription - >({ + const sub = API.graphql>({ query: receiveMessages, variables: { sessionId: sessionId, @@ -241,7 +239,7 @@ export default function MultiChat() { const data = value.data!.receiveMessages?.data; if (data !== undefined && data !== null) { const response: ChatBotMessageResponse = JSON.parse(data); - console.log(response); + console.log(JSON.stringify(response)); if (response.action === ChatBotAction.Heartbeat) { console.log("Heartbeat pong!"); return; @@ -275,33 +273,28 @@ export default function MultiChat() { } const session = createNewSession(); - const sub = subscribe(session.id); - sub - .then(() => { - console.log(`Subscribed to session ${session.id}}`); - const request: ChatBotHeartbeatRequest = { - action: ChatBotAction.Heartbeat, - modelInterface: ChatBotModelInterface.Langchain, - data: { - sessionId: session.id, - }, - }; - const result = API.graphql({ - query: sendQuery, - variables: { - data: JSON.stringify(request), - }, - }); - console.log(result); - }) - .catch((err) => { - console.log(err); - }); + console.log(`Subscribed to session ${session.id}}`); + const request: ChatBotHeartbeatRequest = { + action: ChatBotAction.Heartbeat, + modelInterface: ChatBotModelInterface.Langchain, + data: { + sessionId: session.id, + }, + }; + API.graphql({ + query: sendQuery, + variables: { + data: JSON.stringify(request), + }, + }); session.subscription = sub; refChatSessions.current.push(session); - console.log(refChatSessions); + console.log( + "Sessions", + refChatSessions.current.map((s) => s.id) + ); setChatSessions([...refChatSessions.current]); } @@ -369,7 +362,7 @@ export default function MultiChat() {