diff --git a/packages/core/src/api/api/resources/unstable/client/Client.ts b/packages/core/src/api/api/resources/unstable/client/Client.ts index 4836d7ee..9e981be7 100644 --- a/packages/core/src/api/api/resources/unstable/client/Client.ts +++ b/packages/core/src/api/api/resources/unstable/client/Client.ts @@ -3,6 +3,7 @@ */ import * as core from "../../../../core/index.js"; +import { DashboardWidgets } from "../resources/dashboardWidgets/client/Client.js"; import { EvaluationRules } from "../resources/evaluationRules/client/Client.js"; import { Evaluators } from "../resources/evaluators/client/Client.js"; @@ -29,6 +30,7 @@ export declare namespace Unstable { export class Unstable { protected readonly _options: Unstable.Options; + protected _dashboardWidgets: DashboardWidgets | undefined; protected _evaluationRules: EvaluationRules | undefined; protected _evaluators: Evaluators | undefined; @@ -36,6 +38,10 @@ export class Unstable { this._options = _options; } + public get dashboardWidgets(): DashboardWidgets { + return (this._dashboardWidgets ??= new DashboardWidgets(this._options)); + } + public get evaluationRules(): EvaluationRules { return (this._evaluationRules ??= new EvaluationRules(this._options)); } diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/client/Client.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/client/Client.ts new file mode 100644 index 00000000..aecd448b --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/client/Client.ts @@ -0,0 +1,261 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as core from "../../../../../../core/index.js"; +import * as LangfuseAPI from "../../../../../index.js"; +import { + mergeHeaders, + mergeOnlyDefinedHeaders, +} from "../../../../../../core/headers.js"; +import * as errors from "../../../../../../errors/index.js"; + +export declare namespace DashboardWidgets { + export interface Options { + environment: core.Supplier; + /** Specify a custom URL to connect the client to. */ + baseUrl?: core.Supplier; + username?: core.Supplier; + password?: core.Supplier; + /** Override the X-Langfuse-Sdk-Name header */ + xLangfuseSdkName?: core.Supplier; + /** Override the X-Langfuse-Sdk-Version header */ + xLangfuseSdkVersion?: core.Supplier; + /** Override the X-Langfuse-Public-Key header */ + xLangfusePublicKey?: core.Supplier; + /** Additional headers to include in requests. */ + headers?: Record< + string, + string | core.Supplier | null | undefined + >; + } + + export interface RequestOptions { + /** The maximum time to wait for a response in seconds. */ + timeoutInSeconds?: number; + /** The number of times to retry the request. Defaults to 2. */ + maxRetries?: number; + /** A hook to abort the request. */ + abortSignal?: AbortSignal; + /** Override the X-Langfuse-Sdk-Name header */ + xLangfuseSdkName?: string | undefined; + /** Override the X-Langfuse-Sdk-Version header */ + xLangfuseSdkVersion?: string | undefined; + /** Override the X-Langfuse-Public-Key header */ + xLangfusePublicKey?: string | undefined; + /** Additional query string parameters to include in the request. */ + queryParams?: Record; + /** Additional headers to include in the request. */ + headers?: Record< + string, + string | core.Supplier | null | undefined + >; + } +} + +export class DashboardWidgets { + protected readonly _options: DashboardWidgets.Options; + + constructor(_options: DashboardWidgets.Options) { + this._options = _options; + } + + /** + * Create a reusable dashboard widget. + * + * This endpoint creates the widget. It does not place the widget on a dashboard grid, this has to be done in the UI. + * + * Supported views are `observations`, `scores-numeric`, and `scores-categorical`. + * The legacy `traces` view is not supported by this unstable API, `minVersion` defaults to `2`; values below `2` are rejected. + * + * Unstable API note: + * - This surface may evolve while dashboard/widget APIs are being finalized. + * + * @param {LangfuseAPI.unstable.CreateDashboardWidgetRequest} request + * @param {DashboardWidgets.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link LangfuseAPI.unstable.BadRequestError} + * @throws {@link LangfuseAPI.unstable.UnauthorizedError} + * @throws {@link LangfuseAPI.unstable.AccessDeniedError} + * @throws {@link LangfuseAPI.unstable.MethodNotAllowedError} + * @throws {@link LangfuseAPI.unstable.TooManyRequestsError} + * @throws {@link LangfuseAPI.unstable.InternalServerError} + * @throws {@link LangfuseAPI.Error} + * @throws {@link LangfuseAPI.UnauthorizedError} + * @throws {@link LangfuseAPI.AccessDeniedError} + * @throws {@link LangfuseAPI.MethodNotAllowedError} + * @throws {@link LangfuseAPI.NotFoundError} + * + * @example + * await client.unstable.dashboardWidgets.create({ + * name: "Total cost by model", + * description: "Total model cost grouped by provided model name.", + * view: "observations", + * dimensions: [{ + * field: "providedModelName" + * }], + * metrics: [{ + * measure: "totalCost", + * agg: "sum" + * }], + * filters: [], + * chartType: "HORIZONTAL_BAR", + * chartConfig: { + * type: "HORIZONTAL_BAR", + * row_limit: 10 + * }, + * minVersion: 2 + * }) + */ + public create( + request: LangfuseAPI.unstable.CreateDashboardWidgetRequest, + requestOptions?: DashboardWidgets.RequestOptions, + ): core.HttpResponsePromise { + return core.HttpResponsePromise.fromPromise( + this.__create(request, requestOptions), + ); + } + + private async __create( + request: LangfuseAPI.unstable.CreateDashboardWidgetRequest, + requestOptions?: DashboardWidgets.RequestOptions, + ): Promise> { + let _headers: core.Fetcher.Args["headers"] = mergeHeaders( + this._options?.headers, + mergeOnlyDefinedHeaders({ + Authorization: await this._getAuthorizationHeader(), + "X-Langfuse-Sdk-Name": + requestOptions?.xLangfuseSdkName ?? this._options?.xLangfuseSdkName, + "X-Langfuse-Sdk-Version": + requestOptions?.xLangfuseSdkVersion ?? + this._options?.xLangfuseSdkVersion, + "X-Langfuse-Public-Key": + requestOptions?.xLangfusePublicKey ?? + this._options?.xLangfusePublicKey, + }), + requestOptions?.headers, + ); + const _response = await core.fetcher({ + url: core.url.join( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)), + "/api/public/unstable/dashboard-widgets", + ), + method: "POST", + headers: _headers, + contentType: "application/json", + queryParameters: requestOptions?.queryParams, + requestType: "json", + body: request, + timeoutMs: + requestOptions?.timeoutInSeconds != null + ? requestOptions.timeoutInSeconds * 1000 + : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return { + data: _response.body as LangfuseAPI.unstable.DashboardWidget, + rawResponse: _response.rawResponse, + }; + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new LangfuseAPI.unstable.BadRequestError( + _response.error.body as LangfuseAPI.unstable.PublicApiError, + _response.rawResponse, + ); + case 401: + throw new LangfuseAPI.unstable.UnauthorizedError( + _response.error.body as LangfuseAPI.unstable.PublicApiError, + _response.rawResponse, + ); + case 403: + throw new LangfuseAPI.unstable.AccessDeniedError( + _response.error.body as LangfuseAPI.unstable.PublicApiError, + _response.rawResponse, + ); + case 405: + throw new LangfuseAPI.unstable.MethodNotAllowedError( + _response.error.body as LangfuseAPI.unstable.PublicApiError, + _response.rawResponse, + ); + case 429: + throw new LangfuseAPI.unstable.TooManyRequestsError( + _response.error.body as LangfuseAPI.unstable.PublicApiError, + _response.rawResponse, + ); + case 500: + throw new LangfuseAPI.unstable.InternalServerError( + _response.error.body as LangfuseAPI.unstable.PublicApiError, + _response.rawResponse, + ); + case 400: + throw new LangfuseAPI.Error( + _response.error.body as unknown, + _response.rawResponse, + ); + case 401: + throw new LangfuseAPI.UnauthorizedError( + _response.error.body as unknown, + _response.rawResponse, + ); + case 403: + throw new LangfuseAPI.AccessDeniedError( + _response.error.body as unknown, + _response.rawResponse, + ); + case 405: + throw new LangfuseAPI.MethodNotAllowedError( + _response.error.body as unknown, + _response.rawResponse, + ); + case 404: + throw new LangfuseAPI.NotFoundError( + _response.error.body as unknown, + _response.rawResponse, + ); + default: + throw new errors.LangfuseAPIError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + rawResponse: _response.rawResponse, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.LangfuseAPIError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + rawResponse: _response.rawResponse, + }); + case "timeout": + throw new errors.LangfuseAPITimeoutError( + "Timeout exceeded when calling POST /api/public/unstable/dashboard-widgets.", + ); + case "unknown": + throw new errors.LangfuseAPIError({ + message: _response.error.errorMessage, + rawResponse: _response.rawResponse, + }); + } + } + + protected async _getAuthorizationHeader(): Promise { + const username = await core.Supplier.get(this._options.username); + const password = await core.Supplier.get(this._options.password); + if (username != null && password != null) { + return core.BasicAuth.toAuthorizationHeader({ + username: username, + password: password, + }); + } + + return undefined; + } +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/client/index.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/client/index.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/client/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/index.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/index.ts new file mode 100644 index 00000000..f095e147 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/index.ts @@ -0,0 +1,2 @@ +export * from "./types/index.js"; +export * from "./client/index.js"; diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/CreateDashboardWidgetRequest.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/CreateDashboardWidgetRequest.ts new file mode 100644 index 00000000..807c5b4d --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/CreateDashboardWidgetRequest.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as LangfuseAPI from "../../../../../index.js"; + +export interface CreateDashboardWidgetRequest { + name: string; + description: string; + view: LangfuseAPI.unstable.DashboardWidgetView; + dimensions: LangfuseAPI.unstable.DashboardWidgetDimension[]; + metrics: LangfuseAPI.unstable.DashboardWidgetMetric[]; + filters: LangfuseAPI.unstable.DashboardWidgetFilter[]; + chartType: LangfuseAPI.unstable.DashboardWidgetChartType; + chartConfig: LangfuseAPI.unstable.DashboardWidgetChartConfig; + minVersion?: number; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidget.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidget.ts new file mode 100644 index 00000000..964406c5 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidget.ts @@ -0,0 +1,20 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as LangfuseAPI from "../../../../../index.js"; + +export interface DashboardWidget { + id: string; + createdAt: string; + updatedAt: string; + name: string; + description: string; + view: LangfuseAPI.unstable.DashboardWidgetView; + dimensions: LangfuseAPI.unstable.DashboardWidgetDimension[]; + metrics: LangfuseAPI.unstable.DashboardWidgetMetric[]; + filters: LangfuseAPI.unstable.DashboardWidgetFilter[]; + chartType: LangfuseAPI.unstable.DashboardWidgetChartType; + chartConfig: LangfuseAPI.unstable.DashboardWidgetChartConfig; + minVersion: number; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetChartConfig.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetChartConfig.ts new file mode 100644 index 00000000..086e78e8 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetChartConfig.ts @@ -0,0 +1,21 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as LangfuseAPI from "../../../../../index.js"; + +/** + * Chart-specific widget configuration. + * + * `type` must match the top-level `chartType`. + * `row_limit` applies to total-value charts and pivot tables. + * `bins` applies to histograms. + * `defaultSort` applies to pivot tables. + */ +export interface DashboardWidgetChartConfig { + type: LangfuseAPI.unstable.DashboardWidgetChartType; + row_limit?: number; + show_value_labels?: boolean; + bins?: number; + defaultSort?: LangfuseAPI.unstable.DashboardWidgetDefaultSort; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetChartType.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetChartType.ts new file mode 100644 index 00000000..c93839b8 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetChartType.ts @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type DashboardWidgetChartType = + | "LINE_TIME_SERIES" + | "AREA_TIME_SERIES" + | "BAR_TIME_SERIES" + | "HORIZONTAL_BAR" + | "VERTICAL_BAR" + | "PIE" + | "NUMBER" + | "HISTOGRAM" + | "PIVOT_TABLE"; +export const DashboardWidgetChartType = { + LineTimeSeries: "LINE_TIME_SERIES", + AreaTimeSeries: "AREA_TIME_SERIES", + BarTimeSeries: "BAR_TIME_SERIES", + HorizontalBar: "HORIZONTAL_BAR", + VerticalBar: "VERTICAL_BAR", + Pie: "PIE", + Number: "NUMBER", + Histogram: "HISTOGRAM", + PivotTable: "PIVOT_TABLE", +} as const; diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetDefaultSort.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetDefaultSort.ts new file mode 100644 index 00000000..ba5b147f --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetDefaultSort.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as LangfuseAPI from "../../../../../index.js"; + +export interface DashboardWidgetDefaultSort { + column: string; + order: LangfuseAPI.unstable.DashboardWidgetSortOrder; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetDimension.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetDimension.ts new file mode 100644 index 00000000..4454cc8a --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetDimension.ts @@ -0,0 +1,7 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export interface DashboardWidgetDimension { + field: string; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetFilter.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetFilter.ts new file mode 100644 index 00000000..c791f3b7 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetFilter.ts @@ -0,0 +1,17 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +/** + * A dashboard widget filter in Langfuse filter-state shape. + * + * Filter shapes depend on `type`, for example string filters use a string `value`, + * option filters use a list of strings, and object filters include `key`. + */ +export interface DashboardWidgetFilter { + column: string; + operator: string; + type: string; + value?: unknown; + key?: string; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetMetric.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetMetric.ts new file mode 100644 index 00000000..ae857b03 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetMetric.ts @@ -0,0 +1,10 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as LangfuseAPI from "../../../../../index.js"; + +export interface DashboardWidgetMetric { + measure: string; + agg: LangfuseAPI.unstable.DashboardWidgetMetricAggregation; +} diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetMetricAggregation.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetMetricAggregation.ts new file mode 100644 index 00000000..2fe6d9b4 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetMetricAggregation.ts @@ -0,0 +1,31 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type DashboardWidgetMetricAggregation = + | "sum" + | "avg" + | "count" + | "max" + | "min" + | "p50" + | "p75" + | "p90" + | "p95" + | "p99" + | "histogram" + | "uniq"; +export const DashboardWidgetMetricAggregation = { + Sum: "sum", + Avg: "avg", + Count: "count", + Max: "max", + Min: "min", + P50: "p50", + P75: "p75", + P90: "p90", + P95: "p95", + P99: "p99", + Histogram: "histogram", + Uniq: "uniq", +} as const; diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetSortOrder.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetSortOrder.ts new file mode 100644 index 00000000..a2e684c8 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetSortOrder.ts @@ -0,0 +1,9 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type DashboardWidgetSortOrder = "ASC" | "DESC"; +export const DashboardWidgetSortOrder = { + Asc: "ASC", + Desc: "DESC", +} as const; diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetView.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetView.ts new file mode 100644 index 00000000..3a5b5d90 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/DashboardWidgetView.ts @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +export type DashboardWidgetView = + | "observations" + | "scores-numeric" + | "scores-categorical"; +export const DashboardWidgetView = { + Observations: "observations", + ScoresNumeric: "scores-numeric", + ScoresCategorical: "scores-categorical", +} as const; diff --git a/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/index.ts b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/index.ts new file mode 100644 index 00000000..acad6c29 --- /dev/null +++ b/packages/core/src/api/api/resources/unstable/resources/dashboardWidgets/types/index.ts @@ -0,0 +1,11 @@ +export * from "./DashboardWidgetView.js"; +export * from "./DashboardWidgetChartType.js"; +export * from "./DashboardWidgetMetricAggregation.js"; +export * from "./DashboardWidgetDimension.js"; +export * from "./DashboardWidgetMetric.js"; +export * from "./DashboardWidgetFilter.js"; +export * from "./DashboardWidgetChartConfig.js"; +export * from "./DashboardWidgetDefaultSort.js"; +export * from "./DashboardWidgetSortOrder.js"; +export * from "./CreateDashboardWidgetRequest.js"; +export * from "./DashboardWidget.js"; diff --git a/packages/core/src/api/api/resources/unstable/resources/index.ts b/packages/core/src/api/api/resources/unstable/resources/index.ts index ff0f6f1a..ae1558c5 100644 --- a/packages/core/src/api/api/resources/unstable/resources/index.ts +++ b/packages/core/src/api/api/resources/unstable/resources/index.ts @@ -1,5 +1,7 @@ export * as commons from "./commons/index.js"; export * from "./commons/types/index.js"; +export * as dashboardWidgets from "./dashboardWidgets/index.js"; +export * from "./dashboardWidgets/types/index.js"; export * as errors from "./errors/index.js"; export * from "./errors/types/index.js"; export * as evaluationRules from "./evaluationRules/index.js";