MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / callBackendService

Function callBackendService

frontend/app/store/wos.ts:101–147  ·  view source on GitHub ↗
(service: string, method: string, args: any[], noUIContext?: boolean)

Source from the content-addressed store, hash-verified

99}
100
101function callBackendService(service: string, method: string, args: any[], noUIContext?: boolean): Promise<any> {
102 const startTs = Date.now();
103 let uiContext: UIContext = null;
104 if (!noUIContext && globalThis.window != null) {
105 uiContext = globalStore.get(((window as any).globalAtoms as GlobalAtomsType).uiContext);
106 }
107 const waveCall: WebCallType = {
108 service: service,
109 method: method,
110 args: args,
111 uicontext: uiContext,
112 };
113 // usp is just for debugging (easier to filter URLs)
114 const methodName = `${service}.${method}`;
115 const usp = new URLSearchParams();
116 usp.set("service", service);
117 usp.set("method", method);
118 const webEndpoint = getWebServerEndpoint();
119 if (webEndpoint == null) throw new Error(`cannot call ${methodName}: no web endpoint`);
120 const url = webEndpoint + "/wave/service?" + usp.toString();
121 const fetchPromise = fetch(url, {
122 method: "POST",
123 body: JSON.stringify(waveCall),
124 });
125 const prtn = fetchPromise
126 .then((resp) => {
127 if (!resp.ok) {
128 throw new Error(`call ${methodName} failed: ${resp.status} ${resp.statusText}`);
129 }
130 return resp.json();
131 })
132 .then((respData: WebReturnType) => {
133 if (respData == null) {
134 return null;
135 }
136 if (respData.updates != null) {
137 updateWaveObjects(respData.updates);
138 }
139 if (respData.error != null) {
140 throw new Error(`call ${methodName} error: ${respData.error}`);
141 }
142 const durationStr = Date.now() - startTs + "ms";
143 debugLogBackendCall(methodName, durationStr, args);
144 return respData.data;
145 });
146 return prtn;
147}
148
149const waveObjectValueCache = new Map<string, WaveObjectValue<any>>();
150

Callers 1

GetObjectFunction · 0.70

Calls 5

fetchFunction · 0.90
updateWaveObjectsFunction · 0.85
debugLogBackendCallFunction · 0.85
getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected