replicas-cli 0.2.371 → 0.2.373

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 +79 -87
  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";
@@ -7647,14 +7713,16 @@ var DEFAULT_CHAT_TITLES = {
7647
7713
  opencode: "Opencode",
7648
7714
  relay: "Relay"
7649
7715
  };
7716
+ function isDefaultChat(chat) {
7717
+ return chat.title === DEFAULT_CHAT_TITLES[chat.provider];
7718
+ }
7650
7719
  function getInitialChatId(chats, preferredProvider = "claude") {
7651
7720
  if (chats.length === 0) return null;
7652
- const isDefault = (c) => c.title === DEFAULT_CHAT_TITLES[c.provider];
7653
7721
  const hasActivity = (c) => c.updatedAt > c.createdAt;
7654
7722
  const mostActive = (list) => list.filter(hasActivity).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))[0] ?? null;
7655
7723
  const preferred = chats.filter((c) => c.provider === preferredProvider);
7656
7724
  const others = chats.filter((c) => c.provider !== preferredProvider);
7657
- return mostActive(preferred)?.id ?? mostActive(others)?.id ?? preferred.find(isDefault)?.id ?? others.find(isDefault)?.id ?? chats[0]?.id ?? null;
7725
+ return mostActive(preferred)?.id ?? mostActive(others)?.id ?? preferred.find(isDefaultChat)?.id ?? others.find(isDefaultChat)?.id ?? chats[0]?.id ?? null;
7658
7726
  }
7659
7727
  var CLAUDE_OPUS_1M_MODEL = "opus[1m]";
7660
7728
  var LEGACY_CLAUDE_OPUS_1M_MODEL = "opus-1m";
@@ -9750,7 +9818,7 @@ var HOOK_EXEC_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
9750
9818
  var REPLICAS_CONFIG_FILENAMES = ["replicas.json", "replicas.yaml", "replicas.yml"];
9751
9819
 
9752
9820
  // ../shared/src/cli-version.ts
9753
- var CLI_VERSION = "0.2.371";
9821
+ var CLI_VERSION = "0.2.373";
9754
9822
 
9755
9823
  // ../shared/src/version.ts
9756
9824
  function compareVersions(v1, v2) {
@@ -12006,29 +12074,6 @@ async function authenticatedFetch(url, options) {
12006
12074
  ...options?.headers || {}
12007
12075
  }, options);
12008
12076
  }
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
12077
  async function orgAuthenticatedFetch(url, options) {
12033
12078
  const { bearer, extraHeaders } = await buildOrgAuthHeaders();
12034
12079
  return apiFetch(url, {
@@ -18097,53 +18142,19 @@ function useReconnectingSseStream(options) {
18097
18142
 
18098
18143
  // ../shared/src/hooks/fetch.ts
18099
18144
  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
18145
  function useOrgFetch() {
18124
18146
  const auth = useReplicasAuth();
18125
18147
  return useCallback2(
18126
18148
  async function orgFetch(url, options) {
18127
18149
  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();
18150
+ return apiRequest({
18151
+ monolithUrl: auth.monolithUrl,
18152
+ token,
18153
+ path: url,
18154
+ organizationId: auth.getOrganizationId(),
18155
+ body: options?.body,
18156
+ method: options?.method
18157
+ });
18147
18158
  },
18148
18159
  [auth]
18149
18160
  );
@@ -18311,25 +18322,6 @@ function patchChat(chats, chatId, patch) {
18311
18322
  });
18312
18323
  return changed ? next.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)) : chats;
18313
18324
  }
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
18325
  function useWorkspaceChats(workspaceId) {
18334
18326
  const auth = useReplicasAuth();
18335
18327
  const orgFetch = useOrgFetch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-cli",
3
- "version": "0.2.371",
3
+ "version": "0.2.373",
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": {