Skip to content

Commit 7308923

Browse files
amrmelsayedmaxkorp
andauthored
Update crypto imports to support React Native (#76)
* Replace crypto with UUID for cross platform compatibility * update for post rebase --------- Co-authored-by: Max Korp <[email protected]>
1 parent 6017be4 commit 7308923

File tree

8 files changed

+19
-8
lines changed

8 files changed

+19
-8
lines changed

docs/quickstart/clients.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const agent = new MastraAgent({
145145
agent: new Agent({
146146
name: "AG-UI Assistant",
147147
instructions: `
148-
You are a helpful AI assistant. Be friendly, conversational, and helpful.
148+
You are a helpful AI assistant. Be friendly, conversational, and helpful.
149149
Answer questions to the best of your ability and engage in natural conversation.
150150
`,
151151
model: openai("gpt-4o"),
@@ -175,7 +175,7 @@ Now let's create the interactive chat interface. Create `src/index.ts`:
175175
```typescript
176176
import * as readline from "readline"
177177
import { agent } from "./agent"
178-
import { randomUUID } from "node:crypto"
178+
import { randomUUID } from "@ag-ui/client"
179179

180180
const rl = readline.createInterface({
181181
input: process.stdin,

typescript-sdk/apps/client-cli-example/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as readline from "readline";
22
import { agent } from "./agent";
3-
import { randomUUID } from "node:crypto";
3+
import { randomUUID } from "@ag-ui/client";
44

55
const rl = readline.createInterface({
66
input: process.stdin,

typescript-sdk/integrations/a2a-middleware/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { A2AClient } from "@a2a-js/sdk/client";
1919
import { AgentCard, SendMessageResponse, SendMessageSuccessResponse } from "@a2a-js/sdk";
2020
import { Observable, Subscriber, tap } from "rxjs";
2121
import { createSystemPrompt, sendMessageToA2AAgentTool } from "./utils";
22-
import { randomUUID } from "crypto";
22+
import { randomUUID } from "@ag-ui/client";
2323

2424
export interface A2AAgentConfig extends AgentConfig {
2525
agentUrls: string[];

typescript-sdk/integrations/langgraph/src/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Interrupt,
1212
Thread,
1313
} from "@langchain/langgraph-sdk";
14-
import { randomUUID } from "node:crypto";
14+
import { randomUUID } from "@ag-ui/client";
1515
import {
1616
LangGraphPlatformMessage,
1717
CustomEventNames,
@@ -960,7 +960,7 @@ export class LangGraphAgent extends AbstractAgent {
960960
if (!retrievedAssistant) {
961961
console.error(`
962962
No agent found with graph ID ${this.graphId} found..\n
963-
963+
964964
These are the available agents: [${assistants.map((a) => `${a.graph_id} (ID: ${a.assistant_id})`).join(", ")}]
965965
`);
966966
throw new Error("No agent id found");

typescript-sdk/integrations/mastra/src/mastra.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { AbstractAgent, EventType } from "@ag-ui/client";
1515
import type { StorageThreadType } from "@mastra/core";
1616
import { Agent as LocalMastraAgent } from "@mastra/core/agent";
1717
import { RuntimeContext } from "@mastra/core/runtime-context";
18-
import { randomUUID } from "crypto";
18+
import { randomUUID } from "@ag-ui/client";
1919
import { Observable } from "rxjs";
2020
import { MastraClient } from "@mastra/client-js";
2121
type RemoteMastraAgent = ReturnType<MastraClient["getAgent"]>;

typescript-sdk/integrations/vercel-ai-sdk/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
ToolChoice,
2727
ToolSet,
2828
} from "ai";
29-
import { randomUUID } from "crypto";
29+
import { randomUUID } from "@ag-ui/client";
3030
import { z } from "zod";
3131

3232
type ProcessedEvent =

typescript-sdk/packages/client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export * from "./transform";
44
export * from "./run";
55
export * from "./legacy";
66
export * from "./agent";
7+
export * from "./utils";
78
export * from "@ag-ui/core";
89
export * from "./chunks";

typescript-sdk/packages/client/src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { v4 as uuidv4 } from 'uuid';
2+
13
export const structuredClone_ = <T>(obj: T): T => {
24
if (typeof structuredClone === "function") {
35
return structuredClone(obj);
@@ -9,3 +11,11 @@ export const structuredClone_ = <T>(obj: T): T => {
911
return { ...obj } as T;
1012
}
1113
};
14+
15+
/**
16+
* Generate a random UUID v4
17+
* Cross-platform compatible (Node.js, browsers, React Native)
18+
*/
19+
export function randomUUID(): string {
20+
return uuidv4();
21+
}

0 commit comments

Comments
 (0)