@eyepop.ai/eyepop 3.15.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/eyepop.index.d.mts +73 -22
- package/dist/eyepop.index.d.ts +73 -22
- package/dist/eyepop.index.js +269 -58
- package/dist/eyepop.index.js.map +1 -1
- package/dist/eyepop.index.mjs +269 -58
- package/dist/eyepop.index.mjs.map +1 -1
- package/dist/eyepop.min.js +1 -1
- package/package.json +6 -1
package/dist/eyepop.index.mjs
CHANGED
|
@@ -9717,8 +9717,9 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9717
9717
|
};
|
|
9718
9718
|
} else {
|
|
9719
9719
|
class NodeHttpClient {
|
|
9720
|
-
constructor(agent, logger) {
|
|
9720
|
+
constructor(agent, fetchFn, logger) {
|
|
9721
9721
|
this._agent = agent;
|
|
9722
|
+
this._fetch = fetchFn;
|
|
9722
9723
|
this._logger = logger;
|
|
9723
9724
|
}
|
|
9724
9725
|
async fetch(input, init) {
|
|
@@ -9726,7 +9727,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9726
9727
|
init.dispatcher = this._agent;
|
|
9727
9728
|
const logLine = logLineFromRequest(input, init);
|
|
9728
9729
|
this._logger.debug(`Node fetch() BEFORE ${logLine}`);
|
|
9729
|
-
const response = await
|
|
9730
|
+
const response = await this._fetch(input, init);
|
|
9730
9731
|
this._logger.debug(`AFTER ${logLine} -> ${response.status}`);
|
|
9731
9732
|
return response;
|
|
9732
9733
|
}
|
|
@@ -9746,7 +9747,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
|
|
|
9746
9747
|
pipelining: 0
|
|
9747
9748
|
});
|
|
9748
9749
|
logger.debug("Using node fetch with undici agent as http client");
|
|
9749
|
-
return new NodeHttpClient(agent, logger);
|
|
9750
|
+
return new NodeHttpClient(agent, undici.fetch, logger);
|
|
9750
9751
|
};
|
|
9751
9752
|
}
|
|
9752
9753
|
|
|
@@ -10162,6 +10163,7 @@ var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
|
|
|
10162
10163
|
SessionStatus2["PIPELINE_OK"] = "pipeline_ok";
|
|
10163
10164
|
SessionStatus2["PIPELINE_CHECKING"] = "pipeline_checking";
|
|
10164
10165
|
SessionStatus2["PIPELINE_ERROR"] = "pipeline_error";
|
|
10166
|
+
SessionStatus2["UPGRADING"] = "upgrading";
|
|
10165
10167
|
return SessionStatus2;
|
|
10166
10168
|
})(SessionStatus || {});
|
|
10167
10169
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -10172,7 +10174,10 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10172
10174
|
this._baseUrl = null;
|
|
10173
10175
|
this._pipelineId = null;
|
|
10174
10176
|
this._popName = null;
|
|
10177
|
+
this._sessionAccessToken = null;
|
|
10178
|
+
this._sessionAccessTokenValidUntil = null;
|
|
10175
10179
|
this._pipeline = null;
|
|
10180
|
+
this._pipelineCreatePromise = null;
|
|
10176
10181
|
}
|
|
10177
10182
|
options() {
|
|
10178
10183
|
return this._options;
|
|
@@ -10199,20 +10204,29 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10199
10204
|
this._baseUrl = null;
|
|
10200
10205
|
}
|
|
10201
10206
|
async session() {
|
|
10202
|
-
|
|
10203
|
-
if (this._baseUrl == null
|
|
10207
|
+
let session = null;
|
|
10208
|
+
if (this._baseUrl == null) {
|
|
10204
10209
|
await this.reconnect();
|
|
10205
|
-
if (this._baseUrl == null
|
|
10210
|
+
if (this._baseUrl == null) {
|
|
10206
10211
|
return Promise.reject("endpoint not connected");
|
|
10207
10212
|
}
|
|
10208
10213
|
}
|
|
10214
|
+
if (this._sessionAccessToken) {
|
|
10215
|
+
session = {
|
|
10216
|
+
eyepopUrl: this.options().eyepopUrl,
|
|
10217
|
+
accessToken: this._sessionAccessToken,
|
|
10218
|
+
validUntil: this._sessionAccessTokenValidUntil || Number.MAX_VALUE
|
|
10219
|
+
};
|
|
10220
|
+
} else {
|
|
10221
|
+
session = await super.session();
|
|
10222
|
+
}
|
|
10209
10223
|
return {
|
|
10210
10224
|
eyepopUrl: session.eyepopUrl,
|
|
10211
10225
|
accessToken: session.accessToken,
|
|
10212
10226
|
validUntil: session.validUntil,
|
|
10213
10227
|
popId: this.options().popId,
|
|
10214
10228
|
baseUrl: this._baseUrl,
|
|
10215
|
-
pipelineId: this._pipelineId,
|
|
10229
|
+
pipelineId: this._pipelineId || void 0,
|
|
10216
10230
|
authenticationHeaders: () => this._authenticationHeaders(session)
|
|
10217
10231
|
};
|
|
10218
10232
|
}
|
|
@@ -10222,11 +10236,14 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10222
10236
|
pop() {
|
|
10223
10237
|
if (this._pipeline) {
|
|
10224
10238
|
return this._pipeline.pop || null;
|
|
10225
|
-
} else {
|
|
10226
|
-
return null;
|
|
10227
10239
|
}
|
|
10240
|
+
return this.options().pop || null;
|
|
10228
10241
|
}
|
|
10229
10242
|
async changePop(pop) {
|
|
10243
|
+
if (this.options().popId == "transient" /* Transient */) {
|
|
10244
|
+
await this.changeTransientPop(pop);
|
|
10245
|
+
return;
|
|
10246
|
+
}
|
|
10230
10247
|
const client = this._client;
|
|
10231
10248
|
const baseUrl = this._baseUrl;
|
|
10232
10249
|
if (!baseUrl || !client) {
|
|
@@ -10249,6 +10266,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10249
10266
|
const message = await response.text();
|
|
10250
10267
|
throw new Error(`Unexpected status ${response.status}: ${message}`);
|
|
10251
10268
|
}
|
|
10269
|
+
this.options().pop = pop;
|
|
10252
10270
|
if (this._pipeline) {
|
|
10253
10271
|
this._pipeline.pop = pop;
|
|
10254
10272
|
} else {
|
|
@@ -10263,6 +10281,10 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10263
10281
|
_authenticationHeaders(session) {
|
|
10264
10282
|
return this._options.auth.isLocal !== void 0 ? {} : { Authorization: `Bearer ${session.accessToken}` };
|
|
10265
10283
|
}
|
|
10284
|
+
/**
|
|
10285
|
+
* @deprecated Pop ids are only retained for backwards compatibility.
|
|
10286
|
+
* Configure transient sessions with `WorkerOptions.pop`.
|
|
10287
|
+
*/
|
|
10266
10288
|
popId() {
|
|
10267
10289
|
return this.options().popId || null;
|
|
10268
10290
|
}
|
|
@@ -10308,6 +10330,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10308
10330
|
}
|
|
10309
10331
|
}
|
|
10310
10332
|
async uploadFile(source, params) {
|
|
10333
|
+
await this.ensureTransientPipelineStarted();
|
|
10311
10334
|
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10312
10335
|
return Promise.reject("endpoint not connected, use connect()");
|
|
10313
10336
|
}
|
|
@@ -10340,6 +10363,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10340
10363
|
}
|
|
10341
10364
|
}
|
|
10342
10365
|
async uploadStream(source, params) {
|
|
10366
|
+
await this.ensureTransientPipelineStarted();
|
|
10343
10367
|
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10344
10368
|
return Promise.reject("endpoint not connected, use connect()");
|
|
10345
10369
|
}
|
|
@@ -10372,6 +10396,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10372
10396
|
}
|
|
10373
10397
|
}
|
|
10374
10398
|
async uploadPath(source, params) {
|
|
10399
|
+
await this.ensureTransientPipelineStarted();
|
|
10375
10400
|
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10376
10401
|
throw new Error("endpoint not connected, use connect()");
|
|
10377
10402
|
}
|
|
@@ -10418,6 +10443,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10418
10443
|
params
|
|
10419
10444
|
);
|
|
10420
10445
|
}
|
|
10446
|
+
await this.ensureTransientPipelineStarted();
|
|
10421
10447
|
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10422
10448
|
throw new Error("endpoint not connected, use connect()");
|
|
10423
10449
|
}
|
|
@@ -10447,6 +10473,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10447
10473
|
}
|
|
10448
10474
|
}
|
|
10449
10475
|
async loadFromAssetUuid(source, params) {
|
|
10476
|
+
await this.ensureTransientPipelineStarted();
|
|
10450
10477
|
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10451
10478
|
throw new Error("endpoint not connected, use connect()");
|
|
10452
10479
|
}
|
|
@@ -10476,6 +10503,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10476
10503
|
}
|
|
10477
10504
|
}
|
|
10478
10505
|
async loadMediaStream(source, params) {
|
|
10506
|
+
await this.ensureTransientPipelineStarted();
|
|
10479
10507
|
if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
|
|
10480
10508
|
throw new Error("endpoint not connected, use connect()");
|
|
10481
10509
|
}
|
|
@@ -10518,7 +10546,9 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10518
10546
|
async reconnect() {
|
|
10519
10547
|
if (this.options().popId == "transient" /* Transient */) {
|
|
10520
10548
|
await this.getComputeSession();
|
|
10521
|
-
|
|
10549
|
+
if (this.options().pop) {
|
|
10550
|
+
this.setTransientPipelinePop();
|
|
10551
|
+
}
|
|
10522
10552
|
} else if (this.options().sessionUuid) {
|
|
10523
10553
|
await this.getComputeSession();
|
|
10524
10554
|
} else {
|
|
@@ -10615,29 +10645,65 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10615
10645
|
}
|
|
10616
10646
|
}
|
|
10617
10647
|
}
|
|
10648
|
+
sessionReadyTimeoutMs() {
|
|
10649
|
+
const seconds = this.options().sessionReadyTimeoutSeconds;
|
|
10650
|
+
return typeof seconds == "number" && Number.isFinite(seconds) && seconds > 0 ? seconds * 1e3 : _WorkerEndpoint.WAIT_FOR_IS_READY;
|
|
10651
|
+
}
|
|
10652
|
+
sessionHealthReady(body, contentType) {
|
|
10653
|
+
if (contentType.includes("application/json")) {
|
|
10654
|
+
const health = JSON.parse(body);
|
|
10655
|
+
if (health && typeof health == "object") {
|
|
10656
|
+
if (health.message && !health.session_status) {
|
|
10657
|
+
return true;
|
|
10658
|
+
}
|
|
10659
|
+
return health.session_status == "running" /* RUNNING */;
|
|
10660
|
+
}
|
|
10661
|
+
}
|
|
10662
|
+
return contentType.includes("text/plain") && body.includes("I'm fine");
|
|
10663
|
+
}
|
|
10618
10664
|
async getComputeSession() {
|
|
10619
10665
|
if (!this._client) {
|
|
10620
10666
|
throw new Error("endpoint not initialized");
|
|
10621
10667
|
}
|
|
10622
10668
|
let session;
|
|
10623
|
-
let headers;
|
|
10624
10669
|
const sessionUuid = this.options().sessionUuid;
|
|
10625
10670
|
if (sessionUuid) {
|
|
10626
|
-
|
|
10671
|
+
session = await this.getPermanentComputeSession(this._client, sessionUuid);
|
|
10627
10672
|
} else {
|
|
10628
|
-
|
|
10673
|
+
session = await this.getOnDemandComputeSession(this._client);
|
|
10629
10674
|
}
|
|
10675
|
+
this.setComputeSessionAccessToken(session);
|
|
10676
|
+
const headers = {
|
|
10677
|
+
Authorization: await this.authorizationHeader()
|
|
10678
|
+
};
|
|
10630
10679
|
let isReady = false;
|
|
10631
|
-
const
|
|
10680
|
+
const readyTimeoutMs = this.sessionReadyTimeoutMs();
|
|
10681
|
+
const deadline = Date.now() + readyTimeoutMs;
|
|
10632
10682
|
while (!isReady) {
|
|
10633
10683
|
const health_url = `${session.session_endpoint}/health`;
|
|
10634
10684
|
const response = await this._client.fetch(health_url, {
|
|
10635
|
-
headers
|
|
10685
|
+
headers: {
|
|
10686
|
+
...headers,
|
|
10687
|
+
Accept: "application/json"
|
|
10688
|
+
}
|
|
10636
10689
|
});
|
|
10637
|
-
if (response.status
|
|
10638
|
-
|
|
10690
|
+
if (response.status == 200) {
|
|
10691
|
+
const contentType = response.headers.get("content-type") || "";
|
|
10692
|
+
const body = await response.text();
|
|
10693
|
+
try {
|
|
10694
|
+
isReady = this.sessionHealthReady(body, contentType);
|
|
10695
|
+
} catch (error) {
|
|
10696
|
+
this._logger.debug(`session ${session.session_uuid} health check returned invalid JSON, wait and poll for update`);
|
|
10697
|
+
}
|
|
10698
|
+
if (!isReady && Date.now() > deadline) {
|
|
10699
|
+
throw new Error(`Created session ${session.session_uuid} did not become healthy after ${readyTimeoutMs / 1e3} seconds`);
|
|
10700
|
+
}
|
|
10701
|
+
if (!isReady) {
|
|
10702
|
+
this._logger.debug(`session ${session.session_uuid} health check not ready, wait and poll for update`);
|
|
10703
|
+
await sleep(_WorkerEndpoint.CHECK_FOR_IS_READY_INTERVAL);
|
|
10704
|
+
}
|
|
10639
10705
|
} else if (Date.now() > deadline) {
|
|
10640
|
-
throw new Error(`Created session ${session.session_uuid} did not become healthy after ${
|
|
10706
|
+
throw new Error(`Created session ${session.session_uuid} did not become healthy after ${readyTimeoutMs / 1e3} seconds`);
|
|
10641
10707
|
} else {
|
|
10642
10708
|
this._logger.debug(`session ${session.session_uuid} health check status ${response.status}, wait and poll for update`);
|
|
10643
10709
|
await sleep(_WorkerEndpoint.CHECK_FOR_IS_READY_INTERVAL);
|
|
@@ -10645,51 +10711,59 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10645
10711
|
}
|
|
10646
10712
|
this._baseUrl = session.session_endpoint;
|
|
10647
10713
|
this._pipeline = null;
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
this._pipelineId = session.pipelines[0].pipeline_id;
|
|
10652
|
-
} else {
|
|
10653
|
-
this._pipelineId = null;
|
|
10714
|
+
this._pipelineId = this.pipelineIdFromSession(session);
|
|
10715
|
+
if (this.options().pop) {
|
|
10716
|
+
this.setTransientPipelinePop();
|
|
10654
10717
|
}
|
|
10655
10718
|
}
|
|
10656
10719
|
async getOnDemandComputeSession(httpClient) {
|
|
10657
10720
|
let session = null;
|
|
10658
10721
|
const sessionsUrl = `${this.eyepopUrl()}/v1/sessions`;
|
|
10659
|
-
this._requestLogger.debug("fetching sessions from: %s", sessionsUrl);
|
|
10660
10722
|
const headers = {
|
|
10661
|
-
Authorization: await this.
|
|
10723
|
+
Authorization: await this.computeAuthorizationHeader()
|
|
10662
10724
|
};
|
|
10663
|
-
let response = await httpClient.fetch(sessionsUrl, {
|
|
10664
|
-
headers
|
|
10665
|
-
});
|
|
10666
10725
|
let sessions;
|
|
10667
|
-
if (
|
|
10668
|
-
sessions
|
|
10669
|
-
|
|
10670
|
-
|
|
10671
|
-
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
10676
|
-
|
|
10677
|
-
|
|
10678
|
-
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
|
|
10726
|
+
if (!this.options().pop) {
|
|
10727
|
+
this._requestLogger.debug("fetching sessions from: %s", sessionsUrl);
|
|
10728
|
+
const response = await httpClient.fetch(sessionsUrl, {
|
|
10729
|
+
headers
|
|
10730
|
+
});
|
|
10731
|
+
if (response.status == 404) {
|
|
10732
|
+
sessions = [];
|
|
10733
|
+
} else if (response.status != 200) {
|
|
10734
|
+
this.updateState("Error" /* Error */);
|
|
10735
|
+
const message = await response.text();
|
|
10736
|
+
throw new Error(`Unexpected status ${response.status} fetching compute sessions: ${message}`);
|
|
10737
|
+
} else {
|
|
10738
|
+
const response_content = await response.json();
|
|
10739
|
+
sessions = response_content;
|
|
10740
|
+
}
|
|
10741
|
+
if (sessions.length > 0) {
|
|
10742
|
+
this._logger.debug(`User has ${sessions.length} sessions, inspecting for usable session`);
|
|
10743
|
+
for (let s of sessions) {
|
|
10744
|
+
if (!_WorkerEndpoint.SESSION_DEAD.has(s.session_status) && !s.persistent) {
|
|
10745
|
+
session = s;
|
|
10746
|
+
this._logger.debug(`Use active session ${s.session_uuid} with pipeline ${this.pipelineIdFromSession(s)}`);
|
|
10747
|
+
break;
|
|
10748
|
+
}
|
|
10684
10749
|
}
|
|
10685
10750
|
}
|
|
10686
10751
|
}
|
|
10687
10752
|
if (!session) {
|
|
10688
10753
|
this._requestLogger.debug("creating a new session at: %s", sessionsUrl);
|
|
10689
|
-
|
|
10690
|
-
|
|
10754
|
+
const createBody = this.sessionCreateBody();
|
|
10755
|
+
const createHeaders = {
|
|
10756
|
+
...headers,
|
|
10757
|
+
...createBody ? { "Content-Type": "application/json" } : {}
|
|
10758
|
+
};
|
|
10759
|
+
const request = {
|
|
10760
|
+
headers: createHeaders,
|
|
10691
10761
|
method: "POST"
|
|
10692
|
-
}
|
|
10762
|
+
};
|
|
10763
|
+
if (createBody) {
|
|
10764
|
+
request.body = createBody;
|
|
10765
|
+
}
|
|
10766
|
+
const response = await httpClient.fetch(`${sessionsUrl}?wait=true`, request);
|
|
10693
10767
|
if (response.status != 200) {
|
|
10694
10768
|
this.updateState("Error" /* Error */);
|
|
10695
10769
|
const message = await response.text();
|
|
@@ -10705,14 +10779,14 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10705
10779
|
if (!session) {
|
|
10706
10780
|
throw new Error("unexpected undefined session");
|
|
10707
10781
|
}
|
|
10708
|
-
return
|
|
10782
|
+
return session;
|
|
10709
10783
|
}
|
|
10710
10784
|
async getPermanentComputeSession(httpClient, sessionUuid) {
|
|
10711
10785
|
let session = null;
|
|
10712
10786
|
const sessionUrl = `${this.eyepopUrl()}/v1/sessions/${sessionUuid}`;
|
|
10713
10787
|
this._requestLogger.debug("fetching session from: %s", sessionUrl);
|
|
10714
10788
|
const headers = {
|
|
10715
|
-
Authorization: await this.
|
|
10789
|
+
Authorization: await this.computeAuthorizationHeader()
|
|
10716
10790
|
};
|
|
10717
10791
|
let response = await httpClient.fetch(sessionUrl, {
|
|
10718
10792
|
headers
|
|
@@ -10728,7 +10802,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10728
10802
|
const response_content = await response.json();
|
|
10729
10803
|
session = response_content;
|
|
10730
10804
|
}
|
|
10731
|
-
return
|
|
10805
|
+
return session;
|
|
10732
10806
|
}
|
|
10733
10807
|
async startTransientPipeline() {
|
|
10734
10808
|
const client = this._client;
|
|
@@ -10737,12 +10811,12 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10737
10811
|
throw new Error("endpoint not initialized");
|
|
10738
10812
|
}
|
|
10739
10813
|
let pop;
|
|
10740
|
-
if (this.
|
|
10814
|
+
if (this.options().pop) {
|
|
10815
|
+
pop = this.options().pop;
|
|
10816
|
+
} else if (this._pipeline && this._pipeline.pop) {
|
|
10741
10817
|
pop = this._pipeline.pop;
|
|
10742
10818
|
} else {
|
|
10743
|
-
|
|
10744
|
-
components: []
|
|
10745
|
-
};
|
|
10819
|
+
throw new Error("Cannot start a transient pipeline without a pop");
|
|
10746
10820
|
}
|
|
10747
10821
|
const body = {
|
|
10748
10822
|
pop,
|
|
@@ -10754,8 +10828,9 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10754
10828
|
videoOutput: "no_output"
|
|
10755
10829
|
};
|
|
10756
10830
|
const post_url = `${baseUrl.replace(/\/+$/, "")}/pipelines`;
|
|
10757
|
-
|
|
10831
|
+
const response = await this.fetchWithRetry(async () => {
|
|
10758
10832
|
let headers = {
|
|
10833
|
+
Accept: "application/json",
|
|
10759
10834
|
"Content-Type": "application/json",
|
|
10760
10835
|
Authorization: await this.authorizationHeader()
|
|
10761
10836
|
};
|
|
@@ -10767,11 +10842,138 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10767
10842
|
});
|
|
10768
10843
|
if (response.status != 200) {
|
|
10769
10844
|
const message = await response.text();
|
|
10770
|
-
throw new Error(`Unexpected status ${response.status}: ${message}`);
|
|
10845
|
+
throw new Error(`Unexpected status ${response.status} starting transient pipeline: ${message.slice(0, 300)}`);
|
|
10771
10846
|
}
|
|
10772
10847
|
const result = await response.json();
|
|
10773
10848
|
return result["id"];
|
|
10774
10849
|
}
|
|
10850
|
+
async ensureTransientPipelineStarted() {
|
|
10851
|
+
if (this.options().popId != "transient" /* Transient */ || this._pipelineId) {
|
|
10852
|
+
return;
|
|
10853
|
+
}
|
|
10854
|
+
if (!this.options().pop) {
|
|
10855
|
+
return;
|
|
10856
|
+
}
|
|
10857
|
+
if (!this._baseUrl) {
|
|
10858
|
+
await this.reconnect();
|
|
10859
|
+
}
|
|
10860
|
+
if (this._pipelineId) {
|
|
10861
|
+
return;
|
|
10862
|
+
}
|
|
10863
|
+
if (!this._pipelineCreatePromise) {
|
|
10864
|
+
this._pipelineCreatePromise = this.startTransientPipeline();
|
|
10865
|
+
}
|
|
10866
|
+
try {
|
|
10867
|
+
this._pipelineId = await this._pipelineCreatePromise;
|
|
10868
|
+
this.setTransientPipelinePop();
|
|
10869
|
+
} finally {
|
|
10870
|
+
this._pipelineCreatePromise = null;
|
|
10871
|
+
}
|
|
10872
|
+
}
|
|
10873
|
+
async changeTransientPop(pop) {
|
|
10874
|
+
if (!this._client) {
|
|
10875
|
+
throw new Error("endpoint not initialized");
|
|
10876
|
+
}
|
|
10877
|
+
const previousPop = this.options().pop;
|
|
10878
|
+
const previousPipeline = this._pipeline;
|
|
10879
|
+
if (this._pipelineId) {
|
|
10880
|
+
await this.deleteTransientPipeline(this._pipelineId);
|
|
10881
|
+
this._pipelineId = null;
|
|
10882
|
+
}
|
|
10883
|
+
this._pipeline = null;
|
|
10884
|
+
try {
|
|
10885
|
+
this.options().pop = pop;
|
|
10886
|
+
await this.ensureTransientPipelineStarted();
|
|
10887
|
+
} catch (error) {
|
|
10888
|
+
this.options().pop = previousPop;
|
|
10889
|
+
this._pipeline = previousPipeline;
|
|
10890
|
+
throw error;
|
|
10891
|
+
}
|
|
10892
|
+
if (!this._pipelineId) {
|
|
10893
|
+
throw new Error("Compute session did not provide a pipeline for the requested pop");
|
|
10894
|
+
}
|
|
10895
|
+
this.setTransientPipelinePop();
|
|
10896
|
+
}
|
|
10897
|
+
async deleteTransientPipeline(pipelineId) {
|
|
10898
|
+
if (!this._client || !this._baseUrl) {
|
|
10899
|
+
return;
|
|
10900
|
+
}
|
|
10901
|
+
const deleteUrl = `${this._baseUrl}/pipelines/${pipelineId}`;
|
|
10902
|
+
const headers = {
|
|
10903
|
+
Authorization: await this.authorizationHeader()
|
|
10904
|
+
};
|
|
10905
|
+
let response = await this._client.fetch(deleteUrl, {
|
|
10906
|
+
method: "DELETE",
|
|
10907
|
+
headers
|
|
10908
|
+
});
|
|
10909
|
+
if (response.status >= 300) {
|
|
10910
|
+
const message = await response.text();
|
|
10911
|
+
this._logger.info(`stopping pipeline failed, status ${response.status}: ${message}`);
|
|
10912
|
+
}
|
|
10913
|
+
}
|
|
10914
|
+
pipelineIdFromSession(session) {
|
|
10915
|
+
if (session.pipeline_uuid) {
|
|
10916
|
+
return session.pipeline_uuid;
|
|
10917
|
+
}
|
|
10918
|
+
const pipeline = session.pipelines?.[0];
|
|
10919
|
+
return pipeline?.id || pipeline?.pipeline_id || null;
|
|
10920
|
+
}
|
|
10921
|
+
async authorizationHeader() {
|
|
10922
|
+
if (this._sessionAccessToken) {
|
|
10923
|
+
return `Bearer ${this._sessionAccessToken}`;
|
|
10924
|
+
}
|
|
10925
|
+
return super.authorizationHeader();
|
|
10926
|
+
}
|
|
10927
|
+
async computeAuthorizationHeader() {
|
|
10928
|
+
if (this.options().auth.isLocal !== void 0) {
|
|
10929
|
+
return "Implicit";
|
|
10930
|
+
}
|
|
10931
|
+
if (this.options().auth.apiKey !== void 0) {
|
|
10932
|
+
return `Bearer ${this.options().auth.apiKey}`;
|
|
10933
|
+
}
|
|
10934
|
+
return super.authorizationHeader();
|
|
10935
|
+
}
|
|
10936
|
+
setComputeSessionAccessToken(session) {
|
|
10937
|
+
if (!session.access_token) {
|
|
10938
|
+
throw new Error(`Compute session ${session.session_uuid} did not provide an access token`);
|
|
10939
|
+
}
|
|
10940
|
+
this._sessionAccessToken = session.access_token;
|
|
10941
|
+
if (session.access_token_expires_at) {
|
|
10942
|
+
const expiresAt = Date.parse(session.access_token_expires_at);
|
|
10943
|
+
this._sessionAccessTokenValidUntil = Number.isNaN(expiresAt) ? null : expiresAt;
|
|
10944
|
+
} else if (session.access_token_expires_in) {
|
|
10945
|
+
this._sessionAccessTokenValidUntil = Date.now() + session.access_token_expires_in * 1e3;
|
|
10946
|
+
} else {
|
|
10947
|
+
this._sessionAccessTokenValidUntil = null;
|
|
10948
|
+
}
|
|
10949
|
+
}
|
|
10950
|
+
setTransientPipelinePop() {
|
|
10951
|
+
const pop = this.options().pop;
|
|
10952
|
+
if (pop && this._pipelineId) {
|
|
10953
|
+
this._pipeline = {
|
|
10954
|
+
id: this._pipelineId,
|
|
10955
|
+
state: "idle",
|
|
10956
|
+
startTime: (/* @__PURE__ */ new Date()).toString(),
|
|
10957
|
+
pop
|
|
10958
|
+
};
|
|
10959
|
+
}
|
|
10960
|
+
}
|
|
10961
|
+
sessionCreateBody() {
|
|
10962
|
+
const body = {};
|
|
10963
|
+
if (this.options().sessionName) {
|
|
10964
|
+
body.session_name = this.options().sessionName;
|
|
10965
|
+
}
|
|
10966
|
+
if (this.options().pipelineImage) {
|
|
10967
|
+
body.pipeline_image = this.options().pipelineImage;
|
|
10968
|
+
}
|
|
10969
|
+
if (this.options().pipelineVersion) {
|
|
10970
|
+
body.pipeline_version = this.options().pipelineVersion;
|
|
10971
|
+
}
|
|
10972
|
+
if (this.options().pop) {
|
|
10973
|
+
body.pop = this.options().pop;
|
|
10974
|
+
}
|
|
10975
|
+
return Object.keys(body).length > 0 ? JSON.stringify(body) : void 0;
|
|
10976
|
+
}
|
|
10775
10977
|
};
|
|
10776
10978
|
_WorkerEndpoint.SESSION_DEAD = /* @__PURE__ */ new Set(["error" /* ERROR */, "failed" /* FAILED */, "stopped" /* STOPPED */, "pipeline_error" /* PIPELINE_ERROR */, "unknown" /* UNKNOWN */]);
|
|
10777
10979
|
_WorkerEndpoint.WAIT_FOR_IS_READY = 60 * 1e3;
|
|
@@ -12149,6 +12351,15 @@ var EyePop;
|
|
|
12149
12351
|
if (opts.sessionUuid === void 0) {
|
|
12150
12352
|
opts.sessionUuid = readEnv("EYEPOP_SESSION_UUID");
|
|
12151
12353
|
}
|
|
12354
|
+
if (opts.sessionName === void 0) {
|
|
12355
|
+
opts.sessionName = readEnv("EYEPOP_SESSION_NAME");
|
|
12356
|
+
}
|
|
12357
|
+
if (opts.pipelineImage === void 0) {
|
|
12358
|
+
opts.pipelineImage = readEnv("EYEPOP_PIPELINE_IMAGE");
|
|
12359
|
+
}
|
|
12360
|
+
if (opts.pipelineVersion === void 0) {
|
|
12361
|
+
opts.pipelineVersion = readEnv("EYEPOP_PIPELINE_VERSION");
|
|
12362
|
+
}
|
|
12152
12363
|
if (opts.popId === void 0 && opts.sessionUuid === void 0) {
|
|
12153
12364
|
opts.popId = readEnv("EYEPOP_POP_ID") || "transient" /* Transient */;
|
|
12154
12365
|
}
|