@redocly/replay 0.27.0-next.8 → 0.27.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/dist/{replay-AiChatProvider-DHIxHTKX.js → replay-AiChatProvider-LQhrLIDL.js} +44 -44
- package/dist/{replay-AiChatProvider-O8HHQobN.js → replay-AiChatProvider-Oms5CFgT.js} +1 -1
- package/dist/{replay-AiChatSqliteDBStorage-DNMrzkJg.js → replay-AiChatSqliteDBStorage-3-p1mthX.js} +1 -1
- package/dist/{replay-AiChatSqliteDBStorage-DjUq9VX3.js → replay-AiChatSqliteDBStorage-GZibdHOQ.js} +1 -1
- package/dist/replay-AiPanel-BvwwBTh1.js +742 -0
- package/dist/{replay-AiPanel-CR815YqV.js → replay-AiPanel-lcDNvgo0.js} +973 -1176
- package/dist/replay-FileWatcher-ClVd_wG0.js +1 -0
- package/dist/replay-FileWatcher-DR-wJLe2.js +343 -0
- package/dist/replay-Observable-D6wKbFwB.js +31 -0
- package/dist/replay-Observable-bjJ6wkRB.js +1 -0
- package/dist/replay-SemanticSearchService-CCqwCRo6.js +1 -0
- package/dist/replay-SemanticSearchService-U1eXQGfF.js +723 -0
- package/dist/{replay-SqliteDBStorage-B3oYWXem.js → replay-SqliteDBStorage-Dn6DoVWW.js} +1 -1
- package/dist/{replay-SqliteDBStorage-CC9kLioX.js → replay-SqliteDBStorage-d_ZK6ScA.js} +1 -1
- package/dist/replay-TauriFileSystemAdapter-CpiUuG3T.js +99 -0
- package/dist/replay-TauriFileSystemAdapter-dwJ0xBYr.js +1 -0
- package/dist/replay-TauriRootStorage-CuVbYMXX.js +605 -0
- package/dist/replay-TauriRootStorage-DhzbAahU.js +1 -0
- package/dist/{replay-agent-loop-CTq5eJ4u.js → replay-agent-loop-BLSu4v_O.js} +1 -1
- package/dist/{replay-agent-loop-CCYOzyHo.js → replay-agent-loop-DgEHdXUt.js} +11 -11
- package/dist/{replay-ai-chat-mappers-C8y5UhCq.js → replay-ai-chat-mappers-BvfcEubB.js} +5 -5
- package/dist/{replay-ai-chat-mappers-B_wovMvG.js → replay-ai-chat-mappers-Dy2kJ7ZG.js} +1 -1
- package/dist/replay-core-BJmXmoC5.js +1 -0
- package/dist/replay-core-B_hiOZZr.js +10 -0
- package/dist/{replay-create-model-C5yvtnXA.js → replay-create-model-DNPFcOIp.js} +579 -578
- package/dist/{replay-create-model-CBCmuEKC.js → replay-create-model-bOIDB-e8.js} +10 -10
- package/dist/{replay-db-CCBQadnT.js → replay-db-BQGv3PGw.js} +1 -1
- package/dist/{replay-db-DfOjLqsq.js → replay-db-CMXZZs9v.js} +1 -1
- package/dist/{replay-external-resolver-BRouROm6.js → replay-external-resolver-mrykFC2h.js} +2 -2
- package/dist/{replay-external-resolver-B6tpqUZt.js → replay-external-resolver-n5OvQMRF.js} +1 -1
- package/dist/replay-index-3lwhSmvi.js +1 -0
- package/dist/{replay-index-BzzBKjHm.js → replay-index-Bc5RHu5L.js} +23771 -25420
- package/dist/replay-index-CFLu-XMV.js +25 -0
- package/dist/{replay-index-Xq6K7XSm.js → replay-index-CHGVyIdG.js} +1 -1
- package/dist/{replay-index-Cpkh9r0X.js → replay-index-CSR_qlua.js} +1 -1
- package/dist/replay-index-CepJ5Z0m.js +6875 -0
- package/dist/{replay-index-Bzttek8l.js → replay-index-CgCGhu4l.js} +6 -6
- package/dist/replay-index-DDjmUXWm.js +1 -0
- package/dist/replay-index-DiSy_1OY.js +21 -0
- package/dist/replay-index-Oct6Dygd.js +1 -0
- package/dist/{replay-index-B_OHqSlS.js → replay-index-QXosJxRc.js} +18 -18
- package/dist/replay-index-jkDlU0Lx.js +32 -0
- package/dist/{replay-lint-gtuMJgII.js → replay-lint-DoHQIATV.js} +122 -122
- package/dist/{replay-lint-DlDmPTBV.js → replay-lint-PWaLESz5.js} +8921 -8880
- package/dist/{replay-lint-graphql-DHOq8lRT.js → replay-lint-graphql-xh8VoAwd.js} +1 -1
- package/dist/{replay-lint-graphql-BQJ00lU4.js → replay-lint-graphql-zO8zunug.js} +1 -1
- package/dist/replay-periodic-revalidation-BoyLQHtg.js +1 -0
- package/dist/replay-periodic-revalidation-Dsp-n7ui.js +21 -0
- package/dist/replay-promise-map-limit-DRDkHc-b.js +1 -0
- package/dist/replay-promise-map-limit-Db_42GvV.js +14 -0
- package/dist/replay-resolve-B0AjmaE9.js +47 -0
- package/dist/{replay-resolve-DsgcWnjC.js → replay-resolve-MVe_8Ube.js} +1364 -1329
- package/dist/{replay-respect-run-7Cwe1_ri.js → replay-respect-run-BJsR4a4m.js} +1 -1
- package/dist/{replay-respect-run-D1zyh-5j.js → replay-respect-run-X4PSO6Fj.js} +3 -3
- package/dist/{replay-tauri-path-BAY3g5sW.js → replay-tauri-path-CkGiQWsb.js} +5 -5
- package/dist/{replay-tauri-path-CaVeI3a-.js → replay-tauri-path-D8FJsoZb.js} +1 -1
- package/dist/replay-useAiChatQueries-BXL-_N2Q.js +215 -0
- package/dist/{replay-useAiChatQueries-CxZNLVje.js → replay-useAiChatQueries-D7sHNAfV.js} +1078 -1022
- package/dist/{replay-validate-key-Cv0mvYDS.js → replay-validate-key-CmzSfORv.js} +1 -1
- package/dist/{replay-validate-key-Di8MCBz7.js → replay-validate-key-CtZEJRP7.js} +2 -2
- package/dist/replay.cjs +1 -1
- package/dist/replay.js +11 -11
- package/package.json +10 -9
- package/dist/replay-AiPanel-CfYBCkrN.js +0 -868
- package/dist/replay-index-C6SJPGDO.js +0 -23
- package/dist/replay-index-CUs62_1f.js +0 -1
- package/dist/replay-index-Dfnqt_IZ.js +0 -6899
- package/dist/replay-resolve-DqFS69S_.js +0 -47
- package/dist/replay-useAiChatQueries-D99tAUpY.js +0 -215
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./replay-index-CepJ5Z0m.js"),u=require("./replay-SemanticSearchService-CCqwCRo6.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;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { i as u, t as y, P as m, n as v } from "./replay-index-Bc5RHu5L.js";
|
|
2
|
+
import { g as p } from "./replay-SemanticSearchService-U1eXQGfF.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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class l {
|
|
2
|
+
listeners = /* @__PURE__ */ new Map();
|
|
3
|
+
on(e, s) {
|
|
4
|
+
let t = this.listeners.get(e);
|
|
5
|
+
t || (t = /* @__PURE__ */ new Set(), this.listeners.set(e, t)), t.add(s);
|
|
6
|
+
}
|
|
7
|
+
off(e, s) {
|
|
8
|
+
this.listeners.get(e)?.delete(s);
|
|
9
|
+
}
|
|
10
|
+
emit(e, s) {
|
|
11
|
+
const t = this.listeners.get(e);
|
|
12
|
+
if (t)
|
|
13
|
+
for (const i of t)
|
|
14
|
+
i(s);
|
|
15
|
+
}
|
|
16
|
+
subscribe(e, s) {
|
|
17
|
+
return this.on(e, s), () => {
|
|
18
|
+
this.off(e, s);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
removeAllListeners(e) {
|
|
22
|
+
if (e !== void 0) {
|
|
23
|
+
this.listeners.delete(e);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.listeners.clear();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
l as O
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";class r{listeners=new Map;on(e,s){let t=this.listeners.get(e);t||(t=new Set,this.listeners.set(e,t)),t.add(s)}off(e,s){this.listeners.get(e)?.delete(s)}emit(e,s){const t=this.listeners.get(e);if(t)for(const i of t)i(s)}subscribe(e,s){return this.on(e,s),()=>{this.off(e,s)}}removeAllListeners(e){if(e!==void 0){this.listeners.delete(e);return}this.listeners.clear()}}exports.Observable=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const d=require("./replay-index-CepJ5Z0m.js"),J=require("./replay-Observable-bjJ6wkRB.js"),ee=require("./replay-promise-map-limit-DRDkHc-b.js");function g(t){return t==null?"":typeof t=="string"?t:typeof t=="object"&&"raw"in t&&typeof t.raw=="string"?t.raw:String(t)}function $(t){return t.replace(/\s+/g," ").trim()}function S(t){return typeof t=="object"&&t!==null&&"$ref"in t}function P(t){return S(t)?null:t}function q(t){try{return JSON.stringify(t)}catch{return String(t)}}function U(t){let e=`${t.name} (${t.in}`;return t.required&&(e+=", required"),t.type&&(e+=`, ${t.type}`),t.format&&(e+=`, format: ${t.format}`),t.enum&&(e+=`, enum: [${t.enum.join(",")}]`),t.pattern&&(e+=`, pattern: ${t.pattern}`),e+=")",e}function F(t){return t.type?Array.isArray(t.type)?t.type.join("|"):t.type:t.oneOf?"oneOf":t.anyOf?"anyOf":t.allOf?"allOf":"object"}function te(t){return t==="querystring"?"query":t==="query"||t==="header"||t==="path"||t==="cookie"?t:"query"}function ne(t){const e=t.schema&&!S(t.schema)?t.schema:null,n={name:t.name,in:te(t.in),required:t.required??!1};return e&&(n.type=F(e),e.format&&(n.format=e.format),e.enum&&(n.enum=e.enum.map(String)),e.pattern&&(n.pattern=e.pattern),e.example!==void 0&&(n.example=String(e.example))),t.description&&(n.description=g(t.description)),t.example!==void 0&&!n.example&&(n.example=String(t.example)),n}function ie(t,e){const n=new Set,o=[],s=i=>{for(const r of i){const c=P(r);if(!c||!c.name)continue;const a=`${c.in}:${c.name}`;n.has(a)||(n.add(a),o.push(ne(c)))}};return t.parameters&&s(t.parameters),e.parameters&&s(e.parameters),o}function L(t,e=2,n=0){if(n>=e||!t.properties)return[];const o=new Set(t.required??[]);return Object.entries(t.properties).map(([s,i])=>({name:s,type:F(i),required:o.has(s),readOnly:i.readOnly}))}function G(t){const e=t.components?.securitySchemes;if(!e)return[];const n=[];for(const[o,s]of Object.entries(e)){const i=P(s);i&&n.push(oe(o,i))}return n}function oe(t,e){const n={schemeName:t,type:e.type};if(e.in&&(n.in=e.in),e.name&&(n.name=e.name),e.scheme&&(n.scheme=e.scheme),e.bearerFormat&&(n.bearerFormat=e.bearerFormat),e.flows){const o=Object.keys(e.flows).filter(i=>e.flows[i]);o.length>0&&(n.flows=o.join(", "));const s=new Set;for(const i of o){const r=e.flows[i];r?.scopes&&Object.keys(r.scopes).forEach(c=>s.add(c))}s.size>0&&(n.scopes=[...s].join(", "))}return n}function se(t,e,n){const o=t??e;if(!o||n.length===0)return[];const s=new Set;for(const i of o)for(const r of Object.keys(i))s.add(r);return n.filter(i=>s.has(i.schemeName))}function re(t){return t.length===0?"":`Security: ${t.map(n=>{let o=`${n.schemeName} (${n.type}`;return n.scheme&&(o+=`, ${n.scheme}`),n.in&&n.name&&(o+=`, ${n.name} in ${n.in}`),o+=")",o}).join("; ")}.`}const ce=["get","put","post","delete","options","head","patch","trace"],ae=["query","x-query"];function le(t,e){const n=[],o=Object.keys(t.content??{});if(o.length===0)return{textPart:"",schemaJson:"{}",examples:n};const s=o.find(u=>u.includes("json"))??o[0],i=t.content?.[s],r=i?.schema&&!S(i.schema)?i.schema:null,a=(r?L(r):[]).filter(u=>!e.hideReadOnly||!u.readOnly),p=t.required?"required":"optional";let l=`Request body (${s}, ${p})`;if(a.length>0){const u=a.map(f=>`${f.name}: ${f.type}${f.required?" required":""}${f.readOnly?" readOnly":""}`);l+=`: {${u.join(", ")}}`}return i?.example!==void 0&&n.push(q(i.example)),{textPart:l,schemaJson:JSON.stringify(a),examples:n}}function de(t){const e=[],n=[];for(const[o,s]of Object.entries(t)){if(S(s))continue;const i=g(s.description??"");e.push(`${o} ${i}`.trim());const r={statusCode:o};i&&(r.description=i);const c=s.content;if(c){const a=Object.keys(c).find(l=>l.includes("json"))??Object.keys(c)[0],p=c[a]?.schema;if(p&&!S(p)){const l=L(p);l.length>0&&(r.schemaProperties=JSON.stringify(l))}}n.push(r)}return{textParts:e,summaries:n}}function D(t){const{apiId:e,apiTitle:n,path:o,method:s,op:i,pathItem:r,globalSchemes:c,apiSecurity:a}=t,p=i.summary??"",l=g(i.description??""),u=i.operationId??"",f=i.tags??[],m=s.toUpperCase(),I=ie(i,r),h=se(i.security,a,c),y=h.length>0?h.map(v=>`api_sec:${e}:${v.schemeName}`):void 0,x=[n,`${m} ${o}`,p,l];u&&x.push(`operationId: ${u}`),f.length>0&&x.push(`Tags: ${f.join(", ")}`),i.deprecated&&x.push("DEPRECATED"),I.length>0&&x.push(`Parameters: ${I.map(U).join(". ")}.`);let A;const _=[],B=i.requestBody;if(B){const v=P(B);if(v){const b=le(v,{hideReadOnly:m==="POST"||m==="PUT"||m==="PATCH"});b.textPart&&x.push(b.textPart),A=b.schemaJson,_.push(...b.examples)}}const{textParts:C,summaries:E}=de(i.responses??{});C.length>0&&x.push(`Responses: ${C.join(", ")}.`);const R=re(h);R&&x.push(R);const M=`api_op:${e}:${o}:${s}:${u||`${o}-${s}`}`,V={type:"api_operation",id:M,contentHash:"",title:p||`${m} ${o}`,description:l||void 0,apiId:e,path:o,method:m,operationId:u||void 0,tags:f.length>0?f:void 0,deprecated:i.deprecated||void 0,parameterDetails:I.length>0?I:void 0,requestBodySchema:A,responseSchemas:E.length>0?E:void 0,securitySchemeRefs:y,examples:_.length>0?_:void 0};return{id:M,text:$(x.filter(Boolean).join(" ")),payload:V}}function W(t){const e=t.info?.title??"Untitled API",n=g(t.info?.description??t.info?.summary??""),o=t.id;return{id:`api:${o}`,text:$([e,n].filter(Boolean).join(" ")),payload:{type:"api",id:`api:${o}`,contentHash:"",title:e,description:n||void 0,apiId:o}}}function T(t){const e=[];for(const n of t){e.push(W(n));const o=n.info?.title??"Untitled API",s=n.id,i=G(n);for(const c of i){const a=`api_sec:${s}:${c.schemeName}`,p=[`${c.schemeName}: type=${c.type}`,c.scheme?`scheme=${c.scheme}`:"",c.in&&c.name?`${c.name} in ${c.in}`:"",c.bearerFormat?`format=${c.bearerFormat}`:"",c.flows?`flows=[${c.flows}]`:"",c.scopes?`scopes=[${c.scopes}]`:""].filter(Boolean).join(" ");e.push({id:a,text:$(`${o} Authentication. ${c.schemeName}. ${p}.`),payload:{type:"api_security",id:a,contentHash:"",title:`${o} — ${c.schemeName}`,apiId:s,securityScheme:c}})}const r=n.paths??{};for(const[c,a]of Object.entries(r)){if(!a||typeof a!="object")continue;const p=[...ce.filter(u=>u in a),...ae.filter(u=>u in a)];for(const u of p){const f=a[u];!f||typeof f!="object"||e.push(D({apiId:s,apiTitle:o,path:c,method:u,op:f,pathItem:a,globalSchemes:i,apiSecurity:n.security}))}const l=a.additionalOperations;if(l&&typeof l=="object")for(const[u,f]of Object.entries(l))!f||typeof f!="object"||e.push(D({apiId:s,apiTitle:o,path:c,method:u,op:f,pathItem:a,globalSchemes:i,apiSecurity:n.security}))}}return e}function ue(t){const e=[],n=[{list:t.queryParameters,loc:"query"},{list:t.headers,loc:"header"},{list:t.cookies,loc:"cookie"},{list:t.pathParameters,loc:"path"}];for(const{list:o,loc:s}of n)for(const i of o)if("key"in i){const r=i;e.push({name:r.key,in:s,required:!1})}return e}function Q(t){const e=t.id,n=t.info?.title??"Untitled Collection",o=g(t.info?.description??t.info?.summary??"");return{id:`collection:${e}`,text:$([n,o].filter(Boolean).join(" ")),payload:{type:"collection",id:`collection:${e}`,contentHash:"",title:n,description:o||void 0,collectionId:e}}}function X(t){const{collectionId:e,collectionTitle:n,workflow:o}=t,s=o.workflowId??"",i=o.summary??s,r=g(o.description??""),c=[n,i,r];if(o.inputs&&c.push(`Inputs schema: ${q(o.inputs)}`),o.outputs?.length){const a=o.outputs.map(p=>p.key).filter(Boolean);a.length&&c.push(`Outputs: ${a.join(", ")}`)}return o.dependsOn?.length&&c.push(`Depends on: ${o.dependsOn.join(", ")}`),{id:`workflow:${e}:${s}`,text:$(c.filter(Boolean).join(" ")),payload:{type:"workflow",id:`workflow:${e}:${s}`,contentHash:"",title:i,description:r||void 0,collectionId:e,workflowId:s}}}function K(t){const{collectionId:e,collectionTitle:n,workflowId:o,workflowTitle:s,step:i}=t,r=i.stepId??"",c=g(i.description??""),a=i.operation,p=i.xOperation,l=[n,s,`step: ${r}`];c&&l.push(c),a?(l.push(`${a.method?.toUpperCase()} ${a.path}`),a.apiId&&l.push(`API: ${a.apiId}`),a.operationId&&l.push(`operationId: ${a.operationId}`)):p&&l.push(`${p.method?.toUpperCase()} ${p.url}`);const u=i.parameters?ue(i.parameters):[];u.length>0&&l.push(`Parameters: ${u.map(U).join(". ")}.`),i.requestBody?.type&&l.push(`Request body type: ${i.requestBody.type}`);const m=(i.successCriteria??[]).map(h=>{let y=h.condition;return h.context&&(y+=` context: ${h.context}`),h.type&&(y+=` (${h.type})`),y});if(m.length>0&&l.push(`Success criteria: ${m.join("; ")}`),i.outputs?.length){const h=i.outputs.map(y=>`${y.key}=${y.value}`).filter(Boolean);h.length&&l.push(`Outputs: ${h.join(", ")}`)}const I=`step:${e}:${o}:${r}`;return{id:I,text:$(l.filter(Boolean).join(" ")),payload:{type:"step",id:I,contentHash:"",title:r,description:c||void 0,collectionId:e,workflowId:o,stepId:r,path:a?.path??p?.url,method:(a?.method??p?.method)?.toUpperCase(),apiId:a?.apiId,operationId:a?.operationId,parameterDetails:u.length>0?u:void 0,successCriteria:m.length>0?m:void 0,requestBodySchema:i.requestBody?.type?q(i.requestBody):void 0}}}function j(t){const e=[];for(const n of t){const o=n.id,s=n.info?.title??"Untitled Collection";e.push(Q(n));for(const i of n.workflows??[]){e.push(X({collectionId:o,collectionTitle:s,workflow:i}));const r=i.workflowId??"",c=i.summary??r;for(const a of i.steps??[])e.push(K({collectionId:o,collectionTitle:s,workflowId:r,workflowTitle:c,step:a}))}}return e}function Y(t,e){return[...T(t),...j(e)]}const N=10,pe=4;function H(t){let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n)|0;return e>>>0}function fe(t){return d.bytesToHex(d.md5(t))}const he={};class me extends J.Observable{constructor(e){super(),this.collectionName=e}collectionName;activeIndexJobs=0;getIndexingActivityState(){return{inProgress:this.activeIndexJobs>0}}beginIndexJob(){this.activeIndexJobs++,this.activeIndexJobs===1&&this.emit("indexing-activity",{inProgress:!0})}endIndexJob(){this.activeIndexJobs=Math.max(0,this.activeIndexJobs-1),this.activeIndexJobs===0&&this.emit("indexing-activity",{inProgress:!1})}async getIdsByPayload(e,n){return d.invoke("semantic_search_get_ids_by_payload",{collectionName:this.collectionName,field:e,value:n})}async getAllIds(){return d.invoke("semantic_search_get_all_ids",{collectionName:this.collectionName})}async getScopeHashes(e){const n=e.apiIds??[],o=e.collectionIds??[];let s;if(n.length===0&&o.length===0)s=await this.getAllIds();else{const r=[];for(const a of n)r.push(this.getIdsByPayload("apiId",a));for(const a of o)r.push(this.getIdsByPayload("collectionId",a));s=(await Promise.all(r)).flat()}const i=new Map;for(const r of s)i.set(r.id,r.contentHash);return i}async indexDocuments(e,n){if(e.length===0&&!n)return{added:0,updated:0,removed:0,unchanged:0};const o=await this.getScopeHashes(n??{}),s=[],i=new Set;let r=0,c=0;for(const l of e){const u=fe(l.text);l.payload.contentHash=u,i.add(l.id);const f=o.get(l.id);f===u?c++:(f||r++,s.push(l))}const a=s.length-r,p=[];for(const l of o.keys())i.has(l)||p.push(l);if(p.length>0||s.length>0){this.beginIndexJob();try{p.length>0&&await this.deletePoints(p.map(H)),s.length>0&&await this.embedAndUpsert(s),await this.flush()}finally{this.endIndexJob()}}return{added:r,updated:a,removed:p.length,unchanged:c}}async removeByPayloadFilter(e,n){return d.invoke("semantic_search_delete_by_payload",{collectionName:this.collectionName,field:e,value:n})}async getStoredDocumentCount(){try{return(await d.invoke("plugin:velesdb|list_collections"))?.find(o=>o.name===this.collectionName)?.count??0}catch{return 0}}async getDocumentsByIds(e){if(e.length===0)return new Map;const n=e.map(H),o=await d.invoke("plugin:velesdb|get_points",{request:{collection:this.collectionName,ids:n}}),s=new Map;for(const i of o??[])if(i?.payload){const r=i.payload;r.id&&s.set(r.id,r)}return s}async embedAndUpsert(e){const n=[],o=e.length;for(let s=0;s<o;s+=N)n.push({docs:e.slice(s,s+N),index:Math.floor(s/N)});await ee.promiseMapLimit(n,pe,async s=>{const i=s.docs.map(r=>({id:r.id,text:r.text||r.payload.title,payload:r.payload}));await d.invoke("semantic_search_embed_and_upsert",{collectionName:this.collectionName,documents:i})})}async deletePoints(e){e.length!==0&&await d.invoke("plugin:velesdb|delete_points",{request:{collection:this.collectionName,ids:e}})}async flush(){await d.invoke("plugin:velesdb|flush",{name:this.collectionName}),await d.invoke("semantic_search_write_hnsw_marker",{collectionName:this.collectionName}).catch(()=>{})}}const z="replay_search",ye=384,w={added:0,updated:0,removed:0,unchanged:0};function k(t){return t.added+t.updated>0}class Z extends J.Observable{initialized=!1;projectId=null;indexer=null;indexQueue=Promise.resolve();get collectionName(){return this.projectId?`${z}_${this.projectId}`:z}createIndexer(){const e=new me(this.collectionName);return e.subscribe("indexing-activity",n=>{this.emit("indexing-activity",n)}),e}getIndexer(){return this.indexer||(this.indexer=this.createIndexer()),this.indexer}getIndexingActivityState(){return this.getIndexer().getIndexingActivityState()}async ensureInitialized(){this.initialized||await this.init()}enqueueIndex(e,n){const s=this.indexQueue.then(()=>e()).then(async i=>(n(i)&&await this.unloadModel(),i)).catch(async i=>{throw console.error("Semantic index:",i),await this.unloadModel(),i});return this.indexQueue=s.catch(()=>{}),s}async unloadModel(){try{await d.invoke("semantic_search_unload_model")}catch{}}setProject(e){this.projectId!==e&&(this.projectId=e,this.initialized=!1,this.indexer=this.createIndexer())}async init(){if(d.isTauriApp()&&!this.initialized){try{if((await d.invoke("plugin:velesdb|list_collections"))?.some(n=>n.name===this.collectionName)){this.initialized=!0;return}}catch{}await d.invoke("plugin:velesdb|create_collection",{request:{name:this.collectionName,dimension:ye,metric:"cosine",storage_mode:"full"}}),this.initialized=!0}}async indexApis(e){if(!d.isTauriApp())return w;const n=this.collectionName,o=this.getIndexer(),s=T(e),i={apiIds:e.map(r=>r.id)};return await this.ensureInitialized(),this.enqueueIndex(async()=>this.collectionName!==n?w:o.indexDocuments(s,i),k)}async indexCollections(e){if(!d.isTauriApp())return w;const n=this.collectionName,o=this.getIndexer(),s=j(e),i={collectionIds:e.map(r=>r.id)};return await this.ensureInitialized(),this.enqueueIndex(async()=>this.collectionName!==n?w:o.indexDocuments(s,i),k)}async removeApi(e){if(!d.isTauriApp())return;const n=this.getIndexer();await this.ensureInitialized(),await this.enqueueIndex(()=>n.removeByPayloadFilter("apiId",e),()=>!1)}async removeCollection(e){if(!d.isTauriApp())return;const n=this.getIndexer();await this.ensureInitialized(),await this.enqueueIndex(()=>n.removeByPayloadFilter("collectionId",e),()=>!1)}async reindex(e){if(!d.isTauriApp())return w;const n=this.collectionName,o=this.getIndexer();return await this.ensureInitialized(),this.enqueueIndex(async()=>{if(this.collectionName!==n)return w;const{apis:s,collections:i}=e(),r=Y(s,i);return o.indexDocuments(r,he)},k)}async search(e,n=10,o){if(!d.isTauriApp())return[];try{await this.ensureInitialized();const s=o&&Object.keys(o).length>0?{type:o.type,apiId:o.apiId,collectionId:o.collectionId,path:o.path,method:o.method,operationId:o.operationId,workflowId:o.workflowId,stepId:o.stepId}:void 0,r=((await d.invoke("semantic_search_text",{collection:this.collectionName,query:e,topK:n,filters:s})).results??[]).map(c=>({...c.payload,score:c.score??0}));return await this.enrichWithRelatedSecurity(r),r}catch{return[]}}async enrichWithRelatedSecurity(e){const n=e.filter(i=>i.type==="api_operation"&&i.securitySchemeRefs?.length);if(n.length===0)return;const o=[...new Set(n.flatMap(i=>i.securitySchemeRefs??[]))],s=await this.getIndexer().getDocumentsByIds(o);for(const i of n){const r=[];for(const c of i.securitySchemeRefs??[]){const a=s.get(c);a?.securityScheme&&r.push(a.securityScheme)}r.length>0&&(i.relatedSecuritySchemes=r)}}async status(){if(!d.isTauriApp())return{indexed:0,modelLoaded:!1};const e=await this.getIndexer().getStoredDocumentCount();let n=!1;try{n=(await d.invoke("semantic_search_model_status")).loaded}catch{}return{indexed:e,modelLoaded:n}}async clear(){if(!(!d.isTauriApp()||!this.initialized))try{await d.invoke("plugin:velesdb|delete_collection",{name:this.collectionName}),this.initialized=!1}catch{}}async preloadModel(){if(d.isTauriApp())try{await d.invoke("semantic_search_preload_model")}catch{}}}let O=null;function xe(){return O||(O=new Z),O}exports.SemanticSearchService=Z;exports.extractAllDocuments=Y;exports.extractApiDocument=W;exports.extractApiDocuments=T;exports.extractCollectionDocument=Q;exports.extractCollectionDocuments=j;exports.extractGlobalSecuritySchemes=G;exports.extractOperationDocument=D;exports.extractStepDocument=K;exports.extractWorkflowDocument=X;exports.getSemanticSearchService=xe;
|