@cubos/agent-sdk 0.0.1152175 → 0.0.1153146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/index.d.ts +3 -3
- package/dist/admin/metrics.d.ts +172 -0
- package/dist/generated/schema.d.ts +643 -345
- package/dist/index.d.ts +1 -2
- package/dist/index.js +73 -44
- package/dist/index.js.map +6 -6
- package/package.json +1 -1
- package/dist/admin/cost-metrics.d.ts +0 -61
package/dist/admin/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ import { channelsApi } from "./channels.js";
|
|
|
7
7
|
import { clientToolsApi } from "./client-tools.js";
|
|
8
8
|
import { componentLibrariesApi } from "./component-libraries.js";
|
|
9
9
|
import { conversationsAdminApi } from "./conversations.js";
|
|
10
|
-
import { costMetricsApi, instanceCostMetricsApi } from "./cost-metrics.js";
|
|
11
10
|
import { apiKeysApi, pluginsApi, sharedProvidersApi, tenantsApi } from "./global.js";
|
|
12
11
|
import { knowledgeBasesApi } from "./knowledge-bases.js";
|
|
13
12
|
import { mcpsApi } from "./mcps.js";
|
|
13
|
+
import { instanceMetricsApi, metricsApi } from "./metrics.js";
|
|
14
14
|
import { skillsApi } from "./skills.js";
|
|
15
15
|
import { backgroundTasksApi, scheduledRunsApi, taskTemplatesApi } from "./task-templates.js";
|
|
16
16
|
import { userRolesApi, usersApi, userTokensApi } from "./users.js";
|
|
@@ -46,7 +46,7 @@ export interface TenantScope {
|
|
|
46
46
|
backgroundTasks: ReturnType<typeof backgroundTasksApi>;
|
|
47
47
|
conversations: ReturnType<typeof conversationsAdminApi>;
|
|
48
48
|
clientTools: ReturnType<typeof clientToolsApi>;
|
|
49
|
-
|
|
49
|
+
metrics: ReturnType<typeof metricsApi>;
|
|
50
50
|
}
|
|
51
51
|
export interface AdminClient {
|
|
52
52
|
health(signal?: AbortSignal): Promise<Schemas["Health"]>;
|
|
@@ -55,7 +55,7 @@ export interface AdminClient {
|
|
|
55
55
|
apiKeys: ReturnType<typeof apiKeysApi>;
|
|
56
56
|
sharedProviders: ReturnType<typeof sharedProvidersApi>;
|
|
57
57
|
plugins: ReturnType<typeof pluginsApi>;
|
|
58
|
-
|
|
58
|
+
metrics: ReturnType<typeof instanceMetricsApi>;
|
|
59
59
|
tenant(slug: string): TenantScope;
|
|
60
60
|
/** Escape hatch for a route the SDK hasn't wrapped yet. Paths are absolute
|
|
61
61
|
* (`/api/v1/…`) and auth is applied for you. */
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { Transport } from "../http.js";
|
|
2
|
+
import type { Schemas } from "../schemas.js";
|
|
3
|
+
export type MetricId = Schemas["Metric"];
|
|
4
|
+
export type Dimension = Schemas["Dimension"];
|
|
5
|
+
export type Granularity = Schemas["Granularity"];
|
|
6
|
+
export type MetricsInclude = Schemas["Include"];
|
|
7
|
+
export type MetricsCatalog = Schemas["MetricsCatalog"];
|
|
8
|
+
export type MetricInfo = Schemas["MetricInfo"];
|
|
9
|
+
export type MetricsCompleteness = Schemas["Completeness"];
|
|
10
|
+
/** A metric as asked for: its id, or `{ id }`. The object form is where a
|
|
11
|
+
* parameterised metric (a quantile, say) will take its parameters. */
|
|
12
|
+
export type MetricSpec = MetricId | {
|
|
13
|
+
readonly id: MetricId;
|
|
14
|
+
};
|
|
15
|
+
/** The id a spec names. */
|
|
16
|
+
export type MetricIdOf<S> = S extends MetricId ? S : S extends {
|
|
17
|
+
readonly id: infer I extends MetricId;
|
|
18
|
+
} ? I : never;
|
|
19
|
+
/** The values a dimension is restricted to. `none` also keeps the rows where
|
|
20
|
+
* the dimension has no value. A filter listing nothing is refused by the
|
|
21
|
+
* server — leave the dimension out to keep every value. */
|
|
22
|
+
export interface MetricsFilter {
|
|
23
|
+
readonly in?: readonly string[];
|
|
24
|
+
readonly none?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type MetricsFilters<Dim extends Dimension = Dimension> = {
|
|
27
|
+
readonly [D in Dim]?: MetricsFilter;
|
|
28
|
+
};
|
|
29
|
+
export type MetricsOrderBy<M extends MetricId, D extends Dimension> = {
|
|
30
|
+
readonly metric: M;
|
|
31
|
+
readonly direction?: "asc" | "desc";
|
|
32
|
+
} | {
|
|
33
|
+
readonly dimension: D;
|
|
34
|
+
readonly direction?: "asc" | "desc";
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A metrics query. Every type parameter is inferred from the literal you
|
|
38
|
+
* pass, which is what types the result: the metrics you ask for are the keys
|
|
39
|
+
* of each row's `values`, the dimensions you group by are the keys of its
|
|
40
|
+
* `dimensions`, a granularity adds `bucket` (and `buckets`), and `include`
|
|
41
|
+
* adds `totals` and `labels`.
|
|
42
|
+
*/
|
|
43
|
+
export interface MetricsQuery<S extends readonly MetricSpec[] = readonly MetricSpec[], D extends readonly Dimension[] = readonly Dimension[], G extends Granularity | null = Granularity | null, I extends readonly MetricsInclude[] = readonly MetricsInclude[], Dim extends Dimension = Dimension> {
|
|
44
|
+
readonly metrics: S;
|
|
45
|
+
/** Inclusive; rounded down to the hour. Default: 30 days before `to`. */
|
|
46
|
+
readonly from?: Date | string;
|
|
47
|
+
/** Exclusive; rounded up to the hour. Default: the end of the current hour. */
|
|
48
|
+
readonly to?: Date | string;
|
|
49
|
+
/** IANA zone buckets are cut in. Default `UTC`. */
|
|
50
|
+
readonly timezone?: string;
|
|
51
|
+
/** Omit (or `null`) for one row per group over the whole interval — and,
|
|
52
|
+
* with no `groupBy` either, exactly one row. */
|
|
53
|
+
readonly granularity?: G;
|
|
54
|
+
readonly groupBy?: D;
|
|
55
|
+
readonly filters?: MetricsFilters<Dim>;
|
|
56
|
+
/** Within a bucket; rows always go bucket by bucket. Default: the first
|
|
57
|
+
* metric, descending. */
|
|
58
|
+
readonly orderBy?: readonly MetricsOrderBy<MetricIdOf<S[number]>, D[number]>[];
|
|
59
|
+
/** 1 to 10 000. Default 1 000. */
|
|
60
|
+
readonly limit?: number;
|
|
61
|
+
readonly cursor?: string | null;
|
|
62
|
+
readonly include?: I;
|
|
63
|
+
}
|
|
64
|
+
type Values<M extends MetricId> = {
|
|
65
|
+
readonly [K in M]: number;
|
|
66
|
+
};
|
|
67
|
+
type Dims<D extends Dimension> = {
|
|
68
|
+
readonly [K in D]: string | null;
|
|
69
|
+
};
|
|
70
|
+
/** `yes` when the literal certainly holds `K`, `no` when it certainly does
|
|
71
|
+
* not, `maybe` when the type is too wide to tell (an `Include[]` variable). */
|
|
72
|
+
type Has<I extends readonly unknown[], K> = number extends I["length"] ? "maybe" : K extends I[number] ? "yes" : "no";
|
|
73
|
+
type BucketField<G> = [G] extends [null] ? unknown : [G] extends [Granularity] ? {
|
|
74
|
+
readonly bucket: string;
|
|
75
|
+
} : {
|
|
76
|
+
readonly bucket?: string;
|
|
77
|
+
};
|
|
78
|
+
export type MetricsRow<M extends MetricId = MetricId, D extends Dimension = Dimension, G extends Granularity | null = Granularity | null> = BucketField<G> & {
|
|
79
|
+
/** Every grouped dimension; `null` for the rows where it has no value. */
|
|
80
|
+
readonly dimensions: Dims<D>;
|
|
81
|
+
readonly values: Values<M>;
|
|
82
|
+
};
|
|
83
|
+
/** With neither `groupBy` nor `granularity`, the server answers exactly one
|
|
84
|
+
* row — so its type is a one-tuple and `rows[0]` needs no check. */
|
|
85
|
+
type Rows<M extends MetricId, D extends readonly Dimension[], G> = D extends readonly [] ? [G] extends [null] ? readonly [MetricsRow<M, never, null>] : readonly MetricsRow<M, never, G & (Granularity | null)>[] : readonly MetricsRow<M, D[number], G & (Granularity | null)>[];
|
|
86
|
+
/** A name for an id; which fields are set depends on the dimension. */
|
|
87
|
+
export interface EntityLabel {
|
|
88
|
+
readonly slug?: string;
|
|
89
|
+
readonly display_name?: string | null;
|
|
90
|
+
/** A user's first channel identity (a phone, a handle). */
|
|
91
|
+
readonly primary_identifier?: string | null;
|
|
92
|
+
/** A provider's type (`openai`, `anthropic`, …). */
|
|
93
|
+
readonly provider_type?: string;
|
|
94
|
+
}
|
|
95
|
+
type LabeledDimension = "tenant" | "user" | "agent" | "provider";
|
|
96
|
+
type Labels<D extends Dimension> = {
|
|
97
|
+
readonly [K in Extract<D, LabeledDimension>]?: Readonly<Record<string, EntityLabel>>;
|
|
98
|
+
};
|
|
99
|
+
type Optional<Present extends "yes" | "no" | "maybe", T> = Present extends "yes" ? T : Present extends "no" ? unknown : Partial<T>;
|
|
100
|
+
export type MetricsResult<S extends readonly MetricSpec[] = readonly MetricSpec[], D extends readonly Dimension[] = readonly Dimension[], G extends Granularity | null = Granularity | null, I extends readonly MetricsInclude[] = readonly MetricsInclude[]> = {
|
|
101
|
+
/** The query as answered: defaults filled in, the interval rounded to whole
|
|
102
|
+
* hours. */
|
|
103
|
+
readonly query: Schemas["ResolvedQuery"];
|
|
104
|
+
readonly columns: readonly Schemas["Column"][];
|
|
105
|
+
readonly rows: Rows<MetricIdOf<S[number]>, D, G>;
|
|
106
|
+
/** Pass back as `cursor`, with the same query, for the next page. */
|
|
107
|
+
readonly next_cursor: string | null;
|
|
108
|
+
readonly completeness: MetricsCompleteness;
|
|
109
|
+
} & ([G] extends [null] ? unknown : [G] extends [Granularity] ? {
|
|
110
|
+
readonly buckets: readonly string[];
|
|
111
|
+
} : {
|
|
112
|
+
readonly buckets?: readonly string[];
|
|
113
|
+
}) & Optional<Has<I, "totals">, {
|
|
114
|
+
readonly totals: {
|
|
115
|
+
readonly values: Values<MetricIdOf<S[number]>>;
|
|
116
|
+
};
|
|
117
|
+
}> & Optional<Has<I, "labels">, {
|
|
118
|
+
readonly labels: Labels<D[number]>;
|
|
119
|
+
}>;
|
|
120
|
+
export interface DimensionValuesQuery<Dim extends Dimension = Dimension> {
|
|
121
|
+
/** Ranks the values, and is what `metric_value` holds. */
|
|
122
|
+
readonly metric: MetricId;
|
|
123
|
+
readonly from?: Date | string;
|
|
124
|
+
readonly to?: Date | string;
|
|
125
|
+
readonly timezone?: string;
|
|
126
|
+
/** The page's other filters; this dimension's own is ignored. */
|
|
127
|
+
readonly filters?: MetricsFilters<Dim>;
|
|
128
|
+
/** Keep values whose id or name contains this, case-insensitively. */
|
|
129
|
+
readonly search?: string;
|
|
130
|
+
readonly limit?: number;
|
|
131
|
+
readonly cursor?: string | null;
|
|
132
|
+
}
|
|
133
|
+
export interface DimensionValues {
|
|
134
|
+
readonly values: readonly {
|
|
135
|
+
/** `null` is the rows with no value — filter on it with `none`. */
|
|
136
|
+
readonly value: string | null;
|
|
137
|
+
readonly label?: EntityLabel;
|
|
138
|
+
readonly metric_value: number;
|
|
139
|
+
}[];
|
|
140
|
+
readonly next_cursor: string | null;
|
|
141
|
+
}
|
|
142
|
+
/** The whole instance's metrics. Root only. */
|
|
143
|
+
export declare function instanceMetricsApi(t: Transport): {
|
|
144
|
+
/** The metrics this credential may read here: unit, aggregation,
|
|
145
|
+
* dimensions, finest granularity, completeness. */
|
|
146
|
+
catalog: (signal?: AbortSignal) => Promise<{
|
|
147
|
+
dimensions: import("../generated/schema.js").components["schemas"]["DimensionInfo"][];
|
|
148
|
+
metrics: import("../generated/schema.js").components["schemas"]["MetricInfo"][];
|
|
149
|
+
}>;
|
|
150
|
+
query: <const S extends readonly MetricSpec[], const D extends readonly ("agent" | "kind" | "model" | "provider" | "tenant" | "user")[] = [], G extends Granularity | null = null, const I extends readonly MetricsInclude[] = []>(q: MetricsQuery<S, D, G, I, "agent" | "kind" | "model" | "provider" | "tenant" | "user">, signal?: AbortSignal) => Promise<MetricsResult<S, D, G, I>>;
|
|
151
|
+
/** Every row of the query, following the cursor page by page. */
|
|
152
|
+
queryAll<const S extends readonly MetricSpec[], const D extends readonly ("agent" | "kind" | "model" | "provider" | "tenant" | "user")[] = [], G extends Granularity | null = null>(q: Omit<MetricsQuery<S, D, G, [], "agent" | "kind" | "model" | "provider" | "tenant" | "user">, "cursor" | "include">, signal?: AbortSignal): AsyncGenerator<Rows<MetricIdOf<S[number]>, D, G>[number], any, any>;
|
|
153
|
+
/** The values `dimension` takes in a slice, ranked by a metric — what a
|
|
154
|
+
* filter can offer given the page's other filters. */
|
|
155
|
+
dimensionValues: (dimension: "agent" | "kind" | "model" | "provider" | "tenant" | "user", q: DimensionValuesQuery<"agent" | "kind" | "model" | "provider" | "tenant" | "user">, signal?: AbortSignal) => Promise<DimensionValues>;
|
|
156
|
+
};
|
|
157
|
+
/** One tenant's metrics; there is no `tenant` dimension in this scope. */
|
|
158
|
+
export declare function metricsApi(t: Transport, tenantSlug: string): {
|
|
159
|
+
/** The metrics this credential may read here: unit, aggregation,
|
|
160
|
+
* dimensions, finest granularity, completeness. */
|
|
161
|
+
catalog: (signal?: AbortSignal) => Promise<{
|
|
162
|
+
dimensions: import("../generated/schema.js").components["schemas"]["DimensionInfo"][];
|
|
163
|
+
metrics: import("../generated/schema.js").components["schemas"]["MetricInfo"][];
|
|
164
|
+
}>;
|
|
165
|
+
query: <const S extends readonly MetricSpec[], const D extends readonly ("agent" | "kind" | "model" | "provider" | "user")[] = [], G extends Granularity | null = null, const I extends readonly MetricsInclude[] = []>(q: MetricsQuery<S, D, G, I, "agent" | "kind" | "model" | "provider" | "user">, signal?: AbortSignal) => Promise<MetricsResult<S, D, G, I>>;
|
|
166
|
+
/** Every row of the query, following the cursor page by page. */
|
|
167
|
+
queryAll<const S extends readonly MetricSpec[], const D extends readonly ("agent" | "kind" | "model" | "provider" | "user")[] = [], G extends Granularity | null = null>(q: Omit<MetricsQuery<S, D, G, [], "agent" | "kind" | "model" | "provider" | "user">, "cursor" | "include">, signal?: AbortSignal): AsyncGenerator<Rows<MetricIdOf<S[number]>, D, G>[number], any, any>;
|
|
168
|
+
/** The values `dimension` takes in a slice, ranked by a metric — what a
|
|
169
|
+
* filter can offer given the page's other filters. */
|
|
170
|
+
dimensionValues: (dimension: "agent" | "kind" | "model" | "provider" | "user", q: DimensionValuesQuery<"agent" | "kind" | "model" | "provider" | "user">, signal?: AbortSignal) => Promise<DimensionValues>;
|
|
171
|
+
};
|
|
172
|
+
export {};
|