import { trace } from "@agentmark-ai/sdk";
import { client } from "./agentmark.client";
import { generateText } from "ai";
const sessionId = `session-${Date.now()}`;
// Each trace call with the same sessionId groups under one session
const { result: greeting } = await trace(
{
name: 'handle-greeting',
sessionId,
sessionName: 'Customer Support Chat #12345',
userId: 'user-123'
},
async (ctx) => {
const prompt = await client.loadTextPrompt('chat.prompt.mdx');
const input = await prompt.format({
props: { message: 'Hello!' },
telemetry: { isEnabled: true }
});
return await generateText(input);
}
);
// Later, another trace in the same session
const { result: followUp } = await trace(
{
name: 'handle-follow-up',
sessionId,
sessionName: 'Customer Support Chat #12345',
userId: 'user-123'
},
async (ctx) => {
const prompt = await client.loadTextPrompt('chat.prompt.mdx');
const input = await prompt.format({
props: { message: 'What can you help me with?' },
telemetry: { isEnabled: true }
});
return await generateText(input);
}
);