@eyepop.ai/eyepop 1.9.1 → 1.10.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.
@@ -8755,10 +8755,7 @@ var Stream = class _Stream {
8755
8755
  }
8756
8756
  };
8757
8757
  };
8758
- return [
8759
- new _Stream(() => teeIterator(left), this.controller),
8760
- new _Stream(() => teeIterator(right), this.controller)
8761
- ];
8758
+ return [new _Stream(() => teeIterator(left), this.controller), new _Stream(() => teeIterator(right), this.controller)];
8762
8759
  }
8763
8760
  /**
8764
8761
  * Converts this stream to a newline-separated ReadableStream of
@@ -8842,13 +8839,9 @@ var _LineDecoder = class _LineDecoder {
8842
8839
  this.textDecoder ?? (this.textDecoder = new TextDecoder("utf8"));
8843
8840
  return this.textDecoder.decode(bytes);
8844
8841
  }
8845
- throw new Error(
8846
- `Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`
8847
- );
8842
+ throw new Error(`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`);
8848
8843
  }
8849
- throw new Error(
8850
- `Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`
8851
- );
8844
+ throw new Error(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`);
8852
8845
  }
8853
8846
  flush() {
8854
8847
  if (!this.buffer.length && !this.trailingCR) {
@@ -8904,13 +8897,9 @@ var AbstractJob = class {
8904
8897
  if (!this._responseStream) {
8905
8898
  throw Error("logical bug");
8906
8899
  }
8907
- return Stream.iterFromReadableStream(
8908
- this._responseStream,
8909
- this._controller,
8910
- async (event) => {
8911
- return await this.onEvent(event);
8912
- }
8913
- );
8900
+ return Stream.iterFromReadableStream(this._responseStream, this._controller, async (event) => {
8901
+ return await this.onEvent(event);
8902
+ });
8914
8903
  }
8915
8904
  async startJob() {
8916
8905
  return Promise.reject("abstract class");
@@ -9004,8 +8993,8 @@ var UploadJob = class extends AbstractJob {
9004
8993
  formData.append("params", paramBlob);
9005
8994
  formData.append("file", this._uploadStream);
9006
8995
  const headers = {
9007
- "Authorization": `Bearer ${session.accessToken}`,
9008
- "Accept": "application/jsonl"
8996
+ ...session.authenticationHeaders(),
8997
+ Accept: "application/jsonl"
9009
8998
  };
9010
8999
  request = this._client.fetch(postUrl, {
9011
9000
  headers,
@@ -9018,8 +9007,8 @@ var UploadJob = class extends AbstractJob {
9018
9007
  } else {
9019
9008
  this._requestLogger.debug("before POST %s with stream as body", postUrl);
9020
9009
  const headers = {
9021
- "Authorization": `Bearer ${session.accessToken}`,
9022
- "Accept": "application/jsonl",
9010
+ ...session.authenticationHeaders(),
9011
+ Accept: "application/jsonl",
9023
9012
  "Content-Type": this._mimeType
9024
9013
  };
9025
9014
  request = this._client.fetch(postUrl, {
@@ -9052,8 +9041,8 @@ var UploadJob = class extends AbstractJob {
9052
9041
  if (this._needsFullDuplex) {
9053
9042
  const prepareUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/prepareSource?timeout=10s`;
9054
9043
  const headers = {
9055
- "Authorization": `Bearer ${session.accessToken}`,
9056
- "Accept": "application/jsonl"
9044
+ ...session.authenticationHeaders(),
9045
+ Accept: "application/jsonl"
9057
9046
  };
9058
9047
  this._requestLogger.debug("before POST %s to prepare full duplex upload", prepareUrl);
9059
9048
  response = await this._client.fetch(prepareUrl, {
@@ -9074,8 +9063,8 @@ var UploadJob = class extends AbstractJob {
9074
9063
  formData.append("params", paramBlob);
9075
9064
  formData.append("file", this._uploadStream);
9076
9065
  const headers = {
9077
- "Authorization": `Bearer ${session.accessToken}`,
9078
- "Accept": "application/jsonl"
9066
+ ...session.authenticationHeaders(),
9067
+ Accept: "application/jsonl"
9079
9068
  };
9080
9069
  response = await this._client.fetch(postUrl, {
9081
9070
  headers,
@@ -9089,8 +9078,8 @@ var UploadJob = class extends AbstractJob {
9089
9078
  } else {
9090
9079
  this._requestLogger.debug("before POST %s with stream as body", postUrl);
9091
9080
  const headers = {
9092
- "Authorization": `Bearer ${session.accessToken}`,
9093
- "Accept": "application/jsonl",
9081
+ ...session.authenticationHeaders(),
9082
+ Accept: "application/jsonl",
9094
9083
  "Content-Type": this._mimeType
9095
9084
  };
9096
9085
  response = await this._client.fetch(postUrl, {
@@ -9121,13 +9110,13 @@ var LoadFromJob = class extends AbstractJob {
9121
9110
  return Promise.reject("session.baseUrl must not ne null");
9122
9111
  }
9123
9112
  const body = {
9124
- "sourceType": "URL",
9125
- "url": this._location,
9126
- "params": this._params
9113
+ sourceType: "URL",
9114
+ url: this._location,
9115
+ params: this._params
9127
9116
  };
9128
9117
  const headers = {
9129
- "Authorization": `Bearer ${session.accessToken}`,
9130
- "Accept": "application/jsonl",
9118
+ ...session.authenticationHeaders(),
9119
+ Accept: "application/jsonl",
9131
9120
  "Content-Type": "application/json"
9132
9121
  };
9133
9122
  const patchUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/source?mode=queue&processing=sync`;
@@ -9156,13 +9145,13 @@ var LoadLiveIngressJob = class extends AbstractJob {
9156
9145
  return Promise.reject("session.baseUrl must not ne null");
9157
9146
  }
9158
9147
  const body = {
9159
- "sourceType": "LIVE_INGRESS",
9160
- "liveIngressId": this._ingressId,
9161
- "params": this._params
9148
+ sourceType: "LIVE_INGRESS",
9149
+ liveIngressId: this._ingressId,
9150
+ params: this._params
9162
9151
  };
9163
9152
  const headers = {
9164
- "Authorization": `Bearer ${session.accessToken}`,
9165
- "Accept": "application/jsonl",
9153
+ ...session.authenticationHeaders(),
9154
+ Accept: "application/jsonl",
9166
9155
  "Content-Type": "application/json"
9167
9156
  };
9168
9157
  const patchUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/source?mode=preempt&processing=sync`;
@@ -9263,7 +9252,7 @@ var WebrtcBase = class _WebrtcBase {
9263
9252
  const ingressUrl = new URL(this._urlPath, session.baseUrl);
9264
9253
  this._requestLogger.debug("before POST: %s", ingressUrl);
9265
9254
  const headers = {
9266
- "Authorization": `Bearer ${session.accessToken}`,
9255
+ ...session.authenticationHeaders(),
9267
9256
  "Content-Type": "application/sdp"
9268
9257
  };
9269
9258
  const response = await this._client.fetch(ingressUrl, {
@@ -9276,10 +9265,12 @@ var WebrtcBase = class _WebrtcBase {
9276
9265
  }
9277
9266
  this._eTag = response.headers.get("ETag") ?? "";
9278
9267
  this._location = response.headers.get("Location");
9279
- return this.onRemoteAnswer(new RTCSessionDescription({
9280
- type: "answer",
9281
- sdp: await response.text()
9282
- }));
9268
+ return this.onRemoteAnswer(
9269
+ new RTCSessionDescription({
9270
+ type: "answer",
9271
+ sdp: await response.text()
9272
+ })
9273
+ );
9283
9274
  }
9284
9275
  async sendLocalCandidates(candidates) {
9285
9276
  if (!this._offerData) {
@@ -9295,7 +9286,7 @@ var WebrtcBase = class _WebrtcBase {
9295
9286
  const ingressUrl = new URL(urlPath, session.baseUrl);
9296
9287
  this._requestLogger.debug("before PATCH: %s", ingressUrl);
9297
9288
  const headers = {
9298
- "Authorization": `Bearer ${session.accessToken}`,
9289
+ ...session.authenticationHeaders(),
9299
9290
  "Content-Type": "application/trickle-ice-sdpfrag",
9300
9291
  "If-Match": this._eTag
9301
9292
  };
@@ -9476,11 +9467,8 @@ var WebrtcWhip = class extends WebrtcBase {
9476
9467
  const session = await this._getSession();
9477
9468
  const ingressUrl = new URL(this._urlPath, session.baseUrl);
9478
9469
  this._requestLogger.debug("before GET: %s", ingressUrl);
9479
- const headers = {
9480
- "Authorization": `Bearer ${session.accessToken}`
9481
- };
9482
9470
  const response = await this._client.fetch(ingressUrl, {
9483
- headers,
9471
+ headers: session.authenticationHeaders(),
9484
9472
  method: "GET"
9485
9473
  });
9486
9474
  if (response.status >= 300) {
@@ -9580,11 +9568,8 @@ var WebrtcWhep = class extends WebrtcBase {
9580
9568
  const session = await this._getSession();
9581
9569
  const egressUrl = new URL(this._urlPath, session.baseUrl);
9582
9570
  this._requestLogger.debug("before GET: %s", egressUrl);
9583
- const headers = {
9584
- "Authorization": `Bearer ${session.accessToken}`
9585
- };
9586
9571
  const response = await this._client.fetch(egressUrl, {
9587
- headers,
9572
+ headers: session.authenticationHeaders(),
9588
9573
  method: "GET"
9589
9574
  });
9590
9575
  if (response.status >= 300) {
@@ -9686,7 +9671,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
9686
9671
  constructor() {
9687
9672
  }
9688
9673
  async fetch(input, init) {
9689
- return fetch(input, init);
9674
+ return await fetch(input, init);
9690
9675
  }
9691
9676
  async close() {
9692
9677
  }
@@ -9702,7 +9687,7 @@ if ("document" in globalThis && "implementation" in globalThis.document) {
9702
9687
  async fetch(input, init) {
9703
9688
  init || (init = {});
9704
9689
  init.dispatcher = this.agent;
9705
- return fetch(input, init);
9690
+ return await fetch(input, init);
9706
9691
  }
9707
9692
  async close() {
9708
9693
  return this.agent.close();
@@ -9980,6 +9965,7 @@ var Endpoint = class {
9980
9965
  this._expire_token_time = this._options.auth.session.validUntil / 1e3;
9981
9966
  } else if (this._options.auth.oAuth2 !== void 0) {
9982
9967
  } else if (this._options.auth.secretKey !== void 0) {
9968
+ } else if (this._options.auth.isLocal !== void 0) {
9983
9969
  } else {
9984
9970
  return Promise.reject("option secretKey or environment variable EYEPOP_SECRET_KEY is required");
9985
9971
  }
@@ -10017,7 +10003,7 @@ var Endpoint = class {
10017
10003
  while (true) {
10018
10004
  try {
10019
10005
  const response = await fetcher();
10020
- if (response.status <= 300) {
10006
+ if (response.ok) {
10021
10007
  return response;
10022
10008
  } else {
10023
10009
  const handler = this._statusRetryHandlers.get(response.status);
@@ -10026,10 +10012,10 @@ var Endpoint = class {
10026
10012
  if (retries--) {
10027
10013
  this._requestLogger.info("received %d response, retry", response.status);
10028
10014
  } else {
10029
- return Promise.reject(`response ${response.status}: ${response.statusText}`);
10015
+ return response;
10030
10016
  }
10031
10017
  } else {
10032
- return Promise.reject(`response ${response.status}: ${response.statusText}`);
10018
+ return response;
10033
10019
  }
10034
10020
  }
10035
10021
  } catch (error) {
@@ -10051,6 +10037,9 @@ var Endpoint = class {
10051
10037
  throw new Error("reconnect() not implemented");
10052
10038
  }
10053
10039
  async authorizationHeader() {
10040
+ if (this._options.auth.isLocal !== void 0) {
10041
+ return `Implicit`;
10042
+ }
10054
10043
  return `Bearer ${await this.currentAccessToken()}`;
10055
10044
  }
10056
10045
  async currentAccessToken() {
@@ -10060,6 +10049,9 @@ var Endpoint = class {
10060
10049
  try {
10061
10050
  if (!this._client) {
10062
10051
  return Promise.reject("endpoint not connected");
10052
+ } else if (this._options.auth.isLocal !== void 0) {
10053
+ this._token = "implicit";
10054
+ this._expire_token_time = Number.MAX_VALUE;
10063
10055
  } else if (this._options.auth.session !== void 0) {
10064
10056
  return Promise.reject("temporary access token expired");
10065
10057
  } else if (this._options.auth.oAuth2 !== void 0 && this._options.eyepopUrl) {
@@ -10068,7 +10060,7 @@ var Endpoint = class {
10068
10060
  this._expire_token_time = session.validUntil / 1e3;
10069
10061
  } else if (this._options.auth.secretKey !== void 0 && this._options.eyepopUrl) {
10070
10062
  const secretKeyAuth = this._options.auth;
10071
- const body = { "secret_key": secretKeyAuth.secretKey };
10063
+ const body = { secret_key: secretKeyAuth.secretKey };
10072
10064
  const headers = { "Content-Type": "application/json" };
10073
10065
  const post_url = `${this.eyepopUrl()}/authentication/token`;
10074
10066
  this._requestLogger.debug("before POST %s", post_url);
@@ -10117,7 +10109,7 @@ var WorkerEndpoint = class extends Endpoint {
10117
10109
  this._ingressEventWs = null;
10118
10110
  this._sandboxId = null;
10119
10111
  const sessionAuth = options.auth;
10120
- if (sessionAuth.session !== void 0) {
10112
+ if (sessionAuth !== void 0 && sessionAuth.session !== void 0) {
10121
10113
  const workerSession = sessionAuth.session;
10122
10114
  if (workerSession.sandboxId) {
10123
10115
  this._sandboxId = workerSession.sandboxId;
@@ -10129,10 +10121,26 @@ var WorkerEndpoint = class extends Endpoint {
10129
10121
  return this._options;
10130
10122
  }
10131
10123
  async disconnect(wait = true) {
10124
+ if (this.options().popId == "transient" /* Transient */ && this._pipelineId) {
10125
+ const deleteUrl = `${this._baseUrl}/pipelines/${this._pipelineId}`;
10126
+ const headers = {
10127
+ Authorization: await this.authorizationHeader()
10128
+ };
10129
+ this._requestLogger.debug("before DELETE %s", deleteUrl);
10130
+ let response = await this._client?.fetch(deleteUrl, {
10131
+ method: "DELETE",
10132
+ headers
10133
+ });
10134
+ this._requestLogger.debug("after DELETE %s", deleteUrl);
10135
+ if (response?.status != 204) {
10136
+ const message = await response?.text();
10137
+ this._logger.info(`stoppping pipeline failed, status ${response?.status}: ${message}`);
10138
+ }
10139
+ }
10132
10140
  if (this._sandboxId && this._baseUrl) {
10133
10141
  const sandboxUrl = `${this._baseUrl}/sandboxes/${this._sandboxId}`;
10134
10142
  const headers = {
10135
- "Authorization": await this.authorizationHeader()
10143
+ Authorization: await this.authorizationHeader()
10136
10144
  };
10137
10145
  this._requestLogger.debug("before DELETE %s", sandboxUrl);
10138
10146
  let response = await this._client?.fetch(sandboxUrl, {
@@ -10142,7 +10150,7 @@ var WorkerEndpoint = class extends Endpoint {
10142
10150
  this._requestLogger.debug("after DELETE %s", sandboxUrl);
10143
10151
  if (response?.status != 204) {
10144
10152
  const message = await response?.text();
10145
- return Promise.reject(`disconnecting sandbox failed, status ${response?.status}: ${message}`);
10153
+ this._logger.info(`disconnecting sandbox failed, status ${response?.status}: ${message}`);
10146
10154
  }
10147
10155
  this._sandboxId = null;
10148
10156
  }
@@ -10167,7 +10175,8 @@ var WorkerEndpoint = class extends Endpoint {
10167
10175
  popId: this.options().popId,
10168
10176
  baseUrl: this._baseUrl,
10169
10177
  pipelineId: this._pipelineId,
10170
- sandboxId: this._sandboxId ?? void 0
10178
+ sandboxId: this._sandboxId ?? void 0,
10179
+ authenticationHeaders: () => this._authenticationHeaders(session)
10171
10180
  };
10172
10181
  }
10173
10182
  popName() {
@@ -10189,12 +10198,12 @@ var WorkerEndpoint = class extends Endpoint {
10189
10198
  let response = await this.fetchWithRetry(async () => {
10190
10199
  const session = await this.session();
10191
10200
  let headers = {
10192
- "Authorization": `Bearer ${session.accessToken}`,
10193
- "Content-Type": "application/json"
10201
+ "Content-Type": "application/json",
10202
+ ...this._authenticationHeaders(session)
10194
10203
  };
10195
10204
  const patch_url = `${session.baseUrl}/pipelines/${session.pipelineId}/pop`;
10196
10205
  this._requestLogger.debug("before PATCH %s - %s", patch_url, JSON.stringify(pop));
10197
- return client.fetch(patch_url, {
10206
+ return await client.fetch(patch_url, {
10198
10207
  method: "PATCH",
10199
10208
  body: JSON.stringify(pop),
10200
10209
  headers
@@ -10202,7 +10211,6 @@ var WorkerEndpoint = class extends Endpoint {
10202
10211
  });
10203
10212
  if (response.status != 204) {
10204
10213
  const message = await response.text();
10205
- console.error(message);
10206
10214
  return Promise.reject(`Unexpected status ${response.status}: ${message}`);
10207
10215
  }
10208
10216
  this._requestLogger.debug("after PATCH pop");
@@ -10210,6 +10218,9 @@ var WorkerEndpoint = class extends Endpoint {
10210
10218
  this._pipeline.pop = pop;
10211
10219
  }
10212
10220
  }
10221
+ _authenticationHeaders(session) {
10222
+ return this._options.auth.isLocal !== void 0 ? {} : { Authorization: `Bearer ${session.accessToken}` };
10223
+ }
10213
10224
  /**
10214
10225
  * @deprecated use pop() instead
10215
10226
  */
@@ -10230,13 +10241,13 @@ var WorkerEndpoint = class extends Endpoint {
10230
10241
  return Promise.reject("endpoint not connected, use connect() before changePopComp()");
10231
10242
  }
10232
10243
  const body = {
10233
- "pipeline": popComp,
10234
- "modelRefs": modelRefs
10244
+ pipeline: popComp,
10245
+ modelRefs
10235
10246
  };
10236
10247
  let response = await this.fetchWithRetry(async () => {
10237
10248
  const session = await this.session();
10238
10249
  let headers = {
10239
- "Authorization": `Bearer ${session.accessToken}`,
10250
+ ...this._authenticationHeaders(session),
10240
10251
  "Content-Type": "application/json"
10241
10252
  };
10242
10253
  const patch_url = `${session.baseUrl}/pipelines/${session.pipelineId}/inferencePipeline`;
@@ -10248,7 +10259,6 @@ var WorkerEndpoint = class extends Endpoint {
10248
10259
  });
10249
10260
  if (response.status != 204) {
10250
10261
  const message = await response.text();
10251
- console.error(message);
10252
10262
  return Promise.reject(`Unexpected status ${response.status}: ${message}`);
10253
10263
  }
10254
10264
  if (this._pipeline) {
@@ -10276,12 +10286,12 @@ var WorkerEndpoint = class extends Endpoint {
10276
10286
  return Promise.reject("endpoint not connected, use connect() before changePopComp()");
10277
10287
  }
10278
10288
  const body = {
10279
- "transform": postTransform
10289
+ transform: postTransform
10280
10290
  };
10281
10291
  let response = await this.fetchWithRetry(async () => {
10282
10292
  const session = await this.session();
10283
10293
  let headers = {
10284
- "Authorization": `Bearer ${session.accessToken}`,
10294
+ ...this._authenticationHeaders(session),
10285
10295
  "Content-Type": "application/json"
10286
10296
  };
10287
10297
  const patch_url = `${session.baseUrl}/pipelines/${session.pipelineId}/postTransform`;
@@ -10314,18 +10324,28 @@ var WorkerEndpoint = class extends Endpoint {
10314
10324
  if (!this._baseUrl || !this._client) {
10315
10325
  return Promise.reject("endpoint not connected, use connect() before ingress()");
10316
10326
  }
10317
- const whip = new WebrtcWhip(stream, async () => {
10318
- return this.session();
10319
- }, this._client, this._requestLogger);
10327
+ const whip = new WebrtcWhip(
10328
+ stream,
10329
+ async () => {
10330
+ return this.session();
10331
+ },
10332
+ this._client,
10333
+ this._requestLogger
10334
+ );
10320
10335
  return whip.start();
10321
10336
  }
10322
10337
  async liveEgress(ingressId) {
10323
10338
  if (!this._baseUrl || !this._client) {
10324
10339
  return Promise.reject("endpoint not connected, use connect() before ingress()");
10325
10340
  }
10326
- const whep = new WebrtcWhep(ingressId, async () => {
10327
- return this.session();
10328
- }, this._client, this._requestLogger);
10341
+ const whep = new WebrtcWhep(
10342
+ ingressId,
10343
+ async () => {
10344
+ return this.session();
10345
+ },
10346
+ this._client,
10347
+ this._requestLogger
10348
+ );
10329
10349
  return whep.start();
10330
10350
  }
10331
10351
  async process(source, params = void 0) {
@@ -10352,7 +10372,7 @@ var WorkerEndpoint = class extends Endpoint {
10352
10372
  const session = await this.session();
10353
10373
  let response = await this.fetchWithRetry(async () => {
10354
10374
  const headers = {
10355
- "Authorization": `Bearer ${session.accessToken}`
10375
+ ...this._authenticationHeaders(session)
10356
10376
  };
10357
10377
  const getTokenUrl = `${session.baseUrl}/liveIngress/events/token`;
10358
10378
  return client.fetch(getTokenUrl, { headers });
@@ -10381,14 +10401,24 @@ var WorkerEndpoint = class extends Endpoint {
10381
10401
  await this._limit.acquire();
10382
10402
  try {
10383
10403
  this.updateState();
10384
- const job = new UploadJob(source.file, source.file.type, params, async () => {
10385
- return this.session();
10386
- }, this._client, this._requestLogger);
10387
- return job.start(() => {
10388
- this.jobDone(job);
10389
- }, (statusCode) => {
10390
- this.jobStatus(job, statusCode);
10391
- });
10404
+ const job = new UploadJob(
10405
+ source.file,
10406
+ source.file.type,
10407
+ params,
10408
+ async () => {
10409
+ return this.session();
10410
+ },
10411
+ this._client,
10412
+ this._requestLogger
10413
+ );
10414
+ return job.start(
10415
+ () => {
10416
+ this.jobDone(job);
10417
+ },
10418
+ (statusCode) => {
10419
+ this.jobStatus(job, statusCode);
10420
+ }
10421
+ );
10392
10422
  } catch (e) {
10393
10423
  this._limit.release();
10394
10424
  throw e;
@@ -10401,14 +10431,24 @@ var WorkerEndpoint = class extends Endpoint {
10401
10431
  await this._limit.acquire();
10402
10432
  try {
10403
10433
  this.updateState();
10404
- const job = new UploadJob(source.stream, source.mimeType, params, async () => {
10405
- return this.session();
10406
- }, this._client, this._requestLogger);
10407
- return job.start(() => {
10408
- this.jobDone(job);
10409
- }, (statusCode) => {
10410
- this.jobStatus(job, statusCode);
10411
- });
10434
+ const job = new UploadJob(
10435
+ source.stream,
10436
+ source.mimeType,
10437
+ params,
10438
+ async () => {
10439
+ return this.session();
10440
+ },
10441
+ this._client,
10442
+ this._requestLogger
10443
+ );
10444
+ return job.start(
10445
+ () => {
10446
+ this.jobDone(job);
10447
+ },
10448
+ (statusCode) => {
10449
+ this.jobStatus(job, statusCode);
10450
+ }
10451
+ );
10412
10452
  } catch (e) {
10413
10453
  this._limit.release();
10414
10454
  throw e;
@@ -10422,14 +10462,24 @@ var WorkerEndpoint = class extends Endpoint {
10422
10462
  try {
10423
10463
  this.updateState();
10424
10464
  const streamSource = await resolvePath(source);
10425
- const job = new UploadJob(streamSource.stream, streamSource.mimeType, params, async () => {
10426
- return this.session();
10427
- }, this._client, this._requestLogger);
10428
- return job.start(() => {
10429
- this.jobDone(job);
10430
- }, (statusCode) => {
10431
- this.jobStatus(job, statusCode);
10432
- });
10465
+ const job = new UploadJob(
10466
+ streamSource.stream,
10467
+ streamSource.mimeType,
10468
+ params,
10469
+ async () => {
10470
+ return this.session();
10471
+ },
10472
+ this._client,
10473
+ this._requestLogger
10474
+ );
10475
+ return job.start(
10476
+ () => {
10477
+ this.jobDone(job);
10478
+ },
10479
+ (statusCode) => {
10480
+ this.jobStatus(job, statusCode);
10481
+ }
10482
+ );
10433
10483
  } catch (e) {
10434
10484
  this._limit.release();
10435
10485
  throw e;
@@ -10442,14 +10492,23 @@ var WorkerEndpoint = class extends Endpoint {
10442
10492
  await this._limit.acquire();
10443
10493
  try {
10444
10494
  this.updateState();
10445
- const job = new LoadFromJob(source.url, params, async () => {
10446
- return this.session();
10447
- }, this._client, this._requestLogger);
10448
- return job.start(() => {
10449
- this.jobDone(job);
10450
- }, (statusCode) => {
10451
- this.jobStatus(job, statusCode);
10452
- });
10495
+ const job = new LoadFromJob(
10496
+ source.url,
10497
+ params,
10498
+ async () => {
10499
+ return this.session();
10500
+ },
10501
+ this._client,
10502
+ this._requestLogger
10503
+ );
10504
+ return job.start(
10505
+ () => {
10506
+ this.jobDone(job);
10507
+ },
10508
+ (statusCode) => {
10509
+ this.jobStatus(job, statusCode);
10510
+ }
10511
+ );
10453
10512
  } catch (e) {
10454
10513
  this._limit.release();
10455
10514
  throw e;
@@ -10462,14 +10521,23 @@ var WorkerEndpoint = class extends Endpoint {
10462
10521
  await this._limit.acquire();
10463
10522
  try {
10464
10523
  this.updateState();
10465
- const job = new LoadLiveIngressJob(source.ingressId, params, async () => {
10466
- return this.session();
10467
- }, this._client, this._requestLogger);
10468
- return job.start(() => {
10469
- this.jobDone(job);
10470
- }, (statusCode) => {
10471
- this.jobStatus(job, statusCode);
10472
- });
10524
+ const job = new LoadLiveIngressJob(
10525
+ source.ingressId,
10526
+ params,
10527
+ async () => {
10528
+ return this.session();
10529
+ },
10530
+ this._client,
10531
+ this._requestLogger
10532
+ );
10533
+ return job.start(
10534
+ () => {
10535
+ this.jobDone(job);
10536
+ },
10537
+ (statusCode) => {
10538
+ this.jobStatus(job, statusCode);
10539
+ }
10540
+ );
10473
10541
  } catch (e) {
10474
10542
  this._limit.release();
10475
10543
  throw e;
@@ -10497,7 +10565,7 @@ var WorkerEndpoint = class extends Endpoint {
10497
10565
  config_url = `${this.eyepopUrl()}/pops/${this.options().popId}/config?auto_start=false`;
10498
10566
  }
10499
10567
  const headers = {
10500
- "Authorization": await this.authorizationHeader()
10568
+ Authorization: await this.authorizationHeader()
10501
10569
  };
10502
10570
  this.updateState("FetchConfig" /* FetchConfig */);
10503
10571
  this._requestLogger.debug("before GET %s", config_url);
@@ -10506,7 +10574,7 @@ var WorkerEndpoint = class extends Endpoint {
10506
10574
  this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", config_url);
10507
10575
  this.statusHandler401(response.status);
10508
10576
  const headers2 = {
10509
- "Authorization": await this.authorizationHeader()
10577
+ Authorization: await this.authorizationHeader()
10510
10578
  };
10511
10579
  this.updateState("FetchConfig" /* FetchConfig */);
10512
10580
  response = await this._client.fetch(config_url, {
@@ -10528,7 +10596,7 @@ var WorkerEndpoint = class extends Endpoint {
10528
10596
  const auto_start_config_url = `${this.eyepopUrl()}/pops/${this.options().popId}/config?auto_start=true`;
10529
10597
  this._requestLogger.debug("pop was not running, trying to autostart with: %s", auto_start_config_url);
10530
10598
  const headers2 = {
10531
- "Authorization": await this.authorizationHeader()
10599
+ Authorization: await this.authorizationHeader()
10532
10600
  };
10533
10601
  response = await this._client.fetch(auto_start_config_url, {
10534
10602
  headers: headers2
@@ -10546,7 +10614,7 @@ var WorkerEndpoint = class extends Endpoint {
10546
10614
  this._baseUrl = this._baseUrl.replace(/\/+$/, "");
10547
10615
  if (this.options().isSandbox && this._sandboxId === null) {
10548
10616
  const headers3 = {
10549
- "Authorization": await this.authorizationHeader()
10617
+ Authorization: await this.authorizationHeader()
10550
10618
  };
10551
10619
  const createSandboxUrl = `${this._baseUrl}/sandboxes`;
10552
10620
  this._requestLogger.debug("before POST %s", createSandboxUrl);
@@ -10577,7 +10645,7 @@ var WorkerEndpoint = class extends Endpoint {
10577
10645
  this._baseUrl = this._baseUrl.replace(/\/+$/, "");
10578
10646
  const get_url = `${this._baseUrl}/pipelines/${this._pipelineId}`;
10579
10647
  const headers2 = {
10580
- "Authorization": await this.authorizationHeader()
10648
+ Authorization: await this.authorizationHeader()
10581
10649
  };
10582
10650
  this._requestLogger.debug("before GET %s", get_url);
10583
10651
  let response2 = await this._client.fetch(get_url, {
@@ -10591,9 +10659,9 @@ var WorkerEndpoint = class extends Endpoint {
10591
10659
  this._requestLogger.debug("after GET %s", get_url);
10592
10660
  this._pipeline = await response2.json();
10593
10661
  if (this.options().stopJobs) {
10594
- const body = { "sourceType": "NONE" };
10662
+ const body = { sourceType: "NONE" };
10595
10663
  const headers3 = {
10596
- "Authorization": await this.authorizationHeader()
10664
+ Authorization: await this.authorizationHeader()
10597
10665
  };
10598
10666
  const stop_url = `${this._baseUrl}/pipelines/${this._pipeline.id}/source?mode=preempt&processing=sync`;
10599
10667
  let response3 = await this._client.fetch(stop_url, {
@@ -10629,13 +10697,13 @@ var WorkerEndpoint = class extends Endpoint {
10629
10697
  };
10630
10698
  }
10631
10699
  const body = {
10632
- "pop": pop,
10633
- "source": {
10634
- "sourceType": "NONE"
10700
+ pop,
10701
+ source: {
10702
+ sourceType: "NONE"
10635
10703
  },
10636
- "idleTimeoutSeconds": 30,
10637
- "logging": ["out_meta"],
10638
- "videoOutput": "no_output"
10704
+ idleTimeoutSeconds: 30,
10705
+ logging: ["out_meta"],
10706
+ videoOutput: "no_output"
10639
10707
  };
10640
10708
  let post_url;
10641
10709
  if (sandboxId) {
@@ -10646,7 +10714,7 @@ var WorkerEndpoint = class extends Endpoint {
10646
10714
  let response = await this.fetchWithRetry(async () => {
10647
10715
  let headers = {
10648
10716
  "Content-Type": "application/json",
10649
- "Authorization": await this.authorizationHeader()
10717
+ Authorization: await this.authorizationHeader()
10650
10718
  };
10651
10719
  this._requestLogger.debug("before POST %s", post_url);
10652
10720
  return client.fetch(post_url, {
@@ -10679,7 +10747,7 @@ var WorkerEndpoint = class extends Endpoint {
10679
10747
  let response = await this.fetchWithRetry(async () => {
10680
10748
  const session = await this.session();
10681
10749
  let headers = {
10682
- "Authorization": `Bearer ${session.accessToken}`,
10750
+ ...this._authenticationHeaders(session),
10683
10751
  "Content-Type": "application/json"
10684
10752
  };
10685
10753
  this._requestLogger.debug("before GET %s", get_path);
@@ -10709,7 +10777,7 @@ var WorkerEndpoint = class extends Endpoint {
10709
10777
  let response = await this.fetchWithRetry(async () => {
10710
10778
  const session = await this.session();
10711
10779
  let headers = {
10712
- "Authorization": `Bearer ${session.accessToken}`,
10780
+ ...this._authenticationHeaders(session),
10713
10781
  "Content-Type": "application/json"
10714
10782
  };
10715
10783
  this._requestLogger.debug("before GET %s", get_path);
@@ -10739,7 +10807,7 @@ var WorkerEndpoint = class extends Endpoint {
10739
10807
  let response = await this.fetchWithRetry(async () => {
10740
10808
  const session = await this.session();
10741
10809
  let headers = {
10742
- "Authorization": `Bearer ${session.accessToken}`,
10810
+ ...this._authenticationHeaders(session),
10743
10811
  "Content-Type": "application/json"
10744
10812
  };
10745
10813
  this._requestLogger.debug("before PUT %s", put_url);
@@ -10771,7 +10839,7 @@ var WorkerEndpoint = class extends Endpoint {
10771
10839
  let response = await this.fetchWithRetry(async () => {
10772
10840
  const session = await this.session();
10773
10841
  let headers = {
10774
- "Authorization": `Bearer ${session.accessToken}`,
10842
+ ...this._authenticationHeaders(session),
10775
10843
  "Content-Type": "application/json"
10776
10844
  };
10777
10845
  this._requestLogger.debug("before POST %s", post_url);
@@ -10805,7 +10873,7 @@ var WorkerEndpoint = class extends Endpoint {
10805
10873
  let response = await this.fetchWithRetry(async () => {
10806
10874
  const session = await this.session();
10807
10875
  let headers = {
10808
- "Authorization": `Bearer ${session.accessToken}`,
10876
+ ...this._authenticationHeaders(session),
10809
10877
  "Content-Type": "application/json"
10810
10878
  };
10811
10879
  this._requestLogger.debug("before DELETE %s", delete_url);
@@ -11020,7 +11088,7 @@ var DataEndpoint = class extends Endpoint {
11020
11088
  }
11021
11089
  const config_url = `${this.eyepopUrl()}/data/config?account_uuid=${this._accountId}`;
11022
11090
  let headers = {
11023
- "Authorization": await this.authorizationHeader()
11091
+ Authorization: await this.authorizationHeader()
11024
11092
  };
11025
11093
  this.updateState("FetchConfig" /* FetchConfig */);
11026
11094
  this._requestLogger.debug("before GET %s", config_url);
@@ -11029,7 +11097,7 @@ var DataEndpoint = class extends Endpoint {
11029
11097
  this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", config_url);
11030
11098
  this.statusHandler401(response.status);
11031
11099
  headers = {
11032
- "Authorization": await this.authorizationHeader()
11100
+ Authorization: await this.authorizationHeader()
11033
11101
  };
11034
11102
  this.updateState("FetchConfig" /* FetchConfig */);
11035
11103
  response = await this._client.fetch(config_url, {
@@ -11054,7 +11122,7 @@ var DataEndpoint = class extends Endpoint {
11054
11122
  const client = this._client;
11055
11123
  const url = urlJoin(this._baseUrl, "security", "check?set_cookie=true");
11056
11124
  const headers2 = {
11057
- "Authorization": await this.authorizationHeader()
11125
+ Authorization: await this.authorizationHeader()
11058
11126
  };
11059
11127
  response = await client.fetch(url, {
11060
11128
  headers: headers2
@@ -11141,7 +11209,7 @@ var DataEndpoint = class extends Endpoint {
11141
11209
  const session = await this.session();
11142
11210
  const headers = {
11143
11211
  "Content-Type": "application/json",
11144
- ...disableAuth ? {} : { "Authorization": `Bearer ${session.accessToken}` },
11212
+ ...disableAuth ? {} : { Authorization: `Bearer ${session.accessToken}` },
11145
11213
  ...options.headers || {}
11146
11214
  };
11147
11215
  if (!options.body) {
@@ -11556,6 +11624,13 @@ var readEnv = (env) => {
11556
11624
  }
11557
11625
  return void 0;
11558
11626
  };
11627
+ var stringToBooleanSafe = (str) => {
11628
+ if (typeof str == "undefined") {
11629
+ return false;
11630
+ }
11631
+ const loweCaseStr = str.toLowerCase();
11632
+ return loweCaseStr == "true" || loweCaseStr == "yes";
11633
+ };
11559
11634
  var EyePop;
11560
11635
  ((EyePop2) => {
11561
11636
  const envSecretKey = readEnv("EYEPOP_SECRET_KEY");
@@ -11564,20 +11639,32 @@ var EyePop;
11564
11639
  } : void 0;
11565
11640
  EyePop2.endpoint = workerEndpoint;
11566
11641
  function workerEndpoint(opts = {}) {
11567
- _fill_default_options(opts);
11568
- if (typeof opts.popId == "undefined") {
11569
- opts.popId = readEnv("EYEPOP_POP_ID");
11642
+ if (opts.isLocalMode === void 0) {
11643
+ opts.isLocalMode = stringToBooleanSafe(readEnv("EYEPOP_LOCAL_MODE"));
11570
11644
  }
11571
- if (typeof opts.autoStart == "undefined") {
11645
+ _fill_default_options(opts, opts.isLocalMode ? "http://127.0.0.1:8080/standalone" : void 0);
11646
+ if (opts.auth === void 0) {
11647
+ if (opts.isLocalMode) {
11648
+ opts.auth = { isLocal: true };
11649
+ } else {
11650
+ throw new Error("auth option or EYEPOP_SECRET_KEY environment variable is required");
11651
+ }
11652
+ }
11653
+ if (opts.popId === void 0) {
11654
+ opts.popId = readEnv("EYEPOP_POP_ID") || "transient" /* Transient */;
11655
+ }
11656
+ if (opts.autoStart === void 0) {
11572
11657
  opts.autoStart = true;
11573
11658
  }
11574
- if (typeof opts.stopJobs == "undefined") {
11659
+ if (opts.stopJobs === void 0) {
11575
11660
  opts.stopJobs = true;
11576
11661
  }
11577
- if (opts.auth.session !== void 0) {
11662
+ if (opts.auth !== void 0) {
11578
11663
  if (opts.auth.session !== void 0) {
11579
- if (opts.auth.session.popId) {
11580
- opts.popId = opts.auth.session.popId;
11664
+ if (opts.auth.session !== void 0) {
11665
+ if (opts.auth.session.popId) {
11666
+ opts.popId = opts.auth.session.popId;
11667
+ }
11581
11668
  }
11582
11669
  }
11583
11670
  }
@@ -11586,7 +11673,10 @@ var EyePop;
11586
11673
  EyePop2.workerEndpoint = workerEndpoint;
11587
11674
  function dataEndpoint(opts = {}) {
11588
11675
  _fill_default_options(opts);
11589
- if (typeof opts.accountId == "undefined") {
11676
+ if (opts.auth === void 0) {
11677
+ throw new Error("auth option or EYEPOP_SECRET_KEY environment variable is required");
11678
+ }
11679
+ if (opts.accountId === void 0) {
11590
11680
  opts.accountId = readEnv("EYEPOP_ACCOUNT_ID");
11591
11681
  }
11592
11682
  if (opts.auth.session !== void 0) {
@@ -11599,45 +11689,44 @@ var EyePop;
11599
11689
  return new DataEndpoint(opts);
11600
11690
  }
11601
11691
  EyePop2.dataEndpoint = dataEndpoint;
11602
- function _fill_default_options(opts) {
11603
- if (typeof opts.auth == "undefined") {
11604
- if (typeof defaultAuth == "undefined") {
11605
- throw new Error("auth option or EYEPOP_SECRET_KEY environment variable is required");
11606
- }
11692
+ function _fill_default_options(opts, default_eyepop_url = "https://api.eyepop.ai") {
11693
+ if (opts.auth === void 0) {
11607
11694
  opts.auth = defaultAuth;
11608
11695
  }
11609
- if (typeof opts.eyepopUrl == "undefined") {
11610
- opts.eyepopUrl = readEnv("EYEPOP_URL") || "https://api.eyepop.ai";
11696
+ if (opts.eyepopUrl === void 0) {
11697
+ opts.eyepopUrl = readEnv("EYEPOP_URL") || default_eyepop_url;
11611
11698
  }
11612
- if (typeof opts.jobQueueLength == "undefined") {
11699
+ if (opts.jobQueueLength === void 0) {
11613
11700
  opts.jobQueueLength = 1024;
11614
11701
  }
11615
- if (typeof opts.auth.oAuth2 != "undefined") {
11616
- if (typeof opts.auth.oAuth2 === "boolean") {
11617
- if (opts.eyepopUrl.startsWith("https://web-api.staging.eyepop.xyz")) {
11618
- opts.auth = {
11619
- oAuth2: {
11620
- domain: "dev-eyepop.us.auth0.com",
11621
- clientId: "jktx3YO2UnbkNPvr05PQWf26t1kNTJyg",
11622
- audience: "https://dev-app.eyepop.ai",
11623
- scope: "admin:clouds access:inference-api access:datasets"
11624
- }
11625
- };
11626
- } else {
11627
- opts.auth = {
11628
- oAuth2: {
11629
- domain: "eyepop.us.auth0.com",
11630
- clientId: "Lb9ubA9Hf3jlaqWLUx8XgA0zvotgViCl",
11631
- audience: "https://api.eyepop.ai",
11632
- scope: "admin:clouds access:inference-api access:datasets"
11633
- }
11634
- };
11702
+ if (opts.auth !== void 0) {
11703
+ if (opts.auth.oAuth2 !== void 0) {
11704
+ if (typeof opts.auth.oAuth2 === "boolean") {
11705
+ if (opts.eyepopUrl.startsWith("https://web-api.staging.eyepop.xyz")) {
11706
+ opts.auth = {
11707
+ oAuth2: {
11708
+ domain: "dev-eyepop.us.auth0.com",
11709
+ clientId: "jktx3YO2UnbkNPvr05PQWf26t1kNTJyg",
11710
+ audience: "https://dev-app.eyepop.ai",
11711
+ scope: "admin:clouds access:inference-api access:datasets"
11712
+ }
11713
+ };
11714
+ } else {
11715
+ opts.auth = {
11716
+ oAuth2: {
11717
+ domain: "eyepop.us.auth0.com",
11718
+ clientId: "Lb9ubA9Hf3jlaqWLUx8XgA0zvotgViCl",
11719
+ audience: "https://api.eyepop.ai",
11720
+ scope: "admin:clouds access:inference-api access:datasets"
11721
+ }
11722
+ };
11723
+ }
11635
11724
  }
11636
11725
  }
11637
- }
11638
- if (opts.auth.session !== void 0) {
11639
- if (opts.auth.session.eyepopUrl) {
11640
- opts.eyepopUrl = opts.auth.session.eyepopUrl;
11726
+ if (opts.auth.session !== void 0) {
11727
+ if (opts.auth.session.eyepopUrl) {
11728
+ opts.eyepopUrl = opts.auth.session.eyepopUrl;
11729
+ }
11641
11730
  }
11642
11731
  }
11643
11732
  }