@oxy-hq/sdk 2.5.0 → 2.8.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @oxy-hq/sdk
2
2
 
3
- React SDK for building **customer-app bundles** on the [Oxy](https://oxygen-hq.com)
3
+ React SDK for building **custom-app bundles** on the [Oxy](https://oxygen-hq.com)
4
4
  platform. A bundle is a normal Vite + React app that reads from its linked oxy
5
5
  project — raw SQL, the semantic layer, agents, and procedures — through a
6
6
  small set of hooks, plus a couple of drop-in components.
@@ -88,11 +88,61 @@ couldn't already read.
88
88
  | `<OxyAnswer … />` | Renders markdown + SQL artifacts + thread link. URL schemes are allowlisted (rejects `javascript:` etc.). |
89
89
  | `OxyApiError` | Structured `{ message, code? }` server-error envelope. |
90
90
 
91
- ### Metric Tree
91
+ ### World Model & analysis hooks
92
92
 
93
- Additional exports for programmatic metric-tree analyses (`AnomaliesClient`,
94
- `MetricTreeClient` and all related types) are available from the package root
95
- — see [metricTree.ts](src/metricTree.ts) and [anomalies.ts](src/anomalies.ts).
93
+ The same airlayer analyses the IDE's **World Model** and **Metric Tree** run,
94
+ exposed as hooks so a bundle can do RCA, opportunity sizing, and driver
95
+ exploration itself. Each fetches when enabled and its input is present; pass
96
+ `null` for a request/id to keep a hook idle until the user makes a selection.
97
+
98
+ | Export | What it does |
99
+ | --- | --- |
100
+ | `useWorldModel()` | The entity/measure graph — entities, their measures, and how measures promote across the hierarchy (edges). |
101
+ | `useWorldModelInstances(entityId, { search?, limit? })` | Searchable listing of an entity's instances (primary key + display label). |
102
+ | `useMetricTree({ root? })` | The metric tree (measures + component/driver edges), or the subtree at `root`. |
103
+ | `useSensitivity(measureId)` | Ranked **drivers** of a measure — "what moves this?" |
104
+ | `usePredict(changes)` | **What-if**: propagate hypothetical `(measure, delta)` changes upward (pure tree walk, no warehouse). |
105
+ | `useExplain(request)` | **RCA**: period-over-period root-cause decomposition. |
106
+ | `useOpportunity(request)` | Segment **opportunity sizing** — addressable upside vs a benchmark peer. |
107
+ | `useDistribution(request)` | Single-period distribution against an auto-derived prior baseline. |
108
+ | `useTimeDimensions()` | Valid time dimensions per view — the period axis for the ops above. |
109
+ | `useMeasureBreakdown(entityId, key, measure)` | Per-instance **driver tree** (SSE) — node values fill in as they resolve. |
110
+
111
+ ```tsx
112
+ import { OxyAppProvider, useExplain, useOpportunity } from "@oxy-hq/sdk";
113
+
114
+ function RootCause() {
115
+ // Pass `null` instead of the request object to defer until the user picks a period.
116
+ const { data, loading, error } = useExplain({
117
+ target: "financials.operating_profit",
118
+ time_dimension: "financials.month",
119
+ current_period: ["2025-09-01", "2025-09-30"],
120
+ previous_period: ["2025-08-01", "2025-08-31"]
121
+ });
122
+ if (loading) return <p>Explaining…</p>;
123
+ if (error) return <p>{error.message}</p>;
124
+ return <p>Δ {data?.target_delta} — {((data?.coverage ?? 0) * 100).toFixed(0)}% explained</p>;
125
+ }
126
+
127
+ function Upside() {
128
+ const { data } = useOpportunity({
129
+ target: "orders.net_revenue",
130
+ time_dimension: "orders.order_date",
131
+ period: ["2025-04-01", "2025-06-30"]
132
+ });
133
+ return <>{data?.dimensions.map((d) => <p key={d.dimension}>{d.dimension}: +{d.total_upside}</p>)}</>;
134
+ }
135
+ ```
136
+
137
+ A fuller worked example (graph + opportunity + RCA + streaming driver tree) is
138
+ in [examples/world-model-analysis.tsx](examples/world-model-analysis.tsx).
139
+
140
+ ### Metric Tree (client-class)
141
+
142
+ For non-React / API-key callers, the programmatic `MetricTreeClient` and
143
+ `AnomaliesClient` (and all related types) are available from the package root
144
+ — see [metricTree.ts](src/metricTree.ts), [anomalies.ts](src/anomalies.ts), and
145
+ [examples/metric-tree.ts](examples/metric-tree.ts).
96
146
 
97
147
  Hooks fail loudly if called outside `<OxyAppProvider>`. The default fetcher
98
148
  sends `credentials: "include"` so same-origin (served-by-oxy) calls carry the