TypeScript SDK
The TypeScript SDK is currently in development. For now, you can interact with DuraGraph using the REST API or the LangGraph SDK.
Using the LangGraph SDK
Section titled “Using the LangGraph SDK”DuraGraph is compatible with the LangGraph TypeScript SDK:
import { Client } from '@langchain/langgraph-sdk';
// Point to your DuraGraph instanceconst client = new Client({ apiUrl: 'http://localhost:8081',});
// Create an assistantconst assistant = await client.assistants.create({ graphId: 'my-graph', config: {},});
// Create a threadconst thread = await client.threads.create();
// Run a workflowconst run = await client.runs.create(thread.thread_id, assistant.assistant_id, { input: { message: 'Hello!' },});
console.log('Run created:', run);Using the REST API
Section titled “Using the REST API”const baseUrl = 'http://localhost:8081/api/v1';
// Create an assistantconst response = await fetch(`${baseUrl}/assistants`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'my-assistant', graph_schema: {}, }),});
const assistant = await response.json();console.log('Created assistant:', assistant);Streaming with SSE
Section titled “Streaming with SSE”const runId = 'your-run-id';const eventSource = new EventSource(`http://localhost:8081/api/v1/stream?run_id=${runId}`);
eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Event:', data);};
eventSource.onerror = () => { eventSource.close();};