{"version":3,"sources":["../src/client-sdk/services/suites/suites-api.service.ts"],"sourcesContent":["import type { paths } 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 SuiteResponse = NonNullable<\n  paths[\"/api/suites\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n>[number] & {\n  /** URL to view this suite on the LangWatch platform */\n  platformUrl?: string;\n};\n\nexport type CreateSuiteBody = NonNullable<\n  paths[\"/api/suites\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\nexport type UpdateSuiteBody = NonNullable<\n  paths[\"/api/suites/{id}\"][\"patch\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\nexport type SuiteRunResult =\n  paths[\"/api/suites/{id}/run\"][\"post\"][\"responses\"][\"200\"][\"content\"][\"application/json\"];\n\nexport interface SuiteTarget {\n  type: \"prompt\" | \"http\" | \"code\" | \"workflow\";\n  referenceId: string;\n}\n\nexport class SuitesApiError extends Error {\n  constructor(\n    message: string,\n    public readonly operation: string,\n    public readonly originalError?: unknown,\n  ) {\n    super(message);\n    this.name = \"SuitesApiError\";\n  }\n}\n\nexport class SuitesApiService {\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 SuitesApiError(message, operation, error);\n  }\n\n  async getAll(): Promise<SuiteResponse[]> {\n    const { data, error } = await this.apiClient.GET(\"/api/suites\");\n    if (error) this.handleApiError(\"list suites\", error);\n    return data;\n  }\n\n  async get(id: string): Promise<SuiteResponse> {\n    const { data, error } = await this.apiClient.GET(\"/api/suites/{id}\", {\n      params: { path: { id } },\n    });\n    if (error) this.handleApiError(`get suite \"${id}\"`, error);\n    return data;\n  }\n\n  async create(params: CreateSuiteBody): Promise<SuiteResponse> {\n    const { data, error } = await this.apiClient.POST(\"/api/suites\", {\n      body: params,\n    });\n    if (error) this.handleApiError(\"create suite\", error);\n    return data;\n  }\n\n  async update(id: string, params: UpdateSuiteBody): Promise<SuiteResponse> {\n    const { data, error } = await this.apiClient.PATCH(\"/api/suites/{id}\", {\n      params: { path: { id } },\n      body: params,\n    });\n    if (error) this.handleApiError(`update suite \"${id}\"`, error);\n    return data;\n  }\n\n  async duplicate(id: string): Promise<SuiteResponse> {\n    const { data, error } = await this.apiClient.POST(\"/api/suites/{id}/duplicate\", {\n      params: { path: { id } },\n    });\n    if (error) this.handleApiError(`duplicate suite \"${id}\"`, error);\n    return data;\n  }\n\n  async run(id: string, idempotencyKey?: string): Promise<SuiteRunResult> {\n    const { data, error } = await this.apiClient.POST(\"/api/suites/{id}/run\", {\n      params: { path: { id } },\n      body: {\n        idempotencyKey: idempotencyKey ?? `cli-${Date.now()}-${Math.random().toString(36).slice(2)}`,\n      },\n    });\n    if (error) this.handleApiError(`run suite \"${id}\"`, error);\n    return data;\n  }\n\n  async delete(id: string): Promise<{ id: string; archived: boolean }> {\n    const { data, error } = await this.apiClient.DELETE(\"/api/suites/{id}\", {\n      params: { path: { id } },\n    });\n    if (error) this.handleApiError(`delete suite \"${id}\"`, error);\n    return data as unknown as { id: string; archived: boolean };\n  }\n}\n"],"mappings":";;;;;;;;;AAkCO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC,YACE,SACgB,WACA,eAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,MAAuB;AAAA,EAG5B,YAAY,QAAqD;AAhDnE;AAiDI,SAAK,aAAY,sCAAQ,uBAAR,YAA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