@shuffleio/shuffle-mcps 0.0.16 → 0.0.17

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.js CHANGED
@@ -29,10 +29,137 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  ));
30
30
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
31
 
32
+ // fetchBreaker.ts
33
+ var FAIL_THRESHOLD, ROLLING_WINDOW_MS, COOLDOWN_MS, HARD_BURST_THRESHOLD, HARD_BURST_WINDOW_MS, state, installed, allowedOrigins, getEntry, prune, keyFor, synthetic503, registerProtectedOrigin, installFetchBreaker;
34
+ var init_fetchBreaker = __esm({
35
+ "fetchBreaker.ts"() {
36
+ FAIL_THRESHOLD = 12;
37
+ ROLLING_WINDOW_MS = 5e3;
38
+ COOLDOWN_MS = 3e4;
39
+ HARD_BURST_THRESHOLD = 30;
40
+ HARD_BURST_WINDOW_MS = 1e3;
41
+ state = /* @__PURE__ */ new Map();
42
+ installed = false;
43
+ allowedOrigins = /* @__PURE__ */ new Set();
44
+ getEntry = (key) => {
45
+ let entry = state.get(key);
46
+ if (!entry) {
47
+ entry = { failures: [], attempts: [], blockedUntil: 0, warned: false };
48
+ state.set(key, entry);
49
+ }
50
+ return entry;
51
+ };
52
+ prune = (arr, now, windowMs) => {
53
+ const cutoff = now - windowMs;
54
+ while (arr.length && arr[0] < cutoff) arr.shift();
55
+ };
56
+ keyFor = (input, init) => {
57
+ let urlStr;
58
+ let method = (init?.method || (typeof input !== "string" && "method" in input ? input.method : "GET") || "GET").toUpperCase();
59
+ if (typeof input === "string") urlStr = input;
60
+ else if (input instanceof URL) urlStr = input.toString();
61
+ else if (input && typeof input.url === "string") urlStr = input.url;
62
+ else return null;
63
+ try {
64
+ const u = new URL(urlStr, typeof window !== "undefined" ? window.location.href : "http://localhost");
65
+ if (allowedOrigins.size && !allowedOrigins.has(u.origin)) return null;
66
+ if (!u.pathname.startsWith("/api/")) return null;
67
+ return `${method} ${u.origin}${u.pathname}`;
68
+ } catch {
69
+ return null;
70
+ }
71
+ };
72
+ synthetic503 = (key, retryInMs) => new Response(
73
+ JSON.stringify({
74
+ error: "circuit_breaker_open",
75
+ message: `Too many failures for ${key}. Cooling down for ${Math.ceil(retryInMs / 1e3)}s.`
76
+ }),
77
+ {
78
+ status: 503,
79
+ statusText: "Service Unavailable (circuit breaker)",
80
+ headers: { "Content-Type": "application/json", "Retry-After": String(Math.ceil(retryInMs / 1e3)) }
81
+ }
82
+ );
83
+ registerProtectedOrigin = (url) => {
84
+ if (!url) return;
85
+ try {
86
+ const origin = new URL(url, typeof window !== "undefined" ? window.location.href : "http://localhost").origin;
87
+ allowedOrigins.add(origin);
88
+ } catch {
89
+ }
90
+ };
91
+ installFetchBreaker = () => {
92
+ if (installed) return;
93
+ if (typeof window === "undefined" || typeof window.fetch !== "function") return;
94
+ installed = true;
95
+ const original = window.fetch.bind(window);
96
+ window.fetch = (async (input, init) => {
97
+ const key = keyFor(input, init);
98
+ if (!key) return original(input, init);
99
+ const entry = getEntry(key);
100
+ const now = Date.now();
101
+ if (entry.blockedUntil > now) {
102
+ return synthetic503(key, entry.blockedUntil - now);
103
+ }
104
+ entry.attempts.push(now);
105
+ prune(entry.attempts, now, HARD_BURST_WINDOW_MS);
106
+ if (entry.attempts.length > HARD_BURST_THRESHOLD) {
107
+ entry.blockedUntil = now + COOLDOWN_MS;
108
+ if (!entry.warned) {
109
+ entry.warned = true;
110
+ console.error(
111
+ `[fetchBreaker] Burst detected on ${key} (${entry.attempts.length} calls / ${HARD_BURST_WINDOW_MS}ms). Blocking for ${COOLDOWN_MS / 1e3}s. Fix the caller \u2014 this is almost always a missing useEffect dep or a render loop.`
112
+ );
113
+ }
114
+ return synthetic503(key, COOLDOWN_MS);
115
+ }
116
+ let response;
117
+ try {
118
+ response = await original(input, init);
119
+ } catch (err) {
120
+ const ts = Date.now();
121
+ entry.failures.push(ts);
122
+ prune(entry.failures, ts, ROLLING_WINDOW_MS);
123
+ if (entry.failures.length >= FAIL_THRESHOLD) {
124
+ entry.blockedUntil = ts + COOLDOWN_MS;
125
+ if (!entry.warned) {
126
+ entry.warned = true;
127
+ console.error(
128
+ `[fetchBreaker] ${entry.failures.length} network errors on ${key} in ${ROLLING_WINDOW_MS / 1e3}s. Blocking for ${COOLDOWN_MS / 1e3}s.`
129
+ );
130
+ }
131
+ }
132
+ throw err;
133
+ }
134
+ if (response.status >= 500 || response.status === 0) {
135
+ const ts = Date.now();
136
+ entry.failures.push(ts);
137
+ prune(entry.failures, ts, ROLLING_WINDOW_MS);
138
+ if (entry.failures.length >= FAIL_THRESHOLD) {
139
+ entry.blockedUntil = ts + COOLDOWN_MS;
140
+ if (!entry.warned) {
141
+ entry.warned = true;
142
+ console.error(
143
+ `[fetchBreaker] ${entry.failures.length} ${response.status}s on ${key} in ${ROLLING_WINDOW_MS / 1e3}s. Blocking for ${COOLDOWN_MS / 1e3}s.`
144
+ );
145
+ }
146
+ }
147
+ } else if (response.status < 400) {
148
+ entry.failures.length = 0;
149
+ entry.warned = false;
150
+ }
151
+ return response;
152
+ });
153
+ };
154
+ }
155
+ });
156
+
32
157
  // api.ts
33
- var DEV_BACKEND, PROD_BACKEND, CLOUD_DOMAINS, getEnvVar, isDevEnvironment, isCloudDomain, isCloud, isOnprem, getDefaultBaseUrl, _regionUrl, _trackedOrgId, getTrackedOrgId, API_CONFIG, getApiUrl, shuffleFetch, getAuthHeader;
158
+ var DEV_BACKEND, PROD_BACKEND, CLOUD_DOMAINS, getEnvVar, isDevEnvironment, isCloudDomain, isCloud, isOnprem, getDefaultBaseUrl, _regionUrl, _trackedOrgId, _hostBaseUrl, isShufflerSubdomain, setRegionUrl, resetRegionUrl, setHostBaseUrl, getHostBaseUrl, getTrackedOrgId, API_CONFIG, getApiUrl, shuffleFetch, getAuthHeader;
34
159
  var init_api = __esm({
35
160
  "api.ts"() {
161
+ init_fetchBreaker();
162
+ installFetchBreaker();
36
163
  DEV_BACKEND = "https://tunnel.schemaless.org";
37
164
  PROD_BACKEND = "https://shuffler.io";
38
165
  CLOUD_DOMAINS = ["security.shuffler.io", "shutdown.no"];
@@ -69,11 +196,59 @@ var init_api = __esm({
69
196
  };
70
197
  _regionUrl = null;
71
198
  _trackedOrgId = null;
199
+ _hostBaseUrl = null;
200
+ isShufflerSubdomain = (url) => {
201
+ try {
202
+ const parsed = new URL(url);
203
+ return parsed.hostname.endsWith(".shuffler.io") || parsed.hostname === "shuffler.io";
204
+ } catch {
205
+ return false;
206
+ }
207
+ };
208
+ setRegionUrl = (regionUrl, orgId) => {
209
+ if (isDevEnvironment()) {
210
+ _trackedOrgId = orgId || null;
211
+ return;
212
+ }
213
+ _trackedOrgId = orgId || null;
214
+ if (regionUrl && isShufflerSubdomain(regionUrl)) {
215
+ const normalized = regionUrl.replace(/\/+$/, "");
216
+ if (normalized !== PROD_BACKEND) {
217
+ _regionUrl = normalized;
218
+ console.log(`[API] Region URL set to: ${_regionUrl}`);
219
+ return;
220
+ }
221
+ }
222
+ _regionUrl = null;
223
+ };
224
+ resetRegionUrl = () => {
225
+ if (_regionUrl) {
226
+ console.log(`[API] Region URL reset to default (org changed)`);
227
+ }
228
+ _regionUrl = null;
229
+ };
230
+ setHostBaseUrl = (url) => {
231
+ const next = url ? url.replace(/\/+$/, "") : null;
232
+ if (next === _hostBaseUrl) return;
233
+ _hostBaseUrl = next;
234
+ if (next) {
235
+ try {
236
+ registerProtectedOrigin(next);
237
+ } catch {
238
+ }
239
+ }
240
+ };
241
+ getHostBaseUrl = () => _hostBaseUrl;
72
242
  getTrackedOrgId = () => _trackedOrgId;
73
243
  API_CONFIG = {
74
- // Shuffle backend URL - uses region URL if set, otherwise default
244
+ // Shuffle backend URL — host override beats region URL beats default.
75
245
  get baseUrl() {
76
- return _regionUrl || getDefaultBaseUrl();
246
+ const url = _hostBaseUrl || _regionUrl || getDefaultBaseUrl();
247
+ try {
248
+ registerProtectedOrigin(url);
249
+ } catch {
250
+ }
251
+ return url;
77
252
  },
78
253
  // API version
79
254
  version: "v1",
@@ -126,11 +301,12 @@ __export(appsCache_exports, {
126
301
  fetchAppsViaApiConfig: () => fetchAppsViaApiConfig,
127
302
  invalidateAppsCache: () => invalidateAppsCache
128
303
  });
129
- var TTL_MS2, cache2, cacheKey2, doFetch2, fetchApps, invalidateAppsCache, fetchAppsViaApiConfig;
304
+ var TTL_MS2, ERROR_TTL_MS, cache2, cacheKey2, doFetch2, fetchApps, invalidateAppsCache, fetchAppsViaApiConfig;
130
305
  var init_appsCache = __esm({
131
306
  "appsCache.ts"() {
132
307
  init_api();
133
308
  TTL_MS2 = 3e4;
309
+ ERROR_TTL_MS = 3e4;
134
310
  cache2 = /* @__PURE__ */ new Map();
135
311
  cacheKey2 = (o) => `${o.baseUrl}|${o.path || "/api/v1/apps"}|${o.apiKey || ""}|${o.orgId || ""}`;
136
312
  doFetch2 = async (o) => {
@@ -156,9 +332,9 @@ var init_appsCache = __esm({
156
332
  const promise = doFetch2(opts).then((data) => {
157
333
  cache2.set(key, { data, fetchedAt: Date.now() });
158
334
  return data;
159
- }).catch((err) => {
160
- cache2.delete(key);
161
- throw err;
335
+ }).catch(() => {
336
+ cache2.set(key, { data: [], fetchedAt: Date.now() - (TTL_MS2 - ERROR_TTL_MS) });
337
+ return [];
162
338
  });
163
339
  cache2.set(key, { ...entry, promise });
164
340
  return promise;
@@ -234,8 +410,10 @@ __export(index_exports, {
234
410
  getDatastoreItem: () => getDatastoreItem,
235
411
  getDatastoreItemPublic: () => getDatastoreItemPublic,
236
412
  getFailureInfo: () => getFailureInfo,
413
+ getHostBaseUrl: () => getHostBaseUrl,
237
414
  getIngestionCategory: () => getIngestionCategory,
238
415
  hasOutputWarning: () => hasOutputWarning,
416
+ installFetchBreaker: () => installFetchBreaker,
239
417
  invalidateAppsCache: () => invalidateAppsCache,
240
418
  invalidateResolvedApps: () => invalidateResolvedApps,
241
419
  isCloud: () => isCloud,
@@ -249,12 +427,16 @@ __export(index_exports, {
249
427
  normalizeAppName: () => normalizeAppName,
250
428
  parseRunResult: () => parseRunResult,
251
429
  refreshAllIntegrationStatus: () => refreshAllIntegrationStatus,
430
+ registerProtectedOrigin: () => registerProtectedOrigin,
431
+ resetRegionUrl: () => resetRegionUrl,
252
432
  resolveApp: () => resolveApp,
253
433
  resolveApps: () => resolveApps,
254
434
  searchAgentActivity: () => searchAgentActivity,
255
435
  seedResolvedApp: () => seedResolvedApp,
256
436
  setDatastoreItem: () => setDatastoreItem,
257
437
  setDatastoreItems: () => setDatastoreItems,
438
+ setHostBaseUrl: () => setHostBaseUrl,
439
+ setRegionUrl: () => setRegionUrl,
258
440
  setRuntimeOrgId: () => setRuntimeOrgId,
259
441
  setToastImpl: () => setToastImpl,
260
442
  shuffleFetch: () => shuffleFetch,
@@ -262,7 +444,8 @@ __export(index_exports, {
262
444
  useAppAuth: () => useAppAuth,
263
445
  useAppDetail: () => useAppDetail,
264
446
  useAppDetailOptional: () => useAppDetailOptional,
265
- useAppLookup: () => useAppLookup
447
+ useAppLookup: () => useAppLookup,
448
+ useSyncHostBaseUrl: () => useSyncHostBaseUrl
266
449
  });
267
450
  module.exports = __toCommonJS(index_exports);
268
451
  var import_shuffle_mcp2 = require("./shuffle-mcp-CN72CJJQ.css");
@@ -379,7 +562,7 @@ var ShuffleMcpThemeProvider = ({
379
562
  };
380
563
 
381
564
  // ShuffleMCP.tsx
382
- var import_react11 = __toESM(require("react"));
565
+ var import_react12 = __toESM(require("react"));
383
566
  var import_algoliasearch = require("algoliasearch");
384
567
  var import_material10 = require("@mui/material");
385
568
 
@@ -5884,13 +6067,23 @@ function SegmentedControl({
5884
6067
  ) });
5885
6068
  }
5886
6069
 
6070
+ // useSyncHostBaseUrl.ts
6071
+ var import_react11 = require("react");
6072
+ init_api();
6073
+ var useSyncHostBaseUrl = (globalUrl) => {
6074
+ (0, import_react11.useEffect)(() => {
6075
+ if (!globalUrl) return;
6076
+ setHostBaseUrl(globalUrl);
6077
+ }, [globalUrl]);
6078
+ };
6079
+
5887
6080
  // ShuffleMCP.tsx
5888
6081
  var import_jsx_runtime14 = require("react/jsx-runtime");
5889
6082
  var DEFAULT_ALGOLIA_APP_ID = "JNSS5CFDZZ";
5890
6083
  var DEFAULT_ALGOLIA_API_KEY = "33e4e3564f4f060e96e0531957bed552";
5891
6084
  var DEFAULT_ALGOLIA_INDEX = "appsearch";
5892
6085
  var EMPTY_SELECTED_APPS = [];
5893
- var ShuffleMCP = import_react11.default.forwardRef(({
6086
+ var ShuffleMCP = import_react12.default.forwardRef(({
5894
6087
  authToken,
5895
6088
  orgId,
5896
6089
  placeholder = "Search apps...",
@@ -5927,25 +6120,27 @@ var ShuffleMCP = import_react11.default.forwardRef(({
5927
6120
  renderLoadingState,
5928
6121
  onAppSelected,
5929
6122
  onSelectionChange,
5930
- onSearchChange
6123
+ onSearchChange,
6124
+ globalUrl
5931
6125
  }, ref) => {
5932
- const [query, setQuery] = (0, import_react11.useState)(initialQuery);
5933
- const [results, setResults] = (0, import_react11.useState)([]);
5934
- const [privateApps, setPrivateApps] = (0, import_react11.useState)([]);
5935
- const [sourceFilter, setSourceFilter] = (0, import_react11.useState)("all");
5936
- const [isLoading, setIsLoading] = (0, import_react11.useState)(false);
5937
- const [searchError, setSearchError] = (0, import_react11.useState)(null);
5938
- const [isOpen, setIsOpen] = (0, import_react11.useState)(false);
5939
- const [selectedIndex, setSelectedIndex] = (0, import_react11.useState)(-1);
5940
- const [internalSelectedApps, setInternalSelectedApps] = (0, import_react11.useState)(selectedApps);
5941
- const [authenticatedApps, setAuthenticatedApps] = (0, import_react11.useState)(externalAuthenticatedApps || []);
5942
- const [drawerApp, setDrawerApp] = (0, import_react11.useState)(null);
5943
- const hasInitialized = (0, import_react11.useRef)(false);
5944
- const containerRef = (0, import_react11.useRef)(null);
5945
- const inputRef = (0, import_react11.useRef)(null);
5946
- const debounceTimer = (0, import_react11.useRef)(null);
5947
- const searchClient = (0, import_react11.useRef)(null);
5948
- const fetchAuthenticatedApps2 = (0, import_react11.useCallback)(async () => {
6126
+ useSyncHostBaseUrl(globalUrl);
6127
+ const [query, setQuery] = (0, import_react12.useState)(initialQuery);
6128
+ const [results, setResults] = (0, import_react12.useState)([]);
6129
+ const [privateApps, setPrivateApps] = (0, import_react12.useState)([]);
6130
+ const [sourceFilter, setSourceFilter] = (0, import_react12.useState)("all");
6131
+ const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
6132
+ const [searchError, setSearchError] = (0, import_react12.useState)(null);
6133
+ const [isOpen, setIsOpen] = (0, import_react12.useState)(false);
6134
+ const [selectedIndex, setSelectedIndex] = (0, import_react12.useState)(-1);
6135
+ const [internalSelectedApps, setInternalSelectedApps] = (0, import_react12.useState)(selectedApps);
6136
+ const [authenticatedApps, setAuthenticatedApps] = (0, import_react12.useState)(externalAuthenticatedApps || []);
6137
+ const [drawerApp, setDrawerApp] = (0, import_react12.useState)(null);
6138
+ const hasInitialized = (0, import_react12.useRef)(false);
6139
+ const containerRef = (0, import_react12.useRef)(null);
6140
+ const inputRef = (0, import_react12.useRef)(null);
6141
+ const debounceTimer = (0, import_react12.useRef)(null);
6142
+ const searchClient = (0, import_react12.useRef)(null);
6143
+ const fetchAuthenticatedApps2 = (0, import_react12.useCallback)(async () => {
5949
6144
  if (!apiKey) return;
5950
6145
  try {
5951
6146
  const response = await fetch(`${apiBaseUrl}${authPath}`, {
@@ -5965,10 +6160,10 @@ var ShuffleMCP = import_react11.default.forwardRef(({
5965
6160
  console.error("Failed to fetch authenticated apps:", error);
5966
6161
  }
5967
6162
  }, [apiKey, apiBaseUrl, authPath, orgId]);
5968
- (0, import_react11.useEffect)(() => {
6163
+ (0, import_react12.useEffect)(() => {
5969
6164
  fetchAuthenticatedApps2();
5970
6165
  }, [fetchAuthenticatedApps2]);
5971
- (0, import_react11.useEffect)(() => {
6166
+ (0, import_react12.useEffect)(() => {
5972
6167
  if (disablePrivateApps) {
5973
6168
  setPrivateApps([]);
5974
6169
  return;
@@ -6008,7 +6203,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6008
6203
  };
6009
6204
  fetchPrivateApps();
6010
6205
  }, [apiKey, apiBaseUrl, privateAppsPath, disablePrivateApps, orgId]);
6011
- (0, import_react11.useEffect)(() => {
6206
+ (0, import_react12.useEffect)(() => {
6012
6207
  if (authenticatedApps.length > 0 && results.length > 0) {
6013
6208
  const validatedApps = authenticatedApps.filter((auth) => auth.validation?.valid);
6014
6209
  const appsToAutoSelect = results.filter(
@@ -6028,12 +6223,12 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6028
6223
  }
6029
6224
  }
6030
6225
  }, [authenticatedApps, results]);
6031
- (0, import_react11.useEffect)(() => {
6226
+ (0, import_react12.useEffect)(() => {
6032
6227
  if (externalAuthenticatedApps) {
6033
6228
  setAuthenticatedApps(externalAuthenticatedApps);
6034
6229
  }
6035
6230
  }, [externalAuthenticatedApps]);
6036
- (0, import_react11.useEffect)(() => {
6231
+ (0, import_react12.useEffect)(() => {
6037
6232
  searchClient.current = (0, import_algoliasearch.algoliasearch)(algoliaAppId, algoliaApiKey);
6038
6233
  if (!hasInitialized.current) {
6039
6234
  hasInitialized.current = true;
@@ -6046,10 +6241,10 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6046
6241
  }, 100);
6047
6242
  }
6048
6243
  }, []);
6049
- (0, import_react11.useEffect)(() => {
6244
+ (0, import_react12.useEffect)(() => {
6050
6245
  setInternalSelectedApps(selectedApps);
6051
6246
  }, [selectedApps]);
6052
- (0, import_react11.useEffect)(() => {
6247
+ (0, import_react12.useEffect)(() => {
6053
6248
  const handleClickOutside = (event) => {
6054
6249
  if (containerRef.current && !containerRef.current.contains(event.target)) {
6055
6250
  setIsOpen(false);
@@ -6059,23 +6254,23 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6059
6254
  document.addEventListener("click", handleClickOutside);
6060
6255
  return () => document.removeEventListener("click", handleClickOutside);
6061
6256
  }, []);
6062
- const isAppConfigured = (0, import_react11.useCallback)((app) => {
6257
+ const isAppConfigured = (0, import_react12.useCallback)((app) => {
6063
6258
  return authenticatedApps.some(
6064
6259
  (auth) => auth.app.name.toLowerCase() === app.name.toLowerCase() && auth.active === true
6065
6260
  );
6066
6261
  }, [authenticatedApps]);
6067
- const isAppValidated = (0, import_react11.useCallback)((app) => {
6262
+ const isAppValidated = (0, import_react12.useCallback)((app) => {
6068
6263
  return authenticatedApps.some(
6069
6264
  (auth) => auth.app.name.toLowerCase() === app.name.toLowerCase() && auth.validation?.valid === true
6070
6265
  );
6071
6266
  }, [authenticatedApps]);
6072
- const getAppAuthState = (0, import_react11.useCallback)((app) => {
6267
+ const getAppAuthState = (0, import_react12.useCallback)((app) => {
6073
6268
  return {
6074
6269
  configured: isAppConfigured(app),
6075
6270
  validated: isAppValidated(app)
6076
6271
  };
6077
6272
  }, [isAppConfigured, isAppValidated]);
6078
- const performSearch = (0, import_react11.useCallback)(async (searchQuery) => {
6273
+ const performSearch = (0, import_react12.useCallback)(async (searchQuery) => {
6079
6274
  if (!searchClient.current) {
6080
6275
  return;
6081
6276
  }
@@ -6109,7 +6304,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6109
6304
  setIsLoading(false);
6110
6305
  }
6111
6306
  }, [hitsPerPage, algoliaIndexName, privateApps.length]);
6112
- (0, import_react11.useImperativeHandle)(ref, () => ({
6307
+ (0, import_react12.useImperativeHandle)(ref, () => ({
6113
6308
  search: (searchQuery) => {
6114
6309
  setQuery(searchQuery);
6115
6310
  onSearchChange?.(searchQuery);
@@ -6121,7 +6316,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6121
6316
  },
6122
6317
  getQuery: () => query
6123
6318
  }), [performSearch, onSearchChange, query]);
6124
- const handleInputChange = (0, import_react11.useCallback)((event) => {
6319
+ const handleInputChange = (0, import_react12.useCallback)((event) => {
6125
6320
  const value = event.target.value;
6126
6321
  setQuery(value);
6127
6322
  setSelectedIndex(-1);
@@ -6133,7 +6328,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6133
6328
  performSearch(value);
6134
6329
  }, 300);
6135
6330
  }, [performSearch, onSearchChange]);
6136
- const selectApp = (0, import_react11.useCallback)((app) => {
6331
+ const selectApp = (0, import_react12.useCallback)((app) => {
6137
6332
  const handoffToken = apiKey || authToken || "";
6138
6333
  const authUrl = `${apiBaseUrl}${appAuthPath}?app_id=${app.objectID}&auth=${handoffToken}&source=shuffle${orgId ? `&org_id=${encodeURIComponent(orgId)}` : ""}`;
6139
6334
  if (multiSelect) {
@@ -6153,7 +6348,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6153
6348
  setIsOpen(false);
6154
6349
  }
6155
6350
  }, [authToken, apiKey, apiBaseUrl, appAuthPath, orgId, multiSelect, internalSelectedApps, onAppSelected, onSelectionChange, preventDefault]);
6156
- const handleKeyDown = (0, import_react11.useCallback)((event) => {
6351
+ const handleKeyDown = (0, import_react12.useCallback)((event) => {
6157
6352
  if (!isOpen) return;
6158
6353
  switch (event.key) {
6159
6354
  case "ArrowDown":
@@ -6178,14 +6373,14 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6178
6373
  break;
6179
6374
  }
6180
6375
  }, [isOpen, results, selectedIndex, selectApp]);
6181
- const isAppSelected = (0, import_react11.useCallback)((app) => {
6376
+ const isAppSelected = (0, import_react12.useCallback)((app) => {
6182
6377
  const norm4 = (s) => (s || "").toLowerCase().replace(/[\s-]+/g, "_");
6183
6378
  const target = norm4(app.name);
6184
6379
  return internalSelectedApps.some(
6185
6380
  (a) => a.objectID === app.objectID || target && norm4(a.name) === target
6186
6381
  );
6187
6382
  }, [internalSelectedApps]);
6188
- const filteredPrivateApps = (0, import_react11.useMemo)(() => {
6383
+ const filteredPrivateApps = (0, import_react12.useMemo)(() => {
6189
6384
  if (privateApps.length === 0) return [];
6190
6385
  const q = query.trim().toLowerCase();
6191
6386
  if (!q) return privateApps;
@@ -6193,7 +6388,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6193
6388
  (a) => a.name.toLowerCase().includes(q) || (a.description || "").toLowerCase().includes(q) || (a.categories || []).some((c) => c.toLowerCase().includes(q))
6194
6389
  );
6195
6390
  }, [privateApps, query]);
6196
- const displayResults = (0, import_react11.useMemo)(() => {
6391
+ const displayResults = (0, import_react12.useMemo)(() => {
6197
6392
  const norm4 = (n) => (n || "").toLowerCase().replace(/[\s_\-]+/g, "");
6198
6393
  let merged;
6199
6394
  if (sourceFilter === "public") {
@@ -6213,7 +6408,7 @@ var ShuffleMCP = import_react11.default.forwardRef(({
6213
6408
  const pinnedNames = new Set(pinnedApps.map((a) => norm4(a.name)));
6214
6409
  return [...pinnedApps, ...merged.filter((a) => !pinnedNames.has(norm4(a.name)))];
6215
6410
  }, [pinnedApps, results, filteredPrivateApps, sourceFilter, isAppConfigured]);
6216
- const getGridColumnsStyle = (0, import_react11.useMemo)(() => {
6411
+ const getGridColumnsStyle = (0, import_react12.useMemo)(() => {
6217
6412
  if (layout !== "grid") return {};
6218
6413
  const cols = typeof gridColumns === "number" ? gridColumns : gridColumns.md || 3;
6219
6414
  return { "--singul-grid-columns": cols };
@@ -6423,7 +6618,7 @@ ShuffleMCP.displayName = "ShuffleMCP";
6423
6618
  var ShuffleMCP_default = ShuffleMCP;
6424
6619
 
6425
6620
  // AppSearchDrawer.tsx
6426
- var import_react12 = require("react");
6621
+ var import_react13 = require("react");
6427
6622
  var import_lucide_react7 = require("lucide-react");
6428
6623
  var import_material11 = require("@mui/material");
6429
6624
  var import_framer_motion8 = require("framer-motion");
@@ -6528,10 +6723,10 @@ function AppSearchDrawer({
6528
6723
  selectedApps,
6529
6724
  onSelectionChange
6530
6725
  }) {
6531
- const [detailAppName, setDetailAppName] = (0, import_react12.useState)(null);
6532
- const [detailAppId, setDetailAppId] = (0, import_react12.useState)(null);
6533
- const [highlightActive, setHighlightActive] = (0, import_react12.useState)(false);
6534
- (0, import_react12.useEffect)(() => {
6726
+ const [detailAppName, setDetailAppName] = (0, import_react13.useState)(null);
6727
+ const [detailAppId, setDetailAppId] = (0, import_react13.useState)(null);
6728
+ const [highlightActive, setHighlightActive] = (0, import_react13.useState)(false);
6729
+ (0, import_react13.useEffect)(() => {
6535
6730
  setHighlightActive(false);
6536
6731
  if (!open || !highlightAppName) return;
6537
6732
  const t = setTimeout(() => setHighlightActive(true), highlightDelayMs);
@@ -7093,7 +7288,7 @@ function ShufflePipelinesBanner() {
7093
7288
  var ShufflePipelinesBanner_default = ShufflePipelinesBanner;
7094
7289
 
7095
7290
  // AgentUI.tsx
7096
- var import_react14 = require("react");
7291
+ var import_react15 = require("react");
7097
7292
  var import_lucide_react11 = require("lucide-react");
7098
7293
  var import_react_router_dom2 = require("react-router-dom");
7099
7294
  var import_material16 = require("@mui/material");
@@ -7737,7 +7932,7 @@ var AgentDiagnosisCtas = ({ diagnosis, compact = false, tone = "medium" }) => {
7737
7932
  var AgentDiagnosisCtas_default = AgentDiagnosisCtas;
7738
7933
 
7739
7934
  // AgentRunDiagnosisBanner.tsx
7740
- var import_react13 = require("react");
7935
+ var import_react14 = require("react");
7741
7936
 
7742
7937
  // agentDiagnosis.ts
7743
7938
  var deepParseJsonStrings2 = (obj, depth = 0) => {
@@ -8114,13 +8309,13 @@ var writeDismissed = (key) => {
8114
8309
  }
8115
8310
  };
8116
8311
  var AgentRunDiagnosisBanner = ({ run, sx, onJumpToEvidence, executionId }) => {
8117
- const dismissKey = (0, import_react13.useMemo)(() => {
8312
+ const dismissKey = (0, import_react14.useMemo)(() => {
8118
8313
  if (executionId) return executionId;
8119
8314
  const fromRun = run?.execution_id;
8120
8315
  return typeof fromRun === "string" && fromRun ? fromRun : null;
8121
8316
  }, [executionId, run]);
8122
- const [dismissed, setDismissed] = (0, import_react13.useState)(() => readDismissed(dismissKey));
8123
- (0, import_react13.useEffect)(() => {
8317
+ const [dismissed, setDismissed] = (0, import_react14.useState)(() => readDismissed(dismissKey));
8318
+ (0, import_react14.useEffect)(() => {
8124
8319
  setDismissed(readDismissed(dismissKey));
8125
8320
  }, [dismissKey]);
8126
8321
  if (!run || dismissed) return null;
@@ -8399,7 +8594,7 @@ var TimelineRow = ({
8399
8594
  isAppAuthenticated,
8400
8595
  highlight = false
8401
8596
  }) => {
8402
- const [submitAttempted, setSubmitAttempted] = (0, import_react14.useState)(false);
8597
+ const [submitAttempted, setSubmitAttempted] = (0, import_react15.useState)(false);
8403
8598
  const validate = validateJson(item.details);
8404
8599
  const itemStart = item.start_time || 0;
8405
8600
  const itemEnd = item.end_time || itemStart;
@@ -8833,70 +9028,70 @@ var AgentUI = ({
8833
9028
  sx,
8834
9029
  contentSx
8835
9030
  }) => {
8836
- const resolveUrl2 = (0, import_react14.useCallback)(
9031
+ const resolveUrl2 = (0, import_react15.useCallback)(
8837
9032
  (path) => apiBaseUrl ? `${apiBaseUrl.replace(/\/+$/, "")}${path}` : getApiUrl(path),
8838
9033
  [apiBaseUrl]
8839
9034
  );
8840
- const resolveHeaders2 = (0, import_react14.useCallback)(() => {
9035
+ const resolveHeaders2 = (0, import_react15.useCallback)(() => {
8841
9036
  const h = apiKey ? { Authorization: `Bearer ${apiKey}` } : { ...getAuthHeader() };
8842
9037
  if (orgId) h["Org-Id"] = orgId;
8843
9038
  return h;
8844
9039
  }, [apiKey, orgId]);
8845
9040
  const hasApiKey = !!apiKey || !!API_CONFIG.apiKey;
8846
9041
  const navigate = (0, import_react_router_dom2.useNavigate)();
8847
- const [actionInput, setActionInput] = (0, import_react14.useState)(defaultInput);
9042
+ const [actionInput, setActionInput] = (0, import_react15.useState)(defaultInput);
8848
9043
  const BUILTIN_DEFAULT_APPS = [
8849
9044
  { name: "http" },
8850
9045
  { name: "shuffle_tools" }
8851
9046
  ];
8852
- const [chosenApps, setChosenApps] = (0, import_react14.useState)(apps ?? defaultApps ?? BUILTIN_DEFAULT_APPS);
8853
- const [availableApps, setAvailableApps] = (0, import_react14.useState)([]);
8854
- const [executionApps, setExecutionApps] = (0, import_react14.useState)([]);
8855
- const [resolvedToolApps, setResolvedToolApps] = (0, import_react14.useState)({});
8856
- const [appSearchOpen, setAppSearchOpen] = (0, import_react14.useState)(false);
8857
- const [authDrawerApp, setAuthDrawerApp] = (0, import_react14.useState)(null);
8858
- const [agentRequestLoading, setAgentRequestLoading] = (0, import_react14.useState)(false);
8859
- const [execution, setExecution] = (0, import_react14.useState)(null);
8860
- const [agentData, setAgentData] = (0, import_react14.useState)({});
8861
- const [agentActionResult, setAgentActionResult] = (0, import_react14.useState)(null);
8862
- const [showStarter, setShowStarter] = (0, import_react14.useState)(true);
8863
- const [scheduleAnchor, setScheduleAnchor] = (0, import_react14.useState)(null);
8864
- const [scheduleCron, setScheduleCron] = (0, import_react14.useState)("0 * * * *");
8865
- const [scheduleSaving, setScheduleSaving] = (0, import_react14.useState)(false);
8866
- const [scheduleSteps, setScheduleSteps] = (0, import_react14.useState)([
9047
+ const [chosenApps, setChosenApps] = (0, import_react15.useState)(apps ?? defaultApps ?? BUILTIN_DEFAULT_APPS);
9048
+ const [availableApps, setAvailableApps] = (0, import_react15.useState)([]);
9049
+ const [executionApps, setExecutionApps] = (0, import_react15.useState)([]);
9050
+ const [resolvedToolApps, setResolvedToolApps] = (0, import_react15.useState)({});
9051
+ const [appSearchOpen, setAppSearchOpen] = (0, import_react15.useState)(false);
9052
+ const [authDrawerApp, setAuthDrawerApp] = (0, import_react15.useState)(null);
9053
+ const [agentRequestLoading, setAgentRequestLoading] = (0, import_react15.useState)(false);
9054
+ const [execution, setExecution] = (0, import_react15.useState)(null);
9055
+ const [agentData, setAgentData] = (0, import_react15.useState)({});
9056
+ const [agentActionResult, setAgentActionResult] = (0, import_react15.useState)(null);
9057
+ const [showStarter, setShowStarter] = (0, import_react15.useState)(true);
9058
+ const [scheduleAnchor, setScheduleAnchor] = (0, import_react15.useState)(null);
9059
+ const [scheduleCron, setScheduleCron] = (0, import_react15.useState)("0 * * * *");
9060
+ const [scheduleSaving, setScheduleSaving] = (0, import_react15.useState)(false);
9061
+ const [scheduleSteps, setScheduleSteps] = (0, import_react15.useState)([
8867
9062
  { id: "name", state: "pending" },
8868
9063
  { id: "workflow", state: "pending" },
8869
9064
  { id: "schedule", state: "pending" }
8870
9065
  ]);
8871
- const [schedFreq, setSchedFreq] = (0, import_react14.useState)("hours");
8872
- const [schedInterval, setSchedInterval] = (0, import_react14.useState)(1);
8873
- const [schedHour, setSchedHour] = (0, import_react14.useState)(9);
8874
- const [schedMinute, setSchedMinute] = (0, import_react14.useState)(0);
8875
- const [schedWeekdays, setSchedWeekdays] = (0, import_react14.useState)(() => /* @__PURE__ */ new Set([1]));
8876
- const [schedDayOfMonth, setSchedDayOfMonth] = (0, import_react14.useState)(1);
8877
- const [schedAdvancedOpen, setSchedAdvancedOpen] = (0, import_react14.useState)(false);
8878
- const cronManualOverrideRef = (0, import_react14.useRef)(false);
8879
- const [openIndexes, setOpenIndexes] = (0, import_react14.useState)(/* @__PURE__ */ new Set());
8880
- const [highlightedIndex, setHighlightedIndex] = (0, import_react14.useState)(null);
8881
- const [questionAnswers, setQuestionAnswers] = (0, import_react14.useState)({});
8882
- const [simpleSubmitAttempted, setSimpleSubmitAttempted] = (0, import_react14.useState)(false);
8883
- const [continuationText, setContinuationText] = (0, import_react14.useState)("");
8884
- const [error, setError] = (0, import_react14.useState)(null);
9066
+ const [schedFreq, setSchedFreq] = (0, import_react15.useState)("hours");
9067
+ const [schedInterval, setSchedInterval] = (0, import_react15.useState)(1);
9068
+ const [schedHour, setSchedHour] = (0, import_react15.useState)(9);
9069
+ const [schedMinute, setSchedMinute] = (0, import_react15.useState)(0);
9070
+ const [schedWeekdays, setSchedWeekdays] = (0, import_react15.useState)(() => /* @__PURE__ */ new Set([1]));
9071
+ const [schedDayOfMonth, setSchedDayOfMonth] = (0, import_react15.useState)(1);
9072
+ const [schedAdvancedOpen, setSchedAdvancedOpen] = (0, import_react15.useState)(false);
9073
+ const cronManualOverrideRef = (0, import_react15.useRef)(false);
9074
+ const [openIndexes, setOpenIndexes] = (0, import_react15.useState)(/* @__PURE__ */ new Set());
9075
+ const [highlightedIndex, setHighlightedIndex] = (0, import_react15.useState)(null);
9076
+ const [questionAnswers, setQuestionAnswers] = (0, import_react15.useState)({});
9077
+ const [simpleSubmitAttempted, setSimpleSubmitAttempted] = (0, import_react15.useState)(false);
9078
+ const [continuationText, setContinuationText] = (0, import_react15.useState)("");
9079
+ const [error, setError] = (0, import_react15.useState)(null);
8885
9080
  const [searchParams, setSearchParams] = (0, import_react_router_dom2.useSearchParams)();
8886
9081
  const initialViewParam = searchParams.get("agentView");
8887
- const [viewMode, setViewMode] = (0, import_react14.useState)(
9082
+ const [viewMode, setViewMode] = (0, import_react15.useState)(
8888
9083
  initialViewParam === "detailed" ? "detailed" : "simple"
8889
9084
  );
8890
- const [attachedImages, setAttachedImages] = (0, import_react14.useState)([]);
8891
- const [nowTick, setNowTick] = (0, import_react14.useState)(() => Math.floor(Date.now() / 1e3));
8892
- const [localRunStart, setLocalRunStart] = (0, import_react14.useState)(null);
8893
- const inputRef = (0, import_react14.useRef)(null);
8894
- const fileInputRef = (0, import_react14.useRef)(null);
8895
- const activeExecutionIdRef = (0, import_react14.useRef)(null);
8896
- const runAbortRef = (0, import_react14.useRef)(null);
8897
- const runGenerationRef = (0, import_react14.useRef)(0);
8898
- const userPickedStartRef = (0, import_react14.useRef)(false);
8899
- const stateRef = (0, import_react14.useRef)({
9085
+ const [attachedImages, setAttachedImages] = (0, import_react15.useState)([]);
9086
+ const [nowTick, setNowTick] = (0, import_react15.useState)(() => Math.floor(Date.now() / 1e3));
9087
+ const [localRunStart, setLocalRunStart] = (0, import_react15.useState)(null);
9088
+ const inputRef = (0, import_react15.useRef)(null);
9089
+ const fileInputRef = (0, import_react15.useRef)(null);
9090
+ const activeExecutionIdRef = (0, import_react15.useRef)(null);
9091
+ const runAbortRef = (0, import_react15.useRef)(null);
9092
+ const runGenerationRef = (0, import_react15.useRef)(0);
9093
+ const userPickedStartRef = (0, import_react15.useRef)(false);
9094
+ const stateRef = (0, import_react15.useRef)({
8900
9095
  execution: null,
8901
9096
  agentData: {},
8902
9097
  agentActionResult: null,
@@ -8914,14 +9109,14 @@ var AgentUI = ({
8914
9109
  stateRef.current.continuationText = continuationText;
8915
9110
  stateRef.current.localRunStart = localRunStart;
8916
9111
  stateRef.current.showStarter = showStarter;
8917
- (0, import_react14.useEffect)(() => {
9112
+ (0, import_react15.useEffect)(() => {
8918
9113
  if (execution?.execution_id || agentRequestLoading) {
8919
9114
  setLocalRunStart((prev) => prev ?? Math.floor(Date.now() / 1e3));
8920
9115
  } else {
8921
9116
  setLocalRunStart(null);
8922
9117
  }
8923
9118
  }, [execution?.execution_id, agentRequestLoading]);
8924
- (0, import_react14.useEffect)(() => {
9119
+ (0, import_react15.useEffect)(() => {
8925
9120
  const status = (execution?.status || agentData?.status || "").toUpperCase();
8926
9121
  const TERMINAL = ["FINISHED", "FAILURE", "ABORTED", "CANCELLED", "CANCELED"];
8927
9122
  if (TERMINAL.includes(status)) return;
@@ -8953,7 +9148,7 @@ var AgentUI = ({
8953
9148
  setError(null);
8954
9149
  }
8955
9150
  };
8956
- const appsById = (0, import_react14.useMemo)(() => {
9151
+ const appsById = (0, import_react15.useMemo)(() => {
8957
9152
  const m = {};
8958
9153
  const add = (a) => {
8959
9154
  if (!a?.name) return;
@@ -8971,13 +9166,13 @@ var AgentUI = ({
8971
9166
  }
8972
9167
  return m;
8973
9168
  }, [chosenApps, executionApps, resolvedToolApps]);
8974
- const isAppAuthenticated = (0, import_react14.useCallback)((appName) => {
9169
+ const isAppAuthenticated = (0, import_react15.useCallback)((appName) => {
8975
9170
  if (!appName) return false;
8976
9171
  const norm4 = (s) => s.toLowerCase().replace(/[\s-]+/g, "_");
8977
9172
  const target = norm4(appName);
8978
9173
  return availableApps.some((a) => norm4(a.name || "") === target);
8979
9174
  }, [availableApps]);
8980
- const pendingAuthApps = (0, import_react14.useMemo)(() => {
9175
+ const pendingAuthApps = (0, import_react15.useMemo)(() => {
8981
9176
  const decisions = agentData?.decisions || [];
8982
9177
  const seen = /* @__PURE__ */ new Set();
8983
9178
  const out = [];
@@ -8994,10 +9189,10 @@ var AgentUI = ({
8994
9189
  }
8995
9190
  return out;
8996
9191
  }, [agentData, appsById, isAppAuthenticated]);
8997
- (0, import_react14.useEffect)(() => {
9192
+ (0, import_react15.useEffect)(() => {
8998
9193
  if (apps) setChosenApps(apps);
8999
9194
  }, [apps]);
9000
- (0, import_react14.useEffect)(() => {
9195
+ (0, import_react15.useEffect)(() => {
9001
9196
  const decisions = agentData?.decisions || [];
9002
9197
  if (!Array.isArray(decisions) || decisions.length === 0) return;
9003
9198
  const norm4 = (s) => s.toLowerCase().replace(/[\s-]+/g, "_");
@@ -9045,7 +9240,7 @@ var AgentUI = ({
9045
9240
  cancelled = true;
9046
9241
  };
9047
9242
  }, [JSON.stringify(agentData?.decisions?.map((d) => [d?.details?.tool || d?.tool, extractAuthRequest(d)?.appName]) || []), appsById]);
9048
- (0, import_react14.useEffect)(() => {
9243
+ (0, import_react15.useEffect)(() => {
9049
9244
  const missing = chosenApps.filter((a) => !a.icon && a.name);
9050
9245
  if (missing.length === 0) return;
9051
9246
  let cancelled = false;
@@ -9103,7 +9298,7 @@ var AgentUI = ({
9103
9298
  cancelled = true;
9104
9299
  };
9105
9300
  }, [chosenApps, availableApps, resolveUrl2, resolveHeaders2]);
9106
- (0, import_react14.useEffect)(() => {
9301
+ (0, import_react15.useEffect)(() => {
9107
9302
  if (!autoLoadApps) return;
9108
9303
  if (apps || defaultApps) return;
9109
9304
  if (!hasApiKey) return;
@@ -9142,7 +9337,7 @@ var AgentUI = ({
9142
9337
  cancelled = true;
9143
9338
  };
9144
9339
  }, [autoLoadApps, apps, defaultApps, hasApiKey, resolveUrl2, resolveHeaders2]);
9145
- (0, import_react14.useEffect)(() => {
9340
+ (0, import_react15.useEffect)(() => {
9146
9341
  const raw = agentData?.allowed_actions;
9147
9342
  if (!Array.isArray(raw) || raw.length === 0) {
9148
9343
  setExecutionApps([]);
@@ -9251,7 +9446,7 @@ var AgentUI = ({
9251
9446
  cancelled = true;
9252
9447
  };
9253
9448
  }, [JSON.stringify(agentData?.allowed_actions || []), availableApps]);
9254
- const getExecution = (0, import_react14.useCallback)(async (executionId2, authorization2) => {
9449
+ const getExecution = (0, import_react15.useCallback)(async (executionId2, authorization2) => {
9255
9450
  if (!executionId2 || !authorization2) return;
9256
9451
  try {
9257
9452
  const resp = await fetch(resolveUrl2("/api/v1/streams/results"), {
@@ -9286,7 +9481,7 @@ var AgentUI = ({
9286
9481
  setError(err instanceof Error ? err.message : "Network error.");
9287
9482
  }
9288
9483
  }, []);
9289
- (0, import_react14.useEffect)(() => {
9484
+ (0, import_react15.useEffect)(() => {
9290
9485
  let eid = null;
9291
9486
  let auth = null;
9292
9487
  if (executionId && authorization) {
@@ -9304,7 +9499,7 @@ var AgentUI = ({
9304
9499
  getExecution(eid, auth);
9305
9500
  }
9306
9501
  }, [readUrlParams, executionId, authorization, getExecution]);
9307
- (0, import_react14.useEffect)(() => {
9502
+ (0, import_react15.useEffect)(() => {
9308
9503
  if (!initialExecution || !initialExecution.execution_id) return;
9309
9504
  if (!userPickedStartRef.current) setShowStarter(false);
9310
9505
  activeExecutionIdRef.current = initialExecution.execution_id;
@@ -9337,7 +9532,7 @@ var AgentUI = ({
9337
9532
  getExecution(initialExecution.execution_id, initialExecution.authorization);
9338
9533
  }
9339
9534
  }, [initialExecution?.execution_id]);
9340
- (0, import_react14.useEffect)(() => {
9535
+ (0, import_react15.useEffect)(() => {
9341
9536
  if (!execution?.execution_id || !execution?.authorization) return;
9342
9537
  const status = (execution.status || "").toUpperCase();
9343
9538
  const TERMINAL = ["FINISHED", "FAILURE", "ABORTED", "CANCELLED", "CANCELED"];
@@ -9347,7 +9542,7 @@ var AgentUI = ({
9347
9542
  }, 3e3);
9348
9543
  return () => clearInterval(id);
9349
9544
  }, [execution?.execution_id, execution?.authorization, execution?.status, getExecution]);
9350
- const submitInput = (0, import_react14.useCallback)(async (text) => {
9545
+ const submitInput = (0, import_react15.useCallback)(async (text) => {
9351
9546
  if (!text.trim()) return;
9352
9547
  setError(null);
9353
9548
  setAgentRequestLoading(true);
@@ -9483,14 +9678,14 @@ var AgentUI = ({
9483
9678
  onRun?.({ input: text, success: true, executionId: eid });
9484
9679
  }
9485
9680
  }, [chosenApps, getExecution, onRun, attachedImages, readUrlParams, viewMode]);
9486
- const autoSubmittedRef = (0, import_react14.useRef)(false);
9487
- (0, import_react14.useEffect)(() => {
9681
+ const autoSubmittedRef = (0, import_react15.useRef)(false);
9682
+ (0, import_react15.useEffect)(() => {
9488
9683
  if (autoSubmit && defaultInput && !autoSubmittedRef.current && !executionId) {
9489
9684
  autoSubmittedRef.current = true;
9490
9685
  submitInput(defaultInput);
9491
9686
  }
9492
9687
  }, [autoSubmit, defaultInput, executionId, submitInput]);
9493
- const submitQuestions = (0, import_react14.useCallback)(async (decisionId, answers, isContinuation) => {
9688
+ const submitQuestions = (0, import_react15.useCallback)(async (decisionId, answers, isContinuation) => {
9494
9689
  if (!execution?.execution_id || !execution?.authorization) return;
9495
9690
  let newArgument = {};
9496
9691
  if (isContinuation) {
@@ -9537,7 +9732,7 @@ var AgentUI = ({
9537
9732
  setAgentRequestLoading(false);
9538
9733
  }
9539
9734
  }, [execution, getExecution]);
9540
- const rerunAgent = (0, import_react14.useCallback)(() => {
9735
+ const rerunAgent = (0, import_react15.useCallback)(() => {
9541
9736
  const input = agentData?.original_input || actionInput || (() => {
9542
9737
  const msgs = agentData?.input?.messages || [];
9543
9738
  const m = msgs.find((m2) => m2?.role === "user" && !String(m2?.role).includes("USER CONTEXT"));
@@ -9562,7 +9757,7 @@ var AgentUI = ({
9562
9757
  return next;
9563
9758
  }, { replace: true });
9564
9759
  }, [agentData, actionInput, executionApps, setSearchParams, disableStartTab, submitInput]);
9565
- const abortAgent = (0, import_react14.useCallback)(async () => {
9760
+ const abortAgent = (0, import_react15.useCallback)(async () => {
9566
9761
  const execId = execution?.execution_id;
9567
9762
  const auth = execution?.authorization;
9568
9763
  const wfId = execution?.workflow?.id;
@@ -9615,7 +9810,7 @@ var AgentUI = ({
9615
9810
  toast({ title: "Network error", description: String(err), variant: "destructive" });
9616
9811
  }
9617
9812
  }, [execution, resolveUrl2, resolveHeaders2, getExecution, setSearchParams]);
9618
- const getFormUrl = (0, import_react14.useCallback)((decisionId) => {
9813
+ const getFormUrl = (0, import_react15.useCallback)((decisionId) => {
9619
9814
  const wfId = execution?.workflow?.id;
9620
9815
  const auth = execution?.authorization;
9621
9816
  const execId = execution?.execution_id;
@@ -9631,7 +9826,7 @@ var AgentUI = ({
9631
9826
  });
9632
9827
  return `/forms/${wfId}?${params.toString()}`;
9633
9828
  }, [execution, agentActionResult, apiBaseUrl]);
9634
- const rerunDecision = (0, import_react14.useCallback)(async (decision) => {
9829
+ const rerunDecision = (0, import_react15.useCallback)(async (decision) => {
9635
9830
  if (!execution?.execution_id) {
9636
9831
  toast({ title: "No execution loaded", description: "Cannot rerun this decision.", variant: "destructive" });
9637
9832
  return;
@@ -9670,7 +9865,7 @@ var AgentUI = ({
9670
9865
  setAgentRequestLoading(false);
9671
9866
  }
9672
9867
  }, [execution, agentActionResult, getExecution]);
9673
- const { timeline, originalStartTime, totalDuration, finishDecisionId, finishAnswer } = (0, import_react14.useMemo)(() => {
9868
+ const { timeline, originalStartTime, totalDuration, finishDecisionId, finishAnswer } = (0, import_react15.useMemo)(() => {
9674
9869
  const toSec = (t) => {
9675
9870
  const n = Number(t) || 0;
9676
9871
  return n > 1e12 ? n / 1e3 : n;
@@ -9792,7 +9987,7 @@ var AgentUI = ({
9792
9987
  else next.add(i);
9793
9988
  return next;
9794
9989
  });
9795
- const handlePrimarySubmit = (0, import_react14.useCallback)(() => {
9990
+ const handlePrimarySubmit = (0, import_react15.useCallback)(() => {
9796
9991
  if (submitOverride) {
9797
9992
  submitOverride({ input: actionInput, apps: chosenApps });
9798
9993
  } else {
@@ -9808,7 +10003,7 @@ var AgentUI = ({
9808
10003
  const activeTab = showStarter ? "start" : viewMode;
9809
10004
  const hasExecution = !!execution?.execution_id;
9810
10005
  const showRunSwitcher = hasExecution || agentRequestLoading;
9811
- (0, import_react14.useEffect)(() => {
10006
+ (0, import_react15.useEffect)(() => {
9812
10007
  onViewChange?.(activeTab);
9813
10008
  }, [activeTab, onViewChange]);
9814
10009
  const goToTab = (t) => {
@@ -9842,7 +10037,7 @@ var AgentUI = ({
9842
10037
  }, { replace: true });
9843
10038
  }
9844
10039
  };
9845
- const { scheduleDisabledReasons } = (0, import_react14.useMemo)(() => {
10040
+ const { scheduleDisabledReasons } = (0, import_react15.useMemo)(() => {
9846
10041
  const decisions = agentData?.decisions || [];
9847
10042
  const runStatus = String(execution?.status || agentData?.status || "").toUpperCase();
9848
10043
  const isNotFinished = runStatus !== "" && !["FINISHED", "FAILURE", "ABORTED", "CANCELLED", "CANCELED"].includes(runStatus);
@@ -9912,16 +10107,16 @@ var AgentUI = ({
9912
10107
  }
9913
10108
  return { scheduleDisabledReasons: reasons };
9914
10109
  }, [agentData, execution?.status, showStarter]);
9915
- const scheduleHint = (0, import_react14.useMemo)(() => parseScheduleHint(actionInput), [actionInput]);
9916
- const lastAppliedHintRef = (0, import_react14.useRef)(null);
9917
- (0, import_react14.useEffect)(() => {
10110
+ const scheduleHint = (0, import_react15.useMemo)(() => parseScheduleHint(actionInput), [actionInput]);
10111
+ const lastAppliedHintRef = (0, import_react15.useRef)(null);
10112
+ (0, import_react15.useEffect)(() => {
9918
10113
  if (!scheduleHint) return;
9919
10114
  if (scheduleAnchor) return;
9920
10115
  if (lastAppliedHintRef.current === scheduleHint.cron) return;
9921
10116
  setScheduleCron(scheduleHint.cron);
9922
10117
  lastAppliedHintRef.current = scheduleHint.cron;
9923
10118
  }, [scheduleHint, scheduleAnchor]);
9924
- (0, import_react14.useEffect)(() => {
10119
+ (0, import_react15.useEffect)(() => {
9925
10120
  if (cronManualOverrideRef.current) return;
9926
10121
  const m = Math.max(0, Math.min(59, schedMinute));
9927
10122
  const h = Math.max(0, Math.min(23, schedHour));
@@ -9957,7 +10152,7 @@ var AgentUI = ({
9957
10152
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_material16.Box, { component: "span", children: r })
9958
10153
  ] }, i)) })
9959
10154
  ] }) : scheduleDisabledReasons.length === 1 ? `Cannot schedule: ${scheduleDisabledReasons[0]}` : "";
9960
- const tabBarRef = (0, import_react14.useRef)(null);
10155
+ const tabBarRef = (0, import_react15.useRef)(null);
9961
10156
  const tabBar = /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
9962
10157
  import_material16.Box,
9963
10158
  {
@@ -11403,7 +11598,7 @@ var AgentUI = ({
11403
11598
  var AgentUI_default = AgentUI;
11404
11599
 
11405
11600
  // AgentRunDrawer.tsx
11406
- var import_react15 = require("react");
11601
+ var import_react16 = require("react");
11407
11602
  var import_material17 = require("@mui/material");
11408
11603
  var import_lucide_react12 = require("lucide-react");
11409
11604
  var import_jsx_runtime21 = require("react/jsx-runtime");
@@ -11425,11 +11620,13 @@ var AgentRunDrawer = ({
11425
11620
  paperSx,
11426
11621
  headerSx,
11427
11622
  tabsSx,
11428
- bodySx
11623
+ bodySx,
11624
+ globalUrl
11429
11625
  }) => {
11430
- const [activeTab, setActiveTab] = (0, import_react15.useState)(initialTab);
11431
- const prevOpenRef = (0, import_react15.useRef)(open);
11432
- (0, import_react15.useEffect)(() => {
11626
+ useSyncHostBaseUrl(globalUrl);
11627
+ const [activeTab, setActiveTab] = (0, import_react16.useState)(initialTab);
11628
+ const prevOpenRef = (0, import_react16.useRef)(open);
11629
+ (0, import_react16.useEffect)(() => {
11433
11630
  if (open && !prevOpenRef.current) setActiveTab(initialTab);
11434
11631
  prevOpenRef.current = open;
11435
11632
  }, [open, initialTab]);
@@ -11572,6 +11769,7 @@ var AgentRunDrawer = ({
11572
11769
  hideHeroIcon: true,
11573
11770
  title: "",
11574
11771
  subtitle: null,
11772
+ apiBaseUrl: globalUrl,
11575
11773
  ...agentUIProps
11576
11774
  }
11577
11775
  ) }),
@@ -11585,7 +11783,7 @@ var AgentRunDrawer = ({
11585
11783
  var AgentRunDrawer_default = AgentRunDrawer;
11586
11784
 
11587
11785
  // AgentActivityList.tsx
11588
- var import_react16 = require("react");
11786
+ var import_react17 = require("react");
11589
11787
  var import_material18 = require("@mui/material");
11590
11788
  var import_lucide_react13 = require("lucide-react");
11591
11789
 
@@ -12006,21 +12204,21 @@ var AgentActivityList = ({
12006
12204
  toolbarSx,
12007
12205
  rowSx
12008
12206
  }) => {
12009
- const [runs, setRuns] = (0, import_react16.useState)([]);
12010
- const [cursor, setCursor] = (0, import_react16.useState)("");
12011
- const [hasMore, setHasMore] = (0, import_react16.useState)(false);
12012
- const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
12013
- const [error, setError] = (0, import_react16.useState)(null);
12014
- const [statusFilter, setStatusFilter] = (0, import_react16.useState)("");
12015
- const [searchQuery, setSearchQuery] = (0, import_react16.useState)("");
12016
- const [debouncedQuery, setDebouncedQuery] = (0, import_react16.useState)("");
12017
- const [agentWorkflows, setAgentWorkflows] = (0, import_react16.useState)([]);
12018
- const [workflowFilter, setWorkflowFilter] = (0, import_react16.useState)("");
12019
- const [stopOpen, setStopOpen] = (0, import_react16.useState)(false);
12020
- const [stopLoading, setStopLoading] = (0, import_react16.useState)(false);
12021
- const debounceRef = (0, import_react16.useRef)();
12207
+ const [runs, setRuns] = (0, import_react17.useState)([]);
12208
+ const [cursor, setCursor] = (0, import_react17.useState)("");
12209
+ const [hasMore, setHasMore] = (0, import_react17.useState)(false);
12210
+ const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
12211
+ const [error, setError] = (0, import_react17.useState)(null);
12212
+ const [statusFilter, setStatusFilter] = (0, import_react17.useState)("");
12213
+ const [searchQuery, setSearchQuery] = (0, import_react17.useState)("");
12214
+ const [debouncedQuery, setDebouncedQuery] = (0, import_react17.useState)("");
12215
+ const [agentWorkflows, setAgentWorkflows] = (0, import_react17.useState)([]);
12216
+ const [workflowFilter, setWorkflowFilter] = (0, import_react17.useState)("");
12217
+ const [stopOpen, setStopOpen] = (0, import_react17.useState)(false);
12218
+ const [stopLoading, setStopLoading] = (0, import_react17.useState)(false);
12219
+ const debounceRef = (0, import_react17.useRef)();
12022
12220
  const selectedAgentWorkflow = agentWorkflows.find((w) => w.id === workflowFilter) || null;
12023
- const openEditPrompt = (0, import_react16.useCallback)(async () => {
12221
+ const openEditPrompt = (0, import_react17.useCallback)(async () => {
12024
12222
  if (!workflowFilter) return;
12025
12223
  try {
12026
12224
  const { prompt, apps } = await getAgentScheduleConfig(workflowFilter, { apiKey, apiBaseUrl, orgId });
@@ -12034,7 +12232,7 @@ var AgentActivityList = ({
12034
12232
  setError(e instanceof Error ? e.message : "Failed to load workflow");
12035
12233
  }
12036
12234
  }, [workflowFilter, selectedAgentWorkflow, apiKey, apiBaseUrl, orgId, onEditWorkflow]);
12037
- const confirmStop = (0, import_react16.useCallback)(async () => {
12235
+ const confirmStop = (0, import_react17.useCallback)(async () => {
12038
12236
  if (!workflowFilter) return;
12039
12237
  setStopLoading(true);
12040
12238
  try {
@@ -12049,15 +12247,15 @@ var AgentActivityList = ({
12049
12247
  setStopLoading(false);
12050
12248
  }
12051
12249
  }, [workflowFilter, apiKey, apiBaseUrl, orgId]);
12052
- const updateSearchQuery = (0, import_react16.useCallback)((q) => {
12250
+ const updateSearchQuery = (0, import_react17.useCallback)((q) => {
12053
12251
  setSearchQuery(q);
12054
12252
  if (debounceRef.current) clearTimeout(debounceRef.current);
12055
12253
  debounceRef.current = setTimeout(() => setDebouncedQuery(q), 350);
12056
12254
  }, []);
12057
- (0, import_react16.useEffect)(() => () => {
12255
+ (0, import_react17.useEffect)(() => () => {
12058
12256
  if (debounceRef.current) clearTimeout(debounceRef.current);
12059
12257
  }, []);
12060
- const fetchRuns = (0, import_react16.useCallback)(
12258
+ const fetchRuns = (0, import_react17.useCallback)(
12061
12259
  async (append = false, cursorParam = "") => {
12062
12260
  setIsLoading(true);
12063
12261
  setError(null);
@@ -12086,10 +12284,10 @@ var AgentActivityList = ({
12086
12284
  },
12087
12285
  [statusFilter, limit, apiKey, apiBaseUrl, orgId, workflowFilter]
12088
12286
  );
12089
- (0, import_react16.useEffect)(() => {
12287
+ (0, import_react17.useEffect)(() => {
12090
12288
  fetchRuns(false, "");
12091
12289
  }, [statusFilter, apiKey, apiBaseUrl, orgId, workflowFilter]);
12092
- (0, import_react16.useEffect)(() => {
12290
+ (0, import_react17.useEffect)(() => {
12093
12291
  let cancelled = false;
12094
12292
  listAgentScheduleWorkflows({ apiKey, apiBaseUrl, orgId }).then((items) => {
12095
12293
  if (!cancelled) setAgentWorkflows(items);
@@ -12099,7 +12297,7 @@ var AgentActivityList = ({
12099
12297
  cancelled = true;
12100
12298
  };
12101
12299
  }, [apiKey, apiBaseUrl, orgId]);
12102
- const loadMore = (0, import_react16.useCallback)(() => {
12300
+ const loadMore = (0, import_react17.useCallback)(() => {
12103
12301
  if (cursor && !isLoading) fetchRuns(true, cursor);
12104
12302
  }, [cursor, isLoading, fetchRuns]);
12105
12303
  const filteredRuns = debouncedQuery ? runs.filter((r) => {
@@ -12533,19 +12731,20 @@ var AgentExecutionDrawer = ({
12533
12731
  var AgentExecutionDrawer_default = AgentExecutionDrawer;
12534
12732
 
12535
12733
  // AgentsView.tsx
12536
- var import_react17 = require("react");
12734
+ var import_react18 = require("react");
12537
12735
  var import_material20 = require("@mui/material");
12538
12736
  var import_jsx_runtime24 = require("react/jsx-runtime");
12539
- var AgentsView = ({ onSchedule, maxWidth = 820 }) => {
12540
- const [selectedRun, setSelectedRun] = (0, import_react17.useState)(null);
12541
- const [agentView, setAgentView] = (0, import_react17.useState)("start");
12542
- const [prefill, setPrefill] = (0, import_react17.useState)({
12737
+ var AgentsView = ({ onSchedule, maxWidth = 820, globalUrl, isLoaded, isLoggedIn, userdata, serverside }) => {
12738
+ useSyncHostBaseUrl(globalUrl);
12739
+ const [selectedRun, setSelectedRun] = (0, import_react18.useState)(null);
12740
+ const [agentView, setAgentView] = (0, import_react18.useState)("start");
12741
+ const [prefill, setPrefill] = (0, import_react18.useState)({
12543
12742
  input: "",
12544
12743
  apps: [],
12545
12744
  key: 0
12546
12745
  });
12547
- const [editing, setEditing] = (0, import_react17.useState)(null);
12548
- const handleEditWorkflow = (0, import_react17.useCallback)(
12746
+ const [editing, setEditing] = (0, import_react18.useState)(null);
12747
+ const handleEditWorkflow = (0, import_react18.useCallback)(
12549
12748
  ({ workflowId, name, prompt, apps }) => {
12550
12749
  setEditing({ workflowId, name });
12551
12750
  setPrefill((prev) => ({
@@ -12557,7 +12756,7 @@ var AgentsView = ({ onSchedule, maxWidth = 820 }) => {
12557
12756
  },
12558
12757
  []
12559
12758
  );
12560
- const handleSaveEdit = (0, import_react17.useCallback)(
12759
+ const handleSaveEdit = (0, import_react18.useCallback)(
12561
12760
  async ({ input, apps }) => {
12562
12761
  if (!editing) return;
12563
12762
  try {
@@ -12622,6 +12821,7 @@ var AgentsView = ({ onSchedule, maxWidth = 820 }) => {
12622
12821
  AgentUI_default,
12623
12822
  {
12624
12823
  maxWidth,
12824
+ apiBaseUrl: globalUrl,
12625
12825
  onViewChange: setAgentView,
12626
12826
  onSchedule,
12627
12827
  defaultInput: prefill.input,
@@ -12637,6 +12837,7 @@ var AgentsView = ({ onSchedule, maxWidth = 820 }) => {
12637
12837
  agentView === "start" && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_material20.Box, { sx: { pt: "12vh" }, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
12638
12838
  AgentActivityList_default,
12639
12839
  {
12840
+ apiBaseUrl: globalUrl,
12640
12841
  onRunClick: setSelectedRun,
12641
12842
  onEditWorkflow: handleEditWorkflow
12642
12843
  }
@@ -12648,6 +12849,7 @@ var AgentsView = ({ onSchedule, maxWidth = 820 }) => {
12648
12849
  open: selectedRun !== null,
12649
12850
  onClose: () => setSelectedRun(null),
12650
12851
  run: selectedRun,
12852
+ apiBaseUrl: globalUrl,
12651
12853
  onSchedule
12652
12854
  }
12653
12855
  )
@@ -12656,14 +12858,14 @@ var AgentsView = ({ onSchedule, maxWidth = 820 }) => {
12656
12858
  var AgentsView_default = AgentsView;
12657
12859
 
12658
12860
  // useAppLookup.ts
12659
- var import_react18 = require("react");
12861
+ var import_react19 = require("react");
12660
12862
  init_api();
12661
12863
  init_appsCache();
12662
12864
  var norm3 = (s) => s.toLowerCase().replace(/[\s_\-]+/g, "_");
12663
12865
  function useAppLookup(appName) {
12664
- const [loading, setLoading] = (0, import_react18.useState)(false);
12665
- const [info, setInfo] = (0, import_react18.useState)(null);
12666
- const [algoliaId, setAlgoliaId] = (0, import_react18.useState)(null);
12866
+ const [loading, setLoading] = (0, import_react19.useState)(false);
12867
+ const [info, setInfo] = (0, import_react19.useState)(null);
12868
+ const [algoliaId, setAlgoliaId] = (0, import_react19.useState)(null);
12667
12869
  const {
12668
12870
  authStates,
12669
12871
  authenticatedApps,
@@ -12672,7 +12874,7 @@ function useAppLookup(appName) {
12672
12874
  handleSaveAuth,
12673
12875
  refreshAuth
12674
12876
  } = useAppAuth();
12675
- (0, import_react18.useEffect)(() => {
12877
+ (0, import_react19.useEffect)(() => {
12676
12878
  if (!appName) {
12677
12879
  setInfo(null);
12678
12880
  setAlgoliaId(null);
@@ -12751,13 +12953,13 @@ function useAppLookup(appName) {
12751
12953
  setLoading(false);
12752
12954
  })();
12753
12955
  }, [appName]);
12754
- const matchingEntries = (0, import_react18.useMemo)(() => {
12956
+ const matchingEntries = (0, import_react19.useMemo)(() => {
12755
12957
  if (!appName) return [];
12756
12958
  return authenticatedApps.filter(
12757
12959
  (auth) => auth.app?.name && norm3(auth.app.name) === norm3(appName)
12758
12960
  );
12759
12961
  }, [appName, authenticatedApps]);
12760
- const image = (0, import_react18.useMemo)(() => {
12962
+ const image = (0, import_react19.useMemo)(() => {
12761
12963
  if (info?.image) return info.image;
12762
12964
  for (const entry of matchingEntries) {
12763
12965
  const img = entry.app?.large_image || entry.large_image;
@@ -12765,7 +12967,7 @@ function useAppLookup(appName) {
12765
12967
  }
12766
12968
  return "";
12767
12969
  }, [info, matchingEntries]);
12768
- const algoliaApp = (0, import_react18.useMemo)(() => {
12970
+ const algoliaApp = (0, import_react19.useMemo)(() => {
12769
12971
  if (!appName) return null;
12770
12972
  return {
12771
12973
  objectID: algoliaId || appName,
@@ -12798,6 +13000,7 @@ function useAppLookup(appName) {
12798
13000
 
12799
13001
  // index.ts
12800
13002
  init_api();
13003
+ init_fetchBreaker();
12801
13004
  init_appsCache();
12802
13005
 
12803
13006
  // UsageBar.tsx
@@ -12929,8 +13132,10 @@ var UsageBar = ({
12929
13132
  getDatastoreItem,
12930
13133
  getDatastoreItemPublic,
12931
13134
  getFailureInfo,
13135
+ getHostBaseUrl,
12932
13136
  getIngestionCategory,
12933
13137
  hasOutputWarning,
13138
+ installFetchBreaker,
12934
13139
  invalidateAppsCache,
12935
13140
  invalidateResolvedApps,
12936
13141
  isCloud,
@@ -12944,12 +13149,16 @@ var UsageBar = ({
12944
13149
  normalizeAppName,
12945
13150
  parseRunResult,
12946
13151
  refreshAllIntegrationStatus,
13152
+ registerProtectedOrigin,
13153
+ resetRegionUrl,
12947
13154
  resolveApp,
12948
13155
  resolveApps,
12949
13156
  searchAgentActivity,
12950
13157
  seedResolvedApp,
12951
13158
  setDatastoreItem,
12952
13159
  setDatastoreItems,
13160
+ setHostBaseUrl,
13161
+ setRegionUrl,
12953
13162
  setRuntimeOrgId,
12954
13163
  setToastImpl,
12955
13164
  shuffleFetch,
@@ -12957,5 +13166,6 @@ var UsageBar = ({
12957
13166
  useAppAuth,
12958
13167
  useAppDetail,
12959
13168
  useAppDetailOptional,
12960
- useAppLookup
13169
+ useAppLookup,
13170
+ useSyncHostBaseUrl
12961
13171
  });