@runflow-ai/sdk 1.1.10 → 1.1.11

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './utils';
3
+ export * from './constants';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // Shared types, utils, and constants for Runflow platform
3
+ // Export everything from subdirectories
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("./utils"), exports);
21
+ __exportStar(require("./constants"), exports);
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Dashboard Cards — single source of truth for card types, configs, tabs and
3
+ * grid layout. Used by:
4
+ * - Portal UI (apps/portal)
5
+ * - API DTOs (apps/api-portal)
6
+ * - CLI metrics.json schema (packages/cli)
7
+ * - SDK `runflow.metrics.defineCard()` (packages/sdk)
8
+ * - MCP tools (apps/api-portal/src/modules/mcp/tools)
9
+ *
10
+ * Any change here must be coordinated across all five surfaces.
11
+ */
12
+ export declare const ALL_CARD_TYPES: readonly ["number", "rate", "line", "bar", "pie", "table", "funnel", "gauge"];
13
+ export type CardType = (typeof ALL_CARD_TYPES)[number];
14
+ /** Legacy DTO allowlist — kept for one minor version with deprecation header. */
15
+ export declare const LEGACY_V1_CARD_TYPES: readonly ["number", "rate", "line", "bar", "pie"];
16
+ export type Aggregation = "count" | "rate" | "sum" | "avg" | "distinct_count" | "group_by";
17
+ export type DateGrouping = "hour" | "day" | "week" | "month";
18
+ export type CardFormat = "number" | "percentage" | "currency" | "duration";
19
+ export type FilterOperator = "eq" | "neq" | "gt" | "lt" | "gte" | "lte" | "contains" | "in";
20
+ export interface BaseCardConfig {
21
+ /** Event from observability stream. Required for KPI/chart cards. */
22
+ eventName?: string;
23
+ aggregation?: Aggregation;
24
+ propertyKey?: string;
25
+ propertyValue?: string;
26
+ /** For line/bar charts. */
27
+ dateGrouping?: DateGrouping;
28
+ format?: CardFormat;
29
+ color?: string;
30
+ /** Free-form icon slug (UI-defined). */
31
+ icon?: string;
32
+ }
33
+ export type TableColumnFormat = "number" | "percentage" | "currency" | "duration" | "text";
34
+ export interface TableColumnConfig {
35
+ key: string;
36
+ label?: string;
37
+ format?: TableColumnFormat;
38
+ width?: number;
39
+ }
40
+ export interface TableMetric {
41
+ /** Aggregation accepts the full union; conditional formatting may narrow it. */
42
+ aggregation: Aggregation;
43
+ propertyKey?: string;
44
+ alias?: string;
45
+ }
46
+ export interface TableFilter {
47
+ /** Key on the property being filtered (e.g. "status", "amount"). */
48
+ key: string;
49
+ operator: FilterOperator;
50
+ /** Allow scalar or array for `in`/multi-value comparisons. */
51
+ value: unknown;
52
+ }
53
+ /** Per-rule conditional formatting (colors/badges on table cells). */
54
+ export interface TableConditionRule {
55
+ operator: Exclude<FilterOperator, "in" | "contains">;
56
+ value: string;
57
+ color: string;
58
+ label?: string;
59
+ }
60
+ export interface TableCondition {
61
+ columnKey: string;
62
+ type: "color" | "badge";
63
+ rules: TableConditionRule[];
64
+ }
65
+ export interface TablePagination {
66
+ limit: number;
67
+ offset: number;
68
+ }
69
+ export interface TableCardConfig extends BaseCardConfig {
70
+ mode: "raw" | "aggregate";
71
+ /**
72
+ * Column descriptors. Old portal versions used `string[]`; both shapes are
73
+ * accepted by the API (the normalizer keeps them as-is).
74
+ */
75
+ columns?: Array<string | TableColumnConfig>;
76
+ groupByKey?: string;
77
+ metrics?: TableMetric[];
78
+ /** Server-side saved filters that ship with the card. */
79
+ filters?: TableFilter[];
80
+ /** UI-side conditional formatting (colors/badges per column rule). */
81
+ conditions?: TableCondition[];
82
+ sortBy?: string;
83
+ sortOrder?: "asc" | "desc";
84
+ pagination?: TablePagination;
85
+ /** Convenience knob from the UI builder. */
86
+ rowsPerPage?: number;
87
+ }
88
+ export interface FunnelStep {
89
+ eventName: string;
90
+ label?: string;
91
+ }
92
+ export interface FunnelStepValue {
93
+ value: string;
94
+ label?: string;
95
+ }
96
+ export interface FunnelCardConfig extends BaseCardConfig {
97
+ funnelMode: "multi_event" | "single_event";
98
+ layout?: "vertical" | "horizontal";
99
+ /** Required when funnelMode === "multi_event". */
100
+ steps?: FunnelStep[];
101
+ /** Required when funnelMode === "single_event" (alongside eventName + propertyKey). */
102
+ stepValues?: FunnelStepValue[];
103
+ }
104
+ export interface GaugeThresholds {
105
+ v1: number;
106
+ v2: number;
107
+ }
108
+ export interface GaugeZoneColors {
109
+ low: string;
110
+ mid: string;
111
+ high: string;
112
+ }
113
+ export interface GaugeCardConfig extends BaseCardConfig {
114
+ min: number;
115
+ max: number;
116
+ target?: number;
117
+ thresholds: GaugeThresholds;
118
+ zoneColors?: GaugeZoneColors;
119
+ unit?: string;
120
+ }
121
+ /**
122
+ * Discriminated union over `cardType` is enforced at the {@link DashboardCard}
123
+ * level. This wider type is convenient for normalization helpers and stores.
124
+ */
125
+ export type DashboardCardConfig = BaseCardConfig | TableCardConfig | FunnelCardConfig | GaugeCardConfig;
126
+ export interface GridLayoutItem {
127
+ x: number;
128
+ y: number;
129
+ w: number;
130
+ h: number;
131
+ }
132
+ /** Constraints applied by the UI's drag-and-drop grid. */
133
+ export declare const GRID_CONSTRAINTS: Record<CardType, {
134
+ minW: number;
135
+ minH: number;
136
+ maxW: number;
137
+ maxH: number;
138
+ }>;
139
+ /**
140
+ * Returns true when the provided grid item satisfies the constraints for the
141
+ * card type. UI uses this same helper at drop-time; API DTOs use it on
142
+ * validation.
143
+ */
144
+ export declare function isValidGridLayout(cardType: CardType, layout: GridLayoutItem): {
145
+ ok: true;
146
+ } | {
147
+ ok: false;
148
+ reason: string;
149
+ };
150
+ export interface DashboardCard {
151
+ id: string;
152
+ tenantId: string;
153
+ agentId: string;
154
+ tabId?: string | null;
155
+ title: string;
156
+ cardType: CardType;
157
+ config: DashboardCardConfig;
158
+ gridLayout?: GridLayoutItem;
159
+ sortOrder?: number;
160
+ createdAt?: string;
161
+ updatedAt?: string;
162
+ }
163
+ export interface DashboardTab {
164
+ id: string;
165
+ tenantId: string;
166
+ agentId: string;
167
+ name: string;
168
+ sortOrder: number;
169
+ createdAt?: string;
170
+ updatedAt?: string;
171
+ }
172
+ export interface ReorderCardEntry {
173
+ id: string;
174
+ sortOrder: number;
175
+ gridLayout?: GridLayoutItem;
176
+ tabId?: string | null;
177
+ }
178
+ export interface ReorderCardsInput {
179
+ cards: ReorderCardEntry[];
180
+ }
181
+ export interface ReorderTabEntry {
182
+ id: string;
183
+ sortOrder: number;
184
+ }
185
+ export interface ReorderTabsInput {
186
+ tabs: ReorderTabEntry[];
187
+ }
188
+ export interface CreateDashboardCardInput {
189
+ agentId: string;
190
+ title: string;
191
+ cardType: CardType;
192
+ config: DashboardCardConfig;
193
+ tabId?: string | null;
194
+ gridLayout?: GridLayoutItem;
195
+ sortOrder?: number;
196
+ /** Caller-supplied idempotency key. When absent, server derives one. */
197
+ idempotencyKey?: string;
198
+ }
199
+ export interface UpdateDashboardCardInput {
200
+ title?: string;
201
+ config?: DashboardCardConfig;
202
+ tabId?: string | null;
203
+ gridLayout?: GridLayoutItem;
204
+ sortOrder?: number;
205
+ }
206
+ export interface CreateDashboardTabInput {
207
+ agentId: string;
208
+ name: string;
209
+ sortOrder?: number;
210
+ }
211
+ export interface UpdateDashboardTabInput {
212
+ name?: string;
213
+ sortOrder?: number;
214
+ }
215
+ export interface DefineCardInput<T extends CardType = CardType> {
216
+ title: string;
217
+ cardType: T;
218
+ config: T extends "table" ? TableCardConfig : T extends "funnel" ? FunnelCardConfig : T extends "gauge" ? GaugeCardConfig : BaseCardConfig;
219
+ tab?: string;
220
+ gridLayout?: GridLayoutItem;
221
+ sortOrder?: number;
222
+ }
223
+ export interface DefineTabInput {
224
+ name: string;
225
+ sortOrder?: number;
226
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Dashboard Cards — single source of truth for card types, configs, tabs and
4
+ * grid layout. Used by:
5
+ * - Portal UI (apps/portal)
6
+ * - API DTOs (apps/api-portal)
7
+ * - CLI metrics.json schema (packages/cli)
8
+ * - SDK `runflow.metrics.defineCard()` (packages/sdk)
9
+ * - MCP tools (apps/api-portal/src/modules/mcp/tools)
10
+ *
11
+ * Any change here must be coordinated across all five surfaces.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.GRID_CONSTRAINTS = exports.LEGACY_V1_CARD_TYPES = exports.ALL_CARD_TYPES = void 0;
15
+ exports.isValidGridLayout = isValidGridLayout;
16
+ // -----------------------------------------------------------------------------
17
+ // Card type taxonomy
18
+ // -----------------------------------------------------------------------------
19
+ exports.ALL_CARD_TYPES = [
20
+ "number",
21
+ "rate",
22
+ "line",
23
+ "bar",
24
+ "pie",
25
+ "table",
26
+ "funnel",
27
+ "gauge",
28
+ ];
29
+ /** Legacy DTO allowlist — kept for one minor version with deprecation header. */
30
+ exports.LEGACY_V1_CARD_TYPES = ["number", "rate", "line", "bar", "pie"];
31
+ /** Constraints applied by the UI's drag-and-drop grid. */
32
+ exports.GRID_CONSTRAINTS = {
33
+ number: { minW: 2, minH: 2, maxW: 6, maxH: 4 },
34
+ rate: { minW: 2, minH: 2, maxW: 6, maxH: 4 },
35
+ gauge: { minW: 2, minH: 3, maxW: 6, maxH: 6 },
36
+ line: { minW: 4, minH: 3, maxW: 12, maxH: 8 },
37
+ bar: { minW: 4, minH: 3, maxW: 12, maxH: 8 },
38
+ pie: { minW: 3, minH: 3, maxW: 8, maxH: 8 },
39
+ table: { minW: 4, minH: 3, maxW: 12, maxH: 12 },
40
+ funnel: { minW: 4, minH: 4, maxW: 12, maxH: 12 },
41
+ };
42
+ /**
43
+ * Returns true when the provided grid item satisfies the constraints for the
44
+ * card type. UI uses this same helper at drop-time; API DTOs use it on
45
+ * validation.
46
+ */
47
+ function isValidGridLayout(cardType, layout) {
48
+ const c = exports.GRID_CONSTRAINTS[cardType];
49
+ if (!c)
50
+ return { ok: false, reason: `unknown cardType: ${cardType}` };
51
+ if (layout.x < 0 || layout.y < 0)
52
+ return { ok: false, reason: "x/y must be >= 0" };
53
+ if (layout.w < c.minW)
54
+ return { ok: false, reason: `w must be >= ${c.minW} for ${cardType}` };
55
+ if (layout.h < c.minH)
56
+ return { ok: false, reason: `h must be >= ${c.minH} for ${cardType}` };
57
+ if (layout.w > c.maxW)
58
+ return { ok: false, reason: `w must be <= ${c.maxW} for ${cardType}` };
59
+ if (layout.h > c.maxH)
60
+ return { ok: false, reason: `h must be <= ${c.maxH} for ${cardType}` };
61
+ return { ok: true };
62
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Tolerant normalizer for `DashboardCard.config`.
3
+ *
4
+ * Maps known legacy aliases used by older portal/CLI/SDK versions into the
5
+ * canonical shape defined in `dashboard-cards.ts`. The helper is intentionally
6
+ * permissive: unknown keys are preserved, missing required keys are NOT
7
+ * filled in (validation is the caller's responsibility — see
8
+ * `dashboard-cards.zod.ts`).
9
+ *
10
+ * Used by:
11
+ * - apps/api-portal/src/modules/observability/events.service.ts
12
+ * (upsertDashboardCard, queryEvents, funnelQuery)
13
+ * - apps/api-portal/scripts/normalize-dashboard-cards.ts (one-off backfill)
14
+ * - packages/cli (pre-sync sanitation)
15
+ * - packages/sdk (defineCard runtime check, soft mode)
16
+ *
17
+ * Every transformation increments a counter so callers can emit telemetry
18
+ * (`legacy_card_alias_used`) and eventually flip `STRICT_DASHBOARD_VALIDATION`.
19
+ */
20
+ import type { CardType, DashboardCardConfig } from "./dashboard-cards";
21
+ export type LegacyAlias = "table.tableMode->mode" | "funnel.funnelSteps->steps" | "funnel.stepEvents->steps" | "funnel.missingFunnelMode->multi_event" | "gauge.thresholdsArray->object" | "gauge.zoneColorsArray->object" | "gauge.colorsArray->zoneColors" | "gauge.range->minMax" | "card.gridPosition->gridLayout" | "card.layout->gridLayout";
22
+ export interface NormalizeResult {
23
+ config: DashboardCardConfig;
24
+ aliasesApplied: LegacyAlias[];
25
+ }
26
+ /**
27
+ * Normalize a card config to the canonical shape. Pure function, never throws.
28
+ *
29
+ * @param cardType Discriminator that decides which shape to coerce into.
30
+ * @param raw Anything that came off the wire / out of the DB.
31
+ */
32
+ export declare function normalizeCardConfig(cardType: CardType, raw: unknown): NormalizeResult;
33
+ export declare function normalizeGridLayout(raw: unknown): {
34
+ x: number;
35
+ y: number;
36
+ w: number;
37
+ h: number;
38
+ } | undefined;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ /**
3
+ * Tolerant normalizer for `DashboardCard.config`.
4
+ *
5
+ * Maps known legacy aliases used by older portal/CLI/SDK versions into the
6
+ * canonical shape defined in `dashboard-cards.ts`. The helper is intentionally
7
+ * permissive: unknown keys are preserved, missing required keys are NOT
8
+ * filled in (validation is the caller's responsibility — see
9
+ * `dashboard-cards.zod.ts`).
10
+ *
11
+ * Used by:
12
+ * - apps/api-portal/src/modules/observability/events.service.ts
13
+ * (upsertDashboardCard, queryEvents, funnelQuery)
14
+ * - apps/api-portal/scripts/normalize-dashboard-cards.ts (one-off backfill)
15
+ * - packages/cli (pre-sync sanitation)
16
+ * - packages/sdk (defineCard runtime check, soft mode)
17
+ *
18
+ * Every transformation increments a counter so callers can emit telemetry
19
+ * (`legacy_card_alias_used`) and eventually flip `STRICT_DASHBOARD_VALIDATION`.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.normalizeCardConfig = normalizeCardConfig;
23
+ exports.normalizeGridLayout = normalizeGridLayout;
24
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
25
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : undefined;
26
+ const str = (v) => typeof v === "string" && v.length > 0 ? v : undefined;
27
+ /**
28
+ * Normalize a card config to the canonical shape. Pure function, never throws.
29
+ *
30
+ * @param cardType Discriminator that decides which shape to coerce into.
31
+ * @param raw Anything that came off the wire / out of the DB.
32
+ */
33
+ function normalizeCardConfig(cardType, raw) {
34
+ const aliasesApplied = [];
35
+ const src = isObject(raw) ? { ...raw } : {};
36
+ switch (cardType) {
37
+ case "table":
38
+ return normalizeTable(src, aliasesApplied);
39
+ case "funnel":
40
+ return normalizeFunnel(src, aliasesApplied);
41
+ case "gauge":
42
+ return normalizeGauge(src, aliasesApplied);
43
+ default:
44
+ // KPI / chart cards — pass through with a few generic cleanups.
45
+ return { config: src, aliasesApplied };
46
+ }
47
+ }
48
+ // -----------------------------------------------------------------------------
49
+ // Per-type normalizers
50
+ // -----------------------------------------------------------------------------
51
+ function normalizeTable(src, applied) {
52
+ if (src.mode === undefined && typeof src.tableMode === "string") {
53
+ src.mode = src.tableMode;
54
+ delete src.tableMode;
55
+ applied.push("table.tableMode->mode");
56
+ }
57
+ // Permissive cast — required fields (mode) may still be missing; validation
58
+ // is the caller's responsibility via the zod schema.
59
+ return {
60
+ config: src,
61
+ aliasesApplied: applied,
62
+ };
63
+ }
64
+ function normalizeFunnel(src, applied) {
65
+ if (src.steps === undefined) {
66
+ if (Array.isArray(src.funnelSteps)) {
67
+ src.steps = src.funnelSteps;
68
+ delete src.funnelSteps;
69
+ applied.push("funnel.funnelSteps->steps");
70
+ }
71
+ else if (Array.isArray(src.stepEvents)) {
72
+ src.steps = src.stepEvents;
73
+ delete src.stepEvents;
74
+ applied.push("funnel.stepEvents->steps");
75
+ }
76
+ }
77
+ if (typeof src.funnelMode !== "string") {
78
+ src.funnelMode = "multi_event";
79
+ applied.push("funnel.missingFunnelMode->multi_event");
80
+ }
81
+ return {
82
+ config: src,
83
+ aliasesApplied: applied,
84
+ };
85
+ }
86
+ function normalizeGauge(src, applied) {
87
+ // thresholds: [v1, v2] → { v1, v2 }
88
+ if (Array.isArray(src.thresholds) && src.thresholds.length === 2) {
89
+ const [v1, v2] = src.thresholds;
90
+ if (num(v1) !== undefined && num(v2) !== undefined) {
91
+ src.thresholds = { v1: v1, v2: v2 };
92
+ applied.push("gauge.thresholdsArray->object");
93
+ }
94
+ }
95
+ // zoneColors: [low, mid, high] → { low, mid, high }
96
+ if (Array.isArray(src.zoneColors) && src.zoneColors.length === 3) {
97
+ const [low, mid, high] = src.zoneColors;
98
+ if (str(low) && str(mid) && str(high)) {
99
+ src.zoneColors = {
100
+ low: low,
101
+ mid: mid,
102
+ high: high,
103
+ };
104
+ applied.push("gauge.zoneColorsArray->object");
105
+ }
106
+ }
107
+ // Older builds used `colors: [...]` for zone colors.
108
+ if (src.zoneColors === undefined && Array.isArray(src.colors)) {
109
+ const [low, mid, high] = src.colors;
110
+ if (str(low) && str(mid) && str(high)) {
111
+ src.zoneColors = {
112
+ low: low,
113
+ mid: mid,
114
+ high: high,
115
+ };
116
+ delete src.colors;
117
+ applied.push("gauge.colorsArray->zoneColors");
118
+ }
119
+ }
120
+ // Some legacy rows stored `range: { from, to }` instead of min/max.
121
+ if ((src.min === undefined || src.max === undefined) &&
122
+ isObject(src.range)) {
123
+ const range = src.range;
124
+ if (num(range.from) !== undefined && src.min === undefined) {
125
+ src.min = range.from;
126
+ }
127
+ if (num(range.to) !== undefined && src.max === undefined) {
128
+ src.max = range.to;
129
+ }
130
+ delete src.range;
131
+ applied.push("gauge.range->minMax");
132
+ }
133
+ return {
134
+ config: src,
135
+ aliasesApplied: applied,
136
+ };
137
+ }
138
+ // -----------------------------------------------------------------------------
139
+ // gridLayout normalizer — accepts a few legacy shapes for the card-level field
140
+ // (not the config). Returns undefined if input is unrecognizable.
141
+ // -----------------------------------------------------------------------------
142
+ function normalizeGridLayout(raw) {
143
+ if (!isObject(raw))
144
+ return undefined;
145
+ const x = num(raw.x) ?? num(raw.X);
146
+ const y = num(raw.y) ?? num(raw.Y);
147
+ const w = num(raw.w) ?? num(raw.width);
148
+ const h = num(raw.h) ?? num(raw.height);
149
+ if (x === undefined || y === undefined || w === undefined || h === undefined)
150
+ return undefined;
151
+ return { x, y, w, h };
152
+ }