@arizeai/phoenix-client
Version:
A client for the Phoenix API
52 lines • 1.72 kB
JavaScript
import { createClient } from "../client.js";
import { ADD_TRACE_NOTE, ADD_TRACE_NOTE_IDENTIFIER, } from "../constants/serverRequirements.js";
import { formatApiError } from "../utils/apiErrorUtils.js";
import { ensureServerCapability } from "../utils/serverVersionUtils.js";
/**
* Add a note to a trace.
*
* When `traceNote.identifier` is omitted, each call appends a new note with an
* auto-generated identifier. When `identifier` is non-empty, repeated calls
* with the same `(traceId, name='note', identifier)` overwrite the existing
* note.
*
* @param params - The parameters to add a trace note.
* @returns The ID of the created note annotation.
*
* @example
* ```ts
* const result = await addTraceNote({
* traceNote: {
* traceId: "abc123",
* note: "Needs review"
* }
* });
* ```
*/
export async function addTraceNote({ client: _client, traceNote, }) {
const client = _client ?? createClient();
await ensureServerCapability({ client, requirement: ADD_TRACE_NOTE });
if (traceNote.identifier) {
await ensureServerCapability({
client,
requirement: ADD_TRACE_NOTE_IDENTIFIER,
});
}
const { data, error } = await client.POST("/v1/trace_notes", {
body: {
data: {
trace_id: traceNote.traceId.trim(),
note: traceNote.note,
identifier: traceNote.identifier,
},
},
});
if (error) {
throw new Error(`Failed to add trace note: ${formatApiError(error)}`);
}
if (!data?.data) {
throw new Error("Failed to add trace note: no data returned");
}
return data.data;
}
//# sourceMappingURL=addTraceNote.js.map