replicas-cli 0.2.370 → 0.2.372

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 (2) hide show
  1. package/dist/index.mjs +75 -85
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -7539,6 +7539,53 @@ function isRecord(value) {
7539
7539
  return typeof value === "object" && value !== null && !Array.isArray(value);
7540
7540
  }
7541
7541
 
7542
+ // ../shared/src/api-request.ts
7543
+ var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
7544
+ var MAX_REDIRECTS = 5;
7545
+ async function fetchWithRedirects(url, init, attempt = 0) {
7546
+ const response = await fetch(url, { ...init, redirect: "manual" });
7547
+ if (REDIRECT_STATUSES.has(response.status)) {
7548
+ if (attempt >= MAX_REDIRECTS) {
7549
+ throw new Error("Too many redirects while contacting the Replicas API");
7550
+ }
7551
+ const location = response.headers.get("location");
7552
+ if (!location) {
7553
+ throw new Error(`Redirect status ${response.status} missing Location header`);
7554
+ }
7555
+ const nextUrl = new URL(location, url).toString();
7556
+ const shouldForceGet = response.status === 303 && init.method !== void 0 && init.method.toUpperCase() !== "GET";
7557
+ return fetchWithRedirects(
7558
+ nextUrl,
7559
+ { ...init, method: shouldForceGet ? "GET" : init.method, body: shouldForceGet ? void 0 : init.body },
7560
+ attempt + 1
7561
+ );
7562
+ }
7563
+ return response;
7564
+ }
7565
+ async function apiRequest({
7566
+ monolithUrl,
7567
+ token,
7568
+ path: path6,
7569
+ organizationId,
7570
+ body,
7571
+ method = "GET"
7572
+ }) {
7573
+ const response = await fetchWithRedirects(`${monolithUrl}${path6}`, {
7574
+ method,
7575
+ headers: {
7576
+ Authorization: `Bearer ${token}`,
7577
+ "Content-Type": "application/json",
7578
+ ...organizationId ? { "Replicas-Org-Id": organizationId } : {}
7579
+ },
7580
+ body: body !== void 0 ? JSON.stringify(body) : void 0
7581
+ });
7582
+ if (!response.ok) {
7583
+ const payload = await response.json().catch(() => ({ error: "Request failed" }));
7584
+ throw new Error(typeof payload?.error === "string" ? payload.error : "Request failed");
7585
+ }
7586
+ return response.json();
7587
+ }
7588
+
7542
7589
  // ../shared/src/result.ts
7543
7590
  function createSuccessResult(data) {
7544
7591
  return { ok: true, data };
@@ -7635,6 +7682,25 @@ function getClaudePartialMessageStreamId(event) {
7635
7682
  if (event.type !== CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE) return null;
7636
7683
  return typeof event.payload.streamId === "string" && event.payload.streamId ? event.payload.streamId : null;
7637
7684
  }
7685
+ function getEventSignature(event) {
7686
+ const streamId = getClaudePartialMessageStreamId(event);
7687
+ if (streamId) {
7688
+ return `${CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE}:${streamId}`;
7689
+ }
7690
+ const normalize = (input) => {
7691
+ if (Array.isArray(input)) return input.map(normalize);
7692
+ if (input && typeof input === "object") {
7693
+ const entries = Object.entries(input).sort(([a], [b]) => a.localeCompare(b)).map(([key, val]) => [key, normalize(val)]);
7694
+ return Object.fromEntries(entries);
7695
+ }
7696
+ return input;
7697
+ };
7698
+ try {
7699
+ return JSON.stringify(normalize(event));
7700
+ } catch {
7701
+ return String(event);
7702
+ }
7703
+ }
7638
7704
  var USER_MESSAGE_ID_PAYLOAD_KEY = "replicasMessageId";
7639
7705
  var CODEX_ASP_ITEM_ID_PAYLOAD_KEY = "codexAspItemId";
7640
7706
  var CODEX_QUOTA_STATUS_EVENT_TYPE = "codex-quota-status";
@@ -9750,7 +9816,7 @@ var HOOK_EXEC_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
9750
9816
  var REPLICAS_CONFIG_FILENAMES = ["replicas.json", "replicas.yaml", "replicas.yml"];
9751
9817
 
9752
9818
  // ../shared/src/cli-version.ts
9753
- var CLI_VERSION = "0.2.370";
9819
+ var CLI_VERSION = "0.2.372";
9754
9820
 
9755
9821
  // ../shared/src/version.ts
9756
9822
  function compareVersions(v1, v2) {
@@ -12006,29 +12072,6 @@ async function authenticatedFetch(url, options) {
12006
12072
  ...options?.headers || {}
12007
12073
  }, options);
12008
12074
  }
12009
- var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
12010
- var MAX_REDIRECTS = 5;
12011
- async function fetchWithRedirects(url, init, attempt = 0) {
12012
- const response = await fetch(url, { ...init, redirect: "manual" });
12013
- if (REDIRECT_STATUSES.has(response.status)) {
12014
- if (attempt >= MAX_REDIRECTS) {
12015
- throw new Error("Too many redirects while contacting the Replicas API");
12016
- }
12017
- const location = response.headers.get("location");
12018
- if (!location) {
12019
- throw new Error(`Redirect status ${response.status} missing Location header`);
12020
- }
12021
- const nextUrl = new URL(location, url).toString();
12022
- const shouldForceGet = response.status === 303 && init.method !== void 0 && init.method.toUpperCase() !== "GET";
12023
- const nextInit = {
12024
- ...init,
12025
- method: shouldForceGet ? "GET" : init.method,
12026
- body: shouldForceGet ? void 0 : init.body
12027
- };
12028
- return fetchWithRedirects(nextUrl, nextInit, attempt + 1);
12029
- }
12030
- return response;
12031
- }
12032
12075
  async function orgAuthenticatedFetch(url, options) {
12033
12076
  const { bearer, extraHeaders } = await buildOrgAuthHeaders();
12034
12077
  return apiFetch(url, {
@@ -18097,53 +18140,19 @@ function useReconnectingSseStream(options) {
18097
18140
 
18098
18141
  // ../shared/src/hooks/fetch.ts
18099
18142
  import { useCallback as useCallback2 } from "react";
18100
- var REDIRECT_STATUSES2 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
18101
- var MAX_REDIRECTS2 = 5;
18102
- async function fetchWithRedirects2(url, init, attempt = 0) {
18103
- const response = await fetch(url, { ...init, redirect: "manual" });
18104
- if (REDIRECT_STATUSES2.has(response.status)) {
18105
- if (attempt >= MAX_REDIRECTS2) {
18106
- throw new Error("Too many redirects while contacting the Replicas API");
18107
- }
18108
- const location = response.headers.get("location");
18109
- if (!location) {
18110
- throw new Error(`Redirect status ${response.status} missing Location header`);
18111
- }
18112
- const nextUrl = new URL(location, url).toString();
18113
- const shouldForceGet = response.status === 303 && init.method !== void 0 && init.method.toUpperCase() !== "GET";
18114
- const nextInit = {
18115
- ...init,
18116
- method: shouldForceGet ? "GET" : init.method,
18117
- body: shouldForceGet ? void 0 : init.body
18118
- };
18119
- return fetchWithRedirects2(nextUrl, nextInit, attempt + 1);
18120
- }
18121
- return response;
18122
- }
18123
18143
  function useOrgFetch() {
18124
18144
  const auth = useReplicasAuth();
18125
18145
  return useCallback2(
18126
18146
  async function orgFetch(url, options) {
18127
18147
  const token = await auth.getAccessToken();
18128
- const orgId = auth.getOrganizationId();
18129
- const headers = {
18130
- "Authorization": `Bearer ${token}`,
18131
- "Replicas-Org-Id": orgId,
18132
- "Content-Type": "application/json",
18133
- ...options?.headers || {}
18134
- };
18135
- const absoluteUrl = `${auth.monolithUrl}${url}`;
18136
- const requestInit = {
18137
- ...options,
18138
- headers,
18139
- body: options?.body !== void 0 ? JSON.stringify(options.body) : void 0
18140
- };
18141
- const response = await fetchWithRedirects2(absoluteUrl, requestInit);
18142
- if (!response.ok) {
18143
- const error = await response.json().catch(() => ({ error: "Request failed" }));
18144
- throw new Error(error.error || `Request failed with status ${response.status}`);
18145
- }
18146
- return response.json();
18148
+ return apiRequest({
18149
+ monolithUrl: auth.monolithUrl,
18150
+ token,
18151
+ path: url,
18152
+ organizationId: auth.getOrganizationId(),
18153
+ body: options?.body,
18154
+ method: options?.method
18155
+ });
18147
18156
  },
18148
18157
  [auth]
18149
18158
  );
@@ -18311,25 +18320,6 @@ function patchChat(chats, chatId, patch) {
18311
18320
  });
18312
18321
  return changed ? next.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)) : chats;
18313
18322
  }
18314
- function getEventSignature(value) {
18315
- const streamId = getClaudePartialMessageStreamId(value);
18316
- if (streamId) {
18317
- return `${CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE}:${streamId}`;
18318
- }
18319
- const normalize = (input) => {
18320
- if (Array.isArray(input)) return input.map(normalize);
18321
- if (input && typeof input === "object") {
18322
- const entries = Object.entries(input).sort(([a], [b]) => a.localeCompare(b)).map(([key, val]) => [key, normalize(val)]);
18323
- return Object.fromEntries(entries);
18324
- }
18325
- return input;
18326
- };
18327
- try {
18328
- return JSON.stringify(normalize(value));
18329
- } catch {
18330
- return String(value);
18331
- }
18332
- }
18333
18323
  function useWorkspaceChats(workspaceId) {
18334
18324
  const auth = useReplicasAuth();
18335
18325
  const orgFetch = useOrgFetch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-cli",
3
- "version": "0.2.370",
3
+ "version": "0.2.372",
4
4
  "description": "CLI for managing Replicas workspaces - SSH into cloud dev environments with automatic port forwarding",
5
5
  "main": "dist/index.mjs",
6
6
  "bin": {