Instructions to use luclima/mythos-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use luclima/mythos-models with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf luclima/mythos-models:Q4_K_M # Run inference directly in the terminal: llama cli -hf luclima/mythos-models:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf luclima/mythos-models:Q4_K_M # Run inference directly in the terminal: llama cli -hf luclima/mythos-models:Q4_K_M
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf luclima/mythos-models:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf luclima/mythos-models:Q4_K_M
Use Docker
docker model run hf.co/luclima/mythos-models:Q4_K_M
- Llama new
- LM Studio
- Jan
- Ollama
How to use luclima/mythos-models with Ollama:
ollama run hf.co/luclima/mythos-models:Q4_K_M
- Unsloth Desktop
- Docker Model Runner
How to use luclima/mythos-models with Docker Model Runner:
docker model run hf.co/luclima/mythos-models:Q4_K_M
- Lemonade
How to use luclima/mythos-models with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull luclima/mythos-models:Q4_K_M
Run and chat with the model
lemonade run user.mythos-models-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub (part 5)
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- .gitattributes +27 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/streamChat.ts +140 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/tags.tsx +101 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/toast.ts +16 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/tools.ts +93 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/typed.ts +95 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/utils.ts +42 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/index.ts +97 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/persistedStore.ts +54 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/agentsSlice.ts +41 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/citationsSlice.ts +121 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/conversationSlice.ts +90 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/filesSlice.ts +139 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/paramsSlice.ts +64 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/settingsSlice.ts +45 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/code-style.css +265 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/fonts.css +62 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/globals.css +38 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/icons.css +345 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/main.css +55 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/themes/cohereTheme.js +177 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/index.d.ts +43 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/message.ts +167 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/tools.ts +6 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/util.ts +3 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/citations.ts +76 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/cn.ts +89 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/conversation.ts +83 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/delimiters.ts +6 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/download.ts +72 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/error.ts +30 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/file.ts +46 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/format.ts +51 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/getCohereColor.ts +38 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/grounding.ts +9 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/index.ts +12 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/pluralize.ts +8 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/preview.ts +93 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/queryString.ts +14 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/simpleEmailValidation.ts +19 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/tools.ts +78 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/urls.ts +79 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/tailwind.config.js +172 -0
- western_ai/canada/cohere-toolkit/src/interfaces/coral_web/tsconfig.json +44 -0
- western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.env.example +23 -0
- western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.gitignore +4 -0
- western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.nvmrc +1 -0
- western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.prettierignore +2 -0
- western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.prettierrc.js +10 -0
- western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/README.md +370 -0
.gitattributes
CHANGED
|
@@ -1023,3 +1023,30 @@ western_ai/canada/cohere-toolkit/src/interfaces/assistants_web/public/images/sha
|
|
| 1023 |
western_ai/canada/cohere-toolkit/src/interfaces/assistants_web/public/videos/KYC_BG_5K.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 1024 |
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/public/images/kycCellBackground.png filter=lfs diff=lfs merge=lfs -text
|
| 1025 |
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/public/images/share.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1023 |
western_ai/canada/cohere-toolkit/src/interfaces/assistants_web/public/videos/KYC_BG_5K.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 1024 |
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/public/images/kycCellBackground.png filter=lfs diff=lfs merge=lfs -text
|
| 1025 |
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/public/images/share.png filter=lfs diff=lfs merge=lfs -text
|
| 1026 |
+
western_ai/canada/nemo/docs/source/asr/images/citrinet_vertical.png filter=lfs diff=lfs merge=lfs -text
|
| 1027 |
+
western_ai/canada/nemo/docs/source/asr/images/conf-ensembles-overview.png filter=lfs diff=lfs merge=lfs -text
|
| 1028 |
+
western_ai/canada/nemo/docs/source/asr/images/conformer_ctc.png filter=lfs diff=lfs merge=lfs -text
|
| 1029 |
+
western_ai/canada/nemo/docs/source/asr/images/hat.png filter=lfs diff=lfs merge=lfs -text
|
| 1030 |
+
western_ai/canada/nemo/docs/source/asr/images/hybrid_asr_tts_model.png filter=lfs diff=lfs merge=lfs -text
|
| 1031 |
+
western_ai/canada/nemo/docs/source/asr/images/jasper_vertical.png filter=lfs diff=lfs merge=lfs -text
|
| 1032 |
+
western_ai/canada/nemo/docs/source/asr/images/quartz_vertical.png filter=lfs diff=lfs merge=lfs -text
|
| 1033 |
+
western_ai/canada/nemo/docs/source/asr/images/squeezeformer.png filter=lfs diff=lfs merge=lfs -text
|
| 1034 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/aosc_3spk_example.gif filter=lfs diff=lfs merge=lfs -text
|
| 1035 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/asr_sd_diagram.png filter=lfs diff=lfs merge=lfs -text
|
| 1036 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/ats.png filter=lfs diff=lfs merge=lfs -text
|
| 1037 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/cache_fifo_chunk.png filter=lfs diff=lfs merge=lfs -text
|
| 1038 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/data_flow.png filter=lfs diff=lfs merge=lfs -text
|
| 1039 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/e2e_and_cascaded_diar_systems.png filter=lfs diff=lfs merge=lfs -text
|
| 1040 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/intro_comparison.png filter=lfs diff=lfs merge=lfs -text
|
| 1041 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/loss_types.png filter=lfs diff=lfs merge=lfs -text
|
| 1042 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/main_dataflow.png filter=lfs diff=lfs merge=lfs -text
|
| 1043 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/ms_trade_off.png filter=lfs diff=lfs merge=lfs -text
|
| 1044 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/msdd_train_and_infer.png filter=lfs diff=lfs merge=lfs -text
|
| 1045 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/scale_weight_cnn.png filter=lfs diff=lfs merge=lfs -text
|
| 1046 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/sortformer.png filter=lfs diff=lfs merge=lfs -text
|
| 1047 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/streaming_steps.png filter=lfs diff=lfs merge=lfs -text
|
| 1048 |
+
western_ai/canada/nemo/docs/source/asr/speaker_diarization/images/weighted_sum.png filter=lfs diff=lfs merge=lfs -text
|
| 1049 |
+
western_ai/canada/nemo/docs/source/asr/speaker_recognition/images/ICASPP_SpeakerNet.png filter=lfs diff=lfs merge=lfs -text
|
| 1050 |
+
western_ai/canada/nemo/docs/source/asr/speaker_recognition/images/titanet_network.png filter=lfs diff=lfs merge=lfs -text
|
| 1051 |
+
western_ai/canada/nemo/docs/source/asr/speech_classification/images/marblenet_vertical.png filter=lfs diff=lfs merge=lfs -text
|
| 1052 |
+
western_ai/canada/nemo/docs/source/asr/speech_classification/images/matchboxnet_vertical.png filter=lfs diff=lfs merge=lfs -text
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/streamChat.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { EventSourceMessage } from '@microsoft/fetch-event-source';
|
| 2 |
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
| 3 |
+
import { useEffect, useRef } from 'react';
|
| 4 |
+
|
| 5 |
+
import {
|
| 6 |
+
ChatResponseEvent as ChatResponse,
|
| 7 |
+
CohereChatRequest,
|
| 8 |
+
CohereNetworkError,
|
| 9 |
+
ConversationPublic,
|
| 10 |
+
FinishReason,
|
| 11 |
+
StreamEnd,
|
| 12 |
+
StreamEvent,
|
| 13 |
+
isUnauthorizedError,
|
| 14 |
+
useCohereClient,
|
| 15 |
+
} from '@/cohere-client';
|
| 16 |
+
import { useExperimentalFeatures } from '@/hooks/experimentalFeatures';
|
| 17 |
+
|
| 18 |
+
interface StreamingParams {
|
| 19 |
+
onRead: (data: ChatResponse) => void;
|
| 20 |
+
onHeaders: (headers: Headers) => void;
|
| 21 |
+
onFinish: () => void;
|
| 22 |
+
onError: (error: unknown) => void;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export interface StreamingChatParams extends StreamingParams {
|
| 26 |
+
request: CohereChatRequest;
|
| 27 |
+
headers: Record<string, string>;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
const getUpdatedConversations =
|
| 31 |
+
(conversationId: string | undefined, description: string = '') =>
|
| 32 |
+
(conversations: ConversationPublic[] | undefined) => {
|
| 33 |
+
return conversations?.map((c) => {
|
| 34 |
+
if (c.id !== conversationId) return c;
|
| 35 |
+
|
| 36 |
+
return {
|
| 37 |
+
...c,
|
| 38 |
+
description,
|
| 39 |
+
updatedAt: new Date().toISOString(),
|
| 40 |
+
};
|
| 41 |
+
});
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
export const useStreamChat = () => {
|
| 45 |
+
const abortControllerRef = useRef<AbortController | null>(null);
|
| 46 |
+
const cohereClient = useCohereClient();
|
| 47 |
+
const queryClient = useQueryClient();
|
| 48 |
+
const { data: experimentalFeatures } = useExperimentalFeatures();
|
| 49 |
+
|
| 50 |
+
useEffect(() => {
|
| 51 |
+
return () => {
|
| 52 |
+
abortControllerRef.current?.abort();
|
| 53 |
+
};
|
| 54 |
+
}, []);
|
| 55 |
+
|
| 56 |
+
const retry = (failCount: number, error: CohereNetworkError) => {
|
| 57 |
+
// we allow 1 retry for 401 errors
|
| 58 |
+
if (isUnauthorizedError(error)) {
|
| 59 |
+
return failCount < 1;
|
| 60 |
+
}
|
| 61 |
+
return false;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
const updateConversationHistory = (data?: StreamEnd) => {
|
| 65 |
+
if (!data) return;
|
| 66 |
+
|
| 67 |
+
queryClient.setQueryData<ConversationPublic[]>(
|
| 68 |
+
['conversations'],
|
| 69 |
+
getUpdatedConversations(data?.conversation_id ?? '', data?.text)
|
| 70 |
+
);
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
const chatMutation = useMutation<StreamEnd | undefined, CohereNetworkError, StreamingChatParams>({
|
| 74 |
+
mutationFn: async (params: StreamingChatParams) => {
|
| 75 |
+
try {
|
| 76 |
+
queryClient.setQueryData<ConversationPublic[]>(
|
| 77 |
+
['conversations'],
|
| 78 |
+
getUpdatedConversations(params.request.conversation_id ?? '', params.request.message)
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
abortControllerRef.current = new AbortController();
|
| 82 |
+
|
| 83 |
+
const { request, headers, onRead, onError, onFinish } = params;
|
| 84 |
+
|
| 85 |
+
const chatStreamParams = {
|
| 86 |
+
request,
|
| 87 |
+
headers,
|
| 88 |
+
signal: abortControllerRef.current.signal,
|
| 89 |
+
onMessage: (event: EventSourceMessage) => {
|
| 90 |
+
try {
|
| 91 |
+
if (!event.data) return;
|
| 92 |
+
const data = JSON.parse(event.data);
|
| 93 |
+
|
| 94 |
+
if (data?.event === StreamEvent.STREAM_END) {
|
| 95 |
+
const streamEndData = data.data as StreamEnd;
|
| 96 |
+
|
| 97 |
+
if (streamEndData.finish_reason !== FinishReason.COMPLETE) {
|
| 98 |
+
throw new Error(streamEndData.error || 'Stream ended unexpectedly');
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
if (params.request.conversation_id) {
|
| 102 |
+
queryClient.setQueryData<ConversationPublic[]>(
|
| 103 |
+
['conversations'],
|
| 104 |
+
getUpdatedConversations(params.request.conversation_id, streamEndData.text)
|
| 105 |
+
);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
onRead(data);
|
| 109 |
+
} catch (e) {
|
| 110 |
+
const errMsg = e instanceof Error ? e.message : 'unable to parse event data';
|
| 111 |
+
throw new Error(errMsg);
|
| 112 |
+
}
|
| 113 |
+
},
|
| 114 |
+
onError: (err: unknown) => {
|
| 115 |
+
onError(err);
|
| 116 |
+
// Rethrow to stop the operation
|
| 117 |
+
throw err;
|
| 118 |
+
},
|
| 119 |
+
onClose: () => {
|
| 120 |
+
onFinish();
|
| 121 |
+
},
|
| 122 |
+
};
|
| 123 |
+
|
| 124 |
+
await cohereClient.chat({ ...chatStreamParams });
|
| 125 |
+
} catch (e) {
|
| 126 |
+
if (isUnauthorizedError(e)) {
|
| 127 |
+
await queryClient.invalidateQueries({ queryKey: ['defaultAPIKey'] });
|
| 128 |
+
}
|
| 129 |
+
return Promise.reject(e);
|
| 130 |
+
}
|
| 131 |
+
},
|
| 132 |
+
retry,
|
| 133 |
+
onSuccess: updateConversationHistory,
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
return {
|
| 137 |
+
chatMutation,
|
| 138 |
+
abortController: abortControllerRef,
|
| 139 |
+
};
|
| 140 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/tags.tsx
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useMemo, useState } from 'react';
|
| 2 |
+
|
| 3 |
+
import { ToolDefinition } from '@/cohere-client';
|
| 4 |
+
import { Tag } from '@/components/Conversation/Composer/DataSourceMenu';
|
| 5 |
+
import { TOOL_FALLBACK_ICON, TOOL_ID_TO_DISPLAY_INFO } from '@/constants';
|
| 6 |
+
import { useListFiles } from '@/hooks/files';
|
| 7 |
+
import { useListTools } from '@/hooks/tools';
|
| 8 |
+
import { useConversationStore } from '@/stores';
|
| 9 |
+
import { formatFileSize } from '@/utils';
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* @description Hook that contains all the logic for filtering and displaying tags
|
| 13 |
+
* for data sources.
|
| 14 |
+
*/
|
| 15 |
+
export const useDataSourceTags = ({ requiredTools }: { requiredTools?: string[] }) => {
|
| 16 |
+
const [tagQuery, setTagQuery] = useState<string>('');
|
| 17 |
+
const {
|
| 18 |
+
conversation: { id },
|
| 19 |
+
} = useConversationStore();
|
| 20 |
+
const query = tagQuery.replace('@', '');
|
| 21 |
+
const { data: tools = [] } = useListTools();
|
| 22 |
+
const { data: files } = useListFiles(id);
|
| 23 |
+
const onlyRequiredTools = useMemo(() => {
|
| 24 |
+
const availableTools = tools.filter((t) => t.is_visible && t.is_available);
|
| 25 |
+
if (!requiredTools) {
|
| 26 |
+
return availableTools;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
return requiredTools
|
| 30 |
+
.map((rt) => availableTools.find((t) => t.name === rt))
|
| 31 |
+
.filter((t) => !!t) as ToolDefinition[];
|
| 32 |
+
}, [tools, requiredTools]);
|
| 33 |
+
|
| 34 |
+
const filteredFileIdTags: Tag[] = useMemo(
|
| 35 |
+
() =>
|
| 36 |
+
(files ?? [])
|
| 37 |
+
.filter((file) => {
|
| 38 |
+
return file.file_name.toLowerCase().includes(query.toLowerCase());
|
| 39 |
+
})
|
| 40 |
+
.map(({ id, file_name, file_size = 0 }) => ({
|
| 41 |
+
id,
|
| 42 |
+
name: file_name,
|
| 43 |
+
metadata: formatFileSize(file_size),
|
| 44 |
+
getValue: () => id,
|
| 45 |
+
})),
|
| 46 |
+
[files, query]
|
| 47 |
+
);
|
| 48 |
+
|
| 49 |
+
const allToolTags: Tag[] = useMemo(() => {
|
| 50 |
+
const allTools = [];
|
| 51 |
+
for (const t of onlyRequiredTools) {
|
| 52 |
+
allTools.push({
|
| 53 |
+
id: t.name ?? '',
|
| 54 |
+
name: t.display_name ?? t.name ?? '',
|
| 55 |
+
description: t.description ?? '',
|
| 56 |
+
icon: TOOL_ID_TO_DISPLAY_INFO[t.name ?? '']?.icon ?? TOOL_FALLBACK_ICON,
|
| 57 |
+
getValue: () => t,
|
| 58 |
+
});
|
| 59 |
+
}
|
| 60 |
+
return allTools;
|
| 61 |
+
}, [onlyRequiredTools]);
|
| 62 |
+
const filteredToolTags: Tag[] = useMemo(
|
| 63 |
+
() =>
|
| 64 |
+
allToolTags.filter(
|
| 65 |
+
(tag) =>
|
| 66 |
+
tag.id.toLowerCase().includes(query.toLowerCase()) ||
|
| 67 |
+
tag.name.toLowerCase().includes(query.toLowerCase())
|
| 68 |
+
),
|
| 69 |
+
[allToolTags, query]
|
| 70 |
+
);
|
| 71 |
+
|
| 72 |
+
// if user types @ at the current input cursor position, return the @ and the string that follows
|
| 73 |
+
const getTagQuery = (value: string, cursorPosition: number): string => {
|
| 74 |
+
// Find the nearest space to the left of the cursor position
|
| 75 |
+
const spaceIndex = value.lastIndexOf(' ', cursorPosition);
|
| 76 |
+
|
| 77 |
+
// Determine the starting index based on the nearest space
|
| 78 |
+
const startIndex = spaceIndex !== -1 ? spaceIndex + 1 : 0;
|
| 79 |
+
|
| 80 |
+
// Match the first word of the string if it starts with "@"
|
| 81 |
+
const regexPattern = /^@(\S*)/;
|
| 82 |
+
const match = value.substring(startIndex).match(regexPattern);
|
| 83 |
+
if (match) {
|
| 84 |
+
return match[0];
|
| 85 |
+
}
|
| 86 |
+
return '';
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
suggestedTags: {
|
| 91 |
+
fileIds: filteredFileIdTags,
|
| 92 |
+
tools: filteredToolTags,
|
| 93 |
+
},
|
| 94 |
+
totalTags: {
|
| 95 |
+
fileIds: files?.length ?? 0,
|
| 96 |
+
},
|
| 97 |
+
tagQuery,
|
| 98 |
+
setTagQuery,
|
| 99 |
+
getTagQuery,
|
| 100 |
+
};
|
| 101 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/toast.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { toast } from 'sonner';
|
| 2 |
+
|
| 3 |
+
export const useNotify = () => {
|
| 4 |
+
const error = (message: string) =>
|
| 5 |
+
toast.error(message, {
|
| 6 |
+
duration: Infinity,
|
| 7 |
+
cancel: { label: 'x', onClick: () => toast.dismiss() },
|
| 8 |
+
});
|
| 9 |
+
const info = (message: string) => toast.info(message, { duration: 5000 });
|
| 10 |
+
const success = (message: string) => toast.success(message, { duration: 5000 });
|
| 11 |
+
const loading = (message: string) => toast.loading(message);
|
| 12 |
+
|
| 13 |
+
const dismiss = (id: string | number) => toast.dismiss(id);
|
| 14 |
+
|
| 15 |
+
return { error, info, success, loading, dismiss };
|
| 16 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/tools.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useLocalStorageValue } from '@react-hookz/web';
|
| 2 |
+
import { useQuery } from '@tanstack/react-query';
|
| 3 |
+
import useDrivePicker from 'react-google-drive-picker';
|
| 4 |
+
import type { PickerCallback } from 'react-google-drive-picker/dist/typeDefs';
|
| 5 |
+
|
| 6 |
+
import { ToolDefinition, useCohereClient } from '@/cohere-client';
|
| 7 |
+
import { LOCAL_STORAGE_KEYS, TOOL_GOOGLE_DRIVE_ID } from '@/constants';
|
| 8 |
+
import { STRINGS } from '@/constants/strings';
|
| 9 |
+
import { env } from '@/env.mjs';
|
| 10 |
+
import { useNotify } from '@/hooks/toast';
|
| 11 |
+
|
| 12 |
+
export const useListTools = (enabled: boolean = true) => {
|
| 13 |
+
const client = useCohereClient();
|
| 14 |
+
return useQuery<ToolDefinition[], Error>({
|
| 15 |
+
queryKey: ['tools'],
|
| 16 |
+
queryFn: () => client.listTools({}),
|
| 17 |
+
refetchOnWindowFocus: false,
|
| 18 |
+
enabled,
|
| 19 |
+
});
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @description A hook that returns a list of tools that require authentication
|
| 24 |
+
*/
|
| 25 |
+
export const useUnauthedTools = (enabled: boolean = true) => {
|
| 26 |
+
const { data: tools } = useListTools(enabled);
|
| 27 |
+
const unauthedTools = tools?.filter((tool) => tool.is_auth_required) ?? [];
|
| 28 |
+
const isToolAuthRequired = unauthedTools.length > 0;
|
| 29 |
+
return { unauthedTools, isToolAuthRequired };
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
export const useShowUnauthedToolsModal = () => {
|
| 33 |
+
const { isToolAuthRequired } = useUnauthedTools();
|
| 34 |
+
const { value: hasDismissed, set } = useLocalStorageValue(
|
| 35 |
+
LOCAL_STORAGE_KEYS.unauthedToolsModalDismissed,
|
| 36 |
+
{
|
| 37 |
+
defaultValue: false,
|
| 38 |
+
initializeWithValue: true,
|
| 39 |
+
}
|
| 40 |
+
);
|
| 41 |
+
return {
|
| 42 |
+
show: !hasDismissed && isToolAuthRequired,
|
| 43 |
+
onDismissed: () => set(true),
|
| 44 |
+
};
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
export const useOpenGoogleDrivePicker = (callbackFunction: (data: PickerCallback) => void) => {
|
| 48 |
+
const [openPicker] = useDrivePicker();
|
| 49 |
+
const { data: toolsData } = useListTools();
|
| 50 |
+
const { info } = useNotify();
|
| 51 |
+
|
| 52 |
+
const googleDriveTool = toolsData?.find((tool) => tool.name === TOOL_GOOGLE_DRIVE_ID);
|
| 53 |
+
|
| 54 |
+
const handleCallback = (data: PickerCallback) => {
|
| 55 |
+
if (!data.docs) return;
|
| 56 |
+
|
| 57 |
+
const folders = data.docs.filter((doc) => doc.type === 'folder');
|
| 58 |
+
const files = data.docs.filter((doc) => doc.type !== 'folder');
|
| 59 |
+
|
| 60 |
+
if (folders.length > 0 && files.length > 0) {
|
| 61 |
+
info(STRINGS.selectGoogleDriveFilesOrFolders);
|
| 62 |
+
return;
|
| 63 |
+
}
|
| 64 |
+
if (files.length > 5) {
|
| 65 |
+
info(STRINGS.selectMaxGoogleDriveFilesDescription);
|
| 66 |
+
return;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
callbackFunction(data);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
const googleDriveClientId = env.NEXT_PUBLIC_GOOGLE_DRIVE_CLIENT_ID;
|
| 73 |
+
const googleDriveDeveloperKey = env.NEXT_PUBLIC_GOOGLE_DRIVE_DEVELOPER_KEY;
|
| 74 |
+
if (!googleDriveClientId || !googleDriveDeveloperKey) {
|
| 75 |
+
return () => {
|
| 76 |
+
info(STRINGS.googleDriveUnavailableError);
|
| 77 |
+
};
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return () =>
|
| 81 |
+
openPicker({
|
| 82 |
+
clientId: googleDriveClientId,
|
| 83 |
+
developerKey: googleDriveDeveloperKey,
|
| 84 |
+
token: googleDriveTool?.token || '',
|
| 85 |
+
setIncludeFolders: true,
|
| 86 |
+
setSelectFolderEnabled: true,
|
| 87 |
+
showUploadView: false,
|
| 88 |
+
showUploadFolders: false,
|
| 89 |
+
supportDrives: true,
|
| 90 |
+
multiselect: true,
|
| 91 |
+
callbackFunction: handleCallback,
|
| 92 |
+
});
|
| 93 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/typed.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useState } from 'react';
|
| 2 |
+
|
| 3 |
+
type TypeOptions = {
|
| 4 |
+
typeSpeed?: number;
|
| 5 |
+
charactersPerInterval?: number;
|
| 6 |
+
paragraphDelay?: number;
|
| 7 |
+
enabled?: boolean;
|
| 8 |
+
onParagraphTyped?: (paragraphIndex: number) => void;
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* A hook to render text with a typing effect.
|
| 13 |
+
* Each character in a phrase is "typed" at the designated `typeSpeed` and each
|
| 14 |
+
* phrase begins "typing" after the designated `paragraphDelay`.
|
| 15 |
+
* @param texts - the phrases to be typed out
|
| 16 |
+
* @param options.typeSpeed - delay between characters typed in ms
|
| 17 |
+
* @param options.charactersPerInterval - number of chars to be typed at a time
|
| 18 |
+
* @param options.paragraphDelay - delay between paragraphs in ms
|
| 19 |
+
* @param options.enabled - whether or not to start typing
|
| 20 |
+
* @param options.onParagraphTyped - callback when a paragraph is fully typed
|
| 21 |
+
|
| 22 |
+
*/
|
| 23 |
+
export const useTyped = (
|
| 24 |
+
texts: string[],
|
| 25 |
+
{
|
| 26 |
+
typeSpeed = 5,
|
| 27 |
+
charactersPerInterval = 1,
|
| 28 |
+
paragraphDelay = 1000,
|
| 29 |
+
enabled = true,
|
| 30 |
+
onParagraphTyped,
|
| 31 |
+
}: TypeOptions
|
| 32 |
+
) => {
|
| 33 |
+
const [typed, setTyped] = useState('');
|
| 34 |
+
const [isTyping, setIsTyping] = useState<boolean>();
|
| 35 |
+
const [isFinished, setIsFinished] = useState(false);
|
| 36 |
+
const [timer, setTimer] = useState<NodeJS.Timeout>();
|
| 37 |
+
|
| 38 |
+
// reset state when texts change
|
| 39 |
+
useEffect(() => {
|
| 40 |
+
setTyped('');
|
| 41 |
+
setIsTyping(false);
|
| 42 |
+
setIsFinished(false);
|
| 43 |
+
clearTimeout(timer);
|
| 44 |
+
setTimer(undefined);
|
| 45 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 46 |
+
}, [texts]);
|
| 47 |
+
|
| 48 |
+
useEffect(() => {
|
| 49 |
+
if (!enabled) return;
|
| 50 |
+
if (isFinished) return;
|
| 51 |
+
|
| 52 |
+
setIsTyping(true);
|
| 53 |
+
|
| 54 |
+
let fullyTyped = '';
|
| 55 |
+
let phraseIndex = 0;
|
| 56 |
+
let charIndex = 0;
|
| 57 |
+
setTimer(
|
| 58 |
+
setTimeout(function type() {
|
| 59 |
+
fullyTyped += texts[phraseIndex].slice(charIndex, charIndex + charactersPerInterval);
|
| 60 |
+
setTyped(fullyTyped);
|
| 61 |
+
charIndex += charactersPerInterval;
|
| 62 |
+
|
| 63 |
+
if (charIndex >= texts[phraseIndex].length) {
|
| 64 |
+
charIndex = 0;
|
| 65 |
+
phraseIndex += 1;
|
| 66 |
+
onParagraphTyped?.(phraseIndex);
|
| 67 |
+
|
| 68 |
+
if (phraseIndex === texts.length) {
|
| 69 |
+
setIsTyping(false);
|
| 70 |
+
setIsFinished(true);
|
| 71 |
+
clearTimeout(timer);
|
| 72 |
+
} else {
|
| 73 |
+
setTimer(setTimeout(type, paragraphDelay));
|
| 74 |
+
}
|
| 75 |
+
} else {
|
| 76 |
+
setTimer(setTimeout(type, typeSpeed));
|
| 77 |
+
}
|
| 78 |
+
}, 0)
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
return () => clearTimeout(timer);
|
| 82 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 83 |
+
}, [
|
| 84 |
+
texts,
|
| 85 |
+
typeSpeed,
|
| 86 |
+
isTyping,
|
| 87 |
+
paragraphDelay,
|
| 88 |
+
charactersPerInterval,
|
| 89 |
+
enabled,
|
| 90 |
+
isFinished,
|
| 91 |
+
onParagraphTyped,
|
| 92 |
+
]);
|
| 93 |
+
|
| 94 |
+
return { typed, isTyping };
|
| 95 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/hooks/utils.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from 'react';
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
*
|
| 5 |
+
* A hook used to track steps in a type-safe way.
|
| 6 |
+
*
|
| 7 |
+
* @param numberOfSteps The number of steps to track
|
| 8 |
+
* @param onComplete A callback to be called when the last step is reached
|
| 9 |
+
* @returns An object containing the current step and a function to set the current step
|
| 10 |
+
*
|
| 11 |
+
* @example
|
| 12 |
+
* const { step, setStep } = useSteps(3, () => console.info('done'));
|
| 13 |
+
* setStep(1); // step is now 1
|
| 14 |
+
* setStep(2); // step is now 2
|
| 15 |
+
* setStep(3); // step is now 3 and 'done' is logged to the console
|
| 16 |
+
*
|
| 17 |
+
* Note: It's best used with numeric enums
|
| 18 |
+
*
|
| 19 |
+
* @example
|
| 20 |
+
* enum Steps {
|
| 21 |
+
* Step1,
|
| 22 |
+
* Step2,
|
| 23 |
+
* Step3,
|
| 24 |
+
* }
|
| 25 |
+
* const { step, setStep } = useSteps<Steps>(Steps.Step3, () => console.info('done'));
|
| 26 |
+
*/
|
| 27 |
+
export const useSteps = <T extends number>(numberOfSteps: number, onComplete: VoidFunction) => {
|
| 28 |
+
const [step, _setStep] = useState(0);
|
| 29 |
+
|
| 30 |
+
const setStep = (step: T) => {
|
| 31 |
+
if (step > numberOfSteps) return;
|
| 32 |
+
_setStep(step);
|
| 33 |
+
if (step === numberOfSteps) {
|
| 34 |
+
onComplete();
|
| 35 |
+
}
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
return {
|
| 39 |
+
step: step as T,
|
| 40 |
+
setStep,
|
| 41 |
+
};
|
| 42 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { create } from 'zustand';
|
| 2 |
+
import { shallow } from 'zustand/shallow';
|
| 3 |
+
|
| 4 |
+
import { ToolDefinition } from '@/cohere-client';
|
| 5 |
+
import { AgentsStore, createAgentsSlice } from '@/stores/slices/agentsSlice';
|
| 6 |
+
import { CitationsStore, createCitationsSlice } from '@/stores/slices/citationsSlice';
|
| 7 |
+
import { ConversationStore, createConversationSlice } from '@/stores/slices/conversationSlice';
|
| 8 |
+
import { FilesStore, createFilesSlice } from '@/stores/slices/filesSlice';
|
| 9 |
+
import { ParamStore, createParamsSlice } from '@/stores/slices/paramsSlice';
|
| 10 |
+
|
| 11 |
+
export type ChatSettingsDefaultsValue = {
|
| 12 |
+
preamble?: string;
|
| 13 |
+
model?: string;
|
| 14 |
+
temperature?: number;
|
| 15 |
+
tools?: ToolDefinition[];
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
export type StoreState = CitationsStore & ConversationStore & FilesStore & ParamStore & AgentsStore;
|
| 19 |
+
|
| 20 |
+
const useStore = create<StoreState>((...a) => ({
|
| 21 |
+
...createCitationsSlice(...a),
|
| 22 |
+
...createConversationSlice(...a),
|
| 23 |
+
...createFilesSlice(...a),
|
| 24 |
+
...createParamsSlice(...a),
|
| 25 |
+
...createAgentsSlice(...a),
|
| 26 |
+
}));
|
| 27 |
+
|
| 28 |
+
export const useCitationsStore = () => {
|
| 29 |
+
return useStore(
|
| 30 |
+
(state) => ({
|
| 31 |
+
citations: state.citations,
|
| 32 |
+
addSearchResults: state.addSearchResults,
|
| 33 |
+
addCitation: state.addCitation,
|
| 34 |
+
selectCitation: state.selectCitation,
|
| 35 |
+
hoverCitation: state.hoverCitation,
|
| 36 |
+
resetCitations: state.resetCitations,
|
| 37 |
+
saveOutputFiles: state.saveOutputFiles,
|
| 38 |
+
agents: state.agents,
|
| 39 |
+
}),
|
| 40 |
+
shallow
|
| 41 |
+
);
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
export const useConversationStore = () => {
|
| 45 |
+
return useStore(
|
| 46 |
+
(state) => ({
|
| 47 |
+
conversation: state.conversation,
|
| 48 |
+
setConversation: state.setConversation,
|
| 49 |
+
setPendingMessage: state.setPendingMessage,
|
| 50 |
+
resetConversation: state.resetConversation,
|
| 51 |
+
}),
|
| 52 |
+
shallow
|
| 53 |
+
);
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
export const useFilesStore = () => {
|
| 57 |
+
return useStore(
|
| 58 |
+
(state) => ({
|
| 59 |
+
files: state.files,
|
| 60 |
+
queueFocusFileInput: state.queueFocusFileInput,
|
| 61 |
+
clearFocusFileInput: state.clearFocusFileInput,
|
| 62 |
+
addUploadingFile: state.addUploadingFile,
|
| 63 |
+
addUploadingFiles: state.addUploadingFiles,
|
| 64 |
+
deleteUploadingFile: state.deleteUploadingFile,
|
| 65 |
+
addComposerFile: state.addComposerFile,
|
| 66 |
+
deleteComposerFile: state.deleteComposerFile,
|
| 67 |
+
clearComposerFiles: state.clearComposerFiles,
|
| 68 |
+
clearUploadingErrors: state.clearUploadingErrors,
|
| 69 |
+
updateUploadingFileError: state.updateUploadingFileError,
|
| 70 |
+
}),
|
| 71 |
+
shallow
|
| 72 |
+
);
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
export const useParamsStore = () => {
|
| 76 |
+
return useStore(
|
| 77 |
+
(state) => ({
|
| 78 |
+
params: state.params,
|
| 79 |
+
setParams: state.setParams,
|
| 80 |
+
resetFileParams: state.resetFileParams,
|
| 81 |
+
}),
|
| 82 |
+
shallow
|
| 83 |
+
);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
export const useAgentsStore = () => {
|
| 87 |
+
return useStore(
|
| 88 |
+
(state) => ({
|
| 89 |
+
agents: state.agents,
|
| 90 |
+
setAgentsSidePanelOpen: state.setAgentsSidePanelOpen,
|
| 91 |
+
setEditAgentPanelOpen: state.setEditAgentPanelOpen,
|
| 92 |
+
}),
|
| 93 |
+
shallow
|
| 94 |
+
);
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
export { useSettingsStore } from '@/stores/persistedStore';
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/persistedStore.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useState } from 'react';
|
| 2 |
+
import { create } from 'zustand';
|
| 3 |
+
import { persist } from 'zustand/middleware';
|
| 4 |
+
import { shallow } from 'zustand/shallow';
|
| 5 |
+
|
| 6 |
+
import { SettingsStore, createSettingsSlice } from '@/stores/slices/settingsSlice';
|
| 7 |
+
|
| 8 |
+
type PersistedStore = SettingsStore;
|
| 9 |
+
|
| 10 |
+
const useEmptyPersistedStore = create<PersistedStore>((...a) => ({
|
| 11 |
+
...createSettingsSlice(...a),
|
| 12 |
+
}));
|
| 13 |
+
|
| 14 |
+
const usePersistedStore = create<PersistedStore>()(
|
| 15 |
+
persist(
|
| 16 |
+
(...a) => ({
|
| 17 |
+
...createSettingsSlice(...a),
|
| 18 |
+
}),
|
| 19 |
+
{
|
| 20 |
+
name: 'persisted-store',
|
| 21 |
+
version: 2,
|
| 22 |
+
}
|
| 23 |
+
)
|
| 24 |
+
);
|
| 25 |
+
/**
|
| 26 |
+
* Wrap usePersistedStore with a hook that returns an empty store until the persisted store is hydrated.
|
| 27 |
+
* This avoids an issue where the server-rendered HTML does not match with the first client render,
|
| 28 |
+
* since the server cannot load from localStorage and renders with an empty store, while the client
|
| 29 |
+
* would load from localStorage and render with a hydrated store.
|
| 30 |
+
*
|
| 31 |
+
* By waiting until after a useEffect completes for the client render, the first render will use
|
| 32 |
+
* an empty store and match the server.
|
| 33 |
+
*
|
| 34 |
+
* @see https://github.com/pmndrs/zustand/issues/1145#issuecomment-1207233036
|
| 35 |
+
*/
|
| 36 |
+
const usePersistedStoresWithHydration = ((selector, compare) => {
|
| 37 |
+
const emptyStore = useEmptyPersistedStore(selector, compare);
|
| 38 |
+
const store = usePersistedStore(selector, compare);
|
| 39 |
+
const [hydrated, setHydrated] = useState(false);
|
| 40 |
+
useEffect(() => setHydrated(true), []);
|
| 41 |
+
|
| 42 |
+
return hydrated ? store : emptyStore;
|
| 43 |
+
}) as typeof usePersistedStore;
|
| 44 |
+
|
| 45 |
+
export const useSettingsStore = () => {
|
| 46 |
+
return usePersistedStoresWithHydration(
|
| 47 |
+
(state) => ({
|
| 48 |
+
settings: state.settings,
|
| 49 |
+
setSettings: state.setSettings,
|
| 50 |
+
setIsConvListPanelOpen: state.setIsConvListPanelOpen,
|
| 51 |
+
}),
|
| 52 |
+
shallow
|
| 53 |
+
);
|
| 54 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/agentsSlice.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StateCreator } from 'zustand';
|
| 2 |
+
|
| 3 |
+
import { StoreState } from '@/stores';
|
| 4 |
+
|
| 5 |
+
const INITIAL_STATE = {
|
| 6 |
+
isEditAgentPanelOpen: false,
|
| 7 |
+
isAgentsSidePanelOpen: true,
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
type State = {
|
| 11 |
+
isAgentsSidePanelOpen: boolean;
|
| 12 |
+
isEditAgentPanelOpen: boolean;
|
| 13 |
+
};
|
| 14 |
+
type Actions = {
|
| 15 |
+
setAgentsSidePanelOpen: (isOpen: boolean) => void;
|
| 16 |
+
setEditAgentPanelOpen: (isOpen: boolean) => void;
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
export type AgentsStore = {
|
| 20 |
+
agents: State;
|
| 21 |
+
} & Actions;
|
| 22 |
+
|
| 23 |
+
export const createAgentsSlice: StateCreator<StoreState, [], [], AgentsStore> = (set) => ({
|
| 24 |
+
setAgentsSidePanelOpen(isOpen) {
|
| 25 |
+
set((state) => ({
|
| 26 |
+
agents: {
|
| 27 |
+
...state.agents,
|
| 28 |
+
isAgentsSidePanelOpen: isOpen,
|
| 29 |
+
},
|
| 30 |
+
}));
|
| 31 |
+
},
|
| 32 |
+
setEditAgentPanelOpen(isOpen) {
|
| 33 |
+
set((state) => ({
|
| 34 |
+
agents: {
|
| 35 |
+
...state.agents,
|
| 36 |
+
isEditAgentPanelOpen: isOpen,
|
| 37 |
+
},
|
| 38 |
+
}));
|
| 39 |
+
},
|
| 40 |
+
agents: INITIAL_STATE,
|
| 41 |
+
});
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/citationsSlice.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StateCreator } from 'zustand';
|
| 2 |
+
|
| 3 |
+
import { Document } from '@/cohere-client';
|
| 4 |
+
|
| 5 |
+
import { StoreState } from '..';
|
| 6 |
+
|
| 7 |
+
const INITIAL_STATE: State = {
|
| 8 |
+
citationReferences: {},
|
| 9 |
+
hasCitations: false,
|
| 10 |
+
selectedCitation: null,
|
| 11 |
+
hoveredGenerationId: null,
|
| 12 |
+
searchResults: {},
|
| 13 |
+
outputFiles: {},
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
type Citation = {
|
| 17 |
+
generationId: string;
|
| 18 |
+
start: string;
|
| 19 |
+
end: string;
|
| 20 |
+
/** Used to scroll to highlight position */
|
| 21 |
+
yPosition: number | null;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
type CitationReferences = {
|
| 25 |
+
[generationId: string]: {
|
| 26 |
+
/** In the format: {startIndex}-{endIndex} */
|
| 27 |
+
[startEndKey: string]: Document[];
|
| 28 |
+
};
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
interface SearchResults {
|
| 32 |
+
[documentId: string]: Record<string, any>;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
export type OutputFiles = { [name: string]: { name: string; data: string; documentId?: string } };
|
| 36 |
+
|
| 37 |
+
type State = {
|
| 38 |
+
citationReferences: CitationReferences;
|
| 39 |
+
hasCitations: boolean;
|
| 40 |
+
selectedCitation: Citation | null;
|
| 41 |
+
hoveredGenerationId: string | null;
|
| 42 |
+
searchResults: SearchResults;
|
| 43 |
+
outputFiles: OutputFiles;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
type Actions = {
|
| 47 |
+
addSearchResults: (results: Record<string, any>) => void;
|
| 48 |
+
addCitation: (generationId: string, startEndKey: string, documents: Document[]) => void;
|
| 49 |
+
selectCitation: (citation: Citation | null) => void;
|
| 50 |
+
hoverCitation: (generationId: string | null) => void;
|
| 51 |
+
resetCitations: VoidFunction;
|
| 52 |
+
saveOutputFiles: (outputFiles: OutputFiles) => void;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
export type CitationsStore = {
|
| 56 |
+
citations: State;
|
| 57 |
+
} & Actions;
|
| 58 |
+
|
| 59 |
+
export const createCitationsSlice: StateCreator<StoreState, [], [], CitationsStore> = (set) => ({
|
| 60 |
+
addSearchResults(results) {
|
| 61 |
+
set((state) => {
|
| 62 |
+
const newResults = { ...state.citations.searchResults };
|
| 63 |
+
(results || []).forEach((result: any) => {
|
| 64 |
+
(result?.documentIds ?? []).forEach((docId: string) => {
|
| 65 |
+
newResults[docId] = result;
|
| 66 |
+
});
|
| 67 |
+
});
|
| 68 |
+
return {
|
| 69 |
+
citations: {
|
| 70 |
+
...state.citations,
|
| 71 |
+
...(results ? { searchResults: newResults } : {}),
|
| 72 |
+
},
|
| 73 |
+
};
|
| 74 |
+
});
|
| 75 |
+
},
|
| 76 |
+
addCitation(generationId, startEndKey, documents) {
|
| 77 |
+
set((state) => ({
|
| 78 |
+
citations: {
|
| 79 |
+
...state.citations,
|
| 80 |
+
citationReferences: {
|
| 81 |
+
...state.citations.citationReferences,
|
| 82 |
+
[generationId]: {
|
| 83 |
+
...state.citations.citationReferences[generationId],
|
| 84 |
+
[startEndKey]: documents,
|
| 85 |
+
},
|
| 86 |
+
},
|
| 87 |
+
hasCitations: true,
|
| 88 |
+
},
|
| 89 |
+
}));
|
| 90 |
+
},
|
| 91 |
+
selectCitation(citation) {
|
| 92 |
+
set((state) => ({
|
| 93 |
+
citations: {
|
| 94 |
+
...state.citations,
|
| 95 |
+
selectedCitation: citation,
|
| 96 |
+
},
|
| 97 |
+
}));
|
| 98 |
+
},
|
| 99 |
+
hoverCitation(generationId) {
|
| 100 |
+
set((state) => ({
|
| 101 |
+
citations: {
|
| 102 |
+
...state.citations,
|
| 103 |
+
hoveredGenerationId: generationId,
|
| 104 |
+
},
|
| 105 |
+
}));
|
| 106 |
+
},
|
| 107 |
+
resetCitations() {
|
| 108 |
+
set(() => ({
|
| 109 |
+
citations: INITIAL_STATE,
|
| 110 |
+
}));
|
| 111 |
+
},
|
| 112 |
+
saveOutputFiles(outputFiles) {
|
| 113 |
+
set((state) => ({
|
| 114 |
+
citations: {
|
| 115 |
+
...state.citations,
|
| 116 |
+
outputFiles,
|
| 117 |
+
},
|
| 118 |
+
}));
|
| 119 |
+
},
|
| 120 |
+
citations: INITIAL_STATE,
|
| 121 |
+
});
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/conversationSlice.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StateCreator } from 'zustand';
|
| 2 |
+
|
| 3 |
+
import { DEFAULT_CONVERSATION_NAME } from '@/constants';
|
| 4 |
+
import {
|
| 5 |
+
ChatMessage,
|
| 6 |
+
FulfilledMessage,
|
| 7 |
+
LoadingMessage,
|
| 8 |
+
TypingMessage,
|
| 9 |
+
isLoadingMessage,
|
| 10 |
+
isTypingMessage,
|
| 11 |
+
} from '@/types/message';
|
| 12 |
+
|
| 13 |
+
import { StoreState } from '..';
|
| 14 |
+
|
| 15 |
+
const INITIAL_STATE: State = {
|
| 16 |
+
id: undefined,
|
| 17 |
+
name: DEFAULT_CONVERSATION_NAME,
|
| 18 |
+
messages: [],
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
type State = {
|
| 22 |
+
id?: string;
|
| 23 |
+
name?: string;
|
| 24 |
+
messages: ChatMessage[];
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
type Actions = {
|
| 28 |
+
setConversation: (conversation: Partial<State>) => void;
|
| 29 |
+
setPendingMessage: (message: FulfilledMessage | LoadingMessage | TypingMessage | null) => void;
|
| 30 |
+
resetConversation: VoidFunction;
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
export type ConversationStore = {
|
| 34 |
+
conversation: State;
|
| 35 |
+
} & Actions;
|
| 36 |
+
|
| 37 |
+
export const createConversationSlice: StateCreator<StoreState, [], [], ConversationStore> = (
|
| 38 |
+
set
|
| 39 |
+
) => ({
|
| 40 |
+
setConversation(conversation) {
|
| 41 |
+
set((state) => ({
|
| 42 |
+
conversation: {
|
| 43 |
+
...state.conversation,
|
| 44 |
+
...conversation,
|
| 45 |
+
},
|
| 46 |
+
}));
|
| 47 |
+
},
|
| 48 |
+
resetConversation() {
|
| 49 |
+
set(() => ({
|
| 50 |
+
conversation: INITIAL_STATE,
|
| 51 |
+
}));
|
| 52 |
+
},
|
| 53 |
+
setPendingMessage(message) {
|
| 54 |
+
if (!message) {
|
| 55 |
+
set((state) => ({
|
| 56 |
+
conversation: {
|
| 57 |
+
...state.conversation,
|
| 58 |
+
messages: state.conversation.messages.filter((m) => !isLoadingMessage(m)),
|
| 59 |
+
},
|
| 60 |
+
}));
|
| 61 |
+
return;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
set((state) => {
|
| 65 |
+
const messages = state.conversation.messages;
|
| 66 |
+
const newMessages: ChatMessage[] = [];
|
| 67 |
+
let found = false;
|
| 68 |
+
|
| 69 |
+
messages.forEach((m) => {
|
| 70 |
+
if (isTypingMessage(m) || isLoadingMessage(m)) {
|
| 71 |
+
newMessages.push({
|
| 72 |
+
...m,
|
| 73 |
+
...message,
|
| 74 |
+
});
|
| 75 |
+
found = true;
|
| 76 |
+
} else {
|
| 77 |
+
newMessages.push(m);
|
| 78 |
+
}
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
+
return {
|
| 82 |
+
conversation: {
|
| 83 |
+
...state.conversation,
|
| 84 |
+
messages: found ? newMessages : messages.concat(message),
|
| 85 |
+
},
|
| 86 |
+
};
|
| 87 |
+
});
|
| 88 |
+
},
|
| 89 |
+
conversation: INITIAL_STATE,
|
| 90 |
+
});
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/filesSlice.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StateCreator } from 'zustand';
|
| 2 |
+
|
| 3 |
+
import { ListConversationFile as CohereFile } from '@/cohere-client';
|
| 4 |
+
|
| 5 |
+
import { StoreState } from '..';
|
| 6 |
+
|
| 7 |
+
const INITIAL_STATE: State = {
|
| 8 |
+
isFileInputQueuedToFocus: false,
|
| 9 |
+
uploadingFiles: [],
|
| 10 |
+
composerFiles: [],
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
export interface UploadingFile {
|
| 14 |
+
id: string;
|
| 15 |
+
file: File;
|
| 16 |
+
error?: string;
|
| 17 |
+
progress: number;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
type State = {
|
| 21 |
+
isFileInputQueuedToFocus: boolean;
|
| 22 |
+
uploadingFiles: UploadingFile[];
|
| 23 |
+
composerFiles: CohereFile[];
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
type Actions = {
|
| 27 |
+
queueFocusFileInput: () => void;
|
| 28 |
+
clearFocusFileInput: () => void;
|
| 29 |
+
addUploadingFile: (file: UploadingFile) => void;
|
| 30 |
+
addUploadingFiles: (files: UploadingFile[]) => void;
|
| 31 |
+
addComposerFile: (file: CohereFile) => void;
|
| 32 |
+
updateUploadingFileError: (file: UploadingFile, error: string) => void;
|
| 33 |
+
deleteUploadingFile: (id: string) => void;
|
| 34 |
+
deleteComposerFile: (id: string) => void;
|
| 35 |
+
clearUploadingErrors: () => void;
|
| 36 |
+
clearComposerFiles: () => void;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
export type FilesStore = {
|
| 40 |
+
files: State;
|
| 41 |
+
} & Actions;
|
| 42 |
+
|
| 43 |
+
export const createFilesSlice: StateCreator<StoreState, [], [], FilesStore> = (set) => ({
|
| 44 |
+
queueFocusFileInput() {
|
| 45 |
+
set((state) => ({
|
| 46 |
+
files: {
|
| 47 |
+
...state.files,
|
| 48 |
+
isFileInputQueuedToFocus: true,
|
| 49 |
+
},
|
| 50 |
+
}));
|
| 51 |
+
},
|
| 52 |
+
clearFocusFileInput() {
|
| 53 |
+
set((state) => ({
|
| 54 |
+
files: {
|
| 55 |
+
...state.files,
|
| 56 |
+
isFileInputQueuedToFocus: false,
|
| 57 |
+
},
|
| 58 |
+
}));
|
| 59 |
+
},
|
| 60 |
+
addUploadingFile(file) {
|
| 61 |
+
set((state) => ({
|
| 62 |
+
files: {
|
| 63 |
+
...state.files,
|
| 64 |
+
uploadingFiles: [...state.files.uploadingFiles, file],
|
| 65 |
+
},
|
| 66 |
+
}));
|
| 67 |
+
},
|
| 68 |
+
addUploadingFiles(files) {
|
| 69 |
+
set((state) => ({
|
| 70 |
+
files: {
|
| 71 |
+
...state.files,
|
| 72 |
+
uploadingFiles: [...state.files.uploadingFiles, ...files],
|
| 73 |
+
},
|
| 74 |
+
}));
|
| 75 |
+
},
|
| 76 |
+
addComposerFile(file) {
|
| 77 |
+
set((state) => ({
|
| 78 |
+
files: {
|
| 79 |
+
...state.files,
|
| 80 |
+
composerFiles: [...state.files.composerFiles, file],
|
| 81 |
+
},
|
| 82 |
+
}));
|
| 83 |
+
},
|
| 84 |
+
updateUploadingFileError(file, error) {
|
| 85 |
+
set((state) => {
|
| 86 |
+
const newUploadingFiles = [...state.files.uploadingFiles];
|
| 87 |
+
const uploadingFile = newUploadingFiles.find((f) => f.id === file.id);
|
| 88 |
+
if (uploadingFile) {
|
| 89 |
+
uploadingFile.error = error;
|
| 90 |
+
return {
|
| 91 |
+
files: {
|
| 92 |
+
...state.files,
|
| 93 |
+
uploadingFiles: newUploadingFiles,
|
| 94 |
+
},
|
| 95 |
+
};
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
return {};
|
| 99 |
+
});
|
| 100 |
+
},
|
| 101 |
+
deleteUploadingFile(id) {
|
| 102 |
+
set((state) => ({
|
| 103 |
+
files: {
|
| 104 |
+
...state.files,
|
| 105 |
+
uploadingFiles: state.files.uploadingFiles.filter((f) => f.id !== id),
|
| 106 |
+
},
|
| 107 |
+
}));
|
| 108 |
+
},
|
| 109 |
+
deleteComposerFile(id) {
|
| 110 |
+
set((state) => ({
|
| 111 |
+
files: {
|
| 112 |
+
...state.files,
|
| 113 |
+
composerFiles: state.files.composerFiles.filter((f) => f.id !== id),
|
| 114 |
+
},
|
| 115 |
+
}));
|
| 116 |
+
},
|
| 117 |
+
clearUploadingErrors() {
|
| 118 |
+
set((state) => {
|
| 119 |
+
const newUploadingFiles = state.files.uploadingFiles.filter(
|
| 120 |
+
(f) => typeof f.error === 'undefined'
|
| 121 |
+
);
|
| 122 |
+
return {
|
| 123 |
+
files: {
|
| 124 |
+
...state.files,
|
| 125 |
+
uploadingFiles: newUploadingFiles,
|
| 126 |
+
},
|
| 127 |
+
};
|
| 128 |
+
});
|
| 129 |
+
},
|
| 130 |
+
clearComposerFiles() {
|
| 131 |
+
set((state) => ({
|
| 132 |
+
files: {
|
| 133 |
+
...state.files,
|
| 134 |
+
composerFiles: [],
|
| 135 |
+
},
|
| 136 |
+
}));
|
| 137 |
+
},
|
| 138 |
+
files: INITIAL_STATE,
|
| 139 |
+
});
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/paramsSlice.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StateCreator } from 'zustand';
|
| 2 |
+
|
| 3 |
+
import { CohereChatRequest, DEFAULT_CHAT_TEMPERATURE } from '@/cohere-client';
|
| 4 |
+
import { isDefaultFileLoaderTool } from '@/utils';
|
| 5 |
+
|
| 6 |
+
import { StoreState } from '..';
|
| 7 |
+
|
| 8 |
+
const INITIAL_STATE: ConfigurableParams = {
|
| 9 |
+
model: undefined,
|
| 10 |
+
temperature: DEFAULT_CHAT_TEMPERATURE,
|
| 11 |
+
preamble: '',
|
| 12 |
+
tools: [],
|
| 13 |
+
fileIds: [],
|
| 14 |
+
deployment: undefined,
|
| 15 |
+
deploymentConfig: undefined,
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
export type ConfigurableParams = Pick<CohereChatRequest, 'temperature' | 'tools'> & {
|
| 19 |
+
preamble: string;
|
| 20 |
+
fileIds: CohereChatRequest['file_ids'];
|
| 21 |
+
model?: string;
|
| 22 |
+
deployment?: string;
|
| 23 |
+
deploymentConfig?: string;
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
type State = ConfigurableParams;
|
| 27 |
+
type Actions = {
|
| 28 |
+
setParams: (params?: Partial<ConfigurableParams> | null) => void;
|
| 29 |
+
resetFileParams: VoidFunction;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
export type ParamStore = {
|
| 33 |
+
params: State;
|
| 34 |
+
} & Actions;
|
| 35 |
+
|
| 36 |
+
export const createParamsSlice: StateCreator<StoreState, [], [], ParamStore> = (set) => ({
|
| 37 |
+
setParams(params?) {
|
| 38 |
+
let tools = params?.tools;
|
| 39 |
+
let fileIds = params?.fileIds;
|
| 40 |
+
|
| 41 |
+
set((state) => {
|
| 42 |
+
return {
|
| 43 |
+
params: {
|
| 44 |
+
...state.params,
|
| 45 |
+
...params,
|
| 46 |
+
...(tools ? { tools } : []),
|
| 47 |
+
...(fileIds ? { fileIds } : {}),
|
| 48 |
+
},
|
| 49 |
+
};
|
| 50 |
+
});
|
| 51 |
+
},
|
| 52 |
+
resetFileParams() {
|
| 53 |
+
set((state) => {
|
| 54 |
+
return {
|
| 55 |
+
params: {
|
| 56 |
+
...state.params,
|
| 57 |
+
fileIds: [],
|
| 58 |
+
tools: state.params?.tools?.filter((t) => !isDefaultFileLoaderTool(t)),
|
| 59 |
+
},
|
| 60 |
+
};
|
| 61 |
+
});
|
| 62 |
+
},
|
| 63 |
+
params: INITIAL_STATE,
|
| 64 |
+
});
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/stores/slices/settingsSlice.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StateCreator } from 'zustand';
|
| 2 |
+
|
| 3 |
+
const INITIAL_STATE: Required<State> = {
|
| 4 |
+
isConfigDrawerOpen: false,
|
| 5 |
+
activeConfigDrawerTab: '',
|
| 6 |
+
isConvListPanelOpen: true,
|
| 7 |
+
isMobileConvListPanelOpen: false,
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
type State = {
|
| 11 |
+
isConfigDrawerOpen: boolean;
|
| 12 |
+
activeConfigDrawerTab: string;
|
| 13 |
+
isConvListPanelOpen: boolean;
|
| 14 |
+
isMobileConvListPanelOpen: boolean;
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
type Actions = {
|
| 18 |
+
setSettings: (settings: Partial<State>) => void;
|
| 19 |
+
setIsConvListPanelOpen: (isOpen: boolean) => void;
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
export type SettingsStore = {
|
| 23 |
+
settings: State;
|
| 24 |
+
} & Actions;
|
| 25 |
+
|
| 26 |
+
export const createSettingsSlice: StateCreator<SettingsStore, [], [], SettingsStore> = (set) => ({
|
| 27 |
+
setSettings(settings) {
|
| 28 |
+
set((state) => ({
|
| 29 |
+
settings: {
|
| 30 |
+
...state.settings,
|
| 31 |
+
...settings,
|
| 32 |
+
},
|
| 33 |
+
}));
|
| 34 |
+
},
|
| 35 |
+
setIsConvListPanelOpen(isOpen) {
|
| 36 |
+
set((state) => ({
|
| 37 |
+
settings: {
|
| 38 |
+
...state.settings,
|
| 39 |
+
isConvListPanelOpen: isOpen,
|
| 40 |
+
isMobileConvListPanelOpen: isOpen,
|
| 41 |
+
},
|
| 42 |
+
}));
|
| 43 |
+
},
|
| 44 |
+
settings: INITIAL_STATE,
|
| 45 |
+
});
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/code-style.css
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.hljs {
|
| 2 |
+
display: block;
|
| 3 |
+
overflow-x: auto;
|
| 4 |
+
padding: 0.5em;
|
| 5 |
+
color: #212121;
|
| 6 |
+
background: transparent;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
.linenumber {
|
| 10 |
+
color: #556f65;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
.hljs-comment {
|
| 14 |
+
color: #212121;
|
| 15 |
+
font-style: italic;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
.hljs-quote {
|
| 19 |
+
color: #ca492d;
|
| 20 |
+
font-style: italic;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.hljs-keyword {
|
| 24 |
+
color: #2d4cb9;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.hljs-selector-tag {
|
| 28 |
+
color: #afa694;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.hljs-literal {
|
| 32 |
+
color: #9b60aa;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.hljs-subst {
|
| 36 |
+
color: #9b60aa;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.hljs-number {
|
| 40 |
+
color: #39594d;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.hljs-string {
|
| 44 |
+
color: #ca492d;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.hljs-doctag {
|
| 48 |
+
color: #ca492d;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.hljs-selector-id {
|
| 52 |
+
color: #39594d;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.hljs-selector-class {
|
| 56 |
+
color: #39594d;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.hljs-section {
|
| 60 |
+
color: #39594d;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.hljs-type {
|
| 64 |
+
color: #39594d;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.hljs-params {
|
| 68 |
+
color: #9b60aa;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.hljs-title {
|
| 72 |
+
color: #9b60aa;
|
| 73 |
+
font-weight: bold;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.hljs-tag {
|
| 77 |
+
color: #9b60aa;
|
| 78 |
+
font-weight: normal;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.hljs-name {
|
| 82 |
+
color: #9b60aa;
|
| 83 |
+
font-weight: normal;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.hljs-attribute {
|
| 87 |
+
color: #ca492d;
|
| 88 |
+
font-weight: normal;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.hljs-attr {
|
| 92 |
+
color: #9b60aa;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.hljs-variable {
|
| 96 |
+
color: #ca492d;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.hljs-template-variable {
|
| 100 |
+
color: #ca492d;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.hljs-regexp {
|
| 104 |
+
color: #9b60aa;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.hljs-link {
|
| 108 |
+
color: #9b60aa;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.hljs-function {
|
| 112 |
+
color: #9b60aa;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.hljs-symbol {
|
| 116 |
+
color: #990073;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.hljs-bullet {
|
| 120 |
+
color: #990073;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.hljs-built_in {
|
| 124 |
+
color: #39594d;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.hljs-builtin-name {
|
| 128 |
+
color: #2d4cb9;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.hljs-meta {
|
| 132 |
+
color: #39594d;
|
| 133 |
+
font-weight: bold;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.hljs-deletion {
|
| 137 |
+
background: #b20000;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.hljs-addition {
|
| 141 |
+
background: #39594d;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.hljs-emphasis {
|
| 145 |
+
font-style: italic;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.hljs-strong {
|
| 149 |
+
font-weight: bold;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.dark {
|
| 153 |
+
.hljs {
|
| 154 |
+
display: block;
|
| 155 |
+
overflow-x: auto;
|
| 156 |
+
padding: 0.5em;
|
| 157 |
+
color: #eeeeee;
|
| 158 |
+
background: transparent;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.linenumber {
|
| 162 |
+
color: #556f65;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.hljs-comment {
|
| 166 |
+
color: #616161;
|
| 167 |
+
font-style: italic;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.hljs-quote {
|
| 171 |
+
color: #ff7759;
|
| 172 |
+
font-style: italic;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.hljs-keyword {
|
| 176 |
+
color: #77ecc5;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.hljs-selector-tag {
|
| 180 |
+
color: #afa694;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.hljs-literal,
|
| 184 |
+
.hljs-subst {
|
| 185 |
+
color: #e074fb;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
.hljs-number {
|
| 189 |
+
color: #77ecc5;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.hljs-string,
|
| 193 |
+
.hljs-doctag,
|
| 194 |
+
.hljs-variable,
|
| 195 |
+
.hljs-template-variable {
|
| 196 |
+
color: #ff7759;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.hljs-selector-id,
|
| 200 |
+
.hljs-selector-class,
|
| 201 |
+
.hljs-section,
|
| 202 |
+
.hljs-type,
|
| 203 |
+
.hljs-symbol,
|
| 204 |
+
.hljs-builtin-name {
|
| 205 |
+
color: #77ecc5;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.hljs-params,
|
| 209 |
+
.hljs-title,
|
| 210 |
+
.hljs-tag,
|
| 211 |
+
.hljs-name,
|
| 212 |
+
.hljs-attribute,
|
| 213 |
+
.hljs-attr,
|
| 214 |
+
.hljs-regexp,
|
| 215 |
+
.hljs-link,
|
| 216 |
+
.hljs-function,
|
| 217 |
+
.hljs-meta {
|
| 218 |
+
color: #e074fb;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.hljs-title,
|
| 222 |
+
.hljs-strong {
|
| 223 |
+
font-weight: bold;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
.hljs-tag,
|
| 227 |
+
.hljs-name,
|
| 228 |
+
.hljs-attribute,
|
| 229 |
+
.hljs-emphasis {
|
| 230 |
+
font-weight: normal;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
.hljs-regexp,
|
| 234 |
+
.hljs-link,
|
| 235 |
+
.hljs-function,
|
| 236 |
+
.hljs-symbol,
|
| 237 |
+
.hljs-bullet {
|
| 238 |
+
color: #990073;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
.hljs-built_in {
|
| 242 |
+
color: #77ecc5;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
.hljs-meta {
|
| 246 |
+
color: #eeeeee;
|
| 247 |
+
font-weight: bold;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
.hljs-deletion {
|
| 251 |
+
background: #b20000;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.hljs-addition {
|
| 255 |
+
background: #77ecc5;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
.hljs-emphasis {
|
| 259 |
+
font-style: italic;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
.hljs-strong {
|
| 263 |
+
font-weight: bold;
|
| 264 |
+
}
|
| 265 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/fonts.css
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@font-face {
|
| 2 |
+
font-family: 'CohereText';
|
| 3 |
+
src: url('https://fonts.cohere.com/CohereText-Regular.woff2') format('woff2'),
|
| 4 |
+
url('https://fonts.cohere.com/CohereText-Regular.woff') format('woff');
|
| 5 |
+
font-weight: 400;
|
| 6 |
+
font-style: normal;
|
| 7 |
+
font-display: swap;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
@font-face {
|
| 11 |
+
font-family: 'CohereText';
|
| 12 |
+
/* In the nature design system, bolded fonts always use Cohere Variable. */
|
| 13 |
+
src: url('https://fonts.cohere.com/CohereVariable.woff2') format('woff2'),
|
| 14 |
+
url('https://fonts.cohere.com/CohereVariable.woff') format('woff');
|
| 15 |
+
font-weight: 500 525;
|
| 16 |
+
font-style: normal;
|
| 17 |
+
font-display: swap;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
@font-face {
|
| 21 |
+
font-family: 'CohereMono';
|
| 22 |
+
src: url('https://fonts.cohere.com/CohereMono-Regular.woff2') format('woff2'),
|
| 23 |
+
url('https://fonts.cohere.com/CohereMono-Regular.woff') format('woff');
|
| 24 |
+
font-weight: 400;
|
| 25 |
+
font-style: normal;
|
| 26 |
+
font-display: swap;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
@font-face {
|
| 30 |
+
font-family: 'CohereMono';
|
| 31 |
+
/* In the nature design system, bolded fonts always use Cohere Variable. */
|
| 32 |
+
src: url('https://fonts.cohere.com/CohereVariable.woff2') format('woff2'),
|
| 33 |
+
url('https://fonts.cohere.com/CohereVariable.woff') format('woff');
|
| 34 |
+
font-weight: 500 525;
|
| 35 |
+
font-style: normal;
|
| 36 |
+
font-display: swap;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
@font-face {
|
| 40 |
+
font-family: 'CohereVariable';
|
| 41 |
+
src: url('https://fonts.cohere.com/CohereVariable.woff2') format('woff2'),
|
| 42 |
+
url('https://fonts.cohere.com/CohereVariable.woff') format('woff');
|
| 43 |
+
font-weight: 400 420 450;
|
| 44 |
+
font-style: normal;
|
| 45 |
+
font-display: swap;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
@font-face {
|
| 49 |
+
font-family: 'CohereIconDefault';
|
| 50 |
+
src: url('../../public/fonts/CohereIcon-Default.woff') format('woff');
|
| 51 |
+
font-weight: normal;
|
| 52 |
+
font-style: normal;
|
| 53 |
+
font-display: block;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
@font-face {
|
| 57 |
+
font-family: 'CohereIconOutline';
|
| 58 |
+
src: url('../../public/fonts/CohereIcon-Outline.woff') format('woff');
|
| 59 |
+
font-weight: normal;
|
| 60 |
+
font-style: normal;
|
| 61 |
+
font-display: block;
|
| 62 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/globals.css
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@tailwind base;
|
| 2 |
+
@tailwind components;
|
| 3 |
+
@tailwind utilities;
|
| 4 |
+
|
| 5 |
+
body {
|
| 6 |
+
-webkit-font-smoothing: antialiased;
|
| 7 |
+
-moz-osx-font-smoothing: grayscale;
|
| 8 |
+
background-color: theme('colors.marble.1000');
|
| 9 |
+
font-family: theme('fontFamily.body');
|
| 10 |
+
font-size: 16px;
|
| 11 |
+
font-weight: 400;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
/* Google File Picker styles */
|
| 15 |
+
.picker-dialog {
|
| 16 |
+
@apply rounded-lg border !border-marble-800 drop-shadow-2xl;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
@layer utilities {
|
| 20 |
+
.font-cuts-0 {
|
| 21 |
+
font-variation-settings: 'cuts' 0, 'move' 0;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.font-cuts-1 {
|
| 25 |
+
font-variation-settings: 'cuts' 100, 'move' 100;
|
| 26 |
+
font-variant-ligatures: 'common-ligatures';
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.font-cuts-2 {
|
| 30 |
+
font-variation-settings: 'cuts' 200, 'move' 200;
|
| 31 |
+
font-variant-ligatures: 'common-ligatures';
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.font-cuts-3 {
|
| 35 |
+
font-variation-settings: 'cuts' 300, 'move' 300;
|
| 36 |
+
font-variant-ligatures: 'common-ligatures';
|
| 37 |
+
}
|
| 38 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/icons.css
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.icon-default {
|
| 2 |
+
/* use !important to prevent issues with browser extensions that change fonts */
|
| 3 |
+
font-family: 'CohereIconDefault' !important;
|
| 4 |
+
speak: never;
|
| 5 |
+
font-style: normal;
|
| 6 |
+
font-weight: normal;
|
| 7 |
+
font-variant: normal;
|
| 8 |
+
text-transform: none;
|
| 9 |
+
line-height: 1;
|
| 10 |
+
|
| 11 |
+
/* Better Font Rendering =========== */
|
| 12 |
+
-webkit-font-smoothing: antialiased;
|
| 13 |
+
-moz-osx-font-smoothing: grayscale;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.icon-outline {
|
| 17 |
+
/* use !important to prevent issues with browser extensions that change fonts */
|
| 18 |
+
font-family: 'CohereIconOutline' !important;
|
| 19 |
+
speak: never;
|
| 20 |
+
font-style: normal;
|
| 21 |
+
font-weight: normal;
|
| 22 |
+
font-variant: normal;
|
| 23 |
+
text-transform: none;
|
| 24 |
+
line-height: 1;
|
| 25 |
+
|
| 26 |
+
/* Better Font Rendering =========== */
|
| 27 |
+
-webkit-font-smoothing: antialiased;
|
| 28 |
+
-moz-osx-font-smoothing: grayscale;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.icon-add-in-frame:before {
|
| 32 |
+
content: '\e900';
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.icon-add:before {
|
| 36 |
+
content: '\e901';
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.icon-arrow-down:before {
|
| 40 |
+
content: '\e902';
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.icon-arrow-left:before {
|
| 44 |
+
content: '\e903';
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.icon-arrow-right:before {
|
| 48 |
+
content: '\e904';
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.icon-arrow-up:before {
|
| 52 |
+
content: '\e905';
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.icon-arrow-up-right:before {
|
| 56 |
+
content: '\e906';
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.icon-chat:before {
|
| 60 |
+
content: '\e907';
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.icon-check-mark:before {
|
| 64 |
+
content: '\e908';
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.icon-chevron-down:before {
|
| 68 |
+
content: '\e909';
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.icon-chevron-left:before {
|
| 72 |
+
content: '\e90a';
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.icon-chevron-right:before {
|
| 76 |
+
content: '\e90b';
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.icon-chevron-up:before {
|
| 80 |
+
content: '\e90c';
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.icon-close:before {
|
| 84 |
+
content: '\e90d';
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.icon-close-drawer:before {
|
| 88 |
+
content: '\e90e';
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.icon-copy:before {
|
| 92 |
+
content: '\e90f';
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.icon-dashboard:before {
|
| 96 |
+
content: '\e910';
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.icon-edit:before {
|
| 100 |
+
content: '\e911';
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.icon-error:before {
|
| 104 |
+
content: '\e912';
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.icon-file:before {
|
| 108 |
+
content: '\e913';
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.icon-folder:before {
|
| 112 |
+
content: '\e914';
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.icon-fullscreen:before {
|
| 116 |
+
content: '\e915';
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.icon-grid:before {
|
| 120 |
+
content: '\e916';
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.icon-help:before {
|
| 124 |
+
content: '\e917';
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.icon-hide:before {
|
| 128 |
+
content: '\e918';
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.icon-hourglass:before {
|
| 132 |
+
content: '\e919';
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.icon-information:before {
|
| 136 |
+
content: '\e91a';
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.icon-kebab:before {
|
| 140 |
+
content: '\e91b';
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
.icon-key:before {
|
| 144 |
+
content: '\e91c';
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.icon-link:before {
|
| 148 |
+
content: '\e91d';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
.icon-list:before {
|
| 152 |
+
content: '\e91e';
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.icon-menu:before {
|
| 156 |
+
content: '\e91f';
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.icon-notification:before {
|
| 160 |
+
content: '\e920';
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.icon-payment:before {
|
| 164 |
+
content: '\e921';
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
.icon-profile:before {
|
| 168 |
+
content: '\e922';
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
.icon-range:before {
|
| 172 |
+
content: '\e923';
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.icon-reorder:before {
|
| 176 |
+
content: '\e924';
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.icon-search:before {
|
| 180 |
+
content: '\e925';
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.icon-show:before {
|
| 184 |
+
content: '\e926';
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.icon-start-now:before {
|
| 188 |
+
content: '\e927';
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.icon-subtract:before {
|
| 192 |
+
content: '\e928';
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
.icon-success:before {
|
| 196 |
+
content: '\e929';
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.icon-template:before {
|
| 200 |
+
content: '\e92a';
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.icon-trash:before {
|
| 204 |
+
content: '\e92b';
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.icon-upload:before {
|
| 208 |
+
content: '\e92c';
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.icon-warning:before {
|
| 212 |
+
content: '\e92d';
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.icon-thumbs-down:before {
|
| 216 |
+
content: '\e92e';
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.icon-thumbs-up:before {
|
| 220 |
+
content: '\e92f';
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.icon-enter:before {
|
| 224 |
+
content: '\e930';
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.icon-redo:before {
|
| 228 |
+
content: '\e931';
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.icon-new-message:before {
|
| 232 |
+
content: '\e932';
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.icon-sources:before {
|
| 236 |
+
content: '\e933';
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.icon-side-panel:before {
|
| 240 |
+
content: '\e934';
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
.icon-citations:before {
|
| 244 |
+
content: '\e935';
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
.icon-sparkle:before {
|
| 248 |
+
content: '\e936';
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
.icon-web:before {
|
| 252 |
+
content: '\e937';
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
.icon-clip:before {
|
| 256 |
+
content: '\e938';
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
.icon-download:before {
|
| 260 |
+
content: '\e939';
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.icon-pin:before {
|
| 264 |
+
content: '\e93a';
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.icon-calendar:before {
|
| 268 |
+
content: '\e93b';
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.icon-code:before {
|
| 272 |
+
content: '\e93c';
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.icon-globe-stand:before {
|
| 276 |
+
content: '\e93d';
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
.icon-book:before {
|
| 280 |
+
content: '\e93e';
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
.icon-book-open-text:before {
|
| 284 |
+
content: '\e93f';
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.icon-flask:before {
|
| 288 |
+
content: '\e940';
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
.icon-list-magnifying-glass:before {
|
| 292 |
+
content: '\e941';
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
.icon-newspaper:before {
|
| 296 |
+
content: '\e942';
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
.icon-circles-four:before {
|
| 300 |
+
content: '\e943';
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
.icon-calculator:before {
|
| 304 |
+
content: '\e944';
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
.icon-github:before {
|
| 308 |
+
content: '\e945';
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
.icon-at:before {
|
| 312 |
+
content: '\e946';
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.icon-plugs-connected:before {
|
| 316 |
+
content: '\e947';
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.icon-settings:before {
|
| 320 |
+
content: '\e948';
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.icon-magnifying-glass:before {
|
| 324 |
+
content: '\e949';
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.icon-code-block:before {
|
| 328 |
+
content: '\e94a';
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
.icon-compass:before {
|
| 332 |
+
content: '\e94b';
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
.icon-wrench:before {
|
| 336 |
+
content: '\e94c';
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
.icon-share:before {
|
| 340 |
+
content: '\e94d';
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
.icon-selection-slash:before {
|
| 344 |
+
content: '\e94e';
|
| 345 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/styles/main.css
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@tailwind base;
|
| 2 |
+
@tailwind components;
|
| 3 |
+
@tailwind utilities;
|
| 4 |
+
|
| 5 |
+
@import url('./fonts.css');
|
| 6 |
+
@import url('./icons.css');
|
| 7 |
+
@import url('./globals.css');
|
| 8 |
+
@import url('./code-style.css');
|
| 9 |
+
|
| 10 |
+
@layer base {
|
| 11 |
+
html {
|
| 12 |
+
height: 100%;
|
| 13 |
+
width: 100%;
|
| 14 |
+
@apply selection:bg-marble-950 dark:selection:bg-marble-950;
|
| 15 |
+
|
| 16 |
+
/* Firefox */
|
| 17 |
+
scrollbar-color: theme('colors.marble.800') transparent;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
::-webkit-scrollbar {
|
| 21 |
+
@apply h-2.5 w-2.5;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
::-webkit-scrollbar-track {
|
| 25 |
+
@apply bg-transparent;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
::-webkit-scrollbar-thumb {
|
| 29 |
+
box-shadow: inset 0 0 5px 5px rgb(189 189 189 / 0.5); /* marble-500/50 */
|
| 30 |
+
@apply rounded-b-full rounded-t-full border-2 border-solid border-transparent;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
@layer utilities {
|
| 35 |
+
/* @see: https://css-tricks.com/scrollbars-on-hover/ */
|
| 36 |
+
.hide-scrollbar {
|
| 37 |
+
overflow-y: scroll !important;
|
| 38 |
+
mask-position: left bottom;
|
| 39 |
+
mask-size: 100% 20000px;
|
| 40 |
+
mask-image: linear-gradient(to top, transparent, black),
|
| 41 |
+
linear-gradient(to left, transparent 12px, black 12px);
|
| 42 |
+
transition: mask-position 300ms ease;
|
| 43 |
+
transition-duration: 300ms;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.hide-scrollbar:hover,
|
| 47 |
+
.hide-scrollbar:focus {
|
| 48 |
+
mask-position: left top;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* hide recaptcha badge */
|
| 53 |
+
.grecaptcha-badge {
|
| 54 |
+
visibility: hidden;
|
| 55 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/themes/cohereTheme.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const defaultTheme = require('tailwindcss/defaultTheme');
|
| 2 |
+
|
| 3 |
+
// Any changes to the theme should be reflected into our `customTwMerge` in `utils/cn.ts`
|
| 4 |
+
module.exports = {
|
| 5 |
+
theme: {
|
| 6 |
+
extend: {
|
| 7 |
+
colors: {
|
| 8 |
+
black: '#212121',
|
| 9 |
+
white: '#FAFAFA',
|
| 10 |
+
// Simulated Coral
|
| 11 |
+
coral: {
|
| 12 |
+
950: '#FFEAE5',
|
| 13 |
+
900: '#FFD5CC',
|
| 14 |
+
800: '#FFAC99',
|
| 15 |
+
700: '#FF8266',
|
| 16 |
+
600: '#FF5833',
|
| 17 |
+
500: '#FF2F00',
|
| 18 |
+
400: '#CC2500',
|
| 19 |
+
300: '#991C00',
|
| 20 |
+
200: '#661300',
|
| 21 |
+
150: '#330900',
|
| 22 |
+
},
|
| 23 |
+
// Mushroom Grey
|
| 24 |
+
mushroom: {
|
| 25 |
+
950: '#F4F3F0',
|
| 26 |
+
900: '#E9E7E2',
|
| 27 |
+
800: '#D2CDC4',
|
| 28 |
+
700: '#BDB6A8',
|
| 29 |
+
600: '#A79E8B',
|
| 30 |
+
500: '#91856E',
|
| 31 |
+
400: '#70695C',
|
| 32 |
+
300: '#575042',
|
| 33 |
+
200: '#3A352C',
|
| 34 |
+
150: '#2C2821',
|
| 35 |
+
},
|
| 36 |
+
// Evolved Mushroom Grey
|
| 37 |
+
'evolved-mushroom': {
|
| 38 |
+
500: '#FFAA00',
|
| 39 |
+
600: '#FFBB33',
|
| 40 |
+
800: '#FFDC97',
|
| 41 |
+
},
|
| 42 |
+
// Marble White
|
| 43 |
+
marble: {
|
| 44 |
+
1000: '#FFFFFF',
|
| 45 |
+
980: '#F9F9FB',
|
| 46 |
+
950: '#EFEFF5',
|
| 47 |
+
900: '#DFDFEC',
|
| 48 |
+
850: '#D0D0E2',
|
| 49 |
+
800: '#C4C4C4',
|
| 50 |
+
},
|
| 51 |
+
// Volcanic Black
|
| 52 |
+
volcanic: {
|
| 53 |
+
950: '#F2F2F2',
|
| 54 |
+
900: '#E6E6E6',
|
| 55 |
+
800: '#CBCBCB',
|
| 56 |
+
700: '#B3B3B3',
|
| 57 |
+
600: '#999999',
|
| 58 |
+
500: '#808080',
|
| 59 |
+
400: '#666666',
|
| 60 |
+
300: '#4D4D4D',
|
| 61 |
+
200: '#333333',
|
| 62 |
+
150: '#262626',
|
| 63 |
+
100: '#292929',
|
| 64 |
+
60: '#0F0F0F',
|
| 65 |
+
},
|
| 66 |
+
// Coniferous Green
|
| 67 |
+
green: {
|
| 68 |
+
950: '#F0F5F3',
|
| 69 |
+
900: '#E0EBE7',
|
| 70 |
+
800: '#C0D6CD',
|
| 71 |
+
700: '#A2C3B6',
|
| 72 |
+
600: '#84AE9D',
|
| 73 |
+
500: '#659A84',
|
| 74 |
+
400: '#517B6A',
|
| 75 |
+
250: '#324D42',
|
| 76 |
+
200: '#283E35',
|
| 77 |
+
150: '#141F1B',
|
| 78 |
+
},
|
| 79 |
+
// Evolved Coniferous Green
|
| 80 |
+
'evolved-green': {
|
| 81 |
+
500: '#0DF293',
|
| 82 |
+
700: '#6EF7BE',
|
| 83 |
+
900: '#CFFCE9',
|
| 84 |
+
},
|
| 85 |
+
// Synthetic Quartz
|
| 86 |
+
quartz: {
|
| 87 |
+
950: '#F7EBFA',
|
| 88 |
+
900: '#EFD6F5',
|
| 89 |
+
800: '#DDACEA',
|
| 90 |
+
700: '#CE85E0',
|
| 91 |
+
600: '#BD5DD5',
|
| 92 |
+
500: '#AD34CB',
|
| 93 |
+
400: '#8A2AA2',
|
| 94 |
+
300: '#681F7A',
|
| 95 |
+
200: '#451551',
|
| 96 |
+
150: '#34103D',
|
| 97 |
+
},
|
| 98 |
+
// Evolved synthetic quartz
|
| 99 |
+
'evolved-quartz': {
|
| 100 |
+
500: '#C40DF2',
|
| 101 |
+
700: '#DC6EF7',
|
| 102 |
+
900: '#F3CFFC',
|
| 103 |
+
},
|
| 104 |
+
// Acrylic Blue
|
| 105 |
+
blue: {
|
| 106 |
+
950: '#E9EDFC',
|
| 107 |
+
900: '#D2DBF9',
|
| 108 |
+
800: '#A4B5F2',
|
| 109 |
+
700: '#7992EC',
|
| 110 |
+
600: '#4D6EE5',
|
| 111 |
+
500: '#204ADF',
|
| 112 |
+
400: '#193BB2',
|
| 113 |
+
300: '#132C86',
|
| 114 |
+
200: '#0D1D59',
|
| 115 |
+
150: '#0A1643',
|
| 116 |
+
},
|
| 117 |
+
// Evolved Acrylic Blue
|
| 118 |
+
'evolved-blue': {
|
| 119 |
+
500: '#0039FF',
|
| 120 |
+
},
|
| 121 |
+
// Safety Green
|
| 122 |
+
success: {
|
| 123 |
+
950: '#E7FEE9',
|
| 124 |
+
300: '#089113',
|
| 125 |
+
200: '#05610C',
|
| 126 |
+
150: '#044909',
|
| 127 |
+
},
|
| 128 |
+
// Safety Red
|
| 129 |
+
danger: {
|
| 130 |
+
950: '#FFE5E5',
|
| 131 |
+
500: '#FF0000',
|
| 132 |
+
350: '#B30000',
|
| 133 |
+
},
|
| 134 |
+
},
|
| 135 |
+
fontSize: {
|
| 136 |
+
// rem values calculated with a base font of 16px
|
| 137 |
+
caption: ['0.75rem', { letterSpacing: '-0.01em', lineHeight: '136%' }], // 12px - Caption
|
| 138 |
+
'label-sm': ['0.625rem', { letterSpacing: '0.04em', lineHeight: '136%' }], // 10px - Small Label
|
| 139 |
+
label: ['0.75rem', { letterSpacing: '0.04em', lineHeight: '136%' }], // 12px - Label
|
| 140 |
+
overline: ['0.875rem', { letterSpacing: '0.04em', lineHeight: '136%' }], // 14px - Overline
|
| 141 |
+
'p-xs': ['0.625rem', { letterSpacing: '0.0025em', lineHeight: '150%' }], // 10px - XSmall Paragraph
|
| 142 |
+
'p-sm': ['0.75rem', { letterSpacing: '-0.01em', lineHeight: '150%' }], // 12px - Small Paragraph
|
| 143 |
+
p: ['0.875rem', { letterSpacing: '0.0025em', lineHeight: '150%' }], // 14px - Paragraph
|
| 144 |
+
'p-lg': ['1rem', { letterSpacing: '0em', lineHeight: '150%' }], // 16px - Large Paragraph
|
| 145 |
+
code: ['1rem', { letterSpacing: '0.03em', lineHeight: '136%' }], // 16px - Code
|
| 146 |
+
'code-sm': ['0.75rem', { letterSpacing: '0.03em', lineHeight: '136%' }], // 12px - Small Code
|
| 147 |
+
// Headings
|
| 148 |
+
logo: ['1.5rem', { letterSpacing: '0em', lineHeight: '100%' }], // 24px - Logo Application
|
| 149 |
+
'h5-m': ['1.125rem', { letterSpacing: '0em', lineHeight: '136%' }], // 18px - Mobile Heading 5
|
| 150 |
+
h5: ['1.3125rem', { letterSpacing: '0em', lineHeight: '136%' }], // 21px - Desktop Heading 5
|
| 151 |
+
'h4-m': ['1.3125rem', { letterSpacing: '0em', lineHeight: '136%' }], // 21px - Mobile Heading 4
|
| 152 |
+
h4: ['1.75rem', { letterSpacing: '0em', lineHeight: '136%' }], // 28px - Desktop Heading 4
|
| 153 |
+
'h3-m': ['1.75rem', { letterSpacing: '0em', lineHeight: '136%' }], // 28px - Mobile Heading 3
|
| 154 |
+
h3: ['2.375rem', { letterSpacing: '0em', lineHeight: '120%' }], // 38px - Desktop Heading 3
|
| 155 |
+
'h2-m': ['2.375rem', { letterSpacing: '0em', lineHeight: '120%' }], // 38px - Mobile Heading 2
|
| 156 |
+
h2: ['3.1875rem', { letterSpacing: '0em', lineHeight: '116%' }], // 51px - Desktop Heading 2
|
| 157 |
+
'h1-m': ['3.1875rem', { letterSpacing: '0em', lineHeight: '116%' }], // 51px - Mobile Heading 1
|
| 158 |
+
h1: ['4.1875rem', { letterSpacing: '0em', lineHeight: '116%' }], // 67px - Desktop Heading 1
|
| 159 |
+
'icon-sm': ['12px', { lineHeight: '100%' }],
|
| 160 |
+
'icon-md': ['16px', { lineHeight: '100%' }],
|
| 161 |
+
'icon-lg': ['24px', { lineHeight: '100%' }],
|
| 162 |
+
'icon-xl': ['36px', { lineHeight: '100%' }],
|
| 163 |
+
},
|
| 164 |
+
fontFamily: {
|
| 165 |
+
body: ['CohereText', 'Arial', ...defaultTheme.fontFamily.sans],
|
| 166 |
+
variable: ['CohereVariable', 'Arial', ...defaultTheme.fontFamily.serif],
|
| 167 |
+
code: ['CohereMono', ...defaultTheme.fontFamily.mono],
|
| 168 |
+
iconOutline: ['CohereIconOutline'],
|
| 169 |
+
iconDefault: ['CohereIconDefault'],
|
| 170 |
+
},
|
| 171 |
+
fontWeight: {
|
| 172 |
+
// Bolded fonts will always use Cohere Variable with the weight 525
|
| 173 |
+
medium: '525',
|
| 174 |
+
},
|
| 175 |
+
},
|
| 176 |
+
},
|
| 177 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
type Nullable<T> = T | null;
|
| 2 |
+
|
| 3 |
+
declare module 'js-resume-parser' {
|
| 4 |
+
export function getDataFromPDF(file: File): Promise<{ text: string }>;
|
| 5 |
+
export function getDataFromDocx(file: File): Promise<{ text: string }>;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
// from https://github.com/compulim/react-scroll-to-bottom/issues/81 with additions
|
| 9 |
+
declare module 'react-scroll-to-bottom' {
|
| 10 |
+
import * as React from 'react';
|
| 11 |
+
|
| 12 |
+
interface ReactScrollToBottomProps {
|
| 13 |
+
checkInterval?: number;
|
| 14 |
+
className?: string;
|
| 15 |
+
debounce?: number;
|
| 16 |
+
followButtonClassName?: string;
|
| 17 |
+
mode?: string;
|
| 18 |
+
scrollViewClassName?: string;
|
| 19 |
+
children: React.ReactNode;
|
| 20 |
+
debug?: boolean;
|
| 21 |
+
initialScrollBehavior?: 'smooth' | 'auto';
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
interface ScrollOptions {
|
| 25 |
+
behavior: ScrollBehavior;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
interface FunctionContextProps {
|
| 29 |
+
scrollTo: (scrollTo: number, options: ScrollOptions) => void;
|
| 30 |
+
scrollToBottom: (options: ScrollOptions) => void;
|
| 31 |
+
scrollToEnd: (options: ScrollOptions) => void;
|
| 32 |
+
scrollToStart: (options: ScrollOptions) => void;
|
| 33 |
+
scrollToTop: (options: ScrollOptions) => void;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export const useScrollToBottom: () => FunctionContextProps.scrollToBottom;
|
| 37 |
+
export const useAtTop: () => [boolean];
|
| 38 |
+
export const useSticky: () => [boolean];
|
| 39 |
+
|
| 40 |
+
const FunctionContext: React.Context<FunctionContextProps>;
|
| 41 |
+
|
| 42 |
+
export default class ScrollToBottom extends React.PureComponent<ReactScrollToBottomProps> {}
|
| 43 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/message.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
Citation,
|
| 3 |
+
ListConversationFile,
|
| 4 |
+
StreamToolCallsGeneration,
|
| 5 |
+
StreamToolInput,
|
| 6 |
+
} from '@/cohere-client';
|
| 7 |
+
|
| 8 |
+
export enum BotState {
|
| 9 |
+
LOADING = 'loading',
|
| 10 |
+
TYPING = 'typing',
|
| 11 |
+
FULFILLED = 'fulfilled',
|
| 12 |
+
ERROR = 'error',
|
| 13 |
+
ABORTED = 'aborted',
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export enum MessageType {
|
| 17 |
+
BOT = 'bot',
|
| 18 |
+
USER = 'user',
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
type BaseMessage = {
|
| 22 |
+
type: MessageType;
|
| 23 |
+
text: string;
|
| 24 |
+
error?: string;
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* This is a bot-only state for all past bot messages that have been returned from the server.
|
| 29 |
+
*/
|
| 30 |
+
export type FulfilledMessage = BaseMessage & {
|
| 31 |
+
type: MessageType.BOT;
|
| 32 |
+
state: BotState.FULFILLED;
|
| 33 |
+
/**
|
| 34 |
+
* Unique Id per generation for given responseId
|
| 35 |
+
* A responseId can have multiple generations
|
| 36 |
+
*/
|
| 37 |
+
generationId: string;
|
| 38 |
+
/* This id links a particular message to a piece of feedback given by the user. */
|
| 39 |
+
feedbackId?: string;
|
| 40 |
+
goodResponse?: boolean;
|
| 41 |
+
citations?: Citation[];
|
| 42 |
+
isRAGOn?: boolean;
|
| 43 |
+
originalText: string;
|
| 44 |
+
toolEvents?: StreamToolCallsGeneration[];
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* This is a bot-only state for when a message is aborted.
|
| 49 |
+
*/
|
| 50 |
+
export type AbortedMessage = BaseMessage & {
|
| 51 |
+
type: MessageType.BOT;
|
| 52 |
+
state: BotState.ABORTED;
|
| 53 |
+
toolEvents?: StreamToolCallsGeneration[];
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* This is a bot-only state for when we wait for the bot's first token to arrive.
|
| 58 |
+
*/
|
| 59 |
+
export type LoadingMessage = BaseMessage & {
|
| 60 |
+
type: MessageType.BOT;
|
| 61 |
+
state: BotState.LOADING;
|
| 62 |
+
isRAGOn?: boolean;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* This is a bot-only state for when we are streaming in tokens.
|
| 67 |
+
*/
|
| 68 |
+
export type TypingMessage = BaseMessage & {
|
| 69 |
+
type: MessageType.BOT;
|
| 70 |
+
state: BotState.TYPING;
|
| 71 |
+
generationId: string;
|
| 72 |
+
originalText: string;
|
| 73 |
+
citations?: Citation[];
|
| 74 |
+
isRAGOn?: boolean;
|
| 75 |
+
toolEvents?: StreamToolCallsGeneration[];
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* This is a bot-only state for when there is an error from the server.
|
| 80 |
+
*/
|
| 81 |
+
export type ErrorMessage = BaseMessage & {
|
| 82 |
+
type: MessageType.BOT;
|
| 83 |
+
state: BotState.ERROR;
|
| 84 |
+
toolEvents?: StreamToolInput[];
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Message sent from the user.
|
| 89 |
+
*/
|
| 90 |
+
export type UserMessage = BaseMessage & {
|
| 91 |
+
type: MessageType.USER;
|
| 92 |
+
files?: ListConversationFile[];
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
export type ChatMessage = UserMessage | BotMessage;
|
| 96 |
+
|
| 97 |
+
export type BotMessage =
|
| 98 |
+
| LoadingMessage
|
| 99 |
+
| TypingMessage
|
| 100 |
+
| FulfilledMessage
|
| 101 |
+
| ErrorMessage
|
| 102 |
+
| AbortedMessage;
|
| 103 |
+
|
| 104 |
+
export type StreamingMessage = FulfilledMessage | TypingMessage | LoadingMessage;
|
| 105 |
+
|
| 106 |
+
export const isUserMessage = (message: ChatMessage): message is UserMessage => {
|
| 107 |
+
return message.type === MessageType.USER;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
export const isFulfilledMessage = (message: ChatMessage): message is FulfilledMessage => {
|
| 111 |
+
return message.type === MessageType.BOT && message.state === BotState.FULFILLED;
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
export const isErroredMessage = (message: ChatMessage): message is ErrorMessage => {
|
| 115 |
+
return message.type == MessageType.BOT && message.state === BotState.ERROR;
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
export const isTypingMessage = (message: ChatMessage): message is TypingMessage => {
|
| 119 |
+
return message.type === MessageType.BOT && message.state === BotState.TYPING;
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
export const isLoadingMessage = (message: ChatMessage): message is TypingMessage => {
|
| 123 |
+
return message.type === MessageType.BOT && message.state === BotState.LOADING;
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
export const isAbortedMessage = (message: ChatMessage): message is AbortedMessage => {
|
| 127 |
+
return message.type === MessageType.BOT && message.state === BotState.ABORTED;
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
export const isFulfilledOrTypingMessage = (
|
| 131 |
+
message: ChatMessage
|
| 132 |
+
): message is FulfilledMessage | TypingMessage => {
|
| 133 |
+
return isFulfilledMessage(message) || isTypingMessage(message);
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
export const isFulfilledOrTypingMessageWithCitations = (
|
| 137 |
+
m: ChatMessage
|
| 138 |
+
): m is FulfilledMessage | (TypingMessage & Required<Pick<FulfilledMessage, 'citations'>>) =>
|
| 139 |
+
m && isFulfilledOrTypingMessage(m) && !!m.citations && m.citations.length > 0;
|
| 140 |
+
|
| 141 |
+
export const createErrorMessage = (message: Omit<ErrorMessage, 'type' | 'state'>): ErrorMessage => {
|
| 142 |
+
return {
|
| 143 |
+
...message,
|
| 144 |
+
type: MessageType.BOT,
|
| 145 |
+
state: BotState.ERROR,
|
| 146 |
+
};
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
export const createAbortedMessage = (
|
| 150 |
+
message: Omit<AbortedMessage, 'type' | 'state'>
|
| 151 |
+
): AbortedMessage => {
|
| 152 |
+
return {
|
| 153 |
+
...message,
|
| 154 |
+
type: MessageType.BOT,
|
| 155 |
+
state: BotState.ABORTED,
|
| 156 |
+
};
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
export const createLoadingMessage = (
|
| 160 |
+
message: Omit<LoadingMessage, 'type' | 'state'>
|
| 161 |
+
): LoadingMessage => {
|
| 162 |
+
return {
|
| 163 |
+
...message,
|
| 164 |
+
type: MessageType.BOT,
|
| 165 |
+
state: BotState.LOADING,
|
| 166 |
+
};
|
| 167 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/tools.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type GoogleDriveToolArtifact = {
|
| 2 |
+
type: string;
|
| 3 |
+
id: string;
|
| 4 |
+
name: string;
|
| 5 |
+
url: string;
|
| 6 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/types/util.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type NoNullProperties<Type> = {
|
| 2 |
+
[Property in keyof Type]-?: NonNullable<Type[Property]>;
|
| 3 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/citations.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Citation } from '@/cohere-client';
|
| 2 |
+
import { DYNAMIC_STRINGS } from '@/constants/strings';
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* @description Helper function to temporarily ensure markdown image syntax provided by the model is correct.
|
| 6 |
+
* This is a temporary fix as the current model is consistently returning incorrect markdown image syntax.
|
| 7 |
+
* @param text - message text or citation text
|
| 8 |
+
*/
|
| 9 |
+
export const fixMarkdownImagesInText = (text: string) => {
|
| 10 |
+
return text.replace('! [', '![');
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Replace text string with citations following the format:
|
| 17 |
+
* :cite[<text>]{generationId="<generationId>" start="<startIndex>" end"<endIndex>"}
|
| 18 |
+
* @param text
|
| 19 |
+
* @param citations
|
| 20 |
+
* @param generationId
|
| 21 |
+
* @returns text with citations
|
| 22 |
+
*/
|
| 23 |
+
export const replaceTextWithCitations = (
|
| 24 |
+
text: string,
|
| 25 |
+
citations: Citation[],
|
| 26 |
+
generationId: string
|
| 27 |
+
) => {
|
| 28 |
+
if (!citations.length || !generationId) return text;
|
| 29 |
+
let replacedText = text;
|
| 30 |
+
|
| 31 |
+
let lengthDifference = 0; // Track the cumulative length difference
|
| 32 |
+
let notFoundReferences: string[] = [];
|
| 33 |
+
citations.forEach(({ start = 0, end = 0, text: citationText }, index) => {
|
| 34 |
+
const citeStart = start + lengthDifference;
|
| 35 |
+
const citeEnd = end + lengthDifference;
|
| 36 |
+
|
| 37 |
+
// if citeStart is higher than the length of the text, add it to the bottom of the text as "Reference #n"
|
| 38 |
+
if (start >= text.length || isReferenceBetweenIframes(replacedText, start)) {
|
| 39 |
+
const ref = DYNAMIC_STRINGS.referenceNumber(index + 1);
|
| 40 |
+
notFoundReferences.push(
|
| 41 |
+
`:cite[${ref}]{generationId="${generationId}" start="${start}" end="${end}"}`
|
| 42 |
+
);
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const fixedText = fixMarkdownImagesInText(citationText);
|
| 47 |
+
|
| 48 |
+
// Encode the citationText in case there are any weird characters or unclosed brackets that will
|
| 49 |
+
// interfere with parsing the markdown. However, let markdown images through so they may be properly
|
| 50 |
+
// rendered.
|
| 51 |
+
const isMarkdownImage = fixedText.match(/!\[.*\]\(.*\)/);
|
| 52 |
+
const encodedCitationText = isMarkdownImage ? fixedText : encodeURIComponent(fixedText);
|
| 53 |
+
const citationId = `:cite[${encodedCitationText}]{generationId="${generationId}" start="${start}" end="${end}"}`;
|
| 54 |
+
|
| 55 |
+
replacedText = replacedText.slice(0, citeStart) + citationId + replacedText.slice(citeEnd);
|
| 56 |
+
lengthDifference += citationId.length - (citeEnd - citeStart);
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
const references = DYNAMIC_STRINGS.fromReferences(formatter.format(notFoundReferences));
|
| 60 |
+
if (notFoundReferences.length > 0) {
|
| 61 |
+
return references + '\n' + replacedText;
|
| 62 |
+
}
|
| 63 |
+
return replacedText;
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
export const createStartEndKey = (start: number | string, end: number | string) =>
|
| 67 |
+
`${start}-${end}`;
|
| 68 |
+
|
| 69 |
+
function isReferenceBetweenIframes(replacedText: string, citeStart: number): boolean {
|
| 70 |
+
const IFRAME_REGEX = /<iframe.*<\/iframe>/g;
|
| 71 |
+
const match = IFRAME_REGEX.exec(replacedText);
|
| 72 |
+
|
| 73 |
+
if (!match) return false;
|
| 74 |
+
|
| 75 |
+
return match.index < citeStart && citeStart < match.index + match[0].length;
|
| 76 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/cn.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cx from 'classnames';
|
| 2 |
+
import { extendTailwindMerge } from 'tailwind-merge';
|
| 3 |
+
|
| 4 |
+
const customTwMerge = extendTailwindMerge({
|
| 5 |
+
// @see: https://github.com/dcastil/tailwind-merge/blob/v1.14.0/docs/configuration.md#class-groups
|
| 6 |
+
classGroups: {
|
| 7 |
+
'font-size': [
|
| 8 |
+
{
|
| 9 |
+
text: [
|
| 10 |
+
'caption',
|
| 11 |
+
'label-sm',
|
| 12 |
+
'label',
|
| 13 |
+
'overline',
|
| 14 |
+
'p-xs',
|
| 15 |
+
'p-sm',
|
| 16 |
+
'p',
|
| 17 |
+
'p-lg',
|
| 18 |
+
'code',
|
| 19 |
+
'logo',
|
| 20 |
+
'h5',
|
| 21 |
+
'h5-m',
|
| 22 |
+
'h4',
|
| 23 |
+
'h4-m',
|
| 24 |
+
'h3',
|
| 25 |
+
'h3-m',
|
| 26 |
+
'h2',
|
| 27 |
+
'h2-m',
|
| 28 |
+
'h1',
|
| 29 |
+
'h1-m',
|
| 30 |
+
],
|
| 31 |
+
},
|
| 32 |
+
],
|
| 33 |
+
'min-w': [
|
| 34 |
+
{
|
| 35 |
+
'min-w': [
|
| 36 |
+
'citation-panel-md',
|
| 37 |
+
'citation-panel-lg',
|
| 38 |
+
'citation-panel-xl',
|
| 39 |
+
'menu',
|
| 40 |
+
'left-panel-lg',
|
| 41 |
+
'left-panel-2xl',
|
| 42 |
+
'left-panel-3xl',
|
| 43 |
+
],
|
| 44 |
+
},
|
| 45 |
+
],
|
| 46 |
+
'max-w': [
|
| 47 |
+
{
|
| 48 |
+
'max-w': [
|
| 49 |
+
'modal-xs',
|
| 50 |
+
'modal-sm',
|
| 51 |
+
'modal-md',
|
| 52 |
+
'modal',
|
| 53 |
+
'modal-lg',
|
| 54 |
+
'modal-xl',
|
| 55 |
+
'container',
|
| 56 |
+
'page',
|
| 57 |
+
'drawer',
|
| 58 |
+
'drawer-lg',
|
| 59 |
+
],
|
| 60 |
+
},
|
| 61 |
+
],
|
| 62 |
+
z: [{ z: ['navigation', 'modal', 'dropdown', 'toast'] }],
|
| 63 |
+
w: [
|
| 64 |
+
{
|
| 65 |
+
w: [
|
| 66 |
+
'modal',
|
| 67 |
+
'ep-icon-sm',
|
| 68 |
+
'ep-icon-md',
|
| 69 |
+
'ep-icon-lg',
|
| 70 |
+
'ep-icon-xl',
|
| 71 |
+
'btn-sm',
|
| 72 |
+
'btn-md',
|
| 73 |
+
'btn-lg',
|
| 74 |
+
'btn-xl',
|
| 75 |
+
],
|
| 76 |
+
},
|
| 77 |
+
],
|
| 78 |
+
h: [{ h: ['ep-icon-sm', 'ep-icon-md', 'ep-icon-lg', 'ep-icon-xl'] }],
|
| 79 |
+
'max-h': [{ 'max-h': ['cell-xs', 'cell-sm', 'cell-md', 'cell-lg', 'cell-xl'] }],
|
| 80 |
+
'min-h': [{ 'min-h': ['cell-xs', 'cell-sm', 'cell-md', 'cell-lg', 'cell-xl'] }],
|
| 81 |
+
},
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* Combines classnames with tailwind-merge
|
| 86 |
+
*/
|
| 87 |
+
export function cn(...inputs: cx.ArgumentArray) {
|
| 88 |
+
return customTwMerge(cx(inputs));
|
| 89 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/conversation.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Message, MessageAgent } from '@/cohere-client';
|
| 2 |
+
import { BotState, ChatMessage, FulfilledMessage, MessageType, UserMessage } from '@/types/message';
|
| 3 |
+
import { replaceTextWithCitations } from '@/utils/citations';
|
| 4 |
+
import { replaceCodeBlockWithIframe } from '@/utils/preview';
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* A utility function that checks if the conversation title should be updated
|
| 8 |
+
* Based on:
|
| 9 |
+
* - It has only two messages, one from the user and one from the bot.
|
| 10 |
+
* - If ~5 turns have passed, meaning every 5 messages from the bot.
|
| 11 |
+
* - Note: the bot can fail to respond and these turns can become out of sync but 5 bot messages
|
| 12 |
+
* implies that there were at least 5 matching user messages (user message === request, bot message === response pairs)
|
| 13 |
+
* @param messages - The messages array
|
| 14 |
+
* */
|
| 15 |
+
export const shouldUpdateConversationTitle = (messages: ChatMessage[]) => {
|
| 16 |
+
const numUserMessages = messages.filter(
|
| 17 |
+
(message) => message.type === MessageType.USER && !message.error
|
| 18 |
+
).length;
|
| 19 |
+
const numBotMessages = messages.filter(
|
| 20 |
+
(message) => message.type === MessageType.BOT && message.state === BotState.FULFILLED
|
| 21 |
+
).length;
|
| 22 |
+
|
| 23 |
+
if (numUserMessages === 1 && numBotMessages === 1) {
|
| 24 |
+
return true;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return numBotMessages % 5 === 0;
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
export type UserOrBotMessage = UserMessage | FulfilledMessage;
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* @description Maps chat history given by the API to a list of messages that can be displayed in the chat.
|
| 34 |
+
*/
|
| 35 |
+
export const mapHistoryToMessages = (history?: Message[]): UserOrBotMessage[] => {
|
| 36 |
+
if (!history) return [];
|
| 37 |
+
|
| 38 |
+
let messages: UserOrBotMessage[] = [];
|
| 39 |
+
let tempToolEvents: FulfilledMessage['toolEvents'];
|
| 40 |
+
|
| 41 |
+
for (const message of history) {
|
| 42 |
+
if (message.agent === MessageAgent.CHATBOT) {
|
| 43 |
+
if (!message.tool_plan) {
|
| 44 |
+
messages.push({
|
| 45 |
+
type: MessageType.BOT,
|
| 46 |
+
state: BotState.FULFILLED,
|
| 47 |
+
originalText: message.text ?? '',
|
| 48 |
+
text: replaceTextWithCitations(
|
| 49 |
+
replaceCodeBlockWithIframe(message.text) ?? '',
|
| 50 |
+
message.citations ?? [],
|
| 51 |
+
message.generation_id ?? ''
|
| 52 |
+
),
|
| 53 |
+
generationId: message.generation_id ?? '',
|
| 54 |
+
citations: message.citations,
|
| 55 |
+
toolEvents: tempToolEvents,
|
| 56 |
+
});
|
| 57 |
+
tempToolEvents = undefined;
|
| 58 |
+
} else {
|
| 59 |
+
// Historical tool events come in as chatbot messages before the actual final response message.
|
| 60 |
+
if (tempToolEvents) {
|
| 61 |
+
tempToolEvents.push({
|
| 62 |
+
text: message.tool_plan,
|
| 63 |
+
tool_calls: message.tool_calls,
|
| 64 |
+
});
|
| 65 |
+
} else {
|
| 66 |
+
tempToolEvents = [{ text: message.tool_plan, tool_calls: message.tool_calls }];
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
} else {
|
| 70 |
+
messages.push({
|
| 71 |
+
type: MessageType.USER,
|
| 72 |
+
text: replaceTextWithCitations(
|
| 73 |
+
message.text ?? '',
|
| 74 |
+
message.citations ?? [],
|
| 75 |
+
message.generation_id ?? ''
|
| 76 |
+
),
|
| 77 |
+
files: message.files,
|
| 78 |
+
});
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return messages;
|
| 83 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/delimiters.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Simple helper to check if a string has common delimiters. For now this is only looking for commas.
|
| 3 |
+
*/
|
| 4 |
+
export const hasCommonDelimiters = (str: string): boolean => {
|
| 5 |
+
return str.includes(',');
|
| 6 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/download.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type StructuredTable = {
|
| 2 |
+
header: string[];
|
| 3 |
+
rows: string[][];
|
| 4 |
+
};
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* A client-side function that triggers a file download in the user's browser.
|
| 8 |
+
* Note: This creates a temporary <a /> tag in the document body and simulates a click on it which may not always work
|
| 9 |
+
* https://stackoverflow.com/questions/50694881/how-to-download-file-in-react-js/50695407#50695407
|
| 10 |
+
*
|
| 11 |
+
* @param fileName The name of the file
|
| 12 |
+
* @param parts Data that will comprise the file
|
| 13 |
+
* @param type MIME-type of the data
|
| 14 |
+
*
|
| 15 |
+
* @returns True If the download was successful, else False
|
| 16 |
+
*/
|
| 17 |
+
export function downloadFile(
|
| 18 |
+
fileName: string,
|
| 19 |
+
parts: BlobPart[],
|
| 20 |
+
type: string = 'text/plain'
|
| 21 |
+
): boolean {
|
| 22 |
+
if (window === null || window === undefined || document === null || document === undefined) {
|
| 23 |
+
return false;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
const file = new File(parts, fileName, { type: type });
|
| 27 |
+
const link = document.createElement('a');
|
| 28 |
+
const url = URL.createObjectURL(file);
|
| 29 |
+
|
| 30 |
+
try {
|
| 31 |
+
link.href = url;
|
| 32 |
+
link.download = file.name;
|
| 33 |
+
document.body.appendChild(link);
|
| 34 |
+
link.click();
|
| 35 |
+
// schedule a removal in the next event loop
|
| 36 |
+
setTimeout(() => {
|
| 37 |
+
document.body.removeChild(link);
|
| 38 |
+
window.URL.revokeObjectURL(url);
|
| 39 |
+
}, 0);
|
| 40 |
+
} catch (e) {
|
| 41 |
+
return false;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return true;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Converts an object of type StructuredTable into a string representation of an XSV
|
| 49 |
+
*
|
| 50 |
+
* Ex 1: Using the delimiter ',' will result in a CSV file (comma seperated)
|
| 51 |
+
* Ex 2: Using the delimiter '\t' will result in a TSV file (tab seperated)
|
| 52 |
+
* @param table An object of type StructuredTable
|
| 53 |
+
* @param delimiter A delimiter for the XSV (ex: ',' or '\t')
|
| 54 |
+
*/
|
| 55 |
+
export function structuredTableToXSV(
|
| 56 |
+
table: StructuredTable | null,
|
| 57 |
+
delimiter: string = ','
|
| 58 |
+
): string | null {
|
| 59 |
+
if (!table || table.header.length === 0 || table.rows.length === 0) return null;
|
| 60 |
+
|
| 61 |
+
let xsv = '';
|
| 62 |
+
table.header.forEach(
|
| 63 |
+
(txt, i) => (xsv += `"${txt}"${i < table.header.length - 1 ? delimiter : ''}`)
|
| 64 |
+
);
|
| 65 |
+
xsv += '\n';
|
| 66 |
+
table.rows.forEach((row) => {
|
| 67 |
+
row.forEach((txt, i) => (xsv += `"${txt}"${i < row.length - 1 ? delimiter : ''}`));
|
| 68 |
+
xsv += '\n';
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
return xsv;
|
| 72 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/error.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { CohereNetworkError } from '@/cohere-client';
|
| 2 |
+
|
| 3 |
+
export const isAbortError = (error: unknown) => {
|
| 4 |
+
return error instanceof DOMException && error.name === 'AbortError';
|
| 5 |
+
};
|
| 6 |
+
|
| 7 |
+
export const isShareLinkExpiredError = (error: unknown): error is CohereNetworkError =>
|
| 8 |
+
error instanceof CohereNetworkError &&
|
| 9 |
+
error.status === 404 &&
|
| 10 |
+
error.message === 'snapshot link has expired';
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Wraps a promise and always returns an array with the first element being the data and the second element the error.
|
| 14 |
+
* If the promise errors out, the data element will be null while the error element while have a value (and vice-versa).
|
| 15 |
+
* @param promiseVar A promise
|
| 16 |
+
*
|
| 17 |
+
* @example
|
| 18 |
+
* let [data, err] = await safeAsync(GetSomeData());
|
| 19 |
+
* if (err === null) {
|
| 20 |
+
* useTheData(data);
|
| 21 |
+
* }
|
| 22 |
+
*/
|
| 23 |
+
export async function safeAsync<T>(promiseVar: Promise<T>): Promise<[T | null, Error | null]> {
|
| 24 |
+
try {
|
| 25 |
+
const data = await promiseVar;
|
| 26 |
+
return [data, null];
|
| 27 |
+
} catch (e) {
|
| 28 |
+
return [null, e as Error];
|
| 29 |
+
}
|
| 30 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/file.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { FILE_TOOL_CATEGORY, ToolDefinition } from '@/cohere-client';
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Gets the file extension from its name.
|
| 5 |
+
* @param filename
|
| 6 |
+
* @returns file extension e.g. .pdf or .txt
|
| 7 |
+
*/
|
| 8 |
+
export const getFileExtension = (filename: string): string | undefined => {
|
| 9 |
+
const ext = filename.split('.').pop();
|
| 10 |
+
return ext ? `.${ext}` : undefined;
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* Generate a random number between min and max.
|
| 15 |
+
* @param min
|
| 16 |
+
* @param max
|
| 17 |
+
* @returns random number between min and max
|
| 18 |
+
*/
|
| 19 |
+
export const getRandomNumberInBetween = (min: number, max: number) => {
|
| 20 |
+
return Math.floor(Math.random() * (max - min) + min);
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Estimate the upload time in ms based on the file size.
|
| 25 |
+
* This equation estimates upload speed using a least squares regression of some existing data points with various file sizes.
|
| 26 |
+
* 18MB, 60 seconds,
|
| 27 |
+
* 12MB, 45 seconds,
|
| 28 |
+
* 8.7MB, 32 seconds,
|
| 29 |
+
* 6MB, 23 seconds,
|
| 30 |
+
* 4.3MB, 12 seconds,
|
| 31 |
+
* 1.9MB, 4.8 seconds,
|
| 32 |
+
* 1.1MB, 3 seconds,
|
| 33 |
+
* 350KB, 1.51 seconds
|
| 34 |
+
* @param fileSizeInBytes
|
| 35 |
+
* @returns random number between min and max
|
| 36 |
+
*/
|
| 37 |
+
export const getFileUploadTimeEstimateInMs = (fileSizeInBytes: number) => {
|
| 38 |
+
// This equation estimates upload speed based on some existing data points with various file sizes.
|
| 39 |
+
return ((3.51 * fileSizeInBytes) / 1000000 - 0.3) * 1000;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* @description Determines if a tool is the default file loader tool.
|
| 44 |
+
*/
|
| 45 |
+
export const isDefaultFileLoaderTool = (t: ToolDefinition) =>
|
| 46 |
+
t.category === FILE_TOOL_CATEGORY && t.is_visible;
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/format.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { DYNAMIC_STRINGS } from '@/constants/strings';
|
| 2 |
+
import { pluralize } from '@/utils';
|
| 3 |
+
|
| 4 |
+
const WEEK_IN_MILLIS = 7 * 24 * 60 * 60 * 1000;
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Returns the number of weeks ago and a string representation of the number of weeks ago.
|
| 8 |
+
*/
|
| 9 |
+
export const getWeeksAgo = (date: string | Date): { weeksAgo: number; weeksAgoStr: string } => {
|
| 10 |
+
const now = new Date();
|
| 11 |
+
const diffInMillis = now.getTime() - new Date(date).getTime();
|
| 12 |
+
const weeksAgo = Math.floor(diffInMillis / WEEK_IN_MILLIS);
|
| 13 |
+
const weeksAgoStr = DYNAMIC_STRINGS.weeksAgo(weeksAgo);
|
| 14 |
+
|
| 15 |
+
return {
|
| 16 |
+
weeksAgo,
|
| 17 |
+
weeksAgoStr,
|
| 18 |
+
};
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Converts a file size in megabytes to bytes
|
| 23 |
+
*/
|
| 24 |
+
export const fileSizeToBytes = (size: number): number => {
|
| 25 |
+
return size * 1024 * 1024;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Converts a file size in bytes to megabytes
|
| 30 |
+
* */
|
| 31 |
+
export const fileSizeToMB = (size: number): number => {
|
| 32 |
+
return size / 1024 / 1024;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Returns file size with units e.g. 10 bytes, 10 KB, 10 MB
|
| 37 |
+
* Only works for bytes, KB, and MB
|
| 38 |
+
* Add additional units as needed
|
| 39 |
+
*/
|
| 40 |
+
export const formatFileSize = (bytes: number): string => {
|
| 41 |
+
const kb = 1024;
|
| 42 |
+
const mb = kb * 1024;
|
| 43 |
+
|
| 44 |
+
if (bytes < kb) {
|
| 45 |
+
return DYNAMIC_STRINGS.numBytes(bytes);
|
| 46 |
+
} else if (bytes < mb) {
|
| 47 |
+
return DYNAMIC_STRINGS.numKB((bytes / kb).toFixed(1));
|
| 48 |
+
} else {
|
| 49 |
+
return DYNAMIC_STRINGS.numMB((bytes / mb).toFixed(1));
|
| 50 |
+
}
|
| 51 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/getCohereColor.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const BG_COLOR_LIST = [
|
| 2 |
+
'bg-quartz-700',
|
| 3 |
+
'bg-green-600',
|
| 4 |
+
'bg-coral-500',
|
| 5 |
+
'bg-quartz-700',
|
| 6 |
+
'bg-green-250',
|
| 7 |
+
'bg-coral-700',
|
| 8 |
+
];
|
| 9 |
+
|
| 10 |
+
const TEXT_COLOR_LIST = [
|
| 11 |
+
'text-quartz-700',
|
| 12 |
+
'text-green-600',
|
| 13 |
+
'text-coral-500',
|
| 14 |
+
'text-quartz-700',
|
| 15 |
+
'text-green-250',
|
| 16 |
+
'text-coral-700',
|
| 17 |
+
];
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* @description Get a color from the Cohere color palette, when no index is provided, a random color is returned
|
| 21 |
+
* @param id - id for generating a constant color in the palette
|
| 22 |
+
* @param background - if true, returns a background color, otherwise returns a text color
|
| 23 |
+
* @returns color from the Cohere color palette
|
| 24 |
+
*/
|
| 25 |
+
export const getCohereColor = (
|
| 26 |
+
id?: string,
|
| 27 |
+
options: { background?: boolean } = { background: true }
|
| 28 |
+
) => {
|
| 29 |
+
const COLOR_LIST = options?.background ? BG_COLOR_LIST : TEXT_COLOR_LIST;
|
| 30 |
+
if (id === undefined) {
|
| 31 |
+
const randomIndex = Math.floor(Math.random() * COLOR_LIST.length);
|
| 32 |
+
|
| 33 |
+
return COLOR_LIST[randomIndex];
|
| 34 |
+
}
|
| 35 |
+
const idNumber = id.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
|
| 36 |
+
const index = idNumber % COLOR_LIST.length;
|
| 37 |
+
return COLOR_LIST[index];
|
| 38 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/grounding.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Tool } from '@/cohere-client';
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Helper function to determine if grounding is on.
|
| 5 |
+
* Note: this doesn't mean that RAG was used, just that it's on.
|
| 6 |
+
*/
|
| 7 |
+
export const isGroundingOn = (tools: Tool[], documents: string[]) => {
|
| 8 |
+
return tools.length > 0 || documents.length > 0;
|
| 9 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from './citations';
|
| 2 |
+
export * from './cn';
|
| 3 |
+
export * from './conversation';
|
| 4 |
+
export * from './delimiters';
|
| 5 |
+
export * from './error';
|
| 6 |
+
export * from './file';
|
| 7 |
+
export * from './format';
|
| 8 |
+
export * from './grounding';
|
| 9 |
+
export * from './pluralize';
|
| 10 |
+
export * from './queryString';
|
| 11 |
+
export * from './simpleEmailValidation';
|
| 12 |
+
export * from './urls';
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/pluralize.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const pluralize = (text: string, quantity: number, customPluralization?: string) => {
|
| 2 |
+
const isPlural = quantity > 1 || quantity === 0;
|
| 3 |
+
if (customPluralization) {
|
| 4 |
+
return isPlural ? customPluralization : text;
|
| 5 |
+
}
|
| 6 |
+
const pluralization = text.endsWith('s') ? 'es' : 's';
|
| 7 |
+
return `${text}${isPlural ? pluralization : ''}`;
|
| 8 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/preview.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Adds an onError event to all img elements in the html string
|
| 3 |
+
* @param html
|
| 4 |
+
* @returns
|
| 5 |
+
*/
|
| 6 |
+
const addOnErrorToImg = (html: string) => {
|
| 7 |
+
const regex = /<img([\s\S]+?)>/g;
|
| 8 |
+
const imgElements = html.match(regex);
|
| 9 |
+
if (imgElements) {
|
| 10 |
+
for (let i = 0; i < imgElements.length; i++) {
|
| 11 |
+
const imgElement = imgElements[i];
|
| 12 |
+
let newImgElement = imgElement;
|
| 13 |
+
if (imgElement.endsWith('/>')) {
|
| 14 |
+
newImgElement = imgElement.replace('/>', ' onError="onImageError(this)"/>');
|
| 15 |
+
} else {
|
| 16 |
+
newImgElement = imgElement.replace('>', ' onError="onImageError(this)">');
|
| 17 |
+
}
|
| 18 |
+
html = html.replace(imgElement, newImgElement);
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
html = html + GET_IMAGE_DEF;
|
| 22 |
+
return html;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
const GET_IMAGE_DEF = `
|
| 26 |
+
<script>
|
| 27 |
+
function onImageError(element) {
|
| 28 |
+
element.src = 'https://picsum.photos/' + element.width + '/' + element.height;
|
| 29 |
+
element.onerror = null;
|
| 30 |
+
}
|
| 31 |
+
</script>
|
| 32 |
+
`;
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Reconstructs the html from the plain string
|
| 36 |
+
* @param rawHTML
|
| 37 |
+
* @returns
|
| 38 |
+
*/
|
| 39 |
+
const getReconstructedHtml = (rawHTML: string) => {
|
| 40 |
+
const htmlRegex = /```(?:html)\n([\s\S]*?)(```|$)/;
|
| 41 |
+
const jsRegex = /```(?:js)\n([\s\S]*?)```/;
|
| 42 |
+
const cssRegex = /```(?:css)\n([\s\S]*?)```/;
|
| 43 |
+
|
| 44 |
+
const code = rawHTML.match(htmlRegex);
|
| 45 |
+
|
| 46 |
+
let html = '';
|
| 47 |
+
if (code) {
|
| 48 |
+
html = code[1];
|
| 49 |
+
const cssCode = rawHTML.match(cssRegex);
|
| 50 |
+
let css = '';
|
| 51 |
+
if (cssCode) {
|
| 52 |
+
css = cssCode[1];
|
| 53 |
+
html = `<style>${css}</style>` + html;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
const jsCode = rawHTML.match(jsRegex);
|
| 57 |
+
let js = '';
|
| 58 |
+
if (jsCode) {
|
| 59 |
+
js = jsCode[1];
|
| 60 |
+
html = html + `<script>${js}</script>`;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
return html;
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
// removes all the added code blocks and returns the original html
|
| 67 |
+
export const cleanupCodeBlock = (content: string) => {
|
| 68 |
+
const imgRegex = / onError="onImageError\(this\)"/g;
|
| 69 |
+
const cleanContent = content.replace(GET_IMAGE_DEF, '').replace(imgRegex, '');
|
| 70 |
+
|
| 71 |
+
return cleanContent;
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
export const replaceCodeBlockWithIframe = (content: string) => {
|
| 75 |
+
const matchingRegex = /```html([\s\S]+)/;
|
| 76 |
+
const replacingRegex = /```html([\s\S]+?)(```|$)/;
|
| 77 |
+
|
| 78 |
+
const match = content.match(matchingRegex);
|
| 79 |
+
|
| 80 |
+
if (!match) {
|
| 81 |
+
return content;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
const html = addOnErrorToImg(getReconstructedHtml(content));
|
| 85 |
+
|
| 86 |
+
const blob = new Blob([html], { type: 'text/html' });
|
| 87 |
+
const src = URL.createObjectURL(blob);
|
| 88 |
+
const iframe = `<iframe data-src="${src}"></iframe>`;
|
| 89 |
+
|
| 90 |
+
content = content.replace(replacingRegex, iframe);
|
| 91 |
+
|
| 92 |
+
return content;
|
| 93 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/queryString.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Get the query param as a string to avoid the usual
|
| 3 |
+
* Array.isArray(router.query.[param])
|
| 4 |
+
* ? router.query.[param][0]
|
| 5 |
+
* : router.query.[param];
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
export const getQueryString = (param?: string | string[] | null) => {
|
| 9 |
+
if (!param) return;
|
| 10 |
+
if (Array.isArray(param)) {
|
| 11 |
+
return param[0] as string;
|
| 12 |
+
}
|
| 13 |
+
return param as string;
|
| 14 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/simpleEmailValidation.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Validates email address complies with the spec at https://tools.ietf.org/html/rfc5322#section-3.4.1
|
| 2 |
+
// local-part "@" domain
|
| 3 |
+
// where local-part and domains are each 64 characters or less
|
| 4 |
+
|
| 5 |
+
export const simpleEmailValidation = (email: string) => {
|
| 6 |
+
const emailRegex =
|
| 7 |
+
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
| 8 |
+
const isPotentiallyValid = emailRegex.test(email);
|
| 9 |
+
if (!isPotentiallyValid) {
|
| 10 |
+
return false;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const parts = email.split('@');
|
| 14 |
+
if (parts.length !== 2) {
|
| 15 |
+
return false;
|
| 16 |
+
}
|
| 17 |
+
const [before, after] = parts;
|
| 18 |
+
return before.length > 0 && before.length <= 64 && after.length > 0 && after.length <= 64;
|
| 19 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/tools.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Document } from '@/cohere-client';
|
| 2 |
+
|
| 3 |
+
type PythonInterpreterFieldsBase = {
|
| 4 |
+
snippet?: string; // citation snippet, will either be the stdout, stderr, or the file name
|
| 5 |
+
};
|
| 6 |
+
|
| 7 |
+
type PythonInterpreterImageFields = {
|
| 8 |
+
/**
|
| 9 |
+
* String representation of a json object with the following fields:
|
| 10 |
+
* - filename: string
|
| 11 |
+
* - b64_data: string
|
| 12 |
+
*/
|
| 13 |
+
output_file?: string;
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
type PythonInterpreterCodeFields = {
|
| 17 |
+
code_runtime?: string;
|
| 18 |
+
success?: string; // "True" or "False"
|
| 19 |
+
std_out?: string;
|
| 20 |
+
std_err?: string;
|
| 21 |
+
/**
|
| 22 |
+
* String representation of a json object with the following fields:
|
| 23 |
+
* - type: string (e.g. "ZeroDivisionError")
|
| 24 |
+
* - message: string (usually a stack trace)
|
| 25 |
+
*/
|
| 26 |
+
error?: string;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
type PythonInterpreterFields = PythonInterpreterFieldsBase &
|
| 30 |
+
PythonInterpreterImageFields &
|
| 31 |
+
PythonInterpreterCodeFields;
|
| 32 |
+
|
| 33 |
+
export type PythonInterpreterOutputFile = { filename: string; b64_data: string };
|
| 34 |
+
export type PythonInterpreterCodeError = { type: string; message: string };
|
| 35 |
+
|
| 36 |
+
export const parsePythonInterpreterToolFields = (document: Document) => {
|
| 37 |
+
if (!document.fields) {
|
| 38 |
+
return {
|
| 39 |
+
snippet: undefined,
|
| 40 |
+
success: undefined,
|
| 41 |
+
codeRuntime: undefined,
|
| 42 |
+
stdErr: undefined,
|
| 43 |
+
stdOut: undefined,
|
| 44 |
+
error: undefined,
|
| 45 |
+
outputFile: undefined,
|
| 46 |
+
};
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const fields = document.fields as PythonInterpreterFields;
|
| 50 |
+
let outputFile: PythonInterpreterOutputFile | undefined;
|
| 51 |
+
let error: PythonInterpreterCodeError | undefined;
|
| 52 |
+
|
| 53 |
+
if (fields.output_file) {
|
| 54 |
+
try {
|
| 55 |
+
outputFile = JSON.parse(fields.output_file);
|
| 56 |
+
} catch (e) {
|
| 57 |
+
console.error('Could not parse output_file', e);
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if (fields.error) {
|
| 62 |
+
try {
|
| 63 |
+
error = JSON.parse(fields.error);
|
| 64 |
+
} catch (e) {
|
| 65 |
+
console.error('Could not parse error', e);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return {
|
| 70 |
+
snippet: fields.snippet,
|
| 71 |
+
success: fields.success ? fields.success.toLowerCase() === 'true' : undefined,
|
| 72 |
+
codeRuntime: fields.code_runtime,
|
| 73 |
+
stdErr: fields.std_err,
|
| 74 |
+
stdOut: fields.std_out,
|
| 75 |
+
error,
|
| 76 |
+
outputFile,
|
| 77 |
+
};
|
| 78 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/src/utils/urls.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { ParseResultType, parseDomain } from 'parse-domain';
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Returns the domain name of a url.
|
| 5 |
+
* * e.g. https://www.google.com -> google
|
| 6 |
+
* * e.g. https://www.google.co.uk -> google
|
| 7 |
+
* * e.g. https://www.en.wikipedia.co.uk/search?q=hello -> wikipedia
|
| 8 |
+
* * e.g. https://www.cloud.console.aws.amazon.co.uk -> amazon
|
| 9 |
+
*/
|
| 10 |
+
export const getWebDomain = (url?: string) => {
|
| 11 |
+
if (!url) return '';
|
| 12 |
+
|
| 13 |
+
try {
|
| 14 |
+
const urlObj = new URL(url);
|
| 15 |
+
|
| 16 |
+
const parsed = parseDomain(urlObj.hostname);
|
| 17 |
+
|
| 18 |
+
if (parsed.type === ParseResultType.Listed) {
|
| 19 |
+
return parsed.domain;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
return '';
|
| 23 |
+
} catch {
|
| 24 |
+
return '';
|
| 25 |
+
}
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Returns the url if it is valid and safe.
|
| 30 |
+
* * e.g. https://www.google.com -> ok
|
| 31 |
+
* * e.g. alert('hi') -> not ok, return undefined
|
| 32 |
+
* * e.g. https://www.google.com?q=<script>alert(1)</script> -> ok, return encoded url
|
| 33 |
+
*/
|
| 34 |
+
export const getSafeUrl = (url?: string) => {
|
| 35 |
+
if (!url) return undefined;
|
| 36 |
+
|
| 37 |
+
try {
|
| 38 |
+
const urlObj = new URL(url);
|
| 39 |
+
const parsed = parseDomain(urlObj.hostname);
|
| 40 |
+
|
| 41 |
+
if (parsed.type === ParseResultType.Listed) {
|
| 42 |
+
const encodedPathname = urlObj.pathname
|
| 43 |
+
.split('/')
|
| 44 |
+
.map((p) => encodeURIComponent(p))
|
| 45 |
+
.join('/');
|
| 46 |
+
|
| 47 |
+
const encodedSearchParamsList = [];
|
| 48 |
+
for (const [key, value] of urlObj.searchParams) {
|
| 49 |
+
encodedSearchParamsList.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
| 50 |
+
}
|
| 51 |
+
const encodedSearchParams =
|
| 52 |
+
encodedSearchParamsList.length > 0 ? `?${encodedSearchParamsList.join('&')}` : '';
|
| 53 |
+
|
| 54 |
+
return `${urlObj.origin}${encodedPathname}${encodedSearchParams}${urlObj.hash}`;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return undefined;
|
| 58 |
+
} catch {
|
| 59 |
+
return undefined;
|
| 60 |
+
}
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Returns the url if it is valid.
|
| 65 |
+
* * e.g. https://www.google.com -> ok
|
| 66 |
+
* * e.g. alert('hi') -> not ok, return undefined
|
| 67 |
+
*
|
| 68 |
+
* @param url The url to validate.
|
| 69 |
+
* @returns The url if it is valid, otherwise undefined.
|
| 70 |
+
*/
|
| 71 |
+
export const getValidURL = (url?: string | null) => {
|
| 72 |
+
if (!url) return undefined;
|
| 73 |
+
try {
|
| 74 |
+
new URL(url);
|
| 75 |
+
return url;
|
| 76 |
+
} catch {
|
| 77 |
+
return undefined;
|
| 78 |
+
}
|
| 79 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/tailwind.config.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('tailwindcss').Config} */
|
| 2 |
+
module.exports = {
|
| 3 |
+
presets: [require('./src/themes/cohereTheme')],
|
| 4 |
+
content: ['src/**/*.{js,jsx,ts,tsx}'],
|
| 5 |
+
plugins: [require('@tailwindcss/typography')],
|
| 6 |
+
darkMode: 'selector',
|
| 7 |
+
theme: {
|
| 8 |
+
extend: {
|
| 9 |
+
screens: {
|
| 10 |
+
'3xl': '2000px',
|
| 11 |
+
},
|
| 12 |
+
minWidth: {
|
| 13 |
+
'citation-panel-md': '259px', // subtract 10px for scrollbar and 1px for border
|
| 14 |
+
'citation-panel-lg': '325px', // subtract 10px for scrollbar and 1px for border
|
| 15 |
+
'citation-panel-xl': '349px', // subtract 10px for scrollbar and 1px for border
|
| 16 |
+
menu: '174px',
|
| 17 |
+
'agents-panel-collapsed': '82px',
|
| 18 |
+
'agents-panel-expanded': '288px',
|
| 19 |
+
'agents-panel-expanded-lg': '320px',
|
| 20 |
+
'left-panel-lg': '242px',
|
| 21 |
+
'left-panel-2xl': '300px',
|
| 22 |
+
'left-panel-3xl': '360px',
|
| 23 |
+
},
|
| 24 |
+
width: {
|
| 25 |
+
'ep-icon-sm': '12px',
|
| 26 |
+
'ep-icon-md': '16px',
|
| 27 |
+
'ep-icon-lg': '24px',
|
| 28 |
+
'ep-icon-xl': '36px',
|
| 29 |
+
'btn-sm': '280px',
|
| 30 |
+
'btn-md': '312px',
|
| 31 |
+
'btn-lg': '350px',
|
| 32 |
+
'btn-xl': '370px',
|
| 33 |
+
modal: '648px',
|
| 34 |
+
toast: '320px',
|
| 35 |
+
'toast-sm': '280px',
|
| 36 |
+
'citation-md': '250px',
|
| 37 |
+
'citation-lg': '298px',
|
| 38 |
+
'citation-xl': '320px',
|
| 39 |
+
file: '224px',
|
| 40 |
+
'edit-agent-panel': '350px',
|
| 41 |
+
'edit-agent-panel-lg': '683px',
|
| 42 |
+
'edit-agent-panel-2xl': '800px',
|
| 43 |
+
},
|
| 44 |
+
maxWidth: {
|
| 45 |
+
'modal-xs': '352px',
|
| 46 |
+
'modal-sm': '463px',
|
| 47 |
+
'modal-md': '476px',
|
| 48 |
+
modal: '648px',
|
| 49 |
+
'modal-lg': '1062px',
|
| 50 |
+
'modal-xl': '1600px',
|
| 51 |
+
message: '976px',
|
| 52 |
+
'agents-panel-collapsed': '82px',
|
| 53 |
+
'agents-panel-expanded': '288px',
|
| 54 |
+
'agents-panel-expanded-lg': '320px',
|
| 55 |
+
drawer: '288px',
|
| 56 |
+
'drawer-lg': '360px',
|
| 57 |
+
'left-panel-lg': '242px',
|
| 58 |
+
'left-panel-2xl': '300px',
|
| 59 |
+
'left-panel-3xl': '360px',
|
| 60 |
+
'share-content': '700px',
|
| 61 |
+
'share-content-with-citations': '1500px',
|
| 62 |
+
},
|
| 63 |
+
height: {
|
| 64 |
+
'ep-icon-sm': '12px',
|
| 65 |
+
'ep-icon-md': '16px',
|
| 66 |
+
'ep-icon-lg': '24px',
|
| 67 |
+
'ep-icon-xl': '36px',
|
| 68 |
+
header: '64px',
|
| 69 |
+
},
|
| 70 |
+
minHeight: {
|
| 71 |
+
'cell-xs': '24px',
|
| 72 |
+
'cell-sm': '32px',
|
| 73 |
+
'cell-md': '40px',
|
| 74 |
+
'cell-lg': '50px',
|
| 75 |
+
'cell-xl': '64px',
|
| 76 |
+
header: '64px',
|
| 77 |
+
},
|
| 78 |
+
maxHeight: {
|
| 79 |
+
'cell-xs': '24px',
|
| 80 |
+
'cell-sm': '32px',
|
| 81 |
+
'cell-md': '40px',
|
| 82 |
+
'cell-lg': '50px',
|
| 83 |
+
'cell-xl': '64px',
|
| 84 |
+
},
|
| 85 |
+
zIndex: {
|
| 86 |
+
backdrop: '20',
|
| 87 |
+
navigation: '30',
|
| 88 |
+
modal: '50',
|
| 89 |
+
dropdown: '60',
|
| 90 |
+
toast: '70',
|
| 91 |
+
'main-section': '10',
|
| 92 |
+
'tag-suggestions': '10',
|
| 93 |
+
'drag-drop-input-overlay': '10',
|
| 94 |
+
'configuration-drawer': '20',
|
| 95 |
+
'selected-citation': '20',
|
| 96 |
+
'read-only-conversation-footer': '30',
|
| 97 |
+
menu: '90',
|
| 98 |
+
'guide-tooltip': '30',
|
| 99 |
+
tooltip: '50',
|
| 100 |
+
},
|
| 101 |
+
boxShadow: {
|
| 102 |
+
drawer: '-10px 4px 12px -10px rgba(197, 188, 172, 0.48)', // secondary-400
|
| 103 |
+
menu: '0px 4px 12px 0px rgba(197, 188, 172, 0.48)', // secondary-400
|
| 104 |
+
top: '4px 0px 12px 0px rgba(197, 188, 172, 0.48)', // secondary-400
|
| 105 |
+
},
|
| 106 |
+
typography: (theme) => ({
|
| 107 |
+
DEFAULT: {
|
| 108 |
+
css: {
|
| 109 |
+
color: theme('colors.volcanic.100'),
|
| 110 |
+
},
|
| 111 |
+
},
|
| 112 |
+
}),
|
| 113 |
+
keyframes: {
|
| 114 |
+
typing: {
|
| 115 |
+
'0%': {
|
| 116 |
+
width: '0%',
|
| 117 |
+
visibility: 'hidden',
|
| 118 |
+
},
|
| 119 |
+
'100%': {
|
| 120 |
+
width: '100%',
|
| 121 |
+
},
|
| 122 |
+
},
|
| 123 |
+
'left-to-right': {
|
| 124 |
+
'0%': {
|
| 125 |
+
left: '0%',
|
| 126 |
+
transform: 'translateX(-100%)',
|
| 127 |
+
},
|
| 128 |
+
'100%': {
|
| 129 |
+
left: '100%',
|
| 130 |
+
transform: 'translateX(0%)',
|
| 131 |
+
},
|
| 132 |
+
},
|
| 133 |
+
borealisBar: {
|
| 134 |
+
'0%': {
|
| 135 |
+
left: '0%',
|
| 136 |
+
right: '100%',
|
| 137 |
+
width: '0%',
|
| 138 |
+
},
|
| 139 |
+
'20%': {
|
| 140 |
+
left: '0%',
|
| 141 |
+
right: '75%',
|
| 142 |
+
width: '25%',
|
| 143 |
+
},
|
| 144 |
+
'80%': {
|
| 145 |
+
right: '0%',
|
| 146 |
+
left: '75%',
|
| 147 |
+
width: '25%',
|
| 148 |
+
},
|
| 149 |
+
'100%': {
|
| 150 |
+
left: '100%',
|
| 151 |
+
right: '0%',
|
| 152 |
+
width: '0%',
|
| 153 |
+
},
|
| 154 |
+
},
|
| 155 |
+
},
|
| 156 |
+
animation: {
|
| 157 |
+
'typing-ellipsis': 'typing 2s steps(4) infinite',
|
| 158 |
+
'typing-loading-message': 'typing 0.7s steps(20)',
|
| 159 |
+
'ping-once': 'ping 1s cubic-bezier(0, 0, 0.2, 1)',
|
| 160 |
+
'left-to-right': 'left-to-right 0.5s ease-in-out infinite',
|
| 161 |
+
borealisBar: 'borealisBar 2s linear infinite',
|
| 162 |
+
},
|
| 163 |
+
scale: {
|
| 164 |
+
175: '1.75',
|
| 165 |
+
},
|
| 166 |
+
variants: {
|
| 167 |
+
extend: {},
|
| 168 |
+
},
|
| 169 |
+
plugins: [],
|
| 170 |
+
},
|
| 171 |
+
},
|
| 172 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/coral_web/tsconfig.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"include": [
|
| 3 |
+
"src",
|
| 4 |
+
"next-env.d.ts",
|
| 5 |
+
"next-env.d.ts",
|
| 6 |
+
"**/*.ts",
|
| 7 |
+
"**/*.tsx",
|
| 8 |
+
".next/types/**/*.ts"
|
| 9 |
+
],
|
| 10 |
+
"exclude": ["node_modules"],
|
| 11 |
+
"compilerOptions": {
|
| 12 |
+
"baseUrl": ".",
|
| 13 |
+
"paths": {
|
| 14 |
+
"@/*": ["src/*"]
|
| 15 |
+
},
|
| 16 |
+
"target": "es6",
|
| 17 |
+
"lib": ["dom", "dom.iterable", "esnext"],
|
| 18 |
+
"allowJs": true,
|
| 19 |
+
"strict": true,
|
| 20 |
+
"forceConsistentCasingInFileNames": true,
|
| 21 |
+
"noEmit": true,
|
| 22 |
+
"incremental": true,
|
| 23 |
+
"esModuleInterop": true,
|
| 24 |
+
"module": "esnext",
|
| 25 |
+
"resolveJsonModule": true,
|
| 26 |
+
"inlineSources": false,
|
| 27 |
+
"isolatedModules": true,
|
| 28 |
+
"composite": false,
|
| 29 |
+
"declaration": false,
|
| 30 |
+
"declarationMap": false,
|
| 31 |
+
"moduleResolution": "node",
|
| 32 |
+
"noUnusedLocals": false,
|
| 33 |
+
"noUnusedParameters": false,
|
| 34 |
+
"preserveWatchOutput": true,
|
| 35 |
+
"strictNullChecks": true,
|
| 36 |
+
"jsx": "preserve",
|
| 37 |
+
"skipLibCheck": true,
|
| 38 |
+
"plugins": [
|
| 39 |
+
{
|
| 40 |
+
"name": "next"
|
| 41 |
+
}
|
| 42 |
+
]
|
| 43 |
+
}
|
| 44 |
+
}
|
western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.env.example
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Environment variables declared in this file are automatically made available to Prisma, and to the application when NODE_ENV=development.
|
| 2 |
+
# See README.md and https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
| 3 |
+
|
| 4 |
+
TOOLKIT_API_HOST=http://0.0.0.0:8000
|
| 5 |
+
COHERE_ORGANIZATION_ID=<cohere-organization-id>
|
| 6 |
+
COHERE_SLACK_TEAM_ID=<cohere-slack-team-id>
|
| 7 |
+
SLACK_SIGNING_SECRET=<signing-secret>
|
| 8 |
+
FEEDBACK_CLIENT_TAG=<feedback-client-tag>
|
| 9 |
+
COMMAND_SUFFIX=<app-name>
|
| 10 |
+
SENTRY_DSN=<sentry-dsn>
|
| 11 |
+
DATABASE_URL="postgresql://commandslack:password@localhost:5432/commandslackdb"
|
| 12 |
+
|
| 13 |
+
# Option 1: socket mode
|
| 14 |
+
SLACK_CONNECTION_MODE=socket
|
| 15 |
+
SLACK_BOT_TOKEN=<xoxb-token>
|
| 16 |
+
SLACK_APP_TOKEN=<xapp-token>
|
| 17 |
+
|
| 18 |
+
# Option 2: http mode with OAuth
|
| 19 |
+
# SLACK_CONNECTION_MODE=http
|
| 20 |
+
# SLACK_CLIENT_ID=<oauth-client-id>
|
| 21 |
+
# SLACK_CLIENT_SECRET=<oauth-client-secret>
|
| 22 |
+
# SLACK_STATE_SECRET=my-state-secret
|
| 23 |
+
# SLACK_INSTALL_PASSWORD=password
|
western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
**/node_modules
|
| 3 |
+
**/coverage
|
| 4 |
+
.idea
|
western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
v20.12.2
|
western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.prettierignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dist/
|
| 2 |
+
coverage/
|
western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/.prettierrc.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://prettier.io/docs/en/options.html
|
| 2 |
+
|
| 3 |
+
module.exports = {
|
| 4 |
+
printWidth: 100,
|
| 5 |
+
singleQuote: true,
|
| 6 |
+
importOrder: ['<THIRD_PARTY_MODULES>', '^@/*/(.*)$', '^[./]', '(.*)\\.css$'],
|
| 7 |
+
importOrderSeparation: true,
|
| 8 |
+
importOrderSortSpecifiers: true,
|
| 9 |
+
plugins: [require.resolve('@trivago/prettier-plugin-sort-imports')],
|
| 10 |
+
};
|
western_ai/canada/cohere-toolkit/src/interfaces/slack_bot/README.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Command Slack Bot
|
| 2 |
+
|
| 3 |
+
This is a Slack bot that uses the Cohere Toolkit to generate responses to messages.
|
| 4 |
+
|
| 5 |
+
## Getting Started
|
| 6 |
+
|
| 7 |
+
The Slack bot interface is a Node project that runs independently of the main Toolkit backend. The following steps are required to get up and running with the Slack bot:
|
| 8 |
+
|
| 9 |
+
- Ensure that you have an instance of the Toolkit running and configured with required secrets
|
| 10 |
+
- Ensure that the Slack bot app is accessible from a public ip address
|
| 11 |
+
- Create a PostreSQL database and run the Prisma database migrations
|
| 12 |
+
- Create a new Slack app in your Slack account based on the example app manifest
|
| 13 |
+
- Configure environment variables and generate required values on the Slack website
|
| 14 |
+
- Add the Slack app to your workspace and complete OAuth flow
|
| 15 |
+
- Run the setup command in your Slack workspace
|
| 16 |
+
- Invite Command Slack Bot to a channel
|
| 17 |
+
- Optionally set channel parameters to override default model settings
|
| 18 |
+
- Begin chatting!
|
| 19 |
+
|
| 20 |
+
The sections below will provide further details on these required steps.
|
| 21 |
+
|
| 22 |
+
### Set up the Toolkit
|
| 23 |
+
|
| 24 |
+
The Slack bot makes use of the Toolkit, and requires the Toolkit to be running separately
|
| 25 |
+
from the Slack bot. All requests to the models are made through requests to the Toolkit APIs.
|
| 26 |
+
|
| 27 |
+
Please see the documentation for the Toolkit to see how configure and deploy it.
|
| 28 |
+
|
| 29 |
+
https://github.com/cohere-ai/cohere-toolkit
|
| 30 |
+
|
| 31 |
+
If you are running the Toolkit on localhost, the default API URL should work. If you have
|
| 32 |
+
the Toolkit deployed on a server, then you will need to set the `TOOLKIT_API_HOST` environment
|
| 33 |
+
variable with the appropriate value.
|
| 34 |
+
|
| 35 |
+
### Deploy app or configure ngrok for local dev
|
| 36 |
+
|
| 37 |
+
There are two ways for the Slack bot to receive data from Slack. The recommended way is to use
|
| 38 |
+
webhooks, which requires Slack to be able to make HTTP requests to the running Slack bot app from
|
| 39 |
+
this repo. For Slack to make those requests, it requires the app to be accessible on a public IP address.
|
| 40 |
+
The URLs for the webhooks must be configured in the app manifest on the Slack website.
|
| 41 |
+
|
| 42 |
+
If the app is deployed to a server, this should be no problem. Use the hostname of the server where
|
| 43 |
+
you have deployed it. For local development, however, Slack needs to be able to access the webhook
|
| 44 |
+
endpoints running in your local environment, which requires a proxy for local development.
|
| 45 |
+
|
| 46 |
+
One way of doing this is with a program called ngrok. It is a service that allows you to access code
|
| 47 |
+
running on your local machine from a public ip and domain. It is a commercial app, but there is
|
| 48 |
+
a free tier that should be sufficient for local development of this app.
|
| 49 |
+
|
| 50 |
+
Please see https://ngrok.com for instructions on installing ngrok and obtaining an API key.
|
| 51 |
+
|
| 52 |
+
Once ngrok is set up, you can start it with:
|
| 53 |
+
|
| 54 |
+
`ngrok http 3000`
|
| 55 |
+
|
| 56 |
+
On the free plan this will give you a random domain each time. There is a `-domain` option that will
|
| 57 |
+
allow you to choose a specific hostname if it is available. Paid accounts can reserve specific
|
| 58 |
+
hostnames for your use only, which could be useful for ongoing development, since the hostname needs
|
| 59 |
+
to be saved in several different places in the app manifest, and not using a reserved domain could
|
| 60 |
+
require you to have to make changes to the app configuration on the Slack website, each time the
|
| 61 |
+
ngrok domain you are assigned changes.
|
| 62 |
+
|
| 63 |
+
Alternatively, the Slack bot can be used with socket mode. With socket mode, the bot will
|
| 64 |
+
establish a websocket connection to Slack, over which the Slack events can be received. Socket
|
| 65 |
+
mode can simplify local development by eliminating the requirement for a proxy to your local environment.
|
| 66 |
+
|
| 67 |
+
Use of socket mode requires socket mode to be enabled in the Slack app configuration on the Slack
|
| 68 |
+
website, in addition to being enabled and configured with socket mode specific secrets in the
|
| 69 |
+
environment variables. See the section further below for more information on configuring socket mode.
|
| 70 |
+
|
| 71 |
+
### Create PostgreSQL database and run migrations
|
| 72 |
+
|
| 73 |
+
The Slack bot requires a PostgreSQL database for storing workspace and channel settings. Follow standard
|
| 74 |
+
procedures for creating a PostgreSQL database and once the database and PostgreSQL user have been
|
| 75 |
+
created, set the `DATABASE_URL` environment variable.
|
| 76 |
+
|
| 77 |
+
You can use any database name, user and host as long as the `DATABASE_URL` is configured. The following
|
| 78 |
+
steps are a guide for how to do this.
|
| 79 |
+
|
| 80 |
+
Start the psql shell with a postgres admin account.
|
| 81 |
+
|
| 82 |
+
```shell
|
| 83 |
+
psql --host=localhost --port=5432 --username=postgres
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
In the psql shell run the following commands:
|
| 87 |
+
|
| 88 |
+
```
|
| 89 |
+
CREATE DATABASE commandslackdb;
|
| 90 |
+
CREATE USER commandslack WITH PASSWORD 'password';
|
| 91 |
+
GRANT ALL PRIVILEGES ON DATABASE commandslackdb TO commandslack;
|
| 92 |
+
ALTER USER commandslack WITH CREATEDB;
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Set the `DATABASE_URL` with the db name, user and password you used above:
|
| 96 |
+
|
| 97 |
+
```shell
|
| 98 |
+
DATABASE_URL="postgresql://commandslack:password@localhost:5432/commandslackdb"`
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
Once the database has been set up, you must run the Prisma migrations. In development use:
|
| 102 |
+
|
| 103 |
+
```shell
|
| 104 |
+
prisma migrate dev
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
### Create Slack app
|
| 108 |
+
|
| 109 |
+
To use the Slack bot, you must create your own app on the api.slack.com website. Choose the option
|
| 110 |
+
to create a new app, and choose the option "From an app manifest". Follow the instructions to
|
| 111 |
+
choose the workspace, and when prompted for the manifest, choose the YAML option, and copy and paste
|
| 112 |
+
the contents of the `example-manifest.yaml` file from this repo.
|
| 113 |
+
|
| 114 |
+
It is possible to custom configure all the values in Slack, and it is not mandatory to use the
|
| 115 |
+
all the settings from the example manifest. For example, you could change the display name
|
| 116 |
+
or username of the bot. However, using the `example-manifest.yaml` file will make the process much
|
| 117 |
+
simpler. For getting up and running quickly, it is strongly recommended to start with this file,
|
| 118 |
+
rather than custom configuring all required values from scratch. There are some important defaults
|
| 119 |
+
in the example that could lead to hard to debug problems if they are not present.
|
| 120 |
+
|
| 121 |
+
When configuring the Slack app, it is important to change the hostnames of all URLs in the example
|
| 122 |
+
manifest. Every instance of https://slack-bot-host/slack/events in the example manifest must be
|
| 123 |
+
changed to use the domain of your deployed app or the ngrok domain you are using for local development.
|
| 124 |
+
|
| 125 |
+
### Configure environment variables
|
| 126 |
+
|
| 127 |
+
For local development, copy the `.env.example` file to `.env`, and edit the values accordingly. The
|
| 128 |
+
required values depend on whether you choose to use HTTP mode (recommended for production) or socket mode.
|
| 129 |
+
|
| 130 |
+
### Add the Slack app to your workspace and complete OAuth flow
|
| 131 |
+
|
| 132 |
+
The Command Slack bot may appear in your workspace after you create the new app from the manifest, but
|
| 133 |
+
it will not work properly without granting permissions with OAuth.
|
| 134 |
+
|
| 135 |
+
In order for the OAuth flow to work, you must ensure that the Slack app has the redirect URL configured
|
| 136 |
+
in the Slack app configuration/manifest. The default redirect URL in the example is set to
|
| 137 |
+
https://slack-bot-host/slack/oauth_redirect, but the host name needs to be changed. Ensure this was
|
| 138 |
+
done in the previous steps.
|
| 139 |
+
|
| 140 |
+
To grant OAuth permissions, go to the following URL:
|
| 141 |
+
|
| 142 |
+
https://slack-bot-host/slack/install/
|
| 143 |
+
|
| 144 |
+
You can optionally set an environment variable called `SLACK_INSTALL_PASSWORD` to obscure this URL.
|
| 145 |
+
If you set the value, the URL to start OAuth flow will be:
|
| 146 |
+
|
| 147 |
+
https://slack-bot-host/slack/install/password-you-chose
|
| 148 |
+
|
| 149 |
+
You must of course change the host to the server where the Slack bot is deployed or the proxy address.
|
| 150 |
+
|
| 151 |
+
This page will redirect you to Slack, and after you grant the permissions, you will be redirected
|
| 152 |
+
back to the Slack bot host in your browser. When returning, you should come back to the following
|
| 153 |
+
URL:
|
| 154 |
+
|
| 155 |
+
https://slack-bot-host/slack/oauth_redirect
|
| 156 |
+
|
| 157 |
+
The above URL does not change based on the value of `SLACK_INSTALL_PASSWORD` like the install
|
| 158 |
+
URL does.
|
| 159 |
+
|
| 160 |
+
When you return, you will be prompted to open the Slack application by your browser. You should allow this.
|
| 161 |
+
|
| 162 |
+
### Run the setup command in your Slack workspace
|
| 163 |
+
|
| 164 |
+
The Command Slack bot will add several new `/` commands to your Slack workspace. To begin using the
|
| 165 |
+
bot, you must run the `/setup-command` command inside of Slack. If this command is not available in
|
| 166 |
+
your workspace, it means that the above steps have not been completed successfully yet.
|
| 167 |
+
|
| 168 |
+
When the Slack bot is running in production environments, only an administrator of the Slack workspace
|
| 169 |
+
can run the `/setup-command` command. When `NODE_ENV` is set to `development`, this restricted is lifted,
|
| 170 |
+
and anyone can run `/setup-command`. Some features of the Slack bot may work before this has been run,
|
| 171 |
+
but it is advisable to run it as soon as you've completed the OAuth flow, in order to avoid any hard
|
| 172 |
+
to debug problems when there is no record in the `WorkspaceSettings` table.
|
| 173 |
+
|
| 174 |
+
### Invite Command Slack Bot to a channel
|
| 175 |
+
|
| 176 |
+
If you have followed the above instructions, with the suggested defaults, then you should now have the
|
| 177 |
+
Command Slack bot in your workspace. The default username in the example manifest is `@Command`. You
|
| 178 |
+
should be able to talk to this user directly, or invite `@Command` to a channel. In order for it to
|
| 179 |
+
respond in a channel, you must tag the user `@Command`. Once `@Command` has been tagged in a thread,
|
| 180 |
+
it will continue responding to that thread without being tagged.
|
| 181 |
+
|
| 182 |
+
### Optionally set channel parameters to override default model settings
|
| 183 |
+
|
| 184 |
+
To see the full list of commands available, type `/command-help` in your workspace in the Slack application.
|
| 185 |
+
|
| 186 |
+
The configuration commands available include:
|
| 187 |
+
|
| 188 |
+
- `/set-deployment [deployment name]` - Set the deployment used for a specific channel
|
| 189 |
+
- `/view-deployment` - View the deployment used for a specific channel
|
| 190 |
+
- `/set-model [model name]` - Set the model used for a specific channel
|
| 191 |
+
- `/view-model` - View the model used for a specific channel
|
| 192 |
+
- `/set-temperature [0.0 - 5.0]` - Set the temperature used for a specific channel
|
| 193 |
+
- `/view-temperature` - View the temperature used for a specific channel
|
| 194 |
+
- `/set-preamble [preamble]` - Set the preamble override used for a specific channel
|
| 195 |
+
- `/view-preamble` - View the preamble override used for a specific channel
|
| 196 |
+
- `/set-tools` - Set tools for a specific channel
|
| 197 |
+
- `/view-tools [all]` - View all tools available in your Cohere account or tools enabled for a specific channel
|
| 198 |
+
|
| 199 |
+
### Begin chatting!
|
| 200 |
+
|
| 201 |
+
You should now be able to use the Command Slack bot in your workspace. You can communicate with `@Command` via
|
| 202 |
+
direct message, or tagging `@Command` in channel messages. There are also several other commands available,
|
| 203 |
+
to perform actions such as summarize a thread. To see the full list of things `@Command` can do, run the
|
| 204 |
+
`/command-help` command.
|
| 205 |
+
|
| 206 |
+
## Usage
|
| 207 |
+
|
| 208 |
+
The Command Slack bot is a Node application built with TypeScript.
|
| 209 |
+
|
| 210 |
+
```shell
|
| 211 |
+
# start in development mode
|
| 212 |
+
pnpm dev
|
| 213 |
+
|
| 214 |
+
# build for production
|
| 215 |
+
pnpm build
|
| 216 |
+
|
| 217 |
+
# run sql migrations and start in production mode
|
| 218 |
+
pnpm start
|
| 219 |
+
|
| 220 |
+
# lint
|
| 221 |
+
pnpm lint
|
| 222 |
+
|
| 223 |
+
# check formatting with prettier
|
| 224 |
+
pnpm format
|
| 225 |
+
|
| 226 |
+
# format with prettier
|
| 227 |
+
pnpm format:write
|
| 228 |
+
|
| 229 |
+
# run all unit tests, with coverage report
|
| 230 |
+
pnpm test
|
| 231 |
+
|
| 232 |
+
# run and watch unit tests
|
| 233 |
+
pnpm test:watch
|
| 234 |
+
```
|
| 235 |
+
|
| 236 |
+
## Project Structure
|
| 237 |
+
|
| 238 |
+
```text
|
| 239 |
+
slack_bot/
|
| 240 |
+
ββ src/
|
| 241 |
+
β ββ constants.ts
|
| 242 |
+
β β β constants live here
|
| 243 |
+
β ββ cohere-client/
|
| 244 |
+
β β β functions that interact with the toolkit api live here
|
| 245 |
+
β ββ handlers/
|
| 246 |
+
β β β functions that handle slack events live here
|
| 247 |
+
β ββ utils/
|
| 248 |
+
β β β miscellaneous utility functions live here
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
## Socket Mode and HTTP Mode
|
| 252 |
+
|
| 253 |
+
The Slack bot supports two modes of operation: Socket Mode and HTTP Mode.
|
| 254 |
+
|
| 255 |
+
In Socket Mode, the application initiates a connection to Slack via a long-lived TCP connection. This mode is recommended for local development and for private cloud deployment, since it requires no public HTTP endpoints to be exposed.
|
| 256 |
+
|
| 257 |
+
In HTTP Mode, the application exposes HTTP endpoints that Slack can use to send events and commands. This mode is recommended for public cloud deployment, since it supports installation via the public [Slack App Directory](https://api.slack.com/start/distributing#app_directory_apps).
|
| 258 |
+
|
| 259 |
+
The `SLACK_CONNECTION_MODE` environment variable controls which mode is used. Additional environment variables are required for each mode, as described under [Environment variables](#environment-variables).
|
| 260 |
+
|
| 261 |
+
Socket mode must also enabled in the Slack app configuration, under "Socket Mode" in the Settings menu.
|
| 262 |
+
|
| 263 |
+
The event subscription request URL will be https://slack-bot-host/slack/events, where "slack-bot-host" should be replaced with the hostname where the command slack bot is deployed.
|
| 264 |
+
|
| 265 |
+
See also:
|
| 266 |
+
|
| 267 |
+
- https://api.slack.com/apis/connections/socket
|
| 268 |
+
- https://slack.dev/bolt-js/concepts#socket-mode
|
| 269 |
+
|
| 270 |
+
## Database migrations
|
| 271 |
+
|
| 272 |
+
Apply migrations in development:
|
| 273 |
+
|
| 274 |
+
```
|
| 275 |
+
./node_modules/.bin/prisma migrate dev
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
Create new migration:
|
| 279 |
+
|
| 280 |
+
```
|
| 281 |
+
./node_modules/.bin/prisma migrate dev --name <name-of-migration>
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
Apply migrations in production:
|
| 285 |
+
|
| 286 |
+
```
|
| 287 |
+
./node_modules/.bin/prisma migrate deploy
|
| 288 |
+
```
|
| 289 |
+
|
| 290 |
+
_Note: `prisma migrate deploy` is run automatically upon `pnpm start` in production._
|
| 291 |
+
|
| 292 |
+
See also:
|
| 293 |
+
|
| 294 |
+
- https://www.prisma.io/docs/concepts/components/prisma-migrate/migrate-development-production
|
| 295 |
+
|
| 296 |
+
## Slack App Configuration
|
| 297 |
+
|
| 298 |
+
To use the bot with Slack, you'll need to create a new Slack App and install it to your workspace. The easiest way to do this is to use
|
| 299 |
+
the option to create a new app **from an app manifest**. Use the `example-manifest.yaml` file in this repo and tweak as needed. Ensure
|
| 300 |
+
that you change the toolkit host in the URLs to the URL where the Slack bot is being hosted.
|
| 301 |
+
|
| 302 |
+
To create a new Slack app, visit:
|
| 303 |
+
|
| 304 |
+
https://api.slack.com/apps?new_app=1
|
| 305 |
+
|
| 306 |
+
Alternatively, you can create a new Slack app from scratch. You can do this by following the instructions in the [Slack Bolt documentation](https://slack.dev/bolt-js/tutorial/getting-started), including the "Tokens and installing apps" step and "Setting up events" step.
|
| 307 |
+
|
| 308 |
+
As a result of this process, you should have a signing secret, bot token, and app-level token, which you must set as environment variables.
|
| 309 |
+
|
| 310 |
+
There are several differences in the Slack app configuration based on whether you use socket mode or HTTP mode.
|
| 311 |
+
|
| 312 |
+
### Socket Mode
|
| 313 |
+
|
| 314 |
+
You must enable socket mode in the Slack app configuration.
|
| 315 |
+
|
| 316 |
+
See: https://slack.dev/bolt-js/tutorial/getting-started#setting-up-events.
|
| 317 |
+
|
| 318 |
+
### HTTP Mode
|
| 319 |
+
|
| 320 |
+
With HTTP mode, you must ensure that event subscriptions are enabled on the _Event Subscriptions_ page under the _Features_ menu. You must also ensure that the URL to the Command Slack bot's events hook has been entered into the _Request URL_ field. The URL to handle events should be https://slack-bot-host/slack/events.
|
| 321 |
+
|
| 322 |
+
With HTTP mode it is also necessary to grant OAuth permissions.
|
| 323 |
+
|
| 324 |
+
### Testing with HTTP Mode
|
| 325 |
+
|
| 326 |
+
To test with HTTP Mode, you'll need to expose the bot to the public internet. You can do this with [ngrok](https://ngrok.com/):
|
| 327 |
+
|
| 328 |
+
```shell
|
| 329 |
+
brew install ngrok
|
| 330 |
+
ngrok http 3000
|
| 331 |
+
```
|
| 332 |
+
|
| 333 |
+
This command will expose a public HTTPS server which you can use to receive Slack events, e.g. https://6c36-142-181-59-160.ngrok-free.app. Use this URL in your App's config on https://api.slack.com/apps.
|
| 334 |
+
|
| 335 |
+
You can install the Slack App to a workspace by appending `/slack/install`, e.g. https://6c36-142-181-59-160.ngrok-free.app/slack/install.
|
| 336 |
+
|
| 337 |
+
For some ngrok features, you will need to sign up with a free account: https://ngrok.com/signup.
|
| 338 |
+
|
| 339 |
+
## Environment variables
|
| 340 |
+
|
| 341 |
+
| Variable | Required for Socket Mode | Required for HTTP Mode | Example | Description |
|
| 342 |
+
| ------------------------ | ------------------------ | ---------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
|
| 343 |
+
| `TOOLKIT_API_HOST` | Yes | Yes | `http://0.0.0.0:8000` | Protocol and host to access the Cohere Toolkit API. |
|
| 344 |
+
| `COHERE_SLACK_TEAM_ID` | Yes | Yes | `TV82C32HX` | Cohere's Slack Workspace Team ID. Can include multiple comma separated IDs |
|
| 345 |
+
| `COHERE_ORGANIZATION_ID` | Yes | Yes | `d489c39a-e152-49da-9ddc-9801bd74d823` | Cohere's Org ID |
|
| 346 |
+
| `SLACK_CONNECTION_MODE` | Yes | Yes | `socket` or `http` | Whether to use Socket Mode or HTTP Mode. |
|
| 347 |
+
| `SLACK_SIGNING_SECRET` | Yes | Yes | `abc123` | Signing secret from _Basic Information -> App Credentials -> Signing Secret_. |
|
| 348 |
+
| `SLACK_BOT_TOKEN` | Yes | No | `xoxb-abc123` | OAuth token from _OAuth & Permissions -> Bot User OAuth Token_. |
|
| 349 |
+
| `SLACK_APP_TOKEN` | Yes | No | `xapp-abc123` | App-Level token from _Basic Information -> App-Level Tokens_. Must contain the `connections:write` scope. |
|
| 350 |
+
| `DATABASE_URL` | No | Yes | `postgresql://commandslack:password@localhost:5432/commandslackdb` | Prisma-compatible PostgreSQL database URL. |
|
| 351 |
+
| `SLACK_CLIENT_ID` | No | Yes | `abc.123` | OAuth client ID from _Basic Information -> App Credentials -> Client ID_. |
|
| 352 |
+
| `SLACK_CLIENT_SECRET` | No | Yes | `abc123` | OAuth client secret from _Basic Information -> App Credentials -> Client Secret_. |
|
| 353 |
+
| `SLACK_STATE_SECRET` | No | Yes | `my-state-secret` | Sufficiently random static string used to secure the OAuth flow in web browsers. This can be changed when redeploying the app. |
|
| 354 |
+
| `SLACK_INSTALL_PASSWORD` | No | Yes | `mypassword` | A value to make the installation URL hard to guess. The URL will be `${HOST}/slack/install/${SLACK_INSTALL_PASSWORD}`. |
|
| 355 |
+
| `COMMAND_SUFFIX` | Yes | Yes | `-stg` | Suffix to add to command names to avoid collisions |
|
| 356 |
+
| `SENTRY_DSN` | No | No | `https://{SENTRY-ACCOUNT}.ingest.sentry.io/{SENTRY-ID}` | Optional value to send error events to the right Sentry project |
|
| 357 |
+
|
| 358 |
+
In development with `pnpm dev`, the bot will automatically load environment variables from a `.env` file in the root of the project. You can copy the `.env.example` file to get started:
|
| 359 |
+
|
| 360 |
+
```shell
|
| 361 |
+
cp .env.example .env
|
| 362 |
+
# edit .env with values from your Slack App
|
| 363 |
+
```
|
| 364 |
+
|
| 365 |
+
## Resources
|
| 366 |
+
|
| 367 |
+
- https://slack.dev/bolt-js/tutorial/getting-started
|
| 368 |
+
- https://slack.dev/bolt-js/reference
|
| 369 |
+
- https://github.com/vercel/turbo/tree/main/examples/kitchen-sink/apps/api
|
| 370 |
+
- https://github.com/slackapi/bolt-js/tree/main/examples/getting-started-typescript
|