diff --git a/package-lock.json b/package-lock.json index 4968a73..84245ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "dotenv": "^16.4.5", "mobx-react-lite": "^4.0.7", "mobx-state-tree": "^7.0.0", + "nanoid": "^5.0.9", "openai": "^4.72.0", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -14491,10 +14492,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.8", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", - "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", - "dev": true, + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.9.tgz", + "integrity": "sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==", "funding": [ { "type": "github", @@ -14503,10 +14503,10 @@ ], "license": "MIT", "bin": { - "nanoid": "bin/nanoid.cjs" + "nanoid": "bin/nanoid.js" }, "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + "node": "^18 || >=20" } }, "node_modules/natural-compare": { @@ -16129,6 +16129,25 @@ "dev": true, "license": "MIT" }, + "node_modules/postcss/node_modules/nanoid": { + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index 78c7c70..a5686e0 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "dotenv": "^16.4.5", "mobx-react-lite": "^4.0.7", "mobx-state-tree": "^7.0.0", + "nanoid": "^5.0.9", "openai": "^4.72.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/src/models/chat-transcript-model.ts b/src/models/chat-transcript-model.ts index fb19133..c7dcdff 100644 --- a/src/models/chat-transcript-model.ts +++ b/src/models/chat-transcript-model.ts @@ -1,5 +1,6 @@ import { Instance, types } from "mobx-state-tree"; -import { createMessageId, timeStamp } from "../utils/utils"; +import { nanoid } from "nanoid"; +import { timeStamp } from "../utils/utils"; import { MessageContent } from "../types"; const MessageModel = types.model("MessageModel", { @@ -26,7 +27,7 @@ export const ChatTranscriptModel = types speaker, messageContent, timestamp: timeStamp(), - id: createMessageId(), + id: nanoid(), }); }, clearTranscript() { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d113c4d..fa10d66 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -3,18 +3,6 @@ export const timeStamp = (): string => { return now.toLocaleString(); }; -const idChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; -export const createMessageId = (): string => { - const result: string[] = []; - - while (result.length < 10) { - const randomIndex = Math.floor(Math.random() * idChars.length); - result.push(idChars.charAt(randomIndex)); - } - - return result.join(""); -}; - export const formatJsonMessage = (json: any) => { return JSON.stringify(json, null, 2); };