@eyepop.ai/eyepop 3.17.0 → 3.17.2
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/dist/eyepop.index.d.mts +4 -1
- package/dist/eyepop.index.d.ts +4 -1
- package/dist/eyepop.index.js +123 -30
- package/dist/eyepop.index.js.map +1 -1
- package/dist/eyepop.index.mjs +123 -30
- package/dist/eyepop.index.mjs.map +1 -1
- package/dist/eyepop.min.js +1 -1
- package/package.json +1 -1
package/dist/eyepop.index.mjs
CHANGED
|
@@ -8681,14 +8681,96 @@ function accessTokenValidUntil(session) {
|
|
|
8681
8681
|
}
|
|
8682
8682
|
return null;
|
|
8683
8683
|
}
|
|
8684
|
+
function errorInfoMessage(errorInfo) {
|
|
8685
|
+
return [errorInfo.code, errorInfo.message, errorInfo.details].filter((part) => typeof part == "string" && part.length > 0).join(": ");
|
|
8686
|
+
}
|
|
8687
|
+
function pipelineErrorMessage(session) {
|
|
8688
|
+
if (session.pipeline_error) {
|
|
8689
|
+
const message = errorInfoMessage(session.pipeline_error);
|
|
8690
|
+
return message ? `Pipeline failed for compute session ${session.session_uuid}: ${message}` : `Pipeline failed for compute session ${session.session_uuid}`;
|
|
8691
|
+
}
|
|
8692
|
+
if (session.session_status == "pipeline_error" /* PIPELINE_ERROR */) {
|
|
8693
|
+
return `Pipeline failed for compute session ${session.session_uuid}`;
|
|
8694
|
+
}
|
|
8695
|
+
return null;
|
|
8696
|
+
}
|
|
8697
|
+
async function responseErrorMessage(response) {
|
|
8698
|
+
const contentType = response.headers.get("content-type") || "";
|
|
8699
|
+
if (contentType.includes("application/json")) {
|
|
8700
|
+
try {
|
|
8701
|
+
const parsed = normalizedJsonValue(await response.clone().json());
|
|
8702
|
+
const message2 = normalizedErrorMessage(parsed);
|
|
8703
|
+
if (message2) {
|
|
8704
|
+
return message2;
|
|
8705
|
+
}
|
|
8706
|
+
} catch (_) {
|
|
8707
|
+
}
|
|
8708
|
+
}
|
|
8709
|
+
const body = await response.text();
|
|
8710
|
+
const message = normalizedErrorMessage(body);
|
|
8711
|
+
return message || body;
|
|
8712
|
+
}
|
|
8713
|
+
function normalizedJsonValue(value) {
|
|
8714
|
+
if (typeof value == "string") {
|
|
8715
|
+
try {
|
|
8716
|
+
const parsed = JSON.parse(value);
|
|
8717
|
+
return normalizedJsonValue(parsed);
|
|
8718
|
+
} catch (_) {
|
|
8719
|
+
const unescaped = value.replace(/\\"/g, '"');
|
|
8720
|
+
if (unescaped != value) {
|
|
8721
|
+
try {
|
|
8722
|
+
const parsed = JSON.parse(unescaped);
|
|
8723
|
+
return normalizedJsonValue(parsed);
|
|
8724
|
+
} catch (_2) {
|
|
8725
|
+
}
|
|
8726
|
+
}
|
|
8727
|
+
return value;
|
|
8728
|
+
}
|
|
8729
|
+
}
|
|
8730
|
+
return value;
|
|
8731
|
+
}
|
|
8732
|
+
async function responseJson(response) {
|
|
8733
|
+
return normalizedJsonValue(await response.json());
|
|
8734
|
+
}
|
|
8735
|
+
function normalizedErrorMessage(value) {
|
|
8736
|
+
value = normalizedJsonValue(value);
|
|
8737
|
+
if (typeof value == "string") {
|
|
8738
|
+
return value;
|
|
8739
|
+
}
|
|
8740
|
+
if (!value || typeof value != "object") {
|
|
8741
|
+
return null;
|
|
8742
|
+
}
|
|
8743
|
+
const record = value;
|
|
8744
|
+
const normalizedError = normalizedJsonValue(record["error"]);
|
|
8745
|
+
const errorMessage = normalizedErrorMessage(normalizedError) || (typeof normalizedError == "string" ? normalizedError : null);
|
|
8746
|
+
const message = [record["code"], errorMessage, record["message"], record["details"]].filter((part) => typeof part == "string" && part.length > 0).join(": ");
|
|
8747
|
+
if (message) {
|
|
8748
|
+
return message;
|
|
8749
|
+
}
|
|
8750
|
+
if (record["pipeline_error"]) {
|
|
8751
|
+
return normalizedErrorMessage(record["pipeline_error"]);
|
|
8752
|
+
}
|
|
8753
|
+
if (normalizedError && typeof normalizedError == "object") {
|
|
8754
|
+
return normalizedErrorMessage(normalizedError);
|
|
8755
|
+
}
|
|
8756
|
+
try {
|
|
8757
|
+
return JSON.stringify(value);
|
|
8758
|
+
} catch (_) {
|
|
8759
|
+
return null;
|
|
8760
|
+
}
|
|
8761
|
+
}
|
|
8684
8762
|
var ComputeSessionClient = class {
|
|
8685
8763
|
constructor(options) {
|
|
8686
8764
|
this.options = options;
|
|
8687
8765
|
}
|
|
8688
8766
|
async resolve() {
|
|
8689
8767
|
const session = this.options.sessionUuid ? await this.getPermanentComputeSession(this.options.sessionUuid) : await this.getOnDemandComputeSession();
|
|
8690
|
-
const
|
|
8691
|
-
|
|
8768
|
+
const pipelineFailure = pipelineErrorMessage(session);
|
|
8769
|
+
if (pipelineFailure) {
|
|
8770
|
+
throw new Error(pipelineFailure);
|
|
8771
|
+
}
|
|
8772
|
+
const authorizationHeader = await this.sessionAuthorizationHeader(session);
|
|
8773
|
+
await this.waitUntilReady(session, authorizationHeader);
|
|
8692
8774
|
const pipelineId = pipelineIdFromSession(session);
|
|
8693
8775
|
if (this.options.pop && !pipelineId) {
|
|
8694
8776
|
throw new Error("Compute session did not provide a pipeline for the requested pop");
|
|
@@ -8696,7 +8778,7 @@ var ComputeSessionClient = class {
|
|
|
8696
8778
|
return {
|
|
8697
8779
|
session,
|
|
8698
8780
|
pipelineId,
|
|
8699
|
-
accessToken,
|
|
8781
|
+
accessToken: session.access_token || null,
|
|
8700
8782
|
accessTokenValidUntil: accessTokenValidUntil(session)
|
|
8701
8783
|
};
|
|
8702
8784
|
}
|
|
@@ -8715,10 +8797,10 @@ var ComputeSessionClient = class {
|
|
|
8715
8797
|
if (response.status == 404) {
|
|
8716
8798
|
sessions = [];
|
|
8717
8799
|
} else if (response.status != 200) {
|
|
8718
|
-
const message = await response
|
|
8800
|
+
const message = await responseErrorMessage(response);
|
|
8719
8801
|
throw new Error(`Unexpected status ${response.status} fetching compute sessions: ${message}`);
|
|
8720
8802
|
} else {
|
|
8721
|
-
const response_content = await response
|
|
8803
|
+
const response_content = await responseJson(response);
|
|
8722
8804
|
sessions = response_content;
|
|
8723
8805
|
}
|
|
8724
8806
|
if (sessions.length > 0) {
|
|
@@ -8749,10 +8831,10 @@ var ComputeSessionClient = class {
|
|
|
8749
8831
|
const query = "wait=true";
|
|
8750
8832
|
const response = await this.options.httpClient.fetch(`${sessionsUrl}?${query}`, request);
|
|
8751
8833
|
if (response.status != 200) {
|
|
8752
|
-
const message = await response
|
|
8834
|
+
const message = await responseErrorMessage(response);
|
|
8753
8835
|
throw new Error(`Unexpected status ${response.status} creating a compute session: ${message}`);
|
|
8754
8836
|
} else {
|
|
8755
|
-
sessions = await response
|
|
8837
|
+
sessions = await responseJson(response);
|
|
8756
8838
|
}
|
|
8757
8839
|
if (sessions.length == 0) {
|
|
8758
8840
|
throw new Error("Unexpected, no compute session after attempt to create one");
|
|
@@ -8762,9 +8844,6 @@ var ComputeSessionClient = class {
|
|
|
8762
8844
|
if (!session) {
|
|
8763
8845
|
throw new Error("unexpected undefined session");
|
|
8764
8846
|
}
|
|
8765
|
-
if (this.options.pop && !pipelineIdFromSession(session)) {
|
|
8766
|
-
throw new Error("Compute session did not provide a pipeline for the requested pop");
|
|
8767
|
-
}
|
|
8768
8847
|
return session;
|
|
8769
8848
|
}
|
|
8770
8849
|
async getPermanentComputeSession(sessionUuid) {
|
|
@@ -8780,28 +8859,28 @@ var ComputeSessionClient = class {
|
|
|
8780
8859
|
if (response.status == 404) {
|
|
8781
8860
|
throw new Error(`Unexpected status ${response.status} compute sessions ${sessionUuid} not found`);
|
|
8782
8861
|
} else if (response.status != 200) {
|
|
8783
|
-
const message = await response
|
|
8862
|
+
const message = await responseErrorMessage(response);
|
|
8784
8863
|
throw new Error(`Unexpected status ${response.status} fetching compute sessions: ${message}`);
|
|
8785
8864
|
} else {
|
|
8786
|
-
const response_content = await response
|
|
8865
|
+
const response_content = await responseJson(response);
|
|
8787
8866
|
session = response_content;
|
|
8788
8867
|
}
|
|
8789
8868
|
return session;
|
|
8790
8869
|
}
|
|
8791
|
-
|
|
8792
|
-
if (
|
|
8793
|
-
|
|
8870
|
+
async sessionAuthorizationHeader(session) {
|
|
8871
|
+
if (session.access_token) {
|
|
8872
|
+
return `Bearer ${session.access_token}`;
|
|
8794
8873
|
}
|
|
8795
|
-
return
|
|
8874
|
+
return this.options.authorizationHeader();
|
|
8796
8875
|
}
|
|
8797
|
-
async waitUntilReady(session,
|
|
8876
|
+
async waitUntilReady(session, authorizationHeader) {
|
|
8798
8877
|
let isReady = false;
|
|
8799
8878
|
const deadline = Date.now() + this.options.readyTimeoutMs;
|
|
8800
8879
|
while (!isReady) {
|
|
8801
8880
|
const health_url = `${session.session_endpoint}/health`;
|
|
8802
8881
|
const response = await this.options.httpClient.fetch(health_url, {
|
|
8803
8882
|
headers: {
|
|
8804
|
-
Authorization:
|
|
8883
|
+
Authorization: authorizationHeader,
|
|
8805
8884
|
Accept: "application/json"
|
|
8806
8885
|
}
|
|
8807
8886
|
});
|
|
@@ -9599,14 +9678,18 @@ var UploadJob = class extends AbstractJob {
|
|
|
9599
9678
|
get [Symbol.toStringTag]() {
|
|
9600
9679
|
return "uploadJob";
|
|
9601
9680
|
}
|
|
9602
|
-
constructor(stream, mimeType, size, videoMode, params, getSession, client, requestLogger) {
|
|
9681
|
+
constructor(stream, mimeType, size, videoMode, params, getSession, client, requestLogger, uploadBodyFactory) {
|
|
9603
9682
|
super(params, getSession, client, requestLogger);
|
|
9604
9683
|
this._uploadStream = stream;
|
|
9684
|
+
this._uploadBodyFactory = uploadBodyFactory;
|
|
9605
9685
|
this._mimeType = mimeType;
|
|
9606
9686
|
this._size = size;
|
|
9607
9687
|
this._videoMode = videoMode;
|
|
9608
9688
|
this._needsFullDuplex = !client.isFullDuplex() && mimeType.startsWith("video/") && videoMode == "stream" /* STREAM */;
|
|
9609
9689
|
}
|
|
9690
|
+
async uploadBody() {
|
|
9691
|
+
return this._uploadBodyFactory ? await this._uploadBodyFactory() : this._uploadStream;
|
|
9692
|
+
}
|
|
9610
9693
|
async onEvent(event) {
|
|
9611
9694
|
if (event.type == "prepared") {
|
|
9612
9695
|
if (!event.source_id) {
|
|
@@ -9648,7 +9731,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9648
9731
|
const blob = new Blob([JSON.stringify(this._params.fps)], { type: "application/json" });
|
|
9649
9732
|
formData.append("fps", blob);
|
|
9650
9733
|
}
|
|
9651
|
-
const fileBlob = await new Response(this.
|
|
9734
|
+
const fileBlob = await new Response(await this.uploadBody()).blob();
|
|
9652
9735
|
formData.append("file", fileBlob);
|
|
9653
9736
|
const headers = {
|
|
9654
9737
|
...session.authenticationHeaders(),
|
|
@@ -9675,7 +9758,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9675
9758
|
request = this._client.fetch(postUrl, {
|
|
9676
9759
|
headers,
|
|
9677
9760
|
method: "POST",
|
|
9678
|
-
body: this.
|
|
9761
|
+
body: await this.uploadBody(),
|
|
9679
9762
|
signal: this._controller.signal,
|
|
9680
9763
|
// @ts-ignore
|
|
9681
9764
|
duplex: "half",
|
|
@@ -9743,7 +9826,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9743
9826
|
const blob = new Blob([JSON.stringify(this._params.fps)], { type: "application/json" });
|
|
9744
9827
|
formData.append("fps", blob);
|
|
9745
9828
|
}
|
|
9746
|
-
const fileBlob = await new Response(this.
|
|
9829
|
+
const fileBlob = await new Response(await this.uploadBody()).blob();
|
|
9747
9830
|
formData.append("file", fileBlob);
|
|
9748
9831
|
const headers = {
|
|
9749
9832
|
...session.authenticationHeaders(),
|
|
@@ -9770,7 +9853,7 @@ var UploadJob = class extends AbstractJob {
|
|
|
9770
9853
|
response = await this._client.fetch(postUrl, {
|
|
9771
9854
|
headers,
|
|
9772
9855
|
method: "POST",
|
|
9773
|
-
body: this.
|
|
9856
|
+
body: await this.uploadBody(),
|
|
9774
9857
|
signal: this._controller.signal,
|
|
9775
9858
|
// @ts-ignore
|
|
9776
9859
|
duplex: "half"
|
|
@@ -10870,12 +10953,21 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10870
10953
|
await this._limit.acquire();
|
|
10871
10954
|
try {
|
|
10872
10955
|
this.updateState();
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
}
|
|
10956
|
+
const resolveStreamSource = async () => {
|
|
10957
|
+
if (this._options.platformSupport?.resolvePath) {
|
|
10958
|
+
return await this._options.platformSupport.resolvePath(source, this._logger);
|
|
10959
|
+
}
|
|
10960
|
+
return await resolvePath(source, this._logger);
|
|
10961
|
+
};
|
|
10962
|
+
const streamSource = await resolveStreamSource();
|
|
10963
|
+
let firstStreamPending = true;
|
|
10964
|
+
const uploadBodyFactory = async () => {
|
|
10965
|
+
if (firstStreamPending) {
|
|
10966
|
+
firstStreamPending = false;
|
|
10967
|
+
return streamSource.stream;
|
|
10968
|
+
}
|
|
10969
|
+
return (await resolveStreamSource()).stream;
|
|
10970
|
+
};
|
|
10879
10971
|
const job = new UploadJob(
|
|
10880
10972
|
streamSource.stream,
|
|
10881
10973
|
streamSource.mimeType,
|
|
@@ -10886,7 +10978,8 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
|
|
|
10886
10978
|
return this.session();
|
|
10887
10979
|
},
|
|
10888
10980
|
this._client,
|
|
10889
|
-
this._requestLogger
|
|
10981
|
+
this._requestLogger,
|
|
10982
|
+
uploadBodyFactory
|
|
10890
10983
|
);
|
|
10891
10984
|
return job.start(
|
|
10892
10985
|
() => {
|