@oxy-hq/sdk 2.11.0 → 2.12.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.
Files changed (40) hide show
  1. package/README.md +44 -4
  2. package/dist/function-context-D8eyZuw_.d.cts +720 -0
  3. package/dist/function-context-D8eyZuw_.d.cts.map +1 -0
  4. package/dist/function-context-D8eyZuw_.d.mts +720 -0
  5. package/dist/function-context-D8eyZuw_.d.mts.map +1 -0
  6. package/dist/index.cjs +156 -11
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +338 -638
  9. package/dist/index.d.cts.map +1 -1
  10. package/dist/index.d.mts +338 -638
  11. package/dist/index.d.mts.map +1 -1
  12. package/dist/index.mjs +155 -12
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/ops.cjs +85 -0
  15. package/dist/ops.cjs.map +1 -0
  16. package/dist/ops.d.cts +61 -0
  17. package/dist/ops.d.cts.map +1 -0
  18. package/dist/ops.d.mts +61 -0
  19. package/dist/ops.d.mts.map +1 -0
  20. package/dist/ops.mjs +79 -0
  21. package/dist/ops.mjs.map +1 -0
  22. package/dist/{react-DqnINwTi.mjs → react-BXGyzgz0.mjs} +8 -3
  23. package/dist/react-BXGyzgz0.mjs.map +1 -0
  24. package/dist/{react-CLONxcnA.d.cts → react-DW7Z96sD.d.cts} +8 -1
  25. package/dist/{react-CLONxcnA.d.cts.map → react-DW7Z96sD.d.cts.map} +1 -1
  26. package/dist/{react-CLONxcnA.d.mts → react-DW7Z96sD.d.mts} +8 -1
  27. package/dist/{react-CLONxcnA.d.mts.map → react-DW7Z96sD.d.mts.map} +1 -1
  28. package/dist/{react-riTxd9ce.cjs → react-DcT-mUPj.cjs} +8 -3
  29. package/dist/react-DcT-mUPj.cjs.map +1 -0
  30. package/dist/shell.cjs +34 -4
  31. package/dist/shell.cjs.map +1 -1
  32. package/dist/shell.d.cts +39 -7
  33. package/dist/shell.d.cts.map +1 -1
  34. package/dist/shell.d.mts +39 -7
  35. package/dist/shell.d.mts.map +1 -1
  36. package/dist/shell.mjs +34 -5
  37. package/dist/shell.mjs.map +1 -1
  38. package/package.json +12 -1
  39. package/dist/react-DqnINwTi.mjs.map +0 -1
  40. package/dist/react-riTxd9ce.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-context-D8eyZuw_.d.mts","names":[],"sources":["../src/custom-app/function-context.ts"],"mappings":";;;;;;;;;;UA+BiB;;EAEf;;;KAMU,iBAAiB;;UAGZ;EACf;EACA;;;;;;;;;;;;;;;;;KAkBU;;;;;;;;;;;UAYK;;;;;EAKf;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;EAIA;;EAEA;;;;;;;;;;;;;;;;;;;;;;EAsBA;;;;;;;;;;EAUA;;;;;;;;;;;;;;;EAeA,QAAQ;;;;;;;;;;;;;;;;;;;;;EAqBR,OAAO;;;;;;;;;;EAUP,OAAO;;;UAIQ;EACf;;EAEA;;EAEA;;;UAIe;EACf;;EAEA;;EAEA;;;;;;KAOU,eAAe;;;;;;;EAOzB;;;;;;;;;;UAWe;;;;;;;;EAQf,MAAM,kBAAkB,cAAc;IAAU,MAAM;IAAkB;;EACxE,OAAO,kBAAkB,eAAe,MAAM,mBAAmB;EACjE,KAAK,kBAAkB,cAAc;EACrC,OACE,kBACA,eACA,MAAM,kBACN,4BACC;;;;;;;;;;;;;;UAeY;;EAEf,MAAM,aAAa,qBAAqB,QAAQ;;EAEhD,KAAK,aAAa,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAwCxB;;EAEf,MAAM,aAAa,qBAAqB,QAAQ;;EAEhD,KAAK,aAAa,qBAAqB;;;UAIxB;EACf,IAAI,aAAa,gBAAgB;;;UAIlB;;;;;;;;;EASf,MAAM,MAAM;IAA4B;MAAoB;;;UAI7C;EACf,IAAI,qBAAqB,YAAY,iCAAiC;IAAU;;;;;;;;;UAWjE;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;E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cAAc,QAAQ;;EAE5B,YACE,aACA;IAAS;MACR,eAAe;;;;;;EAMlB,MAAM,aAAa,OAAO,eAAe,QAAQ;EACjD,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCX,GAAG,GAAG,kBAAkB,KAAK,IAAI,mBAAmB,QAAQ,KAAK,IAAI,QAAQ;;;;;;;EAO7E,MAAM;EACN,SAAS;EACT,UAAU;EACV,QAAQ;EACR,OAAO;EACP,SAAS;;;KAIC,sBACV,KAAK,oBACL,KAAK,uBACF,QAAQ,YAAY"}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // @oxy/sdk - TypeScript SDK for Oxy data platform
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const require_react = require('./react-riTxd9ce.cjs');
3
+ const require_react = require('./react-DcT-mUPj.cjs');
4
4
  let react = require("react");
5
5
  react = require_react.__toESM(react, 1);
6
6
 
@@ -388,14 +388,69 @@ function useSensitivity(measureId, opts = {}) {
388
388
  * Propagate hypothetical `(measure, delta)` changes upward through the
389
389
  * tree and return the estimated impact on every downstream measure — a
390
390
  * pure metric-tree walk, no warehouse query. Pass `null` to stay idle.
391
+ *
392
+ * Because it is database-free it can only use the coefficients it is GIVEN.
393
+ * Without `opts.coefficients` from {@link useBaseline}, every driver edge
394
+ * whose `.view.yml` declares no `coefficient:` contributes nothing and its
395
+ * downstream measures are simply absent from `impacts` — no error, no
396
+ * refusal. Without `opts.values`, multiplicative component edges come back
397
+ * `unquantifiable` rather than sized.
391
398
  */
392
399
  function usePredict(changes, opts = {}) {
393
400
  const { projectId, fetcher } = require_react.useOxyApp();
394
401
  const enabled = opts.enabled !== false;
402
+ const { values, coefficients } = opts;
403
+ const body = {
404
+ changes,
405
+ ...values ? { values } : {},
406
+ ...coefficients?.length ? { coefficients } : {}
407
+ };
395
408
  return useMetricTreeEndpoint(projectId && changes ? JSON.stringify({
396
409
  projectId,
397
- changes
398
- }) : null, (signal) => postJson(fetcher, `${metricTreePath(projectId)}/predict`, { changes }, signal), enabled);
410
+ body
411
+ }) : null, (signal) => postJson(fetcher, `${metricTreePath(projectId)}/predict`, body, signal), enabled);
412
+ }
413
+ /**
414
+ * Value a scenario's starting point, and measure the coefficients it needs.
415
+ *
416
+ * Two warehouse reads: the current value of every node reachable from
417
+ * `request.roots`, and — for driver edges declaring no `coefficient:` — a fit
418
+ * over the window. Both are expensive, which is why they live here and not in
419
+ * {@link usePredict}: predict is database-free by design so it can re-run per
420
+ * keystroke, and it CANNOT measure a coefficient itself.
421
+ *
422
+ * That is the whole reason to call this. Feed `data.values` and `data.fitted`
423
+ * into `usePredict`; omit them and an undeclared edge propagates nothing.
424
+ * Pass `null` to stay idle until levers and a period are chosen.
425
+ */
426
+ function useBaseline(request, opts = {}) {
427
+ const { projectId, fetcher } = require_react.useOxyApp();
428
+ const enabled = opts.enabled !== false;
429
+ return useMetricTreeEndpoint(projectId && request ? JSON.stringify({
430
+ projectId,
431
+ request
432
+ }) : null, (signal) => postJson(fetcher, `${metricTreePath(projectId)}/baseline`, request, signal), enabled);
433
+ }
434
+ /**
435
+ * Bucketed history for the levers and everything downstream, plus the forward
436
+ * curve the forecaster expects next — the scenario's time axis.
437
+ *
438
+ * One warehouse query, so it belongs on a window change, not on a lever edit.
439
+ * It returns the BASELINE curve only: the scenario's second curve is
440
+ * arithmetic over this and a `usePredict` result — a proportional shift
441
+ * landing `lag` buckets in — composed client-side precisely so editing a lever
442
+ * costs no query.
443
+ *
444
+ * Treat a series with a `refusal` as a stated absence: it must not render as a
445
+ * flat forward line. Pass `null` to stay idle.
446
+ */
447
+ function useProjection(request, opts = {}) {
448
+ const { projectId, fetcher } = require_react.useOxyApp();
449
+ const enabled = opts.enabled !== false;
450
+ return useMetricTreeEndpoint(projectId && request ? JSON.stringify({
451
+ projectId,
452
+ request
453
+ }) : null, (signal) => postJson(fetcher, `${metricTreePath(projectId)}/projection`, request, signal), enabled);
399
454
  }
400
455
  /**
401
456
  * Period-over-period root-cause decomposition: recursively splits the
@@ -556,9 +611,9 @@ function useWorldModelGraph(opts = {}) {
556
611
  * to stay idle until an entity is chosen.
557
612
  */
558
613
  function useWorldModelInstances(entityId, opts = {}) {
559
- const { projectId, fetcher } = require_react.useOxyApp();
614
+ const { projectId, appId, fetcher } = require_react.useOxyApp();
560
615
  const enabled = opts.enabled !== false;
561
- const { search, limit } = opts;
616
+ const { search, limit, scope } = opts;
562
617
  const [data, setData] = react.useState(null);
563
618
  const [loading, setLoading] = react.useState(enabled && !!projectId && !!entityId);
564
619
  const [error, setError] = react.useState(null);
@@ -575,6 +630,10 @@ function useWorldModelInstances(entityId, opts = {}) {
575
630
  const params = new URLSearchParams({ entity: entityId });
576
631
  if (search) params.set("search", search);
577
632
  if (limit != null) params.set("limit", String(limit));
633
+ if (scope) {
634
+ params.set("scope", scope);
635
+ if (appId) params.set("app", appId);
636
+ }
578
637
  fetcher(`${worldModelPath(projectId)}/instances?${params}`, {
579
638
  method: "GET",
580
639
  signal: ctrl.signal
@@ -601,7 +660,9 @@ function useWorldModelInstances(entityId, opts = {}) {
601
660
  entityId,
602
661
  search,
603
662
  limit,
604
- fetcher
663
+ fetcher,
664
+ scope,
665
+ appId
605
666
  ]);
606
667
  return {
607
668
  data,
@@ -818,9 +879,10 @@ function useWorldModel() {
818
879
  //#endregion
819
880
  //#region src/metricTree.ts
820
881
  /**
821
- * Client for the `/semantic/metric-tree*` endpoints. Surfaces the four
822
- * airlayer metric-tree analyses (tree introspection, sensitivity, predict,
823
- * explain, opportunity) over typed methods.
882
+ * Client for the `/semantic/metric-tree*` endpoints. Surfaces the airlayer
883
+ * metric-tree analyses — tree introspection, sensitivity, explain, opportunity
884
+ * — plus the three legs of scenario forecasting (`baseline` levels,
885
+ * `predict` propagation, `projection` curves) over typed methods.
824
886
  *
825
887
  * Construction is internal to {@link OxyClient} — call `client.metricTree`
826
888
  * to access an instance rather than building one yourself.
@@ -880,9 +942,50 @@ var MetricTreeClient = class {
880
942
  return this.request(this.path(`/${encodeURIComponent(measureId)}/sensitivity${query}`));
881
943
  }
882
944
  /**
945
+ * Value a change's starting point, and measure the coefficients it needs.
946
+ *
947
+ * Two warehouse reads: the current value of every node reachable from
948
+ * `roots`, and — for driver edges that declare no `coefficient:` — a fit
949
+ * over the window. Both are expensive, which is why they live here and not
950
+ * in `predict`: `predict` is database-free by design so it can re-run per
951
+ * keystroke, and it CANNOT measure a coefficient itself.
952
+ *
953
+ * That is the whole reason to call this. Pass `fitted` back into `predict`
954
+ * and an undeclared edge propagates; omit it and `predict` has nothing to
955
+ * multiply by, so the impact is simply absent — no error, no refusal, just a
956
+ * downstream measure that never appears.
957
+ *
958
+ * @example
959
+ * ```typescript
960
+ * const baseline = await client.metricTree.getBaseline({
961
+ * roots: ["marketing_spend.total_spend"],
962
+ * time_dimension: "orders.order_date",
963
+ * period: ["2025-09-01", "2025-09-30"],
964
+ * });
965
+ * const result = await client.metricTree.predict(
966
+ * [{ measure: "marketing_spend.total_spend", delta: 10000 }],
967
+ * { values: baseline.values, coefficients: baseline.fitted }
968
+ * );
969
+ * ```
970
+ */
971
+ async getBaseline(request) {
972
+ const query = this.buildQuery();
973
+ return this.request(this.path(`/baseline${query}`), {
974
+ method: "POST",
975
+ body: JSON.stringify(request)
976
+ });
977
+ }
978
+ /**
883
979
  * Propagate hypothetical `(measure, delta)` changes upward through the
884
980
  * tree. Returns the estimated impact on every downstream measure.
885
981
  *
982
+ * Database-free, so it re-runs cheaply — and so it can only use
983
+ * coefficients it is GIVEN. Without `options.coefficients` from
984
+ * {@link getBaseline}, every edge whose `.view.yml` declares no
985
+ * `coefficient:` contributes nothing and its downstream measures are
986
+ * silently missing from `impacts`. Without `options.values`, multiplicative
987
+ * component edges come back `unquantifiable` rather than sized.
988
+ *
886
989
  * @example
887
990
  * ```typescript
888
991
  * const result = await client.metricTree.predict([
@@ -890,11 +993,51 @@ var MetricTreeClient = class {
890
993
  * ]);
891
994
  * ```
892
995
  */
893
- async predict(changes) {
996
+ async predict(changes, options = {}) {
894
997
  const query = this.buildQuery();
895
998
  return this.request(this.path(`/predict${query}`), {
896
999
  method: "POST",
897
- body: JSON.stringify({ changes })
1000
+ body: JSON.stringify({
1001
+ changes,
1002
+ ...options.values ? { values: options.values } : {},
1003
+ ...options.coefficients?.length ? { coefficients: options.coefficients } : {}
1004
+ })
1005
+ });
1006
+ }
1007
+ /**
1008
+ * Draw the scenario's time axis: bucketed history for the levers and
1009
+ * everything downstream, plus the forward curve the detector's own model
1010
+ * expects next.
1011
+ *
1012
+ * The third leg of scenario forecasting. {@link getBaseline} gives levels
1013
+ * and coefficients, {@link predict} propagates a change with no database at
1014
+ * all, and this gives time — one warehouse query, so treat it like the
1015
+ * baseline: fetch on a window change, not on a lever edit.
1016
+ *
1017
+ * **Returns the BASELINE curve only.** The scenario's second curve is
1018
+ * arithmetic over this and a `predict` result — a proportional shift landing
1019
+ * `lag` buckets in — and is composed client-side deliberately, so editing a
1020
+ * lever costs no query.
1021
+ *
1022
+ * @example
1023
+ * ```typescript
1024
+ * const projection = await client.metricTree.getProjection({
1025
+ * roots: ["marketing_spend.total_spend"],
1026
+ * time_dimension: "orders.order_date",
1027
+ * period: ["2024-09-01", "2025-08-31"],
1028
+ * granularity: "day",
1029
+ * horizon: 30,
1030
+ * });
1031
+ * for (const series of projection.series) {
1032
+ * if (series.refusal) console.warn(series.measure, series.refusal);
1033
+ * }
1034
+ * ```
1035
+ */
1036
+ async getProjection(request) {
1037
+ const query = this.buildQuery();
1038
+ return this.request(this.path(`/projection${query}`), {
1039
+ method: "POST",
1040
+ body: JSON.stringify(request)
898
1041
  });
899
1042
  }
900
1043
  /**
@@ -964,6 +1107,7 @@ exports.readInjectedAppConfig = require_react.readInjectedAppConfig;
964
1107
  exports.readJsonSseStream = readJsonSseStream;
965
1108
  exports.setOxyAppLogger = require_react.setOxyAppLogger;
966
1109
  exports.useAgentRun = require_react.useAgentRun;
1110
+ exports.useBaseline = useBaseline;
967
1111
  exports.useDistribution = useDistribution;
968
1112
  exports.useExplain = useExplain;
969
1113
  exports.useFunction = require_react.useFunction;
@@ -973,6 +1117,7 @@ exports.useOpportunity = useOpportunity;
973
1117
  exports.useOxyApp = require_react.useOxyApp;
974
1118
  exports.usePredict = usePredict;
975
1119
  exports.useProcedureRun = require_react.useProcedureRun;
1120
+ exports.useProjection = useProjection;
976
1121
  exports.useQuery = require_react.useQuery;
977
1122
  exports.useResolvedManifest = require_react.useResolvedManifest;
978
1123
  exports.useSemanticQuery = require_react.useSemanticQuery;