UNPKG

@arizeai/phoenix-client

Version:
54 lines 1.81 kB
import { createClient } from "../client.js"; import { ADD_SESSION_NOTE, ADD_SESSION_NOTE_IDENTIFIER, } from "../constants/serverRequirements.js"; import { formatApiError } from "../utils/apiErrorUtils.js"; import { ensureServerCapability } from "../utils/serverVersionUtils.js"; /** * Add a note to a session. * * When `sessionNote.identifier` is omitted, each call appends a new note with * an auto-generated identifier. When `identifier` is non-empty, repeated calls * with the same `(sessionId, name='note', identifier)` overwrite the existing * note. * * @param params - The parameters to add a session note. * @returns The ID of the created note annotation. * * @requires Phoenix server >= 14.17.0 * * @example * ```ts * const result = await addSessionNote({ * sessionNote: { * sessionId: "my-session", * note: "Needs review" * } * }); * ``` */ export async function addSessionNote({ client: _client, sessionNote, }) { const client = _client ?? createClient(); await ensureServerCapability({ client, requirement: ADD_SESSION_NOTE }); if (sessionNote.identifier) { await ensureServerCapability({ client, requirement: ADD_SESSION_NOTE_IDENTIFIER, }); } const { data, error } = await client.POST("/v1/session_notes", { body: { data: { session_id: sessionNote.sessionId.trim(), note: sessionNote.note, identifier: sessionNote.identifier, }, }, }); if (error) { throw new Error(`Failed to add session note: ${formatApiError(error)}`); } if (!data?.data) { throw new Error("Failed to add session note: no data returned"); } return data.data; } //# sourceMappingURL=addSessionNote.js.map