{"version":3,"sources":["../src/client-sdk/services/annotations/annotations-api.service.ts"],"sourcesContent":["import type { paths, components } from \"@/internal/generated/openapi/api-client\";\nimport {\n  createLangWatchApiClient,\n  type LangwatchApiClient,\n} from \"@/internal/api/client\";\nimport { type InternalConfig } from \"@/client-sdk/types\";\nimport {\n  extractStatusFromResponse,\n  formatApiErrorForOperation,\n} from \"@/client-sdk/services/_shared/format-api-error\";\n\nexport type AnnotationResponse = components[\"schemas\"][\"Annotation\"];\n\nexport type CreateAnnotationBody = NonNullable<\n  paths[\"/api/annotations/trace/{id}\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\nexport class AnnotationsApiError extends Error {\n  constructor(\n    message: string,\n    public readonly operation: string,\n    public readonly originalError?: unknown,\n  ) {\n    super(message);\n    this.name = \"AnnotationsApiError\";\n  }\n}\n\nexport class AnnotationsApiService {\n  private readonly apiClient: LangwatchApiClient;\n\n  constructor(config?: Pick<InternalConfig, \"langwatchApiClient\">) {\n    this.apiClient = config?.langwatchApiClient ?? createLangWatchApiClient();\n  }\n\n  private handleApiError(operation: string, error: unknown): never {\n    const message = formatApiErrorForOperation({ operation: operation, error: error, options: {\n      status: extractStatusFromResponse(error),\n    } });\n    throw new AnnotationsApiError(message, operation, error);\n  }\n\n  async getAll(): Promise<AnnotationResponse[]> {\n    const { data, error } = await this.apiClient.GET(\"/api/annotations\");\n    if (error) this.handleApiError(\"fetch all annotations\", error);\n    return data;\n  }\n\n  async get(id: string): Promise<AnnotationResponse> {\n    const { data, error } = await this.apiClient.GET(\"/api/annotations/{id}\", {\n      params: { path: { id } },\n    });\n    if (error)\n      this.handleApiError(`fetch annotation with ID \"${id}\"`, error);\n    return data;\n  }\n\n  async getByTrace(traceId: string): Promise<AnnotationResponse[]> {\n    const { data, error } = await this.apiClient.GET(\n      \"/api/annotations/trace/{id}\",\n      {\n        params: { path: { id: traceId } },\n      },\n    );\n    if (error)\n      this.handleApiError(`fetch annotations for trace \"${traceId}\"`, error);\n    return data;\n  }\n\n  async create(traceId: string, params: CreateAnnotationBody): Promise<AnnotationResponse> {\n    const { data, error } = await this.apiClient.POST(\n      \"/api/annotations/trace/{id}\",\n      {\n        params: { path: { id: traceId } },\n        body: params,\n      },\n    );\n    if (error) this.handleApiError(\"create annotation\", error);\n    return data;\n  }\n\n  async delete(id: string): Promise<{ status?: string; message?: string }> {\n    const { data, error } = await this.apiClient.DELETE(\n      \"/api/annotations/{id}\",\n      {\n        params: { path: { id } },\n      },\n    );\n    if (error)\n      this.handleApiError(`delete annotation with ID \"${id}\"`, error);\n    return data;\n  }\n}\n"],"mappings":";;;;;;;;;AAiBO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACE,SACgB,WACA,eAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,wBAAN,MAA4B;AAAA,EAGjC,YAAY,QAAqD;AA/BnE;AAgCI,SAAK,aAAY,sCAAQ,uBAAR,YAA8B,yBAAyB;AAAA,EAC1E;AAAA,EAEQ,eAAe,WAAmB,OAAuB;AAC/D,UAAM,UAAU,2BAA2B,EAAE,WAAsB,OAAc,SAAS;AAAA,MACxF,QAAQ,0BAA0B,KAAK;AAAA,IACzC,EAAE,CAAC;AACH,UAAM,IAAI,oBAAoB,SAAS,WAAW,KAAK;AAAA,EACzD;AAAA,EAEA,MAAM,SAAwC;AAC5C,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,KAAK,UAAU,IAAI,kBAAkB;AACnE,QAAI,MAAO,MAAK,eAAe,yBAAyB,KAAK;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,IAAI,IAAyC;AACjD,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,KAAK,UAAU,IAAI,yBAAyB;AAAA,MACxE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE;AAAA,IACzB,CAAC;AACD,QAAI;AACF,WAAK,eAAe,6BAA6B,EAAE,KAAK,KAAK;AAC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