@redocly/replay 0.27.1 → 0.28.0-next.1

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 (54) hide show
  1. package/dist/{replay-AiChatProvider-Cdve_kxz.js → replay-AiChatProvider-COJYrrQ6.js} +6 -6
  2. package/dist/{replay-AiChatProvider-IuOVaWMC.js → replay-AiChatProvider-DjEmmTbN.js} +1 -1
  3. package/dist/{replay-AiChatSqliteDBStorage-jEhfZgK3.js → replay-AiChatSqliteDBStorage-BenAoLmM.js} +1 -1
  4. package/dist/{replay-AiChatSqliteDBStorage-B3aaY0Uo.js → replay-AiChatSqliteDBStorage-CBeRerfX.js} +1 -1
  5. package/dist/{replay-AiPanel-BT_RLVeR.js → replay-AiPanel-BN1uduZr.js} +37 -37
  6. package/dist/{replay-AiPanel-0GXuobhF.js → replay-AiPanel-FAJJA4QT.js} +1 -1
  7. package/dist/replay-FileWatcher-DDlINC06.js +1 -0
  8. package/dist/replay-FileWatcher-paEMsDuu.js +352 -0
  9. package/dist/{replay-SemanticSearchService--QXHzf7_.js → replay-SemanticSearchService-DwIcsNYC.js} +1 -1
  10. package/dist/{replay-SemanticSearchService-DJ_jBUyi.js → replay-SemanticSearchService-OutwGWqD.js} +1 -1
  11. package/dist/{replay-SqliteDBStorage-0JYq0UPY.js → replay-SqliteDBStorage-Cn8L_KB1.js} +1 -1
  12. package/dist/{replay-SqliteDBStorage-ClD7MBeX.js → replay-SqliteDBStorage-CrB-WSIX.js} +1 -1
  13. package/dist/{replay-TauriFileSystemAdapter-BnSXgnQc.js → replay-TauriFileSystemAdapter-CocGBrH_.js} +1 -1
  14. package/dist/{replay-TauriFileSystemAdapter-BuHbmM-L.js → replay-TauriFileSystemAdapter-q89YsNXx.js} +1 -1
  15. package/dist/{replay-TauriRootStorage-B1vFT2Rg.js → replay-TauriRootStorage-CZXVp2Zw.js} +1 -1
  16. package/dist/{replay-TauriRootStorage-D6K0MuWv.js → replay-TauriRootStorage-DHVdmo5Z.js} +5 -3
  17. package/dist/{replay-agent-loop-jUYXZfye.js → replay-agent-loop-cbxVIXnO.js} +9 -9
  18. package/dist/{replay-agent-loop-X2MrvEk-.js → replay-agent-loop-vzQUCpCA.js} +1 -1
  19. package/dist/{replay-ai-chat-mappers-B0Ay6VKi.js → replay-ai-chat-mappers-BnAf2rpg.js} +1 -1
  20. package/dist/{replay-ai-chat-mappers-sgE5XiwA.js → replay-ai-chat-mappers-pb8lpkUD.js} +1 -1
  21. package/dist/{replay-create-model-DB6xE5Ap.js → replay-create-model-CqA612v0.js} +3 -3
  22. package/dist/{replay-create-model-NrGYVueM.js → replay-create-model-Dr80k74P.js} +4 -4
  23. package/dist/{replay-db-BZNR8xEd.js → replay-db-Bq7IGfIa.js} +1 -1
  24. package/dist/{replay-db-BiP6dME4.js → replay-db-C8RC-t2R.js} +1 -1
  25. package/dist/{replay-external-resolver-PLyV0HZs.js → replay-external-resolver-Bw7R-LTs.js} +1 -1
  26. package/dist/{replay-external-resolver-DPAdPRks.js → replay-external-resolver-D6WP4NJY.js} +2 -2
  27. package/dist/{replay-index-yAV5TCua.js → replay-index-B3sCvU48.js} +1 -1
  28. package/dist/{replay-index-HHtp5T42.js → replay-index-BFdS3tY7.js} +1 -1
  29. package/dist/{replay-index-B2RZCGOF.js → replay-index-BizzVzWT.js} +22420 -21604
  30. package/dist/{replay-index-DTD47ryK.js → replay-index-CI5L8ebr.js} +1 -1
  31. package/dist/{replay-index-D85qPcEF.js → replay-index-D3evrr0U.js} +1205 -1098
  32. package/dist/{replay-index-DDUSidTx.js → replay-index-DZwTSW3m.js} +2 -2
  33. package/dist/{replay-index-DmAVD_C4.js → replay-index-DsAn0c_r.js} +1 -1
  34. package/dist/{replay-index-DKNhWzy4.js → replay-index-bspotqBs.js} +5 -5
  35. package/dist/{replay-lint-DyUeemr_.js → replay-lint-D5d7AeDU.js} +3 -3
  36. package/dist/{replay-lint-graphql-D_p-TkyV.js → replay-lint-graphql-CYl9hbRz.js} +1 -1
  37. package/dist/{replay-lint-graphql-pt1vf5MX.js → replay-lint-graphql-C_f79j2l.js} +1 -1
  38. package/dist/{replay-lint-Bico-a-1.js → replay-lint-q7b2-PPR.js} +3 -3
  39. package/dist/{replay-resolve-CQzlNcS2.js → replay-resolve-CftMmcPx.js} +1 -1
  40. package/dist/{replay-resolve-IKJYgmPW.js → replay-resolve-Km_DObpf.js} +1 -1
  41. package/dist/{replay-respect-run-CtDn7oS8.js → replay-respect-run-CfbJ-uak.js} +3 -3
  42. package/dist/{replay-respect-run-rx_nPWZM.js → replay-respect-run-DBe6ZUcc.js} +1 -1
  43. package/dist/{replay-tauri-path-iA6pF5e0.js → replay-tauri-path-BrtMOZvF.js} +1 -1
  44. package/dist/{replay-tauri-path-DrwBKGJP.js → replay-tauri-path-Ek8BSAa0.js} +2 -2
  45. package/dist/{replay-useAiChatQueries-PECgHJpT.js → replay-useAiChatQueries-BR1eEjUB.js} +4 -4
  46. package/dist/{replay-useAiChatQueries-BIZfilWh.js → replay-useAiChatQueries-DjjzEorX.js} +1 -1
  47. package/dist/{replay-validate-key-CvZaTfXj.js → replay-validate-key-CZSwxFid.js} +2 -2
  48. package/dist/{replay-validate-key-CTJn216O.js → replay-validate-key-Cox-cRT6.js} +1 -1
  49. package/dist/replay.cjs +1 -1
  50. package/dist/replay.d.ts +9 -0
  51. package/dist/replay.js +6 -6
  52. package/package.json +2 -2
  53. package/dist/replay-FileWatcher-CtHVgewC.js +0 -343
  54. package/dist/replay-FileWatcher-NkpXJA-C.js +0 -1
package/dist/replay.d.ts CHANGED
@@ -180,6 +180,15 @@ declare type InputSettings = {
180
180
  allowedEnvironments?: string[];
181
181
  apiId?: string;
182
182
  predefinedEnvValues?: Record<string, Record<string, PredefinedEnvValue>>;
183
+ /**
184
+ * Set by `useAuthGateSettings` only. `predefinedEnvValues` is merged from several sources, so
185
+ * it cannot say which environments a ReplayGate asked for; only `names` are created.
186
+ * `baseEnvironment` stays separate because the gate overwrites `selectedEnvironment`.
187
+ */
188
+ gateEnvironments?: {
189
+ names: string[];
190
+ baseEnvironment?: string;
191
+ };
183
192
  dynamicReplayValues?: ConfigureRequestValues | ConfigureServerRequestValues | null;
184
193
  certificates?: Certificate[];
185
194
  storageKey?: string;
package/dist/replay.js CHANGED
@@ -1,11 +1,11 @@
1
- import { V as s, G as r, bj as t, bk as l, F as o, bl as b, bm as d, d as m, bn as p, bo as R, b as n, bp as u, bq as y, br as i, bs as A, C as T, B as h, bt as O, bu as C } from "./replay-index-B2RZCGOF.js";
2
- import { O as I, h as P } from "./replay-oauth2-redirect-handler-CqKZB3aV.js";
1
+ import { X as s, J as r, bk as t, bl as l, H as o, bm as b, bn as d, e as m, bo as p, bp as R, d as n, bq as u, br as y, bs as i, bt as A, E as T, C as h, bu as E, bv as O } from "./replay-index-BizzVzWT.js";
2
+ import { O as v, h as I } from "./replay-oauth2-redirect-handler-CqKZB3aV.js";
3
3
  export {
4
4
  s as AI_PROVIDERS,
5
5
  r as AiPanelContext,
6
6
  t as EmbeddedReplay,
7
7
  l as Modal,
8
- I as OAuth2Error,
8
+ v as OAuth2Error,
9
9
  o as REUNITE_AI_PROVIDER,
10
10
  b as Replay,
11
11
  d as ReplayOverlay,
@@ -14,12 +14,12 @@ export {
14
14
  R as applyThemeToDOM,
15
15
  n as createResource,
16
16
  u as getCurrentTheme,
17
- P as handleOAuth2Redirect,
17
+ I as handleOAuth2Redirect,
18
18
  y as loadAgentLoop,
19
19
  i as makeProviderRecord,
20
20
  A as resolveTheme,
21
21
  T as useAiPanel,
22
22
  h as useTelemetry,
23
- O as useTelemetryClient,
24
- C as validateApiKey
23
+ E as useTelemetryClient,
24
+ O as validateApiKey
25
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/replay",
3
- "version": "0.27.1",
3
+ "version": "0.28.0-next.1",
4
4
  "type": "module",
5
5
  "main": "./dist/replay.cjs",
6
6
  "module": "./dist/replay.js",
@@ -21,7 +21,7 @@
21
21
  "react-dom": "^19.2.7",
22
22
  "react-router": "^8.3.0",
23
23
  "styled-components": "^6.4.2",
24
- "@redocly/theme": "0.68.1"
24
+ "@redocly/theme": "0.69.0-next.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@ai-sdk/anthropic": "4.0.4",
@@ -1,343 +0,0 @@
1
- import { i as u, t as y, P as m, n as v } from "./replay-index-B2RZCGOF.js";
2
- import { g as p } from "./replay-SemanticSearchService-DJ_jBUyi.js";
3
- import "react";
4
- var w;
5
- (function(r) {
6
- r.WINDOW_RESIZED = "tauri://resize", r.WINDOW_MOVED = "tauri://move", r.WINDOW_CLOSE_REQUESTED = "tauri://close-requested", r.WINDOW_DESTROYED = "tauri://destroyed", r.WINDOW_FOCUS = "tauri://focus", r.WINDOW_BLUR = "tauri://blur", r.WINDOW_SCALE_FACTOR_CHANGED = "tauri://scale-change", r.WINDOW_THEME_CHANGED = "tauri://theme-changed", r.WINDOW_CREATED = "tauri://window-created", r.WEBVIEW_CREATED = "tauri://webview-created", r.DRAG_ENTER = "tauri://drag-enter", r.DRAG_OVER = "tauri://drag-over", r.DRAG_DROP = "tauri://drag-drop", r.DRAG_LEAVE = "tauri://drag-leave";
7
- })(w || (w = {}));
8
- async function E(r, e) {
9
- await u("plugin:event|unlisten", {
10
- event: r,
11
- eventId: e
12
- });
13
- }
14
- async function x(r, e, a) {
15
- var i;
16
- const t = (i = void 0) !== null && i !== void 0 ? i : { kind: "Any" };
17
- return u("plugin:event|listen", {
18
- event: r,
19
- target: t,
20
- handler: y(e)
21
- }).then((s) => async () => E(r, s));
22
- }
23
- class A {
24
- constructor(e, a, i, t) {
25
- this.storage = e, this.state = a, this.projectDir = i, this.aiEnabled = t;
26
- }
27
- storage;
28
- state;
29
- projectDir;
30
- aiEnabled;
31
- watchPath = null;
32
- unlistenEvent = null;
33
- get tauriStorage() {
34
- return this.storage;
35
- }
36
- indexApis(e) {
37
- !this.aiEnabled || e.length === 0 || p().indexApis(e).catch((a) => console.error("Semantic index (apis):", a));
38
- }
39
- indexCollections(e) {
40
- !this.aiEnabled || e.length === 0 || p().indexCollections(e).catch((a) => console.error("Semantic index (collections):", a));
41
- }
42
- removeApis(e) {
43
- if (!this.aiEnabled || e.length === 0) return;
44
- const a = p();
45
- Promise.all(e.map((i) => a.removeApi(i))).catch(
46
- (i) => console.error("Semantic remove (apis):", i)
47
- );
48
- }
49
- removeCollections(e) {
50
- if (!this.aiEnabled || e.length === 0) return;
51
- const a = p();
52
- Promise.all(e.map((i) => a.removeCollection(i))).catch(
53
- (i) => console.error("Semantic remove (collections):", i)
54
- );
55
- }
56
- /**
57
- * Starts watching the directory for changes.
58
- */
59
- async start() {
60
- if (this.watchPath) {
61
- console.warn("Watcher already started for:", this.watchPath);
62
- return;
63
- }
64
- try {
65
- this.unlistenEvent = await x("fs-watch-event", async (e) => {
66
- const a = e.payload;
67
- try {
68
- await this.handleEvent(a);
69
- } catch (i) {
70
- console.error("Error handling file change:", i);
71
- }
72
- }), await u("fs_watch", {
73
- path: this.projectDir,
74
- options: {
75
- recursive: !0,
76
- delayMs: 500
77
- }
78
- }), this.watchPath = this.projectDir;
79
- } catch (e) {
80
- throw console.error("Failed to start file watcher:", e), this.unlistenEvent && (this.unlistenEvent(), this.unlistenEvent = null), e;
81
- }
82
- }
83
- /**
84
- * Stops watching and cleans up resources.
85
- */
86
- async stop() {
87
- if (this.watchPath)
88
- try {
89
- await u("fs_unwatch", { path: this.watchPath });
90
- } catch (e) {
91
- console.error("Error stopping file watcher:", e);
92
- } finally {
93
- this.unlistenEvent && (this.unlistenEvent(), this.unlistenEvent = null), this.watchPath = null;
94
- }
95
- }
96
- /**
97
- * Main event handler - dispatches to specific handlers based on event type.
98
- */
99
- async handleEvent(e) {
100
- const { changeType: a, paths: i, pathTypes: t, type: s } = e;
101
- if (await this.isProjectFolderRemoved(i, a)) {
102
- await this.handleProjectFolderRemoval();
103
- return;
104
- }
105
- const n = this.filterSpecFiles(i, t);
106
- if (n.paths.length === 0)
107
- return;
108
- const o = await this.toFileEntries(n.paths, n.pathTypes);
109
- switch (a) {
110
- case "changed":
111
- (s.includes("Data") || s.includes("Name")) && await this.handleModify(o);
112
- break;
113
- case "added":
114
- await this.handleCreate(o);
115
- break;
116
- case "deleted":
117
- await this.handleDelete(o);
118
- break;
119
- case "renamed":
120
- await this.handleRename(o);
121
- break;
122
- default:
123
- console.log("Unhandled change type:", a);
124
- }
125
- }
126
- /**
127
- * Filter paths to only include yaml/json files.
128
- * Returns filtered paths and their corresponding pathTypes.
129
- */
130
- filterSpecFiles(e, a) {
131
- const i = [], t = [];
132
- for (let s = 0; s < e.length; s++) {
133
- const n = e[s], o = n.split(".").pop()?.toLowerCase();
134
- o && ["yaml", "yml", "json"].includes(o) && (i.push(n), t.push(a[s] || "unknown"));
135
- }
136
- return { paths: i, pathTypes: t };
137
- }
138
- /**
139
- * Convert absolute paths to file entry format with relative paths and types.
140
- */
141
- async toFileEntries(e, a) {
142
- return Promise.all(
143
- e.map(async (i, t) => ({
144
- relative_path: await m.relative(this.projectDir, i),
145
- absolute_path: i,
146
- type: a[t] || "unknown"
147
- }))
148
- );
149
- }
150
- consolidateFileEntries(e) {
151
- const a = [], i = /* @__PURE__ */ new Set();
152
- for (const t of e)
153
- i.has(t.relative_path) || (i.add(t.relative_path), this.storage.isWatchExcluded(t.relative_path) || a.push(t));
154
- return a;
155
- }
156
- /**
157
- * Handles file content modification events.
158
- * If file doesn't exist in state yet, treat as creation.
159
- */
160
- async handleModify(e) {
161
- const a = !this.storage.isWatchExcluded("replay-environments.yaml") && e.some((g) => g.relative_path === "replay-environments.yaml"), i = e.filter((g) => g.relative_path !== "replay-environments.yaml"), { newApiFiles: t, existingApiFiles: s } = this.categorizeApisFromFiles(i), { newCollectionFiles: n, existingCollectionFiles: o } = this.categorizeCollectionsFromFiles(i), c = await this.findApisToReload(e), f = await this.findCollectionsToReload(e), d = [...t, ...n];
162
- d.length > 0 && await this.handleCreate(d), a && await this.reloadEnvironments();
163
- const h = this.consolidateFileEntries([...s, ...c]), l = this.consolidateFileEntries([
164
- ...o,
165
- ...f
166
- ]);
167
- await this.reloadApis(h), await this.reloadCollections(l);
168
- }
169
- /**
170
- * Handles file creation events.
171
- * If file already exists in state, update it instead of creating duplicate.
172
- */
173
- async handleCreate(e) {
174
- const a = e.filter((c) => c.type === "api"), i = e.filter((c) => c.type === "collection"), { newApiFiles: t, existingApiFiles: s } = this.categorizeApisFromFiles(a), { newCollectionFiles: n, existingCollectionFiles: o } = this.categorizeCollectionsFromFiles(i);
175
- if (t.length > 0 || n.length > 0) {
176
- t.forEach((l) => this.storage.addPersistExcludedId(l.relative_path)), n.forEach((l) => this.storage.addPersistExcludedId(l.relative_path));
177
- const c = t.length > 0 ? await this.tauriStorage.loadAndParseApis(t, void 0, !0) : [], f = n.length > 0 ? await this.tauriStorage.loadAndParseCollections(n, void 0) : [], d = c.filter((l) => l !== null), h = f.filter((l) => l !== null);
178
- this.state.apis.merge(d), this.state.collections.merge(h), this.indexApis(d), this.indexCollections(h), setTimeout(() => {
179
- t.forEach((l) => this.storage.removePersistExcludedId(l.relative_path)), n.forEach(
180
- (l) => this.storage.removePersistExcludedId(l.relative_path)
181
- );
182
- }, 500);
183
- }
184
- s.length > 0 && await this.reloadApis(s), o.length > 0 && await this.reloadCollections(o);
185
- }
186
- /**
187
- * Categorize API paths into new vs existing
188
- */
189
- /**
190
- * Categorize API files into new vs existing
191
- */
192
- categorizeApisFromFiles(e) {
193
- const a = /* @__PURE__ */ new Set(), i = [], t = [];
194
- for (const s of e) {
195
- if (a.has(s.relative_path))
196
- continue;
197
- a.add(s.relative_path), this.state.apis.get({ noproxy: !0 }).some((o) => o.id === s.relative_path) ? t.push(s) : s.type === "api" && i.push(s);
198
- }
199
- return { newApiFiles: i, existingApiFiles: t };
200
- }
201
- /**
202
- * Categorize collection files into new vs existing
203
- */
204
- categorizeCollectionsFromFiles(e) {
205
- const a = /* @__PURE__ */ new Set(), i = [], t = [];
206
- for (const s of e) {
207
- if (a.has(s.relative_path))
208
- continue;
209
- a.add(s.relative_path), this.state.collections.get({ noproxy: !0 }).some((o) => o.id === s.relative_path) ? t.push(s) : s.type === "collection" && i.push(s);
210
- }
211
- return { newCollectionFiles: i, existingCollectionFiles: t };
212
- }
213
- /**
214
- * Handles file deletion events.
215
- */
216
- async handleDelete(e) {
217
- const a = [], i = [];
218
- for (const t of e) {
219
- this.storage.addPersistExcludedId(t.relative_path);
220
- const s = this.state.apis.get({ noproxy: !0 }).findIndex((o) => o.id === t.relative_path);
221
- s >= 0 && (this.state.apis[s].set(v), this.tauriStorage.deleteApiFromCache(t.relative_path), a.push(t.relative_path));
222
- const n = this.state.collections.get({ noproxy: !0 }).findIndex((o) => o.id === t.relative_path);
223
- n >= 0 && (this.state.collections[n].set(v), i.push(t.relative_path)), setTimeout(() => {
224
- this.storage.removePersistExcludedId(t.relative_path);
225
- }, 500);
226
- }
227
- this.removeApis(a), this.removeCollections(i);
228
- }
229
- /**
230
- * Handles file rename/move events.
231
- * For rename events, files typically contains [oldFile, newFile]
232
- */
233
- async handleRename(e) {
234
- if (e.length >= 2) {
235
- const [a, i] = e;
236
- await this.handleDelete([a]), await this.handleCreate([i]);
237
- } else
238
- await this.handleCreate(e);
239
- }
240
- /**
241
- * Checks if the project folder itself was renamed/moved/deleted.
242
- * This happens when:
243
- * - We get a rename/delete event for the project directory itself
244
- * - Or when paths no longer match the watched directory structure
245
- */
246
- async isProjectFolderRemoved(e, a) {
247
- if (e.length === 0)
248
- return !1;
249
- if (a === "deleted" || a === "renamed") {
250
- for (const t of e)
251
- if (t === this.projectDir)
252
- return !0;
253
- }
254
- return e.filter(
255
- (t) => !t.startsWith(this.projectDir + "/") && t !== this.projectDir
256
- ).length > 0 && a === "renamed";
257
- }
258
- /**
259
- * Handles the case when the entire project folder is renamed or deleted.
260
- * Clears all APIs and collections from state.
261
- */
262
- async handleProjectFolderRemoval() {
263
- const e = this.state.apis.get({ noproxy: !0 }), a = e.map((s) => s.id);
264
- e.forEach((s) => {
265
- this.storage.addPersistExcludedId(s.id), this.tauriStorage.deleteApiFromCache(s.id);
266
- }), this.state.apis.set([]);
267
- const i = this.state.collections.get({ noproxy: !0 }), t = i.map((s) => s.id);
268
- i.forEach((s) => {
269
- this.storage.addPersistExcludedId(s.id);
270
- }), this.state.collections.set([]), setTimeout(() => {
271
- e.forEach((s) => this.storage.removePersistExcludedId(s.id)), i.forEach((s) => this.storage.removePersistExcludedId(s.id));
272
- }, 500), this.removeApis(a), this.removeCollections(t), await this.stop();
273
- }
274
- async findApisToReload(e) {
275
- const a = [];
276
- return await Promise.all(
277
- this.state.apis.map(async (i) => {
278
- const t = i.fileDependencies?.get({ noproxy: !0 }) ?? /* @__PURE__ */ new Set(), s = i.get({ noproxy: !0 }).id, n = e.find((o) => t.has(o.absolute_path));
279
- if (!this.storage.isWatchExcluded(s) && n) {
280
- const o = await m.join(this.projectDir, s);
281
- a.push({
282
- relative_path: s,
283
- absolute_path: o,
284
- type: "api"
285
- });
286
- }
287
- })
288
- ), a;
289
- }
290
- async findCollectionsToReload(e) {
291
- const a = [];
292
- return await Promise.all(
293
- this.state.collections.map(async (i) => {
294
- const t = i.fileDependencies?.get({ noproxy: !0 }) ?? /* @__PURE__ */ new Set(), s = i.get({ noproxy: !0 }).id, n = e.find((o) => t.has(o.absolute_path));
295
- if (!this.storage.isWatchExcluded(s) && n) {
296
- const o = await m.join(this.projectDir, s);
297
- a.push({
298
- relative_path: s,
299
- absolute_path: o,
300
- type: "collection"
301
- });
302
- }
303
- })
304
- ), a;
305
- }
306
- async reloadEnvironments() {
307
- const e = await this.tauriStorage.readEnviroments();
308
- this.storage.addPersistExcludedId("replay-environments.yaml"), this.state.environments.set(e), setTimeout(() => {
309
- this.storage.removePersistExcludedId("replay-environments.yaml");
310
- }, 500);
311
- }
312
- async reloadApis(e) {
313
- if (e.length === 0) return;
314
- const a = await this.tauriStorage.loadAndParseApis(e, void 0, !0), i = [];
315
- await Promise.all(
316
- a.map(async (t, s) => {
317
- if (!t) {
318
- await this.handleDelete([e[s]]);
319
- return;
320
- }
321
- const n = this.state.apis.get({ noproxy: !0 }).findIndex((o) => o.id === t.id);
322
- n >= 0 ? (this.storage.addPersistExcludedId(t.id), this.state.apis[n].set(t), i.push(t), setTimeout(() => this.storage.removePersistExcludedId(t.id), 500)) : console.warn("API not found in state after reload:", t.id);
323
- })
324
- ), i.length > 0 && this.indexApis(i);
325
- }
326
- async reloadCollections(e) {
327
- if (e.length === 0) return;
328
- const a = await this.tauriStorage.loadAndParseCollections(e, void 0), i = [];
329
- await Promise.all(
330
- a.map(async (t, s) => {
331
- if (!t) {
332
- await this.handleDelete([e[s]]);
333
- return;
334
- }
335
- const n = this.state.collections.get({ noproxy: !0 }).findIndex((o) => o.id === t.id);
336
- n >= 0 ? (this.storage.addPersistExcludedId(t.id), this.state.collections[n].set(t), i.push(t), setTimeout(() => this.storage.removePersistExcludedId(t.id), 500)) : console.warn("Collection not found in state after reload:", t.id);
337
- })
338
- ), i.length > 0 && this.indexCollections(i);
339
- }
340
- }
341
- export {
342
- A as FileWatcher
343
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./replay-index-D85qPcEF.js"),u=require("./replay-SemanticSearchService--QXHzf7_.js");require("react");var m;(function(r){r.WINDOW_RESIZED="tauri://resize",r.WINDOW_MOVED="tauri://move",r.WINDOW_CLOSE_REQUESTED="tauri://close-requested",r.WINDOW_DESTROYED="tauri://destroyed",r.WINDOW_FOCUS="tauri://focus",r.WINDOW_BLUR="tauri://blur",r.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",r.WINDOW_THEME_CHANGED="tauri://theme-changed",r.WINDOW_CREATED="tauri://window-created",r.WEBVIEW_CREATED="tauri://webview-created",r.DRAG_ENTER="tauri://drag-enter",r.DRAG_OVER="tauri://drag-over",r.DRAG_DROP="tauri://drag-drop",r.DRAG_LEAVE="tauri://drag-leave"})(m||(m={}));async function v(r,e){await c.invoke("plugin:event|unlisten",{event:r,eventId:e})}async function w(r,e,a){var i;const t=(i=void 0)!==null&&i!==void 0?i:{kind:"Any"};return c.invoke("plugin:event|listen",{event:r,target:t,handler:c.transformCallback(e)}).then(s=>async()=>v(r,s))}class y{constructor(e,a,i,t){this.storage=e,this.state=a,this.projectDir=i,this.aiEnabled=t}storage;state;projectDir;aiEnabled;watchPath=null;unlistenEvent=null;get tauriStorage(){return this.storage}indexApis(e){!this.aiEnabled||e.length===0||u.getSemanticSearchService().indexApis(e).catch(a=>console.error("Semantic index (apis):",a))}indexCollections(e){!this.aiEnabled||e.length===0||u.getSemanticSearchService().indexCollections(e).catch(a=>console.error("Semantic index (collections):",a))}removeApis(e){if(!this.aiEnabled||e.length===0)return;const a=u.getSemanticSearchService();Promise.all(e.map(i=>a.removeApi(i))).catch(i=>console.error("Semantic remove (apis):",i))}removeCollections(e){if(!this.aiEnabled||e.length===0)return;const a=u.getSemanticSearchService();Promise.all(e.map(i=>a.removeCollection(i))).catch(i=>console.error("Semantic remove (collections):",i))}async start(){if(this.watchPath){console.warn("Watcher already started for:",this.watchPath);return}try{this.unlistenEvent=await w("fs-watch-event",async e=>{const a=e.payload;try{await this.handleEvent(a)}catch(i){console.error("Error handling file change:",i)}}),await c.invoke("fs_watch",{path:this.projectDir,options:{recursive:!0,delayMs:500}}),this.watchPath=this.projectDir}catch(e){throw console.error("Failed to start file watcher:",e),this.unlistenEvent&&(this.unlistenEvent(),this.unlistenEvent=null),e}}async stop(){if(this.watchPath)try{await c.invoke("fs_unwatch",{path:this.watchPath})}catch(e){console.error("Error stopping file watcher:",e)}finally{this.unlistenEvent&&(this.unlistenEvent(),this.unlistenEvent=null),this.watchPath=null}}async handleEvent(e){const{changeType:a,paths:i,pathTypes:t,type:s}=e;if(await this.isProjectFolderRemoved(i,a)){await this.handleProjectFolderRemoval();return}const n=this.filterSpecFiles(i,t);if(n.paths.length===0)return;const o=await this.toFileEntries(n.paths,n.pathTypes);switch(a){case"changed":(s.includes("Data")||s.includes("Name"))&&await this.handleModify(o);break;case"added":await this.handleCreate(o);break;case"deleted":await this.handleDelete(o);break;case"renamed":await this.handleRename(o);break;default:console.log("Unhandled change type:",a)}}filterSpecFiles(e,a){const i=[],t=[];for(let s=0;s<e.length;s++){const n=e[s],o=n.split(".").pop()?.toLowerCase();o&&["yaml","yml","json"].includes(o)&&(i.push(n),t.push(a[s]||"unknown"))}return{paths:i,pathTypes:t}}async toFileEntries(e,a){return Promise.all(e.map(async(i,t)=>({relative_path:await c.PathUtils.relative(this.projectDir,i),absolute_path:i,type:a[t]||"unknown"})))}consolidateFileEntries(e){const a=[],i=new Set;for(const t of e)i.has(t.relative_path)||(i.add(t.relative_path),this.storage.isWatchExcluded(t.relative_path)||a.push(t));return a}async handleModify(e){const a=!this.storage.isWatchExcluded("replay-environments.yaml")&&e.some(g=>g.relative_path==="replay-environments.yaml"),i=e.filter(g=>g.relative_path!=="replay-environments.yaml"),{newApiFiles:t,existingApiFiles:s}=this.categorizeApisFromFiles(i),{newCollectionFiles:n,existingCollectionFiles:o}=this.categorizeCollectionsFromFiles(i),h=await this.findApisToReload(e),f=await this.findCollectionsToReload(e),d=[...t,...n];d.length>0&&await this.handleCreate(d),a&&await this.reloadEnvironments();const p=this.consolidateFileEntries([...s,...h]),l=this.consolidateFileEntries([...o,...f]);await this.reloadApis(p),await this.reloadCollections(l)}async handleCreate(e){const a=e.filter(h=>h.type==="api"),i=e.filter(h=>h.type==="collection"),{newApiFiles:t,existingApiFiles:s}=this.categorizeApisFromFiles(a),{newCollectionFiles:n,existingCollectionFiles:o}=this.categorizeCollectionsFromFiles(i);if(t.length>0||n.length>0){t.forEach(l=>this.storage.addPersistExcludedId(l.relative_path)),n.forEach(l=>this.storage.addPersistExcludedId(l.relative_path));const h=t.length>0?await this.tauriStorage.loadAndParseApis(t,void 0,!0):[],f=n.length>0?await this.tauriStorage.loadAndParseCollections(n,void 0):[],d=h.filter(l=>l!==null),p=f.filter(l=>l!==null);this.state.apis.merge(d),this.state.collections.merge(p),this.indexApis(d),this.indexCollections(p),setTimeout(()=>{t.forEach(l=>this.storage.removePersistExcludedId(l.relative_path)),n.forEach(l=>this.storage.removePersistExcludedId(l.relative_path))},500)}s.length>0&&await this.reloadApis(s),o.length>0&&await this.reloadCollections(o)}categorizeApisFromFiles(e){const a=new Set,i=[],t=[];for(const s of e){if(a.has(s.relative_path))continue;a.add(s.relative_path),this.state.apis.get({noproxy:!0}).some(o=>o.id===s.relative_path)?t.push(s):s.type==="api"&&i.push(s)}return{newApiFiles:i,existingApiFiles:t}}categorizeCollectionsFromFiles(e){const a=new Set,i=[],t=[];for(const s of e){if(a.has(s.relative_path))continue;a.add(s.relative_path),this.state.collections.get({noproxy:!0}).some(o=>o.id===s.relative_path)?t.push(s):s.type==="collection"&&i.push(s)}return{newCollectionFiles:i,existingCollectionFiles:t}}async handleDelete(e){const a=[],i=[];for(const t of e){this.storage.addPersistExcludedId(t.relative_path);const s=this.state.apis.get({noproxy:!0}).findIndex(o=>o.id===t.relative_path);s>=0&&(this.state.apis[s].set(c.none),this.tauriStorage.deleteApiFromCache(t.relative_path),a.push(t.relative_path));const n=this.state.collections.get({noproxy:!0}).findIndex(o=>o.id===t.relative_path);n>=0&&(this.state.collections[n].set(c.none),i.push(t.relative_path)),setTimeout(()=>{this.storage.removePersistExcludedId(t.relative_path)},500)}this.removeApis(a),this.removeCollections(i)}async handleRename(e){if(e.length>=2){const[a,i]=e;await this.handleDelete([a]),await this.handleCreate([i])}else await this.handleCreate(e)}async isProjectFolderRemoved(e,a){if(e.length===0)return!1;if(a==="deleted"||a==="renamed"){for(const t of e)if(t===this.projectDir)return!0}return e.filter(t=>!t.startsWith(this.projectDir+"/")&&t!==this.projectDir).length>0&&a==="renamed"}async handleProjectFolderRemoval(){const e=this.state.apis.get({noproxy:!0}),a=e.map(s=>s.id);e.forEach(s=>{this.storage.addPersistExcludedId(s.id),this.tauriStorage.deleteApiFromCache(s.id)}),this.state.apis.set([]);const i=this.state.collections.get({noproxy:!0}),t=i.map(s=>s.id);i.forEach(s=>{this.storage.addPersistExcludedId(s.id)}),this.state.collections.set([]),setTimeout(()=>{e.forEach(s=>this.storage.removePersistExcludedId(s.id)),i.forEach(s=>this.storage.removePersistExcludedId(s.id))},500),this.removeApis(a),this.removeCollections(t),await this.stop()}async findApisToReload(e){const a=[];return await Promise.all(this.state.apis.map(async i=>{const t=i.fileDependencies?.get({noproxy:!0})??new Set,s=i.get({noproxy:!0}).id,n=e.find(o=>t.has(o.absolute_path));if(!this.storage.isWatchExcluded(s)&&n){const o=await c.PathUtils.join(this.projectDir,s);a.push({relative_path:s,absolute_path:o,type:"api"})}})),a}async findCollectionsToReload(e){const a=[];return await Promise.all(this.state.collections.map(async i=>{const t=i.fileDependencies?.get({noproxy:!0})??new Set,s=i.get({noproxy:!0}).id,n=e.find(o=>t.has(o.absolute_path));if(!this.storage.isWatchExcluded(s)&&n){const o=await c.PathUtils.join(this.projectDir,s);a.push({relative_path:s,absolute_path:o,type:"collection"})}})),a}async reloadEnvironments(){const e=await this.tauriStorage.readEnviroments();this.storage.addPersistExcludedId("replay-environments.yaml"),this.state.environments.set(e),setTimeout(()=>{this.storage.removePersistExcludedId("replay-environments.yaml")},500)}async reloadApis(e){if(e.length===0)return;const a=await this.tauriStorage.loadAndParseApis(e,void 0,!0),i=[];await Promise.all(a.map(async(t,s)=>{if(!t){await this.handleDelete([e[s]]);return}const n=this.state.apis.get({noproxy:!0}).findIndex(o=>o.id===t.id);n>=0?(this.storage.addPersistExcludedId(t.id),this.state.apis[n].set(t),i.push(t),setTimeout(()=>this.storage.removePersistExcludedId(t.id),500)):console.warn("API not found in state after reload:",t.id)})),i.length>0&&this.indexApis(i)}async reloadCollections(e){if(e.length===0)return;const a=await this.tauriStorage.loadAndParseCollections(e,void 0),i=[];await Promise.all(a.map(async(t,s)=>{if(!t){await this.handleDelete([e[s]]);return}const n=this.state.collections.get({noproxy:!0}).findIndex(o=>o.id===t.id);n>=0?(this.storage.addPersistExcludedId(t.id),this.state.collections[n].set(t),i.push(t),setTimeout(()=>this.storage.removePersistExcludedId(t.id),500)):console.warn("Collection not found in state after reload:",t.id)})),i.length>0&&this.indexCollections(i)}}exports.FileWatcher=y;