UNPKG

@arizeai/phoenix-client

Version:
51 lines 1.63 kB
import { createClient } from "../client.js"; import { ADD_SPAN_NOTE_IDENTIFIER } from "../constants/serverRequirements.js"; import { formatApiError } from "../utils/apiErrorUtils.js"; import { ensureServerCapability } from "../utils/serverVersionUtils.js"; /** * Add a note to a span. * * When `spanNote.identifier` is omitted, each call appends a new note with an * auto-generated identifier. When `identifier` is non-empty, repeated calls * with the same `(spanId, name='note', identifier)` overwrite the existing * note. * * @param params - The parameters to add a span note * @returns The ID of the created note annotation * * @example * ```ts * const result = await addSpanNote({ * spanNote: { * spanId: "123abc", * note: "This span looks suspicious, needs review" * } * }); * ``` */ export async function addSpanNote({ client: _client, spanNote, }) { const client = _client ?? createClient(); if (spanNote.identifier) { await ensureServerCapability({ client, requirement: ADD_SPAN_NOTE_IDENTIFIER, }); } const { data, error } = await client.POST("/v1/span_notes", { body: { data: { span_id: spanNote.spanId.trim(), note: spanNote.note, identifier: spanNote.identifier, }, }, }); if (error) { throw new Error(`Failed to add span note: ${formatApiError(error)}`); } if (!data?.data) { throw new Error("Failed to add span note: no data returned"); } return data.data; } //# sourceMappingURL=addSpanNote.js.map