tensorlake 0.5.89 → 0.5.92

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.
@@ -19,7 +19,7 @@ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TI
19
19
  var init_defaults = __esm({
20
20
  "src/defaults.ts"() {
21
21
  "use strict";
22
- SDK_VERSION = "0.5.89";
22
+ SDK_VERSION = "0.5.92";
23
23
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
24
24
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
25
25
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -494,7 +494,8 @@ function parseTimestamp(v) {
494
494
  return new Date(ts * 1e3);
495
495
  }
496
496
  function fromSnakeKeys(obj, idField) {
497
- if (Array.isArray(obj)) return obj.map((item) => fromSnakeKeys(item, idField));
497
+ if (Array.isArray(obj))
498
+ return obj.map((item) => fromSnakeKeys(item, idField));
498
499
  if (obj !== null && typeof obj === "object" && !(obj instanceof Date)) {
499
500
  const result = {};
500
501
  for (const [k, v] of Object.entries(obj)) {
@@ -583,6 +584,22 @@ var init_sse = __esm({
583
584
  });
584
585
 
585
586
  // src/cloud-client.ts
587
+ import { nanoid } from "nanoid";
588
+ function applicationAllowsUnauthenticatedRequests(manifest) {
589
+ return Array.isArray(manifest.allow) && manifest.allow.includes(UNAUTHENTICATED_REQUESTS);
590
+ }
591
+ function publicEndpointIdFromManifest(manifest) {
592
+ for (const key of ["public_endpoint_id", "publicEndpointId"]) {
593
+ const value = manifest[key];
594
+ if (typeof value === "string" && value.length > 0) {
595
+ return value;
596
+ }
597
+ }
598
+ return void 0;
599
+ }
600
+ function generatePublicEndpointId() {
601
+ return `endpoint_${nanoid()}`;
602
+ }
586
603
  function createApplicationBuildForm(request, imageContexts) {
587
604
  const contextsByPartName = /* @__PURE__ */ new Map();
588
605
  for (const context of imageContexts) {
@@ -652,7 +669,7 @@ async function parseJsonResponse(response) {
652
669
  }
653
670
  return JSON.parse(text);
654
671
  }
655
- var CloudClient;
672
+ var CloudClient, UNAUTHENTICATED_REQUESTS;
656
673
  var init_cloud_client = __esm({
657
674
  "src/cloud-client.ts"() {
658
675
  "use strict";
@@ -685,6 +702,19 @@ var init_cloud_client = __esm({
685
702
  this.http.close();
686
703
  }
687
704
  async upsertApplication(manifest, codeZip, upgradeRunningRequests = false) {
705
+ const applicationManifest = { ...manifest };
706
+ let publicEndpointId = publicEndpointIdFromManifest(applicationManifest);
707
+ if (applicationAllowsUnauthenticatedRequests(applicationManifest) && publicEndpointId === void 0) {
708
+ const applicationName = applicationManifest.name;
709
+ if (typeof applicationName === "string" && applicationName.length > 0) {
710
+ publicEndpointId = await this.existingApplicationPublicEndpointId(applicationName);
711
+ }
712
+ publicEndpointId ??= generatePublicEndpointId();
713
+ }
714
+ if (publicEndpointId !== void 0) {
715
+ applicationManifest.public_endpoint_id = publicEndpointId;
716
+ delete applicationManifest.publicEndpointId;
717
+ }
688
718
  const form = new FormData();
689
719
  form.append(
690
720
  "code",
@@ -692,7 +722,7 @@ var init_cloud_client = __esm({
692
722
  "code.zip"
693
723
  );
694
724
  form.append("code_content_type", "application/zip");
695
- form.append("application", JSON.stringify(manifest));
725
+ form.append("application", JSON.stringify(applicationManifest));
696
726
  form.append(
697
727
  "upgrade_requests_to_latest_code",
698
728
  String(upgradeRunningRequests)
@@ -1005,6 +1035,18 @@ var init_cloud_client = __esm({
1005
1035
  namespacePath(subpath) {
1006
1036
  return `/v1/namespaces/${encodeURIComponent(this.namespace)}/${subpath.replace(/^\/+/, "")}`;
1007
1037
  }
1038
+ async existingApplicationPublicEndpointId(applicationName) {
1039
+ const response = await this.http.requestResponse(
1040
+ "GET",
1041
+ this.namespacePath(`applications/${encodeURIComponent(applicationName)}`),
1042
+ { allowedErrorStatusCodes: /* @__PURE__ */ new Set([404]) }
1043
+ );
1044
+ if (response.status === 404) {
1045
+ return void 0;
1046
+ }
1047
+ const application = await parseJsonResponse(response);
1048
+ return publicEndpointIdFromManifest(application);
1049
+ }
1008
1050
  resolveScope(organizationId, projectId) {
1009
1051
  const resolvedOrganizationId = organizationId ?? this.organizationId;
1010
1052
  const resolvedProjectId = projectId ?? this.projectId;
@@ -1019,6 +1061,7 @@ var init_cloud_client = __esm({
1019
1061
  };
1020
1062
  }
1021
1063
  };
1064
+ UNAUTHENTICATED_REQUESTS = "unauthenticated_requests";
1022
1065
  }
1023
1066
  });
1024
1067