Lunary JS API Reference

Class: Lunary

Constructor

MethodDescription
constructor()Initializes the Lunary instance.

Methods

MethodDescription
init({ appId?: string, verbose?: boolean, apiUrl?: string })Initializes the Lunary with the provided options.
trackEvent(type: string, event: string, data: RunEvent)Tracks an event with the provided type, event name, and data. The data parameter is of type RunEvent, which has the following structure:
PropertyDescription
typeThe type of the event. It can be one of the following: "log", "tool", "agent", "llm", "convo", "chain", "retriever", "embed", "chat", "convo".
eventThe name of the event. It can be one of the following: "start", "end", "error", "info", "warn", "feedback".
appThe ID of the app.
timestampThe timestamp of the event.
userIdThe ID of the user (optional).
userPropsThe properties of the user (optional).
parentRunIdThe ID of the parent run (optional).
extraExtra data (optional).
tagsTags associated with the event (optional).
runtimeThe runtime of the event (optional).
errorThe error object, if any, with properties message and stack (optional).
runIdThe ID of the run.
inputThe input data (optional).
outputThe output data (optional).
tokensUsageThe token usage data (optional).

| Method | Description | | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------ | | wrapAgent(func: Function, params?: WrapParams) -> Promise | Wraps an agent's Promise to track its input, results, and any errors. Returns a Promise. | | wrapTool(func: Function, params?: WrapParams) -> Promise | Wraps a tool's Promise to track its input, results, and any errors. Returns a Promise. | | wrapModel(func: Function, params?: WrapParams) -> Promise | Wraps a model's Promise to track its input, results, and any errors. Returns a Promise. | | info(message: string, extra?: any) | Logs an informational message with optional extra data. | | log(message: string, extra?: any) | Alias for info. | | warn(message: string, extra?: any) | Logs a warning message with optional extra data. | | error(message: string | any, error?: any) | Reports any errors that occur during the conversation. | | flush() -> Promise | Ensures the event queue is flushed before exiting the program. Returns a Promise. | | trackFeedback(messageId: string, feedback: cJSON) | Tracks feedback for a specific message. | | startThread() -> Thread | Starts a new chat conversation and returns a Thread instance. | | resumeThread(id: string) -> Thread | Resumes a chat conversation with the given thread ID and returns the Thread instance. |

Class: Thread

Constructor

  • constructor(id?: string): Initializes the Thread instance with a provided Lunary.

Methods

  • trackUserMessage(text: string, props?: cJSON, customId?: string) -> string: Tracks a new message from the user and returns the message ID.

  • trackBotMessage(replyToId: string, text: string, props?: cJSON): Tracks a new message from the bot.

(React Specific Exports) Hooks

  • useChatMonitor() -> { startThread: Function, trackUserMessage: Function, trackBotMessage: Function, trackFeedback: Function }: A React hook that provides functions for starting a new thread, tracking user messages, tracking bot messages, and tracking feedback.

  • useMonitorVercelAI(props) -> { ...props, trackFeedback: Function }: A React hook that provides a function for tracking feedback in addition to the properties passed in.

Questions? We're here to help.