Skip to content

Commit c032430

Browse files
fix: custom alphabet (#482)
* custom alphabet * fix test
1 parent 735d238 commit c032430

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

packages/agents-core/src/__tests__/utils/conversations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('getConversationId', () => {
6666
it('should only contain URL-safe characters', () => {
6767
// nanoid uses A-Za-z0-9_- alphabet
6868
// After lowercase conversion: a-z0-9_-
69-
const urlSafePattern = /^[a-z0-9_-]+$/;
69+
const urlSafePattern = /^[a-z0-9]+$/;
7070

7171
for (let i = 0; i < 50; i++) {
7272
const id = getConversationId();
@@ -86,7 +86,7 @@ describe('getConversationId', () => {
8686
// IDs should be valid
8787
for (const id of ids) {
8888
expect(id.length).toBeGreaterThan(0);
89-
expect(/^[a-z0-9_-]+$/.test(id)).toBe(true);
89+
expect(/^[a-z0-9]+$/.test(id)).toBe(true);
9090
}
9191
});
9292
});

packages/agents-core/src/utils/conversations.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { nanoid } from 'nanoid';
1+
import { customAlphabet } from 'nanoid';
2+
3+
// Create a custom nanoid generator with only lowercase letters and numbers
4+
// This ensures IDs are always lowercase and never start with a hyphen
5+
const generateId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 21);
26

37
/**
48
* Generates a standardized conversation ID.
@@ -15,10 +19,5 @@ import { nanoid } from 'nanoid';
1519
* ```
1620
*/
1721
export function getConversationId(): string {
18-
let id = nanoid();
19-
20-
// Convert to lowercase and remove any leading hyphens
21-
id = id.toLowerCase().replace(/^-+/, '');
22-
23-
return id;
22+
return generateId();
2423
}

0 commit comments

Comments
 (0)