@eyepop.ai/eyepop 3.14.6 → 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.
@@ -8695,6 +8695,7 @@ __export(index_exports, {
8695
8695
  Semaphore: () => Semaphore,
8696
8696
  SessionStatus: () => SessionStatus,
8697
8697
  Stream: () => Stream,
8698
+ TaskMode: () => TaskMode,
8698
8699
  TaskType: () => TaskType,
8699
8700
  TranscodeMode: () => TranscodeMode,
8700
8701
  TransientPopId: () => TransientPopId,
@@ -10598,8 +10599,10 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10598
10599
  }
10599
10600
  async reconnect() {
10600
10601
  if (this.options().popId == "transient" /* Transient */) {
10601
- await this.startComputeSession();
10602
+ await this.getComputeSession();
10602
10603
  this._pipelineId = await this.startTransientPipeline();
10604
+ } else if (this.options().sessionUuid) {
10605
+ await this.getComputeSession();
10603
10606
  } else {
10604
10607
  await this.startWebApiSessionWithPopId();
10605
10608
  }
@@ -10694,17 +10697,52 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10694
10697
  }
10695
10698
  }
10696
10699
  }
10697
- async startComputeSession() {
10700
+ async getComputeSession() {
10698
10701
  if (!this._client) {
10699
10702
  throw new Error("endpoint not initialized");
10700
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) {
10701
10739
  let session = null;
10702
10740
  const sessionsUrl = `${this.eyepopUrl()}/v1/sessions`;
10703
10741
  this._requestLogger.debug("fetching sessions from: %s", sessionsUrl);
10704
10742
  const headers = {
10705
10743
  Authorization: await this.authorizationHeader()
10706
10744
  };
10707
- let response = await this._client.fetch(sessionsUrl, {
10745
+ let response = await httpClient.fetch(sessionsUrl, {
10708
10746
  headers
10709
10747
  });
10710
10748
  let sessions;
@@ -10718,11 +10756,10 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10718
10756
  const response_content = await response.json();
10719
10757
  sessions = response_content;
10720
10758
  }
10721
- console.log(sessions);
10722
10759
  if (sessions.length > 0) {
10723
- 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`);
10724
10761
  for (let s of sessions) {
10725
- if (!_WorkerEndpoint.SESSION_DEAD.has(s.session_status)) {
10762
+ if (!_WorkerEndpoint.SESSION_DEAD.has(s.session_status) && !s.persistent) {
10726
10763
  session = s;
10727
10764
  this._logger.debug(`Use active session ${s.session_uuid} with pipeline ${s.pipeline_uuid}`);
10728
10765
  break;
@@ -10731,7 +10768,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10731
10768
  }
10732
10769
  if (!session) {
10733
10770
  this._requestLogger.debug("creating a new session at: %s", sessionsUrl);
10734
- response = await this._client.fetch(`${sessionsUrl}?wait=true`, {
10771
+ response = await httpClient.fetch(`${sessionsUrl}?wait=true`, {
10735
10772
  headers,
10736
10773
  method: "POST"
10737
10774
  });
@@ -10750,29 +10787,30 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10750
10787
  if (!session) {
10751
10788
  throw new Error("unexpected undefined session");
10752
10789
  }
10753
- let isReady = false;
10754
- const deadline = Date.now() + _WorkerEndpoint.WAIT_FOR_IS_READY;
10755
- while (!isReady) {
10756
- const health_url = `${session.session_endpoint}/health`;
10757
- response = await this._client.fetch(health_url, {
10758
- headers
10759
- });
10760
- if (response.status < 300) {
10761
- isReady = true;
10762
- } else if (Date.now() > deadline) {
10763
- throw new Error(`Created session ${session.session_uuid} did not become healthy after ${_WorkerEndpoint.WAIT_FOR_IS_READY / 1e3} seconds`);
10764
- } else {
10765
- this._logger.debug(`session ${session.session_uuid} health check status ${response.status}, wait and poll for update`);
10766
- await sleep(_WorkerEndpoint.CHECK_FOR_IS_READY_INTERVAL);
10767
- }
10768
- }
10769
- this._baseUrl = session.session_endpoint;
10770
- this._pipeline = null;
10771
- if (session.pipeline_uuid) {
10772
- 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}`);
10773
10809
  } else {
10774
- this._pipelineId = null;
10810
+ const response_content = await response.json();
10811
+ session = response_content;
10775
10812
  }
10813
+ return [session, headers];
10776
10814
  }
10777
10815
  async startTransientPipeline() {
10778
10816
  const client = this._client;
@@ -11078,6 +11116,11 @@ var TaskType = /* @__PURE__ */ ((TaskType2) => {
11078
11116
  TaskType2["classification"] = "classification";
11079
11117
  return TaskType2;
11080
11118
  })(TaskType || {});
11119
+ var TaskMode = /* @__PURE__ */ ((TaskMode2) => {
11120
+ TaskMode2["image"] = "image";
11121
+ TaskMode2["video"] = "video";
11122
+ return TaskMode2;
11123
+ })(TaskMode || {});
11081
11124
  var VlmAbilityStatus = /* @__PURE__ */ ((VlmAbilityStatus2) => {
11082
11125
  VlmAbilityStatus2["in_progress"] = "in_progress";
11083
11126
  VlmAbilityStatus2["draft"] = "draft";
@@ -12185,7 +12228,10 @@ var EyePop;
12185
12228
  throw new Error("auth option or EYEPOP_API_KEY environment variable is required");
12186
12229
  }
12187
12230
  }
12188
- 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) {
12189
12235
  opts.popId = readEnv("EYEPOP_POP_ID") || "transient" /* Transient */;
12190
12236
  }
12191
12237
  if (opts.autoStart === void 0) {
@@ -12309,6 +12355,7 @@ var index_default = EyePop;
12309
12355
  Semaphore,
12310
12356
  SessionStatus,
12311
12357
  Stream,
12358
+ TaskMode,
12312
12359
  TaskType,
12313
12360
  TranscodeMode,
12314
12361
  TransientPopId,