@eyepop.ai/eyepop 3.14.7 → 3.15.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.
@@ -10599,8 +10599,10 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10599
10599
  }
10600
10600
  async reconnect() {
10601
10601
  if (this.options().popId == "transient" /* Transient */) {
10602
- await this.startComputeSession();
10602
+ await this.getComputeSession();
10603
10603
  this._pipelineId = await this.startTransientPipeline();
10604
+ } else if (this.options().sessionUuid) {
10605
+ await this.getComputeSession();
10604
10606
  } else {
10605
10607
  await this.startWebApiSessionWithPopId();
10606
10608
  }
@@ -10695,17 +10697,52 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10695
10697
  }
10696
10698
  }
10697
10699
  }
10698
- async startComputeSession() {
10700
+ async getComputeSession() {
10699
10701
  if (!this._client) {
10700
10702
  throw new Error("endpoint not initialized");
10701
10703
  }
10704
+ let session;
10705
+ let headers;
10706
+ const sessionUuid = this.options().sessionUuid;
10707
+ if (sessionUuid) {
10708
+ [session, headers] = await this.getPermanentComputeSession(this._client, sessionUuid);
10709
+ } else {
10710
+ [session, headers] = await this.getOnDemandComputeSession(this._client);
10711
+ }
10712
+ let isReady = false;
10713
+ const deadline = Date.now() + _WorkerEndpoint.WAIT_FOR_IS_READY;
10714
+ while (!isReady) {
10715
+ const health_url = `${session.session_endpoint}/health`;
10716
+ const response = await this._client.fetch(health_url, {
10717
+ headers
10718
+ });
10719
+ if (response.status < 300) {
10720
+ isReady = true;
10721
+ } else if (Date.now() > deadline) {
10722
+ throw new Error(`Created session ${session.session_uuid} did not become healthy after ${_WorkerEndpoint.WAIT_FOR_IS_READY / 1e3} seconds`);
10723
+ } else {
10724
+ this._logger.debug(`session ${session.session_uuid} health check status ${response.status}, wait and poll for update`);
10725
+ await sleep(_WorkerEndpoint.CHECK_FOR_IS_READY_INTERVAL);
10726
+ }
10727
+ }
10728
+ this._baseUrl = session.session_endpoint;
10729
+ this._pipeline = null;
10730
+ if (session.pipeline_uuid) {
10731
+ this._pipelineId = session.pipeline_uuid;
10732
+ } else if (session.pipelines) {
10733
+ this._pipelineId = session.pipelines[0].pipeline_id;
10734
+ } else {
10735
+ this._pipelineId = null;
10736
+ }
10737
+ }
10738
+ async getOnDemandComputeSession(httpClient) {
10702
10739
  let session = null;
10703
10740
  const sessionsUrl = `${this.eyepopUrl()}/v1/sessions`;
10704
10741
  this._requestLogger.debug("fetching sessions from: %s", sessionsUrl);
10705
10742
  const headers = {
10706
10743
  Authorization: await this.authorizationHeader()
10707
10744
  };
10708
- let response = await this._client.fetch(sessionsUrl, {
10745
+ let response = await httpClient.fetch(sessionsUrl, {
10709
10746
  headers
10710
10747
  });
10711
10748
  let sessions;
@@ -10719,11 +10756,10 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10719
10756
  const response_content = await response.json();
10720
10757
  sessions = response_content;
10721
10758
  }
10722
- console.log(sessions);
10723
10759
  if (sessions.length > 0) {
10724
- this._logger.debug(`User has ${sessions.length} sessions, inspecting for active session`);
10760
+ this._logger.debug(`User has ${sessions.length} sessions, inspecting for usable session`);
10725
10761
  for (let s of sessions) {
10726
- if (!_WorkerEndpoint.SESSION_DEAD.has(s.session_status)) {
10762
+ if (!_WorkerEndpoint.SESSION_DEAD.has(s.session_status) && !s.persistent) {
10727
10763
  session = s;
10728
10764
  this._logger.debug(`Use active session ${s.session_uuid} with pipeline ${s.pipeline_uuid}`);
10729
10765
  break;
@@ -10732,7 +10768,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10732
10768
  }
10733
10769
  if (!session) {
10734
10770
  this._requestLogger.debug("creating a new session at: %s", sessionsUrl);
10735
- response = await this._client.fetch(`${sessionsUrl}?wait=true`, {
10771
+ response = await httpClient.fetch(`${sessionsUrl}?wait=true`, {
10736
10772
  headers,
10737
10773
  method: "POST"
10738
10774
  });
@@ -10751,29 +10787,30 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10751
10787
  if (!session) {
10752
10788
  throw new Error("unexpected undefined session");
10753
10789
  }
10754
- let isReady = false;
10755
- const deadline = Date.now() + _WorkerEndpoint.WAIT_FOR_IS_READY;
10756
- while (!isReady) {
10757
- const health_url = `${session.session_endpoint}/health`;
10758
- response = await this._client.fetch(health_url, {
10759
- headers
10760
- });
10761
- if (response.status < 300) {
10762
- isReady = true;
10763
- } else if (Date.now() > deadline) {
10764
- throw new Error(`Created session ${session.session_uuid} did not become healthy after ${_WorkerEndpoint.WAIT_FOR_IS_READY / 1e3} seconds`);
10765
- } else {
10766
- this._logger.debug(`session ${session.session_uuid} health check status ${response.status}, wait and poll for update`);
10767
- await sleep(_WorkerEndpoint.CHECK_FOR_IS_READY_INTERVAL);
10768
- }
10769
- }
10770
- this._baseUrl = session.session_endpoint;
10771
- this._pipeline = null;
10772
- if (session.pipeline_uuid) {
10773
- this._pipelineId = session.pipeline_uuid;
10790
+ return [session, headers];
10791
+ }
10792
+ async getPermanentComputeSession(httpClient, sessionUuid) {
10793
+ let session = null;
10794
+ const sessionUrl = `${this.eyepopUrl()}/v1/sessions/${sessionUuid}`;
10795
+ this._requestLogger.debug("fetching session from: %s", sessionUrl);
10796
+ const headers = {
10797
+ Authorization: await this.authorizationHeader()
10798
+ };
10799
+ let response = await httpClient.fetch(sessionUrl, {
10800
+ headers
10801
+ });
10802
+ if (response.status == 404) {
10803
+ this.updateState("Error" /* Error */);
10804
+ throw new Error(`Unexpected status ${response.status} compute sessions ${sessionUuid} not found`);
10805
+ } else if (response.status != 200) {
10806
+ this.updateState("Error" /* Error */);
10807
+ const message = await response.text();
10808
+ throw new Error(`Unexpected status ${response.status} fetching compute sessions: ${message}`);
10774
10809
  } else {
10775
- this._pipelineId = null;
10810
+ const response_content = await response.json();
10811
+ session = response_content;
10776
10812
  }
10813
+ return [session, headers];
10777
10814
  }
10778
10815
  async startTransientPipeline() {
10779
10816
  const client = this._client;
@@ -12191,7 +12228,10 @@ var EyePop;
12191
12228
  throw new Error("auth option or EYEPOP_API_KEY environment variable is required");
12192
12229
  }
12193
12230
  }
12194
- if (opts.popId === void 0) {
12231
+ if (opts.sessionUuid === void 0) {
12232
+ opts.sessionUuid = readEnv("EYEPOP_SESSION_UUID");
12233
+ }
12234
+ if (opts.popId === void 0 && opts.sessionUuid === void 0) {
12195
12235
  opts.popId = readEnv("EYEPOP_POP_ID") || "transient" /* Transient */;
12196
12236
  }
12197
12237
  if (opts.autoStart === void 0) {