Skip to content

Commit

Permalink
added changes to the meave , the run button triggers the chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Minilik94 committed Feb 27, 2024
1 parent aeceb15 commit cd89e0c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions apps/aitino/src/lib/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { supabase } from "$lib/supabase";
import type { TablesInsert } from "$lib/supabase.types";

export async function saveMaeveNodes(data: TablesInsert<"maeve_nodes">) {
localStorage.setItem("currentMeaveId", data.id);
return supabase.from("maeve_nodes").upsert(data);
}

Expand Down
15 changes: 11 additions & 4 deletions apps/aitino/src/lib/components/ChatRoom.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
import { afterUpdate, onMount } from "svelte";
import SvelteMarkdown from "svelte-markdown";
let maeveId;
onMount(() => {
maeveId = localStorage.getItem("currentMeaveId");
console.log(maeveId, 'maeveId');
});
let messages: string | any[] = [];
function handleKeyDown(event: { key: string }) {
Expand All @@ -25,9 +32,6 @@
id: messages.length + 1,
status: "success",
data: {
id: "599bd33b-2b24-437a-89c5-54c998c87598",
session_id: "76e4f0cf-4678-4ace-8d90-75815d5df78b",
recipient: "SocialMediaManager-OliviaHarris",
content: newMessageContent,
role: "not user",
name: "new user",
Expand Down Expand Up @@ -67,7 +71,7 @@
const response = await fetch(`/api/v1/meave?${queryParams}`);
const data = await response.json();
const jsonResponseString = data.content;
const jsonStrings = jsonResponseString
.split("}}\n")
.map((str: string) => (str.endsWith("}") ? str : str + "}}"));
Expand Down Expand Up @@ -125,6 +129,9 @@
console.error("Error fetching chat maeave:", error);
}
};
</script>

<div class="container -mb-6 flex h-screen max-w-6xl flex-col justify-end p-6">
Expand Down
8 changes: 6 additions & 2 deletions apps/aitino/src/routes/api/v1/meave/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export const GET = async ({ url }) => {
return json({ error: "No id provided" }, { status: 400 });
}

console.log(id, 'from get meave');

//api.aiti.no/maeve?id={maeve_id}&session_id={session_id}&reply={reply}
//api.aiti.no/maeve?id={maeve_id}&session_id={f3e7ba39-e06e-4c24-a4f2-4a03c2de4453}&reply={make}

const apiUrl = `${API_BASE_URL}/maeve?id=${id}`;
console.log(apiUrl, "api url");

try {
const response = await fetch(apiUrl);
Expand All @@ -22,14 +24,16 @@ export const GET = async ({ url }) => {
);
}

console.log(response, "response from backend");

let data = [];
const reader = response.body.getReader();

try {
while (true) {
const { done, value } = await reader.read();
// responseData = new TextDecoder().decode(value);
// console.log(responseData, "res data 0");
letnotVal = new TextDecoder().decode(value);
console.log(notVal, "res data 0");

// console.log(value, "value");
// console.log(done, "done");
Expand Down
2 changes: 2 additions & 0 deletions apps/aitino/src/routes/api/v1/reply/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export const GET = async ({ url }) => {
const session_id = url.searchParams.get("session_id");
const id = url.searchParams.get("meave_id");
const reply = url.searchParams.get("reply");
// const params = url.searchParams.get("params");

console.log(id, session_id, reply, "from reply id api");

if (!id || !reply) {
return json({ error: "No id provided" }, { status: 400 });
Expand Down
31 changes: 19 additions & 12 deletions apps/aitino/src/routes/app/editors/maeve/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
{
name: "Run",
buttonVariant: "default",
onclick: () => {
onclick: async () => {
isChatDialogOpen = true;
await save();
}
},
{ name: "Add Prompt", buttonVariant: "outline", onclick: addNewPrompt },
Expand Down Expand Up @@ -150,6 +151,10 @@
edges: $edges
});
console.log(data.id, "from save node");
localStorage.setItem("currentMeaveId", data.id);
if (error) {
toast.error("Something went wrong when saving the nodes..");
return;
Expand Down Expand Up @@ -227,6 +232,8 @@
$count.prompts++;
}
console.log(data.id, "from save node 0");
</script>

<div style="height:100vh;">
Expand Down Expand Up @@ -301,17 +308,17 @@
</RightEditorSidebar>
</Panel>
<Panel position="bottom-right">
<Dialog.Root
open={isChatDialogOpen}
onOpenChange={() => {
isChatDialogOpen = false;
console.log("close");
}}
>
<Dialog.Content class="sm:max-w-full">
<ChatRoom />
</Dialog.Content>
</Dialog.Root>
<Dialog.Root
open={isChatDialogOpen}
onOpenChange={() => {
isChatDialogOpen = false;
console.log("close");
}}
>
<Dialog.Content class="sm:max-w-full">
<ChatRoom />
</Dialog.Content>
</Dialog.Root>
</Panel>
</SvelteFlow>
</div>

0 comments on commit cd89e0c

Please sign in to comment.