@howone/sdk 0.1.24 → 0.1.26

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.mjs CHANGED
@@ -1223,12 +1223,32 @@ function createClient(opts) {
1223
1223
  }
1224
1224
  } catch (_e) {
1225
1225
  }
1226
+ const workflowRequestWrapped = ai ? {
1227
+ get: ai.get.bind(ai),
1228
+ post: (config) => {
1229
+ const modifiedConfig = { ...config };
1230
+ if (opts?.projectId && modifiedConfig.url) {
1231
+ const workflowPattern = /^\/?(?:workflow\/)?([^\/]+)\/execute/;
1232
+ const match = modifiedConfig.url.match(workflowPattern);
1233
+ if (match) {
1234
+ const workflowId = match[1];
1235
+ modifiedConfig.url = `/workflow/${opts.projectId}/${workflowId}/execute`;
1236
+ }
1237
+ }
1238
+ return ai.post(modifiedConfig);
1239
+ },
1240
+ put: ai.put.bind(ai),
1241
+ delete: ai.delete.bind(ai),
1242
+ request: ai.request.bind(ai),
1243
+ cancelRequest: ai.cancelRequest?.bind(ai),
1244
+ cancelAllRequests: ai.cancelAllRequests?.bind(ai)
1245
+ } : ai;
1226
1246
  return {
1227
1247
  // expose projectId so consumers can read it from the client instance
1228
1248
  projectId: opts?.projectId ?? null,
1229
1249
  request: bizWrapped,
1230
1250
  aiRequest: ai,
1231
- workflowRequest: ai,
1251
+ workflowRequest: workflowRequestWrapped,
1232
1252
  // artifact helpers using artifacts-client
1233
1253
  artifacts: createArtifactsClient(biz),
1234
1254
  me: async () => {
@@ -1581,25 +1601,38 @@ var HowOneProvider = ({
1581
1601
  }) => {
1582
1602
  const [user, setUser] = useState4(() => parseUserFromToken(getToken()));
1583
1603
  const [token, setTokenState] = useState4(() => getToken());
1604
+ const [hasCheckedUrlToken, setHasCheckedUrlToken] = useState4(false);
1584
1605
  useEffect4(() => {
1585
1606
  try {
1586
1607
  const params = new URLSearchParams(window.location.search);
1587
- const urlToken = params.get("access_token") || params.get("token");
1608
+ let urlToken = params.get("access_token") || params.get("token");
1609
+ if (!urlToken && window.location.hash) {
1610
+ const hashParams = new URLSearchParams(window.location.hash.slice(1));
1611
+ urlToken = hashParams.get("access_token") || hashParams.get("token");
1612
+ }
1588
1613
  if (urlToken) {
1614
+ console.log("[HowOneProvider] Token captured from URL, storing to localStorage...");
1589
1615
  setToken(urlToken);
1590
1616
  setTokenState(urlToken);
1591
1617
  setUser(parseUserFromToken(urlToken));
1592
1618
  params.delete("access_token");
1593
1619
  params.delete("token");
1620
+ params.delete("project_id");
1594
1621
  const newSearch = params.toString();
1595
- const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "") + window.location.hash;
1622
+ const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
1596
1623
  window.history.replaceState({}, "", newUrl);
1624
+ console.log("[HowOneProvider] Token stored successfully, URL cleaned");
1597
1625
  }
1598
1626
  } catch (e) {
1599
1627
  console.error("[HowOneProvider] Failed to capture token from URL:", e);
1628
+ } finally {
1629
+ setHasCheckedUrlToken(true);
1600
1630
  }
1601
1631
  }, []);
1602
1632
  useEffect4(() => {
1633
+ if (!hasCheckedUrlToken) {
1634
+ return;
1635
+ }
1603
1636
  if (redirectOnUnauthenticated && !token && !user) {
1604
1637
  const currentUrl = new URL(window.location.href);
1605
1638
  if (!currentUrl.pathname.includes("/auth")) {
@@ -1619,7 +1652,7 @@ var HowOneProvider = ({
1619
1652
  }
1620
1653
  }
1621
1654
  }
1622
- }, [token, user, redirectOnUnauthenticated, authUrl, projectId]);
1655
+ }, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
1623
1656
  const logout = () => {
1624
1657
  try {
1625
1658
  setToken(null);