mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-21 07:36:45 +00:00
fix: lint
This commit is contained in:
@@ -5,24 +5,24 @@ import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
||||
import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
|
||||
|
||||
const llm = new ChatOpenAI({
|
||||
temperature: 0.7,
|
||||
model: "gpt-4o-mini",
|
||||
temperature: 0.7,
|
||||
model: "gpt-4o-mini",
|
||||
});
|
||||
|
||||
const solanaAgent = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL,
|
||||
process.env.OPENAI_API_KEY!,
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL,
|
||||
process.env.OPENAI_API_KEY!,
|
||||
);
|
||||
|
||||
const tools = createSolanaTools(solanaAgent);
|
||||
const memory = new MemorySaver();
|
||||
|
||||
const agent = createReactAgent({
|
||||
llm,
|
||||
tools,
|
||||
checkpointSaver: memory,
|
||||
messageModifier: `
|
||||
llm,
|
||||
tools,
|
||||
checkpointSaver: memory,
|
||||
messageModifier: `
|
||||
You are a helpful agent that can interact onchain using the Solana Agent Kit. You are
|
||||
empowered to interact onchain using your tools. If you ever need funds, you can request them from the
|
||||
faucet. If not, you can provide your wallet details and request funds from the user. If there is a 5XX
|
||||
@@ -34,38 +34,38 @@ const agent = createReactAgent({
|
||||
});
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const messages = body.messages ?? [];
|
||||
try {
|
||||
const body = await req.json();
|
||||
const messages = body.messages ?? [];
|
||||
|
||||
const eventStream = agent.streamEvents(
|
||||
{
|
||||
messages,
|
||||
},
|
||||
{
|
||||
version: "v2",
|
||||
configurable: {
|
||||
thread_id: "Solana Agent Kit!",
|
||||
},
|
||||
},
|
||||
);
|
||||
const eventStream = agent.streamEvents(
|
||||
{
|
||||
messages,
|
||||
},
|
||||
{
|
||||
version: "v2",
|
||||
configurable: {
|
||||
thread_id: "Solana Agent Kit!",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
const transformStream = new ReadableStream({
|
||||
async start(controller) {
|
||||
for await (const { event, data } of eventStream) {
|
||||
if (event === "on_chat_model_stream") {
|
||||
if (!!data.chunk.content) {
|
||||
controller.enqueue(textEncoder.encode(data.chunk.content));
|
||||
}
|
||||
}
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
const textEncoder = new TextEncoder();
|
||||
const transformStream = new ReadableStream({
|
||||
async start(controller) {
|
||||
for await (const { event, data } of eventStream) {
|
||||
if (event === "on_chat_model_stream") {
|
||||
if (data.chunk.content) {
|
||||
controller.enqueue(textEncoder.encode(data.chunk.content));
|
||||
}
|
||||
}
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(transformStream);
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: e.status ?? 500 });
|
||||
}
|
||||
return new Response(transformStream);
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: e.status ?? 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,4 +537,4 @@ const executor = await initializeAgentExecutorWithOptions(tools, llm, {
|
||||
},
|
||||
});
|
||||
\`\`\`
|
||||
`;
|
||||
`;
|
||||
|
||||
@@ -2,29 +2,29 @@ import { marked } from "marked";
|
||||
import DOMPurify from "isomorphic-dompurify";
|
||||
|
||||
interface MarkedOptions {
|
||||
gfm: boolean;
|
||||
breaks: boolean;
|
||||
headerIds: boolean;
|
||||
mangle: false;
|
||||
highlight?: (code: string, lang: string) => string;
|
||||
gfm: boolean;
|
||||
breaks: boolean;
|
||||
headerIds: boolean;
|
||||
mangle: false;
|
||||
highlight?: (code: string, lang: string) => string;
|
||||
}
|
||||
|
||||
// Configure marked options
|
||||
const markedOptions: MarkedOptions = {
|
||||
gfm: true, // GitHub Flavored Markdown
|
||||
breaks: true, // Convert \n to <br>
|
||||
headerIds: true, // Add ids to headers
|
||||
mangle: false, // Don't escape HTML
|
||||
highlight: function (code: string, lang: string): string {
|
||||
// You can add syntax highlighting here if needed
|
||||
return code;
|
||||
},
|
||||
gfm: true, // GitHub Flavored Markdown
|
||||
breaks: true, // Convert \n to <br>
|
||||
headerIds: true, // Add ids to headers
|
||||
mangle: false, // Don't escape HTML
|
||||
highlight: function (code: string, lang: string): string {
|
||||
// You can add syntax highlighting here if needed
|
||||
return code;
|
||||
},
|
||||
};
|
||||
|
||||
marked.setOptions(markedOptions);
|
||||
|
||||
// Basic markdown to HTML conversion with sanitization
|
||||
export default function markdownToHtml(markdown: string) {
|
||||
const rawHtml = marked.parse(markdown);
|
||||
return DOMPurify.sanitize(rawHtml as string);
|
||||
const rawHtml = marked.parse(markdown);
|
||||
return DOMPurify.sanitize(rawHtml as string);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user