rush-ai 0.6.0 → 0.9.0
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/AGENTS.md +37 -0
- package/README.md +206 -7
- package/dist/{chunk-UJLVFMWM.js → chunk-SZO6LEQX.js} +285 -101
- package/dist/chunk-SZO6LEQX.js.map +1 -0
- package/dist/index.js +7701 -1334
- package/dist/index.js.map +1 -1
- package/dist/plugin-assets/SKILL.md +66 -59
- package/dist/{server-MRWAFK5G.js → server-KFDYSF4T.js} +3 -5
- package/dist/{server-MRWAFK5G.js.map → server-KFDYSF4T.js.map} +1 -1
- package/dist/skills/README.md +48 -0
- package/dist/skills/agent-shelf.md +102 -0
- package/dist/skills/hand-off.md +163 -0
- package/package.json +4 -1
- package/skills/README.md +48 -0
- package/skills/agent-shelf.md +102 -0
- package/skills/hand-off.md +163 -0
- package/dist/chunk-MG4HY2PD.js +0 -136
- package/dist/chunk-MG4HY2PD.js.map +0 -1
- package/dist/chunk-UJLVFMWM.js.map +0 -1
- package/dist/client-NTECGN3O.js +0 -10
- package/dist/client-NTECGN3O.js.map +0 -1
|
@@ -77,7 +77,8 @@ var AUTH_DEFAULTS = {
|
|
|
77
77
|
expiresAt: null,
|
|
78
78
|
refreshToken: null,
|
|
79
79
|
method: null,
|
|
80
|
-
tokenId: null
|
|
80
|
+
tokenId: null,
|
|
81
|
+
sourceUrl: null
|
|
81
82
|
};
|
|
82
83
|
var GLOBAL_DEFAULTS = {
|
|
83
84
|
currentTeam: null,
|
|
@@ -123,7 +124,7 @@ function migrateGlobalStoreIfNeeded() {
|
|
|
123
124
|
}
|
|
124
125
|
function migrateAuthStoreIfNeeded() {
|
|
125
126
|
const version = authStore.get("_version");
|
|
126
|
-
if (version ===
|
|
127
|
+
if (version === 3) return;
|
|
127
128
|
const hasOldFormat = authStore.has("token") || authStore.has("method");
|
|
128
129
|
const isEmpty = authStore.size === 0;
|
|
129
130
|
if (hasOldFormat) {
|
|
@@ -132,13 +133,29 @@ function migrateAuthStoreIfNeeded() {
|
|
|
132
133
|
expiresAt: authStore.get("expiresAt") ?? null,
|
|
133
134
|
refreshToken: authStore.get("refreshToken") ?? null,
|
|
134
135
|
method: authStore.get("method") ?? null,
|
|
135
|
-
tokenId: authStore.get("tokenId") ?? null
|
|
136
|
+
tokenId: authStore.get("tokenId") ?? null,
|
|
137
|
+
sourceUrl: null
|
|
136
138
|
};
|
|
137
139
|
authStore.clear();
|
|
138
|
-
authStore.set("_version",
|
|
140
|
+
authStore.set("_version", 3);
|
|
139
141
|
authStore.set("default", oldAuth);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (isEmpty) {
|
|
145
|
+
authStore.set("_version", 3);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (version === 2) {
|
|
149
|
+
for (const key of Object.keys(authStore.store)) {
|
|
150
|
+
if (key === "_version") continue;
|
|
151
|
+
const entry = authStore.get(key);
|
|
152
|
+
if (!entry || typeof entry !== "object") continue;
|
|
153
|
+
const asAuth = entry;
|
|
154
|
+
if (!("sourceUrl" in asAuth)) {
|
|
155
|
+
authStore.set(key, { ...asAuth, sourceUrl: null });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
authStore.set("_version", 3);
|
|
142
159
|
}
|
|
143
160
|
}
|
|
144
161
|
migrateGlobalStoreIfNeeded();
|
|
@@ -194,7 +211,8 @@ function getAuthConfig() {
|
|
|
194
211
|
expiresAt: profileAuth?.expiresAt ?? null,
|
|
195
212
|
refreshToken: profileAuth?.refreshToken ?? null,
|
|
196
213
|
method: profileAuth?.method ?? null,
|
|
197
|
-
tokenId: profileAuth?.tokenId ?? null
|
|
214
|
+
tokenId: profileAuth?.tokenId ?? null,
|
|
215
|
+
sourceUrl: profileAuth?.sourceUrl ?? null
|
|
198
216
|
};
|
|
199
217
|
}
|
|
200
218
|
function setAuthConfig(config) {
|
|
@@ -236,6 +254,16 @@ function isLoggedIn() {
|
|
|
236
254
|
}
|
|
237
255
|
return true;
|
|
238
256
|
}
|
|
257
|
+
function normalizeApiUrl(url) {
|
|
258
|
+
return url.replace(/\/+$/, "").toLowerCase();
|
|
259
|
+
}
|
|
260
|
+
function checkAuthSourceMismatch(overrideCurrentUrl) {
|
|
261
|
+
const auth = getAuthConfig();
|
|
262
|
+
if (!auth.token || !auth.sourceUrl) return null;
|
|
263
|
+
const current = overrideCurrentUrl ?? getGlobalConfig().api;
|
|
264
|
+
if (normalizeApiUrl(auth.sourceUrl) === normalizeApiUrl(current)) return null;
|
|
265
|
+
return { stored: auth.sourceUrl, current };
|
|
266
|
+
}
|
|
239
267
|
function getProfileConfig(name) {
|
|
240
268
|
const profiles = globalStore.get("profiles") ?? {};
|
|
241
269
|
return profiles[name] ?? null;
|
|
@@ -247,7 +275,8 @@ function getProfileAuth(name) {
|
|
|
247
275
|
expiresAt: profileAuth?.expiresAt ?? null,
|
|
248
276
|
refreshToken: profileAuth?.refreshToken ?? null,
|
|
249
277
|
method: profileAuth?.method ?? null,
|
|
250
|
-
tokenId: profileAuth?.tokenId ?? null
|
|
278
|
+
tokenId: profileAuth?.tokenId ?? null,
|
|
279
|
+
sourceUrl: profileAuth?.sourceUrl ?? null
|
|
251
280
|
};
|
|
252
281
|
}
|
|
253
282
|
|
|
@@ -286,6 +315,88 @@ function getCasConfig() {
|
|
|
286
315
|
};
|
|
287
316
|
}
|
|
288
317
|
|
|
318
|
+
// src/util/errors.ts
|
|
319
|
+
var RushError = class extends Error {
|
|
320
|
+
code;
|
|
321
|
+
meta;
|
|
322
|
+
exitCode;
|
|
323
|
+
constructor(message, meta = {}, code = "RUSH_ERROR", exitCode = 2) {
|
|
324
|
+
super(message);
|
|
325
|
+
this.name = "RushError";
|
|
326
|
+
this.code = code;
|
|
327
|
+
this.meta = meta;
|
|
328
|
+
this.exitCode = exitCode;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
var AuthError = class extends RushError {
|
|
332
|
+
constructor(message = "Not authenticated. Run `rush-ai auth login` first.") {
|
|
333
|
+
super(message, {}, "AUTH_ERROR", 3);
|
|
334
|
+
this.name = "AuthError";
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var TaskFailedError = class extends RushError {
|
|
338
|
+
constructor(message, meta = {}) {
|
|
339
|
+
super(message, meta, "TASK_FAILED", 1);
|
|
340
|
+
this.name = "TaskFailedError";
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
function friendlyMessage(status, serverMessage) {
|
|
344
|
+
if (serverMessage) return serverMessage;
|
|
345
|
+
switch (status) {
|
|
346
|
+
case 401:
|
|
347
|
+
return "Authentication expired. Run `rush-ai auth login` to re-authenticate.";
|
|
348
|
+
case 403:
|
|
349
|
+
return "Permission denied. You may not have access to this resource.";
|
|
350
|
+
case 404:
|
|
351
|
+
return "Resource not found.";
|
|
352
|
+
case 429:
|
|
353
|
+
return "Rate limited. The server is busy, please try again later.";
|
|
354
|
+
case 502:
|
|
355
|
+
case 503:
|
|
356
|
+
case 504:
|
|
357
|
+
return "Service temporarily unavailable. Please try again in a moment.";
|
|
358
|
+
default:
|
|
359
|
+
return `Request failed with status ${status}.`;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
var ApiError = class extends RushError {
|
|
363
|
+
status;
|
|
364
|
+
retryAfter;
|
|
365
|
+
constructor(message, status, body, retryAfter) {
|
|
366
|
+
let serverMessage;
|
|
367
|
+
if (body) {
|
|
368
|
+
try {
|
|
369
|
+
const parsed = JSON.parse(body);
|
|
370
|
+
if (parsed.error && typeof parsed.error === "string") {
|
|
371
|
+
serverMessage = parsed.error;
|
|
372
|
+
}
|
|
373
|
+
} catch {
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
super(
|
|
377
|
+
friendlyMessage(status, serverMessage),
|
|
378
|
+
{ status, body },
|
|
379
|
+
"API_ERROR"
|
|
380
|
+
);
|
|
381
|
+
this.name = "ApiError";
|
|
382
|
+
this.status = status;
|
|
383
|
+
this.retryAfter = retryAfter;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
function isRushError(error) {
|
|
387
|
+
return error instanceof RushError;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/util/verbosity.ts
|
|
391
|
+
var _verbose = false;
|
|
392
|
+
var _debug = false;
|
|
393
|
+
function setVerbosity(verbose, debug) {
|
|
394
|
+
_debug = debug;
|
|
395
|
+
_verbose = verbose || debug;
|
|
396
|
+
}
|
|
397
|
+
var isVerbose = () => _verbose;
|
|
398
|
+
var isDebug = () => _debug;
|
|
399
|
+
|
|
289
400
|
// src/util/auth-session.ts
|
|
290
401
|
var VERIFY_PATH = "/api/skill-auth/me";
|
|
291
402
|
var REFRESH_SKEW_MS = 6e4;
|
|
@@ -491,78 +602,6 @@ async function revokePlatformToken() {
|
|
|
491
602
|
}
|
|
492
603
|
}
|
|
493
604
|
|
|
494
|
-
// src/util/errors.ts
|
|
495
|
-
var RushError = class extends Error {
|
|
496
|
-
code;
|
|
497
|
-
meta;
|
|
498
|
-
exitCode;
|
|
499
|
-
constructor(message, meta = {}, code = "RUSH_ERROR", exitCode = 2) {
|
|
500
|
-
super(message);
|
|
501
|
-
this.name = "RushError";
|
|
502
|
-
this.code = code;
|
|
503
|
-
this.meta = meta;
|
|
504
|
-
this.exitCode = exitCode;
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
var AuthError = class extends RushError {
|
|
508
|
-
constructor(message = "Not authenticated. Run `rush-ai auth login` first.") {
|
|
509
|
-
super(message, {}, "AUTH_ERROR", 3);
|
|
510
|
-
this.name = "AuthError";
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
var TaskFailedError = class extends RushError {
|
|
514
|
-
constructor(message, meta = {}) {
|
|
515
|
-
super(message, meta, "TASK_FAILED", 1);
|
|
516
|
-
this.name = "TaskFailedError";
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
function friendlyMessage(status, serverMessage) {
|
|
520
|
-
if (serverMessage) return serverMessage;
|
|
521
|
-
switch (status) {
|
|
522
|
-
case 401:
|
|
523
|
-
return "Authentication expired. Run `rush-ai auth login` to re-authenticate.";
|
|
524
|
-
case 403:
|
|
525
|
-
return "Permission denied. You may not have access to this resource.";
|
|
526
|
-
case 404:
|
|
527
|
-
return "Resource not found.";
|
|
528
|
-
case 429:
|
|
529
|
-
return "Rate limited. The server is busy, please try again later.";
|
|
530
|
-
case 502:
|
|
531
|
-
case 503:
|
|
532
|
-
case 504:
|
|
533
|
-
return "Service temporarily unavailable. Please try again in a moment.";
|
|
534
|
-
default:
|
|
535
|
-
return `Request failed with status ${status}.`;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
var ApiError = class extends RushError {
|
|
539
|
-
status;
|
|
540
|
-
retryAfter;
|
|
541
|
-
constructor(message, status, body, retryAfter) {
|
|
542
|
-
let serverMessage;
|
|
543
|
-
if (body) {
|
|
544
|
-
try {
|
|
545
|
-
const parsed = JSON.parse(body);
|
|
546
|
-
if (parsed.error && typeof parsed.error === "string") {
|
|
547
|
-
serverMessage = parsed.error;
|
|
548
|
-
}
|
|
549
|
-
} catch {
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
super(
|
|
553
|
-
friendlyMessage(status, serverMessage),
|
|
554
|
-
{ status, body },
|
|
555
|
-
"API_ERROR"
|
|
556
|
-
);
|
|
557
|
-
this.name = "ApiError";
|
|
558
|
-
this.status = status;
|
|
559
|
-
this.retryAfter = retryAfter;
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
function isRushError(error) {
|
|
563
|
-
return error instanceof RushError;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
605
|
// src/util/retry.ts
|
|
567
606
|
function parseRetryAfter(value) {
|
|
568
607
|
const seconds = Number(value);
|
|
@@ -654,16 +693,6 @@ async function withRetry(fn, options = {}) {
|
|
|
654
693
|
throw lastError;
|
|
655
694
|
}
|
|
656
695
|
|
|
657
|
-
// src/util/verbosity.ts
|
|
658
|
-
var _verbose = false;
|
|
659
|
-
var _debug = false;
|
|
660
|
-
function setVerbosity(verbose, debug) {
|
|
661
|
-
_debug = debug;
|
|
662
|
-
_verbose = verbose || debug;
|
|
663
|
-
}
|
|
664
|
-
var isVerbose = () => _verbose;
|
|
665
|
-
var isDebug = () => _debug;
|
|
666
|
-
|
|
667
696
|
// src/util/client.ts
|
|
668
697
|
var SENSITIVE_HEADERS = [
|
|
669
698
|
"authorization",
|
|
@@ -702,16 +731,30 @@ var RushClient = class _RushClient {
|
|
|
702
731
|
}
|
|
703
732
|
return headers;
|
|
704
733
|
}
|
|
734
|
+
/**
|
|
735
|
+
* Merge default headers with per-request overrides. A `null` override value
|
|
736
|
+
* drops the default entirely — used by multipart POSTs that need fetch to
|
|
737
|
+
* synthesize its own Content-Type with a boundary. An empty string stays as
|
|
738
|
+
* an empty-value header so callers can still send one intentionally.
|
|
739
|
+
*/
|
|
740
|
+
mergeHeaders(base, overrides) {
|
|
741
|
+
const merged = { ...base };
|
|
742
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
743
|
+
if (value === null) {
|
|
744
|
+
delete merged[key];
|
|
745
|
+
} else {
|
|
746
|
+
merged[key] = value;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return merged;
|
|
750
|
+
}
|
|
705
751
|
async performRequest(url, options, retryOnUnauthorized = true) {
|
|
706
752
|
const requestHeaders = options.headers ?? {};
|
|
707
753
|
const headers = await this.getHeaders();
|
|
708
754
|
try {
|
|
709
755
|
const response = await fetch(url, {
|
|
710
756
|
...options,
|
|
711
|
-
headers:
|
|
712
|
-
...headers,
|
|
713
|
-
...requestHeaders
|
|
714
|
-
}
|
|
757
|
+
headers: this.mergeHeaders(headers, requestHeaders)
|
|
715
758
|
});
|
|
716
759
|
if (response.status === 401 && retryOnUnauthorized && !process.env.RUSH_API_KEY) {
|
|
717
760
|
const auth = getAuthConfig();
|
|
@@ -720,10 +763,7 @@ var RushClient = class _RushClient {
|
|
|
720
763
|
const retryHeaders = await this.getHeaders();
|
|
721
764
|
return await fetch(url, {
|
|
722
765
|
...options,
|
|
723
|
-
headers:
|
|
724
|
-
...retryHeaders,
|
|
725
|
-
...requestHeaders
|
|
726
|
-
}
|
|
766
|
+
headers: this.mergeHeaders(retryHeaders, requestHeaders)
|
|
727
767
|
});
|
|
728
768
|
}
|
|
729
769
|
}
|
|
@@ -823,6 +863,19 @@ var RushClient = class _RushClient {
|
|
|
823
863
|
body: body ? JSON.stringify(body) : void 0
|
|
824
864
|
});
|
|
825
865
|
}
|
|
866
|
+
/**
|
|
867
|
+
* POST multipart/form-data. The default `Content-Type: application/json`
|
|
868
|
+
* must be removed so fetch can set its own multipart boundary — passing
|
|
869
|
+
* `null` as the header value tells mergeHeaders to drop the key.
|
|
870
|
+
*/
|
|
871
|
+
async postFormData(path, formData) {
|
|
872
|
+
return this._doFetch(path, {
|
|
873
|
+
method: "POST",
|
|
874
|
+
body: formData,
|
|
875
|
+
// Cast: RequestInit.headers doesn't include null; mergeHeaders handles it.
|
|
876
|
+
headers: { "Content-Type": null }
|
|
877
|
+
});
|
|
878
|
+
}
|
|
826
879
|
async put(path, body) {
|
|
827
880
|
return this.fetch(path, {
|
|
828
881
|
method: "PUT",
|
|
@@ -837,6 +890,136 @@ function createClient() {
|
|
|
837
890
|
return new RushClient();
|
|
838
891
|
}
|
|
839
892
|
|
|
893
|
+
// src/util/sse.ts
|
|
894
|
+
function createSSEParser(onEvent, onDone) {
|
|
895
|
+
let buffer = "";
|
|
896
|
+
return {
|
|
897
|
+
feed(chunk) {
|
|
898
|
+
buffer += chunk;
|
|
899
|
+
const lines = buffer.split("\n");
|
|
900
|
+
buffer = lines.pop() ?? "";
|
|
901
|
+
for (const line of lines) {
|
|
902
|
+
if (line.startsWith("data: ")) {
|
|
903
|
+
const data = line.slice(6);
|
|
904
|
+
if (data === "[DONE]") {
|
|
905
|
+
onDone?.();
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
try {
|
|
909
|
+
const parsed = JSON.parse(data);
|
|
910
|
+
onEvent({
|
|
911
|
+
type: parsed.type ?? "unknown",
|
|
912
|
+
data: typeof parsed.data === "string" ? parsed.data : JSON.stringify(parsed)
|
|
913
|
+
});
|
|
914
|
+
} catch {
|
|
915
|
+
onEvent({ type: "raw", data });
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
},
|
|
920
|
+
flush() {
|
|
921
|
+
if (buffer.startsWith("data: ")) {
|
|
922
|
+
const data = buffer.slice(6);
|
|
923
|
+
if (data !== "[DONE]") {
|
|
924
|
+
try {
|
|
925
|
+
const parsed = JSON.parse(data);
|
|
926
|
+
onEvent({
|
|
927
|
+
type: parsed.type ?? "unknown",
|
|
928
|
+
data: typeof parsed.data === "string" ? parsed.data : JSON.stringify(parsed)
|
|
929
|
+
});
|
|
930
|
+
} catch {
|
|
931
|
+
onEvent({ type: "raw", data });
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
buffer = "";
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
async function consumeSSEStreamWithReconnect(connectFn, onEvent, options = {}) {
|
|
940
|
+
const {
|
|
941
|
+
maxReconnects = 5,
|
|
942
|
+
reconnectDelay = 1e3,
|
|
943
|
+
signal,
|
|
944
|
+
onReconnect,
|
|
945
|
+
isTerminal
|
|
946
|
+
} = options;
|
|
947
|
+
let emittedEventCount = 0;
|
|
948
|
+
let reconnectAttempts = 0;
|
|
949
|
+
let terminalReached = false;
|
|
950
|
+
while (!terminalReached) {
|
|
951
|
+
if (signal?.aborted) return;
|
|
952
|
+
let receivedDone = false;
|
|
953
|
+
let currentEventIndex = 0;
|
|
954
|
+
try {
|
|
955
|
+
const stream = await connectFn();
|
|
956
|
+
const reader = stream.getReader();
|
|
957
|
+
const decoder = new TextDecoder();
|
|
958
|
+
const parser = createSSEParser(
|
|
959
|
+
(event) => {
|
|
960
|
+
currentEventIndex++;
|
|
961
|
+
if (currentEventIndex <= emittedEventCount) {
|
|
962
|
+
if (isTerminal?.(event)) {
|
|
963
|
+
terminalReached = true;
|
|
964
|
+
}
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
emittedEventCount++;
|
|
968
|
+
onEvent(event);
|
|
969
|
+
if (isTerminal?.(event)) {
|
|
970
|
+
terminalReached = true;
|
|
971
|
+
}
|
|
972
|
+
},
|
|
973
|
+
() => {
|
|
974
|
+
receivedDone = true;
|
|
975
|
+
}
|
|
976
|
+
);
|
|
977
|
+
for (; ; ) {
|
|
978
|
+
if (signal?.aborted || terminalReached) {
|
|
979
|
+
reader.cancel().catch(() => {
|
|
980
|
+
});
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
const { done, value } = await reader.read();
|
|
984
|
+
if (done) break;
|
|
985
|
+
parser.feed(decoder.decode(value, { stream: true }));
|
|
986
|
+
if (terminalReached) {
|
|
987
|
+
reader.cancel().catch(() => {
|
|
988
|
+
});
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
parser.flush();
|
|
993
|
+
} catch {
|
|
994
|
+
if (signal?.aborted || terminalReached) return;
|
|
995
|
+
}
|
|
996
|
+
if (terminalReached) return;
|
|
997
|
+
if (receivedDone && terminalReached) return;
|
|
998
|
+
reconnectAttempts++;
|
|
999
|
+
if (reconnectAttempts > maxReconnects) {
|
|
1000
|
+
throw new Error(
|
|
1001
|
+
`SSE reconnection failed after ${maxReconnects} attempts`
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
if (signal?.aborted) return;
|
|
1005
|
+
onReconnect?.(reconnectAttempts);
|
|
1006
|
+
const delay = Math.min(
|
|
1007
|
+
reconnectDelay * 2 ** (reconnectAttempts - 1),
|
|
1008
|
+
3e4
|
|
1009
|
+
);
|
|
1010
|
+
await new Promise((resolve3) => {
|
|
1011
|
+
const timer = setTimeout(resolve3, delay);
|
|
1012
|
+
if (signal) {
|
|
1013
|
+
const onAbort = () => {
|
|
1014
|
+
clearTimeout(timer);
|
|
1015
|
+
resolve3();
|
|
1016
|
+
};
|
|
1017
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
840
1023
|
export {
|
|
841
1024
|
output,
|
|
842
1025
|
VERSION,
|
|
@@ -852,6 +1035,7 @@ export {
|
|
|
852
1035
|
setGlobalConfig,
|
|
853
1036
|
getConfigDir,
|
|
854
1037
|
isLoggedIn,
|
|
1038
|
+
checkAuthSourceMismatch,
|
|
855
1039
|
getProfileConfig,
|
|
856
1040
|
getProfileAuth,
|
|
857
1041
|
getAuthMethod,
|
|
@@ -864,7 +1048,7 @@ export {
|
|
|
864
1048
|
ApiError,
|
|
865
1049
|
isRushError,
|
|
866
1050
|
setVerbosity,
|
|
867
|
-
|
|
868
|
-
|
|
1051
|
+
createClient,
|
|
1052
|
+
consumeSSEStreamWithReconnect
|
|
869
1053
|
};
|
|
870
|
-
//# sourceMappingURL=chunk-
|
|
1054
|
+
//# sourceMappingURL=chunk-SZO6LEQX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/output/logger.ts","../src/version.ts","../src/util/config.ts","../src/util/auth.ts","../src/util/errors.ts","../src/util/verbosity.ts","../src/util/auth-session.ts","../src/util/retry.ts","../src/util/client.ts","../src/util/sse.ts"],"sourcesContent":["import chalk from 'chalk';\n\n/**\n * Output utilities.\n *\n * Design principle: stdout is for **content** (data the user wants to pipe/redirect).\n * Status messages (success, warn, info, dim) go to **stderr** so they don't pollute pipes.\n *\n * rush-ai task create --agent rush --prompt \"generate HTML\" --json > task.json\n * # stdout → task.json (task data)\n * # stderr → \"Success! Task xxx created.\" (status info, visible in terminal)\n */\nexport const output = {\n /** Content output → stdout. Use for data the user may pipe/redirect. */\n log(message: string): void {\n console.log(message);\n },\n\n /** Status → stderr */\n success(message: string): void {\n console.error(chalk.green('Success!'), message);\n },\n\n /** Error → stderr */\n error(message: string): void {\n console.error(chalk.red('Error:'), message);\n },\n\n /** Warning → stderr */\n warn(message: string): void {\n console.error(chalk.yellow('Warning:'), message);\n },\n\n /** Info → stderr */\n info(message: string): void {\n console.error(chalk.cyan('Info:'), message);\n },\n\n /** Dim status → stderr */\n dim(message: string): void {\n console.error(chalk.dim(message));\n },\n\n table(data: Record<string, string>[]): void {\n console.table(data);\n },\n\n /** Newline → stderr (status separator) */\n newline(): void {\n console.error();\n },\n\n link(text: string, url: string): string {\n return chalk.cyan.underline(url);\n },\n\n bold(text: string): string {\n return chalk.bold(text);\n },\n};\n","import { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\n/**\n * Dynamically read version from package.json.\n *\n * Path resolution:\n * - tsup bundle: dist/index.js → __dirname = dist/ → ../package.json\n * - vitest source: src/version.ts → __dirname = src/ → ../package.json\n */\nexport function loadVersion(): string {\n const __dirname = dirname(fileURLToPath(import.meta.url));\n\n const candidates = [\n resolve(__dirname, '..', 'package.json'),\n resolve(__dirname, '..', '..', 'package.json'),\n ];\n\n for (const candidate of candidates) {\n try {\n const pkg = JSON.parse(readFileSync(candidate, 'utf-8'));\n if (pkg.name === 'rush-ai' && pkg.version) {\n return pkg.version;\n }\n } catch {\n // try next candidate\n }\n }\n console.error('[rush-ai] Warning: Could not read version from package.json');\n return '0.0.0-unknown';\n}\n\nexport const VERSION: string = loadVersion();\n","import { homedir } from 'node:os';\nimport { resolve } from 'node:path';\nimport Conf from 'conf';\n\nexport interface AuthConfig {\n token: string | null;\n expiresAt: number | null;\n refreshToken: string | null;\n /** How the token was obtained */\n method: 'cas' | 'api_key' | 'platform_token' | null;\n /** Platform Token jti (for remote revocation via DELETE /api/platform-tokens?id={tokenId}) */\n tokenId: string | null;\n /**\n * API base URL the token was issued against. Stored at login so we can\n * detect when the current profile's API URL drifts from where the token\n * came from (e.g. `config set api` pointed at a different environment).\n * `null` for tokens migrated from the v2 schema — treated as \"unknown\n * origin\", so we don't flag false positives on upgrade.\n */\n sourceUrl: string | null;\n}\n\nexport interface GlobalConfig {\n currentTeam: string | null;\n api: string;\n collectMetrics: boolean;\n}\n\nexport interface ProjectConfig {\n projectId: string | null;\n orgId: string | null;\n}\n\n// --- Profile store types ---\n\ninterface ProfiledGlobalStore {\n _version: number;\n activeProfile: string;\n profiles: Record<string, GlobalConfig>;\n}\n\ninterface ProfiledAuthStore {\n _version: number;\n [profileName: string]: AuthConfig | number; // profile entries + _version\n}\n\nconst AUTH_CONFIG_DIR = resolve(homedir(), '.rush');\nconst DEFAULT_API = 'https://rush.zhenguanyu.com';\n\nconst AUTH_DEFAULTS: AuthConfig = {\n token: null,\n expiresAt: null,\n refreshToken: null,\n method: null,\n tokenId: null,\n sourceUrl: null,\n};\n\nconst GLOBAL_DEFAULTS: GlobalConfig = {\n currentTeam: null,\n api: DEFAULT_API,\n collectMetrics: true,\n};\n\n// --- Raw stores (untyped to support migration) ---\n\nconst globalStore = new Conf<Record<string, unknown>>({\n projectName: 'rush-ai',\n cwd: AUTH_CONFIG_DIR,\n configName: 'config',\n defaults: {},\n});\n\nconst authStore = new Conf<Record<string, unknown>>({\n projectName: 'rush-ai',\n cwd: AUTH_CONFIG_DIR,\n configName: 'auth',\n defaults: {},\n});\n\n// --- Migration ---\n\nfunction migrateGlobalStoreIfNeeded(): void {\n const version = globalStore.get('_version');\n if (version === 2) return; // Already migrated\n\n // Check if this is old format (has 'api' at top level but no 'profiles')\n const hasOldFormat = globalStore.has('api') && !globalStore.has('profiles');\n const isEmpty = globalStore.size === 0;\n\n if (hasOldFormat) {\n // Migrate old flat format → profile format\n const oldConfig: GlobalConfig = {\n currentTeam: (globalStore.get('currentTeam') as string | null) ?? null,\n api: (globalStore.get('api') as string) ?? DEFAULT_API,\n collectMetrics: (globalStore.get('collectMetrics') as boolean) ?? true,\n };\n\n globalStore.clear();\n globalStore.set('_version', 2);\n globalStore.set('activeProfile', 'default');\n globalStore.set('profiles', { default: oldConfig });\n } else if (isEmpty || !globalStore.has('profiles')) {\n // Fresh install or incomplete state — initialize\n globalStore.set('_version', 2);\n if (!globalStore.has('activeProfile')) {\n globalStore.set('activeProfile', 'default');\n }\n if (!globalStore.has('profiles')) {\n globalStore.set('profiles', { default: { ...GLOBAL_DEFAULTS } });\n }\n }\n}\n\nfunction migrateAuthStoreIfNeeded(): void {\n const version = authStore.get('_version');\n if (version === 3) return;\n\n // v1 → v3: legacy flat format (`token` at top level).\n const hasOldFormat = authStore.has('token') || authStore.has('method');\n const isEmpty = authStore.size === 0;\n\n if (hasOldFormat) {\n const oldAuth: AuthConfig = {\n token: (authStore.get('token') as string | null) ?? null,\n expiresAt: (authStore.get('expiresAt') as number | null) ?? null,\n refreshToken: (authStore.get('refreshToken') as string | null) ?? null,\n method: (authStore.get('method') as AuthConfig['method']) ?? null,\n tokenId: (authStore.get('tokenId') as string | null) ?? null,\n sourceUrl: null,\n };\n\n authStore.clear();\n authStore.set('_version', 3);\n authStore.set('default', oldAuth);\n return;\n }\n\n if (isEmpty) {\n authStore.set('_version', 3);\n return;\n }\n\n // v2 → v3: profile-shaped but missing `sourceUrl`. Backfill null.\n if (version === 2) {\n for (const key of Object.keys(authStore.store)) {\n if (key === '_version') continue;\n const entry = authStore.get(key);\n if (!entry || typeof entry !== 'object') continue;\n const asAuth = entry as Record<string, unknown>;\n if (!('sourceUrl' in asAuth)) {\n authStore.set(key, { ...asAuth, sourceUrl: null });\n }\n }\n authStore.set('_version', 3);\n }\n}\n\n// Run migrations on module load\nmigrateGlobalStoreIfNeeded();\nmigrateAuthStoreIfNeeded();\n\n// --- Profile helpers ---\n\n/**\n * Get the active profile name.\n * RUSH_PROFILE env var takes precedence over stored activeProfile.\n */\nexport function getActiveProfile(): string {\n return (\n process.env.RUSH_PROFILE ??\n (globalStore.get('activeProfile') as string) ??\n 'default'\n );\n}\n\nexport function setActiveProfile(name: string): void {\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n if (!profiles[name]) {\n throw new Error(\n `Profile '${name}' does not exist. Available: ${Object.keys(profiles).join(', ')}`\n );\n }\n globalStore.set('activeProfile', name);\n}\n\nexport function listProfiles(): string[] {\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n return Object.keys(profiles);\n}\n\nexport function createProfile(\n name: string,\n config?: Partial<GlobalConfig>\n): void {\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n if (profiles[name]) {\n throw new Error(`Profile '${name}' already exists.`);\n }\n // Inherit from default profile\n const defaultConfig = profiles.default ?? GLOBAL_DEFAULTS;\n profiles[name] = { ...defaultConfig, ...config };\n globalStore.set('profiles', profiles);\n}\n\nexport function deleteProfile(name: string): void {\n if (name === 'default') {\n throw new Error(\"Cannot delete the 'default' profile.\");\n }\n const active = getActiveProfile();\n if (name === active) {\n throw new Error(\n `Cannot delete the active profile '${name}'. Switch to another profile first.`\n );\n }\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n if (!profiles[name]) {\n throw new Error(`Profile '${name}' does not exist.`);\n }\n delete profiles[name];\n globalStore.set('profiles', profiles);\n\n // Also clear auth for this profile\n authStore.delete(name);\n}\n\n// --- Auth config (profile-aware) ---\n\nexport function getAuthConfig(): AuthConfig {\n const profile = getActiveProfile();\n const profileAuth = authStore.get(profile) as AuthConfig | undefined;\n return {\n token: profileAuth?.token ?? null,\n expiresAt: profileAuth?.expiresAt ?? null,\n refreshToken: profileAuth?.refreshToken ?? null,\n method: profileAuth?.method ?? null,\n tokenId: profileAuth?.tokenId ?? null,\n sourceUrl: profileAuth?.sourceUrl ?? null,\n };\n}\n\nexport function setAuthConfig(config: Partial<AuthConfig>): void {\n const profile = getActiveProfile();\n const current = (authStore.get(profile) as AuthConfig) ?? {\n ...AUTH_DEFAULTS,\n };\n authStore.set(profile, { ...current, ...config });\n}\n\n/** Clear auth for the current profile only */\nexport function clearAuthConfig(): void {\n const profile = getActiveProfile();\n authStore.set(profile, { ...AUTH_DEFAULTS });\n}\n\n/** Clear auth for ALL profiles */\nexport function clearAllAuthConfig(): void {\n const profiles = listProfiles();\n for (const profile of profiles) {\n authStore.set(profile, { ...AUTH_DEFAULTS });\n }\n}\n\n// --- Global config (profile-aware) ---\n\nexport function getGlobalConfig(): GlobalConfig {\n const profile = getActiveProfile();\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n const profileConfig = profiles[profile] ?? GLOBAL_DEFAULTS;\n return {\n currentTeam: profileConfig.currentTeam ?? null,\n api: profileConfig.api ?? DEFAULT_API,\n collectMetrics: profileConfig.collectMetrics ?? true,\n };\n}\n\nexport function setGlobalConfig(config: Partial<GlobalConfig>): void {\n const profile = getActiveProfile();\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n const current = profiles[profile] ?? { ...GLOBAL_DEFAULTS };\n profiles[profile] = { ...current, ...config };\n globalStore.set('profiles', profiles);\n}\n\nexport function getConfigDir(): string {\n return AUTH_CONFIG_DIR;\n}\n\nexport function isLoggedIn(): boolean {\n const auth = getAuthConfig();\n if (!auth.token) return false;\n if (auth.expiresAt && Date.now() > auth.expiresAt) {\n // CAS tokens with refresh_token can still be renewed lazily by the client.\n return auth.method === 'cas' && Boolean(auth.refreshToken);\n }\n return true;\n}\n\n/** Normalize an API URL for comparison — strips trailing slashes + lowercases. */\nexport function normalizeApiUrl(url: string): string {\n return url.replace(/\\/+$/, '').toLowerCase();\n}\n\n/**\n * If the current profile's token was issued against a different API URL than\n * the profile currently points to, return both sides so the caller can prompt\n * the user to re-authenticate. Returns null when no mismatch (or when the\n * stored `sourceUrl` is null — migrated tokens with unknown origin). The\n * caller decides what to do; this function does NOT mutate or clear anything.\n *\n * @param overrideCurrentUrl use this URL instead of reading the current\n * global config. Useful when evaluating mismatch BEFORE writing a new API\n * URL in `config set`.\n */\nexport function checkAuthSourceMismatch(\n overrideCurrentUrl?: string\n): { stored: string; current: string } | null {\n const auth = getAuthConfig();\n if (!auth.token || !auth.sourceUrl) return null;\n const current = overrideCurrentUrl ?? getGlobalConfig().api;\n if (normalizeApiUrl(auth.sourceUrl) === normalizeApiUrl(current)) return null;\n return { stored: auth.sourceUrl, current };\n}\n\n/**\n * Get the config for a specific profile (for display purposes).\n */\nexport function getProfileConfig(name: string): GlobalConfig | null {\n const profiles =\n (globalStore.get('profiles') as Record<string, GlobalConfig>) ?? {};\n return profiles[name] ?? null;\n}\n\n/**\n * Get auth config for a specific profile (for display purposes).\n */\nexport function getProfileAuth(name: string): AuthConfig {\n const profileAuth = authStore.get(name) as AuthConfig | undefined;\n return {\n token: profileAuth?.token ?? null,\n expiresAt: profileAuth?.expiresAt ?? null,\n refreshToken: profileAuth?.refreshToken ?? null,\n method: profileAuth?.method ?? null,\n tokenId: profileAuth?.tokenId ?? null,\n sourceUrl: profileAuth?.sourceUrl ?? null,\n };\n}\n","import { getAuthConfig, getGlobalConfig } from './config.js';\n\nexport type AuthMethod = 'api_key' | 'cas' | 'platform_token' | null;\n\n/**\n * Determine the current authentication method.\n * Priority: RUSH_API_KEY env > stored CAS token > null\n */\nexport function getAuthMethod(): AuthMethod {\n if (process.env.RUSH_API_KEY) {\n return 'api_key';\n }\n const auth = getAuthConfig();\n if (auth.token) {\n // Use stored method if available; detect rush_sk_ prefix as fallback\n if (auth.method === 'api_key' || auth.token.startsWith('rush_sk_')) {\n return 'api_key';\n }\n if (auth.method === 'platform_token') {\n return 'platform_token';\n }\n return auth.method ?? 'cas';\n }\n return null;\n}\n\n/**\n * Get the active auth token.\n * Priority: RUSH_API_KEY env > stored token\n */\nexport function getAuthToken(): string | null {\n if (process.env.RUSH_API_KEY) {\n return process.env.RUSH_API_KEY;\n }\n const auth = getAuthConfig();\n return auth.token;\n}\n\nexport interface CasConfig {\n authorizeEndpoint: string;\n tokenEndpoint: string;\n revokeEndpoint: string;\n clientId: string;\n}\n\n/**\n * Get CAS PKCE configuration.\n * Supports env overrides for private deployments.\n */\nexport function getCasConfig(): CasConfig {\n const config = getGlobalConfig();\n const baseUrl = process.env.RUSH_API_URL ?? config.api;\n\n return {\n authorizeEndpoint:\n process.env.RUSH_CAS_AUTHORIZE_ENDPOINT ??\n `${baseUrl}/cas/oauth2/authorize`,\n tokenEndpoint:\n process.env.RUSH_CAS_TOKEN_ENDPOINT ?? `${baseUrl}/cas/oauth2/token`,\n revokeEndpoint:\n process.env.RUSH_CAS_REVOKE_ENDPOINT ?? `${baseUrl}/cas/oauth2/revoke`,\n clientId: process.env.RUSH_CAS_CLIENT_ID ?? 'rush-ai',\n };\n}\n\nexport interface Principal {\n provider: 'ldap' | 'service';\n subject: string;\n}\n\n/**\n * Build a Principal object from the current auth context.\n * M1: only ldap is supported.\n */\nexport function getPrincipal(subject: string): Principal {\n const method = getAuthMethod();\n return {\n provider: method === 'api_key' ? 'service' : 'ldap',\n subject,\n };\n}\n","export class RushError extends Error {\n public code: string;\n public meta: Record<string, unknown>;\n public exitCode: number;\n\n constructor(\n message: string,\n meta: Record<string, unknown> = {},\n code = 'RUSH_ERROR',\n exitCode = 2\n ) {\n super(message);\n this.name = 'RushError';\n this.code = code;\n this.meta = meta;\n this.exitCode = exitCode;\n }\n}\n\nexport class AuthError extends RushError {\n constructor(message = 'Not authenticated. Run `rush-ai auth login` first.') {\n super(message, {}, 'AUTH_ERROR', 3);\n this.name = 'AuthError';\n }\n}\n\nexport class TaskFailedError extends RushError {\n constructor(message: string, meta: Record<string, unknown> = {}) {\n super(message, meta, 'TASK_FAILED', 1);\n this.name = 'TaskFailedError';\n }\n}\n\n/**\n * Generate a user-friendly error message based on HTTP status.\n * Server-provided error messages take priority.\n */\nfunction friendlyMessage(status: number, serverMessage?: string): string {\n if (serverMessage) return serverMessage;\n\n switch (status) {\n case 401:\n return 'Authentication expired. Run `rush-ai auth login` to re-authenticate.';\n case 403:\n return 'Permission denied. You may not have access to this resource.';\n case 404:\n return 'Resource not found.';\n case 429:\n return 'Rate limited. The server is busy, please try again later.';\n case 502:\n case 503:\n case 504:\n return 'Service temporarily unavailable. Please try again in a moment.';\n default:\n return `Request failed with status ${status}.`;\n }\n}\n\nexport class ApiError extends RushError {\n public status: number;\n public retryAfter?: string;\n\n constructor(\n message: string,\n status: number,\n body?: string,\n retryAfter?: string\n ) {\n // Try to extract server error message from body\n let serverMessage: string | undefined;\n if (body) {\n try {\n const parsed = JSON.parse(body);\n if (parsed.error && typeof parsed.error === 'string') {\n serverMessage = parsed.error;\n }\n } catch {\n // Not JSON\n }\n }\n\n super(\n friendlyMessage(status, serverMessage),\n { status, body },\n 'API_ERROR'\n );\n this.name = 'ApiError';\n this.status = status;\n this.retryAfter = retryAfter;\n }\n}\n\nexport function isRushError(error: unknown): error is RushError {\n return error instanceof RushError;\n}\n","let _verbose = false;\nlet _debug = false;\n\nexport function setVerbosity(verbose: boolean, debug: boolean): void {\n _debug = debug;\n _verbose = verbose || debug;\n}\n\nexport const isVerbose = (): boolean => _verbose;\nexport const isDebug = (): boolean => _debug;\n","import { getAuthToken, getCasConfig } from './auth.js';\nimport { getAuthConfig, getGlobalConfig, setAuthConfig } from './config.js';\n\nconst VERIFY_PATH = '/api/skill-auth/me';\nconst REFRESH_SKEW_MS = 60_000;\nconst AUTH_REQUEST_TIMEOUT_MS = 8_000;\n\ninterface RefreshTokenResponse {\n access_token: string;\n expires_in?: number;\n refresh_token?: string;\n}\n\nexport interface AuthVerificationResult {\n valid: boolean;\n status: number | null;\n message?: string;\n}\n\nexport interface RefreshOptions {\n force?: boolean;\n refreshWindowMs?: number;\n}\n\nfunction getApiBaseUrl(): string {\n return process.env.RUSH_API_URL ?? getGlobalConfig().api;\n}\n\nfunction buildBearerHeaders(token: string): Record<string, string> {\n return {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n 'User-Agent': 'rush-ai/0.2.0',\n };\n}\n\nfunction shouldRefreshToken(options?: RefreshOptions): boolean {\n const auth = getAuthConfig();\n // Platform tokens don't support refresh; only CAS tokens do\n if (!auth.token || auth.method !== 'cas' || !auth.refreshToken) {\n return false;\n }\n if (options?.force) {\n return true;\n }\n if (!auth.expiresAt) {\n return false;\n }\n const refreshWindowMs = options?.refreshWindowMs ?? REFRESH_SKEW_MS;\n return Date.now() >= auth.expiresAt - refreshWindowMs;\n}\n\nexport async function refreshCasAccessToken(\n options?: RefreshOptions\n): Promise<boolean> {\n if (process.env.RUSH_API_KEY || !shouldRefreshToken(options)) {\n return false;\n }\n\n const auth = getAuthConfig();\n if (!auth.refreshToken) {\n return false;\n }\n\n const cas = getCasConfig();\n const body = new URLSearchParams({\n grant_type: 'refresh_token',\n refresh_token: auth.refreshToken,\n client_id: cas.clientId,\n }).toString();\n\n try {\n const response = await fetch(cas.tokenEndpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body,\n signal: AbortSignal.timeout(AUTH_REQUEST_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n return false;\n }\n\n const tokenData = (await response.json()) as RefreshTokenResponse;\n if (!tokenData.access_token) {\n return false;\n }\n\n const expiresAt = tokenData.expires_in\n ? Date.now() + tokenData.expires_in * 1000\n : auth.expiresAt;\n\n setAuthConfig({\n token: tokenData.access_token,\n expiresAt,\n refreshToken: tokenData.refresh_token ?? auth.refreshToken,\n method: 'cas',\n });\n\n return true;\n } catch {\n return false;\n }\n}\n\nexport async function verifyTokenOnline(\n token: string\n): Promise<AuthVerificationResult> {\n const url = `${getApiBaseUrl()}${VERIFY_PATH}`;\n\n try {\n const response = await fetch(url, {\n method: 'GET',\n headers: buildBearerHeaders(token),\n signal: AbortSignal.timeout(AUTH_REQUEST_TIMEOUT_MS),\n });\n\n if (response.ok) {\n return { valid: true, status: response.status };\n }\n\n const message = await response.text().catch(() => undefined);\n return {\n valid: false,\n status: response.status,\n message: message || `Server rejected token (${response.status})`,\n };\n } catch (error) {\n return {\n valid: false,\n status: null,\n message: `Network error: ${error instanceof Error ? error.message : 'unknown'}`,\n };\n }\n}\n\nexport async function verifyCurrentAuthSession(): Promise<AuthVerificationResult> {\n const token = getAuthToken();\n if (!token) {\n return {\n valid: false,\n status: null,\n message: 'Not authenticated',\n };\n }\n\n await refreshCasAccessToken();\n\n let activeToken = getAuthToken();\n if (!activeToken) {\n return {\n valid: false,\n status: null,\n message: 'Not authenticated',\n };\n }\n\n const result = await verifyTokenOnline(activeToken);\n if (result.valid || result.status !== 401 || process.env.RUSH_API_KEY) {\n return result;\n }\n\n const refreshed = await refreshCasAccessToken({ force: true });\n if (!refreshed) {\n return result;\n }\n\n activeToken = getAuthToken();\n if (!activeToken) {\n return result;\n }\n return verifyTokenOnline(activeToken);\n}\n\nasync function revokeToken(\n revokeEndpoint: string,\n clientId: string,\n token: string,\n tokenTypeHint: 'access_token' | 'refresh_token'\n): Promise<boolean> {\n const body = new URLSearchParams({\n token,\n token_type_hint: tokenTypeHint,\n client_id: clientId,\n }).toString();\n\n try {\n const response = await fetch(revokeEndpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body,\n signal: AbortSignal.timeout(AUTH_REQUEST_TIMEOUT_MS),\n });\n return response.ok;\n } catch {\n return false;\n }\n}\n\nexport async function revokeCurrentSession(): Promise<boolean> {\n if (process.env.RUSH_API_KEY) {\n return false;\n }\n\n const auth = getAuthConfig();\n\n if (auth.method === 'platform_token') {\n return revokePlatformToken();\n }\n\n if (auth.method !== 'cas') {\n return false;\n }\n\n const cas = getCasConfig();\n const candidates: Array<{\n token: string;\n hint: 'access_token' | 'refresh_token';\n }> = [];\n if (auth.refreshToken) {\n candidates.push({ token: auth.refreshToken, hint: 'refresh_token' });\n }\n if (auth.token) {\n candidates.push({ token: auth.token, hint: 'access_token' });\n }\n\n if (candidates.length === 0) {\n return false;\n }\n\n let anyRevoked = false;\n for (const candidate of candidates) {\n const revoked = await revokeToken(\n cas.revokeEndpoint,\n cas.clientId,\n candidate.token,\n candidate.hint\n );\n if (revoked) {\n anyRevoked = true;\n }\n }\n\n return anyRevoked;\n}\n\n/** @deprecated Use revokeCurrentSession instead */\nexport const revokeCurrentCasSession = revokeCurrentSession;\n\nasync function revokePlatformToken(): Promise<boolean> {\n const auth = getAuthConfig();\n if (!auth.tokenId || !auth.token) {\n return false;\n }\n\n const baseUrl = getApiBaseUrl();\n const url = `${baseUrl}/api/platform-tokens?id=${encodeURIComponent(auth.tokenId)}`;\n\n try {\n const response = await fetch(url, {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${auth.token}`,\n 'User-Agent': 'rush-ai/0.2.0',\n },\n signal: AbortSignal.timeout(AUTH_REQUEST_TIMEOUT_MS),\n });\n return response.ok;\n } catch {\n return false;\n }\n}\n","import { ApiError, RushError } from './errors.js';\n\nexport interface RetryOptions {\n /** Maximum number of retries (default: 3, total attempts = maxRetries + 1) */\n maxRetries?: number;\n /** Base delay in ms for exponential backoff (default: 1000) */\n baseDelay?: number;\n /** Maximum delay in ms (default: 30000) */\n maxDelay?: number;\n /** HTTP status codes eligible for retry (default: [429, 502, 503, 504]) */\n retryableStatuses?: number[];\n /** AbortSignal to cancel retries */\n signal?: AbortSignal;\n /** Called before each retry with attempt number (1-based) and delay in ms */\n onRetry?: (attempt: number, delayMs: number, status?: number) => void;\n}\n\n/**\n * Parse the Retry-After HTTP header value.\n * Supports both seconds (integer) and HTTP-date formats.\n * Returns delay in milliseconds, or null if unparseable.\n */\nexport function parseRetryAfter(value: string): number | null {\n // Try as integer seconds first\n const seconds = Number(value);\n if (!Number.isNaN(seconds) && seconds >= 0) {\n return seconds * 1000;\n }\n\n // Try as HTTP-date\n const date = new Date(value);\n if (!Number.isNaN(date.getTime())) {\n const delayMs = date.getTime() - Date.now();\n return delayMs > 0 ? delayMs : 0;\n }\n\n return null;\n}\n\n/**\n * Calculate delay with exponential backoff and jitter.\n */\nfunction calculateDelay(\n attempt: number,\n baseDelay: number,\n maxDelay: number\n): number {\n const exponential = baseDelay * 2 ** attempt;\n const jitter = Math.random() * baseDelay * 0.5;\n return Math.min(exponential + jitter, maxDelay);\n}\n\nfunction isRetryableError(\n error: unknown,\n retryableStatuses: number[]\n): boolean {\n // Network errors (fetch failures) are retryable\n if (error instanceof RushError && error.code === 'NETWORK_ERROR') {\n return true;\n }\n\n // API errors with retryable status codes\n if (error instanceof ApiError && retryableStatuses.includes(error.status)) {\n return true;\n }\n\n return false;\n}\n\nfunction getRetryAfterFromError(error: unknown): number | null {\n if (error instanceof ApiError && error.status === 429) {\n // Use Retry-After HTTP header (propagated via ApiError.retryAfter)\n if (error.retryAfter) {\n return parseRetryAfter(error.retryAfter);\n }\n }\n return null;\n}\n\n/**\n * Wrap an async function with retry logic using exponential backoff.\n *\n * Important: This should only be used for idempotent operations.\n * The caller (RushClient) is responsible for only wrapping GET/HEAD/DELETE.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: RetryOptions = {}\n): Promise<T> {\n const {\n maxRetries = 3,\n baseDelay = 1000,\n maxDelay = 30_000,\n retryableStatuses = [429, 502, 503, 504],\n signal,\n onRetry,\n } = options;\n\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n // Check abort before each attempt\n if (signal?.aborted) {\n throw lastError ?? new RushError('Request aborted', {}, 'ABORT_ERROR');\n }\n\n try {\n return await fn();\n } catch (error) {\n lastError = error;\n\n // Don't retry if this is the last attempt\n if (attempt >= maxRetries) {\n throw error;\n }\n\n // Don't retry non-retryable errors\n if (!isRetryableError(error, retryableStatuses)) {\n throw error;\n }\n\n // Check abort before waiting\n if (signal?.aborted) {\n throw error;\n }\n\n // Calculate delay: use Retry-After if available (for 429), otherwise backoff\n let delayMs: number;\n const retryAfterMs = getRetryAfterFromError(error);\n if (retryAfterMs !== null) {\n // Cap Retry-After at 120 seconds\n delayMs = Math.min(retryAfterMs, 120_000);\n } else {\n delayMs = calculateDelay(attempt, baseDelay, maxDelay);\n }\n\n const status = error instanceof ApiError ? error.status : undefined;\n onRetry?.(attempt + 1, delayMs, status);\n\n // Wait with abort support\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, delayMs);\n if (signal) {\n const onAbort = () => {\n clearTimeout(timer);\n reject(lastError);\n };\n signal.addEventListener('abort', onAbort, { once: true });\n // Clean up listener after timer fires\n const origResolve = resolve;\n setTimeout(() => {\n signal.removeEventListener('abort', onAbort);\n origResolve();\n }, delayMs);\n }\n });\n }\n }\n\n // Should never reach here, but TypeScript needs it\n throw lastError;\n}\n","import { output } from '../output/logger.js';\nimport { VERSION } from '../version.js';\nimport { getAuthToken } from './auth.js';\nimport { refreshCasAccessToken } from './auth-session.js';\nimport { getAuthConfig, getGlobalConfig } from './config.js';\nimport { ApiError, RushError } from './errors.js';\nimport { withRetry } from './retry.js';\nimport { isDebug, isVerbose } from './verbosity.js';\n\nconst SENSITIVE_HEADERS = [\n 'authorization',\n 'cookie',\n 'set-cookie',\n 'x-api-key',\n];\n\nfunction maskSensitiveHeaders(headers: Headers): Record<string, string> {\n const result: Record<string, string> = {};\n headers.forEach((value, key) => {\n result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase())\n ? '[REDACTED]'\n : value;\n });\n return result;\n}\n\nexport interface FetchOptions extends RequestInit {\n json?: boolean;\n}\n\nexport interface ApiResponse<T = unknown> {\n ok: boolean;\n status: number;\n data: T;\n}\n\nexport interface ApiErrorBody {\n error: string;\n code: string;\n retryable: boolean;\n}\n\nexport class RushClient {\n private baseUrl: string;\n\n constructor() {\n const config = getGlobalConfig();\n const raw = process.env.RUSH_API_URL ?? config.api;\n this.baseUrl = raw.replace(/\\/+$/, '');\n }\n\n private async getHeaders(): Promise<Record<string, string>> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'User-Agent': `rush-ai/${VERSION}`,\n };\n\n if (!process.env.RUSH_API_KEY) {\n await refreshCasAccessToken();\n }\n\n const token = getAuthToken();\n if (token) {\n // Both CAS token and service account API key (rush_sk_*) use Bearer.\n // Backend distinguishes by the rush_sk_ prefix.\n headers.Authorization = `Bearer ${token}`;\n }\n\n // Test mode: skip CAS auth in non-production environments\n if (process.env.RUSH_TEST_MODE === 'integration-test') {\n headers['X-Test-Mode'] = 'integration-test';\n }\n\n return headers;\n }\n\n /**\n * Merge default headers with per-request overrides. A `null` override value\n * drops the default entirely — used by multipart POSTs that need fetch to\n * synthesize its own Content-Type with a boundary. An empty string stays as\n * an empty-value header so callers can still send one intentionally.\n */\n private mergeHeaders(\n base: Record<string, string>,\n overrides: Record<string, string | null>\n ): Record<string, string> {\n const merged: Record<string, string> = { ...base };\n for (const [key, value] of Object.entries(overrides)) {\n if (value === null) {\n delete merged[key];\n } else {\n merged[key] = value;\n }\n }\n return merged;\n }\n\n private async performRequest(\n url: string,\n options: RequestInit,\n retryOnUnauthorized = true\n ): Promise<Response> {\n // Override headers may use `null` as a sentinel to drop a default\n // (see mergeHeaders). The public fetch signature doesn't know about this,\n // so we cast narrowly here.\n const requestHeaders =\n (options.headers as Record<string, string | null>) ?? {};\n const headers = await this.getHeaders();\n\n try {\n const response = await fetch(url, {\n ...options,\n headers: this.mergeHeaders(headers, requestHeaders),\n });\n\n if (\n response.status === 401 &&\n retryOnUnauthorized &&\n !process.env.RUSH_API_KEY\n ) {\n const auth = getAuthConfig();\n const canRefresh = auth.method === 'cas' && Boolean(auth.refreshToken);\n if (canRefresh && (await refreshCasAccessToken({ force: true }))) {\n const retryHeaders = await this.getHeaders();\n return await fetch(url, {\n ...options,\n headers: this.mergeHeaders(retryHeaders, requestHeaders),\n });\n }\n }\n\n return response;\n } catch (err) {\n throw new RushError(\n `Network error: ${err instanceof Error ? err.message : 'Failed to connect'}`,\n { url },\n 'NETWORK_ERROR'\n );\n }\n }\n\n /** Idempotent HTTP methods eligible for automatic retry */\n private static readonly RETRYABLE_METHODS = ['GET', 'HEAD', 'DELETE'];\n\n /**\n * Internal fetch with response parsing and error handling (no retry).\n */\n private async _doFetch<T = unknown>(\n path: string,\n options: FetchOptions = {}\n ): Promise<ApiResponse<T>> {\n const { json = true, ...fetchOptions } = options;\n const url = `${this.baseUrl}${path}`;\n const method = (fetchOptions.method ?? 'GET').toUpperCase();\n const startTime = Date.now();\n\n if (isVerbose()) {\n output.dim(`→ ${method} ${url}`);\n }\n\n const response = await this.performRequest(url, fetchOptions);\n\n if (isVerbose()) {\n output.dim(\n `← ${response.status} ${response.statusText} (${Date.now() - startTime}ms)`\n );\n }\n\n if (isDebug()) {\n output.dim(\n ` Response headers: ${JSON.stringify(maskSensitiveHeaders(response.headers))}`\n );\n }\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => 'Unknown error');\n const retryAfter = response.headers.get('retry-after') ?? undefined;\n\n throw new ApiError(\n `API request failed: ${response.status} ${response.statusText}`,\n response.status,\n errorBody,\n retryAfter\n );\n }\n\n const data = json\n ? ((await response.json()) as T)\n : ((await response.text()) as T);\n\n return {\n ok: true,\n status: response.status,\n data,\n };\n }\n\n /**\n * Fetch with response parsing, error handling, and automatic retry\n * for idempotent methods (GET, HEAD, DELETE).\n */\n async fetch<T = unknown>(\n path: string,\n options: FetchOptions = {}\n ): Promise<ApiResponse<T>> {\n const method = (options.method ?? 'GET').toUpperCase();\n const isRetryable = RushClient.RETRYABLE_METHODS.includes(method);\n\n if (!isRetryable) {\n return this._doFetch<T>(path, options);\n }\n\n return withRetry(() => this._doFetch<T>(path, options), {\n signal: options.signal ?? undefined,\n onRetry: (attempt, delayMs, status) => {\n const statusInfo = status ? ` (${status})` : '';\n console.error(\n `\\u27F3 Retrying ${method} ${path}${statusInfo} (attempt ${attempt}) in ${(delayMs / 1000).toFixed(1)}s...`\n );\n },\n });\n }\n\n /**\n * Raw fetch for streaming (SSE) responses.\n * Returns the raw Response object.\n */\n async fetchRaw(path: string, options: RequestInit = {}): Promise<Response> {\n const url = `${this.baseUrl}${path}`;\n\n const response = await this.performRequest(url, options);\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => 'Unknown error');\n throw new ApiError(\n `API request failed: ${response.status} ${response.statusText}`,\n response.status,\n errorBody\n );\n }\n\n return response;\n }\n\n async get<T = unknown>(path: string): Promise<ApiResponse<T>> {\n return this.fetch<T>(path, { method: 'GET' });\n }\n\n async post<T = unknown>(\n path: string,\n body?: unknown\n ): Promise<ApiResponse<T>> {\n return this.fetch<T>(path, {\n method: 'POST',\n body: body ? JSON.stringify(body) : undefined,\n });\n }\n\n /**\n * POST multipart/form-data. The default `Content-Type: application/json`\n * must be removed so fetch can set its own multipart boundary — passing\n * `null` as the header value tells mergeHeaders to drop the key.\n */\n async postFormData<T = unknown>(\n path: string,\n formData: FormData\n ): Promise<ApiResponse<T>> {\n return this._doFetch<T>(path, {\n method: 'POST',\n body: formData,\n // Cast: RequestInit.headers doesn't include null; mergeHeaders handles it.\n headers: { 'Content-Type': null } as unknown as HeadersInit,\n });\n }\n\n async put<T = unknown>(\n path: string,\n body?: unknown\n ): Promise<ApiResponse<T>> {\n return this.fetch<T>(path, {\n method: 'PUT',\n body: body ? JSON.stringify(body) : undefined,\n });\n }\n\n async delete<T = unknown>(path: string): Promise<ApiResponse<T>> {\n return this.fetch<T>(path, { method: 'DELETE' });\n }\n}\n\nexport function createClient(): RushClient {\n return new RushClient();\n}\n","/**\n * SSE (Server-Sent Events) line-buffered parser.\n * Handles events split across multiple chunks.\n */\nexport interface SSEEvent {\n type: string;\n data: string;\n}\n\nexport function createSSEParser(\n onEvent: (event: SSEEvent) => void,\n onDone?: () => void\n) {\n let buffer = '';\n\n return {\n feed(chunk: string): void {\n buffer += chunk;\n const lines = buffer.split('\\n');\n // Keep the last (possibly incomplete) line in the buffer\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n const data = line.slice(6);\n if (data === '[DONE]') {\n onDone?.();\n return;\n }\n try {\n const parsed = JSON.parse(data);\n onEvent({\n type: parsed.type ?? 'unknown',\n data:\n typeof parsed.data === 'string'\n ? parsed.data\n : JSON.stringify(parsed),\n });\n } catch {\n // Non-JSON SSE data\n onEvent({ type: 'raw', data });\n }\n }\n }\n },\n flush(): void {\n // Process any remaining buffered data\n if (buffer.startsWith('data: ')) {\n const data = buffer.slice(6);\n if (data !== '[DONE]') {\n try {\n const parsed = JSON.parse(data);\n onEvent({\n type: parsed.type ?? 'unknown',\n data:\n typeof parsed.data === 'string'\n ? parsed.data\n : JSON.stringify(parsed),\n });\n } catch {\n onEvent({ type: 'raw', data });\n }\n }\n }\n buffer = '';\n },\n };\n}\n\n/**\n * Consume an SSE ReadableStream with proper cross-chunk buffering.\n */\nexport async function consumeSSEStream(\n body: ReadableStream<Uint8Array>,\n onEvent: (event: SSEEvent) => void,\n onDone?: () => void\n): Promise<void> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n const parser = createSSEParser(onEvent, onDone);\n\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n parser.feed(decoder.decode(value, { stream: true }));\n }\n parser.flush();\n}\n\nexport interface SSEReconnectOptions {\n /** Maximum number of reconnection attempts (default: 5) */\n maxReconnects?: number;\n /** Initial reconnection delay in ms (default: 1000) */\n reconnectDelay?: number;\n /** AbortSignal to cancel the stream and reconnections */\n signal?: AbortSignal;\n /** Called before each reconnection attempt */\n onReconnect?: (attempt: number) => void;\n /**\n * Determines if an event represents a terminal state.\n * When this returns true, the stream stops and no reconnection occurs.\n */\n isTerminal?: (event: SSEEvent) => boolean;\n}\n\n/**\n * Consume an SSE stream with automatic reconnection and event deduplication.\n *\n * Key behaviors:\n * - [DONE] does NOT automatically stop the stream. Only `isTerminal(event)` stops it.\n * - If [DONE] is received without a terminal event, reconnection is triggered\n * (e.g., server 5-minute SSE connection lifetime timeout).\n * - On reconnection, the server replays all historical events from epoch.\n * Client-side deduplication skips already-seen events using an event counter.\n *\n * @param connectFn - Factory that creates a new SSE stream (called on each reconnect)\n * @param onEvent - Event handler (only called for new, non-duplicate events)\n * @param options - Reconnection options\n */\nexport async function consumeSSEStreamWithReconnect(\n connectFn: () => Promise<ReadableStream<Uint8Array>>,\n onEvent: (event: SSEEvent) => void,\n options: SSEReconnectOptions = {}\n): Promise<void> {\n const {\n maxReconnects = 5,\n reconnectDelay = 1000,\n signal,\n onReconnect,\n isTerminal,\n } = options;\n\n let emittedEventCount = 0;\n let reconnectAttempts = 0;\n let terminalReached = false;\n\n while (!terminalReached) {\n if (signal?.aborted) return;\n\n let receivedDone = false;\n let currentEventIndex = 0;\n\n try {\n const stream = await connectFn();\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n\n // Note: We do NOT reset reconnectAttempts here.\n // For [DONE]+running scenarios (server 5-min timeout), each reconnect\n // should count toward the limit. The counter only resets after the\n // function is called fresh.\n\n const parser = createSSEParser(\n (event) => {\n currentEventIndex++;\n\n // Dedup: skip events we've already emitted in previous connections\n if (currentEventIndex <= emittedEventCount) {\n // Still check for terminal even on dedup'd events\n if (isTerminal?.(event)) {\n terminalReached = true;\n }\n return;\n }\n\n emittedEventCount++;\n onEvent(event);\n\n if (isTerminal?.(event)) {\n terminalReached = true;\n }\n },\n () => {\n receivedDone = true;\n }\n );\n\n for (;;) {\n if (signal?.aborted || terminalReached) {\n reader.cancel().catch(() => {});\n return;\n }\n\n const { done, value } = await reader.read();\n if (done) break;\n parser.feed(decoder.decode(value, { stream: true }));\n\n if (terminalReached) {\n reader.cancel().catch(() => {});\n return;\n }\n }\n parser.flush();\n } catch {\n // Stream error — will attempt reconnect below\n if (signal?.aborted || terminalReached) return;\n }\n\n // If terminal was reached, we're done\n if (terminalReached) return;\n\n // If [DONE] was received AND we already got a terminal event, stop\n // (This shouldn't happen because terminalReached would be true, but safety check)\n if (receivedDone && terminalReached) return;\n\n // Otherwise, reconnect: [DONE] without terminal = server timeout, or stream error\n reconnectAttempts++;\n if (reconnectAttempts > maxReconnects) {\n throw new Error(\n `SSE reconnection failed after ${maxReconnects} attempts`\n );\n }\n\n if (signal?.aborted) return;\n\n onReconnect?.(reconnectAttempts);\n\n // Exponential backoff for reconnection\n const delay = Math.min(\n reconnectDelay * 2 ** (reconnectAttempts - 1),\n 30_000\n );\n\n await new Promise<void>((resolve) => {\n const timer = setTimeout(resolve, delay);\n if (signal) {\n const onAbort = () => {\n clearTimeout(timer);\n resolve();\n };\n signal.addEventListener('abort', onAbort, { once: true });\n }\n });\n }\n}\n"],"mappings":";;;AAAA,OAAO,WAAW;AAYX,IAAM,SAAS;AAAA;AAAA,EAEpB,IAAI,SAAuB;AACzB,YAAQ,IAAI,OAAO;AAAA,EACrB;AAAA;AAAA,EAGA,QAAQ,SAAuB;AAC7B,YAAQ,MAAM,MAAM,MAAM,UAAU,GAAG,OAAO;AAAA,EAChD;AAAA;AAAA,EAGA,MAAM,SAAuB;AAC3B,YAAQ,MAAM,MAAM,IAAI,QAAQ,GAAG,OAAO;AAAA,EAC5C;AAAA;AAAA,EAGA,KAAK,SAAuB;AAC1B,YAAQ,MAAM,MAAM,OAAO,UAAU,GAAG,OAAO;AAAA,EACjD;AAAA;AAAA,EAGA,KAAK,SAAuB;AAC1B,YAAQ,MAAM,MAAM,KAAK,OAAO,GAAG,OAAO;AAAA,EAC5C;AAAA;AAAA,EAGA,IAAI,SAAuB;AACzB,YAAQ,MAAM,MAAM,IAAI,OAAO,CAAC;AAAA,EAClC;AAAA,EAEA,MAAM,MAAsC;AAC1C,YAAQ,MAAM,IAAI;AAAA,EACpB;AAAA;AAAA,EAGA,UAAgB;AACd,YAAQ,MAAM;AAAA,EAChB;AAAA,EAEA,KAAK,MAAc,KAAqB;AACtC,WAAO,MAAM,KAAK,UAAU,GAAG;AAAA,EACjC;AAAA,EAEA,KAAK,MAAsB;AACzB,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB;AACF;;;AC3DA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AASvB,SAAS,cAAsB;AACpC,QAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAExD,QAAM,aAAa;AAAA,IACjB,QAAQ,WAAW,MAAM,cAAc;AAAA,IACvC,QAAQ,WAAW,MAAM,MAAM,cAAc;AAAA,EAC/C;AAEA,aAA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