@eyepop.ai/eyepop 3.23.0 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eyepop.index.d.mts +292 -41
- package/dist/eyepop.index.d.ts +292 -41
- package/dist/eyepop.index.js +2222 -1331
- package/dist/eyepop.index.js.map +1 -1
- package/dist/eyepop.index.mjs +2211 -1331
- package/dist/eyepop.index.mjs.map +1 -1
- package/dist/eyepop.min.js +1 -1
- package/package.json +1 -1
package/dist/eyepop.index.js
CHANGED
|
@@ -8666,6 +8666,7 @@ __export(index_exports, {
|
|
|
8666
8666
|
AssetUrlType: () => AssetUrlType,
|
|
8667
8667
|
AutoAnnotateStatus: () => AutoAnnotateStatus,
|
|
8668
8668
|
AutoAnnotateTask: () => AutoAnnotateTask,
|
|
8669
|
+
COMBINED_UPLOAD_MAX_BYTES: () => COMBINED_UPLOAD_MAX_BYTES,
|
|
8669
8670
|
ChangeType: () => ChangeType,
|
|
8670
8671
|
ComputeAccountMismatchError: () => ComputeAccountMismatchError,
|
|
8671
8672
|
ComputeApiError: () => ComputeApiError,
|
|
@@ -8687,6 +8688,7 @@ __export(index_exports, {
|
|
|
8687
8688
|
LoadFromGroupJob: () => LoadFromGroupJob,
|
|
8688
8689
|
LoadFromJob: () => LoadFromJob,
|
|
8689
8690
|
LoadMediaStreamJob: () => LoadMediaStreamJob,
|
|
8691
|
+
MAX_OPEN_SOURCES: () => MAX_OPEN_SOURCES,
|
|
8690
8692
|
ModelExportStatus: () => ModelExportStatus,
|
|
8691
8693
|
ModelFormat: () => ModelFormat,
|
|
8692
8694
|
ModelPrecisionType: () => ModelPrecisionType,
|
|
@@ -8695,12 +8697,21 @@ __export(index_exports, {
|
|
|
8695
8697
|
ModelTrainingStage: () => ModelTrainingStage,
|
|
8696
8698
|
ModelType: () => ModelType,
|
|
8697
8699
|
MotionModel: () => MotionModel,
|
|
8700
|
+
PIPELINE_PATH: () => PIPELINE_PATH,
|
|
8701
|
+
PipelineBackend: () => PipelineBackend,
|
|
8702
|
+
PipelineCommandError: () => PipelineCommandError,
|
|
8703
|
+
PipelineConfigurationError: () => PipelineConfigurationError,
|
|
8704
|
+
PipelineJob: () => PipelineJob,
|
|
8705
|
+
PipelineSocketClosedError: () => PipelineSocketClosedError,
|
|
8706
|
+
PipelineSourceError: () => PipelineSourceError,
|
|
8698
8707
|
PointCloud: () => PointCloud,
|
|
8699
8708
|
PopComponentType: () => PopComponentType,
|
|
8700
8709
|
PredictionVersion: () => PredictionVersion,
|
|
8701
8710
|
QUATERNION_TOLERANCE: () => QUATERNION_TOLERANCE,
|
|
8711
|
+
SUBPROTOCOL: () => SUBPROTOCOL,
|
|
8702
8712
|
SelectMode: () => SelectMode,
|
|
8703
8713
|
Semaphore: () => Semaphore,
|
|
8714
|
+
SessionBackend: () => SessionBackend,
|
|
8704
8715
|
Stream: () => Stream,
|
|
8705
8716
|
TaskMode: () => TaskMode,
|
|
8706
8717
|
TaskType: () => TaskType,
|
|
@@ -8770,6 +8781,667 @@ function accessTokenCredential(auth) {
|
|
|
8770
8781
|
return nonEmptyCredential(auth.accessToken);
|
|
8771
8782
|
}
|
|
8772
8783
|
|
|
8784
|
+
// types.ts
|
|
8785
|
+
var EndpointState = /* @__PURE__ */ ((EndpointState2) => {
|
|
8786
|
+
EndpointState2["Idle"] = "Idle";
|
|
8787
|
+
EndpointState2["Busy"] = "Busy";
|
|
8788
|
+
EndpointState2["Authenticating"] = "Authenticating";
|
|
8789
|
+
EndpointState2["FetchConfig"] = "FetchConfig";
|
|
8790
|
+
EndpointState2["Error"] = "Error";
|
|
8791
|
+
EndpointState2["NotAvailable"] = "NotAvailable";
|
|
8792
|
+
return EndpointState2;
|
|
8793
|
+
})(EndpointState || {});
|
|
8794
|
+
|
|
8795
|
+
// shims/http_client.ts
|
|
8796
|
+
var createHttpClient;
|
|
8797
|
+
function logLineFromRequest(input, init) {
|
|
8798
|
+
const url = input instanceof Request ? input.url : input;
|
|
8799
|
+
const method = input instanceof Request ? input.method : init?.method || (init?.body !== void 0 ? "POST" : "GET");
|
|
8800
|
+
return `${method} ${url}`;
|
|
8801
|
+
}
|
|
8802
|
+
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
8803
|
+
class BrowserHttpClient {
|
|
8804
|
+
constructor(logger) {
|
|
8805
|
+
this._logger = logger;
|
|
8806
|
+
}
|
|
8807
|
+
async fetch(input, init) {
|
|
8808
|
+
const logLine = logLineFromRequest(input, init);
|
|
8809
|
+
this._logger.debug(`Browser fetch() BEFORE ${logLine}`);
|
|
8810
|
+
const response = await fetch(input, init);
|
|
8811
|
+
this._logger.debug(`AFTER ${logLine} -> ${response.status}`);
|
|
8812
|
+
return response;
|
|
8813
|
+
}
|
|
8814
|
+
async close() {
|
|
8815
|
+
}
|
|
8816
|
+
isFullDuplex() {
|
|
8817
|
+
return false;
|
|
8818
|
+
}
|
|
8819
|
+
}
|
|
8820
|
+
createHttpClient = async (logger) => {
|
|
8821
|
+
return new BrowserHttpClient(logger);
|
|
8822
|
+
};
|
|
8823
|
+
} else {
|
|
8824
|
+
class NodeHttpClient {
|
|
8825
|
+
constructor(agent, fetchFn, logger) {
|
|
8826
|
+
this._agent = agent;
|
|
8827
|
+
this._fetch = fetchFn;
|
|
8828
|
+
this._logger = logger;
|
|
8829
|
+
}
|
|
8830
|
+
async fetch(input, init) {
|
|
8831
|
+
init || (init = {});
|
|
8832
|
+
init.dispatcher = this._agent;
|
|
8833
|
+
const logLine = logLineFromRequest(input, init);
|
|
8834
|
+
this._logger.debug(`Node fetch() BEFORE ${logLine}`);
|
|
8835
|
+
const response = await this._fetch(input, init);
|
|
8836
|
+
this._logger.debug(`AFTER ${logLine} -> ${response.status}`);
|
|
8837
|
+
return response;
|
|
8838
|
+
}
|
|
8839
|
+
async close() {
|
|
8840
|
+
return this._agent.close();
|
|
8841
|
+
}
|
|
8842
|
+
isFullDuplex() {
|
|
8843
|
+
return false;
|
|
8844
|
+
}
|
|
8845
|
+
}
|
|
8846
|
+
createHttpClient = async (logger) => {
|
|
8847
|
+
const undici = require("undici");
|
|
8848
|
+
const agent = new undici.Agent({
|
|
8849
|
+
keepAliveTimeout: 1e4,
|
|
8850
|
+
connections: 5,
|
|
8851
|
+
// two parallel streaming requests to the same host seem to deadlock with pipelining > 0
|
|
8852
|
+
pipelining: 0
|
|
8853
|
+
});
|
|
8854
|
+
logger.debug("Using node fetch with undici agent as http client");
|
|
8855
|
+
return new NodeHttpClient(agent, undici.fetch, logger);
|
|
8856
|
+
};
|
|
8857
|
+
}
|
|
8858
|
+
|
|
8859
|
+
// semaphore.ts
|
|
8860
|
+
var Semaphore = class {
|
|
8861
|
+
/**
|
|
8862
|
+
* Creates a semaphore.
|
|
8863
|
+
* @param permits The number of permits, i.e. strands of execution being allowed
|
|
8864
|
+
* to run in parallel.
|
|
8865
|
+
* This number can be initialized with a negative integer.
|
|
8866
|
+
*/
|
|
8867
|
+
constructor(permits) {
|
|
8868
|
+
this.promiseResolverQueue = [];
|
|
8869
|
+
this.permits = permits;
|
|
8870
|
+
}
|
|
8871
|
+
/**
|
|
8872
|
+
* Returns the number of available permits.
|
|
8873
|
+
* @returns The number of available permits.
|
|
8874
|
+
*/
|
|
8875
|
+
getPermits() {
|
|
8876
|
+
return this.permits;
|
|
8877
|
+
}
|
|
8878
|
+
/**
|
|
8879
|
+
* Returns a promise used to wait for a permit to become available. This method should be awaited on.
|
|
8880
|
+
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
8881
|
+
*/
|
|
8882
|
+
async wait() {
|
|
8883
|
+
if (this.permits > 0) {
|
|
8884
|
+
this.permits -= 1;
|
|
8885
|
+
return Promise.resolve(true);
|
|
8886
|
+
}
|
|
8887
|
+
return new Promise((resolver) => this.promiseResolverQueue.push(resolver));
|
|
8888
|
+
}
|
|
8889
|
+
/**
|
|
8890
|
+
* Alias for {@linkcode Semaphore.wait}.
|
|
8891
|
+
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
8892
|
+
*/
|
|
8893
|
+
async acquire() {
|
|
8894
|
+
return this.wait();
|
|
8895
|
+
}
|
|
8896
|
+
/**
|
|
8897
|
+
* Same as {@linkcode Semaphore.wait} except the promise returned gets resolved with false if no
|
|
8898
|
+
* permit becomes available in time.
|
|
8899
|
+
* @param milliseconds The time spent waiting before the wait is aborted. This is a lower bound,
|
|
8900
|
+
* you shouldn't rely on it being precise.
|
|
8901
|
+
* @returns A promise that gets resolved to true when execution is allowed to proceed or
|
|
8902
|
+
* false if the time given elapses before a permit becomes available.
|
|
8903
|
+
*/
|
|
8904
|
+
async waitFor(milliseconds) {
|
|
8905
|
+
if (this.permits > 0) {
|
|
8906
|
+
this.permits -= 1;
|
|
8907
|
+
return Promise.resolve(true);
|
|
8908
|
+
}
|
|
8909
|
+
let resolver = (_) => void 0;
|
|
8910
|
+
const promise = new Promise((r) => {
|
|
8911
|
+
resolver = r;
|
|
8912
|
+
});
|
|
8913
|
+
this.promiseResolverQueue.push(resolver);
|
|
8914
|
+
setTimeout(() => {
|
|
8915
|
+
const index = this.promiseResolverQueue.indexOf(resolver);
|
|
8916
|
+
if (index !== -1) {
|
|
8917
|
+
this.promiseResolverQueue.splice(index, 1);
|
|
8918
|
+
} else {
|
|
8919
|
+
console.warn(`Semaphore.waitFor couldn't find its promise resolver in the queue`);
|
|
8920
|
+
}
|
|
8921
|
+
resolver(false);
|
|
8922
|
+
}, milliseconds);
|
|
8923
|
+
return promise;
|
|
8924
|
+
}
|
|
8925
|
+
/**
|
|
8926
|
+
* Synchronous function that tries to acquire a permit and returns true if successful, false otherwise.
|
|
8927
|
+
* @returns Whether a permit could be acquired.
|
|
8928
|
+
*/
|
|
8929
|
+
tryAcquire() {
|
|
8930
|
+
if (this.permits > 0) {
|
|
8931
|
+
this.permits -= 1;
|
|
8932
|
+
return true;
|
|
8933
|
+
}
|
|
8934
|
+
return false;
|
|
8935
|
+
}
|
|
8936
|
+
/**
|
|
8937
|
+
* Acquires all permits that are currently available and returns the number of acquired permits.
|
|
8938
|
+
* @returns Number of acquired permits.
|
|
8939
|
+
*/
|
|
8940
|
+
drainPermits() {
|
|
8941
|
+
if (this.permits > 0) {
|
|
8942
|
+
const permitCount = this.permits;
|
|
8943
|
+
this.permits = 0;
|
|
8944
|
+
return permitCount;
|
|
8945
|
+
}
|
|
8946
|
+
return 0;
|
|
8947
|
+
}
|
|
8948
|
+
/**
|
|
8949
|
+
* Increases the number of permits by one. If there are other functions waiting, one of them will
|
|
8950
|
+
* continue to execute in a future iteration of the event loop.
|
|
8951
|
+
*/
|
|
8952
|
+
signal() {
|
|
8953
|
+
this.permits += 1;
|
|
8954
|
+
if (this.permits > 1 && this.promiseResolverQueue.length > 0) {
|
|
8955
|
+
console.warn("Semaphore.permits should never be > 0 when there is someone waiting.");
|
|
8956
|
+
} else if (this.permits === 1 && this.promiseResolverQueue.length > 0) {
|
|
8957
|
+
this.permits -= 1;
|
|
8958
|
+
const nextResolver = this.promiseResolverQueue.shift();
|
|
8959
|
+
if (nextResolver) {
|
|
8960
|
+
nextResolver(true);
|
|
8961
|
+
}
|
|
8962
|
+
}
|
|
8963
|
+
}
|
|
8964
|
+
/**
|
|
8965
|
+
* Alias for {@linkcode Semaphore.signal}.
|
|
8966
|
+
*/
|
|
8967
|
+
release() {
|
|
8968
|
+
this.signal();
|
|
8969
|
+
}
|
|
8970
|
+
/**
|
|
8971
|
+
* Schedules func to be called once a permit becomes available.
|
|
8972
|
+
* Returns a promise that resolves to the return value of func.
|
|
8973
|
+
* @typeparam T The return type of func.
|
|
8974
|
+
* @param func The function to be executed.
|
|
8975
|
+
* @return A promise that gets resolved with the return value of the function.
|
|
8976
|
+
*/
|
|
8977
|
+
async execute(func) {
|
|
8978
|
+
await this.wait();
|
|
8979
|
+
try {
|
|
8980
|
+
return await func();
|
|
8981
|
+
} finally {
|
|
8982
|
+
this.signal();
|
|
8983
|
+
}
|
|
8984
|
+
}
|
|
8985
|
+
};
|
|
8986
|
+
|
|
8987
|
+
// endpoint.ts
|
|
8988
|
+
var import_pino = require("pino");
|
|
8989
|
+
|
|
8990
|
+
// shims/browser_session.ts
|
|
8991
|
+
var import_auth0_spa_js = require("@auth0/auth0-spa-js");
|
|
8992
|
+
var authenticateBrowserSession;
|
|
8993
|
+
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
8994
|
+
authenticateBrowserSession = async (auth0, options) => {
|
|
8995
|
+
if (options.eyepopUrl == null) {
|
|
8996
|
+
return Promise.reject("options.eyepopUrl cannot be null");
|
|
8997
|
+
}
|
|
8998
|
+
const auth0ClientOptions = {
|
|
8999
|
+
clientId: auth0.clientId,
|
|
9000
|
+
domain: auth0.domain,
|
|
9001
|
+
authorizationParams: {
|
|
9002
|
+
scope: auth0.scope,
|
|
9003
|
+
audience: auth0.audience
|
|
9004
|
+
}
|
|
9005
|
+
};
|
|
9006
|
+
const auth0Client = await (0, import_auth0_spa_js.createAuth0Client)(auth0ClientOptions);
|
|
9007
|
+
if (!await auth0Client.isAuthenticated()) {
|
|
9008
|
+
await auth0Client.loginWithPopup();
|
|
9009
|
+
}
|
|
9010
|
+
const accessToken = await auth0Client.getTokenSilently();
|
|
9011
|
+
if (!accessToken) {
|
|
9012
|
+
return Promise.reject("auth0 login failed");
|
|
9013
|
+
}
|
|
9014
|
+
let session;
|
|
9015
|
+
const workerOptions = options;
|
|
9016
|
+
if (typeof workerOptions.popId != "undefined") {
|
|
9017
|
+
const workerSession = {
|
|
9018
|
+
eyepopUrl: options.eyepopUrl,
|
|
9019
|
+
accessToken,
|
|
9020
|
+
validUntil: Date.now() + 60 * 60 * 1e3,
|
|
9021
|
+
popId: workerOptions.popId,
|
|
9022
|
+
baseUrl: void 0,
|
|
9023
|
+
pipelineId: void 0,
|
|
9024
|
+
isPipelineMode: workerOptions.isPipelineMode,
|
|
9025
|
+
authenticationHeaders: () => {
|
|
9026
|
+
return { Authorization: `Bearer ${accessToken}` };
|
|
9027
|
+
}
|
|
9028
|
+
};
|
|
9029
|
+
session = workerSession;
|
|
9030
|
+
} else {
|
|
9031
|
+
session = {
|
|
9032
|
+
eyepopUrl: options.eyepopUrl,
|
|
9033
|
+
accessToken,
|
|
9034
|
+
validUntil: Date.now() + 60 * 60 * 1e3
|
|
9035
|
+
};
|
|
9036
|
+
}
|
|
9037
|
+
return session;
|
|
9038
|
+
};
|
|
9039
|
+
} else {
|
|
9040
|
+
authenticateBrowserSession = (_auth0, _options) => {
|
|
9041
|
+
return Promise.reject("auth0 login not supported server-side");
|
|
9042
|
+
};
|
|
9043
|
+
}
|
|
9044
|
+
|
|
9045
|
+
// endpoint.ts
|
|
9046
|
+
var Endpoint = class {
|
|
9047
|
+
constructor(options) {
|
|
9048
|
+
this._options = options;
|
|
9049
|
+
this._token = null;
|
|
9050
|
+
this._expire_token_time = null;
|
|
9051
|
+
this._client = null;
|
|
9052
|
+
this._statusRetryHandlers = /* @__PURE__ */ new Map();
|
|
9053
|
+
this._statusRetryHandlers.set(401, this.statusHandler401);
|
|
9054
|
+
this._limit = new Semaphore(this._options.jobQueueLength ?? 1024);
|
|
9055
|
+
this._state = "Idle" /* Idle */;
|
|
9056
|
+
this._message = null;
|
|
9057
|
+
this._stateChangeHandler = null;
|
|
9058
|
+
let rootLogger;
|
|
9059
|
+
if (options.logger) {
|
|
9060
|
+
rootLogger = options.logger;
|
|
9061
|
+
} else {
|
|
9062
|
+
rootLogger = (0, import_pino.pino)();
|
|
9063
|
+
}
|
|
9064
|
+
this._logger = rootLogger.child({ module: "eyepop" });
|
|
9065
|
+
this._requestLogger = this._logger.child({ module: "requests" });
|
|
9066
|
+
}
|
|
9067
|
+
setStatusRetryHandlers(statusRetryHandlers = void 0) {
|
|
9068
|
+
this._statusRetryHandlers = new Map(statusRetryHandlers);
|
|
9069
|
+
this._statusRetryHandlers.set(401, this.statusHandler401);
|
|
9070
|
+
}
|
|
9071
|
+
eyepopUrl() {
|
|
9072
|
+
if (this._options.eyepopUrl) {
|
|
9073
|
+
return this._options.eyepopUrl.replace(/\/+$/, "");
|
|
9074
|
+
} else {
|
|
9075
|
+
return "https://compute.eyepop.ai";
|
|
9076
|
+
}
|
|
9077
|
+
}
|
|
9078
|
+
// TODO: deprecated Web API endpoint needed for POP_ID support
|
|
9079
|
+
eyepopWebApiUrl() {
|
|
9080
|
+
if (this._options.eyepopUrl) {
|
|
9081
|
+
return this._options.eyepopUrl.replace(/\/+$/, "").replace(/compute\./, "web-api.");
|
|
9082
|
+
} else {
|
|
9083
|
+
return "https://api.eyepop.ai";
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
pendingJobs() {
|
|
9087
|
+
return (this._options.jobQueueLength ?? 1024) - this._limit.getPermits();
|
|
9088
|
+
}
|
|
9089
|
+
state() {
|
|
9090
|
+
return this._state;
|
|
9091
|
+
}
|
|
9092
|
+
lastMessage() {
|
|
9093
|
+
return this._message;
|
|
9094
|
+
}
|
|
9095
|
+
onStateChanged(handler) {
|
|
9096
|
+
this._stateChangeHandler = handler;
|
|
9097
|
+
return this;
|
|
9098
|
+
}
|
|
9099
|
+
updateState(newState = void 0, message = void 0) {
|
|
9100
|
+
const fromState = this._state;
|
|
9101
|
+
if (newState == void 0) {
|
|
9102
|
+
if (this._limit.getPermits() == this._options.jobQueueLength) {
|
|
9103
|
+
newState = "Idle" /* Idle */;
|
|
9104
|
+
} else {
|
|
9105
|
+
newState = "Busy" /* Busy */;
|
|
9106
|
+
}
|
|
9107
|
+
}
|
|
9108
|
+
this._state = newState;
|
|
9109
|
+
this._message = message ? message : null;
|
|
9110
|
+
if (this._stateChangeHandler) {
|
|
9111
|
+
this._stateChangeHandler(fromState, this._state);
|
|
9112
|
+
}
|
|
9113
|
+
}
|
|
9114
|
+
async connect() {
|
|
9115
|
+
if (this._client) {
|
|
9116
|
+
this._logger.warn("endpoint already connected");
|
|
9117
|
+
return this;
|
|
9118
|
+
}
|
|
9119
|
+
if (!this._options.eyepopUrl) {
|
|
9120
|
+
return Promise.reject("option eyepopUrl or environment variable EYEPOP_URL is required");
|
|
9121
|
+
}
|
|
9122
|
+
const auth = resolveAuth(this._options);
|
|
9123
|
+
if (auth === void 0) {
|
|
9124
|
+
return Promise.reject("cannot connect without defined auth option");
|
|
9125
|
+
}
|
|
9126
|
+
if (auth.session !== void 0) {
|
|
9127
|
+
this._token = auth.session.accessToken;
|
|
9128
|
+
this._expire_token_time = auth.session.validUntil / 1e3;
|
|
9129
|
+
} else if (auth.oAuth2 !== void 0) {
|
|
9130
|
+
} else if (accessTokenCredential(auth) !== void 0) {
|
|
9131
|
+
} else if (apiKeyCredential(auth) !== void 0) {
|
|
9132
|
+
} else if (auth.isLocal !== void 0) {
|
|
9133
|
+
} else {
|
|
9134
|
+
return Promise.reject("option apiKey/accessToken or environment variable EYEPOP_API_KEY is required");
|
|
9135
|
+
}
|
|
9136
|
+
if (this._options.platformSupport?.createHttpClient !== void 0) {
|
|
9137
|
+
this._client = await this._options.platformSupport.createHttpClient(this._requestLogger);
|
|
9138
|
+
} else {
|
|
9139
|
+
this._client = await createHttpClient(this._requestLogger);
|
|
9140
|
+
}
|
|
9141
|
+
return await this.reconnect();
|
|
9142
|
+
}
|
|
9143
|
+
async disconnect(wait = true) {
|
|
9144
|
+
if (wait && this._limit) {
|
|
9145
|
+
for (let j = 0; j < this._options.jobQueueLength; j++) {
|
|
9146
|
+
await this._limit.acquire();
|
|
9147
|
+
}
|
|
9148
|
+
}
|
|
9149
|
+
this._limit = new Semaphore(this._options.jobQueueLength ?? 1024);
|
|
9150
|
+
if (this._client) {
|
|
9151
|
+
await this._client.close();
|
|
9152
|
+
this._client = null;
|
|
9153
|
+
}
|
|
9154
|
+
}
|
|
9155
|
+
async session() {
|
|
9156
|
+
await this.currentAccessToken();
|
|
9157
|
+
if (this._token == null || this._expire_token_time == null) {
|
|
9158
|
+
return Promise.reject("endpoint not connected");
|
|
9159
|
+
}
|
|
9160
|
+
return {
|
|
9161
|
+
eyepopUrl: this._options.eyepopUrl,
|
|
9162
|
+
accessToken: this._token,
|
|
9163
|
+
validUntil: this._expire_token_time * 1e3
|
|
9164
|
+
};
|
|
9165
|
+
}
|
|
9166
|
+
statusHandler401(_statusCode) {
|
|
9167
|
+
this._token = null;
|
|
9168
|
+
this._expire_token_time = null;
|
|
9169
|
+
}
|
|
9170
|
+
async fetchWithRetry(fetcher, retries = 1) {
|
|
9171
|
+
while (true) {
|
|
9172
|
+
try {
|
|
9173
|
+
const response = await fetcher();
|
|
9174
|
+
if (response.ok) {
|
|
9175
|
+
return response;
|
|
9176
|
+
} else {
|
|
9177
|
+
const handler = this._statusRetryHandlers.get(response.status);
|
|
9178
|
+
if (handler != null) {
|
|
9179
|
+
handler(response.status);
|
|
9180
|
+
if (retries--) {
|
|
9181
|
+
this._requestLogger.info("received %d response, retry", response.status);
|
|
9182
|
+
} else {
|
|
9183
|
+
return response;
|
|
9184
|
+
}
|
|
9185
|
+
} else {
|
|
9186
|
+
return response;
|
|
9187
|
+
}
|
|
9188
|
+
}
|
|
9189
|
+
} catch (error) {
|
|
9190
|
+
const handler = this._statusRetryHandlers.get(404);
|
|
9191
|
+
if (handler != null) {
|
|
9192
|
+
handler(error);
|
|
9193
|
+
if (retries--) {
|
|
9194
|
+
this._requestLogger.info("error %s, retry", error);
|
|
9195
|
+
} else {
|
|
9196
|
+
return Promise.reject(`error ${error}`);
|
|
9197
|
+
}
|
|
9198
|
+
} else {
|
|
9199
|
+
return Promise.reject(`error ${error}`);
|
|
9200
|
+
}
|
|
9201
|
+
}
|
|
9202
|
+
}
|
|
9203
|
+
}
|
|
9204
|
+
async reconnect() {
|
|
9205
|
+
throw new Error("reconnect() not implemented");
|
|
9206
|
+
}
|
|
9207
|
+
async authorizationHeader() {
|
|
9208
|
+
if (resolveAuth(this._options)?.isLocal !== void 0) {
|
|
9209
|
+
return `Implicit`;
|
|
9210
|
+
}
|
|
9211
|
+
return `Bearer ${await this.currentAccessToken()}`;
|
|
9212
|
+
}
|
|
9213
|
+
async currentAccessToken() {
|
|
9214
|
+
const now = Date.now() / 1e3;
|
|
9215
|
+
if (!this._token || this._expire_token_time < now) {
|
|
9216
|
+
this.updateState("Authenticating" /* Authenticating */);
|
|
9217
|
+
try {
|
|
9218
|
+
const auth = resolveAuth(this._options);
|
|
9219
|
+
if (!this._client) {
|
|
9220
|
+
return Promise.reject("endpoint not connected");
|
|
9221
|
+
} else if (auth?.isLocal !== void 0) {
|
|
9222
|
+
this._token = "implicit";
|
|
9223
|
+
this._expire_token_time = Number.MAX_VALUE;
|
|
9224
|
+
} else if (auth?.session !== void 0) {
|
|
9225
|
+
return Promise.reject("temporary access token expired");
|
|
9226
|
+
} else if (auth?.oAuth2 !== void 0 && this._options.eyepopUrl) {
|
|
9227
|
+
const session = await authenticateBrowserSession(auth.oAuth2, this._options);
|
|
9228
|
+
this._token = session.accessToken;
|
|
9229
|
+
this._expire_token_time = session.validUntil / 1e3;
|
|
9230
|
+
} else if (accessTokenCredential(auth) !== void 0) {
|
|
9231
|
+
this._token = accessTokenCredential(auth);
|
|
9232
|
+
this._expire_token_time = Number.MAX_VALUE;
|
|
9233
|
+
} else if (this._options.eyepopUrl) {
|
|
9234
|
+
const credential = apiKeyCredential(auth);
|
|
9235
|
+
if (credential === void 0) {
|
|
9236
|
+
return Promise.reject("no valid auth option");
|
|
9237
|
+
}
|
|
9238
|
+
const headers = { Authorization: `Bearer ${credential}` };
|
|
9239
|
+
const post_url = `${this.eyepopUrl()}/v1/auth/authenticate`;
|
|
9240
|
+
const response = await this._client.fetch(post_url, {
|
|
9241
|
+
method: "POST",
|
|
9242
|
+
headers
|
|
9243
|
+
});
|
|
9244
|
+
if (response.status != 200) {
|
|
9245
|
+
const message = await response.text();
|
|
9246
|
+
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
9247
|
+
}
|
|
9248
|
+
const data = await response.json();
|
|
9249
|
+
const token = data;
|
|
9250
|
+
this._token = token.access_token;
|
|
9251
|
+
this._expire_token_time = now + token.expires_in - 60;
|
|
9252
|
+
} else {
|
|
9253
|
+
return Promise.reject("no valid auth option");
|
|
9254
|
+
}
|
|
9255
|
+
} finally {
|
|
9256
|
+
this.updateState();
|
|
9257
|
+
}
|
|
9258
|
+
}
|
|
9259
|
+
this._logger.debug("using access token, valid for at least %d seconds", this._expire_token_time - now);
|
|
9260
|
+
return this._token;
|
|
9261
|
+
}
|
|
9262
|
+
};
|
|
9263
|
+
|
|
9264
|
+
// camera.ts
|
|
9265
|
+
var QUATERNION_TOLERANCE = 1e-3;
|
|
9266
|
+
function isFinite_(value) {
|
|
9267
|
+
return value === void 0 || Number.isFinite(value);
|
|
9268
|
+
}
|
|
9269
|
+
function validateCamera(camera) {
|
|
9270
|
+
if (camera.intrinsics !== void 0 && camera.hfovDegrees !== void 0) {
|
|
9271
|
+
throw new Error("camera.intrinsics and camera.hfovDegrees are alternatives, supply one");
|
|
9272
|
+
}
|
|
9273
|
+
if (camera.intrinsics === void 0 && camera.hfovDegrees === void 0) {
|
|
9274
|
+
throw new Error("camera requires either camera.intrinsics or camera.hfovDegrees");
|
|
9275
|
+
}
|
|
9276
|
+
if (camera.hfovDegrees !== void 0) {
|
|
9277
|
+
if (!(camera.hfovDegrees > 0 && camera.hfovDegrees < 180)) {
|
|
9278
|
+
throw new Error("camera.hfovDegrees must be a horizontal field of view in (0, 180) degrees");
|
|
9279
|
+
}
|
|
9280
|
+
} else {
|
|
9281
|
+
const intrinsics = camera.intrinsics;
|
|
9282
|
+
for (const [name, focal] of [
|
|
9283
|
+
["fx", intrinsics.fx],
|
|
9284
|
+
["fy", intrinsics.fy]
|
|
9285
|
+
]) {
|
|
9286
|
+
if (!(focal > 0) || !Number.isFinite(focal)) {
|
|
9287
|
+
throw new Error(`camera.intrinsics.${name} must be a positive, finite focal length`);
|
|
9288
|
+
}
|
|
9289
|
+
}
|
|
9290
|
+
for (const [name, principal, extent] of [
|
|
9291
|
+
["cx", intrinsics.cx, "width"],
|
|
9292
|
+
["cy", intrinsics.cy, "height"]
|
|
9293
|
+
]) {
|
|
9294
|
+
if (!(principal >= 0 && principal <= 1)) {
|
|
9295
|
+
throw new Error(`camera.intrinsics.${name} must be within [0, 1] of the frame ${extent}`);
|
|
9296
|
+
}
|
|
9297
|
+
}
|
|
9298
|
+
}
|
|
9299
|
+
if (camera.distortion !== void 0) {
|
|
9300
|
+
for (const name of ["k1", "k2", "p1", "p2", "k3"]) {
|
|
9301
|
+
if (!isFinite_(camera.distortion[name])) {
|
|
9302
|
+
throw new Error(`camera.distortion.${name} must be a finite number`);
|
|
9303
|
+
}
|
|
9304
|
+
}
|
|
9305
|
+
}
|
|
9306
|
+
if (camera.extrinsics !== void 0) {
|
|
9307
|
+
const translation = camera.extrinsics.translation;
|
|
9308
|
+
if (translation !== void 0) {
|
|
9309
|
+
for (const axis of ["x", "y", "z"]) {
|
|
9310
|
+
if (!Number.isFinite(translation[axis])) {
|
|
9311
|
+
throw new Error(`camera.extrinsics.translation.${axis} must be a finite number`);
|
|
9312
|
+
}
|
|
9313
|
+
}
|
|
9314
|
+
}
|
|
9315
|
+
const rotation = camera.extrinsics.rotation;
|
|
9316
|
+
if (rotation !== void 0) {
|
|
9317
|
+
const norm = Math.sqrt(rotation.w ** 2 + rotation.x ** 2 + rotation.y ** 2 + rotation.z ** 2);
|
|
9318
|
+
if (!(Math.abs(norm - 1) <= QUATERNION_TOLERANCE)) {
|
|
9319
|
+
throw new Error("camera.extrinsics.rotation must be a unit quaternion");
|
|
9320
|
+
}
|
|
9321
|
+
}
|
|
9322
|
+
}
|
|
9323
|
+
}
|
|
9324
|
+
|
|
9325
|
+
// worker/worker_types.ts
|
|
9326
|
+
var PredictionVersion = /* @__PURE__ */ ((PredictionVersion3) => {
|
|
9327
|
+
PredictionVersion3[PredictionVersion3["V1"] = 1] = "V1";
|
|
9328
|
+
PredictionVersion3[PredictionVersion3["V2"] = 2] = "V2";
|
|
9329
|
+
PredictionVersion3[PredictionVersion3["V3"] = 3] = "V3";
|
|
9330
|
+
return PredictionVersion3;
|
|
9331
|
+
})(PredictionVersion || {});
|
|
9332
|
+
var DEFAULT_PREDICTION_VERSION = 2 /* V2 */;
|
|
9333
|
+
var VideoMode = /* @__PURE__ */ ((VideoMode2) => {
|
|
9334
|
+
VideoMode2["STREAM"] = "stream";
|
|
9335
|
+
VideoMode2["BUFFER"] = "buffer";
|
|
9336
|
+
return VideoMode2;
|
|
9337
|
+
})(VideoMode || {});
|
|
9338
|
+
var PopComponentType = /* @__PURE__ */ ((PopComponentType2) => {
|
|
9339
|
+
PopComponentType2["FORWARD"] = "forward";
|
|
9340
|
+
PopComponentType2["INFERENCE"] = "inference";
|
|
9341
|
+
PopComponentType2["TRACKING"] = "tracking";
|
|
9342
|
+
PopComponentType2["CONTOUR_FINDER"] = "contour_finder";
|
|
9343
|
+
PopComponentType2["COMPONENT_FINDER"] = "component_finder";
|
|
9344
|
+
return PopComponentType2;
|
|
9345
|
+
})(PopComponentType || {});
|
|
9346
|
+
var ForwardOperatorType = /* @__PURE__ */ ((ForwardOperatorType2) => {
|
|
9347
|
+
ForwardOperatorType2["FULL"] = "full";
|
|
9348
|
+
ForwardOperatorType2["CROP"] = "crop";
|
|
9349
|
+
ForwardOperatorType2["CROP_WITH_FULL_FALLBACK"] = "crop_with_full_fallback";
|
|
9350
|
+
ForwardOperatorType2["SELECT_CROP"] = "select_crop";
|
|
9351
|
+
ForwardOperatorType2["SELECT_FULL"] = "select_full";
|
|
9352
|
+
return ForwardOperatorType2;
|
|
9353
|
+
})(ForwardOperatorType || {});
|
|
9354
|
+
var SelectMode = /* @__PURE__ */ ((SelectMode2) => {
|
|
9355
|
+
SelectMode2["MOST_RELEVANT"] = "most_relevant";
|
|
9356
|
+
return SelectMode2;
|
|
9357
|
+
})(SelectMode || {});
|
|
9358
|
+
function isSelectOperator(operator) {
|
|
9359
|
+
return operator?.type === "select_crop" /* SELECT_CROP */ || operator?.type === "select_full" /* SELECT_FULL */;
|
|
9360
|
+
}
|
|
9361
|
+
var InferenceType = /* @__PURE__ */ ((InferenceType2) => {
|
|
9362
|
+
InferenceType2["IMAGE_CLASSIFICATION"] = "image_classification";
|
|
9363
|
+
InferenceType2["OBJECT_DETECTION"] = "object_detection";
|
|
9364
|
+
InferenceType2["KEY_POINTS"] = "key_points";
|
|
9365
|
+
InferenceType2["OCR"] = "ocr";
|
|
9366
|
+
InferenceType2["MESH"] = "mesh";
|
|
9367
|
+
InferenceType2["FEATURE_VECTOR"] = "feature_vector";
|
|
9368
|
+
InferenceType2["SEMANTIC_SEGMENTATION"] = "semantic_segmentation";
|
|
9369
|
+
InferenceType2["SEGMENTATION"] = "segmentation";
|
|
9370
|
+
return InferenceType2;
|
|
9371
|
+
})(InferenceType || {});
|
|
9372
|
+
var MotionModel = /* @__PURE__ */ ((MotionModel2) => {
|
|
9373
|
+
MotionModel2["RANDOM_WALK"] = "random_walk";
|
|
9374
|
+
MotionModel2["CONSTANT_VELOCITY"] = "constant_velocity";
|
|
9375
|
+
MotionModel2["CONSTANT_ACCELERATION"] = "constant_acceleration";
|
|
9376
|
+
return MotionModel2;
|
|
9377
|
+
})(MotionModel || {});
|
|
9378
|
+
var ContourType = /* @__PURE__ */ ((ContourType2) => {
|
|
9379
|
+
ContourType2["ALL_PIXELS"] = "all_pixels";
|
|
9380
|
+
ContourType2["POLYGON"] = "polygon";
|
|
9381
|
+
ContourType2["CONVEX_HULL"] = "convex_hull";
|
|
9382
|
+
ContourType2["HOUGH_CIRCLES"] = "hough_circles";
|
|
9383
|
+
ContourType2["CIRCLE"] = "circle";
|
|
9384
|
+
ContourType2["TRIANGLE"] = "triangle";
|
|
9385
|
+
ContourType2["RECTANGLE"] = "rectangle";
|
|
9386
|
+
return ContourType2;
|
|
9387
|
+
})(ContourType || {});
|
|
9388
|
+
function validatePop(pop) {
|
|
9389
|
+
if (pop.depthMap !== void 0) {
|
|
9390
|
+
if (pop.depthMap.ability === void 0 === (pop.depthMap.abilityUuid === void 0)) {
|
|
9391
|
+
throw new Error("depthMap requires exactly one of ability or abilityUuid");
|
|
9392
|
+
}
|
|
9393
|
+
}
|
|
9394
|
+
if (pop.defaults?.camera !== void 0) {
|
|
9395
|
+
validateCamera(pop.defaults.camera);
|
|
9396
|
+
}
|
|
9397
|
+
validateForwards(pop.components);
|
|
9398
|
+
}
|
|
9399
|
+
function popSelects(pop) {
|
|
9400
|
+
const selects = (components) => (components ?? []).some((component) => isSelectOperator(component.forward?.operator) || selects(component.forward?.targets));
|
|
9401
|
+
return selects(pop?.components);
|
|
9402
|
+
}
|
|
9403
|
+
function validateForwards(components) {
|
|
9404
|
+
for (const component of components ?? []) {
|
|
9405
|
+
const operator = component.forward?.operator;
|
|
9406
|
+
if (operator !== void 0) {
|
|
9407
|
+
validateSelectOperator(operator);
|
|
9408
|
+
}
|
|
9409
|
+
validateForwards(component.forward?.targets);
|
|
9410
|
+
}
|
|
9411
|
+
}
|
|
9412
|
+
function validateSelectOperator(operator) {
|
|
9413
|
+
if (!isSelectOperator(operator)) {
|
|
9414
|
+
if (operator.select !== void 0) {
|
|
9415
|
+
throw new Error("select is only valid with the select_crop or select_full operator");
|
|
9416
|
+
}
|
|
9417
|
+
return;
|
|
9418
|
+
}
|
|
9419
|
+
const select = operator.select;
|
|
9420
|
+
if (select === void 0) {
|
|
9421
|
+
throw new Error(`${operator.type} requires a select block`);
|
|
9422
|
+
}
|
|
9423
|
+
if (select.mode !== void 0 && select.mode !== "most_relevant" /* MOST_RELEVANT */) {
|
|
9424
|
+
throw new Error(`select mode ${select.mode} is not supported, the only mode is ${"most_relevant" /* MOST_RELEVANT */}`);
|
|
9425
|
+
}
|
|
9426
|
+
if (select.relevancyModel !== void 0 && select.relevancyModelUuid !== void 0) {
|
|
9427
|
+
throw new Error("select can only have one of relevancyModelUuid or relevancyModel");
|
|
9428
|
+
}
|
|
9429
|
+
if (select.minTrackLengthSeconds !== void 0 && select.minTrackLengthSeconds < 0) {
|
|
9430
|
+
throw new Error("select minTrackLengthSeconds cannot be negative");
|
|
9431
|
+
}
|
|
9432
|
+
if (select.intervalSeconds !== void 0 && select.intervalSeconds <= 0) {
|
|
9433
|
+
throw new Error("select intervalSeconds must be positive");
|
|
9434
|
+
}
|
|
9435
|
+
if (operator.crop !== void 0) {
|
|
9436
|
+
if (operator.type !== "select_crop" /* SELECT_CROP */) {
|
|
9437
|
+
throw new Error(`crop options are only valid with select_crop, not ${operator.type}`);
|
|
9438
|
+
}
|
|
9439
|
+
if (operator.crop.maxItems !== void 0) {
|
|
9440
|
+
throw new Error("select_crop forwards one detection per selection, maxItems does not apply");
|
|
9441
|
+
}
|
|
9442
|
+
}
|
|
9443
|
+
}
|
|
9444
|
+
|
|
8773
9445
|
// compute/compute_session.ts
|
|
8774
9446
|
var SESSION_DEAD = /* @__PURE__ */ new Set(["error" /* ERROR */, "failed" /* FAILED */, "stopped" /* STOPPED */, "pipeline_error" /* PIPELINE_ERROR */, "unknown" /* UNKNOWN */]);
|
|
8775
9447
|
var CHECK_FOR_IS_READY_INTERVAL = 250;
|
|
@@ -9079,23 +9751,12 @@ var ComputeSessionClient = class {
|
|
|
9079
9751
|
} else if (Date.now() > deadline) {
|
|
9080
9752
|
throw new Error(`Created session ${session.session_uuid} did not become healthy after ${this.options.readyTimeoutMs / 1e3} seconds`);
|
|
9081
9753
|
} else {
|
|
9082
|
-
this.options.logger?.debug(`session ${session.session_uuid} health check status ${response.status}, wait and poll for update`);
|
|
9083
|
-
await sleep(CHECK_FOR_IS_READY_INTERVAL);
|
|
9084
|
-
}
|
|
9085
|
-
}
|
|
9086
|
-
}
|
|
9087
|
-
};
|
|
9088
|
-
|
|
9089
|
-
// types.ts
|
|
9090
|
-
var EndpointState = /* @__PURE__ */ ((EndpointState2) => {
|
|
9091
|
-
EndpointState2["Idle"] = "Idle";
|
|
9092
|
-
EndpointState2["Busy"] = "Busy";
|
|
9093
|
-
EndpointState2["Authenticating"] = "Authenticating";
|
|
9094
|
-
EndpointState2["FetchConfig"] = "FetchConfig";
|
|
9095
|
-
EndpointState2["Error"] = "Error";
|
|
9096
|
-
EndpointState2["NotAvailable"] = "NotAvailable";
|
|
9097
|
-
return EndpointState2;
|
|
9098
|
-
})(EndpointState || {});
|
|
9754
|
+
this.options.logger?.debug(`session ${session.session_uuid} health check status ${response.status}, wait and poll for update`);
|
|
9755
|
+
await sleep(CHECK_FOR_IS_READY_INTERVAL);
|
|
9756
|
+
}
|
|
9757
|
+
}
|
|
9758
|
+
}
|
|
9759
|
+
};
|
|
9099
9760
|
|
|
9100
9761
|
// streaming.ts
|
|
9101
9762
|
var import_uuid = require("uuid");
|
|
@@ -9350,187 +10011,6 @@ Content-Disposition: form-data; name="${part.name}"\r
|
|
|
9350
10011
|
});
|
|
9351
10012
|
}
|
|
9352
10013
|
|
|
9353
|
-
// camera.ts
|
|
9354
|
-
var QUATERNION_TOLERANCE = 1e-3;
|
|
9355
|
-
function isFinite_(value) {
|
|
9356
|
-
return value === void 0 || Number.isFinite(value);
|
|
9357
|
-
}
|
|
9358
|
-
function validateCamera(camera) {
|
|
9359
|
-
if (camera.intrinsics !== void 0 && camera.hfovDegrees !== void 0) {
|
|
9360
|
-
throw new Error("camera.intrinsics and camera.hfovDegrees are alternatives, supply one");
|
|
9361
|
-
}
|
|
9362
|
-
if (camera.intrinsics === void 0 && camera.hfovDegrees === void 0) {
|
|
9363
|
-
throw new Error("camera requires either camera.intrinsics or camera.hfovDegrees");
|
|
9364
|
-
}
|
|
9365
|
-
if (camera.hfovDegrees !== void 0) {
|
|
9366
|
-
if (!(camera.hfovDegrees > 0 && camera.hfovDegrees < 180)) {
|
|
9367
|
-
throw new Error("camera.hfovDegrees must be a horizontal field of view in (0, 180) degrees");
|
|
9368
|
-
}
|
|
9369
|
-
} else {
|
|
9370
|
-
const intrinsics = camera.intrinsics;
|
|
9371
|
-
for (const [name, focal] of [
|
|
9372
|
-
["fx", intrinsics.fx],
|
|
9373
|
-
["fy", intrinsics.fy]
|
|
9374
|
-
]) {
|
|
9375
|
-
if (!(focal > 0) || !Number.isFinite(focal)) {
|
|
9376
|
-
throw new Error(`camera.intrinsics.${name} must be a positive, finite focal length`);
|
|
9377
|
-
}
|
|
9378
|
-
}
|
|
9379
|
-
for (const [name, principal, extent] of [
|
|
9380
|
-
["cx", intrinsics.cx, "width"],
|
|
9381
|
-
["cy", intrinsics.cy, "height"]
|
|
9382
|
-
]) {
|
|
9383
|
-
if (!(principal >= 0 && principal <= 1)) {
|
|
9384
|
-
throw new Error(`camera.intrinsics.${name} must be within [0, 1] of the frame ${extent}`);
|
|
9385
|
-
}
|
|
9386
|
-
}
|
|
9387
|
-
}
|
|
9388
|
-
if (camera.distortion !== void 0) {
|
|
9389
|
-
for (const name of ["k1", "k2", "p1", "p2", "k3"]) {
|
|
9390
|
-
if (!isFinite_(camera.distortion[name])) {
|
|
9391
|
-
throw new Error(`camera.distortion.${name} must be a finite number`);
|
|
9392
|
-
}
|
|
9393
|
-
}
|
|
9394
|
-
}
|
|
9395
|
-
if (camera.extrinsics !== void 0) {
|
|
9396
|
-
const translation = camera.extrinsics.translation;
|
|
9397
|
-
if (translation !== void 0) {
|
|
9398
|
-
for (const axis of ["x", "y", "z"]) {
|
|
9399
|
-
if (!Number.isFinite(translation[axis])) {
|
|
9400
|
-
throw new Error(`camera.extrinsics.translation.${axis} must be a finite number`);
|
|
9401
|
-
}
|
|
9402
|
-
}
|
|
9403
|
-
}
|
|
9404
|
-
const rotation = camera.extrinsics.rotation;
|
|
9405
|
-
if (rotation !== void 0) {
|
|
9406
|
-
const norm = Math.sqrt(rotation.w ** 2 + rotation.x ** 2 + rotation.y ** 2 + rotation.z ** 2);
|
|
9407
|
-
if (!(Math.abs(norm - 1) <= QUATERNION_TOLERANCE)) {
|
|
9408
|
-
throw new Error("camera.extrinsics.rotation must be a unit quaternion");
|
|
9409
|
-
}
|
|
9410
|
-
}
|
|
9411
|
-
}
|
|
9412
|
-
}
|
|
9413
|
-
|
|
9414
|
-
// worker/worker_types.ts
|
|
9415
|
-
var PredictionVersion = /* @__PURE__ */ ((PredictionVersion3) => {
|
|
9416
|
-
PredictionVersion3[PredictionVersion3["V1"] = 1] = "V1";
|
|
9417
|
-
PredictionVersion3[PredictionVersion3["V2"] = 2] = "V2";
|
|
9418
|
-
PredictionVersion3[PredictionVersion3["V3"] = 3] = "V3";
|
|
9419
|
-
return PredictionVersion3;
|
|
9420
|
-
})(PredictionVersion || {});
|
|
9421
|
-
var DEFAULT_PREDICTION_VERSION = 2 /* V2 */;
|
|
9422
|
-
var VideoMode = /* @__PURE__ */ ((VideoMode2) => {
|
|
9423
|
-
VideoMode2["STREAM"] = "stream";
|
|
9424
|
-
VideoMode2["BUFFER"] = "buffer";
|
|
9425
|
-
return VideoMode2;
|
|
9426
|
-
})(VideoMode || {});
|
|
9427
|
-
var PopComponentType = /* @__PURE__ */ ((PopComponentType2) => {
|
|
9428
|
-
PopComponentType2["FORWARD"] = "forward";
|
|
9429
|
-
PopComponentType2["INFERENCE"] = "inference";
|
|
9430
|
-
PopComponentType2["TRACKING"] = "tracking";
|
|
9431
|
-
PopComponentType2["CONTOUR_FINDER"] = "contour_finder";
|
|
9432
|
-
PopComponentType2["COMPONENT_FINDER"] = "component_finder";
|
|
9433
|
-
return PopComponentType2;
|
|
9434
|
-
})(PopComponentType || {});
|
|
9435
|
-
var ForwardOperatorType = /* @__PURE__ */ ((ForwardOperatorType2) => {
|
|
9436
|
-
ForwardOperatorType2["FULL"] = "full";
|
|
9437
|
-
ForwardOperatorType2["CROP"] = "crop";
|
|
9438
|
-
ForwardOperatorType2["CROP_WITH_FULL_FALLBACK"] = "crop_with_full_fallback";
|
|
9439
|
-
ForwardOperatorType2["SELECT_CROP"] = "select_crop";
|
|
9440
|
-
ForwardOperatorType2["SELECT_FULL"] = "select_full";
|
|
9441
|
-
return ForwardOperatorType2;
|
|
9442
|
-
})(ForwardOperatorType || {});
|
|
9443
|
-
var SelectMode = /* @__PURE__ */ ((SelectMode2) => {
|
|
9444
|
-
SelectMode2["MOST_RELEVANT"] = "most_relevant";
|
|
9445
|
-
return SelectMode2;
|
|
9446
|
-
})(SelectMode || {});
|
|
9447
|
-
function isSelectOperator(operator) {
|
|
9448
|
-
return operator?.type === "select_crop" /* SELECT_CROP */ || operator?.type === "select_full" /* SELECT_FULL */;
|
|
9449
|
-
}
|
|
9450
|
-
var InferenceType = /* @__PURE__ */ ((InferenceType2) => {
|
|
9451
|
-
InferenceType2["IMAGE_CLASSIFICATION"] = "image_classification";
|
|
9452
|
-
InferenceType2["OBJECT_DETECTION"] = "object_detection";
|
|
9453
|
-
InferenceType2["KEY_POINTS"] = "key_points";
|
|
9454
|
-
InferenceType2["OCR"] = "ocr";
|
|
9455
|
-
InferenceType2["MESH"] = "mesh";
|
|
9456
|
-
InferenceType2["FEATURE_VECTOR"] = "feature_vector";
|
|
9457
|
-
InferenceType2["SEMANTIC_SEGMENTATION"] = "semantic_segmentation";
|
|
9458
|
-
InferenceType2["SEGMENTATION"] = "segmentation";
|
|
9459
|
-
return InferenceType2;
|
|
9460
|
-
})(InferenceType || {});
|
|
9461
|
-
var MotionModel = /* @__PURE__ */ ((MotionModel2) => {
|
|
9462
|
-
MotionModel2["RANDOM_WALK"] = "random_walk";
|
|
9463
|
-
MotionModel2["CONSTANT_VELOCITY"] = "constant_velocity";
|
|
9464
|
-
MotionModel2["CONSTANT_ACCELERATION"] = "constant_acceleration";
|
|
9465
|
-
return MotionModel2;
|
|
9466
|
-
})(MotionModel || {});
|
|
9467
|
-
var ContourType = /* @__PURE__ */ ((ContourType2) => {
|
|
9468
|
-
ContourType2["ALL_PIXELS"] = "all_pixels";
|
|
9469
|
-
ContourType2["POLYGON"] = "polygon";
|
|
9470
|
-
ContourType2["CONVEX_HULL"] = "convex_hull";
|
|
9471
|
-
ContourType2["HOUGH_CIRCLES"] = "hough_circles";
|
|
9472
|
-
ContourType2["CIRCLE"] = "circle";
|
|
9473
|
-
ContourType2["TRIANGLE"] = "triangle";
|
|
9474
|
-
ContourType2["RECTANGLE"] = "rectangle";
|
|
9475
|
-
return ContourType2;
|
|
9476
|
-
})(ContourType || {});
|
|
9477
|
-
function validatePop(pop) {
|
|
9478
|
-
if (pop.depthMap !== void 0) {
|
|
9479
|
-
if (pop.depthMap.ability === void 0 === (pop.depthMap.abilityUuid === void 0)) {
|
|
9480
|
-
throw new Error("depthMap requires exactly one of ability or abilityUuid");
|
|
9481
|
-
}
|
|
9482
|
-
}
|
|
9483
|
-
if (pop.defaults?.camera !== void 0) {
|
|
9484
|
-
validateCamera(pop.defaults.camera);
|
|
9485
|
-
}
|
|
9486
|
-
validateForwards(pop.components);
|
|
9487
|
-
}
|
|
9488
|
-
function popSelects(pop) {
|
|
9489
|
-
const selects = (components) => (components ?? []).some((component) => isSelectOperator(component.forward?.operator) || selects(component.forward?.targets));
|
|
9490
|
-
return selects(pop?.components);
|
|
9491
|
-
}
|
|
9492
|
-
function validateForwards(components) {
|
|
9493
|
-
for (const component of components ?? []) {
|
|
9494
|
-
const operator = component.forward?.operator;
|
|
9495
|
-
if (operator !== void 0) {
|
|
9496
|
-
validateSelectOperator(operator);
|
|
9497
|
-
}
|
|
9498
|
-
validateForwards(component.forward?.targets);
|
|
9499
|
-
}
|
|
9500
|
-
}
|
|
9501
|
-
function validateSelectOperator(operator) {
|
|
9502
|
-
if (!isSelectOperator(operator)) {
|
|
9503
|
-
if (operator.select !== void 0) {
|
|
9504
|
-
throw new Error("select is only valid with the select_crop or select_full operator");
|
|
9505
|
-
}
|
|
9506
|
-
return;
|
|
9507
|
-
}
|
|
9508
|
-
const select = operator.select;
|
|
9509
|
-
if (select === void 0) {
|
|
9510
|
-
throw new Error(`${operator.type} requires a select block`);
|
|
9511
|
-
}
|
|
9512
|
-
if (select.mode !== void 0 && select.mode !== "most_relevant" /* MOST_RELEVANT */) {
|
|
9513
|
-
throw new Error(`select mode ${select.mode} is not supported, the only mode is ${"most_relevant" /* MOST_RELEVANT */}`);
|
|
9514
|
-
}
|
|
9515
|
-
if (select.relevancyModel !== void 0 && select.relevancyModelUuid !== void 0) {
|
|
9516
|
-
throw new Error("select can only have one of relevancyModelUuid or relevancyModel");
|
|
9517
|
-
}
|
|
9518
|
-
if (select.minTrackLengthSeconds !== void 0 && select.minTrackLengthSeconds < 0) {
|
|
9519
|
-
throw new Error("select minTrackLengthSeconds cannot be negative");
|
|
9520
|
-
}
|
|
9521
|
-
if (select.intervalSeconds !== void 0 && select.intervalSeconds <= 0) {
|
|
9522
|
-
throw new Error("select intervalSeconds must be positive");
|
|
9523
|
-
}
|
|
9524
|
-
if (operator.crop !== void 0) {
|
|
9525
|
-
if (operator.type !== "select_crop" /* SELECT_CROP */) {
|
|
9526
|
-
throw new Error(`crop options are only valid with select_crop, not ${operator.type}`);
|
|
9527
|
-
}
|
|
9528
|
-
if (operator.crop.maxItems !== void 0) {
|
|
9529
|
-
throw new Error("select_crop forwards one detection per selection, maxItems does not apply");
|
|
9530
|
-
}
|
|
9531
|
-
}
|
|
9532
|
-
}
|
|
9533
|
-
|
|
9534
10014
|
// worker/webrtc_whip.ts
|
|
9535
10015
|
var import_uuid2 = require("uuid");
|
|
9536
10016
|
|
|
@@ -10455,1310 +10935,1671 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
10455
10935
|
const mime = require_mime_types();
|
|
10456
10936
|
const filehandle = require("fs/promises");
|
|
10457
10937
|
const fd = await filehandle.open(source.path, "r");
|
|
10938
|
+
const size = (await fd.stat()).size;
|
|
10458
10939
|
const stream = fd.createReadStream();
|
|
10459
10940
|
const iterator = nodeStreamToIterator(stream);
|
|
10460
10941
|
const webStream = iteratorToStream(iterator);
|
|
10461
|
-
const mimeType = source.mimeType ? source.mimeType : mime.lookup(source.path) || "image/*";
|
|
10462
|
-
return {
|
|
10463
|
-
stream: webStream,
|
|
10464
|
-
mimeType
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
}
|
|
10468
|
-
var iteratorToStream2;
|
|
10469
|
-
|
|
10470
|
-
// shims/http_client.ts
|
|
10471
|
-
var createHttpClient;
|
|
10472
|
-
function logLineFromRequest(input, init) {
|
|
10473
|
-
const url = input instanceof Request ? input.url : input;
|
|
10474
|
-
const method = input instanceof Request ? input.method : init?.method || (init?.body !== void 0 ? "POST" : "GET");
|
|
10475
|
-
return `${method} ${url}`;
|
|
10476
|
-
}
|
|
10477
|
-
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
10478
|
-
class BrowserHttpClient {
|
|
10479
|
-
constructor(logger) {
|
|
10480
|
-
this._logger = logger;
|
|
10481
|
-
}
|
|
10482
|
-
async fetch(input, init) {
|
|
10483
|
-
const logLine = logLineFromRequest(input, init);
|
|
10484
|
-
this._logger.debug(`Browser fetch() BEFORE ${logLine}`);
|
|
10485
|
-
const response = await fetch(input, init);
|
|
10486
|
-
this._logger.debug(`AFTER ${logLine} -> ${response.status}`);
|
|
10487
|
-
return response;
|
|
10488
|
-
}
|
|
10489
|
-
async close() {
|
|
10490
|
-
}
|
|
10491
|
-
isFullDuplex() {
|
|
10492
|
-
return false;
|
|
10493
|
-
}
|
|
10494
|
-
}
|
|
10495
|
-
createHttpClient = async (logger) => {
|
|
10496
|
-
return new BrowserHttpClient(logger);
|
|
10497
|
-
};
|
|
10498
|
-
} else {
|
|
10499
|
-
class NodeHttpClient {
|
|
10500
|
-
constructor(agent, fetchFn, logger) {
|
|
10501
|
-
this._agent = agent;
|
|
10502
|
-
this._fetch = fetchFn;
|
|
10503
|
-
this._logger = logger;
|
|
10504
|
-
}
|
|
10505
|
-
async fetch(input, init) {
|
|
10506
|
-
init || (init = {});
|
|
10507
|
-
init.dispatcher = this._agent;
|
|
10508
|
-
const logLine = logLineFromRequest(input, init);
|
|
10509
|
-
this._logger.debug(`Node fetch() BEFORE ${logLine}`);
|
|
10510
|
-
const response = await this._fetch(input, init);
|
|
10511
|
-
this._logger.debug(`AFTER ${logLine} -> ${response.status}`);
|
|
10512
|
-
return response;
|
|
10513
|
-
}
|
|
10514
|
-
async close() {
|
|
10515
|
-
return this._agent.close();
|
|
10516
|
-
}
|
|
10517
|
-
isFullDuplex() {
|
|
10518
|
-
return false;
|
|
10519
|
-
}
|
|
10520
|
-
}
|
|
10521
|
-
createHttpClient = async (logger) => {
|
|
10522
|
-
const undici = require("undici");
|
|
10523
|
-
const agent = new undici.Agent({
|
|
10524
|
-
keepAliveTimeout: 1e4,
|
|
10525
|
-
connections: 5,
|
|
10526
|
-
// two parallel streaming requests to the same host seem to deadlock with pipelining > 0
|
|
10527
|
-
pipelining: 0
|
|
10528
|
-
});
|
|
10529
|
-
logger.debug("Using node fetch with undici agent as http client");
|
|
10530
|
-
return new NodeHttpClient(agent, undici.fetch, logger);
|
|
10942
|
+
const mimeType = source.mimeType ? source.mimeType : mime.lookup(source.path) || "image/*";
|
|
10943
|
+
return {
|
|
10944
|
+
stream: webStream,
|
|
10945
|
+
mimeType,
|
|
10946
|
+
size
|
|
10947
|
+
};
|
|
10531
10948
|
};
|
|
10532
10949
|
}
|
|
10950
|
+
var iteratorToStream2;
|
|
10533
10951
|
|
|
10534
|
-
//
|
|
10535
|
-
var
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
constructor(
|
|
10543
|
-
this.
|
|
10544
|
-
this.
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
/**
|
|
10554
|
-
* Returns a promise used to wait for a permit to become available. This method should be awaited on.
|
|
10555
|
-
* @returns A promise that gets resolved when execution is allowed to proceed.
|
|
10556
|
-
*/
|
|
10557
|
-
async wait() {
|
|
10558
|
-
if (this.permits > 0) {
|
|
10559
|
-
this.permits -= 1;
|
|
10560
|
-
return Promise.resolve(true);
|
|
10561
|
-
}
|
|
10562
|
-
return new Promise((resolver) => this.promiseResolverQueue.push(resolver));
|
|
10952
|
+
// worker/worker_options.ts
|
|
10953
|
+
var TransientPopId = /* @__PURE__ */ ((TransientPopId2) => {
|
|
10954
|
+
TransientPopId2["Transient"] = "transient";
|
|
10955
|
+
return TransientPopId2;
|
|
10956
|
+
})(TransientPopId || {});
|
|
10957
|
+
|
|
10958
|
+
// worker/session_backend.ts
|
|
10959
|
+
var _SessionBackend = class _SessionBackend {
|
|
10960
|
+
constructor(ctx) {
|
|
10961
|
+
this.ctx = ctx;
|
|
10962
|
+
this._baseUrl = null;
|
|
10963
|
+
this._pipelineId = null;
|
|
10964
|
+
this._popName = null;
|
|
10965
|
+
this._sessionAccessToken = null;
|
|
10966
|
+
this._sessionAccessTokenValidUntil = null;
|
|
10967
|
+
// The account the connected compute session runs under, as compute-api reports it.
|
|
10968
|
+
this._accountId = void 0;
|
|
10969
|
+
this._pipeline = null;
|
|
10970
|
+
this._pipelineCreatePromise = null;
|
|
10563
10971
|
}
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
*/
|
|
10568
|
-
async acquire() {
|
|
10569
|
-
return this.wait();
|
|
10972
|
+
async disconnect(closeEndpoint) {
|
|
10973
|
+
await this.deleteOwnPipeline();
|
|
10974
|
+
await closeEndpoint();
|
|
10570
10975
|
}
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
const promise = new Promise((r) => {
|
|
10586
|
-
resolver = r;
|
|
10587
|
-
});
|
|
10588
|
-
this.promiseResolverQueue.push(resolver);
|
|
10589
|
-
setTimeout(() => {
|
|
10590
|
-
const index = this.promiseResolverQueue.indexOf(resolver);
|
|
10591
|
-
if (index !== -1) {
|
|
10592
|
-
this.promiseResolverQueue.splice(index, 1);
|
|
10593
|
-
} else {
|
|
10594
|
-
console.warn(`Semaphore.waitFor couldn't find its promise resolver in the queue`);
|
|
10976
|
+
async deleteOwnPipeline() {
|
|
10977
|
+
const client = this.ctx.client();
|
|
10978
|
+
if (this.ctx.options.popId == "transient" /* Transient */ && this._pipelineId && client) {
|
|
10979
|
+
const deleteUrl = `${this._baseUrl}/pipelines/${this._pipelineId}`;
|
|
10980
|
+
const headers = {
|
|
10981
|
+
Authorization: await this.authorizationHeader()
|
|
10982
|
+
};
|
|
10983
|
+
let response = await client.fetch(deleteUrl, {
|
|
10984
|
+
method: "DELETE",
|
|
10985
|
+
headers
|
|
10986
|
+
});
|
|
10987
|
+
if (response?.status != 204) {
|
|
10988
|
+
const message = await response?.text();
|
|
10989
|
+
this.ctx.logger.info(`stopping pipeline failed, status ${response?.status}: ${message}`);
|
|
10595
10990
|
}
|
|
10596
|
-
resolver(false);
|
|
10597
|
-
}, milliseconds);
|
|
10598
|
-
return promise;
|
|
10599
|
-
}
|
|
10600
|
-
/**
|
|
10601
|
-
* Synchronous function that tries to acquire a permit and returns true if successful, false otherwise.
|
|
10602
|
-
* @returns Whether a permit could be acquired.
|
|
10603
|
-
*/
|
|
10604
|
-
tryAcquire() {
|
|
10605
|
-
if (this.permits > 0) {
|
|
10606
|
-
this.permits -= 1;
|
|
10607
|
-
return true;
|
|
10608
10991
|
}
|
|
10609
|
-
return false;
|
|
10610
10992
|
}
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
|
|
10615
|
-
drainPermits() {
|
|
10616
|
-
if (this.permits > 0) {
|
|
10617
|
-
const permitCount = this.permits;
|
|
10618
|
-
this.permits = 0;
|
|
10619
|
-
return permitCount;
|
|
10993
|
+
onStatus(statusCode) {
|
|
10994
|
+
if (statusCode == 404) {
|
|
10995
|
+
this._pipelineId = null;
|
|
10996
|
+
this._baseUrl = null;
|
|
10620
10997
|
}
|
|
10621
|
-
return 0;
|
|
10622
10998
|
}
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
if (this.permits > 1 && this.promiseResolverQueue.length > 0) {
|
|
10630
|
-
console.warn("Semaphore.permits should never be > 0 when there is someone waiting.");
|
|
10631
|
-
} else if (this.permits === 1 && this.promiseResolverQueue.length > 0) {
|
|
10632
|
-
this.permits -= 1;
|
|
10633
|
-
const nextResolver = this.promiseResolverQueue.shift();
|
|
10634
|
-
if (nextResolver) {
|
|
10635
|
-
nextResolver(true);
|
|
10999
|
+
async session() {
|
|
11000
|
+
let session = null;
|
|
11001
|
+
if (this._baseUrl == null) {
|
|
11002
|
+
await this.reconnect();
|
|
11003
|
+
if (this._baseUrl == null) {
|
|
11004
|
+
return Promise.reject("endpoint not connected");
|
|
10636
11005
|
}
|
|
10637
11006
|
}
|
|
11007
|
+
if (this._sessionAccessToken) {
|
|
11008
|
+
session = {
|
|
11009
|
+
eyepopUrl: this.ctx.options.eyepopUrl,
|
|
11010
|
+
accessToken: this._sessionAccessToken,
|
|
11011
|
+
validUntil: this._sessionAccessTokenValidUntil || Number.MAX_VALUE
|
|
11012
|
+
};
|
|
11013
|
+
} else {
|
|
11014
|
+
session = await this.ctx.credentialSession();
|
|
11015
|
+
}
|
|
11016
|
+
return {
|
|
11017
|
+
eyepopUrl: session.eyepopUrl,
|
|
11018
|
+
accessToken: session.accessToken,
|
|
11019
|
+
validUntil: session.validUntil,
|
|
11020
|
+
popId: this.ctx.options.popId,
|
|
11021
|
+
accountId: this._accountId ?? this.ctx.options.accountId,
|
|
11022
|
+
baseUrl: this._baseUrl,
|
|
11023
|
+
pipelineId: this._pipelineId || void 0,
|
|
11024
|
+
isPipelineMode: false,
|
|
11025
|
+
authenticationHeaders: () => this._authenticationHeaders(session)
|
|
11026
|
+
};
|
|
10638
11027
|
}
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
this.
|
|
11028
|
+
popName() {
|
|
11029
|
+
return this._popName;
|
|
11030
|
+
}
|
|
11031
|
+
pop() {
|
|
11032
|
+
if (this._pipeline) {
|
|
11033
|
+
return this._pipeline.pop || null;
|
|
11034
|
+
}
|
|
11035
|
+
return this.ctx.options.pop || null;
|
|
10644
11036
|
}
|
|
10645
11037
|
/**
|
|
10646
|
-
*
|
|
10647
|
-
*
|
|
10648
|
-
*
|
|
10649
|
-
* @param func The function to be executed.
|
|
10650
|
-
* @return A promise that gets resolved with the return value of the function.
|
|
11038
|
+
* A select forward's results come only at V3. Only a Pop that selects asks
|
|
11039
|
+
* for it, so a worker too old to know V3 - which also rejects that Pop - is
|
|
11040
|
+
* never sent a version it would not accept.
|
|
10651
11041
|
*/
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
try {
|
|
10655
|
-
return await func();
|
|
10656
|
-
} finally {
|
|
10657
|
-
this.signal();
|
|
10658
|
-
}
|
|
11042
|
+
predictionVersion() {
|
|
11043
|
+
return popSelects(this.pop()) ? 3 /* V3 */ : DEFAULT_PREDICTION_VERSION;
|
|
10659
11044
|
}
|
|
10660
|
-
|
|
10661
|
-
|
|
10662
|
-
|
|
10663
|
-
|
|
10664
|
-
|
|
10665
|
-
// shims/browser_session.ts
|
|
10666
|
-
var import_auth0_spa_js = require("@auth0/auth0-spa-js");
|
|
10667
|
-
var authenticateBrowserSession;
|
|
10668
|
-
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
10669
|
-
authenticateBrowserSession = async (auth0, options) => {
|
|
10670
|
-
if (options.eyepopUrl == null) {
|
|
10671
|
-
return Promise.reject("options.eyepopUrl cannot be null");
|
|
10672
|
-
}
|
|
10673
|
-
const auth0ClientOptions = {
|
|
10674
|
-
clientId: auth0.clientId,
|
|
10675
|
-
domain: auth0.domain,
|
|
10676
|
-
authorizationParams: {
|
|
10677
|
-
scope: auth0.scope,
|
|
10678
|
-
audience: auth0.audience
|
|
10679
|
-
}
|
|
10680
|
-
};
|
|
10681
|
-
const auth0Client = await (0, import_auth0_spa_js.createAuth0Client)(auth0ClientOptions);
|
|
10682
|
-
if (!await auth0Client.isAuthenticated()) {
|
|
10683
|
-
await auth0Client.loginWithPopup();
|
|
10684
|
-
}
|
|
10685
|
-
const accessToken = await auth0Client.getTokenSilently();
|
|
10686
|
-
if (!accessToken) {
|
|
10687
|
-
return Promise.reject("auth0 login failed");
|
|
11045
|
+
async changePop(pop) {
|
|
11046
|
+
if (this.ctx.options.popId == "transient" /* Transient */) {
|
|
11047
|
+
await this.changeTransientPop(pop);
|
|
11048
|
+
return;
|
|
10688
11049
|
}
|
|
10689
|
-
|
|
10690
|
-
const
|
|
10691
|
-
if (
|
|
10692
|
-
|
|
10693
|
-
eyepopUrl: options.eyepopUrl,
|
|
10694
|
-
accessToken,
|
|
10695
|
-
validUntil: Date.now() + 60 * 60 * 1e3,
|
|
10696
|
-
popId: workerOptions.popId,
|
|
10697
|
-
baseUrl: void 0,
|
|
10698
|
-
pipelineId: void 0,
|
|
10699
|
-
authenticationHeaders: () => {
|
|
10700
|
-
return { Authorization: `Bearer ${accessToken}` };
|
|
10701
|
-
}
|
|
10702
|
-
};
|
|
10703
|
-
session = workerSession;
|
|
10704
|
-
} else {
|
|
10705
|
-
session = {
|
|
10706
|
-
eyepopUrl: options.eyepopUrl,
|
|
10707
|
-
accessToken,
|
|
10708
|
-
validUntil: Date.now() + 60 * 60 * 1e3
|
|
10709
|
-
};
|
|
11050
|
+
const client = this.ctx.client();
|
|
11051
|
+
const baseUrl = this._baseUrl;
|
|
11052
|
+
if (!baseUrl || !client) {
|
|
11053
|
+
return Promise.reject("endpoint not connected, use connect()");
|
|
10710
11054
|
}
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
|
|
10714
|
-
|
|
10715
|
-
|
|
10716
|
-
|
|
10717
|
-
}
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
this.
|
|
10729
|
-
this.
|
|
10730
|
-
|
|
10731
|
-
this._stateChangeHandler = null;
|
|
10732
|
-
let rootLogger;
|
|
10733
|
-
if (options.logger) {
|
|
10734
|
-
rootLogger = options.logger;
|
|
11055
|
+
let response = await this.ctx.fetchWithRetry(async () => {
|
|
11056
|
+
const session = await this.session();
|
|
11057
|
+
let headers = {
|
|
11058
|
+
"Content-Type": "application/json",
|
|
11059
|
+
...this._authenticationHeaders(session)
|
|
11060
|
+
};
|
|
11061
|
+
const patch_url = `${session.baseUrl}/pipelines/${session.pipelineId}/pop`;
|
|
11062
|
+
return await client.fetch(patch_url, {
|
|
11063
|
+
method: "PATCH",
|
|
11064
|
+
body: JSON.stringify(pop),
|
|
11065
|
+
headers
|
|
11066
|
+
});
|
|
11067
|
+
});
|
|
11068
|
+
if (response.status != 204) {
|
|
11069
|
+
const message = await response.text();
|
|
11070
|
+
throw new Error(`Unexpected status ${response.status}: ${message}`);
|
|
11071
|
+
}
|
|
11072
|
+
this.ctx.options.pop = pop;
|
|
11073
|
+
if (this._pipeline) {
|
|
11074
|
+
this._pipeline.pop = pop;
|
|
10735
11075
|
} else {
|
|
10736
|
-
|
|
11076
|
+
this._pipeline = {
|
|
11077
|
+
id: this._pipelineId || "unknown",
|
|
11078
|
+
state: "idle",
|
|
11079
|
+
startTime: (/* @__PURE__ */ new Date()).toString(),
|
|
11080
|
+
pop
|
|
11081
|
+
};
|
|
10737
11082
|
}
|
|
10738
|
-
this._logger = rootLogger.child({ module: "eyepop" });
|
|
10739
|
-
this._requestLogger = this._logger.child({ module: "requests" });
|
|
10740
11083
|
}
|
|
10741
|
-
|
|
10742
|
-
this.
|
|
10743
|
-
this._statusRetryHandlers.set(401, this.statusHandler401);
|
|
11084
|
+
_authenticationHeaders(session) {
|
|
11085
|
+
return resolveAuth(this.ctx.options)?.isLocal !== void 0 ? {} : { Authorization: `Bearer ${session.accessToken}` };
|
|
10744
11086
|
}
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
11087
|
+
async submit(work) {
|
|
11088
|
+
switch (work.kind) {
|
|
11089
|
+
case "source":
|
|
11090
|
+
return await this.process(work.source, work.params);
|
|
11091
|
+
case "uploadGroup":
|
|
11092
|
+
return await this.uploadGroup(work.paths, work.params);
|
|
11093
|
+
case "uploadStreamGroup":
|
|
11094
|
+
return await this.uploadStreamGroup(work.streams, work.mimeTypes, work.params);
|
|
11095
|
+
case "loadFromGroup":
|
|
11096
|
+
return await this.loadFromGroup(work.urls, work.params);
|
|
10750
11097
|
}
|
|
10751
11098
|
}
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
11099
|
+
async process(source, params) {
|
|
11100
|
+
if (source.file !== void 0) {
|
|
11101
|
+
return this.uploadFile(source, params);
|
|
11102
|
+
} else if (source.stream !== void 0) {
|
|
11103
|
+
return this.uploadStream(source, params);
|
|
11104
|
+
} else if (source.path !== void 0) {
|
|
11105
|
+
return this.uploadPath(source, params);
|
|
11106
|
+
} else if (source.url !== void 0) {
|
|
11107
|
+
return this.loadFrom(source, params);
|
|
11108
|
+
} else if (source.assetUuid !== void 0) {
|
|
11109
|
+
return this.loadFromAssetUuid(source, params);
|
|
11110
|
+
} else if (source.mediaStream !== void 0) {
|
|
11111
|
+
return this.loadMediaStream(source, params);
|
|
10756
11112
|
} else {
|
|
10757
|
-
return
|
|
11113
|
+
return Promise.reject("unknown source type");
|
|
10758
11114
|
}
|
|
10759
11115
|
}
|
|
10760
|
-
|
|
10761
|
-
return
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10770
|
-
|
|
10771
|
-
return this;
|
|
10772
|
-
}
|
|
10773
|
-
updateState(newState = void 0, message = void 0) {
|
|
10774
|
-
const fromState = this._state;
|
|
10775
|
-
if (newState == void 0) {
|
|
10776
|
-
if (this._limit.getPermits() == this._options.jobQueueLength) {
|
|
10777
|
-
newState = "Idle" /* Idle */;
|
|
10778
|
-
} else {
|
|
10779
|
-
newState = "Busy" /* Busy */;
|
|
11116
|
+
start(job) {
|
|
11117
|
+
return job.start(
|
|
11118
|
+
() => {
|
|
11119
|
+
this.ctx.jobDone();
|
|
11120
|
+
},
|
|
11121
|
+
(statusCode) => {
|
|
11122
|
+
if (statusCode == 404) {
|
|
11123
|
+
this.onStatus(statusCode);
|
|
11124
|
+
} else if (statusCode == 401) {
|
|
11125
|
+
this.ctx.forgetCredential();
|
|
11126
|
+
}
|
|
10780
11127
|
}
|
|
10781
|
-
|
|
10782
|
-
this._state = newState;
|
|
10783
|
-
this._message = message ? message : null;
|
|
10784
|
-
if (this._stateChangeHandler) {
|
|
10785
|
-
this._stateChangeHandler(fromState, this._state);
|
|
10786
|
-
}
|
|
11128
|
+
);
|
|
10787
11129
|
}
|
|
10788
|
-
async
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
if (!this._options.eyepopUrl) {
|
|
10794
|
-
return Promise.reject("option eyepopUrl or environment variable EYEPOP_URL is required");
|
|
11130
|
+
async uploadGroup(paths, params) {
|
|
11131
|
+
const client = this.ctx.client();
|
|
11132
|
+
const limit = this.ctx.limit();
|
|
11133
|
+
if (!this._baseUrl || !this._pipelineId || !client) {
|
|
11134
|
+
throw new Error("endpoint not connected, use connect()");
|
|
10795
11135
|
}
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
11136
|
+
await limit.acquire();
|
|
11137
|
+
try {
|
|
11138
|
+
this.ctx.updateState();
|
|
11139
|
+
const sources = await Promise.all(
|
|
11140
|
+
paths.map(async (path2) => {
|
|
11141
|
+
const streamSource = await this.resolvePath({ path: path2 });
|
|
11142
|
+
return { stream: streamSource.stream, mimeType: streamSource.mimeType };
|
|
11143
|
+
})
|
|
11144
|
+
);
|
|
11145
|
+
return this.start(new UploadGroupJob(sources, params, async () => this.session(), client, this.ctx.requestLogger, this.predictionVersion()));
|
|
11146
|
+
} catch (e) {
|
|
11147
|
+
limit.release();
|
|
11148
|
+
throw e;
|
|
10799
11149
|
}
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
} else if (auth.isLocal !== void 0) {
|
|
10807
|
-
} else {
|
|
10808
|
-
return Promise.reject("option apiKey/accessToken or environment variable EYEPOP_API_KEY is required");
|
|
11150
|
+
}
|
|
11151
|
+
async uploadStreamGroup(streams, mimeTypes, params) {
|
|
11152
|
+
const client = this.ctx.client();
|
|
11153
|
+
const limit = this.ctx.limit();
|
|
11154
|
+
if (!this._baseUrl || !this._pipelineId || !client) {
|
|
11155
|
+
throw new Error("endpoint not connected, use connect()");
|
|
10809
11156
|
}
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
11157
|
+
await limit.acquire();
|
|
11158
|
+
try {
|
|
11159
|
+
this.ctx.updateState();
|
|
11160
|
+
const sources = streams.map((stream, i) => ({
|
|
11161
|
+
stream,
|
|
11162
|
+
mimeType: mimeTypes?.[i] ?? null
|
|
11163
|
+
}));
|
|
11164
|
+
return this.start(new UploadGroupJob(sources, params, async () => this.session(), client, this.ctx.requestLogger, this.predictionVersion()));
|
|
11165
|
+
} catch (e) {
|
|
11166
|
+
limit.release();
|
|
11167
|
+
throw e;
|
|
10814
11168
|
}
|
|
10815
|
-
return await this.reconnect();
|
|
10816
11169
|
}
|
|
10817
|
-
async
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
11170
|
+
async loadFromGroup(urls, params) {
|
|
11171
|
+
const client = this.ctx.client();
|
|
11172
|
+
const limit = this.ctx.limit();
|
|
11173
|
+
if (!this._baseUrl || !this._pipelineId || !client) {
|
|
11174
|
+
throw new Error("endpoint not connected, use connect()");
|
|
10822
11175
|
}
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
this.
|
|
11176
|
+
await limit.acquire();
|
|
11177
|
+
try {
|
|
11178
|
+
this.ctx.updateState();
|
|
11179
|
+
return this.start(new LoadFromGroupJob(urls, params, async () => this.session(), client, this.ctx.requestLogger, this.predictionVersion()));
|
|
11180
|
+
} catch (e) {
|
|
11181
|
+
limit.release();
|
|
11182
|
+
throw e;
|
|
10827
11183
|
}
|
|
10828
11184
|
}
|
|
10829
|
-
async
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
return Promise.reject("endpoint not connected");
|
|
11185
|
+
async resolvePath(source) {
|
|
11186
|
+
if (this.ctx.options.platformSupport?.resolvePath) {
|
|
11187
|
+
return await this.ctx.options.platformSupport.resolvePath(source, this.ctx.logger);
|
|
10833
11188
|
}
|
|
10834
|
-
return
|
|
10835
|
-
eyepopUrl: this._options.eyepopUrl,
|
|
10836
|
-
accessToken: this._token,
|
|
10837
|
-
validUntil: this._expire_token_time * 1e3
|
|
10838
|
-
};
|
|
10839
|
-
}
|
|
10840
|
-
statusHandler401(_statusCode) {
|
|
10841
|
-
this._token = null;
|
|
10842
|
-
this._expire_token_time = null;
|
|
11189
|
+
return await resolvePath(source, this.ctx.logger);
|
|
10843
11190
|
}
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
if (handler != null) {
|
|
10853
|
-
handler(response.status);
|
|
10854
|
-
if (retries--) {
|
|
10855
|
-
this._requestLogger.info("received %d response, retry", response.status);
|
|
10856
|
-
} else {
|
|
10857
|
-
return response;
|
|
10858
|
-
}
|
|
10859
|
-
} else {
|
|
10860
|
-
return response;
|
|
10861
|
-
}
|
|
10862
|
-
}
|
|
10863
|
-
} catch (error) {
|
|
10864
|
-
const handler = this._statusRetryHandlers.get(404);
|
|
10865
|
-
if (handler != null) {
|
|
10866
|
-
handler(error);
|
|
10867
|
-
if (retries--) {
|
|
10868
|
-
this._requestLogger.info("error %s, retry", error);
|
|
10869
|
-
} else {
|
|
10870
|
-
return Promise.reject(`error ${error}`);
|
|
10871
|
-
}
|
|
10872
|
-
} else {
|
|
10873
|
-
return Promise.reject(`error ${error}`);
|
|
10874
|
-
}
|
|
11191
|
+
/** Start a job once the transient pipeline runs and a queue permit is held; the permit is released if it cannot start. */
|
|
11192
|
+
async startConnected(makeJob, rejectsWithText = false) {
|
|
11193
|
+
await this.ensureTransientPipelineStarted();
|
|
11194
|
+
const client = this.ctx.client();
|
|
11195
|
+
const limit = this.ctx.limit();
|
|
11196
|
+
if (!this._baseUrl || !this._pipelineId || !client) {
|
|
11197
|
+
if (rejectsWithText) {
|
|
11198
|
+
return Promise.reject("endpoint not connected, use connect()");
|
|
10875
11199
|
}
|
|
11200
|
+
throw new Error("endpoint not connected, use connect()");
|
|
11201
|
+
}
|
|
11202
|
+
await limit.acquire();
|
|
11203
|
+
try {
|
|
11204
|
+
this.ctx.updateState();
|
|
11205
|
+
return this.start(await makeJob(client));
|
|
11206
|
+
} catch (e) {
|
|
11207
|
+
limit.release();
|
|
11208
|
+
throw e;
|
|
10876
11209
|
}
|
|
10877
11210
|
}
|
|
10878
|
-
async
|
|
10879
|
-
|
|
11211
|
+
async uploadFile(source, params) {
|
|
11212
|
+
return await this.startConnected(
|
|
11213
|
+
async (client) => new UploadJob(
|
|
11214
|
+
source.file,
|
|
11215
|
+
source.file.type,
|
|
11216
|
+
source.file.size,
|
|
11217
|
+
source.videoMode,
|
|
11218
|
+
params,
|
|
11219
|
+
async () => this.session(),
|
|
11220
|
+
client,
|
|
11221
|
+
this.ctx.requestLogger,
|
|
11222
|
+
void 0,
|
|
11223
|
+
this.predictionVersion()
|
|
11224
|
+
),
|
|
11225
|
+
true
|
|
11226
|
+
);
|
|
10880
11227
|
}
|
|
10881
|
-
async
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
11228
|
+
async uploadStream(source, params) {
|
|
11229
|
+
return await this.startConnected(
|
|
11230
|
+
async (client) => new UploadJob(source.stream, source.mimeType, source.size, source.videoMode, params, async () => this.session(), client, this.ctx.requestLogger, void 0, this.predictionVersion()),
|
|
11231
|
+
true
|
|
11232
|
+
);
|
|
10886
11233
|
}
|
|
10887
|
-
async
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
return
|
|
10895
|
-
} else if (auth?.isLocal !== void 0) {
|
|
10896
|
-
this._token = "implicit";
|
|
10897
|
-
this._expire_token_time = Number.MAX_VALUE;
|
|
10898
|
-
} else if (auth?.session !== void 0) {
|
|
10899
|
-
return Promise.reject("temporary access token expired");
|
|
10900
|
-
} else if (auth?.oAuth2 !== void 0 && this._options.eyepopUrl) {
|
|
10901
|
-
const session = await authenticateBrowserSession(auth.oAuth2, this._options);
|
|
10902
|
-
this._token = session.accessToken;
|
|
10903
|
-
this._expire_token_time = session.validUntil / 1e3;
|
|
10904
|
-
} else if (accessTokenCredential(auth) !== void 0) {
|
|
10905
|
-
this._token = accessTokenCredential(auth);
|
|
10906
|
-
this._expire_token_time = Number.MAX_VALUE;
|
|
10907
|
-
} else if (this._options.eyepopUrl) {
|
|
10908
|
-
const credential = apiKeyCredential(auth);
|
|
10909
|
-
if (credential === void 0) {
|
|
10910
|
-
return Promise.reject("no valid auth option");
|
|
10911
|
-
}
|
|
10912
|
-
const headers = { Authorization: `Bearer ${credential}` };
|
|
10913
|
-
const post_url = `${this.eyepopUrl()}/v1/auth/authenticate`;
|
|
10914
|
-
const response = await this._client.fetch(post_url, {
|
|
10915
|
-
method: "POST",
|
|
10916
|
-
headers
|
|
10917
|
-
});
|
|
10918
|
-
if (response.status != 200) {
|
|
10919
|
-
const message = await response.text();
|
|
10920
|
-
return Promise.reject(`Unexpected status ${response.status}: ${message}`);
|
|
10921
|
-
}
|
|
10922
|
-
const data = await response.json();
|
|
10923
|
-
const token = data;
|
|
10924
|
-
this._token = token.access_token;
|
|
10925
|
-
this._expire_token_time = now + token.expires_in - 60;
|
|
10926
|
-
} else {
|
|
10927
|
-
return Promise.reject("no valid auth option");
|
|
11234
|
+
async uploadPath(source, params) {
|
|
11235
|
+
return await this.startConnected(async (client) => {
|
|
11236
|
+
const streamSource = await this.resolvePath(source);
|
|
11237
|
+
let firstStreamPending = true;
|
|
11238
|
+
const uploadBodyFactory = async () => {
|
|
11239
|
+
if (firstStreamPending) {
|
|
11240
|
+
firstStreamPending = false;
|
|
11241
|
+
return streamSource.stream;
|
|
10928
11242
|
}
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
11243
|
+
return (await this.resolvePath(source)).stream;
|
|
11244
|
+
};
|
|
11245
|
+
return new UploadJob(
|
|
11246
|
+
streamSource.stream,
|
|
11247
|
+
streamSource.mimeType,
|
|
11248
|
+
streamSource.size,
|
|
11249
|
+
source.videoMode,
|
|
11250
|
+
params,
|
|
11251
|
+
async () => this.session(),
|
|
11252
|
+
client,
|
|
11253
|
+
this.ctx.requestLogger,
|
|
11254
|
+
uploadBodyFactory,
|
|
11255
|
+
this.predictionVersion()
|
|
11256
|
+
);
|
|
11257
|
+
});
|
|
11258
|
+
}
|
|
11259
|
+
async loadFrom(source, params) {
|
|
11260
|
+
if (source.url.startsWith("file://")) {
|
|
11261
|
+
return await this.uploadPath({ path: source.url.substring("file://".length) }, params);
|
|
10932
11262
|
}
|
|
10933
|
-
this.
|
|
10934
|
-
return this._token;
|
|
11263
|
+
return await this.startConnected(async (client) => new LoadFromJob(source.url, params, async () => this.session(), client, this.ctx.requestLogger, this.predictionVersion()));
|
|
10935
11264
|
}
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
// worker/worker_options.ts
|
|
10939
|
-
var TransientPopId = /* @__PURE__ */ ((TransientPopId2) => {
|
|
10940
|
-
TransientPopId2["Transient"] = "transient";
|
|
10941
|
-
return TransientPopId2;
|
|
10942
|
-
})(TransientPopId || {});
|
|
10943
|
-
|
|
10944
|
-
// worker/worker_endpoint.ts
|
|
10945
|
-
var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
10946
|
-
constructor(options) {
|
|
10947
|
-
super(options);
|
|
10948
|
-
this.setStatusRetryHandlers(/* @__PURE__ */ new Map([[404, (statusCode) => this.statusHandler404(statusCode)]]));
|
|
10949
|
-
this._baseUrl = null;
|
|
10950
|
-
this._pipelineId = null;
|
|
10951
|
-
this._popName = null;
|
|
10952
|
-
this._sessionAccessToken = null;
|
|
10953
|
-
this._sessionAccessTokenValidUntil = null;
|
|
10954
|
-
this._accountId = void 0;
|
|
10955
|
-
this._pipeline = null;
|
|
10956
|
-
this._pipelineCreatePromise = null;
|
|
11265
|
+
async loadFromAssetUuid(source, params) {
|
|
11266
|
+
return await this.startConnected(async (client) => new LoadFromAssetUuidJob(source.assetUuid, params, async () => this.session(), client, this.ctx.requestLogger, this.predictionVersion()));
|
|
10957
11267
|
}
|
|
10958
|
-
|
|
10959
|
-
return this.
|
|
11268
|
+
async loadMediaStream(source, params) {
|
|
11269
|
+
return await this.startConnected(async (client) => new LoadMediaStreamJob(source.mediaStream, params, async () => this.session(), client, this.ctx.requestLogger, this.predictionVersion()));
|
|
10960
11270
|
}
|
|
10961
|
-
async
|
|
10962
|
-
if (this.options
|
|
10963
|
-
|
|
10964
|
-
|
|
11271
|
+
async reconnect() {
|
|
11272
|
+
if (this.ctx.options.popId == "transient" /* Transient */) {
|
|
11273
|
+
await this.getComputeSession();
|
|
11274
|
+
if (this.ctx.options.pop) {
|
|
11275
|
+
this.setTransientPipelinePop();
|
|
11276
|
+
}
|
|
11277
|
+
} else if (this.ctx.options.sessionUuid) {
|
|
11278
|
+
await this.getComputeSession();
|
|
11279
|
+
} else {
|
|
11280
|
+
await this.startWebApiSessionWithPopId();
|
|
11281
|
+
}
|
|
11282
|
+
this.ctx.updateState();
|
|
11283
|
+
}
|
|
11284
|
+
async startWebApiSessionWithPopId() {
|
|
11285
|
+
const client = this.ctx.client();
|
|
11286
|
+
if (!client) {
|
|
11287
|
+
throw new Error("endpoint not initialized");
|
|
11288
|
+
}
|
|
11289
|
+
const config_url = `${this.ctx.eyepopWebApiUrl()}/pops/${this.ctx.options.popId}/config?auto_start=false`;
|
|
11290
|
+
const headers = {
|
|
11291
|
+
Authorization: await this.authorizationHeader()
|
|
11292
|
+
};
|
|
11293
|
+
this.ctx.updateState("FetchConfig" /* FetchConfig */);
|
|
11294
|
+
let response = await client.fetch(config_url, { headers });
|
|
11295
|
+
if (response.status == 401) {
|
|
11296
|
+
this.ctx.requestLogger.debug("GET %s: 401, about to retry with fresh access token", config_url);
|
|
11297
|
+
this.ctx.forgetCredential();
|
|
11298
|
+
const headers2 = {
|
|
10965
11299
|
Authorization: await this.authorizationHeader()
|
|
10966
11300
|
};
|
|
10967
|
-
|
|
10968
|
-
|
|
10969
|
-
headers
|
|
11301
|
+
this.ctx.updateState("FetchConfig" /* FetchConfig */);
|
|
11302
|
+
response = await client.fetch(config_url, {
|
|
11303
|
+
headers: headers2
|
|
10970
11304
|
});
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
11305
|
+
}
|
|
11306
|
+
if (response.status != 200) {
|
|
11307
|
+
const message = await response.text();
|
|
11308
|
+
if (response.status == 429) {
|
|
11309
|
+
this.ctx.updateState("NotAvailable" /* NotAvailable */, message);
|
|
11310
|
+
} else {
|
|
11311
|
+
this.ctx.updateState("Error" /* Error */, message);
|
|
10974
11312
|
}
|
|
11313
|
+
throw new Error(`Unexpected status ${response.status}: ${message}`);
|
|
10975
11314
|
}
|
|
10976
|
-
|
|
10977
|
-
|
|
10978
|
-
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
if (
|
|
10987
|
-
|
|
11315
|
+
let config = await response.json();
|
|
11316
|
+
if (!config.base_url && this.ctx.options.autoStart) {
|
|
11317
|
+
const auto_start_config_url = `${this.ctx.eyepopWebApiUrl()}/pops/${this.ctx.options.popId}/config?auto_start=true`;
|
|
11318
|
+
this.ctx.requestLogger.debug("pop was not running, trying to autostart with: %s", auto_start_config_url);
|
|
11319
|
+
const headers2 = {
|
|
11320
|
+
Authorization: await this.authorizationHeader()
|
|
11321
|
+
};
|
|
11322
|
+
response = await client.fetch(auto_start_config_url, {
|
|
11323
|
+
headers: headers2
|
|
11324
|
+
});
|
|
11325
|
+
if (response.status != 200) {
|
|
11326
|
+
this.ctx.updateState("Error" /* Error */);
|
|
11327
|
+
const message = await response.text();
|
|
11328
|
+
throw new Error(`Unexpected status ${response.status}: ${message}`);
|
|
10988
11329
|
}
|
|
11330
|
+
config = await response.json();
|
|
10989
11331
|
}
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
11332
|
+
const baseUrl = new URL(config.base_url, this.ctx.eyepopUrl());
|
|
11333
|
+
this._baseUrl = baseUrl.toString();
|
|
11334
|
+
if (this._baseUrl) {
|
|
11335
|
+
this._baseUrl = this._baseUrl.replace(/\/+$/, "");
|
|
11336
|
+
this._pipelineId = config.pipeline_id;
|
|
11337
|
+
this._popName = config.name;
|
|
11338
|
+
if (!this._pipelineId || !this._baseUrl) {
|
|
11339
|
+
throw new Error("Pop not started");
|
|
11340
|
+
}
|
|
11341
|
+
const get_url = `${this._baseUrl}/pipelines/${this._pipelineId}`;
|
|
11342
|
+
const headers2 = {
|
|
11343
|
+
Authorization: await this.authorizationHeader()
|
|
10995
11344
|
};
|
|
10996
|
-
|
|
10997
|
-
|
|
11345
|
+
let response2 = await client.fetch(get_url, {
|
|
11346
|
+
method: "GET",
|
|
11347
|
+
headers: headers2
|
|
11348
|
+
});
|
|
11349
|
+
if (response2.status > 200) {
|
|
11350
|
+
const message = await response2.text();
|
|
11351
|
+
throw new Error(`Unexpected status ${response2.status}: ${message}`);
|
|
11352
|
+
}
|
|
11353
|
+
this._pipeline = await response2.json();
|
|
11354
|
+
if (this.ctx.options.stopJobs) {
|
|
11355
|
+
const body = { sourceType: "NONE" };
|
|
11356
|
+
const headers3 = {
|
|
11357
|
+
Authorization: await this.authorizationHeader(),
|
|
11358
|
+
"Content-Type": "application/json"
|
|
11359
|
+
};
|
|
11360
|
+
const stop_url = `${this._baseUrl}/pipelines/${this._pipeline.id}/source?mode=preempt&processing=sync`;
|
|
11361
|
+
let response3 = await client.fetch(stop_url, {
|
|
11362
|
+
method: "PATCH",
|
|
11363
|
+
headers: headers3,
|
|
11364
|
+
body: JSON.stringify(body)
|
|
11365
|
+
});
|
|
11366
|
+
if (response3.status >= 300) {
|
|
11367
|
+
const message = await response3.text();
|
|
11368
|
+
throw new Error(`Unexpected status ${response3.status}: ${message}`);
|
|
11369
|
+
}
|
|
11370
|
+
}
|
|
10998
11371
|
}
|
|
10999
|
-
return {
|
|
11000
|
-
eyepopUrl: session.eyepopUrl,
|
|
11001
|
-
accessToken: session.accessToken,
|
|
11002
|
-
validUntil: session.validUntil,
|
|
11003
|
-
popId: this.options().popId,
|
|
11004
|
-
accountId: this._accountId ?? this.options().accountId,
|
|
11005
|
-
baseUrl: this._baseUrl,
|
|
11006
|
-
pipelineId: this._pipelineId || void 0,
|
|
11007
|
-
authenticationHeaders: () => this._authenticationHeaders(session)
|
|
11008
|
-
};
|
|
11009
11372
|
}
|
|
11010
|
-
|
|
11011
|
-
|
|
11373
|
+
sessionReadyTimeoutMs() {
|
|
11374
|
+
const seconds = this.ctx.options.sessionReadyTimeoutSeconds;
|
|
11375
|
+
return typeof seconds == "number" && Number.isFinite(seconds) && seconds > 0 ? seconds * 1e3 : _SessionBackend.WAIT_FOR_IS_READY;
|
|
11012
11376
|
}
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11377
|
+
async getComputeSession() {
|
|
11378
|
+
const client = this.ctx.client();
|
|
11379
|
+
if (!client) {
|
|
11380
|
+
throw new Error("endpoint not initialized");
|
|
11016
11381
|
}
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11382
|
+
let resolved;
|
|
11383
|
+
try {
|
|
11384
|
+
resolved = await new ComputeSessionClient({
|
|
11385
|
+
computeUrl: this.ctx.eyepopUrl(),
|
|
11386
|
+
httpClient: client,
|
|
11387
|
+
authorizationHeader: () => this.computeAuthorizationHeader(),
|
|
11388
|
+
sessionUuid: this.ctx.options.sessionUuid,
|
|
11389
|
+
sessionName: this.ctx.options.sessionName,
|
|
11390
|
+
accountId: this.ctx.options.accountId,
|
|
11391
|
+
pipelineImage: this.ctx.options.pipelineImage,
|
|
11392
|
+
pipelineVersion: this.ctx.options.pipelineVersion,
|
|
11393
|
+
pop: this.ctx.options.pop,
|
|
11394
|
+
readyTimeoutMs: this.sessionReadyTimeoutMs(),
|
|
11395
|
+
logger: this.ctx.logger,
|
|
11396
|
+
requestLogger: this.ctx.requestLogger
|
|
11397
|
+
}).resolve();
|
|
11398
|
+
} catch (error) {
|
|
11399
|
+
this.ctx.updateState("Error" /* Error */);
|
|
11400
|
+
throw error;
|
|
11032
11401
|
}
|
|
11033
|
-
|
|
11402
|
+
this._sessionAccessToken = resolved.accessToken;
|
|
11403
|
+
this._sessionAccessTokenValidUntil = resolved.accessTokenValidUntil;
|
|
11404
|
+
this._baseUrl = resolved.session.session_endpoint;
|
|
11405
|
+
this._accountId = resolved.session.account_uuid || void 0;
|
|
11406
|
+
this._pipeline = null;
|
|
11407
|
+
this._pipelineId = resolved.pipelineId;
|
|
11408
|
+
if (this.ctx.options.pop) {
|
|
11409
|
+
this.setTransientPipelinePop();
|
|
11410
|
+
}
|
|
11411
|
+
}
|
|
11412
|
+
async startTransientPipeline() {
|
|
11413
|
+
const client = this.ctx.client();
|
|
11034
11414
|
const baseUrl = this._baseUrl;
|
|
11035
|
-
if (
|
|
11036
|
-
|
|
11415
|
+
if (client == null || baseUrl == null) {
|
|
11416
|
+
throw new Error("endpoint not initialized");
|
|
11037
11417
|
}
|
|
11038
|
-
let
|
|
11039
|
-
|
|
11418
|
+
let pop;
|
|
11419
|
+
if (this.ctx.options.pop) {
|
|
11420
|
+
pop = this.ctx.options.pop;
|
|
11421
|
+
} else if (this._pipeline && this._pipeline.pop) {
|
|
11422
|
+
pop = this._pipeline.pop;
|
|
11423
|
+
} else {
|
|
11424
|
+
throw new Error("Cannot start a transient pipeline without a pop");
|
|
11425
|
+
}
|
|
11426
|
+
const body = {
|
|
11427
|
+
pop,
|
|
11428
|
+
source: {
|
|
11429
|
+
sourceType: "NONE"
|
|
11430
|
+
},
|
|
11431
|
+
idleTimeoutSeconds: 30,
|
|
11432
|
+
logging: ["out_meta"],
|
|
11433
|
+
videoOutput: "no_output"
|
|
11434
|
+
};
|
|
11435
|
+
const post_url = `${baseUrl.replace(/\/+$/, "")}/pipelines`;
|
|
11436
|
+
const response = await this.ctx.fetchWithRetry(async () => {
|
|
11040
11437
|
let headers = {
|
|
11438
|
+
Accept: "application/json",
|
|
11041
11439
|
"Content-Type": "application/json",
|
|
11042
|
-
|
|
11440
|
+
Authorization: await this.authorizationHeader()
|
|
11043
11441
|
};
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
body: JSON.stringify(pop),
|
|
11442
|
+
return client.fetch(post_url, {
|
|
11443
|
+
method: "POST",
|
|
11444
|
+
body: JSON.stringify(body),
|
|
11048
11445
|
headers
|
|
11049
11446
|
});
|
|
11050
11447
|
});
|
|
11051
|
-
if (response.status !=
|
|
11448
|
+
if (response.status != 200) {
|
|
11449
|
+
const message = await response.text();
|
|
11450
|
+
throw new Error(`Unexpected status ${response.status} starting transient pipeline: ${message.slice(0, 300)}`);
|
|
11451
|
+
}
|
|
11452
|
+
const result = await response.json();
|
|
11453
|
+
return result["id"];
|
|
11454
|
+
}
|
|
11455
|
+
async ensureTransientPipelineStarted() {
|
|
11456
|
+
if (this.ctx.options.popId != "transient" /* Transient */ || this._pipelineId) {
|
|
11457
|
+
return;
|
|
11458
|
+
}
|
|
11459
|
+
if (!this.ctx.options.pop) {
|
|
11460
|
+
return;
|
|
11461
|
+
}
|
|
11462
|
+
if (!this._baseUrl) {
|
|
11463
|
+
await this.reconnect();
|
|
11464
|
+
}
|
|
11465
|
+
if (this._pipelineId) {
|
|
11466
|
+
return;
|
|
11467
|
+
}
|
|
11468
|
+
if (this.ctx.options.pop) {
|
|
11469
|
+
await this.reconnect();
|
|
11470
|
+
if (!this._pipelineId) {
|
|
11471
|
+
throw new Error("Compute session did not provide a pipeline for the requested pop");
|
|
11472
|
+
}
|
|
11473
|
+
return;
|
|
11474
|
+
}
|
|
11475
|
+
if (!this._pipelineCreatePromise) {
|
|
11476
|
+
this._pipelineCreatePromise = this.startTransientPipeline();
|
|
11477
|
+
}
|
|
11478
|
+
try {
|
|
11479
|
+
this._pipelineId = await this._pipelineCreatePromise;
|
|
11480
|
+
this.setTransientPipelinePop();
|
|
11481
|
+
} finally {
|
|
11482
|
+
this._pipelineCreatePromise = null;
|
|
11483
|
+
}
|
|
11484
|
+
}
|
|
11485
|
+
async changeTransientPop(pop) {
|
|
11486
|
+
if (!this.ctx.client()) {
|
|
11487
|
+
throw new Error("endpoint not initialized");
|
|
11488
|
+
}
|
|
11489
|
+
const previousPop = this.ctx.options.pop;
|
|
11490
|
+
const previousBaseUrl = this._baseUrl;
|
|
11491
|
+
const previousSessionAccessToken = this._sessionAccessToken;
|
|
11492
|
+
const previousSessionAccessTokenValidUntil = this._sessionAccessTokenValidUntil;
|
|
11493
|
+
if (this._pipelineId) {
|
|
11494
|
+
await this.deleteTransientPipeline(this._pipelineId);
|
|
11495
|
+
this._pipelineId = null;
|
|
11496
|
+
}
|
|
11497
|
+
this._pipeline = null;
|
|
11498
|
+
try {
|
|
11499
|
+
this.ctx.options.pop = pop;
|
|
11500
|
+
await this.getComputeSession();
|
|
11501
|
+
} catch (error) {
|
|
11502
|
+
this.ctx.options.pop = previousPop;
|
|
11503
|
+
this._pipeline = null;
|
|
11504
|
+
this._pipelineId = null;
|
|
11505
|
+
this._baseUrl = previousPop ? null : previousBaseUrl;
|
|
11506
|
+
this._sessionAccessToken = previousSessionAccessToken;
|
|
11507
|
+
this._sessionAccessTokenValidUntil = previousSessionAccessTokenValidUntil;
|
|
11508
|
+
throw error;
|
|
11509
|
+
}
|
|
11510
|
+
if (!this._pipelineId) {
|
|
11511
|
+
throw new Error("Compute session did not provide a pipeline for the requested pop");
|
|
11512
|
+
}
|
|
11513
|
+
this.setTransientPipelinePop();
|
|
11514
|
+
}
|
|
11515
|
+
async deleteTransientPipeline(pipelineId) {
|
|
11516
|
+
const client = this.ctx.client();
|
|
11517
|
+
if (!client || !this._baseUrl) {
|
|
11518
|
+
return;
|
|
11519
|
+
}
|
|
11520
|
+
const deleteUrl = `${this._baseUrl}/pipelines/${pipelineId}`;
|
|
11521
|
+
const headers = {
|
|
11522
|
+
Authorization: await this.authorizationHeader()
|
|
11523
|
+
};
|
|
11524
|
+
let response = await client.fetch(deleteUrl, {
|
|
11525
|
+
method: "DELETE",
|
|
11526
|
+
headers
|
|
11527
|
+
});
|
|
11528
|
+
if (response.status >= 300) {
|
|
11052
11529
|
const message = await response.text();
|
|
11053
|
-
|
|
11530
|
+
this.ctx.logger.info(`stopping pipeline failed, status ${response.status}: ${message}`);
|
|
11054
11531
|
}
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11532
|
+
}
|
|
11533
|
+
async authorizationHeader() {
|
|
11534
|
+
if (this._sessionAccessToken) {
|
|
11535
|
+
return `Bearer ${this._sessionAccessToken}`;
|
|
11536
|
+
}
|
|
11537
|
+
return this.ctx.credentialHeader();
|
|
11538
|
+
}
|
|
11539
|
+
async computeAuthorizationHeader() {
|
|
11540
|
+
const auth = resolveAuth(this.ctx.options);
|
|
11541
|
+
if (auth?.isLocal !== void 0) {
|
|
11542
|
+
return "Implicit";
|
|
11543
|
+
}
|
|
11544
|
+
const credential = apiKeyCredential(auth) ?? accessTokenCredential(auth);
|
|
11545
|
+
if (credential !== void 0) {
|
|
11546
|
+
return `Bearer ${credential}`;
|
|
11547
|
+
}
|
|
11548
|
+
return this.ctx.credentialHeader();
|
|
11549
|
+
}
|
|
11550
|
+
setTransientPipelinePop() {
|
|
11551
|
+
const pop = this.ctx.options.pop;
|
|
11552
|
+
if (pop && this._pipelineId) {
|
|
11059
11553
|
this._pipeline = {
|
|
11060
|
-
id: this._pipelineId
|
|
11554
|
+
id: this._pipelineId,
|
|
11061
11555
|
state: "idle",
|
|
11062
11556
|
startTime: (/* @__PURE__ */ new Date()).toString(),
|
|
11063
11557
|
pop
|
|
11064
11558
|
};
|
|
11065
11559
|
}
|
|
11066
11560
|
}
|
|
11067
|
-
|
|
11068
|
-
|
|
11561
|
+
};
|
|
11562
|
+
_SessionBackend.WAIT_FOR_IS_READY = 60 * 1e3;
|
|
11563
|
+
var SessionBackend = _SessionBackend;
|
|
11564
|
+
|
|
11565
|
+
// shims/websockets.ts
|
|
11566
|
+
var createWebSocket;
|
|
11567
|
+
var UpgradeError = class extends Error {
|
|
11568
|
+
constructor(message, status, retryAfter) {
|
|
11569
|
+
super(message);
|
|
11570
|
+
this.name = "UpgradeError";
|
|
11571
|
+
this.status = status;
|
|
11572
|
+
this.retryAfter = retryAfter;
|
|
11069
11573
|
}
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
return
|
|
11574
|
+
};
|
|
11575
|
+
var openAuthorizedWebSocket;
|
|
11576
|
+
var isBrowser = "document" in globalThis && "implementation" in globalThis.document;
|
|
11577
|
+
if (isBrowser) {
|
|
11578
|
+
createWebSocket = (url, protocols) => {
|
|
11579
|
+
return new WebSocket(url, protocols);
|
|
11580
|
+
};
|
|
11581
|
+
openAuthorizedWebSocket = (url, protocol, token) => {
|
|
11582
|
+
const protocols = token === void 0 ? [protocol] : [protocol, `eyepop.bearer.${token}`];
|
|
11583
|
+
const ws = new WebSocket(url, protocols);
|
|
11584
|
+
ws.binaryType = "arraybuffer";
|
|
11585
|
+
return new Promise((resolve, reject) => {
|
|
11586
|
+
ws.onopen = () => resolve(ws);
|
|
11587
|
+
ws.onerror = () => reject(new UpgradeError(`could not open ${url}`));
|
|
11588
|
+
});
|
|
11589
|
+
};
|
|
11590
|
+
} else {
|
|
11591
|
+
createWebSocket = (url, protocols) => {
|
|
11592
|
+
const ws = require("ws");
|
|
11593
|
+
return new ws.WebSocket(url, protocols);
|
|
11594
|
+
};
|
|
11595
|
+
openAuthorizedWebSocket = (url, protocol, token) => {
|
|
11596
|
+
const ws = require("ws");
|
|
11597
|
+
const headers = token === void 0 ? {} : { Authorization: `Bearer ${token}` };
|
|
11598
|
+
const socket = new ws.WebSocket(url, [protocol], { headers, maxPayload: 0 });
|
|
11599
|
+
socket.binaryType = "arraybuffer";
|
|
11600
|
+
return new Promise((resolve, reject) => {
|
|
11601
|
+
socket.once("open", () => resolve(socket));
|
|
11602
|
+
socket.once("unexpected-response", (_request, response) => {
|
|
11603
|
+
const retryAfter = Number.parseFloat(response.headers?.["retry-after"]);
|
|
11604
|
+
reject(new UpgradeError(`the pipeline API answered the upgrade ${response.statusCode}`, response.statusCode, Number.isFinite(retryAfter) ? retryAfter : void 0));
|
|
11605
|
+
response.resume();
|
|
11606
|
+
socket.terminate();
|
|
11607
|
+
});
|
|
11608
|
+
socket.once("error", (error) => reject(new UpgradeError(`could not open ${url}: ${error.message}`)));
|
|
11609
|
+
});
|
|
11610
|
+
};
|
|
11611
|
+
}
|
|
11612
|
+
|
|
11613
|
+
// worker/pipeline_backend.ts
|
|
11614
|
+
var PIPELINE_PATH = "/api/v1/pipeline";
|
|
11615
|
+
var SUBPROTOCOL = "eyepop.v1";
|
|
11616
|
+
var MAX_OPEN_SOURCES = 256;
|
|
11617
|
+
var COMBINED_UPLOAD_MAX_BYTES = 8 * 1024 * 1024;
|
|
11618
|
+
var CHUNK = 1;
|
|
11619
|
+
var COMBINED = 2;
|
|
11620
|
+
var CHUNK_BYTES = 64 * 1024;
|
|
11621
|
+
var HEARTBEAT_MS = 20 * 1e3;
|
|
11622
|
+
var MAX_RETRY_MS = 30 * 1e3;
|
|
11623
|
+
var RECONNECT_AT_ONCE = /* @__PURE__ */ new Set(["1008 credential_expired", "1011 overloaded", "1001 shutting_down"]);
|
|
11624
|
+
var MAX_RECONNECT_DELAY_MS = 30 * 1e3;
|
|
11625
|
+
var PipelineConfigurationError = class extends Error {
|
|
11626
|
+
constructor(problem, message, options = []) {
|
|
11627
|
+
super(message);
|
|
11628
|
+
this.name = "PipelineConfigurationError";
|
|
11629
|
+
this.problem = problem;
|
|
11630
|
+
this.options = options;
|
|
11076
11631
|
}
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11632
|
+
};
|
|
11633
|
+
var PipelineSocketClosedError = class extends Error {
|
|
11634
|
+
constructor(code, reason) {
|
|
11635
|
+
super(`the pipeline API closed the socket: ${code ?? ""} ${reason}`.trim());
|
|
11636
|
+
this.name = "PipelineSocketClosedError";
|
|
11637
|
+
this.code = code;
|
|
11638
|
+
this.reason = reason;
|
|
11083
11639
|
}
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
} else if (source.url !== void 0) {
|
|
11092
|
-
return this.loadFrom(source, { componentParams: params });
|
|
11093
|
-
} else if (source.assetUuid !== void 0) {
|
|
11094
|
-
return this.loadFromAssetUuid(source, { componentParams: params });
|
|
11095
|
-
} else if (source.mediaStream !== void 0) {
|
|
11096
|
-
return this.loadMediaStream(source, { componentParams: params });
|
|
11097
|
-
} else {
|
|
11098
|
-
return Promise.reject("unknown source type");
|
|
11099
|
-
}
|
|
11640
|
+
};
|
|
11641
|
+
var PipelineCommandError = class extends Error {
|
|
11642
|
+
constructor(error, detail = "") {
|
|
11643
|
+
super(`the pipeline API refused the command: ${error} ${detail}`.trim());
|
|
11644
|
+
this.name = "PipelineCommandError";
|
|
11645
|
+
this.error = error;
|
|
11646
|
+
this.detail = detail;
|
|
11100
11647
|
}
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
|
|
11109
|
-
*/
|
|
11110
|
-
validateProcessParams(params) {
|
|
11111
|
-
if (params.camera !== void 0) {
|
|
11112
|
-
validateCamera(params.camera);
|
|
11113
|
-
}
|
|
11648
|
+
};
|
|
11649
|
+
var PipelineSourceError = class extends Error {
|
|
11650
|
+
constructor(sourceId, reason, detail = "") {
|
|
11651
|
+
super(`Error in source ${sourceId}: ${reason} ${detail}`.trim());
|
|
11652
|
+
this.name = "PipelineSourceError";
|
|
11653
|
+
this.sourceId = sourceId;
|
|
11654
|
+
this.reason = reason;
|
|
11655
|
+
this.detail = detail;
|
|
11114
11656
|
}
|
|
11115
|
-
|
|
11116
|
-
|
|
11117
|
-
|
|
11118
|
-
|
|
11119
|
-
|
|
11120
|
-
|
|
11121
|
-
|
|
11122
|
-
|
|
11123
|
-
|
|
11124
|
-
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
} else if (request.source.mediaStream !== void 0) {
|
|
11128
|
-
return this.loadMediaStream(request.source, request);
|
|
11657
|
+
};
|
|
11658
|
+
var CANCELLED = /* @__PURE__ */ Symbol("cancelled");
|
|
11659
|
+
var Inbox = class {
|
|
11660
|
+
constructor() {
|
|
11661
|
+
this._items = [];
|
|
11662
|
+
this._waiter = null;
|
|
11663
|
+
}
|
|
11664
|
+
push(item) {
|
|
11665
|
+
const waiter = this._waiter;
|
|
11666
|
+
if (waiter) {
|
|
11667
|
+
this._waiter = null;
|
|
11668
|
+
waiter(item);
|
|
11129
11669
|
} else {
|
|
11130
|
-
|
|
11670
|
+
this._items.push(item);
|
|
11131
11671
|
}
|
|
11132
11672
|
}
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11673
|
+
next() {
|
|
11674
|
+
const item = this._items.shift();
|
|
11675
|
+
if (item !== void 0) {
|
|
11676
|
+
return Promise.resolve(item);
|
|
11136
11677
|
}
|
|
11137
|
-
this.
|
|
11138
|
-
|
|
11139
|
-
|
|
11678
|
+
return new Promise((resolve) => this._waiter = resolve);
|
|
11679
|
+
}
|
|
11680
|
+
};
|
|
11681
|
+
var UploadEnded = class extends Error {
|
|
11682
|
+
};
|
|
11683
|
+
var Credit = class {
|
|
11684
|
+
constructor() {
|
|
11685
|
+
this._credit = 0;
|
|
11686
|
+
this._ended = false;
|
|
11687
|
+
this._waiter = null;
|
|
11688
|
+
}
|
|
11689
|
+
grant(n) {
|
|
11690
|
+
this._credit += n;
|
|
11691
|
+
this.wake();
|
|
11692
|
+
}
|
|
11693
|
+
end() {
|
|
11694
|
+
this._ended = true;
|
|
11695
|
+
this.wake();
|
|
11696
|
+
}
|
|
11697
|
+
async take(most) {
|
|
11698
|
+
while (this._credit <= 0 && !this._ended) {
|
|
11699
|
+
await new Promise((resolve) => this._waiter = resolve);
|
|
11140
11700
|
}
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
this.updateState();
|
|
11144
|
-
const sources = await Promise.all(
|
|
11145
|
-
paths.map(async (path2) => {
|
|
11146
|
-
let streamSource;
|
|
11147
|
-
if (this._options.platformSupport?.resolvePath) {
|
|
11148
|
-
streamSource = await this._options.platformSupport.resolvePath({ path: path2 }, this._logger);
|
|
11149
|
-
} else {
|
|
11150
|
-
streamSource = await resolvePath({ path: path2 }, this._logger);
|
|
11151
|
-
}
|
|
11152
|
-
return { stream: streamSource.stream, mimeType: streamSource.mimeType };
|
|
11153
|
-
})
|
|
11154
|
-
);
|
|
11155
|
-
const job = new UploadGroupJob(sources, params, async () => this.session(), this._client, this._requestLogger, this.predictionVersion());
|
|
11156
|
-
return job.start(
|
|
11157
|
-
() => {
|
|
11158
|
-
this.jobDone(job);
|
|
11159
|
-
},
|
|
11160
|
-
(statusCode) => {
|
|
11161
|
-
this.jobStatus(job, statusCode);
|
|
11162
|
-
}
|
|
11163
|
-
);
|
|
11164
|
-
} catch (e) {
|
|
11165
|
-
this._limit.release();
|
|
11166
|
-
throw e;
|
|
11701
|
+
if (this._ended) {
|
|
11702
|
+
throw new UploadEnded();
|
|
11167
11703
|
}
|
|
11704
|
+
const n = Math.min(most, this._credit);
|
|
11705
|
+
this._credit -= n;
|
|
11706
|
+
return n;
|
|
11168
11707
|
}
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11708
|
+
wake() {
|
|
11709
|
+
const waiter = this._waiter;
|
|
11710
|
+
this._waiter = null;
|
|
11711
|
+
waiter?.();
|
|
11712
|
+
}
|
|
11713
|
+
};
|
|
11714
|
+
var OpenSource = class {
|
|
11715
|
+
constructor(id) {
|
|
11716
|
+
this.id = id;
|
|
11717
|
+
this.inbox = new Inbox();
|
|
11718
|
+
this.uploads = /* @__PURE__ */ new Map();
|
|
11719
|
+
}
|
|
11720
|
+
close(error) {
|
|
11721
|
+
this.uploads.forEach((upload) => upload.end());
|
|
11722
|
+
this.inbox.push(error);
|
|
11723
|
+
}
|
|
11724
|
+
};
|
|
11725
|
+
var PipelineSocket = class {
|
|
11726
|
+
constructor(ws) {
|
|
11727
|
+
this.ws = ws;
|
|
11728
|
+
this.sources = /* @__PURE__ */ new Map();
|
|
11729
|
+
this.commands = /* @__PURE__ */ new Map();
|
|
11730
|
+
this._closed = false;
|
|
11731
|
+
this.closed = new Promise((resolve) => this._markClosed = resolve);
|
|
11732
|
+
}
|
|
11733
|
+
get open() {
|
|
11734
|
+
return !this._closed && this.ws.readyState === 1;
|
|
11735
|
+
}
|
|
11736
|
+
markClosed() {
|
|
11737
|
+
this._closed = true;
|
|
11738
|
+
this._markClosed();
|
|
11739
|
+
}
|
|
11740
|
+
sendJson(message) {
|
|
11741
|
+
this.ws.send(JSON.stringify(message));
|
|
11742
|
+
}
|
|
11743
|
+
sendBytes(data) {
|
|
11744
|
+
this.ws.send(data);
|
|
11745
|
+
}
|
|
11746
|
+
};
|
|
11747
|
+
var PipelineJob = class {
|
|
11748
|
+
constructor(source, media, live, params, mediaStream = void 0) {
|
|
11749
|
+
this.source = source;
|
|
11750
|
+
this.media = media;
|
|
11751
|
+
this.live = live;
|
|
11752
|
+
this.params = params;
|
|
11753
|
+
this.mediaStream = mediaStream;
|
|
11754
|
+
this._results = new Inbox();
|
|
11755
|
+
this._consumed = false;
|
|
11756
|
+
this._cancelled = false;
|
|
11757
|
+
this.openSource = null;
|
|
11758
|
+
// Stops the job's source on the pipeline, once it was sent.
|
|
11759
|
+
this.stopOnPipeline = null;
|
|
11760
|
+
}
|
|
11761
|
+
get cancelled() {
|
|
11762
|
+
return this._cancelled;
|
|
11763
|
+
}
|
|
11764
|
+
command(id) {
|
|
11765
|
+
const command = { type: "setSource", id, ...this.source };
|
|
11766
|
+
if (this.params.componentParams !== void 0) {
|
|
11767
|
+
command["params"] = this.params.componentParams;
|
|
11172
11768
|
}
|
|
11173
|
-
if (
|
|
11174
|
-
|
|
11769
|
+
if (this.params.roi !== void 0) {
|
|
11770
|
+
command["roi"] = this.params.roi;
|
|
11175
11771
|
}
|
|
11176
|
-
this.
|
|
11177
|
-
|
|
11178
|
-
throw new Error("endpoint not connected, use connect()");
|
|
11772
|
+
if (this.params.camera !== void 0) {
|
|
11773
|
+
command["camera"] = this.params.camera;
|
|
11179
11774
|
}
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
this.updateState();
|
|
11183
|
-
const sources = streams.map((stream, i) => ({
|
|
11184
|
-
stream,
|
|
11185
|
-
mimeType: mimeTypes?.[i] ?? null
|
|
11186
|
-
}));
|
|
11187
|
-
const job = new UploadGroupJob(sources, params, async () => this.session(), this._client, this._requestLogger, this.predictionVersion());
|
|
11188
|
-
return job.start(
|
|
11189
|
-
() => {
|
|
11190
|
-
this.jobDone(job);
|
|
11191
|
-
},
|
|
11192
|
-
(statusCode) => {
|
|
11193
|
-
this.jobStatus(job, statusCode);
|
|
11194
|
-
}
|
|
11195
|
-
);
|
|
11196
|
-
} catch (e) {
|
|
11197
|
-
this._limit.release();
|
|
11198
|
-
throw e;
|
|
11775
|
+
if (this.params.fps !== void 0) {
|
|
11776
|
+
command["fps"] = this.params.fps;
|
|
11199
11777
|
}
|
|
11778
|
+
return command;
|
|
11200
11779
|
}
|
|
11201
|
-
|
|
11202
|
-
if (
|
|
11203
|
-
|
|
11204
|
-
}
|
|
11205
|
-
this.validateProcessParams(params);
|
|
11206
|
-
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
11207
|
-
throw new Error("endpoint not connected, use connect()");
|
|
11208
|
-
}
|
|
11209
|
-
await this._limit.acquire();
|
|
11210
|
-
try {
|
|
11211
|
-
this.updateState();
|
|
11212
|
-
const job = new LoadFromGroupJob(urls, params, async () => this.session(), this._client, this._requestLogger, this.predictionVersion());
|
|
11213
|
-
return job.start(
|
|
11214
|
-
() => {
|
|
11215
|
-
this.jobDone(job);
|
|
11216
|
-
},
|
|
11217
|
-
(statusCode) => {
|
|
11218
|
-
this.jobStatus(job, statusCode);
|
|
11219
|
-
}
|
|
11220
|
-
);
|
|
11221
|
-
} catch (e) {
|
|
11222
|
-
this._limit.release();
|
|
11223
|
-
throw e;
|
|
11780
|
+
predicted(prediction) {
|
|
11781
|
+
if (!this._cancelled) {
|
|
11782
|
+
this._results.push(prediction);
|
|
11224
11783
|
}
|
|
11225
11784
|
}
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
return Promise.reject("endpoint not connected, use connect()");
|
|
11230
|
-
}
|
|
11231
|
-
await this._limit.acquire();
|
|
11232
|
-
try {
|
|
11233
|
-
this.updateState();
|
|
11234
|
-
const job = new UploadJob(
|
|
11235
|
-
source.file,
|
|
11236
|
-
source.file.type,
|
|
11237
|
-
source.file.size,
|
|
11238
|
-
source.videoMode,
|
|
11239
|
-
params,
|
|
11240
|
-
async () => {
|
|
11241
|
-
return this.session();
|
|
11242
|
-
},
|
|
11243
|
-
this._client,
|
|
11244
|
-
this._requestLogger,
|
|
11245
|
-
void 0,
|
|
11246
|
-
this.predictionVersion()
|
|
11247
|
-
);
|
|
11248
|
-
return job.start(
|
|
11249
|
-
() => {
|
|
11250
|
-
this.jobDone(job);
|
|
11251
|
-
},
|
|
11252
|
-
(statusCode) => {
|
|
11253
|
-
this.jobStatus(job, statusCode);
|
|
11254
|
-
}
|
|
11255
|
-
);
|
|
11256
|
-
} catch (e) {
|
|
11257
|
-
this._limit.release();
|
|
11258
|
-
throw e;
|
|
11785
|
+
finish(error = null) {
|
|
11786
|
+
if (error !== null) {
|
|
11787
|
+
this._results.push(error);
|
|
11259
11788
|
}
|
|
11789
|
+
this._results.push(null);
|
|
11260
11790
|
}
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
return Promise.reject("endpoint not connected, use connect()");
|
|
11265
|
-
}
|
|
11266
|
-
await this._limit.acquire();
|
|
11267
|
-
try {
|
|
11268
|
-
this.updateState();
|
|
11269
|
-
const job = new UploadJob(
|
|
11270
|
-
source.stream,
|
|
11271
|
-
source.mimeType,
|
|
11272
|
-
source.size,
|
|
11273
|
-
source.videoMode,
|
|
11274
|
-
params,
|
|
11275
|
-
async () => {
|
|
11276
|
-
return this.session();
|
|
11277
|
-
},
|
|
11278
|
-
this._client,
|
|
11279
|
-
this._requestLogger,
|
|
11280
|
-
void 0,
|
|
11281
|
-
this.predictionVersion()
|
|
11282
|
-
);
|
|
11283
|
-
return job.start(
|
|
11284
|
-
() => {
|
|
11285
|
-
this.jobDone(job);
|
|
11286
|
-
},
|
|
11287
|
-
(statusCode) => {
|
|
11288
|
-
this.jobStatus(job, statusCode);
|
|
11289
|
-
}
|
|
11290
|
-
);
|
|
11291
|
-
} catch (e) {
|
|
11292
|
-
this._limit.release();
|
|
11293
|
-
throw e;
|
|
11791
|
+
cancel() {
|
|
11792
|
+
if (this._cancelled) {
|
|
11793
|
+
return;
|
|
11294
11794
|
}
|
|
11795
|
+
this._cancelled = true;
|
|
11796
|
+
this._results.push(null);
|
|
11797
|
+
this.openSource?.inbox.push(CANCELLED);
|
|
11798
|
+
this.stopOnPipeline?.();
|
|
11295
11799
|
}
|
|
11296
|
-
async
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
throw new Error("endpoint not connected, use connect()");
|
|
11800
|
+
async *[Symbol.asyncIterator]() {
|
|
11801
|
+
if (this._consumed) {
|
|
11802
|
+
throw new Error("Cannot iterate over a consumed stream");
|
|
11300
11803
|
}
|
|
11301
|
-
|
|
11302
|
-
|
|
11303
|
-
this.
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
|
|
11309
|
-
}
|
|
11310
|
-
|
|
11311
|
-
let firstStreamPending = true;
|
|
11312
|
-
const uploadBodyFactory = async () => {
|
|
11313
|
-
if (firstStreamPending) {
|
|
11314
|
-
firstStreamPending = false;
|
|
11315
|
-
return streamSource.stream;
|
|
11316
|
-
}
|
|
11317
|
-
return (await resolveStreamSource()).stream;
|
|
11318
|
-
};
|
|
11319
|
-
const job = new UploadJob(
|
|
11320
|
-
streamSource.stream,
|
|
11321
|
-
streamSource.mimeType,
|
|
11322
|
-
streamSource.size,
|
|
11323
|
-
source.videoMode,
|
|
11324
|
-
params,
|
|
11325
|
-
async () => {
|
|
11326
|
-
return this.session();
|
|
11327
|
-
},
|
|
11328
|
-
this._client,
|
|
11329
|
-
this._requestLogger,
|
|
11330
|
-
uploadBodyFactory,
|
|
11331
|
-
this.predictionVersion()
|
|
11332
|
-
);
|
|
11333
|
-
return job.start(
|
|
11334
|
-
() => {
|
|
11335
|
-
this.jobDone(job);
|
|
11336
|
-
},
|
|
11337
|
-
(statusCode) => {
|
|
11338
|
-
this.jobStatus(job, statusCode);
|
|
11339
|
-
}
|
|
11340
|
-
);
|
|
11341
|
-
} catch (e) {
|
|
11342
|
-
this._limit.release();
|
|
11343
|
-
throw e;
|
|
11804
|
+
this._consumed = true;
|
|
11805
|
+
while (true) {
|
|
11806
|
+
const item = await this._results.next();
|
|
11807
|
+
if (item === null) {
|
|
11808
|
+
return;
|
|
11809
|
+
}
|
|
11810
|
+
if (item instanceof Error) {
|
|
11811
|
+
throw item;
|
|
11812
|
+
}
|
|
11813
|
+
yield item;
|
|
11344
11814
|
}
|
|
11345
11815
|
}
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
|
|
11350
|
-
|
|
11351
|
-
|
|
11352
|
-
|
|
11353
|
-
|
|
11816
|
+
};
|
|
11817
|
+
var PipelineBackend = class {
|
|
11818
|
+
constructor(ctx) {
|
|
11819
|
+
this.ctx = ctx;
|
|
11820
|
+
this._pipelineApiUrl = null;
|
|
11821
|
+
this._socket = null;
|
|
11822
|
+
this._connecting = null;
|
|
11823
|
+
// Every job's setSource and every changePop goes out through this chain, in the order submitted.
|
|
11824
|
+
this._sendChain = Promise.resolve();
|
|
11825
|
+
this._disconnecting = false;
|
|
11826
|
+
this._nextId = 0;
|
|
11827
|
+
this._warned = /* @__PURE__ */ new Set();
|
|
11828
|
+
this._heartbeat = null;
|
|
11829
|
+
// Reconnects at once since a source last played.
|
|
11830
|
+
this._reconnects = 0;
|
|
11831
|
+
this._currentPop = ctx.options.pop ?? null;
|
|
11832
|
+
}
|
|
11833
|
+
// Connection
|
|
11834
|
+
async reconnect() {
|
|
11835
|
+
this._disconnecting = false;
|
|
11836
|
+
await this.inOrder(() => this.ensureSocket());
|
|
11837
|
+
this.ctx.updateState();
|
|
11838
|
+
}
|
|
11839
|
+
async disconnect(closeEndpoint) {
|
|
11840
|
+
await closeEndpoint();
|
|
11841
|
+
this._disconnecting = true;
|
|
11842
|
+
if (this._heartbeat !== null) {
|
|
11843
|
+
clearInterval(this._heartbeat);
|
|
11844
|
+
this._heartbeat = null;
|
|
11354
11845
|
}
|
|
11355
|
-
|
|
11356
|
-
|
|
11357
|
-
|
|
11846
|
+
const socket = this._socket;
|
|
11847
|
+
this._socket = null;
|
|
11848
|
+
if (socket !== null) {
|
|
11849
|
+
socket.ws.close(1e3);
|
|
11850
|
+
await socket.closed;
|
|
11358
11851
|
}
|
|
11359
|
-
|
|
11360
|
-
|
|
11361
|
-
|
|
11362
|
-
|
|
11363
|
-
|
|
11364
|
-
|
|
11365
|
-
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
this.jobStatus(job, statusCode);
|
|
11378
|
-
}
|
|
11379
|
-
);
|
|
11380
|
-
} catch (e) {
|
|
11381
|
-
this._limit.release();
|
|
11382
|
-
throw e;
|
|
11852
|
+
}
|
|
11853
|
+
onStatus(_statusCode) {
|
|
11854
|
+
}
|
|
11855
|
+
popName() {
|
|
11856
|
+
return null;
|
|
11857
|
+
}
|
|
11858
|
+
async authorizationHeader() {
|
|
11859
|
+
return this.ctx.credentialHeader();
|
|
11860
|
+
}
|
|
11861
|
+
inOrder(work) {
|
|
11862
|
+
const result = this._sendChain.then(work);
|
|
11863
|
+
this._sendChain = result.catch(() => void 0);
|
|
11864
|
+
return result;
|
|
11865
|
+
}
|
|
11866
|
+
/** The open socket, or a new one with the last pop set on it. */
|
|
11867
|
+
async ensureSocket() {
|
|
11868
|
+
if (this._socket !== null && this._socket.open) {
|
|
11869
|
+
return this._socket;
|
|
11383
11870
|
}
|
|
11871
|
+
if (this._connecting === null) {
|
|
11872
|
+
this._connecting = this.openSocket().finally(() => this._connecting = null);
|
|
11873
|
+
}
|
|
11874
|
+
return await this._connecting;
|
|
11384
11875
|
}
|
|
11385
|
-
async
|
|
11386
|
-
|
|
11387
|
-
|
|
11388
|
-
throw new Error("endpoint not connected, use connect()");
|
|
11876
|
+
async openSocket() {
|
|
11877
|
+
if (this.ctx.client() === null) {
|
|
11878
|
+
throw new PipelineSocketClosedError(void 0, "the endpoint is not connected");
|
|
11389
11879
|
}
|
|
11390
|
-
await this.
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
|
|
11394
|
-
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
},
|
|
11399
|
-
this._client,
|
|
11400
|
-
this._requestLogger,
|
|
11401
|
-
this.predictionVersion()
|
|
11402
|
-
);
|
|
11403
|
-
return job.start(
|
|
11404
|
-
() => {
|
|
11405
|
-
this.jobDone(job);
|
|
11406
|
-
},
|
|
11407
|
-
(statusCode) => {
|
|
11408
|
-
this.jobStatus(job, statusCode);
|
|
11880
|
+
const ws = await this.upgrade(await this.socketUrl());
|
|
11881
|
+
const socket = new PipelineSocket(ws);
|
|
11882
|
+
ws.onmessage = (event) => {
|
|
11883
|
+
if (typeof event.data === "string") {
|
|
11884
|
+
try {
|
|
11885
|
+
this.dispatch(socket, JSON.parse(event.data));
|
|
11886
|
+
} catch (error) {
|
|
11887
|
+
this.ctx.logger.warn("unreadable message from the pipeline API: %s", error);
|
|
11409
11888
|
}
|
|
11410
|
-
|
|
11411
|
-
}
|
|
11412
|
-
|
|
11413
|
-
|
|
11889
|
+
}
|
|
11890
|
+
};
|
|
11891
|
+
ws.onerror = () => {
|
|
11892
|
+
};
|
|
11893
|
+
ws.onclose = (event) => this.closed(socket, event.code, event.reason);
|
|
11894
|
+
this._socket = socket;
|
|
11895
|
+
this.startHeartbeat(ws);
|
|
11896
|
+
if (this._currentPop !== null) {
|
|
11897
|
+
try {
|
|
11898
|
+
await this.setPopOn(socket, this._currentPop);
|
|
11899
|
+
} catch (error) {
|
|
11900
|
+
this._socket = null;
|
|
11901
|
+
ws.close(1e3);
|
|
11902
|
+
throw error;
|
|
11903
|
+
}
|
|
11414
11904
|
}
|
|
11905
|
+
return socket;
|
|
11415
11906
|
}
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
throw new Error("endpoint not connected, use connect()");
|
|
11907
|
+
startHeartbeat(ws) {
|
|
11908
|
+
if (this._heartbeat !== null) {
|
|
11909
|
+
clearInterval(this._heartbeat);
|
|
11420
11910
|
}
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
this.
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
params,
|
|
11427
|
-
async () => {
|
|
11428
|
-
return this.session();
|
|
11429
|
-
},
|
|
11430
|
-
this._client,
|
|
11431
|
-
this._requestLogger,
|
|
11432
|
-
this.predictionVersion()
|
|
11433
|
-
);
|
|
11434
|
-
return job.start(
|
|
11435
|
-
() => {
|
|
11436
|
-
this.jobDone(job);
|
|
11437
|
-
},
|
|
11438
|
-
(statusCode) => {
|
|
11439
|
-
this.jobStatus(job, statusCode);
|
|
11911
|
+
const ping = ws.ping;
|
|
11912
|
+
if (typeof ping === "function") {
|
|
11913
|
+
this._heartbeat = setInterval(() => {
|
|
11914
|
+
if (ws.readyState === 1) {
|
|
11915
|
+
ping.call(ws);
|
|
11440
11916
|
}
|
|
11441
|
-
);
|
|
11442
|
-
|
|
11443
|
-
this._limit.release();
|
|
11444
|
-
throw e;
|
|
11917
|
+
}, HEARTBEAT_MS);
|
|
11918
|
+
this._heartbeat.unref?.();
|
|
11445
11919
|
}
|
|
11446
11920
|
}
|
|
11447
|
-
|
|
11448
|
-
this.
|
|
11449
|
-
|
|
11921
|
+
async socketUrl() {
|
|
11922
|
+
if (this._pipelineApiUrl === null) {
|
|
11923
|
+
const base = this.ctx.options.isLocalMode ? this.ctx.eyepopUrl() : new URL(await this.configuredPipelineApiUrl(), this.ctx.eyepopUrl() + "/").toString();
|
|
11924
|
+
this._pipelineApiUrl = checkedUrl(base);
|
|
11925
|
+
}
|
|
11926
|
+
return "ws" + this._pipelineApiUrl.slice("http".length) + PIPELINE_PATH;
|
|
11450
11927
|
}
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11928
|
+
async configuredPipelineApiUrl() {
|
|
11929
|
+
const client = this.ctx.client();
|
|
11930
|
+
if (client === null) {
|
|
11931
|
+
throw new Error("endpoint not connected");
|
|
11932
|
+
}
|
|
11933
|
+
let configUrl = `${this.ctx.eyepopUrl()}/v1/configs`;
|
|
11934
|
+
const accountId = this.ctx.options.accountId;
|
|
11935
|
+
if (accountId) {
|
|
11936
|
+
configUrl += `?account_uuid=${encodeURIComponent(accountId)}`;
|
|
11937
|
+
}
|
|
11938
|
+
const response = await this.ctx.fetchWithRetry(async () => client.fetch(configUrl, { headers: { Authorization: await this.ctx.credentialHeader() } }));
|
|
11939
|
+
if (!response.ok) {
|
|
11940
|
+
throw new Error(`Unexpected status ${response.status} for GET ${configUrl}: ${await response.text()}`);
|
|
11941
|
+
}
|
|
11942
|
+
const config = await response.json();
|
|
11943
|
+
const url = config?.["pipeline_api_url"];
|
|
11944
|
+
if (!url) {
|
|
11945
|
+
throw new PipelineConfigurationError("no_pipeline_api_url", `${configUrl} has no pipeline_api_url: this compute API serves no pipeline API`);
|
|
11946
|
+
}
|
|
11947
|
+
return url;
|
|
11948
|
+
}
|
|
11949
|
+
async token() {
|
|
11950
|
+
if (resolveAuth(this.ctx.options)?.isLocal !== void 0) {
|
|
11951
|
+
return void 0;
|
|
11456
11952
|
}
|
|
11953
|
+
return (await this.ctx.credentialHeader()).replace(/^Bearer /, "");
|
|
11457
11954
|
}
|
|
11458
|
-
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11955
|
+
/** Open the socket, waiting through 503 with Retry-After and exchanging the API key again after a 401. */
|
|
11956
|
+
async upgrade(url) {
|
|
11957
|
+
const deadline = Date.now() + MAX_RETRY_MS;
|
|
11958
|
+
let rejected = false;
|
|
11959
|
+
while (true) {
|
|
11960
|
+
try {
|
|
11961
|
+
this.ctx.requestLogger.debug("before upgrade %s", url);
|
|
11962
|
+
return await openAuthorizedWebSocket(url, SUBPROTOCOL, await this.token());
|
|
11963
|
+
} catch (error) {
|
|
11964
|
+
if (!(error instanceof UpgradeError)) {
|
|
11965
|
+
throw error;
|
|
11966
|
+
}
|
|
11967
|
+
if (error.status === 401 && !rejected) {
|
|
11968
|
+
this.ctx.requestLogger.debug("the pipeline API answered 401, authenticating again");
|
|
11969
|
+
rejected = true;
|
|
11970
|
+
this.ctx.forgetCredential();
|
|
11971
|
+
continue;
|
|
11972
|
+
}
|
|
11973
|
+
const wait = error.status === 503 && error.retryAfter !== void 0 ? Math.max(error.retryAfter, 1) * 1e3 : void 0;
|
|
11974
|
+
if (wait === void 0 || Date.now() + wait > deadline) {
|
|
11975
|
+
throw error;
|
|
11976
|
+
}
|
|
11977
|
+
this.ctx.requestLogger.info("the pipeline API answered 503, retrying in %d ms", wait);
|
|
11978
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
11463
11979
|
}
|
|
11464
|
-
} else if (this.options().sessionUuid) {
|
|
11465
|
-
await this.getComputeSession();
|
|
11466
|
-
} else {
|
|
11467
|
-
await this.startWebApiSessionWithPopId();
|
|
11468
11980
|
}
|
|
11469
|
-
this.updateState();
|
|
11470
|
-
return Promise.resolve(this);
|
|
11471
11981
|
}
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
11982
|
+
closed(socket, code, reason) {
|
|
11983
|
+
socket.markClosed();
|
|
11984
|
+
if (this._socket === socket) {
|
|
11985
|
+
this._socket = null;
|
|
11475
11986
|
}
|
|
11476
|
-
const
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
this.
|
|
11481
|
-
|
|
11482
|
-
if (response.status == 401) {
|
|
11483
|
-
this._requestLogger.debug("GET %s: 401, about to retry with fresh access token", config_url);
|
|
11484
|
-
this.statusHandler401(response.status);
|
|
11485
|
-
const headers2 = {
|
|
11486
|
-
Authorization: await this.authorizationHeader()
|
|
11487
|
-
};
|
|
11488
|
-
this.updateState("FetchConfig" /* FetchConfig */);
|
|
11489
|
-
response = await this._client.fetch(config_url, {
|
|
11490
|
-
headers: headers2
|
|
11491
|
-
});
|
|
11987
|
+
const error = new PipelineSocketClosedError(code, reason);
|
|
11988
|
+
socket.sources.forEach((source) => source.close(error));
|
|
11989
|
+
socket.commands.forEach((command) => command.reject(error));
|
|
11990
|
+
socket.commands.clear();
|
|
11991
|
+
if (this._disconnecting) {
|
|
11992
|
+
return;
|
|
11492
11993
|
}
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
if (
|
|
11496
|
-
this.
|
|
11497
|
-
} else {
|
|
11498
|
-
this.updateState("Error" /* Error */, message);
|
|
11994
|
+
this.ctx.requestLogger.debug("the pipeline API closed the socket: %s %s", code, reason);
|
|
11995
|
+
if (RECONNECT_AT_ONCE.has(`${code} ${reason}`)) {
|
|
11996
|
+
if (reason === "credential_expired") {
|
|
11997
|
+
this.ctx.forgetCredential();
|
|
11499
11998
|
}
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
const auto_start_config_url = `${this.eyepopWebApiUrl()}/pops/${this.options().popId}/config?auto_start=true`;
|
|
11505
|
-
this._requestLogger.debug("pop was not running, trying to autostart with: %s", auto_start_config_url);
|
|
11506
|
-
const headers2 = {
|
|
11507
|
-
Authorization: await this.authorizationHeader()
|
|
11508
|
-
};
|
|
11509
|
-
response = await this._client.fetch(auto_start_config_url, {
|
|
11510
|
-
headers: headers2
|
|
11999
|
+
const delay = this._reconnects === 0 ? 0 : Math.min(1e3 * 2 ** (this._reconnects - 1), MAX_RECONNECT_DELAY_MS);
|
|
12000
|
+
this._reconnects += 1;
|
|
12001
|
+
new Promise((resolve) => setTimeout(resolve, delay)).then(() => this._disconnecting ? void 0 : this.inOrder(() => this.ensureSocket())).catch((error2) => {
|
|
12002
|
+
this.ctx.requestLogger.info("could not reopen the pipeline API socket: %s", error2);
|
|
11511
12003
|
});
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
12004
|
+
}
|
|
12005
|
+
}
|
|
12006
|
+
dispatch(socket, message) {
|
|
12007
|
+
const type = message["type"];
|
|
12008
|
+
const id = message["id"];
|
|
12009
|
+
const source = typeof id === "string" ? socket.sources.get(id) : void 0;
|
|
12010
|
+
if (type === "send" || type === "credit") {
|
|
12011
|
+
const upload = source?.uploads.get(message["member"] ?? null);
|
|
12012
|
+
upload?.grant(Number(type === "send" ? message["credit"] : message["bytes"]));
|
|
12013
|
+
return;
|
|
12014
|
+
}
|
|
12015
|
+
const command = typeof id === "string" ? socket.commands.get(id) : void 0;
|
|
12016
|
+
if (command !== void 0) {
|
|
12017
|
+
socket.commands.delete(id);
|
|
12018
|
+
if (type === "error") {
|
|
12019
|
+
command.reject(new PipelineCommandError(message["error"] ?? "", message["message"] ?? ""));
|
|
12020
|
+
} else {
|
|
12021
|
+
command.resolve(message);
|
|
11516
12022
|
}
|
|
11517
|
-
|
|
12023
|
+
return;
|
|
11518
12024
|
}
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
this._baseUrl = this._baseUrl.replace(/\/+$/, "");
|
|
11523
|
-
this._pipelineId = config.pipeline_id;
|
|
11524
|
-
this._popName = config.name;
|
|
11525
|
-
if (!this._pipelineId || !this._baseUrl) {
|
|
11526
|
-
throw new Error("Pop not started");
|
|
12025
|
+
if (source !== void 0) {
|
|
12026
|
+
if (type === "start") {
|
|
12027
|
+
this._reconnects = 0;
|
|
11527
12028
|
}
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
Authorization: await this.authorizationHeader()
|
|
11531
|
-
};
|
|
11532
|
-
let response2 = await this._client.fetch(get_url, {
|
|
11533
|
-
method: "GET",
|
|
11534
|
-
headers: headers2
|
|
11535
|
-
});
|
|
11536
|
-
if (response2.status > 200) {
|
|
11537
|
-
const message = await response2.text();
|
|
11538
|
-
throw new Error(`Unexpected status ${response2.status}: ${message}`);
|
|
12029
|
+
if (type === "end") {
|
|
12030
|
+
source.uploads.forEach((upload) => upload.end());
|
|
11539
12031
|
}
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
};
|
|
11547
|
-
const stop_url = `${this._baseUrl}/pipelines/${this._pipeline.id}/source?mode=preempt&processing=sync`;
|
|
11548
|
-
let response3 = await this._client.fetch(stop_url, {
|
|
11549
|
-
method: "PATCH",
|
|
11550
|
-
headers: headers3,
|
|
11551
|
-
body: JSON.stringify(body)
|
|
11552
|
-
});
|
|
11553
|
-
if (response3.status >= 300) {
|
|
11554
|
-
const message = await response3.text();
|
|
11555
|
-
throw new Error(`Unexpected status ${response3.status}: ${message}`);
|
|
11556
|
-
}
|
|
12032
|
+
source.inbox.push(message);
|
|
12033
|
+
} else if (type === "error") {
|
|
12034
|
+
if (id === void 0) {
|
|
12035
|
+
this.ctx.logger.warn("the pipeline API refused a message: %s %s", message["error"], message["message"]);
|
|
12036
|
+
} else {
|
|
12037
|
+
this.ctx.requestLogger.debug("the pipeline API refused a command for %s: %s %s", id, message["error"], message["message"]);
|
|
11557
12038
|
}
|
|
11558
12039
|
}
|
|
11559
12040
|
}
|
|
11560
|
-
|
|
11561
|
-
|
|
11562
|
-
return
|
|
12041
|
+
newId(prefix) {
|
|
12042
|
+
this._nextId += 1;
|
|
12043
|
+
return `${prefix}-${this._nextId}`;
|
|
11563
12044
|
}
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
12045
|
+
/** Send a command that is answered by `result` or `error` under its id. */
|
|
12046
|
+
command(socket, message) {
|
|
12047
|
+
const id = this.newId(message["type"]);
|
|
12048
|
+
return new Promise((resolve, reject) => {
|
|
12049
|
+
socket.commands.set(id, { resolve, reject });
|
|
12050
|
+
socket.sendJson({ ...message, id });
|
|
12051
|
+
});
|
|
12052
|
+
}
|
|
12053
|
+
// Pop
|
|
12054
|
+
pop() {
|
|
12055
|
+
return this._currentPop;
|
|
12056
|
+
}
|
|
12057
|
+
/** Set the pop on the socket's pipeline; a pop it refuses rejects, and the last pop it took stays. */
|
|
12058
|
+
async changePop(pop) {
|
|
12059
|
+
if (this.ctx.client() === null) {
|
|
12060
|
+
this._currentPop = pop;
|
|
12061
|
+
return;
|
|
11567
12062
|
}
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
12063
|
+
await this.inOrder(async () => {
|
|
12064
|
+
if (this._socket !== null && this._socket.open) {
|
|
12065
|
+
await this.setPopOn(this._socket, pop);
|
|
12066
|
+
this._currentPop = pop;
|
|
12067
|
+
return;
|
|
12068
|
+
}
|
|
12069
|
+
const previous = this._currentPop;
|
|
12070
|
+
this._currentPop = pop;
|
|
12071
|
+
try {
|
|
12072
|
+
await this.ensureSocket();
|
|
12073
|
+
} catch (error) {
|
|
12074
|
+
this._currentPop = previous;
|
|
12075
|
+
throw error;
|
|
12076
|
+
}
|
|
12077
|
+
});
|
|
12078
|
+
}
|
|
12079
|
+
async setPopOn(socket, pop) {
|
|
12080
|
+
await this.command(socket, { type: "setPop", pop });
|
|
12081
|
+
}
|
|
12082
|
+
// Jobs
|
|
12083
|
+
async submit(work) {
|
|
12084
|
+
if (this.ctx.client() === null) {
|
|
12085
|
+
throw new Error("endpoint not connected, use connect()");
|
|
11587
12086
|
}
|
|
11588
|
-
|
|
11589
|
-
this.
|
|
11590
|
-
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
this.
|
|
11594
|
-
|
|
11595
|
-
|
|
12087
|
+
const sourceOptions = work.kind === "source" ? work.source : void 0;
|
|
12088
|
+
this.notSent({ motionDetect: work.params.motionDetect, videoMode: sourceOptions?.videoMode, rtspForceNonCompliantUrl: work.params.rtspForceNonCompliantUrl });
|
|
12089
|
+
const job = await this.jobOf(work);
|
|
12090
|
+
const limit = this.ctx.limit();
|
|
12091
|
+
await limit.acquire();
|
|
12092
|
+
this.ctx.updateState();
|
|
12093
|
+
this.run(job).then(
|
|
12094
|
+
() => job.finish(),
|
|
12095
|
+
(error) => job.finish(error instanceof Error ? error : new Error(String(error)))
|
|
12096
|
+
).finally(() => this.ctx.jobDone());
|
|
12097
|
+
return job;
|
|
12098
|
+
}
|
|
12099
|
+
notSent(options) {
|
|
12100
|
+
for (const [name, value] of Object.entries(options)) {
|
|
12101
|
+
if (value === void 0 || this._warned.has(name)) {
|
|
12102
|
+
continue;
|
|
12103
|
+
}
|
|
12104
|
+
this._warned.add(name);
|
|
12105
|
+
const ticket = name === "rtspForceNonCompliantUrl" ? "" : " (AWSU-317)";
|
|
12106
|
+
this.ctx.logger.warn(`${name} is not sent to the pipeline API and has no effect in pipeline mode${ticket}`);
|
|
12107
|
+
}
|
|
12108
|
+
}
|
|
12109
|
+
async jobOf(work) {
|
|
12110
|
+
switch (work.kind) {
|
|
12111
|
+
case "source":
|
|
12112
|
+
return await this.sourceJob(work.source, work.params);
|
|
12113
|
+
case "uploadGroup": {
|
|
12114
|
+
const media = await Promise.all(work.paths.map((path2) => this.pathMedia({ path: path2 })));
|
|
12115
|
+
return new PipelineJob(uploadGroup(media), media, false, work.params);
|
|
12116
|
+
}
|
|
12117
|
+
case "uploadStreamGroup": {
|
|
12118
|
+
const media = work.streams.map((stream, i) => bodyMedia(stream, work.mimeTypes?.[i] ?? "application/octet-stream", void 0));
|
|
12119
|
+
return new PipelineJob(uploadGroup(media), media, false, work.params);
|
|
12120
|
+
}
|
|
12121
|
+
case "loadFromGroup":
|
|
12122
|
+
return new PipelineJob({ group: work.urls.map((url) => ({ url })) }, [], false, work.params);
|
|
11596
12123
|
}
|
|
11597
12124
|
}
|
|
11598
|
-
async
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
}
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
} else if (
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
12125
|
+
async sourceJob(source, params) {
|
|
12126
|
+
if (source.file !== void 0) {
|
|
12127
|
+
const file = source.file;
|
|
12128
|
+
const media = bodyMedia(file, file.type || "application/octet-stream", file.size);
|
|
12129
|
+
return new PipelineJob({ upload: { contentType: media.contentType } }, [media], false, params);
|
|
12130
|
+
} else if (source.stream !== void 0) {
|
|
12131
|
+
const stream = source;
|
|
12132
|
+
const media = bodyMedia(stream.stream, stream.mimeType, stream.size ?? knownSize(stream.stream));
|
|
12133
|
+
return new PipelineJob({ upload: { contentType: media.contentType } }, [media], false, params);
|
|
12134
|
+
} else if (source.path !== void 0) {
|
|
12135
|
+
const media = await this.pathMedia(source);
|
|
12136
|
+
return new PipelineJob({ upload: { contentType: media.contentType } }, [media], false, params);
|
|
12137
|
+
} else if (source.url !== void 0) {
|
|
12138
|
+
const url = source.url;
|
|
12139
|
+
if (url.startsWith("file://")) {
|
|
12140
|
+
return await this.sourceJob({ path: url.substring("file://".length) }, params);
|
|
12141
|
+
}
|
|
12142
|
+
return new PipelineJob({ url }, [], /^(rtsp|rtmp):\/\//.test(url), params);
|
|
12143
|
+
} else if (source.assetUuid !== void 0) {
|
|
12144
|
+
return new PipelineJob({ assetUuid: source.assetUuid }, [], false, params);
|
|
12145
|
+
} else if (source.mediaStream !== void 0) {
|
|
12146
|
+
const ingressId = this.newId("whip");
|
|
12147
|
+
return new PipelineJob({ whip: { ingressId } }, [], true, params, source.mediaStream);
|
|
11611
12148
|
}
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
const
|
|
11636
|
-
|
|
12149
|
+
throw new Error("unknown source type");
|
|
12150
|
+
}
|
|
12151
|
+
async pathMedia(source) {
|
|
12152
|
+
const options = this.ctx.options;
|
|
12153
|
+
const resolve = async () => options.platformSupport?.resolvePath ? await options.platformSupport.resolvePath(source, this.ctx.logger) : await resolvePath(source, this.ctx.logger);
|
|
12154
|
+
const first = await resolve();
|
|
12155
|
+
let firstPending = true;
|
|
12156
|
+
return {
|
|
12157
|
+
contentType: first.mimeType,
|
|
12158
|
+
size: first.size,
|
|
12159
|
+
open: async () => {
|
|
12160
|
+
if (firstPending) {
|
|
12161
|
+
firstPending = false;
|
|
12162
|
+
return first.stream;
|
|
12163
|
+
}
|
|
12164
|
+
return (await resolve()).stream;
|
|
12165
|
+
}
|
|
12166
|
+
};
|
|
12167
|
+
}
|
|
12168
|
+
/** Run the job's source to its end; a live source refused overloaded goes once more on a new socket. */
|
|
12169
|
+
async run(job) {
|
|
12170
|
+
let retried = false;
|
|
12171
|
+
while (true) {
|
|
12172
|
+
const sent = await this.inOrder(() => this.setSource(job));
|
|
12173
|
+
if (sent === null) {
|
|
12174
|
+
return;
|
|
12175
|
+
}
|
|
12176
|
+
const { socket, source } = sent;
|
|
12177
|
+
const uploading = source.uploads.size > 0 ? this.upload(socket, source, job) : Promise.resolve();
|
|
12178
|
+
let whip = null;
|
|
12179
|
+
let overloaded;
|
|
12180
|
+
try {
|
|
12181
|
+
overloaded = await this.follow(job, source, () => {
|
|
12182
|
+
if (job.mediaStream !== void 0) {
|
|
12183
|
+
const fail = (error) => {
|
|
12184
|
+
job.stopOnPipeline?.();
|
|
12185
|
+
source.inbox.push(error instanceof Error ? error : new Error(String(error)));
|
|
12186
|
+
};
|
|
12187
|
+
whip = new SocketWhip(job.mediaStream, job.source["whip"]["ingressId"], (message) => this.command(socket, message), fail, this.ctx.requestLogger);
|
|
12188
|
+
whip.start().catch(fail);
|
|
12189
|
+
}
|
|
12190
|
+
});
|
|
12191
|
+
} finally {
|
|
12192
|
+
job.openSource = null;
|
|
12193
|
+
job.stopOnPipeline = null;
|
|
12194
|
+
socket.sources.delete(source.id);
|
|
12195
|
+
source.uploads.forEach((upload) => upload.end());
|
|
12196
|
+
await uploading;
|
|
12197
|
+
await whip?.close();
|
|
12198
|
+
}
|
|
12199
|
+
if (!overloaded) {
|
|
12200
|
+
return;
|
|
12201
|
+
}
|
|
12202
|
+
if (retried || !job.live) {
|
|
12203
|
+
throw new PipelineCommandError("overloaded", "the pipeline API has no capacity for another live source");
|
|
12204
|
+
}
|
|
12205
|
+
retried = true;
|
|
12206
|
+
await socket.closed;
|
|
11637
12207
|
}
|
|
11638
|
-
const result = await response.json();
|
|
11639
|
-
return result["id"];
|
|
11640
12208
|
}
|
|
11641
|
-
|
|
11642
|
-
|
|
11643
|
-
|
|
12209
|
+
/** Send the job's setSource; the caller runs it in submission order. */
|
|
12210
|
+
async setSource(job) {
|
|
12211
|
+
if (job.cancelled) {
|
|
12212
|
+
return null;
|
|
11644
12213
|
}
|
|
11645
|
-
|
|
11646
|
-
|
|
12214
|
+
const combined = await combinedMedia(job);
|
|
12215
|
+
const socket = await this.ensureSocket();
|
|
12216
|
+
const source = new OpenSource(this.newId("source"));
|
|
12217
|
+
if (combined === null) {
|
|
12218
|
+
uploadKeys(job).forEach((key) => source.uploads.set(key, new Credit()));
|
|
12219
|
+
}
|
|
12220
|
+
socket.sources.set(source.id, source);
|
|
12221
|
+
job.openSource = source;
|
|
12222
|
+
job.stopOnPipeline = () => {
|
|
12223
|
+
if (socket.open) {
|
|
12224
|
+
socket.sendJson({ type: "stopSource", id: source.id });
|
|
12225
|
+
}
|
|
12226
|
+
};
|
|
12227
|
+
const command = job.command(source.id);
|
|
12228
|
+
if (combined === null) {
|
|
12229
|
+
socket.sendJson(command);
|
|
12230
|
+
} else {
|
|
12231
|
+
socket.sendBytes(combinedMessage(command, combined));
|
|
11647
12232
|
}
|
|
11648
|
-
|
|
11649
|
-
|
|
12233
|
+
return { socket, source };
|
|
12234
|
+
}
|
|
12235
|
+
/** Hand the source's predictions to the job until it ends; true when the pipeline API was overloaded. */
|
|
12236
|
+
async follow(job, source, onResult) {
|
|
12237
|
+
while (true) {
|
|
12238
|
+
if (job.cancelled) {
|
|
12239
|
+
return false;
|
|
12240
|
+
}
|
|
12241
|
+
const message = await source.inbox.next();
|
|
12242
|
+
if (message === CANCELLED) {
|
|
12243
|
+
return false;
|
|
12244
|
+
}
|
|
12245
|
+
if (message instanceof Error) {
|
|
12246
|
+
throw message;
|
|
12247
|
+
}
|
|
12248
|
+
switch (message["type"]) {
|
|
12249
|
+
case "result":
|
|
12250
|
+
onResult();
|
|
12251
|
+
break;
|
|
12252
|
+
case "prediction":
|
|
12253
|
+
job.predicted(message["prediction"]);
|
|
12254
|
+
break;
|
|
12255
|
+
case "end":
|
|
12256
|
+
if (message["reason"] === "eos") {
|
|
12257
|
+
return false;
|
|
12258
|
+
}
|
|
12259
|
+
throw new PipelineSourceError(source.id, message["reason"] ?? "", message["message"] ?? "");
|
|
12260
|
+
case "error":
|
|
12261
|
+
if (message["error"] === "overloaded") {
|
|
12262
|
+
return true;
|
|
12263
|
+
}
|
|
12264
|
+
throw new PipelineCommandError(message["error"] ?? "", message["message"] ?? "");
|
|
12265
|
+
case "dropped":
|
|
12266
|
+
this.ctx.requestLogger.debug("the pipeline API dropped %s predictions of a live source", message["count"]);
|
|
12267
|
+
break;
|
|
12268
|
+
}
|
|
11650
12269
|
}
|
|
11651
|
-
|
|
11652
|
-
|
|
12270
|
+
}
|
|
12271
|
+
/** Send each upload member's bytes in chunks within its credit, then its uploaded. */
|
|
12272
|
+
async upload(socket, source, job) {
|
|
12273
|
+
const keys = uploadKeys(job);
|
|
12274
|
+
try {
|
|
12275
|
+
for (let i = 0; i < keys.length; i++) {
|
|
12276
|
+
const key = keys[i];
|
|
12277
|
+
const credit = source.uploads.get(key);
|
|
12278
|
+
for await (let piece of pieces(await job.media[i].open())) {
|
|
12279
|
+
while (piece.length > 0) {
|
|
12280
|
+
const n = await credit.take(Math.min(piece.length, CHUNK_BYTES));
|
|
12281
|
+
const chunk = new Uint8Array(n + 1);
|
|
12282
|
+
chunk[0] = CHUNK;
|
|
12283
|
+
chunk.set(piece.subarray(0, n), 1);
|
|
12284
|
+
socket.sendBytes(chunk);
|
|
12285
|
+
piece = piece.subarray(n);
|
|
12286
|
+
}
|
|
12287
|
+
}
|
|
12288
|
+
socket.sendJson(key === null ? { type: "uploaded", id: source.id } : { type: "uploaded", id: source.id, member: key });
|
|
12289
|
+
}
|
|
12290
|
+
} catch (error) {
|
|
12291
|
+
if (!(error instanceof UploadEnded)) {
|
|
12292
|
+
if (socket.open) {
|
|
12293
|
+
source.inbox.push(error instanceof Error ? error : new Error(String(error)));
|
|
12294
|
+
}
|
|
12295
|
+
}
|
|
11653
12296
|
}
|
|
11654
|
-
|
|
11655
|
-
|
|
11656
|
-
|
|
11657
|
-
|
|
12297
|
+
}
|
|
12298
|
+
async session() {
|
|
12299
|
+
const token = await this.token();
|
|
12300
|
+
const validUntil = token === void 0 ? Number.MAX_VALUE : Math.min((await this.ctx.credentialSession()).validUntil, Number.MAX_VALUE);
|
|
12301
|
+
return {
|
|
12302
|
+
eyepopUrl: this.ctx.eyepopUrl(),
|
|
12303
|
+
accessToken: token ?? "",
|
|
12304
|
+
validUntil,
|
|
12305
|
+
popId: "transient",
|
|
12306
|
+
accountId: this.ctx.options.accountId,
|
|
12307
|
+
baseUrl: this._pipelineApiUrl ?? void 0,
|
|
12308
|
+
pipelineId: void 0,
|
|
12309
|
+
isPipelineMode: true,
|
|
12310
|
+
authenticationHeaders: () => token === void 0 ? {} : { Authorization: `Bearer ${token}` }
|
|
12311
|
+
};
|
|
12312
|
+
}
|
|
12313
|
+
};
|
|
12314
|
+
var SocketWhip = class {
|
|
12315
|
+
constructor(_stream, _ingressId, _command, _fail, _logger) {
|
|
12316
|
+
this._stream = _stream;
|
|
12317
|
+
this._ingressId = _ingressId;
|
|
12318
|
+
this._command = _command;
|
|
12319
|
+
this._fail = _fail;
|
|
12320
|
+
this._logger = _logger;
|
|
12321
|
+
this._pc = null;
|
|
12322
|
+
this._answered = false;
|
|
12323
|
+
this._queued = [];
|
|
12324
|
+
this._offerData = null;
|
|
12325
|
+
}
|
|
12326
|
+
async start() {
|
|
12327
|
+
const servers = await this._command({ type: "whipIceServers", ingressId: this._ingressId });
|
|
12328
|
+
const iceServers = servers["iceServers"] ?? [];
|
|
12329
|
+
this._logger.debug("whip %s: ice servers %j", this._ingressId, iceServers.map((server) => server.split(";")[0]));
|
|
12330
|
+
const pc = new RTCPeerConnection({ iceServers: WebrtcBase.linkToIceServers(iceServers.join(", ") || null) });
|
|
12331
|
+
this._pc = pc;
|
|
12332
|
+
pc.oniceconnectionstatechange = () => {
|
|
12333
|
+
this._logger.debug("whip %s: ice connection %s", this._ingressId, pc.iceConnectionState);
|
|
12334
|
+
if (pc.iceConnectionState === "failed" && this._pc === pc) {
|
|
12335
|
+
this._fail(
|
|
12336
|
+
new Error(
|
|
12337
|
+
`the WebRTC connection of whip ingress ${this._ingressId} failed: no candidate pair connected, so the pipeline API is likely reachable through no STUN or TURN server (ice servers: ${iceServers.length})`
|
|
12338
|
+
)
|
|
12339
|
+
);
|
|
12340
|
+
}
|
|
12341
|
+
};
|
|
12342
|
+
pc.onicecandidate = (evt) => {
|
|
12343
|
+
if (evt.candidate !== null) {
|
|
12344
|
+
this.candidate(evt.candidate).catch((error) => this._logger.debug("whipIce failed: %s", error));
|
|
11658
12345
|
}
|
|
12346
|
+
};
|
|
12347
|
+
this._stream.getTracks().forEach((track) => pc.addTrack(track, this._stream));
|
|
12348
|
+
const offer = await pc.createOffer();
|
|
12349
|
+
if (!offer.sdp) {
|
|
12350
|
+
throw new Error("the local offer has no sdp");
|
|
12351
|
+
}
|
|
12352
|
+
this._offerData = WebrtcBase.parseOffer(offer.sdp);
|
|
12353
|
+
await pc.setLocalDescription(offer);
|
|
12354
|
+
const answer = await this._command({ type: "whipOffer", ingressId: this._ingressId, sdp: offer.sdp });
|
|
12355
|
+
await pc.setRemoteDescription({ type: "answer", sdp: answer["sdp"] });
|
|
12356
|
+
this._answered = true;
|
|
12357
|
+
const queued = this._queued;
|
|
12358
|
+
this._queued = [];
|
|
12359
|
+
if (queued.length > 0) {
|
|
12360
|
+
await this.sendCandidates(queued);
|
|
12361
|
+
}
|
|
12362
|
+
}
|
|
12363
|
+
async candidate(candidate) {
|
|
12364
|
+
if (!this._answered) {
|
|
12365
|
+
this._queued.push(candidate);
|
|
11659
12366
|
return;
|
|
11660
12367
|
}
|
|
11661
|
-
|
|
11662
|
-
|
|
12368
|
+
await this.sendCandidates([candidate]);
|
|
12369
|
+
}
|
|
12370
|
+
async sendCandidates(candidates) {
|
|
12371
|
+
if (this._offerData === null) {
|
|
12372
|
+
return;
|
|
11663
12373
|
}
|
|
12374
|
+
await this._command({ type: "whipIce", ingressId: this._ingressId, fragment: WebrtcBase.generateSdpFragment(this._offerData, candidates) });
|
|
12375
|
+
}
|
|
12376
|
+
async close() {
|
|
12377
|
+
this._stream.getTracks().forEach((track) => track.stop());
|
|
12378
|
+
const pc = this._pc;
|
|
12379
|
+
this._pc = null;
|
|
12380
|
+
pc?.close();
|
|
12381
|
+
}
|
|
12382
|
+
};
|
|
12383
|
+
function checkedUrl(url) {
|
|
12384
|
+
const parsed = new URL(url);
|
|
12385
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
12386
|
+
throw new PipelineConfigurationError("insecure_url", `the pipeline API url ${url} must be an http or https url`);
|
|
12387
|
+
}
|
|
12388
|
+
if (parsed.protocol === "http:" && !isLoopback(parsed.hostname)) {
|
|
12389
|
+
throw new PipelineConfigurationError("insecure_url", `the pipeline API url ${url} must use https unless its host is a loopback address`);
|
|
12390
|
+
}
|
|
12391
|
+
return url.replace(/\/+$/, "");
|
|
12392
|
+
}
|
|
12393
|
+
function isLoopback(host) {
|
|
12394
|
+
return host === "localhost" || host === "[::1]" || host === "::1" || /^127\.\d+\.\d+\.\d+$/.test(host);
|
|
12395
|
+
}
|
|
12396
|
+
function knownSize(body) {
|
|
12397
|
+
if (typeof Blob !== "undefined" && body instanceof Blob) {
|
|
12398
|
+
return body.size;
|
|
12399
|
+
}
|
|
12400
|
+
if (ArrayBuffer.isView(body) || body instanceof ArrayBuffer) {
|
|
12401
|
+
return body.byteLength;
|
|
12402
|
+
}
|
|
12403
|
+
return void 0;
|
|
12404
|
+
}
|
|
12405
|
+
function bodyMedia(body, contentType, size) {
|
|
12406
|
+
return { open: async () => body, contentType, size: size ?? knownSize(body) };
|
|
12407
|
+
}
|
|
12408
|
+
function uploadGroup(media) {
|
|
12409
|
+
return { group: media.map((m) => ({ upload: { contentType: m.contentType } })) };
|
|
12410
|
+
}
|
|
12411
|
+
function uploadKeys(job) {
|
|
12412
|
+
if (job.source["upload"] !== void 0) {
|
|
12413
|
+
return [null];
|
|
12414
|
+
}
|
|
12415
|
+
const group = job.source["group"] ?? [];
|
|
12416
|
+
return group.flatMap((member, i) => member["upload"] !== void 0 ? [i] : []);
|
|
12417
|
+
}
|
|
12418
|
+
async function combinedMedia(job) {
|
|
12419
|
+
if (job.media.length === 0 || job.live || job.media.some((m) => m.size === void 0)) {
|
|
12420
|
+
return null;
|
|
12421
|
+
}
|
|
12422
|
+
if (job.media.reduce((total, m) => total + (m.size ?? 0), 0) > COMBINED_UPLOAD_MAX_BYTES) {
|
|
12423
|
+
return null;
|
|
12424
|
+
}
|
|
12425
|
+
const bytes = [];
|
|
12426
|
+
for (const media of job.media) {
|
|
12427
|
+
bytes.push(await readAll(await media.open()));
|
|
12428
|
+
}
|
|
12429
|
+
return bytes;
|
|
12430
|
+
}
|
|
12431
|
+
async function readAll(body) {
|
|
12432
|
+
const parts = [];
|
|
12433
|
+
for await (const piece of pieces(body)) {
|
|
12434
|
+
parts.push(piece);
|
|
12435
|
+
}
|
|
12436
|
+
return concat(parts);
|
|
12437
|
+
}
|
|
12438
|
+
function concat(parts) {
|
|
12439
|
+
const all = new Uint8Array(parts.reduce((total, p) => total + p.length, 0));
|
|
12440
|
+
let offset = 0;
|
|
12441
|
+
for (const part of parts) {
|
|
12442
|
+
all.set(part, offset);
|
|
12443
|
+
offset += part.length;
|
|
12444
|
+
}
|
|
12445
|
+
return all;
|
|
12446
|
+
}
|
|
12447
|
+
function combinedMessage(command, media) {
|
|
12448
|
+
if (command["group"] !== void 0) {
|
|
12449
|
+
let i = 0;
|
|
12450
|
+
command = {
|
|
12451
|
+
...command,
|
|
12452
|
+
group: command["group"].map((member) => member["upload"] !== void 0 ? { upload: { ...member["upload"], bytes: media[i++].length } } : member)
|
|
12453
|
+
};
|
|
12454
|
+
}
|
|
12455
|
+
const header = new TextEncoder().encode(JSON.stringify(command));
|
|
12456
|
+
const prefix = new Uint8Array(5);
|
|
12457
|
+
prefix[0] = COMBINED;
|
|
12458
|
+
new DataView(prefix.buffer).setUint32(1, header.length, false);
|
|
12459
|
+
return concat([prefix, header, ...media]);
|
|
12460
|
+
}
|
|
12461
|
+
async function* pieces(body) {
|
|
12462
|
+
if (typeof Blob !== "undefined" && body instanceof Blob) {
|
|
12463
|
+
yield* pieces(body.stream());
|
|
12464
|
+
} else if (body instanceof ArrayBuffer) {
|
|
12465
|
+
yield new Uint8Array(body);
|
|
12466
|
+
} else if (ArrayBuffer.isView(body)) {
|
|
12467
|
+
yield new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
|
12468
|
+
} else {
|
|
12469
|
+
const reader = body.getReader();
|
|
11664
12470
|
try {
|
|
11665
|
-
|
|
11666
|
-
|
|
12471
|
+
while (true) {
|
|
12472
|
+
const { value, done } = await reader.read();
|
|
12473
|
+
if (done) {
|
|
12474
|
+
return;
|
|
12475
|
+
}
|
|
12476
|
+
if (value !== void 0 && value.length > 0) {
|
|
12477
|
+
yield value;
|
|
12478
|
+
}
|
|
12479
|
+
}
|
|
11667
12480
|
} finally {
|
|
11668
|
-
|
|
12481
|
+
reader.releaseLock();
|
|
11669
12482
|
}
|
|
11670
12483
|
}
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
|
|
11676
|
-
|
|
11677
|
-
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
this._pipelineId = null;
|
|
11682
|
-
}
|
|
11683
|
-
this._pipeline = null;
|
|
11684
|
-
try {
|
|
11685
|
-
this.options().pop = pop;
|
|
11686
|
-
await this.getComputeSession();
|
|
11687
|
-
} catch (error) {
|
|
11688
|
-
this.options().pop = previousPop;
|
|
11689
|
-
this._pipeline = null;
|
|
11690
|
-
this._pipelineId = null;
|
|
11691
|
-
this._baseUrl = previousPop ? null : previousBaseUrl;
|
|
11692
|
-
this._sessionAccessToken = previousSessionAccessToken;
|
|
11693
|
-
this._sessionAccessTokenValidUntil = previousSessionAccessTokenValidUntil;
|
|
11694
|
-
throw error;
|
|
11695
|
-
}
|
|
11696
|
-
if (!this._pipelineId) {
|
|
11697
|
-
throw new Error("Compute session did not provide a pipeline for the requested pop");
|
|
12484
|
+
}
|
|
12485
|
+
|
|
12486
|
+
// worker/worker_endpoint.ts
|
|
12487
|
+
var WorkerEndpoint = class extends Endpoint {
|
|
12488
|
+
constructor(options) {
|
|
12489
|
+
if (options.isPipelineMode) {
|
|
12490
|
+
options = { ...options, jobQueueLength: options.jobQueueLength || MAX_OPEN_SOURCES };
|
|
12491
|
+
if (options.jobQueueLength > MAX_OPEN_SOURCES) {
|
|
12492
|
+
throw new PipelineConfigurationError("job_queue_length", `jobQueueLength ${options.jobQueueLength} exceeds ${MAX_OPEN_SOURCES}, the open sources a pipeline API socket takes`);
|
|
12493
|
+
}
|
|
11698
12494
|
}
|
|
11699
|
-
|
|
12495
|
+
super(options);
|
|
12496
|
+
const context = {
|
|
12497
|
+
options,
|
|
12498
|
+
logger: this._logger,
|
|
12499
|
+
requestLogger: this._requestLogger,
|
|
12500
|
+
client: () => this._client,
|
|
12501
|
+
limit: () => this._limit,
|
|
12502
|
+
jobDone: () => {
|
|
12503
|
+
this._limit.release();
|
|
12504
|
+
this.updateState();
|
|
12505
|
+
},
|
|
12506
|
+
updateState: (state, message) => this.updateState(state, message),
|
|
12507
|
+
eyepopUrl: () => this.eyepopUrl(),
|
|
12508
|
+
eyepopWebApiUrl: () => this.eyepopWebApiUrl(),
|
|
12509
|
+
credentialHeader: () => super.authorizationHeader(),
|
|
12510
|
+
forgetCredential: () => this.statusHandler401(401),
|
|
12511
|
+
fetchWithRetry: (fetcher, retries) => this.fetchWithRetry(fetcher, retries),
|
|
12512
|
+
credentialSession: () => super.session()
|
|
12513
|
+
};
|
|
12514
|
+
this._backend = options.isPipelineMode ? new PipelineBackend(context) : new SessionBackend(context);
|
|
12515
|
+
this.setStatusRetryHandlers(/* @__PURE__ */ new Map([[404, (statusCode) => this._backend.onStatus(statusCode)]]));
|
|
11700
12516
|
}
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
12517
|
+
options() {
|
|
12518
|
+
return this._options;
|
|
12519
|
+
}
|
|
12520
|
+
/** What runs this endpoint's jobs. */
|
|
12521
|
+
backend() {
|
|
12522
|
+
return this._backend;
|
|
12523
|
+
}
|
|
12524
|
+
async disconnect(wait = true) {
|
|
12525
|
+
await this._backend.disconnect(() => super.disconnect(wait));
|
|
12526
|
+
}
|
|
12527
|
+
async session() {
|
|
12528
|
+
return await this._backend.session();
|
|
12529
|
+
}
|
|
12530
|
+
popName() {
|
|
12531
|
+
return this._backend.popName();
|
|
12532
|
+
}
|
|
12533
|
+
pop() {
|
|
12534
|
+
return this._backend.pop();
|
|
12535
|
+
}
|
|
12536
|
+
async changePop(pop) {
|
|
12537
|
+
validatePop(pop);
|
|
12538
|
+
await this._backend.changePop(pop);
|
|
12539
|
+
}
|
|
12540
|
+
/**
|
|
12541
|
+
* @deprecated Pop ids are only retained for backwards compatibility.
|
|
12542
|
+
* Configure transient sessions with `WorkerOptions.pop`.
|
|
12543
|
+
*/
|
|
12544
|
+
popId() {
|
|
12545
|
+
return this.options().popId || null;
|
|
12546
|
+
}
|
|
12547
|
+
async process(param1, param2) {
|
|
12548
|
+
if (param1.source !== void 0) {
|
|
12549
|
+
const request = param1;
|
|
12550
|
+
this.validateProcessParams(request);
|
|
12551
|
+
return await this.submit({ kind: "source", source: request.source, params: request });
|
|
12552
|
+
} else {
|
|
12553
|
+
return await this.submit({ kind: "source", source: param1, params: { componentParams: param2 } });
|
|
11704
12554
|
}
|
|
11705
|
-
|
|
11706
|
-
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
12555
|
+
}
|
|
12556
|
+
/**
|
|
12557
|
+
* Reject a source's calibration before any work is started for it.
|
|
12558
|
+
*
|
|
12559
|
+
* Called by every entry point that takes ProcessParams, before the
|
|
12560
|
+
* concurrency limit is acquired, so a request that can never be sent
|
|
12561
|
+
* does not hold a slot.
|
|
12562
|
+
*/
|
|
12563
|
+
validateProcessParams(params) {
|
|
12564
|
+
if (params.camera !== void 0) {
|
|
12565
|
+
validateCamera(params.camera);
|
|
11716
12566
|
}
|
|
11717
12567
|
}
|
|
11718
|
-
async
|
|
11719
|
-
if (
|
|
11720
|
-
|
|
12568
|
+
async uploadGroup(paths, params = {}) {
|
|
12569
|
+
if (paths.length === 0) {
|
|
12570
|
+
throw new Error("upload group requires at least one path");
|
|
11721
12571
|
}
|
|
11722
|
-
|
|
12572
|
+
this.validateProcessParams(params);
|
|
12573
|
+
return await this.submit({ kind: "uploadGroup", paths, params });
|
|
11723
12574
|
}
|
|
11724
|
-
async
|
|
11725
|
-
|
|
11726
|
-
|
|
11727
|
-
return "Implicit";
|
|
12575
|
+
async uploadStreamGroup(streams, mimeTypes, params = {}) {
|
|
12576
|
+
if (streams.length === 0) {
|
|
12577
|
+
throw new Error("upload stream group requires at least one stream");
|
|
11728
12578
|
}
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
return `Bearer ${credential}`;
|
|
12579
|
+
if (mimeTypes !== void 0 && mimeTypes.length !== streams.length) {
|
|
12580
|
+
throw new Error("mimeTypes must have the same length as streams");
|
|
11732
12581
|
}
|
|
11733
|
-
|
|
12582
|
+
this.validateProcessParams(params);
|
|
12583
|
+
return await this.submit({ kind: "uploadStreamGroup", streams, mimeTypes, params });
|
|
11734
12584
|
}
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
this._pipeline = {
|
|
11739
|
-
id: this._pipelineId,
|
|
11740
|
-
state: "idle",
|
|
11741
|
-
startTime: (/* @__PURE__ */ new Date()).toString(),
|
|
11742
|
-
pop
|
|
11743
|
-
};
|
|
12585
|
+
async loadFromGroup(urls, params = {}) {
|
|
12586
|
+
if (urls.length === 0) {
|
|
12587
|
+
throw new Error("load from group requires at least one url");
|
|
11744
12588
|
}
|
|
12589
|
+
this.validateProcessParams(params);
|
|
12590
|
+
return await this.submit({ kind: "loadFromGroup", urls, params });
|
|
12591
|
+
}
|
|
12592
|
+
async submit(work) {
|
|
12593
|
+
return await this._backend.submit(work);
|
|
12594
|
+
}
|
|
12595
|
+
async reconnect() {
|
|
12596
|
+
await this._backend.reconnect();
|
|
12597
|
+
return this;
|
|
12598
|
+
}
|
|
12599
|
+
async authorizationHeader() {
|
|
12600
|
+
return await this._backend.authorizationHeader();
|
|
11745
12601
|
}
|
|
11746
12602
|
};
|
|
11747
|
-
_WorkerEndpoint.WAIT_FOR_IS_READY = 60 * 1e3;
|
|
11748
|
-
var WorkerEndpoint = _WorkerEndpoint;
|
|
11749
|
-
|
|
11750
|
-
// shims/websockets.ts
|
|
11751
|
-
var createWebSocket;
|
|
11752
|
-
if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
11753
|
-
createWebSocket = (url, protocols) => {
|
|
11754
|
-
return new WebSocket(url, protocols);
|
|
11755
|
-
};
|
|
11756
|
-
} else {
|
|
11757
|
-
createWebSocket = (url, protocols) => {
|
|
11758
|
-
const ws = require("ws");
|
|
11759
|
-
return new ws.WebSocket(url, protocols);
|
|
11760
|
-
};
|
|
11761
|
-
}
|
|
11762
12603
|
|
|
11763
12604
|
// data/data_endpoint.ts
|
|
11764
12605
|
var import_url_join = __toESM(require("url-join"));
|
|
@@ -13426,6 +14267,13 @@ var EyePop;
|
|
|
13426
14267
|
if (opts.isLocalMode === void 0) {
|
|
13427
14268
|
opts.isLocalMode = stringToBooleanSafe(readEnv("EYEPOP_LOCAL_MODE"));
|
|
13428
14269
|
}
|
|
14270
|
+
if (opts.isPipelineMode === void 0) {
|
|
14271
|
+
const shared = resolveAuth(opts)?.session;
|
|
14272
|
+
opts.isPipelineMode = shared?.isPipelineMode ?? stringToBooleanSafe(readEnv("EYEPOP_PIPELINE_MODE"));
|
|
14273
|
+
}
|
|
14274
|
+
if (opts.isPipelineMode) {
|
|
14275
|
+
return pipelineEndpoint(opts);
|
|
14276
|
+
}
|
|
13429
14277
|
if (opts.isLocalMode) {
|
|
13430
14278
|
opts.eyepopUrl = "http://127.0.0.1:8080";
|
|
13431
14279
|
}
|
|
@@ -13477,6 +14325,38 @@ var EyePop;
|
|
|
13477
14325
|
return new WorkerEndpoint(opts);
|
|
13478
14326
|
}
|
|
13479
14327
|
EyePop2.workerEndpoint = workerEndpoint;
|
|
14328
|
+
function pipelineEndpoint(opts) {
|
|
14329
|
+
const popId = opts.popId ?? readEnv("EYEPOP_POP_ID");
|
|
14330
|
+
const sessionOnly = {
|
|
14331
|
+
popId: popId === "transient" /* Transient */ ? void 0 : popId,
|
|
14332
|
+
sessionUuid: opts.sessionUuid ?? readEnv("EYEPOP_SESSION_UUID"),
|
|
14333
|
+
sessionName: opts.sessionName,
|
|
14334
|
+
pipelineImage: opts.pipelineImage,
|
|
14335
|
+
pipelineVersion: opts.pipelineVersion
|
|
14336
|
+
};
|
|
14337
|
+
const named = Object.entries(sessionOnly).filter(([, value]) => value).map(([name]) => name);
|
|
14338
|
+
if (named.length > 0) {
|
|
14339
|
+
throw new PipelineConfigurationError("session_options", `pipeline mode runs no worker session; it takes no ${named.join(", ")}`, named);
|
|
14340
|
+
}
|
|
14341
|
+
if (opts.isLocalMode && !opts.eyepopUrl) {
|
|
14342
|
+
opts.eyepopUrl = readEnv("EYEPOP_URL") || "http://127.0.0.1:9002";
|
|
14343
|
+
}
|
|
14344
|
+
if (!opts.jobQueueLength) {
|
|
14345
|
+
opts.jobQueueLength = MAX_OPEN_SOURCES;
|
|
14346
|
+
}
|
|
14347
|
+
_fill_default_options(opts);
|
|
14348
|
+
if (resolveAuth(opts) === void 0) {
|
|
14349
|
+
if (opts.isLocalMode) {
|
|
14350
|
+
opts.auth = { isLocal: true };
|
|
14351
|
+
} else {
|
|
14352
|
+
throw new Error("apiKey/accessToken/session/oAuth2 option or EYEPOP_API_KEY environment variable is required");
|
|
14353
|
+
}
|
|
14354
|
+
}
|
|
14355
|
+
if (opts.accountId === void 0) {
|
|
14356
|
+
opts.accountId = resolveAuth(opts)?.session?.accountId ?? readAccountUuidEnv();
|
|
14357
|
+
}
|
|
14358
|
+
return new WorkerEndpoint(opts);
|
|
14359
|
+
}
|
|
13480
14360
|
function dataEndpoint(opts = {}) {
|
|
13481
14361
|
_fill_default_options(opts);
|
|
13482
14362
|
const auth = resolveAuth(opts);
|
|
@@ -13554,6 +14434,7 @@ var index_default = EyePop;
|
|
|
13554
14434
|
AssetUrlType,
|
|
13555
14435
|
AutoAnnotateStatus,
|
|
13556
14436
|
AutoAnnotateTask,
|
|
14437
|
+
COMBINED_UPLOAD_MAX_BYTES,
|
|
13557
14438
|
ChangeType,
|
|
13558
14439
|
ComputeAccountMismatchError,
|
|
13559
14440
|
ComputeApiError,
|
|
@@ -13575,6 +14456,7 @@ var index_default = EyePop;
|
|
|
13575
14456
|
LoadFromGroupJob,
|
|
13576
14457
|
LoadFromJob,
|
|
13577
14458
|
LoadMediaStreamJob,
|
|
14459
|
+
MAX_OPEN_SOURCES,
|
|
13578
14460
|
ModelExportStatus,
|
|
13579
14461
|
ModelFormat,
|
|
13580
14462
|
ModelPrecisionType,
|
|
@@ -13583,12 +14465,21 @@ var index_default = EyePop;
|
|
|
13583
14465
|
ModelTrainingStage,
|
|
13584
14466
|
ModelType,
|
|
13585
14467
|
MotionModel,
|
|
14468
|
+
PIPELINE_PATH,
|
|
14469
|
+
PipelineBackend,
|
|
14470
|
+
PipelineCommandError,
|
|
14471
|
+
PipelineConfigurationError,
|
|
14472
|
+
PipelineJob,
|
|
14473
|
+
PipelineSocketClosedError,
|
|
14474
|
+
PipelineSourceError,
|
|
13586
14475
|
PointCloud,
|
|
13587
14476
|
PopComponentType,
|
|
13588
14477
|
PredictionVersion,
|
|
13589
14478
|
QUATERNION_TOLERANCE,
|
|
14479
|
+
SUBPROTOCOL,
|
|
13590
14480
|
SelectMode,
|
|
13591
14481
|
Semaphore,
|
|
14482
|
+
SessionBackend,
|
|
13592
14483
|
Stream,
|
|
13593
14484
|
TaskMode,
|
|
13594
14485
|
TaskType,
|