@elaraai/e3-ui 1.0.11 → 1.0.12

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,148 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * `Experiment` component — an interactive causal-experiment surface.
7
+ *
8
+ * @remarks
9
+ * `Experiment` lets a domain expert ask *"did X change Y?"* against a dataset
10
+ * and trust the answer, without meeting a statistician's vocabulary. It is a
11
+ * registered extension component (architecturally like {@link Ontology}): the
12
+ * author writes one tag, `Experiment.Root({ … })`; the React renderer lives in
13
+ * `@elaraai/e3-ui-components` and is wired via
14
+ * `implementUIComponent(Experiment.Component, EastChakraExperiment)`.
15
+ *
16
+ * **Generic over the input row, like `Table`.** The author binds the input
17
+ * dataset (`data: BoundValue<ArrayType<Row>>`); the renderer introspects its
18
+ * row struct to drive the treatment / outcome / confounder pickers, so the
19
+ * **end user** re-frames the experiment from the dataset's own columns.
20
+ *
21
+ * **The user adjusts → results go stale → Run re-computes.** Editing a picker
22
+ * stages a new {@link ExperimentSpecType} and marks the result stale; **Run**
23
+ * calls the author-supplied estimator functions ({@link Func.bind} handles) and
24
+ * the answer arrives reactively; **Commit** appends to the journal. The causal
25
+ * compute (DoWhy / EconML) lives entirely in those function bodies, so `e3-ui`
26
+ * never imports `east-py-datascience`.
27
+ *
28
+ * **Visual-first and derived.** Because the user frames an arbitrary
29
+ * experiment, nothing on the result side is hand-authored — every word is a
30
+ * column name the user picked, a number an estimator returned, or a status
31
+ * derived by rule (interval clears zero → HIGHER / LOWER; spans zero → NO CLEAR
32
+ * EFFECT; raw and adjusted disagree in sign → the "misleading" banner). The
33
+ * contract types ({@link ExperimentSpecType}, {@link ExperimentResultType}, …)
34
+ * live in {@link "./experiment/types"} and are reached via `Experiment.Types.*`.
35
+ *
36
+ * @packageDocumentation
37
+ */
38
+ import { East, NullType, BooleanType, StringType, ArrayType, StructType, VariantType, OptionType, none, some, variant, } from '@elaraai/east';
39
+ import { EastUI } from '@elaraai/east-ui';
40
+ import { DiffBindingType } from '../data.js';
41
+ import { FuncBindingType } from '../func.js';
42
+ import { ExperimentSpecType, ExperimentResultType, RefuteResultType, DoseResultType, JournalType, ColumnMetaType, } from './types.js';
43
+ // Re-export the contract types so consumers can reach them from the component
44
+ // module too (the canonical home is `./types`).
45
+ export { WeightingSchemeType, EstimatorType, TargetUnitsType, TrimType, ExperimentSpecType, CiType, BalanceRowType, ExperimentResultType, RefuteKindType, RefuteCheckType, RefuteResultType, DoseSegmentType, DoseResultType, JournalRowType, JournalType, ColumnMetaType, } from './types.js';
46
+ // ============================================================================
47
+ // Component payload — descriptors only (binding handles + options).
48
+ // ============================================================================
49
+ /** Initial result tab variant — `answer` (default), `trust`, or `dose`. */
50
+ export const ExperimentTabType = VariantType({ answer: NullType, trust: NullType, dose: NullType });
51
+ /**
52
+ * The `Experiment` component payload — binding descriptors + options. Renderers
53
+ * decode this and resolve each binding to a live, reactive value / call handle.
54
+ *
55
+ * @property data - {@link DiffBindingType} for the input dataset — the renderer
56
+ * introspects its row struct for the pickers and passes it to the functions.
57
+ * @property spec - {@link DiffBindingType} for the staged {@link ExperimentSpecType}.
58
+ * @property estimate - {@link FuncBindingType} for the `estimate` function.
59
+ * @property refute - Optional {@link FuncBindingType} for the `refute` function.
60
+ * @property dose - Optional {@link FuncBindingType} for the `dose` function.
61
+ * @property journal - Optional {@link DiffBindingType} for the committed-experiment journal.
62
+ * @property columnMeta - Optional per-column display metadata.
63
+ * @property readonly - Render without the Run / Commit / edit affordances.
64
+ * @property defaultTab - Initial result tab ({@link ExperimentTabType}).
65
+ */
66
+ export const ExperimentPayloadType = StructType({
67
+ data: DiffBindingType,
68
+ spec: DiffBindingType,
69
+ estimate: FuncBindingType,
70
+ refute: OptionType(FuncBindingType),
71
+ dose: OptionType(FuncBindingType),
72
+ journal: OptionType(DiffBindingType),
73
+ columnMeta: OptionType(ColumnMetaType),
74
+ readonly: OptionType(BooleanType),
75
+ defaultTab: OptionType(ExperimentTabType),
76
+ });
77
+ /**
78
+ * Internal {@link EastUI.component} carrier. The React renderer registers
79
+ * against this in `@elaraai/e3-ui-components`.
80
+ */
81
+ export const ExperimentComponent = EastUI.component('Experiment', ExperimentPayloadType, { optional: true });
82
+ /**
83
+ * Build an Experiment surface bound to an input dataset + estimator functions.
84
+ *
85
+ * @typeParam Row - The input dataset's row struct, inferred from `data`.
86
+ * @param options - {@link ExperimentOptions}. `data`, `spec` and `estimate` are
87
+ * required; the rest are optional.
88
+ * @returns An East expression of {@link UIComponentType}.
89
+ */
90
+ function createExperiment(options) {
91
+ const defaultTab = options.defaultTab === undefined
92
+ ? none
93
+ : some(East.value(variant(options.defaultTab, null), ExperimentTabType));
94
+ const columnMeta = options.columns === undefined
95
+ ? none
96
+ : some(East.value(new Map(Object.entries(options.columns).map(([k, c]) => [k, {
97
+ label: c?.label !== undefined ? some(c.label) : none,
98
+ unit: c?.unit !== undefined ? some(c.unit) : none,
99
+ higherIsBetter: c?.higherIsBetter !== undefined ? some(c.higherIsBetter) : none,
100
+ }])), ColumnMetaType));
101
+ return ExperimentComponent.Root({
102
+ data: options.data.binding,
103
+ spec: options.spec.binding,
104
+ estimate: options.estimate.binding,
105
+ refute: options.refute !== undefined ? some(options.refute.binding) : none,
106
+ dose: options.dose !== undefined ? some(options.dose.binding) : none,
107
+ journal: options.journal !== undefined ? some(options.journal.binding) : none,
108
+ columnMeta,
109
+ readonly: options.readonly ?? none,
110
+ defaultTab,
111
+ });
112
+ }
113
+ /**
114
+ * The Experiment component namespace. Surfaces an interactive causal-experiment
115
+ * over a bound input dataset + estimator functions, generic over the row struct
116
+ * (the `Table` pattern), with the staged-binding machinery the rest of e3-ui
117
+ * uses.
118
+ *
119
+ * @remarks
120
+ * Use `Experiment.Root({ data, spec, estimate, refute, dose, journal })` inside
121
+ * a `Reactive` block. The `Component` property is the {@link EastUI.component}
122
+ * carrier the renderer registers against; `Types` exposes the render-contract
123
+ * value types (`Spec`, `Result`, `Refute`, `Dose`, `Journal`, …).
124
+ */
125
+ export const Experiment = {
126
+ Root: createExperiment,
127
+ /** The internal {@link EastUI.component} carrier renderers register against. */
128
+ Component: ExperimentComponent,
129
+ Types: {
130
+ /** Rendered payload struct (bindings + options). */
131
+ Payload: ExperimentPayloadType,
132
+ /** The experiment-spec value type (what the pickers stage). */
133
+ Spec: ExperimentSpecType,
134
+ /** The estimator answer value type. */
135
+ Result: ExperimentResultType,
136
+ /** The robustness-battery value type. */
137
+ Refute: RefuteResultType,
138
+ /** The dose-response value type. */
139
+ Dose: DoseResultType,
140
+ /** The committed-experiment journal value type. */
141
+ Journal: JournalType,
142
+ /** Optional per-column display metadata. */
143
+ ColumnMeta: ColumnMetaType,
144
+ /** Initial result tab variant. */
145
+ Tab: ExperimentTabType,
146
+ },
147
+ };
148
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experiment/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,OAAO,GAGV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAwB,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAkB,MAAM,YAAY,CAAC;AAC7D,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,GACjB,MAAM,YAAY,CAAC;AAEpB,8EAA8E;AAC9E,gDAAgD;AAChD,OAAO,EACH,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