@tangle-network/sandbox 0.11.1 → 0.12.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.
- package/README.md +94 -16
- package/dist/agent/index.d.ts +3 -3
- package/dist/{client-D_67csnK.js → client-BCNrDjvA.js} +82 -18
- package/dist/{client-DBioX_CL.d.ts → client-iZbD-9Ks.d.ts} +2 -2
- package/dist/collaboration/index.js +1 -1
- package/dist/{collaboration-DDnuTcZd.js → collaboration-DdD_rFZQ.js} +1 -1
- package/dist/core.d.ts +5 -5
- package/dist/core.js +4 -4
- package/dist/{errors-ntvaf0_F.d.ts → errors-C8HMx78o.d.ts} +2 -2
- package/dist/{errors-Cbs78OlF.js → errors-D9fFOWX9.js} +12 -8
- package/dist/{index-Dj8LzvId.d.ts → index-Bhx4EQca.d.ts} +2 -2
- package/dist/index.d.ts +24 -6
- package/dist/index.js +8 -8
- package/dist/intelligence/index.js +1 -1
- package/dist/{runtime-api-kukaWPtF.js → runtime-api-XhAv6YiH.js} +12 -5
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.js +2 -2
- package/dist/{sandbox-DaLPTCRA.js → sandbox-CWeFm9Hj.js} +978 -57
- package/dist/{sandbox-BRoxCvpS.d.ts → sandbox-hbYwu_Ot.d.ts} +268 -32
- package/dist/session-gateway/index.d.ts +77 -20
- package/dist/session-gateway/index.js +332 -156
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-DHOkbr5a.js → tangle-C8CaT3tE.js} +70 -22
- package/dist/{types-D2C72ySk.d.ts → types-C67osezQ.d.ts} +584 -178
- package/package.json +9 -6
package/dist/tangle/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as TANGLE_JOBS_CONTRACT, c as AgentSandboxBlueprintAbi, d as SandboxCreateParamTypes, f as SandboxCreateResponseParamTypes, i as TANGLE_CHAIN_ID, l as ITangleJobsAbi, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, p as SandboxIdParamTypes, r as JOB_SANDBOX_DELETE, s as TangleSandboxClientConfig, t as TangleSandboxClient, u as JsonResponseParamTypes } from "../index-
|
|
1
|
+
import { a as TANGLE_JOBS_CONTRACT, c as AgentSandboxBlueprintAbi, d as SandboxCreateParamTypes, f as SandboxCreateResponseParamTypes, i as TANGLE_CHAIN_ID, l as ITangleJobsAbi, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, p as SandboxIdParamTypes, r as JOB_SANDBOX_DELETE, s as TangleSandboxClientConfig, t as TangleSandboxClient, u as JsonResponseParamTypes } from "../index-Bhx4EQca.js";
|
|
2
2
|
export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TANGLE_MAINNET_RPC, TangleSandboxClient, TangleSandboxClientConfig };
|
package/dist/tangle/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as TANGLE_JOBS_CONTRACT, c as ITangleJobsAbi, d as SandboxCreateResponseParamTypes, f as SandboxIdParamTypes, i as TANGLE_CHAIN_ID, l as JsonResponseParamTypes, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, r as JOB_SANDBOX_DELETE, s as AgentSandboxBlueprintAbi, t as TangleSandboxClient, u as SandboxCreateParamTypes } from "../tangle-
|
|
1
|
+
import { a as TANGLE_JOBS_CONTRACT, c as ITangleJobsAbi, d as SandboxCreateResponseParamTypes, f as SandboxIdParamTypes, i as TANGLE_CHAIN_ID, l as JsonResponseParamTypes, n as JOB_SANDBOX_CREATE, o as TANGLE_MAINNET_RPC, r as JOB_SANDBOX_DELETE, s as AgentSandboxBlueprintAbi, t as TangleSandboxClient, u as SandboxCreateParamTypes } from "../tangle-C8CaT3tE.js";
|
|
2
2
|
export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TANGLE_MAINNET_RPC, TangleSandboxClient };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { p as parseErrorResponse } from "./errors-
|
|
2
|
-
import {
|
|
1
|
+
import { p as parseErrorResponse } from "./errors-D9fFOWX9.js";
|
|
2
|
+
import { n as createSandboxInstanceFromResponse } from "./sandbox-CWeFm9Hj.js";
|
|
3
3
|
//#region src/tangle/abi.ts
|
|
4
4
|
/**
|
|
5
5
|
* Tangle Contract ABI Definitions
|
|
@@ -632,6 +632,29 @@ function readString(record, keys) {
|
|
|
632
632
|
if (typeof value === "string" && value.length > 0) return value;
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* The incarnation fields are one contract, not three independent hints.
|
|
637
|
+
* Keep the legacy (all absent) wire shape distinct from a partial contract so
|
|
638
|
+
* a readiness-only response cannot authorize a stale runtime credential.
|
|
639
|
+
*/
|
|
640
|
+
function classifyFilesystemIncarnation(value) {
|
|
641
|
+
const rawId = value.filesystemIncarnationId;
|
|
642
|
+
const rawProvenance = value.filesystemIncarnationProvenance;
|
|
643
|
+
const rawReadiness = value.filesystemIncarnationReadiness;
|
|
644
|
+
const id = typeof rawId === "string" && rawId.length > 0 ? rawId : void 0;
|
|
645
|
+
const provenance = rawProvenance === "fresh" || rawProvenance === "restored" || rawProvenance === "unknown" ? rawProvenance : void 0;
|
|
646
|
+
const readiness = rawReadiness === "transitioning" || rawReadiness === "ready" ? rawReadiness : void 0;
|
|
647
|
+
return {
|
|
648
|
+
hasAny: rawId !== void 0 || rawProvenance !== void 0 || rawReadiness !== void 0,
|
|
649
|
+
complete: id !== void 0 && provenance !== void 0 && readiness !== void 0,
|
|
650
|
+
id,
|
|
651
|
+
provenance,
|
|
652
|
+
readiness
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function runtimeCredentialsAllowed(incarnation) {
|
|
656
|
+
return !incarnation.hasAny || incarnation.complete && incarnation.readiness === "ready";
|
|
657
|
+
}
|
|
635
658
|
function entryMetadata(entry) {
|
|
636
659
|
const metadata = {
|
|
637
660
|
...entry.metadata ?? {},
|
|
@@ -642,11 +665,16 @@ function entryMetadata(entry) {
|
|
|
642
665
|
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
643
666
|
}
|
|
644
667
|
function sandboxInfoFromEntry(entry) {
|
|
668
|
+
const incarnation = classifyFilesystemIncarnation(entry);
|
|
669
|
+
const allowRuntime = runtimeCredentialsAllowed(incarnation);
|
|
645
670
|
return {
|
|
646
671
|
id: entry.id,
|
|
647
672
|
name: entry.name,
|
|
673
|
+
filesystemIncarnationId: incarnation.complete ? incarnation.id : void 0,
|
|
674
|
+
filesystemIncarnationProvenance: incarnation.complete ? incarnation.provenance : void 0,
|
|
675
|
+
filesystemIncarnationReadiness: incarnation.complete ? incarnation.readiness : void 0,
|
|
648
676
|
status: entry.status === "deleted" ? "stopped" : entry.status,
|
|
649
|
-
connection: entry.runtimeUrl ? {
|
|
677
|
+
connection: allowRuntime && entry.runtimeUrl ? {
|
|
650
678
|
runtimeUrl: entry.runtimeUrl,
|
|
651
679
|
authToken: entry.runtimeToken
|
|
652
680
|
} : void 0,
|
|
@@ -681,14 +709,26 @@ function sandboxEntryFromWire(fallbackId, raw) {
|
|
|
681
709
|
"sidecarToken",
|
|
682
710
|
"token"
|
|
683
711
|
]) ?? "";
|
|
712
|
+
const tupleField = (key) => Object.hasOwn(raw, key) ? raw[key] : void 0;
|
|
713
|
+
const tupleId = tupleField("filesystemIncarnationId") === void 0 ? void 0 : typeof tupleField("filesystemIncarnationId") === "string" ? tupleField("filesystemIncarnationId") : "";
|
|
714
|
+
const tupleProvenance = tupleField("filesystemIncarnationProvenance") === void 0 ? void 0 : tupleField("filesystemIncarnationProvenance");
|
|
715
|
+
const tupleReadiness = tupleField("filesystemIncarnationReadiness") === void 0 ? void 0 : tupleField("filesystemIncarnationReadiness");
|
|
716
|
+
const allowRuntime = runtimeCredentialsAllowed(classifyFilesystemIncarnation({
|
|
717
|
+
filesystemIncarnationId: tupleId,
|
|
718
|
+
filesystemIncarnationProvenance: tupleProvenance,
|
|
719
|
+
filesystemIncarnationReadiness: tupleReadiness
|
|
720
|
+
}));
|
|
684
721
|
const rawStatus = readString(raw, ["status"]) ?? "running";
|
|
685
722
|
const createdAtRaw = readString(raw, ["createdAt", "created_at"]);
|
|
686
723
|
const createdAt = createdAtRaw ? new Date(createdAtRaw) : /* @__PURE__ */ new Date();
|
|
687
724
|
return {
|
|
688
725
|
id,
|
|
689
726
|
name: readString(raw, ["name"]),
|
|
690
|
-
|
|
691
|
-
|
|
727
|
+
filesystemIncarnationId: tupleId,
|
|
728
|
+
filesystemIncarnationProvenance: tupleProvenance,
|
|
729
|
+
filesystemIncarnationReadiness: tupleReadiness,
|
|
730
|
+
runtimeUrl: allowRuntime ? runtimeUrl : "",
|
|
731
|
+
runtimeToken: allowRuntime ? runtimeToken : "",
|
|
692
732
|
status: rawStatus === "stopped" || rawStatus === "deleted" || rawStatus === "running" ? rawStatus : "running",
|
|
693
733
|
createdAt,
|
|
694
734
|
metadata,
|
|
@@ -728,23 +768,24 @@ var TangleSandboxClient = class {
|
|
|
728
768
|
throw new Error("Failed to decode create job result");
|
|
729
769
|
}
|
|
730
770
|
else throw new Error("No result returned from create job");
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
771
|
+
const wireEntry = sandboxEntryFromWire(sandboxId, responseJson);
|
|
772
|
+
if (wireEntry.runtimeUrl && !wireEntry.runtimeToken) throw new Error("Create job returned a runtime URL without an auth token");
|
|
773
|
+
const allowRuntime = runtimeCredentialsAllowed(classifyFilesystemIncarnation(wireEntry));
|
|
734
774
|
const entry = {
|
|
775
|
+
...wireEntry,
|
|
735
776
|
id: sandboxId,
|
|
736
|
-
name: options?.name,
|
|
737
|
-
runtimeUrl,
|
|
738
|
-
runtimeToken,
|
|
739
|
-
status:
|
|
740
|
-
createdAt:
|
|
741
|
-
metadata: createOptions.metadata,
|
|
742
|
-
teeAttestationJson: responseJson.teeAttestationJson,
|
|
743
|
-
teePublicKeyJson: responseJson.teePublicKeyJson,
|
|
744
|
-
attestationNonce: attestationNonceFromOptions(createOptions)
|
|
777
|
+
name: options?.name ?? wireEntry.name,
|
|
778
|
+
runtimeUrl: allowRuntime ? wireEntry.runtimeUrl : "",
|
|
779
|
+
runtimeToken: allowRuntime ? wireEntry.runtimeToken : "",
|
|
780
|
+
status: wireEntry.status,
|
|
781
|
+
createdAt: wireEntry.createdAt,
|
|
782
|
+
metadata: createOptions.metadata ?? wireEntry.metadata,
|
|
783
|
+
teeAttestationJson: wireEntry.teeAttestationJson ?? responseJson.teeAttestationJson,
|
|
784
|
+
teePublicKeyJson: wireEntry.teePublicKeyJson ?? responseJson.teePublicKeyJson,
|
|
785
|
+
attestationNonce: attestationNonceFromOptions(createOptions) ?? wireEntry.attestationNonce
|
|
745
786
|
};
|
|
746
787
|
this.sandboxes.set(sandboxId, entry);
|
|
747
|
-
return
|
|
788
|
+
return createSandboxInstanceFromResponse(this, sandboxInfoFromEntry(entry));
|
|
748
789
|
}
|
|
749
790
|
/**
|
|
750
791
|
* Get a sandbox by id. Rehydrates from the operator API when configured so
|
|
@@ -758,7 +799,7 @@ var TangleSandboxClient = class {
|
|
|
758
799
|
throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
759
800
|
}
|
|
760
801
|
const data = await response.json();
|
|
761
|
-
return
|
|
802
|
+
return createSandboxInstanceFromResponse(this, sandboxInfoFromEntry(sandboxEntryFromWire(id, data)));
|
|
762
803
|
}
|
|
763
804
|
/**
|
|
764
805
|
* Route interception for SandboxInstance lifecycle calls.
|
|
@@ -781,7 +822,7 @@ var TangleSandboxClient = class {
|
|
|
781
822
|
if (getMatch && method === "GET") {
|
|
782
823
|
const id = decodeURIComponent(requirePathGroup(getMatch, 1));
|
|
783
824
|
let entry = this.sandboxes.get(id);
|
|
784
|
-
if (
|
|
825
|
+
if (this.operatorApiUrl) {
|
|
785
826
|
const operatorResponse = await this.fetchOperatorApi(`/api/sandboxes/${encodeURIComponent(id)}`, { method: "GET" });
|
|
786
827
|
if (!operatorResponse.ok) return operatorResponse;
|
|
787
828
|
entry = sandboxEntryFromWire(id, await operatorResponse.json());
|
|
@@ -861,8 +902,15 @@ var TangleSandboxClient = class {
|
|
|
861
902
|
throw new Error(`Operation not supported via on-chain client: ${method} ${path}`);
|
|
862
903
|
}
|
|
863
904
|
async fetchRuntime(sandboxId, runtimePath, options) {
|
|
864
|
-
|
|
865
|
-
if (
|
|
905
|
+
let entry = this.sandboxes.get(sandboxId);
|
|
906
|
+
if (this.operatorApiUrl) {
|
|
907
|
+
const operatorResponse = await this.fetchOperatorApi(`/api/sandboxes/${encodeURIComponent(sandboxId)}`, { method: "GET" });
|
|
908
|
+
if (!operatorResponse.ok) return operatorResponse;
|
|
909
|
+
entry = sandboxEntryFromWire(sandboxId, await operatorResponse.json());
|
|
910
|
+
this.sandboxes.set(entry.id, entry);
|
|
911
|
+
}
|
|
912
|
+
const incarnation = entry ? classifyFilesystemIncarnation(entry) : void 0;
|
|
913
|
+
if (!entry || !incarnation || !runtimeCredentialsAllowed(incarnation) || !entry.runtimeUrl || !entry.runtimeToken) return new Response(JSON.stringify({ error: "Sandbox runtime unavailable" }), {
|
|
866
914
|
status: 503,
|
|
867
915
|
headers: { "Content-Type": "application/json" }
|
|
868
916
|
});
|