@comergehq/studio 0.1.32 → 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
@@ -5966,9 +5966,9 @@ function PreviewRelatedAppsSection({
5966
5966
  const renderRelatedCard = React27.useCallback(
5967
5967
  (item, options) => {
5968
5968
  const isCurrent = item.app.id === currentAppId;
5969
- const isReady = item.app.status === "ready";
5969
+ const isArchived = item.app.status === "archived";
5970
5970
  const isSwitching = switchingRelatedAppId === item.app.id;
5971
- const disabled = isCurrent || !isReady || Boolean(switchingRelatedAppId);
5971
+ const disabled = isCurrent || isArchived || Boolean(switchingRelatedAppId);
5972
5972
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
5973
5973
  import_react_native35.Pressable,
5974
5974
  {
@@ -6008,7 +6008,7 @@ function PreviewRelatedAppsSection({
6008
6008
  )
6009
6009
  ] }),
6010
6010
  /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(import_react_native35.View, { style: { alignItems: "flex-end", gap: 6 }, children: [
6011
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_react_native35.View, { style: { minHeight: 20, justifyContent: "center" }, children: !isReady ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(PreviewStatusBadge, { status: item.app.status }) : null }),
6011
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_react_native35.View, { style: { minHeight: 20, justifyContent: "center" }, children: item.app.status !== "ready" ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(PreviewStatusBadge, { status: item.app.status }) : null }),
6012
6012
  isSwitching ? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_react_native35.ActivityIndicator, { size: "small", color: theme.colors.primary }) : null
6013
6013
  ] })
6014
6014
  ] })
@@ -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);
@@ -10076,7 +10101,26 @@ function ComergeStudioInner({
10076
10101
  const [upstreamSyncStatus, setUpstreamSyncStatus] = React51.useState(null);
10077
10102
  const isMrTestBuildInProgress = bundle.loading && bundle.loadingMode === "test";
10078
10103
  const isBaseBundleDownloading = bundle.loading && bundle.loadingMode === "base" && !bundle.isTesting;
10079
- const runtimePreparingText = bundle.bundleStatus === "pending" ? "Bundling app\u2026 this may take a few minutes" : "Preparing app\u2026";
10104
+ const runtimePreparingText = React51.useMemo(() => {
10105
+ const status = app == null ? void 0 : app.status;
10106
+ if (status === "ready" && bundle.bundleStatus === "pending") {
10107
+ return "Bundling app\u2026 this may take a few minutes";
10108
+ }
10109
+ switch (status) {
10110
+ case "creating":
10111
+ return "Creating your app\u2026 this may take a moment";
10112
+ case "forking":
10113
+ return "Forking your app\u2026";
10114
+ case "editing":
10115
+ return "Applying your latest changes\u2026";
10116
+ case "merging":
10117
+ return "Merging app updates\u2026";
10118
+ case "error":
10119
+ return "This app hit an error while preparing.";
10120
+ default:
10121
+ return "Preparing app\u2026";
10122
+ }
10123
+ }, [app == null ? void 0 : app.status, bundle.bundleStatus]);
10080
10124
  const chatShowTypingIndicator = React51.useMemo(() => {
10081
10125
  var _a2;
10082
10126
  if (agentProgress.hasLiveProgress) return false;
@@ -10143,9 +10187,9 @@ function ComergeStudioInner({
10143
10187
  setSwitchingRelatedAppId(targetAppId);
10144
10188
  try {
10145
10189
  const targetApp = await appsRepository.getById(targetAppId);
10146
- if (targetApp.status !== "ready") {
10147
- const reason = `target_not_ready:${targetApp.status}`;
10148
- log.warn("[related-apps] switch blocked: target app not ready", {
10190
+ if (targetApp.status === "archived") {
10191
+ const reason = "target_archived";
10192
+ log.warn("[related-apps] switch blocked: target app archived", {
10149
10193
  fromAppId: activeAppId,
10150
10194
  toAppId: targetAppId,
10151
10195
  status: targetApp.status
@@ -10165,7 +10209,7 @@ function ComergeStudioInner({
10165
10209
  source: "related_apps_switcher"
10166
10210
  });
10167
10211
  } else {
10168
- setActiveAppId(targetAppId);
10212
+ setActiveAppId(targetAppId, "related_apps");
10169
10213
  setRuntimeAppId(targetAppId);
10170
10214
  setPendingRuntimeTargetAppId(null);
10171
10215
  }