Skip to content

Commit

Permalink
rename boutons outside outlook
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Oct 28, 2024
1 parent cb3bf66 commit b1b8d36
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
18 changes: 18 additions & 0 deletions src/aipane/AIPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import config from "../config.json" with { type: "json" };
import { isOutlookClient } from "./aipane";

export interface AIAnswer {
/**
Expand Down Expand Up @@ -161,3 +162,20 @@ export function getPrompts(standalone: boolean): AIPrompt[] {
return config.prompts;
}
}

/**
* Retrieves the prompt configuration by its ID.
* @param {string} id - The ID of the prompt.
* @returns {AIPrompt} - The prompt configuration.
*/
export function getPrompt(id: string): AIPrompt {
const prompts: AIPrompt[] = config.prompts;
const prompt: AIPrompt | undefined = prompts.find(
(prompt) => prompt.id === id && (!prompt.standalone || !isOutlookClient())
);
if (!prompt) {
console.error("getPrompt: Prompt not found");
throw new Error("Prompt not found");
}
return prompt;
}
19 changes: 1 addition & 18 deletions src/aipane/aipane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { AI } from "@sctg/ai-sdk";
import config from "../config.json" with { type: "json" };
import type { AIAnswer, AIModel, AIPrompt, AIProvider } from "./AIPrompt.js";
import { getPrompt, type AIAnswer, type AIModel, type AIProvider } from "./AIPrompt.js";
import { SentencePieceProcessor, cleanText, llama_3_1_tokeniser_b64 } from "@sctg/sentencepiece-js";
import { Model } from "@sctg/ai-sdk/resources/models.js";
import DOMPurify from "dompurify";
Expand Down Expand Up @@ -92,23 +92,6 @@ async function aiRequest(
return response;
}

/**
* Retrieves the prompt configuration by its ID.
* @param {string} id - The ID of the prompt.
* @returns {AIPrompt} - The prompt configuration.
*/
function getPrompt(id: string): AIPrompt {
const prompts: AIPrompt[] = config.prompts;
const prompt: AIPrompt | undefined = prompts.find(
(prompt) => prompt.id === id && (!prompt.standalone || !isOutlookClient())
);
if (!prompt) {
console.error("getPrompt: Prompt not found");
throw new Error("Prompt not found");
}
return prompt;
}

/**
* Retrieves the text selected in the email body.
* @returns Promise<string> - The selected text.
Expand Down
9 changes: 7 additions & 2 deletions src/aipane/components/TextInsertion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ const TextInsertion: React.FC<TextInsertionProps> = (props: TextInsertionProps):

const styles = useStyles();

let isOutlook: boolean = true;
isOutlookClient().then((isOutlookClient: boolean) => {
isOutlook = isOutlookClient;
});

return (
<div className={styles.textPromptAndInsertion}>
<Field className={styles.textAreaField} size="large" label="Enter your message.">
Expand All @@ -138,12 +143,12 @@ const TextInsertion: React.FC<TextInsertionProps> = (props: TextInsertionProps):
appearance="primary"
size="large"
onClick={handleTextFromOutlook}
className={isOutlookClient() ? styles.buttonInsert : styles.buttonInsertOff}
className={isOutlook ? styles.buttonInsert : styles.buttonInsertOff}
>
Use selected text
</Button>
<Button appearance="primary" size="large" onClick={handleTextInsertion}>
Insert answer
{isOutlook ? "Insert answer" : "Ask AI"}
</Button>
<div>
<Skeleton aria-label="Loading Content" className={skeletonVisibility ? styles.skeleton : styles.skeletonOff}>
Expand Down

0 comments on commit b1b8d36

Please sign in to comment.