@eyepop.ai/eyepop 0.20.1 → 0.21.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/README.md +41 -24
- package/dist/eyepop.index.d.mts +397 -78
- package/dist/eyepop.index.d.ts +397 -78
- package/dist/eyepop.index.js +1515 -690
- package/dist/eyepop.index.js.map +1 -1
- package/dist/eyepop.index.mjs +1502 -689
- package/dist/eyepop.index.mjs.map +1 -1
- package/dist/eyepop.min.js +1 -1
- package/package.json +6 -3
package/dist/eyepop.index.mjs
CHANGED
|
@@ -8638,7 +8638,6 @@ var EndpointState = /* @__PURE__ */ ((EndpointState2) => {
|
|
|
8638
8638
|
EndpointState2["Busy"] = "Busy";
|
|
8639
8639
|
EndpointState2["Authenticating"] = "Authenticating";
|
|
8640
8640
|
EndpointState2["FetchConfig"] = "FetchConfig";
|
|
8641
|
-
EndpointState2["StartingPop"] = "StartingPop";
|
|
8642
8641
|
EndpointState2["Error"] = "Error";
|
|
8643
8642
|
return EndpointState2;
|
|
8644
8643
|
})(EndpointState || {});
|
|
@@ -8881,7 +8880,7 @@ function readableStreamAsyncIterable(stream) {
|
|
|
8881
8880
|
};
|
|
8882
8881
|
}
|
|
8883
8882
|
|
|
8884
|
-
// jobs.ts
|
|
8883
|
+
// worker/jobs.ts
|
|
8885
8884
|
var AbstractJob = class {
|
|
8886
8885
|
constructor(params, getSession, client, requestLogger) {
|
|
8887
8886
|
this._responseStream = null;
|
|
@@ -8968,6 +8967,9 @@ var UploadJob = class extends AbstractJob {
|
|
|
8968
8967
|
}
|
|
8969
8968
|
async startJob() {
|
|
8970
8969
|
const session = await this._getSession();
|
|
8970
|
+
if (!session.baseUrl) {
|
|
8971
|
+
return Promise.reject("session.baseUrl must not ne null");
|
|
8972
|
+
}
|
|
8971
8973
|
const postUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/source?mode=queue&processing=sync`;
|
|
8972
8974
|
let response;
|
|
8973
8975
|
if (this._params) {
|
|
@@ -9021,12 +9023,15 @@ var LoadFromJob = class extends AbstractJob {
|
|
|
9021
9023
|
return "loadFromJob";
|
|
9022
9024
|
}
|
|
9023
9025
|
async startJob() {
|
|
9026
|
+
const session = await this._getSession();
|
|
9027
|
+
if (!session.baseUrl) {
|
|
9028
|
+
return Promise.reject("session.baseUrl must not ne null");
|
|
9029
|
+
}
|
|
9024
9030
|
const body = {
|
|
9025
9031
|
"sourceType": "URL",
|
|
9026
9032
|
"url": this._location,
|
|
9027
9033
|
"params": this._params
|
|
9028
9034
|
};
|
|
9029
|
-
const session = await this._getSession();
|
|
9030
9035
|
const headers = {
|
|
9031
9036
|
"Authorization": `Bearer ${session.accessToken}`,
|
|
9032
9037
|
"Accept": "application/jsonl",
|
|
@@ -9055,12 +9060,15 @@ var LoadLiveIngressJob = class extends AbstractJob {
|
|
|
9055
9060
|
return "loadLiveIngressJob";
|
|
9056
9061
|
}
|
|
9057
9062
|
async startJob() {
|
|
9063
|
+
const session = await this._getSession();
|
|
9064
|
+
if (!session.baseUrl) {
|
|
9065
|
+
return Promise.reject("session.baseUrl must not ne null");
|
|
9066
|
+
}
|
|
9058
9067
|
const body = {
|
|
9059
9068
|
"sourceType": "LIVE_INGRESS",
|
|
9060
9069
|
"liveIngressId": this._ingressId,
|
|
9061
9070
|
"params": this._params
|
|
9062
9071
|
};
|
|
9063
|
-
const session = await this._getSession();
|
|
9064
9072
|
const headers = {
|
|
9065
9073
|
"Authorization": `Bearer ${session.accessToken}`,
|
|
9066
9074
|
"Accept": "application/jsonl",
|
|
@@ -9081,173 +9089,6 @@ var LoadLiveIngressJob = class extends AbstractJob {
|
|
|
9081
9089
|
}
|
|
9082
9090
|
};
|
|
9083
9091
|
|
|
9084
|
-
// shims/http_client.ts
|
|
9085
|
-
var createHttpClient;
|
|
9086
|
-
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
9087
|
-
class HttpClient2 {
|
|
9088
|
-
constructor() {
|
|
9089
|
-
}
|
|
9090
|
-
async fetch(input, init) {
|
|
9091
|
-
return fetch(input, init);
|
|
9092
|
-
}
|
|
9093
|
-
async close() {
|
|
9094
|
-
}
|
|
9095
|
-
}
|
|
9096
|
-
createHttpClient = async () => {
|
|
9097
|
-
return new HttpClient2();
|
|
9098
|
-
};
|
|
9099
|
-
} else {
|
|
9100
|
-
class HttpClient2 {
|
|
9101
|
-
constructor(agent) {
|
|
9102
|
-
this.agent = agent;
|
|
9103
|
-
}
|
|
9104
|
-
async fetch(input, init) {
|
|
9105
|
-
init || (init = {});
|
|
9106
|
-
init.dispatcher = this.agent;
|
|
9107
|
-
return fetch(input, init);
|
|
9108
|
-
}
|
|
9109
|
-
async close() {
|
|
9110
|
-
return this.agent.close();
|
|
9111
|
-
}
|
|
9112
|
-
}
|
|
9113
|
-
createHttpClient = async () => {
|
|
9114
|
-
const undici = __require("undici");
|
|
9115
|
-
const agent = new undici.Agent({
|
|
9116
|
-
keepAliveTimeout: 1e4,
|
|
9117
|
-
connections: 5
|
|
9118
|
-
});
|
|
9119
|
-
return new HttpClient2(agent);
|
|
9120
|
-
};
|
|
9121
|
-
}
|
|
9122
|
-
|
|
9123
|
-
// semaphore.ts
|
|
9124
|
-
var Semaphore = class {
|
|
9125
|
-
/**
|
|
9126
|
-
* Creates a semaphore.
|
|
9127
|
-
* @param permits The number of permits, i.e. strands of execution being allowed
|
|
9128
|
-
* to run in parallel.
|
|
9129
|
-
* This number can be initialized with a negative integer.
|
|
9130
|
-
*/
|
|
9131
|
-
constructor(permits) {
|
|
9132
|
-
this.promiseResolverQueue = [];
|
|
9133
|
-
this.permits = permits;
|
|
9134
|
-
}
|
|
9135
|
-
/**
|
|
9136
|
-
* Returns the number of available permits.
|
|
9137
|
-
* @returns The number of available permits.
|
|
9138
|
-
*/
|
|
9139
|
-
getPermits() {
|
|
9140
|
-
return this.permits;
|
|
9141
|
-
}
|
|
9142
|
-
/**
|
|
9143
|
-
* Returns a promise used to wait for a permit to become available. This method should be awaited on.
|
|
9144
|
-
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
9145
|
-
*/
|
|
9146
|
-
async wait() {
|
|
9147
|
-
if (this.permits > 0) {
|
|
9148
|
-
this.permits -= 1;
|
|
9149
|
-
return Promise.resolve(true);
|
|
9150
|
-
}
|
|
9151
|
-
return new Promise((resolver) => this.promiseResolverQueue.push(resolver));
|
|
9152
|
-
}
|
|
9153
|
-
/**
|
|
9154
|
-
* Alias for {@linkcode Semaphore.wait}.
|
|
9155
|
-
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
9156
|
-
*/
|
|
9157
|
-
async acquire() {
|
|
9158
|
-
return this.wait();
|
|
9159
|
-
}
|
|
9160
|
-
/**
|
|
9161
|
-
* Same as {@linkcode Semaphore.wait} except the promise returned gets resolved with false if no
|
|
9162
|
-
* permit becomes available in time.
|
|
9163
|
-
* @param milliseconds The time spent waiting before the wait is aborted. This is a lower bound,
|
|
9164
|
-
* you shouldn't rely on it being precise.
|
|
9165
|
-
* @returns A promise that gets resolved to true when execution is allowed to proceed or
|
|
9166
|
-
* false if the time given elapses before a permit becomes available.
|
|
9167
|
-
*/
|
|
9168
|
-
async waitFor(milliseconds) {
|
|
9169
|
-
if (this.permits > 0) {
|
|
9170
|
-
this.permits -= 1;
|
|
9171
|
-
return Promise.resolve(true);
|
|
9172
|
-
}
|
|
9173
|
-
let resolver = (b) => void 0;
|
|
9174
|
-
const promise = new Promise((r) => {
|
|
9175
|
-
resolver = r;
|
|
9176
|
-
});
|
|
9177
|
-
this.promiseResolverQueue.push(resolver);
|
|
9178
|
-
setTimeout(() => {
|
|
9179
|
-
const index = this.promiseResolverQueue.indexOf(resolver);
|
|
9180
|
-
if (index !== -1) {
|
|
9181
|
-
this.promiseResolverQueue.splice(index, 1);
|
|
9182
|
-
} else {
|
|
9183
|
-
console.warn(`Semaphore.waitFor couldn't find its promise resolver in the queue`);
|
|
9184
|
-
}
|
|
9185
|
-
resolver(false);
|
|
9186
|
-
}, milliseconds);
|
|
9187
|
-
return promise;
|
|
9188
|
-
}
|
|
9189
|
-
/**
|
|
9190
|
-
* Synchronous function that tries to acquire a permit and returns true if successful, false otherwise.
|
|
9191
|
-
* @returns Whether a permit could be acquired.
|
|
9192
|
-
*/
|
|
9193
|
-
tryAcquire() {
|
|
9194
|
-
if (this.permits > 0) {
|
|
9195
|
-
this.permits -= 1;
|
|
9196
|
-
return true;
|
|
9197
|
-
}
|
|
9198
|
-
return false;
|
|
9199
|
-
}
|
|
9200
|
-
/**
|
|
9201
|
-
* Acquires all permits that are currently available and returns the number of acquired permits.
|
|
9202
|
-
* @returns Number of acquired permits.
|
|
9203
|
-
*/
|
|
9204
|
-
drainPermits() {
|
|
9205
|
-
if (this.permits > 0) {
|
|
9206
|
-
const permitCount = this.permits;
|
|
9207
|
-
this.permits = 0;
|
|
9208
|
-
return permitCount;
|
|
9209
|
-
}
|
|
9210
|
-
return 0;
|
|
9211
|
-
}
|
|
9212
|
-
/**
|
|
9213
|
-
* Increases the number of permits by one. If there are other functions waiting, one of them will
|
|
9214
|
-
* continue to execute in a future iteration of the event loop.
|
|
9215
|
-
*/
|
|
9216
|
-
signal() {
|
|
9217
|
-
this.permits += 1;
|
|
9218
|
-
if (this.permits > 1 && this.promiseResolverQueue.length > 0) {
|
|
9219
|
-
console.warn("Semaphore.permits should never be > 0 when there is someone waiting.");
|
|
9220
|
-
} else if (this.permits === 1 && this.promiseResolverQueue.length > 0) {
|
|
9221
|
-
this.permits -= 1;
|
|
9222
|
-
const nextResolver = this.promiseResolverQueue.shift();
|
|
9223
|
-
if (nextResolver) {
|
|
9224
|
-
nextResolver(true);
|
|
9225
|
-
}
|
|
9226
|
-
}
|
|
9227
|
-
}
|
|
9228
|
-
/**
|
|
9229
|
-
* Alias for {@linkcode Semaphore.signal}.
|
|
9230
|
-
*/
|
|
9231
|
-
release() {
|
|
9232
|
-
this.signal();
|
|
9233
|
-
}
|
|
9234
|
-
/**
|
|
9235
|
-
* Schedules func to be called once a permit becomes available.
|
|
9236
|
-
* Returns a promise that resolves to the return value of func.
|
|
9237
|
-
* @typeparam T The return type of func.
|
|
9238
|
-
* @param func The function to be executed.
|
|
9239
|
-
* @return A promise that gets resolved with the return value of the function.
|
|
9240
|
-
*/
|
|
9241
|
-
async execute(func) {
|
|
9242
|
-
await this.wait();
|
|
9243
|
-
try {
|
|
9244
|
-
return await func();
|
|
9245
|
-
} finally {
|
|
9246
|
-
this.signal();
|
|
9247
|
-
}
|
|
9248
|
-
}
|
|
9249
|
-
};
|
|
9250
|
-
|
|
9251
9092
|
// ../../node_modules/uuid/dist/esm-node/rng.js
|
|
9252
9093
|
import crypto from "crypto";
|
|
9253
9094
|
var rnds8Pool = new Uint8Array(256);
|
|
@@ -9295,7 +9136,7 @@ function v4(options, buf, offset) {
|
|
|
9295
9136
|
}
|
|
9296
9137
|
var v4_default = v4;
|
|
9297
9138
|
|
|
9298
|
-
// webrtc_base.ts
|
|
9139
|
+
// worker/webrtc_base.ts
|
|
9299
9140
|
import path from "path";
|
|
9300
9141
|
var WebrtcBase = class _WebrtcBase {
|
|
9301
9142
|
constructor(getSession, client, ingressId, urlBasePath, requestLogger) {
|
|
@@ -9536,7 +9377,7 @@ var WebrtcBase = class _WebrtcBase {
|
|
|
9536
9377
|
}
|
|
9537
9378
|
};
|
|
9538
9379
|
|
|
9539
|
-
// webrtc_whip.ts
|
|
9380
|
+
// worker/webrtc_whip.ts
|
|
9540
9381
|
var WebrtcWhip = class extends WebrtcBase {
|
|
9541
9382
|
constructor(stream, getSession, client, requestLogger) {
|
|
9542
9383
|
super(getSession, client, v4_default().toString(), "/liveIngress/whip", requestLogger);
|
|
@@ -9622,7 +9463,7 @@ var WebrtcWhip = class extends WebrtcBase {
|
|
|
9622
9463
|
}
|
|
9623
9464
|
};
|
|
9624
9465
|
|
|
9625
|
-
// webrtc_whep.ts
|
|
9466
|
+
// worker/webrtc_whep.ts
|
|
9626
9467
|
var WebrtcWhep = class extends WebrtcBase {
|
|
9627
9468
|
constructor(ingressId, getSession, client, requestLogger) {
|
|
9628
9469
|
super(getSession, client, ingressId, "/liveIngress/whep", requestLogger);
|
|
@@ -9728,89 +9569,489 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9728
9569
|
};
|
|
9729
9570
|
}
|
|
9730
9571
|
|
|
9731
|
-
//
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
// shims/browser_session.ts
|
|
9735
|
-
import { createAuth0Client } from "@auth0/auth0-spa-js";
|
|
9736
|
-
var authenticateBrowserSession;
|
|
9572
|
+
// shims/http_client.ts
|
|
9573
|
+
var createHttpClient;
|
|
9737
9574
|
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
clientId: auth0.clientId,
|
|
9741
|
-
domain: auth0.domain,
|
|
9742
|
-
authorizationParams: {
|
|
9743
|
-
scope: auth0.scope,
|
|
9744
|
-
audience: auth0.audience
|
|
9745
|
-
}
|
|
9746
|
-
};
|
|
9747
|
-
const auth0Client = await createAuth0Client(options);
|
|
9748
|
-
if (!await auth0Client.isAuthenticated()) {
|
|
9749
|
-
await auth0Client.loginWithPopup();
|
|
9575
|
+
class HttpClient2 {
|
|
9576
|
+
constructor() {
|
|
9750
9577
|
}
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
return Promise.reject("auth0 login failed");
|
|
9578
|
+
async fetch(input, init) {
|
|
9579
|
+
return fetch(input, init);
|
|
9754
9580
|
}
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
};
|
|
9761
|
-
return session;
|
|
9581
|
+
async close() {
|
|
9582
|
+
}
|
|
9583
|
+
}
|
|
9584
|
+
createHttpClient = async () => {
|
|
9585
|
+
return new HttpClient2();
|
|
9762
9586
|
};
|
|
9763
9587
|
} else {
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
}
|
|
9768
|
-
|
|
9769
|
-
// endpoint.ts
|
|
9770
|
-
var Endpoint = class {
|
|
9771
|
-
constructor(options) {
|
|
9772
|
-
this._options = options;
|
|
9773
|
-
this._baseUrl = null;
|
|
9774
|
-
this._pipelineId = null;
|
|
9775
|
-
this._popName = null;
|
|
9776
|
-
this._token = null;
|
|
9777
|
-
this._expire_token_time = null;
|
|
9778
|
-
this._client = null;
|
|
9779
|
-
this._state = "Idle" /* Idle */;
|
|
9780
|
-
this._pipeline = null;
|
|
9781
|
-
this._stateChangeHandler = null;
|
|
9782
|
-
this._ingressEventHandler = null;
|
|
9783
|
-
this._ingressEventWs = null;
|
|
9784
|
-
this._sandboxId = null;
|
|
9785
|
-
const sessionAuth = options.auth;
|
|
9786
|
-
if (sessionAuth.session !== void 0) {
|
|
9787
|
-
const sessionPlus = sessionAuth.session;
|
|
9788
|
-
if (sessionPlus.sandboxId) {
|
|
9789
|
-
this._sandboxId = sessionPlus.sandboxId;
|
|
9790
|
-
}
|
|
9588
|
+
class HttpClient2 {
|
|
9589
|
+
constructor(agent) {
|
|
9590
|
+
this.agent = agent;
|
|
9791
9591
|
}
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
} else {
|
|
9797
|
-
rootLogger = pino();
|
|
9592
|
+
async fetch(input, init) {
|
|
9593
|
+
init || (init = {});
|
|
9594
|
+
init.dispatcher = this.agent;
|
|
9595
|
+
return fetch(input, init);
|
|
9798
9596
|
}
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
}
|
|
9802
|
-
eyepopUrl() {
|
|
9803
|
-
if (this._options.eyepopUrl) {
|
|
9804
|
-
return this._options.eyepopUrl.replace(/\/+$/, "");
|
|
9805
|
-
} else {
|
|
9806
|
-
return "https://api.eyepop.ai";
|
|
9597
|
+
async close() {
|
|
9598
|
+
return this.agent.close();
|
|
9807
9599
|
}
|
|
9808
9600
|
}
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
|
|
9601
|
+
createHttpClient = async () => {
|
|
9602
|
+
const undici = __require("undici");
|
|
9603
|
+
const agent = new undici.Agent({
|
|
9604
|
+
keepAliveTimeout: 1e4,
|
|
9605
|
+
connections: 5
|
|
9606
|
+
});
|
|
9607
|
+
return new HttpClient2(agent);
|
|
9608
|
+
};
|
|
9609
|
+
}
|
|
9610
|
+
|
|
9611
|
+
// semaphore.ts
|
|
9612
|
+
var Semaphore = class {
|
|
9613
|
+
/**
|
|
9614
|
+
* Creates a semaphore.
|
|
9615
|
+
* @param permits The number of permits, i.e. strands of execution being allowed
|
|
9616
|
+
* to run in parallel.
|
|
9617
|
+
* This number can be initialized with a negative integer.
|
|
9618
|
+
*/
|
|
9619
|
+
constructor(permits) {
|
|
9620
|
+
this.promiseResolverQueue = [];
|
|
9621
|
+
this.permits = permits;
|
|
9622
|
+
}
|
|
9623
|
+
/**
|
|
9624
|
+
* Returns the number of available permits.
|
|
9625
|
+
* @returns The number of available permits.
|
|
9626
|
+
*/
|
|
9627
|
+
getPermits() {
|
|
9628
|
+
return this.permits;
|
|
9629
|
+
}
|
|
9630
|
+
/**
|
|
9631
|
+
* Returns a promise used to wait for a permit to become available. This method should be awaited on.
|
|
9632
|
+
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
9633
|
+
*/
|
|
9634
|
+
async wait() {
|
|
9635
|
+
if (this.permits > 0) {
|
|
9636
|
+
this.permits -= 1;
|
|
9637
|
+
return Promise.resolve(true);
|
|
9638
|
+
}
|
|
9639
|
+
return new Promise((resolver) => this.promiseResolverQueue.push(resolver));
|
|
9640
|
+
}
|
|
9641
|
+
/**
|
|
9642
|
+
* Alias for {@linkcode Semaphore.wait}.
|
|
9643
|
+
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
9644
|
+
*/
|
|
9645
|
+
async acquire() {
|
|
9646
|
+
return this.wait();
|
|
9647
|
+
}
|
|
9648
|
+
/**
|
|
9649
|
+
* Same as {@linkcode Semaphore.wait} except the promise returned gets resolved with false if no
|
|
9650
|
+
* permit becomes available in time.
|
|
9651
|
+
* @param milliseconds The time spent waiting before the wait is aborted. This is a lower bound,
|
|
9652
|
+
* you shouldn't rely on it being precise.
|
|
9653
|
+
* @returns A promise that gets resolved to true when execution is allowed to proceed or
|
|
9654
|
+
* false if the time given elapses before a permit becomes available.
|
|
9655
|
+
*/
|
|
9656
|
+
async waitFor(milliseconds) {
|
|
9657
|
+
if (this.permits > 0) {
|
|
9658
|
+
this.permits -= 1;
|
|
9659
|
+
return Promise.resolve(true);
|
|
9660
|
+
}
|
|
9661
|
+
let resolver = (b) => void 0;
|
|
9662
|
+
const promise = new Promise((r) => {
|
|
9663
|
+
resolver = r;
|
|
9664
|
+
});
|
|
9665
|
+
this.promiseResolverQueue.push(resolver);
|
|
9666
|
+
setTimeout(() => {
|
|
9667
|
+
const index = this.promiseResolverQueue.indexOf(resolver);
|
|
9668
|
+
if (index !== -1) {
|
|
9669
|
+
this.promiseResolverQueue.splice(index, 1);
|
|
9670
|
+
} else {
|
|
9671
|
+
console.warn(`Semaphore.waitFor couldn't find its promise resolver in the queue`);
|
|
9672
|
+
}
|
|
9673
|
+
resolver(false);
|
|
9674
|
+
}, milliseconds);
|
|
9675
|
+
return promise;
|
|
9676
|
+
}
|
|
9677
|
+
/**
|
|
9678
|
+
* Synchronous function that tries to acquire a permit and returns true if successful, false otherwise.
|
|
9679
|
+
* @returns Whether a permit could be acquired.
|
|
9680
|
+
*/
|
|
9681
|
+
tryAcquire() {
|
|
9682
|
+
if (this.permits > 0) {
|
|
9683
|
+
this.permits -= 1;
|
|
9684
|
+
return true;
|
|
9685
|
+
}
|
|
9686
|
+
return false;
|
|
9687
|
+
}
|
|
9688
|
+
/**
|
|
9689
|
+
* Acquires all permits that are currently available and returns the number of acquired permits.
|
|
9690
|
+
* @returns Number of acquired permits.
|
|
9691
|
+
*/
|
|
9692
|
+
drainPermits() {
|
|
9693
|
+
if (this.permits > 0) {
|
|
9694
|
+
const permitCount = this.permits;
|
|
9695
|
+
this.permits = 0;
|
|
9696
|
+
return permitCount;
|
|
9697
|
+
}
|
|
9698
|
+
return 0;
|
|
9699
|
+
}
|
|
9700
|
+
/**
|
|
9701
|
+
* Increases the number of permits by one. If there are other functions waiting, one of them will
|
|
9702
|
+
* continue to execute in a future iteration of the event loop.
|
|
9703
|
+
*/
|
|
9704
|
+
signal() {
|
|
9705
|
+
this.permits += 1;
|
|
9706
|
+
if (this.permits > 1 && this.promiseResolverQueue.length > 0) {
|
|
9707
|
+
console.warn("Semaphore.permits should never be > 0 when there is someone waiting.");
|
|
9708
|
+
} else if (this.permits === 1 && this.promiseResolverQueue.length > 0) {
|
|
9709
|
+
this.permits -= 1;
|
|
9710
|
+
const nextResolver = this.promiseResolverQueue.shift();
|
|
9711
|
+
if (nextResolver) {
|
|
9712
|
+
nextResolver(true);
|
|
9713
|
+
}
|
|
9714
|
+
}
|
|
9715
|
+
}
|
|
9716
|
+
/**
|
|
9717
|
+
* Alias for {@linkcode Semaphore.signal}.
|
|
9718
|
+
*/
|
|
9719
|
+
release() {
|
|
9720
|
+
this.signal();
|
|
9721
|
+
}
|
|
9722
|
+
/**
|
|
9723
|
+
* Schedules func to be called once a permit becomes available.
|
|
9724
|
+
* Returns a promise that resolves to the return value of func.
|
|
9725
|
+
* @typeparam T The return type of func.
|
|
9726
|
+
* @param func The function to be executed.
|
|
9727
|
+
* @return A promise that gets resolved with the return value of the function.
|
|
9728
|
+
*/
|
|
9729
|
+
async execute(func) {
|
|
9730
|
+
await this.wait();
|
|
9731
|
+
try {
|
|
9732
|
+
return await func();
|
|
9733
|
+
} finally {
|
|
9734
|
+
this.signal();
|
|
9735
|
+
}
|
|
9736
|
+
}
|
|
9737
|
+
};
|
|
9738
|
+
|
|
9739
|
+
// endpoint.ts
|
|
9740
|
+
import { pino } from "pino";
|
|
9741
|
+
|
|
9742
|
+
// shims/browser_session.ts
|
|
9743
|
+
import { createAuth0Client } from "@auth0/auth0-spa-js";
|
|
9744
|
+
var authenticateBrowserSession;
|
|
9745
|
+
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
9746
|
+
authenticateBrowserSession = async (auth0, options) => {
|
|
9747
|
+
if (options.eyepopUrl == null) {
|
|
9748
|
+
return Promise.reject("options.eyepopUrl cannot be null");
|
|
9749
|
+
}
|
|
9750
|
+
const auth0ClientOptions = {
|
|
9751
|
+
clientId: auth0.clientId,
|
|
9752
|
+
domain: auth0.domain,
|
|
9753
|
+
authorizationParams: {
|
|
9754
|
+
scope: auth0.scope,
|
|
9755
|
+
audience: auth0.audience
|
|
9756
|
+
}
|
|
9757
|
+
};
|
|
9758
|
+
const auth0Client = await createAuth0Client(auth0ClientOptions);
|
|
9759
|
+
if (!await auth0Client.isAuthenticated()) {
|
|
9760
|
+
await auth0Client.loginWithPopup();
|
|
9761
|
+
}
|
|
9762
|
+
const accessToken = await auth0Client.getTokenSilently();
|
|
9763
|
+
if (!accessToken) {
|
|
9764
|
+
return Promise.reject("auth0 login failed");
|
|
9765
|
+
}
|
|
9766
|
+
let session;
|
|
9767
|
+
const workerOptions = options;
|
|
9768
|
+
if (typeof workerOptions.popId != "undefined") {
|
|
9769
|
+
const workerSession = {
|
|
9770
|
+
eyepopUrl: options.eyepopUrl,
|
|
9771
|
+
accessToken,
|
|
9772
|
+
validUntil: Date.now() + 60 * 60 * 1e3,
|
|
9773
|
+
popId: workerOptions.popId,
|
|
9774
|
+
baseUrl: void 0,
|
|
9775
|
+
pipelineId: void 0,
|
|
9776
|
+
sandboxId: void 0
|
|
9777
|
+
};
|
|
9778
|
+
session = workerSession;
|
|
9779
|
+
} else {
|
|
9780
|
+
session = {
|
|
9781
|
+
eyepopUrl: options.eyepopUrl,
|
|
9782
|
+
accessToken,
|
|
9783
|
+
validUntil: Date.now() + 60 * 60 * 1e3
|
|
9784
|
+
};
|
|
9785
|
+
}
|
|
9786
|
+
return session;
|
|
9787
|
+
};
|
|
9788
|
+
} else {
|
|
9789
|
+
authenticateBrowserSession = (auth0, options) => {
|
|
9790
|
+
return Promise.reject("auth0 login not supported server-side");
|
|
9791
|
+
};
|
|
9792
|
+
}
|
|
9793
|
+
|
|
9794
|
+
// endpoint.ts
|
|
9795
|
+
var Endpoint = class {
|
|
9796
|
+
constructor(options) {
|
|
9797
|
+
this._options = options;
|
|
9798
|
+
this._token = null;
|
|
9799
|
+
this._expire_token_time = null;
|
|
9800
|
+
this._client = null;
|
|
9801
|
+
this._statusRetryHandlers = /* @__PURE__ */ new Map();
|
|
9802
|
+
this._statusRetryHandlers.set(401, this.statusHandler401);
|
|
9803
|
+
this._limit = new Semaphore(this._options.jobQueueLength ?? 1024);
|
|
9804
|
+
this._state = "Idle" /* Idle */;
|
|
9805
|
+
this._stateChangeHandler = null;
|
|
9806
|
+
let rootLogger;
|
|
9807
|
+
if (options.logger) {
|
|
9808
|
+
rootLogger = options.logger;
|
|
9809
|
+
} else {
|
|
9810
|
+
rootLogger = pino();
|
|
9811
|
+
}
|
|
9812
|
+
this._logger = rootLogger.child({ module: "eyepop" });
|
|
9813
|
+
this._requestLogger = this._logger.child({ module: "requests" });
|
|
9814
|
+
}
|
|
9815
|
+
setStatusRetryHandlers(statusRetryHandlers = void 0) {
|
|
9816
|
+
this._statusRetryHandlers = new Map(statusRetryHandlers);
|
|
9817
|
+
this._statusRetryHandlers.set(401, this.statusHandler401);
|
|
9818
|
+
}
|
|
9819
|
+
eyepopUrl() {
|
|
9820
|
+
if (this._options.eyepopUrl) {
|
|
9821
|
+
return this._options.eyepopUrl.replace(/\/+$/, "");
|
|
9822
|
+
} else {
|
|
9823
|
+
return "https://api.eyepop.ai";
|
|
9824
|
+
}
|
|
9825
|
+
}
|
|
9826
|
+
pendingJobs() {
|
|
9827
|
+
return (this._options.jobQueueLength ?? 1024) - this._limit.getPermits();
|
|
9828
|
+
}
|
|
9829
|
+
state() {
|
|
9830
|
+
return this._state;
|
|
9831
|
+
}
|
|
9832
|
+
onStateChanged(handler) {
|
|
9833
|
+
this._stateChangeHandler = handler;
|
|
9834
|
+
return this;
|
|
9835
|
+
}
|
|
9836
|
+
updateState(newState = void 0) {
|
|
9837
|
+
const fromState = this._state;
|
|
9838
|
+
if (newState == void 0) {
|
|
9839
|
+
if (this._limit.getPermits() == this._options.jobQueueLength) {
|
|
9840
|
+
newState = "Idle" /* Idle */;
|
|
9841
|
+
} else {
|
|
9842
|
+
newState = "Busy" /* Busy */;
|
|
9843
|
+
}
|
|
9844
|
+
}
|
|
9845
|
+
this._state = newState;
|
|
9846
|
+
if (this._stateChangeHandler) {
|
|
9847
|
+
this._stateChangeHandler(fromState, this._state);
|
|
9848
|
+
}
|
|
9849
|
+
}
|
|
9850
|
+
async connect() {
|
|
9851
|
+
if (this._client) {
|
|
9852
|
+
this._logger.warn("endpoint already connected");
|
|
9853
|
+
return this;
|
|
9854
|
+
}
|
|
9855
|
+
if (!this._options.eyepopUrl) {
|
|
9856
|
+
return Promise.reject("option eyepopUrl or environment variable EYEPOP_URL is required");
|
|
9857
|
+
}
|
|
9858
|
+
if (this._options.auth === void 0) {
|
|
9859
|
+
return Promise.reject("cannot connect without defined auth option");
|
|
9860
|
+
}
|
|
9861
|
+
if (this._options.auth.session !== void 0) {
|
|
9862
|
+
this._token = this._options.auth.session.accessToken;
|
|
9863
|
+
this._expire_token_time = this._options.auth.session.validUntil / 1e3;
|
|
9864
|
+
} else if (this._options.auth.oAuth2 !== void 0) {
|
|
9865
|
+
} else if (this._options.auth.secretKey !== void 0) {
|
|
9866
|
+
} else {
|
|
9867
|
+
return Promise.reject("option secretKey or environment variable EYEPOP_SECRET_KEY is required");
|
|
9868
|
+
}
|
|
9869
|
+
this._client = await createHttpClient();
|
|
9870
|
+
return await this.reconnect();
|
|
9871
|
+
}
|
|
9872
|
+
async disconnect(wait = true) {
|
|
9873
|
+
if (wait && this._limit) {
|
|
9874
|
+
for (let j = 0; j < this._options.jobQueueLength; j++) {
|
|
9875
|
+
await this._limit.acquire();
|
|
9876
|
+
}
|
|
9877
|
+
}
|
|
9878
|
+
this._limit = new Semaphore(this._options.jobQueueLength ?? 1024);
|
|
9879
|
+
if (this._client) {
|
|
9880
|
+
await this._client.close();
|
|
9881
|
+
this._client = null;
|
|
9882
|
+
}
|
|
9883
|
+
}
|
|
9884
|
+
async session() {
|
|
9885
|
+
await this.currentAccessToken();
|
|
9886
|
+
if (this._token == null || this._expire_token_time == null) {
|
|
9887
|
+
return Promise.reject("endpoint not connected");
|
|
9888
|
+
}
|
|
9889
|
+
return {
|
|
9890
|
+
eyepopUrl: this._options.eyepopUrl,
|
|
9891
|
+
accessToken: this._token,
|
|
9892
|
+
validUntil: this._expire_token_time * 1e3
|
|
9893
|
+
};
|
|
9894
|
+
}
|
|
9895
|
+
statusHandler401(statusCode) {
|
|
9896
|
+
this._token = null;
|
|
9897
|
+
this._expire_token_time = null;
|
|
9898
|
+
}
|
|
9899
|
+
async fetchWithRetry(fetcher, retries = 1) {
|
|
9900
|
+
while (true) {
|
|
9901
|
+
try {
|
|
9902
|
+
const response = await fetcher();
|
|
9903
|
+
if (response.status <= 300) {
|
|
9904
|
+
return response;
|
|
9905
|
+
} else {
|
|
9906
|
+
const handler = this._statusRetryHandlers.get(response.status);
|
|
9907
|
+
if (handler != null) {
|
|
9908
|
+
handler(response.status);
|
|
9909
|
+
if (retries--) {
|
|
9910
|
+
this._requestLogger.info("received %d response, retry", response.status);
|
|
9911
|
+
} else {
|
|
9912
|
+
return Promise.reject(`response ${response.status}: ${response.statusText}`);
|
|
9913
|
+
}
|
|
9914
|
+
} else {
|
|
9915
|
+
return Promise.reject(`response ${response.status}: ${response.statusText}`);
|
|
9916
|
+
}
|
|
9917
|
+
}
|
|
9918
|
+
} catch (error) {
|
|
9919
|
+
const handler = this._statusRetryHandlers.get(404);
|
|
9920
|
+
if (handler != null) {
|
|
9921
|
+
handler(error);
|
|
9922
|
+
if (retries--) {
|
|
9923
|
+
this._requestLogger.info("error %s, retry", error);
|
|
9924
|
+
} else {
|
|
9925
|
+
return Promise.reject(`error ${error}`);
|
|
9926
|
+
}
|
|
9927
|
+
} else {
|
|
9928
|
+
return Promise.reject(`error ${error}`);
|
|
9929
|
+
}
|
|
9930
|
+
}
|
|
9931
|
+
}
|
|
9932
|
+
}
|
|
9933
|
+
async reconnect() {
|
|
9934
|
+
throw new Error("reconnect() not implemented");
|
|
9935
|
+
}
|
|
9936
|
+
async authorizationHeader() {
|
|
9937
|
+
return `Bearer ${await this.currentAccessToken()}`;
|
|
9938
|
+
}
|
|
9939
|
+
async currentAccessToken() {
|
|
9940
|
+
const now = Date.now() / 1e3;
|
|
9941
|
+
if (!this._token || this._expire_token_time < now) {
|
|
9942
|
+
this.updateState("Authenticating" /* Authenticating */);
|
|
9943
|
+
try {
|
|
9944
|
+
if (!this._client) {
|
|
9945
|
+
return Promise.reject("endpoint not connected");
|
|
9946
|
+
} else if (this._options.auth.session !== void 0) {
|
|
9947
|
+
return Promise.reject("temporary access token expired");
|
|
9948
|
+
} else if (this._options.auth.oAuth2 !== void 0 && this._options.eyepopUrl) {
|
|
9949
|
+
const session = await authenticateBrowserSession(this._options.auth.oAuth2, this._options);
|
|
9950
|
+
this._token = session.accessToken;
|
|
9951
|
+
this._expire_token_time = session.validUntil / 1e3;
|
|
9952
|
+
} else if (this._options.auth.secretKey !== void 0 && this._options.eyepopUrl) {
|
|
9953
|
+
const secretKeyAuth = this._options.auth;
|
|
9954
|
+
const body = { "secret_key": secretKeyAuth.secretKey };
|
|
9955
|
+
const headers = { "Content-Type": "application/json" };
|
|
9956
|
+
const post_url = `${this.eyepopUrl()}/authentication/token`;
|
|
9957
|
+
this._requestLogger.debug("before POST %s", post_url);
|
|
9958
|
+
const response = await this._client.fetch(post_url, {
|
|
9959
|
+
method: "POST",
|
|
9960
|
+
headers,
|
|
9961
|
+
body: JSON.stringify(body)
|
|
9962
|
+
});
|
|
9963
|
+
if (response.status != 200) {
|
|
9964
|
+
const message = await response.text();
|
|
9965
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
9966
|
+
}
|
|
9967
|
+
this._requestLogger.debug("after POST %s", post_url);
|
|
9968
|
+
const data = await response.json();
|
|
9969
|
+
const token = data;
|
|
9970
|
+
this._token = token.access_token;
|
|
9971
|
+
this._expire_token_time = now + token.expires_in - 60;
|
|
9972
|
+
} else {
|
|
9973
|
+
return Promise.reject("no valid auth option");
|
|
9974
|
+
}
|
|
9975
|
+
} finally {
|
|
9976
|
+
this.updateState();
|
|
9977
|
+
}
|
|
9978
|
+
}
|
|
9979
|
+
this._logger.debug("using access token, valid for at least %d seconds", this._expire_token_time - now);
|
|
9980
|
+
return this._token;
|
|
9981
|
+
}
|
|
9982
|
+
};
|
|
9983
|
+
|
|
9984
|
+
// worker/worker_options.ts
|
|
9985
|
+
var TransientPopId = /* @__PURE__ */ ((TransientPopId2) => {
|
|
9986
|
+
TransientPopId2["Transient"] = "transient";
|
|
9987
|
+
return TransientPopId2;
|
|
9988
|
+
})(TransientPopId || {});
|
|
9989
|
+
|
|
9990
|
+
// worker/worker_endpoint.ts
|
|
9991
|
+
var WorkerEndpoint = class extends Endpoint {
|
|
9992
|
+
constructor(options) {
|
|
9993
|
+
super(options);
|
|
9994
|
+
this.setStatusRetryHandlers(/* @__PURE__ */ new Map([[404, (statusCode) => this.statusHandler404(statusCode)]]));
|
|
9995
|
+
this._baseUrl = null;
|
|
9996
|
+
this._pipelineId = null;
|
|
9997
|
+
this._popName = null;
|
|
9998
|
+
this._pipeline = null;
|
|
9999
|
+
this._ingressEventHandler = null;
|
|
10000
|
+
this._ingressEventWs = null;
|
|
10001
|
+
this._sandboxId = null;
|
|
10002
|
+
const sessionAuth = options.auth;
|
|
10003
|
+
if (sessionAuth.session !== void 0) {
|
|
10004
|
+
const workerSession = sessionAuth.session;
|
|
10005
|
+
if (workerSession.sandboxId) {
|
|
10006
|
+
this._sandboxId = workerSession.sandboxId;
|
|
10007
|
+
this.options().isSandbox = true;
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
10010
|
+
}
|
|
10011
|
+
options() {
|
|
10012
|
+
return this._options;
|
|
10013
|
+
}
|
|
10014
|
+
async disconnect(wait = true) {
|
|
10015
|
+
if (this._sandboxId && this._baseUrl) {
|
|
10016
|
+
const sandboxUrl = `${this._baseUrl}/sandboxes/${this._sandboxId}`;
|
|
10017
|
+
const headers = {
|
|
10018
|
+
"Authorization": await this.authorizationHeader()
|
|
10019
|
+
};
|
|
10020
|
+
this._requestLogger.debug("before DELETE %s", sandboxUrl);
|
|
10021
|
+
let response = await this._client?.fetch(sandboxUrl, {
|
|
10022
|
+
method: "DELETE",
|
|
10023
|
+
headers
|
|
10024
|
+
});
|
|
10025
|
+
this._requestLogger.debug("after DELETE %s", sandboxUrl);
|
|
10026
|
+
if (response?.status != 204) {
|
|
10027
|
+
const message = await response?.text();
|
|
10028
|
+
return Promise.reject(`disconnecting sandbox failed, status ${response?.status}: ${message}`);
|
|
10029
|
+
}
|
|
10030
|
+
this._sandboxId = null;
|
|
10031
|
+
}
|
|
10032
|
+
return super.disconnect(wait);
|
|
10033
|
+
}
|
|
10034
|
+
statusHandler404(statusCode) {
|
|
10035
|
+
this._pipelineId = null;
|
|
10036
|
+
this._baseUrl = null;
|
|
10037
|
+
}
|
|
10038
|
+
async session() {
|
|
10039
|
+
const session = await super.session();
|
|
10040
|
+
if (this._baseUrl == null || this._pipelineId == null) {
|
|
10041
|
+
await this.reconnect();
|
|
10042
|
+
if (this._baseUrl == null || this._pipelineId == null) {
|
|
10043
|
+
return Promise.reject("endpoint not connected");
|
|
10044
|
+
}
|
|
10045
|
+
}
|
|
10046
|
+
return {
|
|
10047
|
+
eyepopUrl: session.eyepopUrl,
|
|
10048
|
+
accessToken: session.accessToken,
|
|
10049
|
+
validUntil: session.validUntil,
|
|
10050
|
+
popId: this.options().popId,
|
|
10051
|
+
baseUrl: this._baseUrl,
|
|
10052
|
+
pipelineId: this._pipelineId,
|
|
10053
|
+
sandboxId: this._sandboxId ?? void 0
|
|
10054
|
+
};
|
|
9814
10055
|
}
|
|
9815
10056
|
popName() {
|
|
9816
10057
|
return this._popName;
|
|
@@ -9891,105 +10132,15 @@ var Endpoint = class {
|
|
|
9891
10132
|
}
|
|
9892
10133
|
}
|
|
9893
10134
|
popId() {
|
|
9894
|
-
return this.
|
|
9895
|
-
}
|
|
9896
|
-
onStateChanged(handler) {
|
|
9897
|
-
this._stateChangeHandler = handler;
|
|
9898
|
-
return this;
|
|
10135
|
+
return this.options().popId || null;
|
|
9899
10136
|
}
|
|
9900
10137
|
onIngressEvent(handler) {
|
|
9901
10138
|
this._ingressEventHandler = handler;
|
|
9902
10139
|
this.startIngressWs().then(() => {
|
|
9903
|
-
}).catch((reason) => {
|
|
9904
|
-
this._logger.warn("unexpected error starting the ingress event handler: %s", reason);
|
|
9905
|
-
});
|
|
9906
|
-
return this;
|
|
9907
|
-
}
|
|
9908
|
-
async connect() {
|
|
9909
|
-
if (this._client) {
|
|
9910
|
-
this._logger.warn("endpoint already connected");
|
|
9911
|
-
return this;
|
|
9912
|
-
}
|
|
9913
|
-
if (!this._options.eyepopUrl) {
|
|
9914
|
-
return Promise.reject("option eyepopUrl or environment variable EYEPOP_URL is required");
|
|
9915
|
-
}
|
|
9916
|
-
if (!this._options.popId) {
|
|
9917
|
-
return Promise.reject("option popId or environment variable EYEPOP_POP_ID is required");
|
|
9918
|
-
}
|
|
9919
|
-
if (this._options.auth === void 0) {
|
|
9920
|
-
return Promise.reject("cannot connect without defined auth option");
|
|
9921
|
-
}
|
|
9922
|
-
if (this._options.auth.session !== void 0) {
|
|
9923
|
-
this._token = this._options.auth.session.accessToken;
|
|
9924
|
-
this._expire_token_time = this._options.auth.session.validUntil / 1e3;
|
|
9925
|
-
} else if (this._options.auth.oAuth2 !== void 0) {
|
|
9926
|
-
} else if (this._options.auth.secretKey !== void 0) {
|
|
9927
|
-
} else {
|
|
9928
|
-
return Promise.reject("option secretKey or environment variable EYEPOP_SECRET_KEY is required");
|
|
9929
|
-
}
|
|
9930
|
-
this._client = await createHttpClient();
|
|
9931
|
-
const client = this._client;
|
|
9932
|
-
let result = await this.reconnect();
|
|
9933
|
-
if (this._baseUrl && this._options.stopJobs) {
|
|
9934
|
-
const body = { "sourceType": "NONE" };
|
|
9935
|
-
let response = await this.fetchWithRetry(async () => {
|
|
9936
|
-
const session = await this.session();
|
|
9937
|
-
const headers = {
|
|
9938
|
-
"Authorization": `Bearer ${session.accessToken}`,
|
|
9939
|
-
"Content-Type": "application/json"
|
|
9940
|
-
};
|
|
9941
|
-
const stop_url = `${session.baseUrl}/pipelines/${session.pipelineId}/source?mode=preempt&processing=sync`;
|
|
9942
|
-
return client.fetch(stop_url, {
|
|
9943
|
-
method: "PATCH",
|
|
9944
|
-
headers,
|
|
9945
|
-
body: JSON.stringify(body)
|
|
9946
|
-
});
|
|
9947
|
-
});
|
|
9948
|
-
if (response.status >= 300) {
|
|
9949
|
-
const message = await response.text();
|
|
9950
|
-
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
9951
|
-
}
|
|
9952
|
-
}
|
|
9953
|
-
if (!this._ingressEventWs && this._ingressEventHandler) {
|
|
9954
|
-
await this.startIngressWs();
|
|
9955
|
-
}
|
|
9956
|
-
return result;
|
|
9957
|
-
}
|
|
9958
|
-
async disconnect(wait = true) {
|
|
9959
|
-
if (wait && this._limit) {
|
|
9960
|
-
for (let j = 0; j < this._options.jobQueueLength; j++) {
|
|
9961
|
-
await this._limit.acquire();
|
|
9962
|
-
}
|
|
9963
|
-
}
|
|
9964
|
-
this._limit = new Semaphore(this._options.jobQueueLength ?? 1024);
|
|
9965
|
-
if (this._client) {
|
|
9966
|
-
await this._client.close();
|
|
9967
|
-
this._client = null;
|
|
9968
|
-
}
|
|
9969
|
-
this._baseUrl = null;
|
|
9970
|
-
this._pipelineId = null;
|
|
9971
|
-
this._sandboxId = null;
|
|
9972
|
-
}
|
|
9973
|
-
async session() {
|
|
9974
|
-
await this.currentAccessToken();
|
|
9975
|
-
if (this._token == null || this._expire_token_time == null) {
|
|
9976
|
-
return Promise.reject("endpoint not connected");
|
|
9977
|
-
}
|
|
9978
|
-
if (this._baseUrl == null || this._pipelineId == null) {
|
|
9979
|
-
await this.reconnect();
|
|
9980
|
-
if (this._baseUrl == null || this._pipelineId == null) {
|
|
9981
|
-
return Promise.reject("endpoint not connected");
|
|
9982
|
-
}
|
|
9983
|
-
}
|
|
9984
|
-
return {
|
|
9985
|
-
eyepopUrl: this._options.eyepopUrl,
|
|
9986
|
-
popId: this._options.popId,
|
|
9987
|
-
accessToken: this._token,
|
|
9988
|
-
validUntil: this._expire_token_time * 1e3,
|
|
9989
|
-
baseUrl: this._baseUrl,
|
|
9990
|
-
pipelineId: this._pipelineId,
|
|
9991
|
-
sandboxId: this._sandboxId ?? void 0
|
|
9992
|
-
};
|
|
10140
|
+
}).catch((reason) => {
|
|
10141
|
+
this._logger.warn("unexpected error starting the ingress event handler: %s", reason);
|
|
10142
|
+
});
|
|
10143
|
+
return this;
|
|
9993
10144
|
}
|
|
9994
10145
|
async liveIngress(stream) {
|
|
9995
10146
|
if (!this._baseUrl || !this._client) {
|
|
@@ -10024,209 +10175,662 @@ var Endpoint = class {
|
|
|
10024
10175
|
return Promise.reject("unknown source type");
|
|
10025
10176
|
}
|
|
10026
10177
|
}
|
|
10027
|
-
async startIngressWs() {
|
|
10178
|
+
async startIngressWs() {
|
|
10179
|
+
const client = this._client;
|
|
10180
|
+
if (this._ingressEventWs || !this._baseUrl || !client) {
|
|
10181
|
+
return;
|
|
10182
|
+
}
|
|
10183
|
+
try {
|
|
10184
|
+
const session = await this.session();
|
|
10185
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10186
|
+
const headers = {
|
|
10187
|
+
"Authorization": `Bearer ${session.accessToken}`
|
|
10188
|
+
};
|
|
10189
|
+
const getTokenUrl = `${session.baseUrl}/liveIngress/events/token`;
|
|
10190
|
+
return client.fetch(getTokenUrl, { headers });
|
|
10191
|
+
});
|
|
10192
|
+
if (response.status != 200) {
|
|
10193
|
+
const message = await response.text();
|
|
10194
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10195
|
+
}
|
|
10196
|
+
const wsAuthToken = await response.json();
|
|
10197
|
+
const wsUrl = this._baseUrl.startsWith("https://") ? `${this._baseUrl.replace("https://", "wss://")}/liveIngress/events/${wsAuthToken.token}` : `${this._baseUrl.replace("http://", "ws://")}/liveIngress/events/${wsAuthToken.token}`;
|
|
10198
|
+
this._ingressEventWs = new WebSocket(wsUrl);
|
|
10199
|
+
this._ingressEventWs.addEventListener("message", (event) => {
|
|
10200
|
+
const ingressEvent = JSON.parse(event.data);
|
|
10201
|
+
if (this._ingressEventHandler) {
|
|
10202
|
+
this._ingressEventHandler(ingressEvent);
|
|
10203
|
+
}
|
|
10204
|
+
});
|
|
10205
|
+
} finally {
|
|
10206
|
+
this.updateState();
|
|
10207
|
+
}
|
|
10208
|
+
}
|
|
10209
|
+
async uploadFile(source, params) {
|
|
10210
|
+
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10211
|
+
return Promise.reject("endpoint not connected, use connect() before upload()");
|
|
10212
|
+
}
|
|
10213
|
+
await this._limit.acquire();
|
|
10214
|
+
try {
|
|
10215
|
+
this.updateState();
|
|
10216
|
+
const job = new UploadJob(source.file, source.file.type, params, async () => {
|
|
10217
|
+
return this.session();
|
|
10218
|
+
}, this._client, this._requestLogger);
|
|
10219
|
+
return job.start(() => {
|
|
10220
|
+
this.jobDone(job);
|
|
10221
|
+
}, (statusCode) => {
|
|
10222
|
+
this.jobStatus(job, statusCode);
|
|
10223
|
+
});
|
|
10224
|
+
} catch (e) {
|
|
10225
|
+
this._limit.release();
|
|
10226
|
+
throw e;
|
|
10227
|
+
}
|
|
10228
|
+
}
|
|
10229
|
+
async uploadStream(source, params) {
|
|
10230
|
+
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10231
|
+
return Promise.reject("endpoint not connected, use connect() before upload()");
|
|
10232
|
+
}
|
|
10233
|
+
await this._limit.acquire();
|
|
10234
|
+
try {
|
|
10235
|
+
this.updateState();
|
|
10236
|
+
const job = new UploadJob(source.stream, source.mimeType, params, async () => {
|
|
10237
|
+
return this.session();
|
|
10238
|
+
}, this._client, this._requestLogger);
|
|
10239
|
+
return job.start(() => {
|
|
10240
|
+
this.jobDone(job);
|
|
10241
|
+
}, (statusCode) => {
|
|
10242
|
+
this.jobStatus(job, statusCode);
|
|
10243
|
+
});
|
|
10244
|
+
} catch (e) {
|
|
10245
|
+
this._limit.release();
|
|
10246
|
+
throw e;
|
|
10247
|
+
}
|
|
10248
|
+
}
|
|
10249
|
+
async uploadPath(source, params) {
|
|
10250
|
+
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10251
|
+
throw new Error("endpoint not connected, use connect() before process()");
|
|
10252
|
+
}
|
|
10253
|
+
await this._limit.acquire();
|
|
10254
|
+
try {
|
|
10255
|
+
this.updateState();
|
|
10256
|
+
const streamSource = await resolvePath(source);
|
|
10257
|
+
const job = new UploadJob(streamSource.stream, streamSource.mimeType, params, async () => {
|
|
10258
|
+
return this.session();
|
|
10259
|
+
}, this._client, this._requestLogger);
|
|
10260
|
+
return job.start(() => {
|
|
10261
|
+
this.jobDone(job);
|
|
10262
|
+
}, (statusCode) => {
|
|
10263
|
+
this.jobStatus(job, statusCode);
|
|
10264
|
+
});
|
|
10265
|
+
} catch (e) {
|
|
10266
|
+
this._limit.release();
|
|
10267
|
+
throw e;
|
|
10268
|
+
}
|
|
10269
|
+
}
|
|
10270
|
+
async loadFrom(source, params) {
|
|
10271
|
+
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10272
|
+
throw new Error("endpoint not connected, use connect() before loadFrom()");
|
|
10273
|
+
}
|
|
10274
|
+
await this._limit.acquire();
|
|
10275
|
+
try {
|
|
10276
|
+
this.updateState();
|
|
10277
|
+
const job = new LoadFromJob(source.url, params, async () => {
|
|
10278
|
+
return this.session();
|
|
10279
|
+
}, this._client, this._requestLogger);
|
|
10280
|
+
return job.start(() => {
|
|
10281
|
+
this.jobDone(job);
|
|
10282
|
+
}, (statusCode) => {
|
|
10283
|
+
this.jobStatus(job, statusCode);
|
|
10284
|
+
});
|
|
10285
|
+
} catch (e) {
|
|
10286
|
+
this._limit.release();
|
|
10287
|
+
throw e;
|
|
10288
|
+
}
|
|
10289
|
+
}
|
|
10290
|
+
async loadLiveIngress(source, params) {
|
|
10291
|
+
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10292
|
+
throw new Error("endpoint not connected, use connect() before loadLiveIngress()");
|
|
10293
|
+
}
|
|
10294
|
+
await this._limit.acquire();
|
|
10295
|
+
try {
|
|
10296
|
+
this.updateState();
|
|
10297
|
+
const job = new LoadLiveIngressJob(source.ingressId, params, async () => {
|
|
10298
|
+
return this.session();
|
|
10299
|
+
}, this._client, this._requestLogger);
|
|
10300
|
+
return job.start(() => {
|
|
10301
|
+
this.jobDone(job);
|
|
10302
|
+
}, (statusCode) => {
|
|
10303
|
+
this.jobStatus(job, statusCode);
|
|
10304
|
+
});
|
|
10305
|
+
} catch (e) {
|
|
10306
|
+
this._limit.release();
|
|
10307
|
+
throw e;
|
|
10308
|
+
}
|
|
10309
|
+
}
|
|
10310
|
+
jobDone(job) {
|
|
10311
|
+
this._limit?.release();
|
|
10312
|
+
this.updateState();
|
|
10313
|
+
}
|
|
10314
|
+
jobStatus(job, statusCode) {
|
|
10315
|
+
if (statusCode == 404) {
|
|
10316
|
+
this.statusHandler404(statusCode);
|
|
10317
|
+
} else if (statusCode == 401) {
|
|
10318
|
+
this.statusHandler401(statusCode);
|
|
10319
|
+
}
|
|
10320
|
+
}
|
|
10321
|
+
async reconnect() {
|
|
10322
|
+
if (!this._client) {
|
|
10323
|
+
return Promise.reject("endpoint not initialized");
|
|
10324
|
+
}
|
|
10325
|
+
let config_url;
|
|
10326
|
+
if (this.options().popId == "transient" /* Transient */) {
|
|
10327
|
+
config_url = `${this.eyepopUrl()}/workers/config`;
|
|
10328
|
+
} else {
|
|
10329
|
+
config_url = `${this.eyepopUrl()}/pops/${this.options().popId}/config?auto_start=false`;
|
|
10330
|
+
}
|
|
10331
|
+
const headers = {
|
|
10332
|
+
"Authorization": await this.authorizationHeader()
|
|
10333
|
+
};
|
|
10334
|
+
this.updateState("FetchConfig" /* FetchConfig */);
|
|
10335
|
+
this._requestLogger.debug("before GET %s", config_url);
|
|
10336
|
+
let response = await this._client.fetch(config_url, { headers });
|
|
10337
|
+
if (response.status == 401) {
|
|
10338
|
+
this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", config_url);
|
|
10339
|
+
this.statusHandler401(response.status);
|
|
10340
|
+
const headers2 = {
|
|
10341
|
+
"Authorization": await this.authorizationHeader()
|
|
10342
|
+
};
|
|
10343
|
+
this.updateState("FetchConfig" /* FetchConfig */);
|
|
10344
|
+
response = await this._client.fetch(config_url, {
|
|
10345
|
+
headers: headers2
|
|
10346
|
+
});
|
|
10347
|
+
}
|
|
10348
|
+
if (response.status != 200) {
|
|
10349
|
+
this.updateState("Error" /* Error */);
|
|
10350
|
+
const message = await response.text();
|
|
10351
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10352
|
+
}
|
|
10353
|
+
let config = await response.json();
|
|
10354
|
+
this._requestLogger.debug("after GET %s", config_url);
|
|
10355
|
+
if (!config.base_url && this.options().autoStart) {
|
|
10356
|
+
const auto_start_config_url = `${this.eyepopUrl()}/pops/${this.options().popId}/config?auto_start=true`;
|
|
10357
|
+
this._requestLogger.debug("pop was not running, trying to autostart with: %s", auto_start_config_url);
|
|
10358
|
+
const headers2 = {
|
|
10359
|
+
"Authorization": await this.authorizationHeader()
|
|
10360
|
+
};
|
|
10361
|
+
response = await this._client.fetch(auto_start_config_url, {
|
|
10362
|
+
headers: headers2
|
|
10363
|
+
});
|
|
10364
|
+
if (response.status != 200) {
|
|
10365
|
+
this.updateState("Error" /* Error */);
|
|
10366
|
+
const message = await response.text();
|
|
10367
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10368
|
+
}
|
|
10369
|
+
config = await response.json();
|
|
10370
|
+
}
|
|
10371
|
+
const baseUrl = new URL(config.base_url, this.eyepopUrl());
|
|
10372
|
+
this._baseUrl = baseUrl.toString();
|
|
10373
|
+
if (this._baseUrl) {
|
|
10374
|
+
this._baseUrl = this._baseUrl.replace(/\/+$/, "");
|
|
10375
|
+
if (this.options().isSandbox && this._sandboxId === null) {
|
|
10376
|
+
const headers3 = {
|
|
10377
|
+
"Authorization": await this.authorizationHeader()
|
|
10378
|
+
};
|
|
10379
|
+
const createSandboxUrl = `${this._baseUrl}/sandboxes`;
|
|
10380
|
+
this._requestLogger.debug("before POST %s", createSandboxUrl);
|
|
10381
|
+
const response3 = await this._client.fetch(createSandboxUrl, {
|
|
10382
|
+
method: "POST",
|
|
10383
|
+
headers: headers3
|
|
10384
|
+
});
|
|
10385
|
+
if (!response3.ok) {
|
|
10386
|
+
const message = await response3.text();
|
|
10387
|
+
return Promise.reject(`Unexpected status ${response3.status}: ${message}`);
|
|
10388
|
+
}
|
|
10389
|
+
const responseJson = await response3.json();
|
|
10390
|
+
this._requestLogger.debug("after POST %s", createSandboxUrl);
|
|
10391
|
+
if (responseJson) {
|
|
10392
|
+
this._sandboxId = responseJson;
|
|
10393
|
+
}
|
|
10394
|
+
}
|
|
10395
|
+
if (this.options().popId == "transient" /* Transient */) {
|
|
10396
|
+
this._pipelineId = await this.startPopLessPipeline();
|
|
10397
|
+
this._popName = this.options().popId || null;
|
|
10398
|
+
} else {
|
|
10399
|
+
this._pipelineId = config.pipeline_id;
|
|
10400
|
+
this._popName = config.name;
|
|
10401
|
+
}
|
|
10402
|
+
if (!this._pipelineId || !this._baseUrl) {
|
|
10403
|
+
return Promise.reject(`Pop not started`);
|
|
10404
|
+
}
|
|
10405
|
+
this._baseUrl = this._baseUrl.replace(/\/+$/, "");
|
|
10406
|
+
const get_url = `${this._baseUrl}/pipelines/${this._pipelineId}`;
|
|
10407
|
+
const headers2 = {
|
|
10408
|
+
"Authorization": await this.authorizationHeader()
|
|
10409
|
+
};
|
|
10410
|
+
this._requestLogger.debug("before GET %s", get_url);
|
|
10411
|
+
let response2 = await this._client.fetch(get_url, {
|
|
10412
|
+
method: "GET",
|
|
10413
|
+
headers: headers2
|
|
10414
|
+
});
|
|
10415
|
+
if (response2.status > 200) {
|
|
10416
|
+
const message = await response2.text();
|
|
10417
|
+
return Promise.reject(`Unexpected status ${response2.status}: ${message}`);
|
|
10418
|
+
}
|
|
10419
|
+
this._requestLogger.debug("after GET %s", get_url);
|
|
10420
|
+
this._pipeline = await response2.json();
|
|
10421
|
+
if (this.options().stopJobs) {
|
|
10422
|
+
const body = { "sourceType": "NONE" };
|
|
10423
|
+
const headers3 = {
|
|
10424
|
+
"Authorization": await this.authorizationHeader()
|
|
10425
|
+
};
|
|
10426
|
+
const stop_url = `${this._baseUrl}/pipelines/${this._pipeline.id}/source?mode=preempt&processing=sync`;
|
|
10427
|
+
let response3 = await this._client.fetch(stop_url, {
|
|
10428
|
+
method: "PATCH",
|
|
10429
|
+
headers: headers3,
|
|
10430
|
+
body: JSON.stringify(body)
|
|
10431
|
+
});
|
|
10432
|
+
if (response3.status >= 300) {
|
|
10433
|
+
const message = await response3.text();
|
|
10434
|
+
return Promise.reject(`Unexpected status ${response3.status}: ${message}`);
|
|
10435
|
+
}
|
|
10436
|
+
}
|
|
10437
|
+
}
|
|
10438
|
+
if (!this._ingressEventWs && this._ingressEventHandler) {
|
|
10439
|
+
await this.startIngressWs();
|
|
10440
|
+
}
|
|
10441
|
+
this.updateState();
|
|
10442
|
+
return Promise.resolve(this);
|
|
10443
|
+
}
|
|
10444
|
+
async startPopLessPipeline() {
|
|
10445
|
+
const client = this._client;
|
|
10446
|
+
const baseUrl = this._baseUrl;
|
|
10447
|
+
const sandboxId = this._sandboxId;
|
|
10448
|
+
if (client == null || baseUrl == null) {
|
|
10449
|
+
return Promise.reject("endpoint not initialized");
|
|
10450
|
+
}
|
|
10451
|
+
let pipeline;
|
|
10452
|
+
if (this._pipeline) {
|
|
10453
|
+
pipeline = this._pipeline.inferPipeline;
|
|
10454
|
+
} else {
|
|
10455
|
+
pipeline = "identity";
|
|
10456
|
+
}
|
|
10457
|
+
let postTransform;
|
|
10458
|
+
if (this._pipeline && this._pipeline.postTransform) {
|
|
10459
|
+
postTransform = this._pipeline.postTransform;
|
|
10460
|
+
} else {
|
|
10461
|
+
postTransform = null;
|
|
10462
|
+
}
|
|
10463
|
+
const body = {
|
|
10464
|
+
"inferPipelineDef": {
|
|
10465
|
+
"pipeline": pipeline
|
|
10466
|
+
},
|
|
10467
|
+
"postTransformDef": {
|
|
10468
|
+
"transform": postTransform
|
|
10469
|
+
},
|
|
10470
|
+
"source": {
|
|
10471
|
+
"sourceType": "NONE"
|
|
10472
|
+
},
|
|
10473
|
+
"idleTimeoutSeconds": 30,
|
|
10474
|
+
"logging": ["out_meta"],
|
|
10475
|
+
"videoOutput": "no_output"
|
|
10476
|
+
};
|
|
10477
|
+
let post_url;
|
|
10478
|
+
if (sandboxId) {
|
|
10479
|
+
post_url = `${baseUrl.replace(/\/+$/, "")}/pipelines?sandboxId=${sandboxId}`;
|
|
10480
|
+
} else {
|
|
10481
|
+
post_url = `${baseUrl.replace(/\/+$/, "")}/pipelines`;
|
|
10482
|
+
}
|
|
10483
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10484
|
+
let headers = {
|
|
10485
|
+
"Content-Type": "application/json",
|
|
10486
|
+
"Authorization": await this.authorizationHeader()
|
|
10487
|
+
};
|
|
10488
|
+
this._requestLogger.debug("before POST %s", post_url);
|
|
10489
|
+
return client.fetch(post_url, {
|
|
10490
|
+
method: "POST",
|
|
10491
|
+
body: JSON.stringify(body),
|
|
10492
|
+
headers
|
|
10493
|
+
});
|
|
10494
|
+
});
|
|
10495
|
+
if (response.status != 200) {
|
|
10496
|
+
const message = await response.text();
|
|
10497
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10498
|
+
}
|
|
10499
|
+
const result = await response.json();
|
|
10500
|
+
this._requestLogger.debug("after POST %s", post_url);
|
|
10501
|
+
return result["id"];
|
|
10502
|
+
}
|
|
10503
|
+
async manifest() {
|
|
10504
|
+
this._logger.warn("getManifest for development use only");
|
|
10028
10505
|
const client = this._client;
|
|
10029
|
-
|
|
10030
|
-
|
|
10506
|
+
const baseUrl = this._baseUrl;
|
|
10507
|
+
if (!baseUrl || !client) {
|
|
10508
|
+
return Promise.reject("endpoint not connected, use connect() before getManifest()");
|
|
10031
10509
|
}
|
|
10032
|
-
|
|
10510
|
+
let get_path;
|
|
10511
|
+
if (this._sandboxId === null) {
|
|
10512
|
+
get_path = `${baseUrl}/models/sources`;
|
|
10513
|
+
} else {
|
|
10514
|
+
get_path = `${baseUrl}/models/sources?sandboxId=${this._sandboxId}`;
|
|
10515
|
+
}
|
|
10516
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10033
10517
|
const session = await this.session();
|
|
10034
|
-
let
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
}
|
|
10045
|
-
const wsAuthToken = await response.json();
|
|
10046
|
-
const wsUrl = this._baseUrl.startsWith("https://") ? `${this._baseUrl.replace("https://", "wss://")}/liveIngress/events/${wsAuthToken.token}` : `${this._baseUrl.replace("http://", "ws://")}/liveIngress/events/${wsAuthToken.token}`;
|
|
10047
|
-
this._ingressEventWs = new WebSocket(wsUrl);
|
|
10048
|
-
this._ingressEventWs.addEventListener("message", (event) => {
|
|
10049
|
-
const ingressEvent = JSON.parse(event.data);
|
|
10050
|
-
if (this._ingressEventHandler) {
|
|
10051
|
-
this._ingressEventHandler(ingressEvent);
|
|
10052
|
-
}
|
|
10053
|
-
});
|
|
10054
|
-
} finally {
|
|
10055
|
-
this.updateState();
|
|
10518
|
+
let headers = {
|
|
10519
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
10520
|
+
"Content-Type": "application/json"
|
|
10521
|
+
};
|
|
10522
|
+
this._requestLogger.debug("before GET %s", get_path);
|
|
10523
|
+
return client.fetch(get_path, { headers });
|
|
10524
|
+
});
|
|
10525
|
+
if (!response.ok) {
|
|
10526
|
+
const message = await response.text();
|
|
10527
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10056
10528
|
}
|
|
10529
|
+
const result = await response.json();
|
|
10530
|
+
this._requestLogger.debug("after GET %s", get_path);
|
|
10531
|
+
return result;
|
|
10057
10532
|
}
|
|
10058
|
-
async
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
this.updateState();
|
|
10065
|
-
const job = new UploadJob(source.file, source.file.type, params, async () => {
|
|
10066
|
-
return this.session();
|
|
10067
|
-
}, this._client, this._requestLogger);
|
|
10068
|
-
return job.start(() => {
|
|
10069
|
-
this.jobDone(job);
|
|
10070
|
-
}, (statusCode) => {
|
|
10071
|
-
this.jobStatus(job, statusCode);
|
|
10072
|
-
});
|
|
10073
|
-
} catch (e) {
|
|
10074
|
-
this._limit.release();
|
|
10075
|
-
throw e;
|
|
10533
|
+
async models() {
|
|
10534
|
+
this._logger.warn("listModels for development use only");
|
|
10535
|
+
const client = this._client;
|
|
10536
|
+
const baseUrl = this._baseUrl;
|
|
10537
|
+
if (!baseUrl || !client) {
|
|
10538
|
+
return Promise.reject("endpoint not connected, use connect() before listModels()");
|
|
10076
10539
|
}
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10540
|
+
let get_path;
|
|
10541
|
+
if (this._sandboxId === null) {
|
|
10542
|
+
get_path = `${baseUrl}/models/instances`;
|
|
10543
|
+
} else {
|
|
10544
|
+
get_path = `${baseUrl}/models/instances?sandboxId=${this._sandboxId}`;
|
|
10081
10545
|
}
|
|
10082
|
-
await this.
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
}
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
this._limit.release();
|
|
10095
|
-
throw e;
|
|
10546
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10547
|
+
const session = await this.session();
|
|
10548
|
+
let headers = {
|
|
10549
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
10550
|
+
"Content-Type": "application/json"
|
|
10551
|
+
};
|
|
10552
|
+
this._requestLogger.debug("before GET %s", get_path);
|
|
10553
|
+
return client.fetch(get_path, { headers });
|
|
10554
|
+
});
|
|
10555
|
+
if (!response.ok) {
|
|
10556
|
+
const message = await response.text();
|
|
10557
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10096
10558
|
}
|
|
10559
|
+
const result = await response.json();
|
|
10560
|
+
this._requestLogger.debug("after GET %s", get_path);
|
|
10561
|
+
return result;
|
|
10097
10562
|
}
|
|
10098
|
-
async
|
|
10099
|
-
|
|
10100
|
-
|
|
10563
|
+
async changeManifest(manifests) {
|
|
10564
|
+
this._logger.warn("setManifest for development use only");
|
|
10565
|
+
const client = this._client;
|
|
10566
|
+
const baseUrl = this._baseUrl;
|
|
10567
|
+
if (!baseUrl || !client) {
|
|
10568
|
+
return Promise.reject("endpoint not connected, use connect() before setManifest()");
|
|
10101
10569
|
}
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10570
|
+
let put_url;
|
|
10571
|
+
if (this._sandboxId === null) {
|
|
10572
|
+
put_url = `${baseUrl}/models/sources`;
|
|
10573
|
+
} else {
|
|
10574
|
+
put_url = `${baseUrl}/models/sources?sandboxId=${this._sandboxId}`;
|
|
10575
|
+
}
|
|
10576
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10577
|
+
const session = await this.session();
|
|
10578
|
+
let headers = {
|
|
10579
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
10580
|
+
"Content-Type": "application/json"
|
|
10581
|
+
};
|
|
10582
|
+
this._requestLogger.debug("before PUT %s", put_url);
|
|
10583
|
+
return client.fetch(put_url, {
|
|
10584
|
+
method: "PUT",
|
|
10585
|
+
body: JSON.stringify(manifests),
|
|
10586
|
+
headers
|
|
10113
10587
|
});
|
|
10114
|
-
}
|
|
10115
|
-
|
|
10116
|
-
|
|
10588
|
+
});
|
|
10589
|
+
if (!response.ok) {
|
|
10590
|
+
const message = await response.text();
|
|
10591
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10117
10592
|
}
|
|
10593
|
+
this._requestLogger.debug("after PUT %s", put_url);
|
|
10118
10594
|
}
|
|
10119
|
-
async
|
|
10120
|
-
|
|
10121
|
-
|
|
10595
|
+
async loadModel(model) {
|
|
10596
|
+
this._logger.warn("loadModel for development use only");
|
|
10597
|
+
const client = this._client;
|
|
10598
|
+
const baseUrl = this._baseUrl;
|
|
10599
|
+
if (!baseUrl || !client) {
|
|
10600
|
+
return Promise.reject("endpoint not connected, use connect() before loadModel()");
|
|
10122
10601
|
}
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10602
|
+
let post_url;
|
|
10603
|
+
if (this._sandboxId === null) {
|
|
10604
|
+
post_url = `${baseUrl}/models/instances`;
|
|
10605
|
+
} else {
|
|
10606
|
+
post_url = `${baseUrl}/models/instances?sandboxId=${this._sandboxId}`;
|
|
10607
|
+
}
|
|
10608
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10609
|
+
const session = await this.session();
|
|
10610
|
+
let headers = {
|
|
10611
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
10612
|
+
"Content-Type": "application/json"
|
|
10613
|
+
};
|
|
10614
|
+
this._requestLogger.debug("before POST %s", post_url);
|
|
10615
|
+
return client.fetch(post_url, {
|
|
10616
|
+
method: "POST",
|
|
10617
|
+
body: JSON.stringify(model),
|
|
10618
|
+
headers
|
|
10133
10619
|
});
|
|
10134
|
-
}
|
|
10135
|
-
|
|
10136
|
-
|
|
10620
|
+
});
|
|
10621
|
+
if (!response.ok) {
|
|
10622
|
+
const message = await response.text();
|
|
10623
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10137
10624
|
}
|
|
10625
|
+
const result = await response.json();
|
|
10626
|
+
this._requestLogger.debug("after POST %s", post_url);
|
|
10627
|
+
return result;
|
|
10138
10628
|
}
|
|
10139
|
-
async
|
|
10140
|
-
|
|
10141
|
-
|
|
10629
|
+
async unloadModel(modelId) {
|
|
10630
|
+
this._logger.warn("purgeModel for development use only");
|
|
10631
|
+
const client = this._client;
|
|
10632
|
+
const baseUrl = this._baseUrl;
|
|
10633
|
+
if (!baseUrl || !client) {
|
|
10634
|
+
return Promise.reject("endpoint not connected, use connect() before unloadModel()");
|
|
10142
10635
|
}
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
this.
|
|
10156
|
-
|
|
10636
|
+
let delete_url;
|
|
10637
|
+
if (this._sandboxId === null) {
|
|
10638
|
+
delete_url = `${baseUrl}/models/instances/${modelId}`;
|
|
10639
|
+
} else {
|
|
10640
|
+
delete_url = `${baseUrl}/models/instances/${modelId}?sandboxId=${this._sandboxId}`;
|
|
10641
|
+
}
|
|
10642
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10643
|
+
const session = await this.session();
|
|
10644
|
+
let headers = {
|
|
10645
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
10646
|
+
"Content-Type": "application/json"
|
|
10647
|
+
};
|
|
10648
|
+
this._requestLogger.debug("before DELETE %s", delete_url);
|
|
10649
|
+
return client.fetch(delete_url, { method: "DELETE", headers });
|
|
10650
|
+
});
|
|
10651
|
+
if (!response.ok) {
|
|
10652
|
+
const message = await response.text();
|
|
10653
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10157
10654
|
}
|
|
10655
|
+
this._requestLogger.debug("after DELETE %s", delete_url);
|
|
10158
10656
|
}
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10657
|
+
};
|
|
10658
|
+
|
|
10659
|
+
// shims/websockets.ts
|
|
10660
|
+
var createWebSocket;
|
|
10661
|
+
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
10662
|
+
createWebSocket = (url, protocols) => {
|
|
10663
|
+
return new WebSocket(url, protocols);
|
|
10664
|
+
};
|
|
10665
|
+
} else {
|
|
10666
|
+
createWebSocket = (url, protocols) => {
|
|
10667
|
+
const ws = __require("ws");
|
|
10668
|
+
return new ws.WebSocket(url, protocols);
|
|
10669
|
+
};
|
|
10670
|
+
}
|
|
10671
|
+
|
|
10672
|
+
// ../../node_modules/url-join/lib/url-join.js
|
|
10673
|
+
function normalize(strArray) {
|
|
10674
|
+
var resultArray = [];
|
|
10675
|
+
if (strArray.length === 0) {
|
|
10676
|
+
return "";
|
|
10162
10677
|
}
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10678
|
+
if (typeof strArray[0] !== "string") {
|
|
10679
|
+
throw new TypeError("Url must be a string. Received " + strArray[0]);
|
|
10680
|
+
}
|
|
10681
|
+
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
|
|
10682
|
+
var first = strArray.shift();
|
|
10683
|
+
strArray[0] = first + strArray[0];
|
|
10684
|
+
}
|
|
10685
|
+
if (strArray[0].match(/^file:\/\/\//)) {
|
|
10686
|
+
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
|
|
10687
|
+
} else {
|
|
10688
|
+
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
|
|
10689
|
+
}
|
|
10690
|
+
for (var i = 0; i < strArray.length; i++) {
|
|
10691
|
+
var component = strArray[i];
|
|
10692
|
+
if (typeof component !== "string") {
|
|
10693
|
+
throw new TypeError("Url must be a string. Received " + component);
|
|
10171
10694
|
}
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
this._stateChangeHandler(fromState, this._state);
|
|
10695
|
+
if (component === "") {
|
|
10696
|
+
continue;
|
|
10175
10697
|
}
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
} else
|
|
10182
|
-
|
|
10183
|
-
this._expire_token_time = null;
|
|
10698
|
+
if (i > 0) {
|
|
10699
|
+
component = component.replace(/^[\/]+/, "");
|
|
10700
|
+
}
|
|
10701
|
+
if (i < strArray.length - 1) {
|
|
10702
|
+
component = component.replace(/[\/]+$/, "");
|
|
10703
|
+
} else {
|
|
10704
|
+
component = component.replace(/[\/]+$/, "/");
|
|
10184
10705
|
}
|
|
10706
|
+
resultArray.push(component);
|
|
10185
10707
|
}
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10189
|
-
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10708
|
+
var str = resultArray.join("/");
|
|
10709
|
+
str = str.replace(/\/(\?|&|#[^!])/g, "$1");
|
|
10710
|
+
var parts = str.split("?");
|
|
10711
|
+
str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
|
|
10712
|
+
return str;
|
|
10713
|
+
}
|
|
10714
|
+
function urlJoin() {
|
|
10715
|
+
var input;
|
|
10716
|
+
if (typeof arguments[0] === "object") {
|
|
10717
|
+
input = arguments[0];
|
|
10718
|
+
} else {
|
|
10719
|
+
input = [].slice.call(arguments);
|
|
10720
|
+
}
|
|
10721
|
+
return normalize(input);
|
|
10722
|
+
}
|
|
10723
|
+
|
|
10724
|
+
// data/data_types.ts
|
|
10725
|
+
var AssetStatus = /* @__PURE__ */ ((AssetStatus2) => {
|
|
10726
|
+
AssetStatus2["rejected"] = "rejected";
|
|
10727
|
+
AssetStatus2["upload_in_progress"] = "upload_in_progress";
|
|
10728
|
+
AssetStatus2["upload_failed"] = "upload_failed";
|
|
10729
|
+
AssetStatus2["transform_failed"] = "transform_failed";
|
|
10730
|
+
AssetStatus2["transform_in_progress"] = "transform_in_progress";
|
|
10731
|
+
AssetStatus2["accepted"] = "accepted";
|
|
10732
|
+
return AssetStatus2;
|
|
10733
|
+
})(AssetStatus || {});
|
|
10734
|
+
var AnnotationType = /* @__PURE__ */ ((AnnotationType2) => {
|
|
10735
|
+
AnnotationType2["manual"] = "manual";
|
|
10736
|
+
AnnotationType2["prediction"] = "prediction";
|
|
10737
|
+
AnnotationType2["auto"] = "auto";
|
|
10738
|
+
return AnnotationType2;
|
|
10739
|
+
})(AnnotationType || {});
|
|
10740
|
+
var UserReview = /* @__PURE__ */ ((UserReview3) => {
|
|
10741
|
+
UserReview3["approved"] = "approved";
|
|
10742
|
+
UserReview3["rejected"] = "rejected";
|
|
10743
|
+
UserReview3["unknown"] = "unknown";
|
|
10744
|
+
return UserReview3;
|
|
10745
|
+
})(UserReview || {});
|
|
10746
|
+
var TranscodeMode = /* @__PURE__ */ ((TranscodeMode2) => {
|
|
10747
|
+
TranscodeMode2["original"] = "original";
|
|
10748
|
+
TranscodeMode2["image_original_size"] = "image_original_size";
|
|
10749
|
+
TranscodeMode2["image_fit_1024"] = "image_fit_1024";
|
|
10750
|
+
TranscodeMode2["image_fit_640"] = "image_fit_640";
|
|
10751
|
+
TranscodeMode2["image_fit_224"] = "image_fit_224";
|
|
10752
|
+
TranscodeMode2["image_cover_1024"] = "image_cover_1024";
|
|
10753
|
+
TranscodeMode2["image_cover_640"] = "image_cover_640";
|
|
10754
|
+
TranscodeMode2["image_cover_224"] = "image_cover_224";
|
|
10755
|
+
return TranscodeMode2;
|
|
10756
|
+
})(TranscodeMode || {});
|
|
10757
|
+
var ModelType = /* @__PURE__ */ ((ModelType2) => {
|
|
10758
|
+
ModelType2["epdet_b1"] = "epdet_b1";
|
|
10759
|
+
return ModelType2;
|
|
10760
|
+
})(ModelType || {});
|
|
10761
|
+
var ModelStatus = /* @__PURE__ */ ((ModelStatus2) => {
|
|
10762
|
+
ModelStatus2["error"] = "error";
|
|
10763
|
+
ModelStatus2["draft"] = "draft";
|
|
10764
|
+
ModelStatus2["requested"] = "requested";
|
|
10765
|
+
ModelStatus2["in_progress"] = "in_progress";
|
|
10766
|
+
ModelStatus2["available"] = "available";
|
|
10767
|
+
ModelStatus2["published"] = "published";
|
|
10768
|
+
return ModelStatus2;
|
|
10769
|
+
})(ModelStatus || {});
|
|
10770
|
+
var ChangeType = /* @__PURE__ */ ((ChangeType2) => {
|
|
10771
|
+
ChangeType2["dataset_added"] = "dataset_added";
|
|
10772
|
+
ChangeType2["dataset_removed"] = "dataset_removed";
|
|
10773
|
+
ChangeType2["dataset_modified"] = "dataset_modified";
|
|
10774
|
+
ChangeType2["dataset_version_modified"] = "dataset_version_modified";
|
|
10775
|
+
ChangeType2["asset_added"] = "asset_added";
|
|
10776
|
+
ChangeType2["asset_removed"] = "asset_removed";
|
|
10777
|
+
ChangeType2["asset_status_modified"] = "asset_status_modified";
|
|
10778
|
+
ChangeType2["asset_annotation_modified"] = "asset_annotation_modified";
|
|
10779
|
+
ChangeType2["model_added"] = "model_added";
|
|
10780
|
+
ChangeType2["model_removed"] = "model_removed";
|
|
10781
|
+
ChangeType2["model_modified"] = "model_modified";
|
|
10782
|
+
ChangeType2["model_status_modified"] = "model_status_modified";
|
|
10783
|
+
return ChangeType2;
|
|
10784
|
+
})(ChangeType || {});
|
|
10785
|
+
|
|
10786
|
+
// data/data_endpoint.ts
|
|
10787
|
+
var WS_INITIAL_RECONNECT_DELAY = 1e3;
|
|
10788
|
+
var WS_MAX_RECONNECT_DELAY = 6e4;
|
|
10789
|
+
var DataEndpoint = class extends Endpoint {
|
|
10790
|
+
constructor(options) {
|
|
10791
|
+
super(options);
|
|
10792
|
+
this._baseUrl = null;
|
|
10793
|
+
this._ws = null;
|
|
10794
|
+
this._ws_current_reconnect_delay = null;
|
|
10795
|
+
this._accountId = options.accountId || null;
|
|
10796
|
+
this._account_event_handlers = [];
|
|
10797
|
+
this._dataset_uuid_to_event_handlers = /* @__PURE__ */ new Map();
|
|
10798
|
+
const sessionAuth = options.auth;
|
|
10799
|
+
if (sessionAuth.session !== void 0) {
|
|
10800
|
+
const dataSession = sessionAuth.session;
|
|
10801
|
+
if (dataSession.accountId) {
|
|
10802
|
+
this._accountId = dataSession.accountId;
|
|
10803
|
+
}
|
|
10804
|
+
}
|
|
10805
|
+
}
|
|
10806
|
+
async session() {
|
|
10807
|
+
const session = await super.session();
|
|
10808
|
+
return {
|
|
10809
|
+
eyepopUrl: session.eyepopUrl,
|
|
10810
|
+
accessToken: session.accessToken,
|
|
10811
|
+
validUntil: session.validUntil,
|
|
10812
|
+
accountId: this.options().accountId,
|
|
10813
|
+
baseUrl: this._baseUrl
|
|
10814
|
+
};
|
|
10815
|
+
}
|
|
10816
|
+
async disconnect(wait = true) {
|
|
10817
|
+
this._baseUrl = null;
|
|
10818
|
+
if (this._ws) {
|
|
10819
|
+
try {
|
|
10820
|
+
this._ws.close();
|
|
10821
|
+
} catch (e) {
|
|
10822
|
+
this._logger.warn("ignored exception", e);
|
|
10216
10823
|
}
|
|
10824
|
+
this._ws = null;
|
|
10217
10825
|
}
|
|
10826
|
+
await super.disconnect(wait);
|
|
10218
10827
|
}
|
|
10219
10828
|
async reconnect() {
|
|
10220
10829
|
if (!this._client) {
|
|
10221
10830
|
return Promise.reject("endpoint not initialized");
|
|
10222
10831
|
}
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
config_url = `${this.eyepopUrl()}/workers/config`;
|
|
10226
|
-
} else {
|
|
10227
|
-
config_url = `${this.eyepopUrl()}/pops/${this._options.popId}/config?auto_start=false`;
|
|
10228
|
-
}
|
|
10229
|
-
const headers = {
|
|
10832
|
+
const config_url = `${this.eyepopUrl()}/data/config?account_uuid=${this._accountId}`;
|
|
10833
|
+
let headers = {
|
|
10230
10834
|
"Authorization": await this.authorizationHeader()
|
|
10231
10835
|
};
|
|
10232
10836
|
this.updateState("FetchConfig" /* FetchConfig */);
|
|
@@ -10234,193 +10838,368 @@ var Endpoint = class {
|
|
|
10234
10838
|
let response = await this._client.fetch(config_url, { headers });
|
|
10235
10839
|
if (response.status == 401) {
|
|
10236
10840
|
this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", config_url);
|
|
10237
|
-
this.
|
|
10238
|
-
|
|
10841
|
+
this.statusHandler401(response.status);
|
|
10842
|
+
headers = {
|
|
10239
10843
|
"Authorization": await this.authorizationHeader()
|
|
10240
10844
|
};
|
|
10241
10845
|
this.updateState("FetchConfig" /* FetchConfig */);
|
|
10242
10846
|
response = await this._client.fetch(config_url, {
|
|
10243
|
-
headers
|
|
10847
|
+
headers
|
|
10244
10848
|
});
|
|
10245
10849
|
}
|
|
10246
10850
|
if (response.status != 200) {
|
|
10247
10851
|
this.updateState("Error" /* Error */);
|
|
10248
10852
|
const message = await response.text();
|
|
10249
10853
|
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10854
|
+
}
|
|
10855
|
+
let config = await response.json();
|
|
10856
|
+
this._requestLogger.debug("after GET %s", config_url);
|
|
10857
|
+
const baseUrl = new URL(config.base_url, this.eyepopUrl());
|
|
10858
|
+
this._baseUrl = baseUrl.toString();
|
|
10859
|
+
if (this.options().disableWs) {
|
|
10860
|
+
this._logger.info("disabled ws connection");
|
|
10250
10861
|
} else {
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
if (this._options.popId == "transient" /* Transient */) {
|
|
10272
|
-
this._pipelineId = await this.startPopLessPipeline();
|
|
10273
|
-
this._popName = this._options.popId;
|
|
10274
|
-
} else {
|
|
10275
|
-
this._pipelineId = config.pipeline_id;
|
|
10276
|
-
this._popName = config.name;
|
|
10277
|
-
}
|
|
10278
|
-
this._requestLogger.debug("after GET %s: %s / %s", config_url, this._baseUrl, this._pipelineId);
|
|
10279
|
-
if (!this._pipelineId || !this._baseUrl) {
|
|
10280
|
-
return Promise.reject(`Pop not started`);
|
|
10862
|
+
await this.reconnect_ws();
|
|
10863
|
+
}
|
|
10864
|
+
this.updateState();
|
|
10865
|
+
return Promise.resolve(this);
|
|
10866
|
+
}
|
|
10867
|
+
async reconnect_ws() {
|
|
10868
|
+
if (this._ws) {
|
|
10869
|
+
this._ws.close();
|
|
10870
|
+
this._ws = null;
|
|
10871
|
+
}
|
|
10872
|
+
const baseUrl = this._baseUrl?.replace("https://", "wss://").replace("http://", "ws://");
|
|
10873
|
+
if (!baseUrl) {
|
|
10874
|
+
return;
|
|
10875
|
+
}
|
|
10876
|
+
const ws_url = urlJoin(baseUrl, "events");
|
|
10877
|
+
this._requestLogger.debug("about to connect ws to: %s", ws_url);
|
|
10878
|
+
return new Promise((resolve, reject) => {
|
|
10879
|
+
const ws = createWebSocket(ws_url);
|
|
10880
|
+
if (!ws) {
|
|
10881
|
+
return resolve();
|
|
10281
10882
|
}
|
|
10282
|
-
this.
|
|
10283
|
-
|
|
10284
|
-
const
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
|
|
10883
|
+
this._ws = ws;
|
|
10884
|
+
ws.onopen = async () => {
|
|
10885
|
+
const auth_header = await this.authorizationHeader();
|
|
10886
|
+
let msg = JSON.stringify({ authorization: auth_header });
|
|
10887
|
+
this._requestLogger.debug("ws send: %s", msg);
|
|
10888
|
+
ws.send(msg);
|
|
10889
|
+
msg = JSON.stringify({ subscribe: { account_uuid: this._accountId } });
|
|
10890
|
+
this._requestLogger.debug("ws send: %s", msg);
|
|
10891
|
+
ws.send(msg);
|
|
10892
|
+
for (let dataset_uuid in this._dataset_uuid_to_event_handlers.keys()) {
|
|
10893
|
+
const msg2 = JSON.stringify({ subscribe: { dataset_uuid } });
|
|
10894
|
+
this._requestLogger.debug("ws send: %s", msg2);
|
|
10895
|
+
ws.send(msg2);
|
|
10896
|
+
}
|
|
10897
|
+
this._ws_current_reconnect_delay = WS_INITIAL_RECONNECT_DELAY;
|
|
10898
|
+
resolve();
|
|
10899
|
+
};
|
|
10900
|
+
ws.onmessage = (event) => {
|
|
10901
|
+
const data = JSON.parse(event.data);
|
|
10902
|
+
this._requestLogger.debug("received ws: %s", JSON.stringify(data));
|
|
10903
|
+
const change_event = data;
|
|
10904
|
+
this.dispatchChangeEvent(change_event);
|
|
10905
|
+
};
|
|
10906
|
+
ws.onclose = (event) => {
|
|
10907
|
+
const { code, reason } = event;
|
|
10908
|
+
this._requestLogger.debug("ws closed: %d %s", code, reason);
|
|
10909
|
+
if (reason !== "unsubscribe") {
|
|
10910
|
+
if (!this._ws_current_reconnect_delay) {
|
|
10911
|
+
this._ws_current_reconnect_delay = WS_INITIAL_RECONNECT_DELAY;
|
|
10912
|
+
} else if (this._ws_current_reconnect_delay < WS_MAX_RECONNECT_DELAY) {
|
|
10913
|
+
this._ws_current_reconnect_delay *= 1.5;
|
|
10914
|
+
}
|
|
10915
|
+
setTimeout(async () => {
|
|
10916
|
+
await this.reconnect_ws();
|
|
10917
|
+
}, this._ws_current_reconnect_delay);
|
|
10296
10918
|
}
|
|
10297
|
-
|
|
10298
|
-
|
|
10919
|
+
};
|
|
10920
|
+
ws.onerror = (event) => {
|
|
10921
|
+
this._logger.error(event);
|
|
10922
|
+
reject(event);
|
|
10923
|
+
return null;
|
|
10924
|
+
};
|
|
10925
|
+
});
|
|
10926
|
+
}
|
|
10927
|
+
options() {
|
|
10928
|
+
return this._options;
|
|
10929
|
+
}
|
|
10930
|
+
async request(path2, options = {}, disableAuth = false) {
|
|
10931
|
+
const client = this._client;
|
|
10932
|
+
const baseUrl = this._baseUrl;
|
|
10933
|
+
if (!baseUrl || !client) {
|
|
10934
|
+
return Promise.reject("endpoint not connected, use connect() before changePopComp()");
|
|
10935
|
+
}
|
|
10936
|
+
let response = await this.fetchWithRetry(async () => {
|
|
10937
|
+
const session = await this.session();
|
|
10938
|
+
const headers = {
|
|
10939
|
+
"Content-Type": "application/json",
|
|
10940
|
+
...disableAuth ? {} : { "Authorization": `Bearer ${session.accessToken}` },
|
|
10941
|
+
...options.headers || {}
|
|
10942
|
+
};
|
|
10943
|
+
if (!options.body) {
|
|
10944
|
+
options.body = null;
|
|
10299
10945
|
}
|
|
10300
|
-
|
|
10301
|
-
|
|
10946
|
+
const ri = {
|
|
10947
|
+
headers,
|
|
10948
|
+
method: options.method || "GET",
|
|
10949
|
+
body: options.body
|
|
10950
|
+
};
|
|
10951
|
+
this._requestLogger.debug("Request - " + ri.method + path2 + " BODY: " + (ri.body ? ri.body : ""));
|
|
10952
|
+
return await client.fetch(urlJoin(session.baseUrl ?? "", path2), ri);
|
|
10953
|
+
});
|
|
10954
|
+
if (response.status === 204) {
|
|
10955
|
+
return null;
|
|
10956
|
+
}
|
|
10957
|
+
if (!response.ok) {
|
|
10958
|
+
const errorData = await response.json();
|
|
10959
|
+
throw new Error(errorData.detail || "Request failed");
|
|
10960
|
+
}
|
|
10961
|
+
const contentType = response.headers.get("Content-Type");
|
|
10962
|
+
if (contentType && contentType.startsWith("image/")) {
|
|
10963
|
+
const blob = await response.blob();
|
|
10964
|
+
return blob;
|
|
10302
10965
|
}
|
|
10966
|
+
this._requestLogger.debug("Response - " + response.status + " " + response.statusText);
|
|
10967
|
+
return response.json();
|
|
10303
10968
|
}
|
|
10304
|
-
async
|
|
10305
|
-
return
|
|
10969
|
+
async listDatasets() {
|
|
10970
|
+
return this.request(`/datasets?account_uuid=${this._accountId}`, {
|
|
10971
|
+
method: "GET"
|
|
10972
|
+
});
|
|
10306
10973
|
}
|
|
10307
|
-
async
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
} finally {
|
|
10348
|
-
this.updateState();
|
|
10974
|
+
async createDataset(data) {
|
|
10975
|
+
return this.request(`/datasets?account_uuid=${this._accountId}`, {
|
|
10976
|
+
method: "POST",
|
|
10977
|
+
body: JSON.stringify(data)
|
|
10978
|
+
});
|
|
10979
|
+
}
|
|
10980
|
+
async getDataset(dataset_uuid) {
|
|
10981
|
+
return this.request(`/datasets/${dataset_uuid}`, {
|
|
10982
|
+
method: "GET"
|
|
10983
|
+
});
|
|
10984
|
+
}
|
|
10985
|
+
async updateDataset(dataset_uuid, data) {
|
|
10986
|
+
return this.request(`/datasets/${dataset_uuid}`, {
|
|
10987
|
+
method: "PATCH",
|
|
10988
|
+
body: JSON.stringify(data)
|
|
10989
|
+
});
|
|
10990
|
+
}
|
|
10991
|
+
async deleteDataset(dataset_uuid) {
|
|
10992
|
+
return this.request(`/datasets/${dataset_uuid}`, {
|
|
10993
|
+
method: "DELETE"
|
|
10994
|
+
});
|
|
10995
|
+
}
|
|
10996
|
+
async freezeDatasetVersion(dataset_uuid, dataset_version) {
|
|
10997
|
+
const versionQuery = dataset_version ? `&dataset_version=${dataset_version}` : "";
|
|
10998
|
+
return this.request(`/datasets/${dataset_uuid}/freeze?${versionQuery}`, {
|
|
10999
|
+
method: "POST"
|
|
11000
|
+
});
|
|
11001
|
+
}
|
|
11002
|
+
async deleteDatasetVersion(dataset_uuid, dataset_version) {
|
|
11003
|
+
return this.request(`/datasets/${dataset_uuid}/delete?dataset_version=${dataset_version}`, {
|
|
11004
|
+
method: "POST"
|
|
11005
|
+
});
|
|
11006
|
+
}
|
|
11007
|
+
// Asset methods
|
|
11008
|
+
async uploadAsset(dataset_uuid, dataset_version, blob) {
|
|
11009
|
+
return this.request(`/assets?dataset_uuid=${dataset_uuid}&dataset_version=${dataset_version}`, {
|
|
11010
|
+
method: "POST",
|
|
11011
|
+
body: blob,
|
|
11012
|
+
headers: {
|
|
11013
|
+
"Content-Type": blob.type || "application/octet-stream"
|
|
10349
11014
|
}
|
|
11015
|
+
});
|
|
11016
|
+
}
|
|
11017
|
+
async listAssets(dataset_uuid, dataset_version, include_annotations = false) {
|
|
11018
|
+
const versionQuery = dataset_version ? `&dataset_version=${dataset_version}` : "";
|
|
11019
|
+
const annotationsQuery = include_annotations ? "&include_annotations=true" : "";
|
|
11020
|
+
return this.request(`/assets?dataset_uuid=${dataset_uuid}${versionQuery}${annotationsQuery}`, {
|
|
11021
|
+
method: "GET"
|
|
11022
|
+
});
|
|
11023
|
+
}
|
|
11024
|
+
async getAsset(asset_uuid, dataset_uuid, dataset_version, include_annotations = false) {
|
|
11025
|
+
const versionQuery = dataset_version ? `&dataset_version=${dataset_version}` : "";
|
|
11026
|
+
const annotationsQuery = include_annotations ? "&include_annotations=true" : "";
|
|
11027
|
+
const datasetQuery = dataset_uuid ? `&dataset_uuid=${dataset_uuid}` : "";
|
|
11028
|
+
return this.request(`/assets/${asset_uuid}?${datasetQuery}${versionQuery}${annotationsQuery}`, {
|
|
11029
|
+
method: "GET"
|
|
11030
|
+
});
|
|
11031
|
+
}
|
|
11032
|
+
async deleteAsset(asset_uuid, dataset_uuid, dataset_version) {
|
|
11033
|
+
const versionQuery = dataset_version ? `&dataset_version=${dataset_version}` : "";
|
|
11034
|
+
const datasetQuery = dataset_uuid ? `&dataset_uuid=${dataset_uuid}` : "";
|
|
11035
|
+
return this.request(`/assets/${asset_uuid}?${datasetQuery}${versionQuery}`, {
|
|
11036
|
+
method: "DELETE"
|
|
11037
|
+
});
|
|
11038
|
+
}
|
|
11039
|
+
async resurrectAsset(asset_uuid, dataset_uuid, from_dataset_version, into_dataset_version) {
|
|
11040
|
+
const intoVersionQuery = into_dataset_version ? `&into_dataset_version=${into_dataset_version}` : "";
|
|
11041
|
+
return this.request(`/assets/${asset_uuid}/resurrect?dataset_uuid=${dataset_uuid}&from_dataset_version=${from_dataset_version}${intoVersionQuery}`, {
|
|
11042
|
+
method: "POST"
|
|
11043
|
+
});
|
|
11044
|
+
}
|
|
11045
|
+
async updateAssetManualAnnotation(asset_uuid, dataset_uuid, dataset_version, prediction) {
|
|
11046
|
+
const versionQuery = dataset_version ? `&dataset_version=${dataset_version}` : "";
|
|
11047
|
+
const datasetQuery = dataset_uuid ? `&dataset_uuid=${dataset_uuid}` : "";
|
|
11048
|
+
return this.request(`/assets/${asset_uuid}/manual_annotate?${datasetQuery}${versionQuery}`, {
|
|
11049
|
+
method: "PATCH",
|
|
11050
|
+
body: JSON.stringify(prediction)
|
|
11051
|
+
});
|
|
11052
|
+
}
|
|
11053
|
+
async updateAutoAnnotationStatus(asset_uuid, auto_annotate, user_review) {
|
|
11054
|
+
const validStatuses = ["approved", "rejected", "unknown"];
|
|
11055
|
+
if (!validStatuses.includes(user_review)) {
|
|
11056
|
+
throw new Error("Invalid status");
|
|
10350
11057
|
}
|
|
10351
|
-
this.
|
|
10352
|
-
|
|
11058
|
+
return this.request(`/assets/${asset_uuid}/auto_annotations/${auto_annotate}/user_review/${user_review}`, {
|
|
11059
|
+
method: "PATCH"
|
|
11060
|
+
});
|
|
10353
11061
|
}
|
|
10354
|
-
async
|
|
10355
|
-
|
|
10356
|
-
|
|
11062
|
+
async downloadAsset(asset_uuid, dataset_uuid, dataset_version, transcode_mode = "original" /* original */) {
|
|
11063
|
+
const versionQuery = dataset_version ? `&dataset_version=${dataset_version}` : "";
|
|
11064
|
+
const datasetQuery = dataset_uuid ? `&dataset_uuid=${dataset_uuid}` : "";
|
|
11065
|
+
return this.request(`/assets/${asset_uuid}/download?${datasetQuery}${versionQuery}&transcode_mode=${transcode_mode}`, {
|
|
11066
|
+
method: "GET"
|
|
11067
|
+
});
|
|
11068
|
+
}
|
|
11069
|
+
// Model methods
|
|
11070
|
+
async listModels() {
|
|
11071
|
+
return this.request(`/models?account_uuid=${this._accountId}`, {
|
|
11072
|
+
method: "GET"
|
|
11073
|
+
});
|
|
11074
|
+
}
|
|
11075
|
+
async createModel(dataset_uuid, dataset_version, data) {
|
|
11076
|
+
return this.request(`/models?dataset_uuid=${dataset_uuid}&dataset_version=${dataset_version}`, {
|
|
11077
|
+
method: "POST",
|
|
11078
|
+
body: JSON.stringify(data)
|
|
11079
|
+
});
|
|
11080
|
+
}
|
|
11081
|
+
async getModel(model_uuid) {
|
|
11082
|
+
return this.request(`/models/${model_uuid}`, {
|
|
11083
|
+
method: "GET"
|
|
11084
|
+
});
|
|
11085
|
+
}
|
|
11086
|
+
async updateModel(model_uuid, data) {
|
|
11087
|
+
return this.request(`/models/${model_uuid}`, {
|
|
11088
|
+
method: "PATCH",
|
|
11089
|
+
body: JSON.stringify(data)
|
|
11090
|
+
});
|
|
11091
|
+
}
|
|
11092
|
+
async deleteModel(model_uuid) {
|
|
11093
|
+
return this.request(`/models/${model_uuid}`, {
|
|
11094
|
+
method: "DELETE"
|
|
11095
|
+
});
|
|
11096
|
+
}
|
|
11097
|
+
async publishModel(model_uuid) {
|
|
11098
|
+
return this.request(`/models/${model_uuid}/publish`, {
|
|
11099
|
+
method: "POST"
|
|
11100
|
+
});
|
|
11101
|
+
}
|
|
11102
|
+
addAccountEventHandler(eventHandler) {
|
|
11103
|
+
this._account_event_handlers.push(eventHandler);
|
|
11104
|
+
}
|
|
11105
|
+
removeAccountEventHandler(eventHandler) {
|
|
11106
|
+
this._account_event_handlers = this._account_event_handlers.filter((h) => h !== eventHandler);
|
|
11107
|
+
}
|
|
11108
|
+
addDatasetEventHandler(dataset_uuid, eventHandler) {
|
|
11109
|
+
let event_handlers = this._dataset_uuid_to_event_handlers.get(dataset_uuid);
|
|
11110
|
+
this._logger.debug("addDatasetEventHandler %s", event_handlers);
|
|
11111
|
+
if (event_handlers === void 0) {
|
|
11112
|
+
event_handlers = [];
|
|
11113
|
+
this._dataset_uuid_to_event_handlers.set(dataset_uuid, event_handlers);
|
|
11114
|
+
const ws = this._ws;
|
|
11115
|
+
if (ws) {
|
|
11116
|
+
const msg = JSON.stringify({ subscribe: { dataset_uuid } });
|
|
11117
|
+
this._requestLogger.debug("ws send: %s", msg);
|
|
11118
|
+
ws.send(msg);
|
|
11119
|
+
}
|
|
10357
11120
|
}
|
|
10358
|
-
|
|
10359
|
-
|
|
10360
|
-
|
|
10361
|
-
pipeline = this._pipeline.inferPipeline;
|
|
10362
|
-
} else {
|
|
10363
|
-
pipeline = "identity";
|
|
11121
|
+
if (event_handlers.find((h) => h === eventHandler) !== eventHandler) {
|
|
11122
|
+
this._logger.debug("addDatasetEventHandler event_handlers=%s", event_handlers);
|
|
11123
|
+
event_handlers.push(eventHandler);
|
|
10364
11124
|
}
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
11125
|
+
}
|
|
11126
|
+
removeDatasetEventHandler(dataset_uuid, eventHandler) {
|
|
11127
|
+
let event_handlers = this._dataset_uuid_to_event_handlers.get(dataset_uuid);
|
|
11128
|
+
if (event_handlers === void 0) {
|
|
11129
|
+
return;
|
|
10370
11130
|
}
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
"
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
},
|
|
10381
|
-
"idleTimeoutSeconds": 30,
|
|
10382
|
-
"logging": ["out_meta"],
|
|
10383
|
-
"videoOutput": "no_output"
|
|
10384
|
-
};
|
|
10385
|
-
let post_url;
|
|
10386
|
-
if (this._sandboxId) {
|
|
10387
|
-
post_url = `${this._baseUrl.replace(/\/+$/, "")}/pipelines?sandboxId=${this._sandboxId}`;
|
|
10388
|
-
} else {
|
|
10389
|
-
post_url = `${this._baseUrl.replace(/\/+$/, "")}/pipelines`;
|
|
11131
|
+
event_handlers = event_handlers.filter((h) => h !== eventHandler);
|
|
11132
|
+
if (event_handlers.length == 0) {
|
|
11133
|
+
const ws = this._ws;
|
|
11134
|
+
if (ws) {
|
|
11135
|
+
const msg = JSON.stringify({ unsubscribe: { dataset_uuid } });
|
|
11136
|
+
this._requestLogger.debug("ws send: %s", msg);
|
|
11137
|
+
ws.send(msg);
|
|
11138
|
+
}
|
|
11139
|
+
this._dataset_uuid_to_event_handlers.delete(dataset_uuid);
|
|
10390
11140
|
}
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
let response = await this._client.fetch(post_url, {
|
|
10397
|
-
method: "POST",
|
|
10398
|
-
headers,
|
|
10399
|
-
body: JSON.stringify(body)
|
|
10400
|
-
});
|
|
10401
|
-
if (response.status == 401) {
|
|
10402
|
-
this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", post_url);
|
|
10403
|
-
this._token = null;
|
|
10404
|
-
headers = {
|
|
10405
|
-
"Content-Type": "application/json",
|
|
10406
|
-
"Authorization": await this.authorizationHeader()
|
|
10407
|
-
};
|
|
10408
|
-
response = await this._client.fetch(post_url, {
|
|
10409
|
-
method: "POST",
|
|
10410
|
-
headers,
|
|
10411
|
-
body: JSON.stringify(body)
|
|
10412
|
-
});
|
|
11141
|
+
}
|
|
11142
|
+
removeAllDatasetEventHandlers(dataset_uuid) {
|
|
11143
|
+
let event_handlers = this._dataset_uuid_to_event_handlers.get(dataset_uuid);
|
|
11144
|
+
if (event_handlers === void 0) {
|
|
11145
|
+
return;
|
|
10413
11146
|
}
|
|
10414
|
-
|
|
10415
|
-
|
|
10416
|
-
|
|
11147
|
+
const ws = this._ws;
|
|
11148
|
+
if (ws) {
|
|
11149
|
+
const msg = JSON.stringify({ unsubscribe: { dataset_uuid } });
|
|
11150
|
+
this._requestLogger.debug("ws send: %s", msg);
|
|
11151
|
+
ws.send(msg);
|
|
11152
|
+
}
|
|
11153
|
+
this._dataset_uuid_to_event_handlers.delete(dataset_uuid);
|
|
11154
|
+
}
|
|
11155
|
+
async dispatchChangeEvent(change_event) {
|
|
11156
|
+
switch (change_event.change_type) {
|
|
11157
|
+
case "dataset_added" /* dataset_added */:
|
|
11158
|
+
case "dataset_modified" /* dataset_modified */:
|
|
11159
|
+
case "dataset_removed" /* dataset_removed */:
|
|
11160
|
+
case "dataset_version_modified" /* dataset_version_modified */:
|
|
11161
|
+
for (let handler of this._account_event_handlers) {
|
|
11162
|
+
await handler(change_event);
|
|
11163
|
+
}
|
|
11164
|
+
case "asset_added" /* asset_added */:
|
|
11165
|
+
case "asset_removed" /* asset_removed */:
|
|
11166
|
+
case "asset_status_modified" /* asset_status_modified */:
|
|
11167
|
+
case "asset_annotation_modified" /* asset_annotation_modified */:
|
|
11168
|
+
case "model_added" /* model_added */:
|
|
11169
|
+
case "model_modified" /* model_modified */:
|
|
11170
|
+
case "model_removed" /* model_removed */:
|
|
11171
|
+
case "model_status_modified" /* model_status_modified */:
|
|
11172
|
+
const event_handlers = this._dataset_uuid_to_event_handlers.get(change_event.dataset_uuid);
|
|
11173
|
+
this._logger.debug("dispatchChangeEvent event_handlers=%s", event_handlers);
|
|
11174
|
+
if (event_handlers !== void 0) {
|
|
11175
|
+
for (let handler of event_handlers) {
|
|
11176
|
+
await handler(change_event);
|
|
11177
|
+
}
|
|
11178
|
+
}
|
|
11179
|
+
break;
|
|
10417
11180
|
}
|
|
10418
|
-
this._requestLogger.debug("after POST %s", post_url);
|
|
10419
|
-
const pipelineId = (await response.json())["id"];
|
|
10420
|
-
return pipelineId;
|
|
10421
11181
|
}
|
|
10422
11182
|
};
|
|
10423
11183
|
|
|
11184
|
+
// worker/worker_types.ts
|
|
11185
|
+
var ModelFormat = /* @__PURE__ */ ((ModelFormat2) => {
|
|
11186
|
+
ModelFormat2["TensorFlowLite"] = "TensorFlowLite";
|
|
11187
|
+
ModelFormat2["TensorFlowGraphDef"] = "TensorFlowGraphDef";
|
|
11188
|
+
ModelFormat2["ONNX"] = "ONNX";
|
|
11189
|
+
ModelFormat2["TorchScript"] = "TorchScript";
|
|
11190
|
+
ModelFormat2["TorchScriptCpu"] = "TorchScriptCpu";
|
|
11191
|
+
ModelFormat2["TorchScriptCuda"] = "TorchScriptCuda";
|
|
11192
|
+
return ModelFormat2;
|
|
11193
|
+
})(ModelFormat || {});
|
|
11194
|
+
var ModelPrecisionType = /* @__PURE__ */ ((ModelPrecisionType2) => {
|
|
11195
|
+
ModelPrecisionType2["float32"] = "float32";
|
|
11196
|
+
ModelPrecisionType2["float16"] = "float16";
|
|
11197
|
+
ModelPrecisionType2["int32"] = "int32";
|
|
11198
|
+
ModelPrecisionType2["int8"] = "int8";
|
|
11199
|
+
ModelPrecisionType2["uint8"] = "uint8";
|
|
11200
|
+
return ModelPrecisionType2;
|
|
11201
|
+
})(ModelPrecisionType || {});
|
|
11202
|
+
|
|
10424
11203
|
// index.ts
|
|
10425
11204
|
var readEnv = (env) => {
|
|
10426
11205
|
if (typeof process !== "undefined") {
|
|
@@ -10434,29 +11213,57 @@ var EyePop;
|
|
|
10434
11213
|
const defaultAuth = envSecretKey ? {
|
|
10435
11214
|
secretKey: envSecretKey
|
|
10436
11215
|
} : void 0;
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
throw new Error("auth option or EYEPOP_SECRET_KEY environment variable is required");
|
|
10441
|
-
}
|
|
10442
|
-
opts.auth = defaultAuth;
|
|
10443
|
-
}
|
|
11216
|
+
EyePop2.endpoint = workerEndpoint;
|
|
11217
|
+
function workerEndpoint(opts = {}) {
|
|
11218
|
+
_fill_default_options(opts);
|
|
10444
11219
|
if (typeof opts.popId == "undefined") {
|
|
10445
11220
|
opts.popId = readEnv("EYEPOP_POP_ID");
|
|
10446
11221
|
}
|
|
10447
|
-
if (typeof opts.eyepopUrl == "undefined") {
|
|
10448
|
-
opts.eyepopUrl = readEnv("EYEPOP_URL") || "https://api.eyepop.ai";
|
|
10449
|
-
}
|
|
10450
11222
|
if (typeof opts.autoStart == "undefined") {
|
|
10451
11223
|
opts.autoStart = true;
|
|
10452
11224
|
}
|
|
10453
11225
|
if (typeof opts.stopJobs == "undefined") {
|
|
10454
11226
|
opts.stopJobs = true;
|
|
10455
11227
|
}
|
|
11228
|
+
if (opts.auth.session !== void 0) {
|
|
11229
|
+
if (opts.auth.session !== void 0) {
|
|
11230
|
+
if (opts.auth.session.popId) {
|
|
11231
|
+
opts.popId = opts.auth.session.popId;
|
|
11232
|
+
}
|
|
11233
|
+
}
|
|
11234
|
+
}
|
|
11235
|
+
return new WorkerEndpoint(opts);
|
|
11236
|
+
}
|
|
11237
|
+
EyePop2.workerEndpoint = workerEndpoint;
|
|
11238
|
+
function dataEndpoint(opts = {}) {
|
|
11239
|
+
_fill_default_options(opts);
|
|
11240
|
+
if (typeof opts.accountId == "undefined") {
|
|
11241
|
+
opts.accountId = readEnv("EYEPOP_ACCOUNT_ID");
|
|
11242
|
+
}
|
|
11243
|
+
if (opts.auth.session !== void 0) {
|
|
11244
|
+
if (opts.auth.session !== void 0) {
|
|
11245
|
+
if (opts.auth.session.accountId) {
|
|
11246
|
+
opts.accountId = opts.auth.session.accountId;
|
|
11247
|
+
}
|
|
11248
|
+
}
|
|
11249
|
+
}
|
|
11250
|
+
return new DataEndpoint(opts);
|
|
11251
|
+
}
|
|
11252
|
+
EyePop2.dataEndpoint = dataEndpoint;
|
|
11253
|
+
function _fill_default_options(opts) {
|
|
11254
|
+
if (typeof opts.auth == "undefined") {
|
|
11255
|
+
if (typeof defaultAuth == "undefined") {
|
|
11256
|
+
throw new Error("auth option or EYEPOP_SECRET_KEY environment variable is required");
|
|
11257
|
+
}
|
|
11258
|
+
opts.auth = defaultAuth;
|
|
11259
|
+
}
|
|
11260
|
+
if (typeof opts.eyepopUrl == "undefined") {
|
|
11261
|
+
opts.eyepopUrl = readEnv("EYEPOP_URL") || "https://api.eyepop.ai";
|
|
11262
|
+
}
|
|
10456
11263
|
if (typeof opts.jobQueueLength == "undefined") {
|
|
10457
11264
|
opts.jobQueueLength = 1024;
|
|
10458
11265
|
}
|
|
10459
|
-
if (typeof opts.auth.oAuth2 != "undefined"
|
|
11266
|
+
if (typeof opts.auth.oAuth2 != "undefined") {
|
|
10460
11267
|
if (typeof opts.auth.oAuth2 === "boolean") {
|
|
10461
11268
|
if (opts.eyepopUrl.startsWith("https://staging-api.eyepop.ai")) {
|
|
10462
11269
|
opts.auth = {
|
|
@@ -10480,22 +11287,28 @@ var EyePop;
|
|
|
10480
11287
|
}
|
|
10481
11288
|
}
|
|
10482
11289
|
if (opts.auth.session !== void 0) {
|
|
10483
|
-
if (opts.auth.session.popId) {
|
|
10484
|
-
opts.popId = opts.auth.session.popId;
|
|
10485
|
-
}
|
|
10486
11290
|
if (opts.auth.session.eyepopUrl) {
|
|
10487
11291
|
opts.eyepopUrl = opts.auth.session.eyepopUrl;
|
|
10488
11292
|
}
|
|
10489
11293
|
}
|
|
10490
|
-
const endpoint2 = new Endpoint(opts);
|
|
10491
|
-
return endpoint2;
|
|
10492
11294
|
}
|
|
10493
|
-
EyePop2.endpoint = endpoint;
|
|
10494
11295
|
})(EyePop || (EyePop = {}));
|
|
10495
11296
|
var eyepop_default = EyePop;
|
|
10496
11297
|
export {
|
|
11298
|
+
AnnotationType,
|
|
11299
|
+
AssetStatus,
|
|
11300
|
+
ChangeType,
|
|
11301
|
+
DataEndpoint,
|
|
10497
11302
|
EndpointState,
|
|
10498
11303
|
EyePop,
|
|
11304
|
+
ModelFormat,
|
|
11305
|
+
ModelPrecisionType,
|
|
11306
|
+
ModelStatus,
|
|
11307
|
+
ModelType,
|
|
11308
|
+
TranscodeMode,
|
|
11309
|
+
TransientPopId,
|
|
11310
|
+
UserReview,
|
|
11311
|
+
WorkerEndpoint,
|
|
10499
11312
|
eyepop_default as default
|
|
10500
11313
|
};
|
|
10501
11314
|
/*! Bundled license information:
|