Skip to content

Commit

Permalink
Use nanoid
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Jun 13, 2024
1 parent d8c10e3 commit 5f863bb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-buttons-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/agent": patch
---

Use nanoid
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@ai-sdk/openai": "^0.0.13",
"@xstate/graph": "^2.0.0",
"ai": "^3.1.32",
"nanoid": "^5.0.7",
"xstate": "^5.13.2"
},
"packageManager": "pnpm@8.11.0"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import {
AgentMemoryContext,
} from './types';
import { simplePlanner } from './planners/simplePlanner';
import { randomUUID } from 'crypto';
import { agentGenerateText, agentStreamText } from './text';
import { agentDecide } from './decision';
import { vercelAdapter } from './adapters/vercel';
import { nanoid } from 'nanoid';

export const agentLogic: AgentLogic<AnyEventObject> = fromTransition(
(state, event, { emit }) => {
Expand Down Expand Up @@ -144,7 +144,7 @@ export function createAgent<
agent.addMessage = (messageInput) => {
const message = {
...messageInput,
id: messageInput.id ?? randomUUID(),
id: messageInput.id ?? nanoid(),
timestamp: messageInput.timestamp ?? Date.now(),
sessionId: agent.sessionId,
};
Expand Down Expand Up @@ -176,7 +176,7 @@ export function createAgent<
agent.addObservation = (observationInput) => {
const observation = {
...observationInput,
id: observationInput.id ?? randomUUID(),
id: observationInput.id ?? nanoid(),
sessionId: agent.sessionId,
timestamp: observationInput.timestamp ?? Date.now(),
};
Expand Down
5 changes: 2 additions & 3 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
AgentGenerateTextOptions,
AgentStreamTextOptions,
} from './types';
import { randomUUID } from 'crypto';
import { defaultTextTemplate } from './templates/defaultText';
import {
AnyMachineSnapshot,
Expand All @@ -20,7 +19,7 @@ import {
fromPromise,
toObserver,
} from 'xstate';
import { vercelAdapter } from './adapters/vercel';
import { nanoid } from 'nanoid';

/**
* Gets an array of messages from the given prompt, based on the agent and options.
Expand Down Expand Up @@ -62,7 +61,7 @@ export async function agentGenerateText<T extends Agent<any>>(
};
const template = resolvedOptions.template ?? defaultTextTemplate;
// TODO: check if messages was provided instead
const id = randomUUID();
const id = nanoid();
const goal =
typeof resolvedOptions.prompt === 'string'
? resolvedOptions.prompt
Expand Down

0 comments on commit 5f863bb

Please sign in to comment.