Skip to content

Commit

Permalink
fix: Remove dependency on node crypto API (#300)
Browse files Browse the repository at this point in the history
As seen in #192 , it is currently not possible to use edge functions in SvelteKit because the node crypto API is not available in the edge runtime. The node crypto API requirement is coming from [nanoid](https://github.com/ai/nanoid/blob/main/index.js). Nanoid has an alternative export, [nanoid/non-secure](https://github.com/ai/nanoid/blob/main/non-secure/index.js), which does not depend on the node crypto API.

From their readme r.e. `nanoid/non-secure`:
```
By default, Nano ID uses hardware random bytes generation for security and low collision probability. If you are not so concerned with security, you can use it for environments without hardware random generators.
```

It seems that `ai` is only using nanoid to generate unique IDs for chat messages - IMO this is a situation where non-secure can be used, which would be great for SvelteKit users.
  • Loading branch information
lachlancollins committed Jul 7, 2023
1 parent 4420187 commit 3ed65bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/violet-monkeys-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Remove dependency on node crypto API
2 changes: 1 addition & 1 deletion packages/core/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { customAlphabet } from 'nanoid'
import { customAlphabet } from 'nanoid/non-secure'

// 7-character random string
export const nanoid = customAlphabet(
Expand Down

0 comments on commit 3ed65bf

Please sign in to comment.