Remove UUID library in favor of Crypto (#221)

This PR swaps usage of the `uuid` library for the built-in
`crypto.randomUUID` function, which is available in both NodeJS and the
browser. The built-in function is around 12x faster than the `uuid`
library. The strings produced by the built-in function are fully
compatible with the UUIDv4 standard, so it's an easy switch.
This commit is contained in:
Evan Simkowitz
2024-08-12 21:20:13 -07:00
committed by GitHub
parent 02801532c0
commit 9e1460b9e1
7 changed files with 6 additions and 37 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { v4 as uuidv4 } from "uuid";
import { getApi } from "./global";
class ContextMenuModelType {
@@ -25,7 +24,7 @@ class ContextMenuModelType {
role: item.role,
type: item.type,
label: item.label,
id: uuidv4(),
id: crypto.randomUUID(),
};
if (item.click) {
this.handlers.set(electronItem.id, item.click);
+2 -3
View File
@@ -7,7 +7,6 @@ import { sendRpcCommand } from "@/app/store/wshrpc";
import { getWebServerEndpoint } from "@/util/endpoints";
import * as jotai from "jotai";
import * as React from "react";
import { v4 as uuidv4 } from "uuid";
import { atoms, globalStore } from "./global";
import * as services from "./services";
@@ -120,7 +119,7 @@ function wshServerRpcHelper_responsestream(
const msg: RpcMessage = {
command: command,
data: data,
reqid: uuidv4(),
reqid: crypto.randomUUID(),
};
if (opts?.timeout) {
msg.timeout = opts.timeout;
@@ -135,7 +134,7 @@ function wshServerRpcHelper_call(command: string, data: any, opts: WshRpcCommand
data: data,
};
if (!opts?.noresponse) {
msg.reqid = uuidv4();
msg.reqid = crypto.randomUUID();
}
if (opts?.timeout) {
msg.timeout = opts.timeout;
+3 -5
View File
@@ -11,8 +11,6 @@ import type { OverlayScrollbars } from "overlayscrollbars";
import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
import tinycolor from "tinycolor2";
import { v4 as uuidv4 } from "uuid";
import "./waveai.less";
interface ChatMessageType {
@@ -33,7 +31,7 @@ interface ChatItemProps {
function promptToMsg(prompt: OpenAIPromptMessageType): ChatMessageType {
return {
id: uuidv4(),
id: crypto.randomUUID(),
user: prompt.role,
text: prompt.content,
isAssistant: prompt.role == "assistant",
@@ -78,7 +76,7 @@ export class WaveAiModel implements ViewModel {
});
this.simulateAssistantResponseAtom = jotai.atom(null, async (get, set, userMessage: ChatMessageType) => {
const typingMessage: ChatMessageType = {
id: uuidv4(),
id: crypto.randomUUID(),
user: "assistant",
text: "",
isAssistant: true,
@@ -145,7 +143,7 @@ export class WaveAiModel implements ViewModel {
const sendMessage = (text: string, user: string = "user") => {
const newMessage: ChatMessageType = {
id: uuidv4(),
id: crypto.randomUUID(),
user,
text,
isAssistant: false,