@tangle-network/agent-provider-tangle 3.1.2 → 3.1.4
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 +13 -0
- package/dist/tangle-environment.js +6 -2
- package/dist/tangle-evidence.js +53 -9
- package/dist/tangle-types.d.ts +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,19 @@ Set `TANGLE_SANDBOX_URL` to use another deployment.
|
|
|
33
33
|
Exact execution replay preserves the admitted request and its digest.
|
|
34
34
|
An explicit replay override cannot replace the selected account, credential channel, or harness.
|
|
35
35
|
|
|
36
|
+
## Workspace file reads
|
|
37
|
+
|
|
38
|
+
`environment.read` accepts file contents up to 4 MiB, measured in UTF-8 bytes.
|
|
39
|
+
Runtime resolves child source files through this reader without copying their contents into tool arguments.
|
|
40
|
+
Paths keep the control-plane limit.
|
|
41
|
+
Live reads require the selected Sandbox workspace capability.
|
|
42
|
+
|
|
43
|
+
Evidence capture retains full workspace files that exceed the Sandbox JSON read limit through bounded binary downloads.
|
|
44
|
+
This requires a Sandbox SDK whose filesystem advertises `supportsBoundedDownload`.
|
|
45
|
+
Capture verifies the downloaded size and SHA-256 receipt before adding bytes to the archive.
|
|
46
|
+
Aggregate limits, credential exclusions, and exact native-session proof remain enforced.
|
|
47
|
+
An unsupported downloader or incomplete transfer fails capture and preserves the source environment.
|
|
48
|
+
|
|
36
49
|
## Named model credentials at creation
|
|
37
50
|
|
|
38
51
|
`modelCredentials` sends a stored credential reference and explicit endpoint before Sandbox provisions the backend.
|
|
@@ -10,7 +10,7 @@ import { execResultFromSandboxExecResult } from "./tangle-result-values.js";
|
|
|
10
10
|
import { capabilitiesForSandbox, frozenCapabilityDocument, sandboxCapabilitySupport, } from "./tangle-capabilities.js";
|
|
11
11
|
import { profileCredentialSource } from "./model-credential-source.js";
|
|
12
12
|
import { deploymentCapabilitySupport, readDeploymentCapabilitySupport } from "./tangle-deployment-capabilities.js";
|
|
13
|
-
import { awaitWithSignal, assertBoundedJson, boundedIdentifier, boundedString, } from "./tangle-contract-safety.js";
|
|
13
|
+
import { awaitWithSignal, assertBoundedJson, boundedIdentifier, boundedString, MAX_PAYLOAD_STRING_BYTES, } from "./tangle-contract-safety.js";
|
|
14
14
|
import { assertExecOptions, assertOptionKeys, } from "./tangle-environment-validation.js";
|
|
15
15
|
import { interruptExecutionAfterAbort, } from "./tangle-environment-control.js";
|
|
16
16
|
import { dispatchEnvironmentRun } from "./tangle-environment-dispatch.js";
|
|
@@ -317,7 +317,11 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
317
317
|
options?.signal?.throwIfAborted();
|
|
318
318
|
const content = await awaitWithSignal(box.read?.(path, options), options?.signal);
|
|
319
319
|
options?.signal?.throwIfAborted();
|
|
320
|
-
|
|
320
|
+
if (typeof content !== "string" ||
|
|
321
|
+
Buffer.byteLength(content, "utf8") > MAX_PAYLOAD_STRING_BYTES) {
|
|
322
|
+
throw new Error("Tangle file content exceeds its bound");
|
|
323
|
+
}
|
|
324
|
+
return content;
|
|
321
325
|
},
|
|
322
326
|
}
|
|
323
327
|
: {}),
|
package/dist/tangle-evidence.js
CHANGED
|
@@ -149,17 +149,27 @@ export async function captureTangleSandboxEvidence(box, options) {
|
|
|
149
149
|
excludedPaths.push({ ...item, reason: "credential-path" });
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
|
+
const remainingBytes = options.maxBytes - capturedBytes;
|
|
153
|
+
if (entry.size > remainingBytes)
|
|
154
|
+
throw new Error("Tangle evidence exceeds byte limit");
|
|
152
155
|
const result = await fs.readBatch([sourcePath], { encoding: "base64" });
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const bytes = Buffer.from(read.content, "base64");
|
|
158
|
-
if (bytes.byteLength !== entry.size || read.size !== entry.size || bytes.toString("base64") !== read.content) {
|
|
159
|
-
throw new Error(`Tangle evidence workspace file changed or was truncated: ${path}`);
|
|
156
|
+
let bytes;
|
|
157
|
+
if (result.files.length === 0 && result.errors.length === 1 &&
|
|
158
|
+
result.errors[0]?.path === sourcePath && result.errors[0]?.code === "FILE_TOO_LARGE") {
|
|
159
|
+
bytes = await downloadWorkspaceEvidenceFile(fs, sourcePath, entry.size, remainingBytes, options.signal);
|
|
160
160
|
}
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
else {
|
|
162
|
+
if (result.errors.length || result.files.length !== 1 || result.files[0]?.path !== sourcePath || result.files[0]?.encoding !== "base64") {
|
|
163
|
+
throw new Error(`Tangle evidence could not read workspace file ${path}`);
|
|
164
|
+
}
|
|
165
|
+
const read = result.files[0];
|
|
166
|
+
bytes = Buffer.from(read.content, "base64");
|
|
167
|
+
if (bytes.byteLength !== entry.size || read.size !== entry.size || bytes.toString("base64") !== read.content) {
|
|
168
|
+
throw new Error(`Tangle evidence workspace file changed or was truncated: ${path}`);
|
|
169
|
+
}
|
|
170
|
+
if (read.hash && read.hash.replace(/^sha256:/, "") !== createHash("sha256").update(bytes).digest("hex")) {
|
|
171
|
+
throw new Error(`Tangle evidence workspace file hash mismatch: ${path}`);
|
|
172
|
+
}
|
|
163
173
|
}
|
|
164
174
|
files.push({ path, bytes, mode: entry.permissions & 0o777 });
|
|
165
175
|
capturedBytes += bytes.byteLength;
|
|
@@ -664,6 +674,40 @@ export async function captureTangleSandboxEvidence(box, options) {
|
|
|
664
674
|
files.push({ path: "__retention__/provenance.json", bytes: provenanceBytes, mode: 0o600 });
|
|
665
675
|
return { files: files.sort((a, b) => a.path.localeCompare(b.path)), provenance };
|
|
666
676
|
}
|
|
677
|
+
/** The JSON reader has a smaller transport cap than an evidence archive. */
|
|
678
|
+
async function downloadWorkspaceEvidenceFile(fs, sourcePath, expectedSize, maxBytes, signal) {
|
|
679
|
+
if (fs.supportsBoundedDownload !== true || !fs.download) {
|
|
680
|
+
throw new Error(`Tangle evidence requires bounded binary download for workspace file ${sourcePath}`);
|
|
681
|
+
}
|
|
682
|
+
const local = await import("node:fs/promises");
|
|
683
|
+
const { tmpdir } = await import("node:os");
|
|
684
|
+
const { join } = await import("node:path");
|
|
685
|
+
signal?.throwIfAborted();
|
|
686
|
+
const directory = await local.mkdtemp(join(tmpdir(), "tangle-evidence-"));
|
|
687
|
+
try {
|
|
688
|
+
const target = join(directory, "content");
|
|
689
|
+
const receipt = await fs.download(sourcePath, target, { maxBytes, expectedSize, signal });
|
|
690
|
+
signal?.throwIfAborted();
|
|
691
|
+
if (!receipt || receipt.sizeBytes !== expectedSize || !/^[a-f0-9]{64}$/i.test(receipt.sha256)) {
|
|
692
|
+
throw new Error("Tangle evidence binary download omitted its exact size or digest receipt");
|
|
693
|
+
}
|
|
694
|
+
const metadata = await local.stat(target);
|
|
695
|
+
if (!metadata.isFile() || metadata.size !== expectedSize || metadata.size > maxBytes) {
|
|
696
|
+
throw new Error(`Tangle evidence workspace file changed or was truncated: ${sourcePath}`);
|
|
697
|
+
}
|
|
698
|
+
const bytes = await local.readFile(target, { signal });
|
|
699
|
+
if (bytes.byteLength !== expectedSize || bytes.byteLength > maxBytes) {
|
|
700
|
+
throw new Error(`Tangle evidence workspace file changed or was truncated: ${sourcePath}`);
|
|
701
|
+
}
|
|
702
|
+
if (createHash("sha256").update(bytes).digest("hex") !== receipt.sha256.toLowerCase()) {
|
|
703
|
+
throw new Error(`Tangle evidence workspace file hash mismatch: ${sourcePath}`);
|
|
704
|
+
}
|
|
705
|
+
return bytes;
|
|
706
|
+
}
|
|
707
|
+
finally {
|
|
708
|
+
await local.rm(directory, { recursive: true, force: true });
|
|
709
|
+
}
|
|
710
|
+
}
|
|
667
711
|
/** Keep every source field; store validated binary content once in the archive. */
|
|
668
712
|
function withoutNativeContent(source) {
|
|
669
713
|
const metadata = { ...source };
|
package/dist/tangle-types.d.ts
CHANGED
|
@@ -435,6 +435,16 @@ export interface SandboxInstanceLike {
|
|
|
435
435
|
exec?(command: string, options?: unknown): Promise<SandboxExecResult>;
|
|
436
436
|
fs?: {
|
|
437
437
|
supportsWriteMode?: true;
|
|
438
|
+
supportsBoundedDownload?: true;
|
|
439
|
+
download?(remotePath: string, localPath: string, options?: {
|
|
440
|
+
overwrite?: boolean;
|
|
441
|
+
maxBytes?: number;
|
|
442
|
+
expectedSize?: number;
|
|
443
|
+
signal?: AbortSignal;
|
|
444
|
+
}): Promise<void | {
|
|
445
|
+
sizeBytes: number;
|
|
446
|
+
sha256: string;
|
|
447
|
+
}>;
|
|
438
448
|
stat(path: string): Promise<{
|
|
439
449
|
size: number;
|
|
440
450
|
isFile: boolean;
|