@eyepop.ai/eyepop 0.16.3 → 0.18.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.
@@ -8898,10 +8898,11 @@ function readableStreamAsyncIterable(stream) {
8898
8898
 
8899
8899
  // jobs.ts
8900
8900
  var AbstractJob = class {
8901
- constructor(getSession, client, requestLogger) {
8901
+ constructor(params, getSession, client, requestLogger) {
8902
8902
  this._responseStream = null;
8903
8903
  this._controller = new AbortController();
8904
8904
  this._getSession = getSession;
8905
+ this._params = params ?? null;
8905
8906
  this._client = client;
8906
8907
  this._requestLogger = requestLogger;
8907
8908
  }
@@ -8975,36 +8976,60 @@ var UploadJob = class extends AbstractJob {
8975
8976
  get [Symbol.toStringTag]() {
8976
8977
  return "uploadJob";
8977
8978
  }
8978
- constructor(stream, mimeType, getSession, client, requestLogger) {
8979
- super(getSession, client, requestLogger);
8979
+ constructor(stream, mimeType, params, getSession, client, requestLogger) {
8980
+ super(params, getSession, client, requestLogger);
8980
8981
  this._uploadStream = stream;
8981
8982
  this._mimeType = mimeType;
8982
8983
  }
8983
8984
  async startJob() {
8984
8985
  const session = await this._getSession();
8985
- const headers = {
8986
- "Authorization": `Bearer ${session.accessToken}`,
8987
- "Accept": "application/jsonl",
8988
- "Content-Type": this._mimeType
8989
- };
8990
8986
  const postUrl = `${session.baseUrl.replace(/\/+$/, "")}/pipelines/${session.pipelineId}/source?mode=queue&processing=sync`;
8991
- this._requestLogger.debug("before POST %s with stream as body");
8992
- const response = await this._client.fetch(postUrl, {
8993
- headers,
8994
- method: "POST",
8995
- body: this._uploadStream,
8996
- signal: this._controller.signal,
8997
- // @ts-ignore
8998
- "duplex": "half",
8999
- dispatcher: this._dispatcher
9000
- });
9001
- this._requestLogger.debug("after POST %s with stream as body");
8987
+ let response;
8988
+ if (this._params) {
8989
+ this._requestLogger.debug("before POST %s with multipart body because of params");
8990
+ const params = JSON.stringify(this._params);
8991
+ const paramBlob = new Blob([params], { type: "application/json" });
8992
+ const formData = new FormData();
8993
+ formData.append("params", paramBlob);
8994
+ formData.append("file", this._uploadStream);
8995
+ const headers = {
8996
+ "Authorization": `Bearer ${session.accessToken}`,
8997
+ "Accept": "application/jsonl"
8998
+ };
8999
+ response = await this._client.fetch(postUrl, {
9000
+ headers,
9001
+ method: "POST",
9002
+ body: formData,
9003
+ signal: this._controller.signal,
9004
+ // @ts-ignore
9005
+ "duplex": "half",
9006
+ dispatcher: this._dispatcher
9007
+ });
9008
+ this._requestLogger.debug("after POST %s with multipart body because of params");
9009
+ } else {
9010
+ this._requestLogger.debug("before POST %s with stream as body");
9011
+ const headers = {
9012
+ "Authorization": `Bearer ${session.accessToken}`,
9013
+ "Accept": "application/jsonl",
9014
+ "Content-Type": this._mimeType
9015
+ };
9016
+ response = await this._client.fetch(postUrl, {
9017
+ headers,
9018
+ method: "POST",
9019
+ body: this._uploadStream,
9020
+ signal: this._controller.signal,
9021
+ // @ts-ignore
9022
+ "duplex": "half",
9023
+ dispatcher: this._dispatcher
9024
+ });
9025
+ this._requestLogger.debug("after POST %s with stream as body");
9026
+ }
9002
9027
  return response;
9003
9028
  }
9004
9029
  };
9005
9030
  var LoadFromJob = class extends AbstractJob {
9006
- constructor(location, getSession, client, requestLogger) {
9007
- super(getSession, client, requestLogger);
9031
+ constructor(location, params, getSession, client, requestLogger) {
9032
+ super(params, getSession, client, requestLogger);
9008
9033
  this._location = location;
9009
9034
  }
9010
9035
  get [Symbol.toStringTag]() {
@@ -9013,7 +9038,8 @@ var LoadFromJob = class extends AbstractJob {
9013
9038
  async startJob() {
9014
9039
  const body = {
9015
9040
  "sourceType": "URL",
9016
- "url": this._location
9041
+ "url": this._location,
9042
+ "params": this._params
9017
9043
  };
9018
9044
  const session = await this._getSession();
9019
9045
  const headers = {
@@ -9036,8 +9062,8 @@ var LoadFromJob = class extends AbstractJob {
9036
9062
  }
9037
9063
  };
9038
9064
  var LoadLiveIngressJob = class extends AbstractJob {
9039
- constructor(ingressId, getSession, client, requestLogger) {
9040
- super(getSession, client, requestLogger);
9065
+ constructor(ingressId, params, getSession, client, requestLogger) {
9066
+ super(params, getSession, client, requestLogger);
9041
9067
  this._ingressId = ingressId;
9042
9068
  }
9043
9069
  get [Symbol.toStringTag]() {
@@ -9046,7 +9072,8 @@ var LoadLiveIngressJob = class extends AbstractJob {
9046
9072
  async startJob() {
9047
9073
  const body = {
9048
9074
  "sourceType": "LIVE_INGRESS",
9049
- "liveIngressId": this._ingressId
9075
+ "liveIngressId": this._ingressId,
9076
+ "params": this._params
9050
9077
  };
9051
9078
  const session = await this._getSession();
9052
9079
  const headers = {
@@ -9765,6 +9792,7 @@ var Endpoint = class {
9765
9792
  this._expire_token_time = null;
9766
9793
  this._client = null;
9767
9794
  this._state = "Idle" /* Idle */;
9795
+ this._pipeline = null;
9768
9796
  this._stateChangeHandler = null;
9769
9797
  this._ingressEventHandler = null;
9770
9798
  this._ingressEventWs = null;
@@ -9794,6 +9822,40 @@ var Endpoint = class {
9794
9822
  popName() {
9795
9823
  return this._popName;
9796
9824
  }
9825
+ popComp() {
9826
+ if (this._pipeline) {
9827
+ return this._pipeline.inferPipeline;
9828
+ } else {
9829
+ return null;
9830
+ }
9831
+ }
9832
+ async changePopComp(popComp) {
9833
+ if (!this._baseUrl || !this._client) {
9834
+ return Promise.reject("endpoint not connected, use connect() before changePopComp()");
9835
+ }
9836
+ const patch_url = `${this._baseUrl}/pipelines/${this._pipelineId}/inferencePipeline`;
9837
+ const headers = {
9838
+ "Authorization": await this.authorizationHeader(),
9839
+ "Content-Type": "application/json"
9840
+ };
9841
+ const body = {
9842
+ "pipeline": popComp
9843
+ };
9844
+ this._requestLogger.debug("before PATCH %s", patch_url);
9845
+ let response = await this._client.fetch(patch_url, {
9846
+ method: "PATCH",
9847
+ body: JSON.stringify(body),
9848
+ headers
9849
+ });
9850
+ if (response.status != 204) {
9851
+ const message = await response.text();
9852
+ return Promise.reject(`Unexpected status ${response.status}: ${message}`);
9853
+ }
9854
+ this._requestLogger.debug("after PATCH %s", patch_url);
9855
+ if (this._pipeline) {
9856
+ this._pipeline.inferPipeline = popComp;
9857
+ }
9858
+ }
9797
9859
  popId() {
9798
9860
  return this._options.popId || null;
9799
9861
  }
@@ -9909,17 +9971,17 @@ var Endpoint = class {
9909
9971
  }, this._client, this._requestLogger);
9910
9972
  return whep.start();
9911
9973
  }
9912
- async process(source) {
9974
+ async process(source, params = void 0) {
9913
9975
  if (source.file !== void 0) {
9914
- return this.uploadFile(source);
9976
+ return this.uploadFile(source, params);
9915
9977
  } else if (source.stream !== void 0) {
9916
- return this.uploadStream(source);
9978
+ return this.uploadStream(source, params);
9917
9979
  } else if (source.path !== void 0) {
9918
- return this.uploadPath(source);
9980
+ return this.uploadPath(source, params);
9919
9981
  } else if (source.url !== void 0) {
9920
- return this.loadFrom(source);
9982
+ return this.loadFrom(source, params);
9921
9983
  } else if (source.ingressId !== void 0) {
9922
- return this.loadLiveIngress(source);
9984
+ return this.loadLiveIngress(source, params);
9923
9985
  } else {
9924
9986
  return Promise.reject("unknown source type");
9925
9987
  }
@@ -9961,14 +10023,14 @@ var Endpoint = class {
9961
10023
  this.updateState();
9962
10024
  }
9963
10025
  }
9964
- async uploadFile(source) {
10026
+ async uploadFile(source, params) {
9965
10027
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9966
10028
  return Promise.reject("endpoint not connected, use connect() before upload()");
9967
10029
  }
9968
10030
  await this._limit.acquire();
9969
10031
  try {
9970
10032
  this.updateState();
9971
- const job = new UploadJob(source.file, source.file.type, async () => {
10033
+ const job = new UploadJob(source.file, source.file.type, params, async () => {
9972
10034
  return this.session();
9973
10035
  }, this._client, this._requestLogger);
9974
10036
  return job.start(() => {
@@ -9981,14 +10043,14 @@ var Endpoint = class {
9981
10043
  throw e;
9982
10044
  }
9983
10045
  }
9984
- async uploadStream(source) {
10046
+ async uploadStream(source, params) {
9985
10047
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
9986
10048
  return Promise.reject("endpoint not connected, use connect() before upload()");
9987
10049
  }
9988
10050
  await this._limit.acquire();
9989
10051
  try {
9990
10052
  this.updateState();
9991
- const job = new UploadJob(source.stream, source.mimeType, async () => {
10053
+ const job = new UploadJob(source.stream, source.mimeType, params, async () => {
9992
10054
  return this.session();
9993
10055
  }, this._client, this._requestLogger);
9994
10056
  return job.start(() => {
@@ -10001,7 +10063,7 @@ var Endpoint = class {
10001
10063
  throw e;
10002
10064
  }
10003
10065
  }
10004
- async uploadPath(source) {
10066
+ async uploadPath(source, params) {
10005
10067
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
10006
10068
  throw new Error("endpoint not connected, use connect() before process()");
10007
10069
  }
@@ -10009,7 +10071,7 @@ var Endpoint = class {
10009
10071
  try {
10010
10072
  this.updateState();
10011
10073
  const streamSource = await resolvePath(source);
10012
- const job = new UploadJob(streamSource.stream, streamSource.mimeType, async () => {
10074
+ const job = new UploadJob(streamSource.stream, streamSource.mimeType, params, async () => {
10013
10075
  return this.session();
10014
10076
  }, this._client, this._requestLogger);
10015
10077
  return job.start(() => {
@@ -10022,14 +10084,14 @@ var Endpoint = class {
10022
10084
  throw e;
10023
10085
  }
10024
10086
  }
10025
- async loadFrom(source) {
10087
+ async loadFrom(source, params) {
10026
10088
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
10027
10089
  throw new Error("endpoint not connected, use connect() before loadFrom()");
10028
10090
  }
10029
10091
  await this._limit.acquire();
10030
10092
  try {
10031
10093
  this.updateState();
10032
- const job = new LoadFromJob(source.url, async () => {
10094
+ const job = new LoadFromJob(source.url, params, async () => {
10033
10095
  return this.session();
10034
10096
  }, this._client, this._requestLogger);
10035
10097
  return job.start(() => {
@@ -10042,14 +10104,14 @@ var Endpoint = class {
10042
10104
  throw e;
10043
10105
  }
10044
10106
  }
10045
- async loadLiveIngress(source) {
10107
+ async loadLiveIngress(source, params) {
10046
10108
  if (!this._baseUrl || !this._pipelineId || !this._client || !this._limit) {
10047
10109
  throw new Error("endpoint not connected, use connect() before loadLiveIngress()");
10048
10110
  }
10049
10111
  await this._limit.acquire();
10050
10112
  try {
10051
10113
  this.updateState();
10052
- const job = new LoadLiveIngressJob(source.ingressId, async () => {
10114
+ const job = new LoadLiveIngressJob(source.ingressId, params, async () => {
10053
10115
  return this.session();
10054
10116
  }, this._client, this._requestLogger);
10055
10117
  return job.start(() => {
@@ -10093,7 +10155,12 @@ var Endpoint = class {
10093
10155
  if (!this._client) {
10094
10156
  return Promise.reject("endpoint not initialized");
10095
10157
  }
10096
- const config_url = `${this.eyepopUrl()}/pops/${this._options.popId}/config?auto_start=false`;
10158
+ let config_url;
10159
+ if (this._options.popId == "transient" /* Transient */) {
10160
+ config_url = `${this.eyepopUrl()}/workers/config`;
10161
+ } else {
10162
+ config_url = `${this.eyepopUrl()}/pops/${this._options.popId}/config?auto_start=false`;
10163
+ }
10097
10164
  const headers = {
10098
10165
  "Authorization": await this.authorizationHeader()
10099
10166
  };
@@ -10138,13 +10205,35 @@ var Endpoint = class {
10138
10205
  }
10139
10206
  const baseUrl = new URL(config.base_url, this.eyepopUrl());
10140
10207
  this._baseUrl = baseUrl.toString();
10141
- this._pipelineId = config.pipeline_id;
10142
- this._popName = config.name;
10208
+ if (this._options.popId == "transient" /* Transient */) {
10209
+ this._pipelineId = await this.startPopLessPipeline();
10210
+ this._popName = this._options.popId;
10211
+ } else {
10212
+ this._pipelineId = config.pipeline_id;
10213
+ this._popName = config.name;
10214
+ }
10143
10215
  this._requestLogger.debug("after GET %s: %s / %s", config_url, this._baseUrl, this._pipelineId);
10144
10216
  if (!this._pipelineId || !this._baseUrl) {
10145
10217
  return Promise.reject(`Pop not started`);
10146
10218
  }
10147
10219
  this._baseUrl = this._baseUrl.replace(/\/+$/, "");
10220
+ if (this._baseUrl) {
10221
+ const get_url = `${this._baseUrl}/pipelines/${this._pipelineId}`;
10222
+ const headers2 = {
10223
+ "Authorization": await this.authorizationHeader()
10224
+ };
10225
+ this._requestLogger.debug("before GET %s", get_url);
10226
+ let response2 = await this._client.fetch(get_url, {
10227
+ method: "GET",
10228
+ headers: headers2
10229
+ });
10230
+ if (response2.status > 200) {
10231
+ const message = await response2.text();
10232
+ return Promise.reject(`Unexpected status ${response2.status}: ${message}`);
10233
+ }
10234
+ this._requestLogger.debug("after GET %s", get_url);
10235
+ this._pipeline = await response2.json();
10236
+ }
10148
10237
  this.updateState();
10149
10238
  return Promise.resolve(this);
10150
10239
  }
@@ -10199,6 +10288,60 @@ var Endpoint = class {
10199
10288
  this._logger.debug("using access token, valid for at least %d seconds", this._expire_token_time - now);
10200
10289
  return this._token;
10201
10290
  }
10291
+ async startPopLessPipeline() {
10292
+ if (this._client == null || this._baseUrl == null) {
10293
+ return Promise.reject("endpoint not initialized");
10294
+ }
10295
+ this.updateState("StartingPop" /* StartingPop */);
10296
+ let pipeline;
10297
+ if (this._pipeline) {
10298
+ pipeline = this._pipeline.inferPipeline;
10299
+ } else {
10300
+ pipeline = "identity";
10301
+ }
10302
+ const body = {
10303
+ "inferPipelineDef": {
10304
+ "pipeline": pipeline
10305
+ },
10306
+ "source": {
10307
+ "sourceType": "NONE"
10308
+ },
10309
+ "idleTimeoutSeconds": 30,
10310
+ "logging": ["out_meta"],
10311
+ "videoOutput": "no_output"
10312
+ };
10313
+ const post_url = `${this._baseUrl.replace(/\/+$/, "")}/pipelines`;
10314
+ let headers = {
10315
+ "Content-Type": "application/json",
10316
+ "Authorization": await this.authorizationHeader()
10317
+ };
10318
+ this._requestLogger.debug("before POST %s", post_url);
10319
+ let response = await this._client.fetch(post_url, {
10320
+ method: "POST",
10321
+ headers,
10322
+ body: JSON.stringify(body)
10323
+ });
10324
+ if (response.status == 401) {
10325
+ this._requestLogger.debug("after GET %s: 401, about to retry with fresh access token", post_url);
10326
+ this._token = null;
10327
+ headers = {
10328
+ "Content-Type": "application/json",
10329
+ "Authorization": await this.authorizationHeader()
10330
+ };
10331
+ response = await this._client.fetch(post_url, {
10332
+ method: "POST",
10333
+ headers,
10334
+ body: JSON.stringify(body)
10335
+ });
10336
+ }
10337
+ if (response.status != 200) {
10338
+ const message = await response.text();
10339
+ return Promise.reject(`Unexpected status ${response.status}: ${message}`);
10340
+ }
10341
+ this._requestLogger.debug("after POST %s", post_url);
10342
+ const pipelineId = (await response.json())["id"];
10343
+ return pipelineId;
10344
+ }
10202
10345
  };
10203
10346
 
10204
10347
  // index.ts