@comergehq/studio 0.1.33 → 0.1.34

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/index.d.mts CHANGED
@@ -26,6 +26,7 @@ type BaseBundleMeta = {
26
26
  updatedAt: string;
27
27
  };
28
28
 
29
+ type ActiveAppChangedSource = 'initial' | 'fork_edit' | 'related_apps' | 'host_route_sync';
29
30
  type ComergeStudioProps = {
30
31
  appId: string;
31
32
  clientKey: string;
@@ -38,6 +39,11 @@ type ComergeStudioProps = {
38
39
  threadId?: string;
39
40
  source?: string;
40
41
  }) => void;
42
+ onActiveAppChanged?: (params: {
43
+ appId: string;
44
+ appKey?: string;
45
+ source: ActiveAppChangedSource;
46
+ }) => void;
41
47
  style?: ViewStyle;
42
48
  showBubble?: boolean;
43
49
  enableAgentProgress?: boolean;
@@ -45,7 +51,7 @@ type ComergeStudioProps = {
45
51
  embeddedBaseBundles?: EmbeddedBaseBundles;
46
52
  onSystemEvent?: (event: ComergeRuntimeSystemEventEnvelope) => void;
47
53
  };
48
- declare function ComergeStudio({ appId, clientKey, appKey, analyticsEnabled, onNavigateHome, onOpenAppRequested, style, showBubble, enableAgentProgress, studioControlOptions, embeddedBaseBundles, onSystemEvent, }: ComergeStudioProps): react_jsx_runtime.JSX.Element;
54
+ declare function ComergeStudio({ appId, clientKey, appKey, analyticsEnabled, onNavigateHome, onOpenAppRequested, onActiveAppChanged, style, showBubble, enableAgentProgress, studioControlOptions, embeddedBaseBundles, onSystemEvent, }: ComergeStudioProps): react_jsx_runtime.JSX.Element;
49
55
 
50
56
  declare function setSupabaseClient(client: SupabaseClient): void;
51
57
 
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ type BaseBundleMeta = {
26
26
  updatedAt: string;
27
27
  };
28
28
 
29
+ type ActiveAppChangedSource = 'initial' | 'fork_edit' | 'related_apps' | 'host_route_sync';
29
30
  type ComergeStudioProps = {
30
31
  appId: string;
31
32
  clientKey: string;
@@ -38,6 +39,11 @@ type ComergeStudioProps = {
38
39
  threadId?: string;
39
40
  source?: string;
40
41
  }) => void;
42
+ onActiveAppChanged?: (params: {
43
+ appId: string;
44
+ appKey?: string;
45
+ source: ActiveAppChangedSource;
46
+ }) => void;
41
47
  style?: ViewStyle;
42
48
  showBubble?: boolean;
43
49
  enableAgentProgress?: boolean;
@@ -45,7 +51,7 @@ type ComergeStudioProps = {
45
51
  embeddedBaseBundles?: EmbeddedBaseBundles;
46
52
  onSystemEvent?: (event: ComergeRuntimeSystemEventEnvelope) => void;
47
53
  };
48
- declare function ComergeStudio({ appId, clientKey, appKey, analyticsEnabled, onNavigateHome, onOpenAppRequested, style, showBubble, enableAgentProgress, studioControlOptions, embeddedBaseBundles, onSystemEvent, }: ComergeStudioProps): react_jsx_runtime.JSX.Element;
54
+ declare function ComergeStudio({ appId, clientKey, appKey, analyticsEnabled, onNavigateHome, onOpenAppRequested, onActiveAppChanged, style, showBubble, enableAgentProgress, studioControlOptions, embeddedBaseBundles, onSystemEvent, }: ComergeStudioProps): react_jsx_runtime.JSX.Element;
49
55
 
50
56
  declare function setSupabaseClient(client: SupabaseClient): void;
51
57
 
package/dist/index.js CHANGED
@@ -9891,6 +9891,7 @@ function ComergeStudio({
9891
9891
  analyticsEnabled,
9892
9892
  onNavigateHome,
9893
9893
  onOpenAppRequested,
9894
+ onActiveAppChanged,
9894
9895
  style,
9895
9896
  showBubble = true,
9896
9897
  enableAgentProgress = true,
@@ -9901,12 +9902,36 @@ function ComergeStudio({
9901
9902
  const [activeAppId, setActiveAppId] = React51.useState(appId);
9902
9903
  const [runtimeAppId, setRuntimeAppId] = React51.useState(appId);
9903
9904
  const [pendingRuntimeTargetAppId, setPendingRuntimeTargetAppId] = React51.useState(null);
9905
+ const didSyncFromHostRef = React51.useRef(false);
9906
+ const lastNotifiedRef = React51.useRef(null);
9904
9907
  const platform = React51.useMemo(() => import_react_native61.Platform.OS === "ios" ? "ios" : "android", []);
9908
+ const notifyActiveAppChanged = React51.useCallback(
9909
+ (nextAppId, source) => {
9910
+ if (!onActiveAppChanged) return;
9911
+ const trimmedAppId = nextAppId.trim();
9912
+ if (!trimmedAppId) return;
9913
+ const nextAppKey = (appKey == null ? void 0 : appKey.trim()) || "MicroMain";
9914
+ const dedupeKey = `${trimmedAppId}:${nextAppKey}`;
9915
+ if (lastNotifiedRef.current === dedupeKey) return;
9916
+ lastNotifiedRef.current = dedupeKey;
9917
+ onActiveAppChanged({ appId: trimmedAppId, appKey: nextAppKey, source });
9918
+ },
9919
+ [appKey, onActiveAppChanged]
9920
+ );
9921
+ const setActiveAppIdWithSource = React51.useCallback(
9922
+ (nextAppId, source) => {
9923
+ setActiveAppId(nextAppId);
9924
+ notifyActiveAppChanged(nextAppId, source);
9925
+ },
9926
+ [notifyActiveAppChanged]
9927
+ );
9905
9928
  React51.useEffect(() => {
9906
- setActiveAppId(appId);
9929
+ const source = didSyncFromHostRef.current ? "host_route_sync" : "initial";
9930
+ didSyncFromHostRef.current = true;
9931
+ setActiveAppIdWithSource(appId, source);
9907
9932
  setRuntimeAppId(appId);
9908
9933
  setPendingRuntimeTargetAppId(null);
9909
- }, [appId]);
9934
+ }, [appId, setActiveAppIdWithSource]);
9910
9935
  const captureTargetRef = React51.useRef(null);
9911
9936
  return /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
9912
9937
  StudioBootstrap,
@@ -9919,7 +9944,7 @@ function ComergeStudio({
9919
9944
  {
9920
9945
  userId,
9921
9946
  activeAppId,
9922
- setActiveAppId,
9947
+ setActiveAppId: setActiveAppIdWithSource,
9923
9948
  runtimeAppId,
9924
9949
  setRuntimeAppId,
9925
9950
  pendingRuntimeTargetAppId,
@@ -10039,7 +10064,7 @@ function ComergeStudioInner({
10039
10064
  userId,
10040
10065
  app,
10041
10066
  onForkedApp: (id, opts) => {
10042
- setActiveAppId(id);
10067
+ setActiveAppId(id, "fork_edit");
10043
10068
  const keepRenderingAppId = opts == null ? void 0 : opts.keepRenderingAppId;
10044
10069
  if (keepRenderingAppId) {
10045
10070
  setRuntimeAppId(keepRenderingAppId);
@@ -10184,7 +10209,7 @@ function ComergeStudioInner({
10184
10209
  source: "related_apps_switcher"
10185
10210
  });
10186
10211
  } else {
10187
- setActiveAppId(targetAppId);
10212
+ setActiveAppId(targetAppId, "related_apps");
10188
10213
  setRuntimeAppId(targetAppId);
10189
10214
  setPendingRuntimeTargetAppId(null);
10190
10215
  }