@eyepop.ai/eyepop 0.18.0 → 0.18.2
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/eyepop.index.d.mts +1 -0
- package/dist/eyepop.index.d.ts +1 -0
- package/dist/eyepop.index.js +70 -40
- package/dist/eyepop.index.js.map +1 -1
- package/dist/eyepop.index.mjs +70 -40
- package/dist/eyepop.index.mjs.map +1 -1
- package/dist/eyepop.min.js +1 -1
- package/package.json +1 -1
package/dist/eyepop.index.d.mts
CHANGED
package/dist/eyepop.index.d.ts
CHANGED
package/dist/eyepop.index.js
CHANGED
|
@@ -9859,28 +9859,31 @@ var Endpoint = class {
|
|
|
9859
9859
|
}
|
|
9860
9860
|
}
|
|
9861
9861
|
async changePopComp(popComp) {
|
|
9862
|
-
|
|
9862
|
+
const client = this._client;
|
|
9863
|
+
const baseUrl = this._baseUrl;
|
|
9864
|
+
if (!baseUrl || !client) {
|
|
9863
9865
|
return Promise.reject("endpoint not connected, use connect() before changePopComp()");
|
|
9864
9866
|
}
|
|
9865
|
-
const patch_url = `${this._baseUrl}/pipelines/${this._pipelineId}/inferencePipeline`;
|
|
9866
|
-
const headers = {
|
|
9867
|
-
"Authorization": await this.authorizationHeader(),
|
|
9868
|
-
"Content-Type": "application/json"
|
|
9869
|
-
};
|
|
9870
9867
|
const body = {
|
|
9871
9868
|
"pipeline": popComp
|
|
9872
9869
|
};
|
|
9873
|
-
this.
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9870
|
+
let response = await this.fetchWithRetry(async () => {
|
|
9871
|
+
const session = await this.session();
|
|
9872
|
+
let headers = {
|
|
9873
|
+
"Authorization": session.accessToken,
|
|
9874
|
+
"Content-Type": "application/json"
|
|
9875
|
+
};
|
|
9876
|
+
const patch_url = `${session.baseUrl}/pipelines/${session.pipelineId}/inferencePipeline`;
|
|
9877
|
+
return client.fetch(patch_url, {
|
|
9878
|
+
method: "PATCH",
|
|
9879
|
+
body: JSON.stringify(body),
|
|
9880
|
+
headers
|
|
9881
|
+
});
|
|
9878
9882
|
});
|
|
9879
9883
|
if (response.status != 204) {
|
|
9880
9884
|
const message = await response.text();
|
|
9881
9885
|
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
9882
9886
|
}
|
|
9883
|
-
this._requestLogger.debug("after PATCH %s", patch_url);
|
|
9884
9887
|
if (this._pipeline) {
|
|
9885
9888
|
this._pipeline.inferPipeline = popComp;
|
|
9886
9889
|
}
|
|
@@ -9923,25 +9926,27 @@ var Endpoint = class {
|
|
|
9923
9926
|
return Promise.reject("option secretKey or environment variable EYEPOP_SECRET_KEY is required");
|
|
9924
9927
|
}
|
|
9925
9928
|
this._client = await createHttpClient();
|
|
9929
|
+
const client = this._client;
|
|
9926
9930
|
let result = await this.reconnect();
|
|
9927
9931
|
if (this._baseUrl && this._options.stopJobs) {
|
|
9928
|
-
const stop_url = `${this._baseUrl}/pipelines/${this._pipelineId}/source?mode=preempt&processing=sync`;
|
|
9929
9932
|
const body = { "sourceType": "NONE" };
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9933
|
+
let response = await this.fetchWithRetry(async () => {
|
|
9934
|
+
const session = await this.session();
|
|
9935
|
+
const headers = {
|
|
9936
|
+
"Authorization": session.accessToken,
|
|
9937
|
+
"Content-Type": "application/json"
|
|
9938
|
+
};
|
|
9939
|
+
const stop_url = `${session.baseUrl}/pipelines/${session.pipelineId}/source?mode=preempt&processing=sync`;
|
|
9940
|
+
return client.fetch(stop_url, {
|
|
9941
|
+
method: "PATCH",
|
|
9942
|
+
headers,
|
|
9943
|
+
body: JSON.stringify(body)
|
|
9944
|
+
});
|
|
9939
9945
|
});
|
|
9940
9946
|
if (response.status >= 300) {
|
|
9941
9947
|
const message = await response.text();
|
|
9942
9948
|
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
9943
9949
|
}
|
|
9944
|
-
this._requestLogger.debug("after PATCH %s", stop_url);
|
|
9945
9950
|
}
|
|
9946
9951
|
if (!this._ingressEventWs && this._ingressEventHandler) {
|
|
9947
9952
|
await this.startIngressWs();
|
|
@@ -10016,25 +10021,19 @@ var Endpoint = class {
|
|
|
10016
10021
|
}
|
|
10017
10022
|
}
|
|
10018
10023
|
async startIngressWs() {
|
|
10019
|
-
|
|
10024
|
+
const client = this._client;
|
|
10025
|
+
if (this._ingressEventWs || !this._baseUrl || !client) {
|
|
10020
10026
|
return;
|
|
10021
10027
|
}
|
|
10022
10028
|
try {
|
|
10023
|
-
const
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
this._requestLogger.debug("before GET %s", getTokenUrl);
|
|
10028
|
-
let response = await this._client.fetch(getTokenUrl, { headers });
|
|
10029
|
-
if (response.status == 401) {
|
|
10030
|
-
this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", getTokenUrl);
|
|
10031
|
-
this._token = null;
|
|
10032
|
-
const headers2 = {
|
|
10033
|
-
"Authorization": await this.authorizationHeader()
|
|
10029
|
+
const session = await this.session();
|
|
10030
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10031
|
+
const headers = {
|
|
10032
|
+
"Authorization": session.accessToken
|
|
10034
10033
|
};
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
}
|
|
10034
|
+
const getTokenUrl = `${session.baseUrl}/liveIngress/events/token`;
|
|
10035
|
+
return client.fetch(getTokenUrl, { headers });
|
|
10036
|
+
});
|
|
10038
10037
|
if (response.status != 200) {
|
|
10039
10038
|
const message = await response.text();
|
|
10040
10039
|
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
@@ -10180,6 +10179,39 @@ var Endpoint = class {
|
|
|
10180
10179
|
this._expire_token_time = null;
|
|
10181
10180
|
}
|
|
10182
10181
|
}
|
|
10182
|
+
async fetchWithRetry(fetcher, retries = 1) {
|
|
10183
|
+
while (true) {
|
|
10184
|
+
try {
|
|
10185
|
+
const response = await fetcher();
|
|
10186
|
+
if (response.status == 401) {
|
|
10187
|
+
this._token = null;
|
|
10188
|
+
this._expire_token_time = null;
|
|
10189
|
+
if (retries--) {
|
|
10190
|
+
this._requestLogger.info("received 401 response, attempt to reauthorize and retry");
|
|
10191
|
+
} else {
|
|
10192
|
+
return Promise.reject(`response ${response.status}: ${response.statusText}`);
|
|
10193
|
+
}
|
|
10194
|
+
} else if (response.status == 404) {
|
|
10195
|
+
this._pipelineId = null;
|
|
10196
|
+
this._baseUrl = null;
|
|
10197
|
+
if (retries--) {
|
|
10198
|
+
this._requestLogger.info("received 404 response, attempt to restart pop and retry");
|
|
10199
|
+
} else {
|
|
10200
|
+
return Promise.reject(`response ${response.status}: ${response.statusText}`);
|
|
10201
|
+
}
|
|
10202
|
+
} else {
|
|
10203
|
+
return response;
|
|
10204
|
+
}
|
|
10205
|
+
} catch (error) {
|
|
10206
|
+
this._pipelineId = null;
|
|
10207
|
+
this._baseUrl = null;
|
|
10208
|
+
if (retries--) {
|
|
10209
|
+
this._requestLogger.info("unknown, attempt to restart pop (as if we received 404)", error);
|
|
10210
|
+
return Promise.reject(error);
|
|
10211
|
+
}
|
|
10212
|
+
}
|
|
10213
|
+
}
|
|
10214
|
+
}
|
|
10183
10215
|
async reconnect() {
|
|
10184
10216
|
if (!this._client) {
|
|
10185
10217
|
return Promise.reject("endpoint not initialized");
|
|
@@ -10205,7 +10237,6 @@ var Endpoint = class {
|
|
|
10205
10237
|
this.updateState("FetchConfig" /* FetchConfig */);
|
|
10206
10238
|
response = await this._client.fetch(config_url, {
|
|
10207
10239
|
headers: headers2
|
|
10208
|
-
// @ts-ignore
|
|
10209
10240
|
});
|
|
10210
10241
|
}
|
|
10211
10242
|
if (response.status != 200) {
|
|
@@ -10223,7 +10254,6 @@ var Endpoint = class {
|
|
|
10223
10254
|
this.updateState("StartingPop" /* StartingPop */);
|
|
10224
10255
|
response = await this._client.fetch(auto_start_config_url, {
|
|
10225
10256
|
headers: headers2
|
|
10226
|
-
// @ts-ignore
|
|
10227
10257
|
});
|
|
10228
10258
|
if (response.status != 200) {
|
|
10229
10259
|
this.updateState("Error" /* Error */);
|