@tangle-network/agent-provider-tangle 3.3.0 → 3.4.1
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 +16 -0
- package/dist/tangle-environment-control.js +4 -3
- package/dist/tangle-environment.js +4 -1
- package/dist/tangle-events.js +9 -3
- package/dist/tangle-prompt.d.ts +6 -5
- package/dist/tangle-prompt.js +31 -110
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,6 +30,12 @@ const provider = createTangleProvider({
|
|
|
30
30
|
`Sandbox` requires an explicit `baseUrl`.
|
|
31
31
|
Set `TANGLE_SANDBOX_URL` to use another deployment.
|
|
32
32
|
|
|
33
|
+
`AgentTurnInput.profile` carries the exact per-turn profile, including mounted file contents larger than the metadata limit.
|
|
34
|
+
The adapter projects it into Sandbox's backend profile and enforces the existing file, inline-payload, and aggregate limits.
|
|
35
|
+
Previously valid `providerOptions.backend.profile` inputs remain supported.
|
|
36
|
+
If both locations are supplied, their canonical profile digests must match; a conflict refuses dispatch before credential selection.
|
|
37
|
+
Use the typed field for large profiles; generic provider metadata keeps its existing limits.
|
|
38
|
+
|
|
33
39
|
Exact execution replay preserves the admitted request and its digest.
|
|
34
40
|
An explicit replay override cannot replace the selected account, credential channel, or harness.
|
|
35
41
|
|
|
@@ -676,3 +682,13 @@ Authentication failures and malformed metadata do not become typed quota refusal
|
|
|
676
682
|
The command transport accepts the same public capacity body only with exit code 75.
|
|
677
683
|
Its typed error has no HTTP status.
|
|
678
684
|
The caller's execution owner decides whether and when to retry.
|
|
685
|
+
|
|
686
|
+
### Completion and native evidence
|
|
687
|
+
|
|
688
|
+
The provider projects terminal results and terminal stream events into bounded completion summaries.
|
|
689
|
+
Cumulative `toolInvocations` stay in native session evidence; they are not copied into the summary or truncated.
|
|
690
|
+
A projected terminal event omits `providerEvent`, which would otherwise claim to contain the full native event.
|
|
691
|
+
The session, execution, and event identities still bind the summary to its source.
|
|
692
|
+
Use `captureTangleEnvironmentEvidence` or the exact Sandbox session's `rawEvidence()` to retain original arguments, outputs, and process records.
|
|
693
|
+
Capture completeness and missing-source reasons remain authoritative; a successful completion does not imply complete archival capture.
|
|
694
|
+
Individual event, terminal text, identity, and usage validation remain unchanged.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { canonicalCandidateDigest } from "@tangle-network/agent-interface";
|
|
2
|
-
import {
|
|
2
|
+
import { backendFromTurnInput, backendRequestIdentity, } from "./tangle-prompt.js";
|
|
3
3
|
export function sessionPromptRequestDigest(input, provider, environmentId, sessionId, options = {}) {
|
|
4
|
-
const backend = backendRequestIdentity(
|
|
4
|
+
const backend = backendRequestIdentity(backendFromTurnInput(input));
|
|
5
5
|
return canonicalCandidateDigest({
|
|
6
6
|
provider,
|
|
7
7
|
environmentId,
|
|
@@ -29,7 +29,8 @@ export function sessionPromptRequestDigest(input, provider, environmentId, sessi
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
export function hasReplayPayload(input) {
|
|
32
|
-
return (input.
|
|
32
|
+
return (input.profile !== undefined ||
|
|
33
|
+
input.prompt !== undefined ||
|
|
33
34
|
input.parts !== undefined ||
|
|
34
35
|
input.model !== undefined ||
|
|
35
36
|
input.timeoutMs !== undefined ||
|
|
@@ -184,11 +184,14 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
184
184
|
// Validate explicit substitutions even on replay, without rewriting its admitted digest.
|
|
185
185
|
if (replay)
|
|
186
186
|
return input;
|
|
187
|
+
const { profile: _profile, ...backendOptions } = backend ?? {};
|
|
187
188
|
return {
|
|
188
189
|
...input,
|
|
189
190
|
providerOptions: {
|
|
190
191
|
...input.providerOptions,
|
|
191
|
-
|
|
192
|
+
// The next validation still sees bounded options, while projection reads
|
|
193
|
+
// the exact typed profile again for the actual SDK dispatch.
|
|
194
|
+
backend: { ...(input.profile === undefined ? backend : backendOptions), type: harness, model: { ...selectedModel, authMode: "oauth" } },
|
|
192
195
|
},
|
|
193
196
|
};
|
|
194
197
|
};
|
package/dist/tangle-events.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CanonicalStreamEventSchema, boundedEventContentRecordSchema, } from "@tangle-network/agent-interface";
|
|
2
2
|
import { optionalNonEmptyString } from "./tangle-environment-values.js";
|
|
3
3
|
import { tokenUsageFromData } from "./tangle-result-values.js";
|
|
4
|
+
import { sandboxTerminalProjection } from "./tangle-prompt.js";
|
|
4
5
|
/** The sidecar sends this envelope when an SSE connection is ready. */
|
|
5
6
|
export function isSandboxConnectionMarker(event) {
|
|
6
7
|
if (!event || typeof event !== "object")
|
|
@@ -133,8 +134,11 @@ export function environmentEventFromSandboxEvent(event, expected = {}) {
|
|
|
133
134
|
record.id.trim() !== record.id)) {
|
|
134
135
|
throw new Error("Tangle Sandbox event contained an invalid event id");
|
|
135
136
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
137
|
+
const terminal = record.type === "result" || record.type === "done";
|
|
138
|
+
const sourceData = record.data;
|
|
139
|
+
const projected = terminal && Object.hasOwn(sourceData, "toolInvocations");
|
|
140
|
+
const data = projected ? sandboxTerminalProjection(sourceData) : sourceData;
|
|
141
|
+
assertBoundedRecord(projected ? { ...record, data } : record);
|
|
138
142
|
if (Object.prototype.hasOwnProperty.call(data, "contextTransferReceipt")) {
|
|
139
143
|
throw new Error("Tangle Sandbox emitted an unsolicited context transfer receipt");
|
|
140
144
|
}
|
|
@@ -189,7 +193,9 @@ export function environmentEventFromSandboxEvent(event, expected = {}) {
|
|
|
189
193
|
// contribute a total to whatever sums these events.
|
|
190
194
|
...(usage ? { usage } : {}),
|
|
191
195
|
...(usageMode === undefined ? {} : { usageMode }),
|
|
192
|
-
|
|
196
|
+
// A terminal projection is not the complete native event. The source is
|
|
197
|
+
// available through exact session/execution evidence, including tool history.
|
|
198
|
+
...(!projected ? { providerEvent: event } : {}),
|
|
193
199
|
};
|
|
194
200
|
}
|
|
195
201
|
function normalizeSandboxEvent(type, data, identity) {
|
package/dist/tangle-prompt.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ export declare function backendFromTurnProviderOptions(providerOptions: Record<s
|
|
|
73
73
|
* identity to the secret inside.
|
|
74
74
|
*/
|
|
75
75
|
export declare function backendRequestIdentity(backend: SandboxPromptBackend | undefined): Record<string, unknown> | undefined;
|
|
76
|
+
/** Project the exact turn profile once for both dispatch and retained identity. */
|
|
77
|
+
export declare function backendFromTurnInput(input: AgentTurnInput): SandboxPromptBackend | undefined;
|
|
76
78
|
type SandboxRunStatus = "success" | "failed" | "blocked_on_approval" | "awaiting_question" | "awaiting_interaction" | "awaiting_plan_decision";
|
|
77
79
|
type ValidatedSandboxPromptResult = Record<string, unknown> & {
|
|
78
80
|
success: boolean;
|
|
@@ -81,12 +83,11 @@ type ValidatedSandboxPromptResult = Record<string, unknown> & {
|
|
|
81
83
|
executionId?: string;
|
|
82
84
|
};
|
|
83
85
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* returned little, and so a caller can decide to re-fetch rather than reason from a partial page.
|
|
86
|
+
* Completion is a bounded summary; cumulative tool history is retained separately.
|
|
87
|
+
* The native session evidence owns the original arguments and outputs. Never
|
|
88
|
+
* truncate that history or require the whole conversation to fit one event.
|
|
88
89
|
*/
|
|
89
|
-
export declare function
|
|
90
|
+
export declare function sandboxTerminalProjection(record: Record<string, unknown>): Record<string, unknown>;
|
|
90
91
|
export declare function validatedSandboxPromptResult(result: PromptResult): ValidatedSandboxPromptResult;
|
|
91
92
|
export declare function agentTurnResultFromPromptRecord(record: ValidatedSandboxPromptResult, options?: {
|
|
92
93
|
contextTransferRequested?: boolean;
|
package/dist/tangle-prompt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertCliAuthReferenceSupported, cliAuthReferenceSchema, } from "@tangle-network/sandbox/auth";
|
|
2
|
-
import { agentProfileSchema,
|
|
2
|
+
import { agentProfileSchema, canonicalAgentProfileDigest, boundedEventContentRecordSchema, AgentExactRunControlRefSchema, AgentTurnInputSchema, ContextTransferReceiptSchema, contextTransferResultMatchesRequest, } from "@tangle-network/agent-interface";
|
|
3
3
|
import { tokenUsageFromData } from "./tangle-result-values.js";
|
|
4
4
|
import { assertBoundedJson, boundedString, PROFILE_AT_PROFILE, } from "./tangle-contract-safety.js";
|
|
5
5
|
import { profileCredentialSource } from "./model-credential-source.js";
|
|
@@ -349,6 +349,24 @@ export function backendRequestIdentity(backend) {
|
|
|
349
349
|
},
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
+
/** Project the exact turn profile once for both dispatch and retained identity. */
|
|
353
|
+
export function backendFromTurnInput(input) {
|
|
354
|
+
const declared = backendFromTurnProviderOptions(input.providerOptions);
|
|
355
|
+
let backend = declared;
|
|
356
|
+
if (input.profile !== undefined) {
|
|
357
|
+
if (declared?.profile !== undefined &&
|
|
358
|
+
canonicalAgentProfileDigest(declared.profile) !== canonicalAgentProfileDigest(input.profile)) {
|
|
359
|
+
throw new Error("Tangle turn profile conflicts with its backend profile");
|
|
360
|
+
}
|
|
361
|
+
if (declared?.type !== undefined && input.profile.harness !== undefined && declared.type !== input.profile.harness) {
|
|
362
|
+
throw new Error("Tangle turn profile conflicts with its backend harness");
|
|
363
|
+
}
|
|
364
|
+
// Validate the complete projected backend, including the existing file/inline
|
|
365
|
+
// payload bounds. The typed profile never becomes provider metadata.
|
|
366
|
+
backend = sandboxPromptBackend({ ...declared, profile: input.profile });
|
|
367
|
+
}
|
|
368
|
+
return backend;
|
|
369
|
+
}
|
|
352
370
|
/**
|
|
353
371
|
* Combine the turn's requested interaction posture with its backend options.
|
|
354
372
|
*
|
|
@@ -359,7 +377,7 @@ export function backendRequestIdentity(backend) {
|
|
|
359
377
|
* posture the caller did not ask for.
|
|
360
378
|
*/
|
|
361
379
|
function turnBackendOptions(input) {
|
|
362
|
-
const backend =
|
|
380
|
+
const backend = backendFromTurnInput(input);
|
|
363
381
|
const backendModel = backend?.model?.model;
|
|
364
382
|
if (input.model !== undefined &&
|
|
365
383
|
backendModel !== undefined &&
|
|
@@ -394,72 +412,13 @@ const SANDBOX_OPTIONAL_RESULT_FIELDS = new Set([
|
|
|
394
412
|
"costUsd",
|
|
395
413
|
]);
|
|
396
414
|
/**
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* returned little, and so a caller can decide to re-fetch rather than reason from a partial page.
|
|
415
|
+
* Completion is a bounded summary; cumulative tool history is retained separately.
|
|
416
|
+
* The native session evidence owns the original arguments and outputs. Never
|
|
417
|
+
* truncate that history or require the whole conversation to fit one event.
|
|
401
418
|
*/
|
|
402
|
-
export function
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Shrink oversized tool output until the whole record fits the content bound.
|
|
407
|
-
*
|
|
408
|
-
* Only `toolInvocations[].result` is touched, because it is the one field that carries arbitrary
|
|
409
|
-
* fetched material rather than identity, accounting, or control state. The largest result is cut
|
|
410
|
-
* first and the loop repeats, so a record with several big results converges instead of destroying
|
|
411
|
-
* the first one it meets.
|
|
412
|
-
*
|
|
413
|
-
* Returns the record unchanged when it already fits, so the common path allocates nothing.
|
|
414
|
-
*/
|
|
415
|
-
function withTruncatedToolOutput(record) {
|
|
416
|
-
if (isBoundedEventContentJson(record))
|
|
417
|
-
return { record, truncated: 0 };
|
|
418
|
-
const invocations = record.toolInvocations;
|
|
419
|
-
if (!Array.isArray(invocations))
|
|
420
|
-
return { record, truncated: 0 };
|
|
421
|
-
const next = invocations.map((entry) => entry && typeof entry === "object" && !Array.isArray(entry)
|
|
422
|
-
? { ...entry }
|
|
423
|
-
: entry);
|
|
424
|
-
const originalLengths = new Map();
|
|
425
|
-
let truncated = 0;
|
|
426
|
-
// Each pass cuts the current widest result by the record's measured overflow, so a single huge
|
|
427
|
-
// value converges immediately and several large ones shrink in turn rather than the first being
|
|
428
|
-
// destroyed. The cap is a backstop: `isBoundedEventContentJson` also enforces node, depth, and
|
|
429
|
-
// array limits that trimming a string cannot satisfy, and those must fall through to the refusal
|
|
430
|
-
// rather than spin here.
|
|
431
|
-
for (let pass = 0; pass < next.length * 4 + 8; pass += 1) {
|
|
432
|
-
const candidate = { ...record, toolInvocations: next };
|
|
433
|
-
if (isBoundedEventContentJson(candidate))
|
|
434
|
-
return { record: candidate, truncated };
|
|
435
|
-
let widest = -1;
|
|
436
|
-
let widestLength = 0;
|
|
437
|
-
for (const [index, entry] of next.entries()) {
|
|
438
|
-
const value = entry?.result;
|
|
439
|
-
if (typeof value === "string" && value.length > widestLength) {
|
|
440
|
-
widest = index;
|
|
441
|
-
widestLength = value.length;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
// Nothing left to shrink: the overflow is elsewhere, and the caller refuses rather than
|
|
445
|
-
// silently altering a field that is not tool output.
|
|
446
|
-
if (widest < 0 || widestLength === 0)
|
|
447
|
-
return { record, truncated };
|
|
448
|
-
const entry = next[widest];
|
|
449
|
-
const current = entry.result;
|
|
450
|
-
const original = originalLengths.get(widest) ?? current.length;
|
|
451
|
-
originalLengths.set(widest, original);
|
|
452
|
-
// Cut by what the record is actually over, plus room for the marker and for JSON escaping,
|
|
453
|
-
// which can widen a byte count well past the character count.
|
|
454
|
-
const serialized = Buffer.byteLength(JSON.stringify(candidate) ?? "", "utf8");
|
|
455
|
-
const overflow = Math.max(0, serialized - CONTRACT_MAX_JSON_BYTES);
|
|
456
|
-
const marker = toolOutputTruncationMarker(0, original).length;
|
|
457
|
-
const cut = Math.max(1, overflow + marker + 1024);
|
|
458
|
-
const kept = Math.max(0, current.length - cut);
|
|
459
|
-
entry.result = current.slice(0, kept) + toolOutputTruncationMarker(kept, original);
|
|
460
|
-
truncated += 1;
|
|
461
|
-
}
|
|
462
|
-
return { record, truncated };
|
|
419
|
+
export function sandboxTerminalProjection(record) {
|
|
420
|
+
const { toolInvocations: _toolInvocations, ...terminal } = record;
|
|
421
|
+
return terminal;
|
|
463
422
|
}
|
|
464
423
|
export function validatedSandboxPromptResult(result) {
|
|
465
424
|
if (!result || typeof result !== "object" || Array.isArray(result)) {
|
|
@@ -473,54 +432,16 @@ export function validatedSandboxPromptResult(result) {
|
|
|
473
432
|
// The Sandbox SDK materializes absent optional response fields as
|
|
474
433
|
// `undefined`. They were absent on the JSON wire and must stay absent in the
|
|
475
434
|
// provider-neutral result before the strict JSON check runs.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
//
|
|
479
|
-
// This validator runs inside the terminal result read — after the live stream has drained and
|
|
480
|
-
// after the usage receipt has been credited — so a throw here cannot prevent the work or the
|
|
481
|
-
// charge. It can only discard a finished, fully paid turn, which a supervisor then reports as a
|
|
482
|
-
// child that did nothing at all. That failure mode cost one Discovery Lab 143 of 199 children
|
|
483
|
-
// across 16 pursuits, and its six-stage sourcing graph blocked in 24 of 24 invocations.
|
|
484
|
-
//
|
|
485
|
-
// Widening the bound alone does not remove it. The Sandbox SDK serializes each tool value up to
|
|
486
|
-
// MAX_SERIALIZED_TOOL_VALUE_BYTES (4 MiB) while this bound is CONTRACT_MAX_JSON_BYTES (1 MiB)
|
|
487
|
-
// across the WHOLE record, so a single 2 MiB fetch still dies, and so do two 0.6 MiB fetches
|
|
488
|
-
// together. Any bound that throws on this path is one large page away from discarding a paid
|
|
489
|
-
// turn again.
|
|
490
|
-
//
|
|
491
|
-
// So the bound is enforced by replacing what does not fit, and saying so in the record. The
|
|
492
|
-
// caller still receives the turn, its response text, its usage, and every tool call it made;
|
|
493
|
-
// what it loses is the tail of an oversized tool result, marked where it was cut. Only tool
|
|
494
|
-
// output is truncatable: every other field is identity, accounting, or control material where a
|
|
495
|
-
// silently shortened value would be worse than a refusal, so those still refuse below.
|
|
496
|
-
const bounded = withTruncatedToolOutput(record);
|
|
497
|
-
const content = boundedEventContentRecordSchema.safeParse(bounded.record);
|
|
435
|
+
const record = sandboxTerminalProjection(Object.fromEntries(Object.entries(source).filter(([field, value]) => value !== undefined || !SANDBOX_OPTIONAL_RESULT_FIELDS.has(field))));
|
|
436
|
+
const content = boundedEventContentRecordSchema.safeParse(record);
|
|
498
437
|
if (!content.success) {
|
|
499
438
|
throw new Error("Tangle prompt result exceeded its JSON bound", { cause: content.error });
|
|
500
439
|
}
|
|
501
|
-
|
|
502
|
-
//
|
|
503
|
-
// that describe the turn keep their metadata limits.
|
|
504
|
-
//
|
|
505
|
-
// `toolInvocations` belongs with the response text, not with the metadata. It carries whatever a
|
|
506
|
-
// tool returned, and one `webfetch` of a paper or an API page is routinely tens or hundreds of
|
|
507
|
-
// kilobytes, while the metadata bound is CONTRACT_MAX_STRING_LENGTH — 16,384 characters per
|
|
508
|
-
// string. `isBoundedEventContentJson` was written for exactly this material ("content may contain
|
|
509
|
-
// a single large transcript or tool result") and the whole record has already passed it at
|
|
510
|
-
// CONTRACT_MAX_JSON_BYTES.
|
|
511
|
-
//
|
|
512
|
-
// Holding tool output to the metadata bound rejected a turn the Sandbox SDK had already accepted:
|
|
513
|
-
// it serializes each tool value up to MAX_SERIALIZED_TOOL_VALUE_BYTES (4 MiB), a 256x mismatch.
|
|
514
|
-
// Because this validator runs inside the terminal result read, AFTER the live stream has drained
|
|
515
|
-
// and the usage receipt has been credited, the rejection did not fail the tool call — it
|
|
516
|
-
// converted a finished, fully paid turn into an unreconcilable retained execution that a
|
|
517
|
-
// supervisor reports as a child that did no work at all. Measured 2026-09-11 in one Discovery Lab
|
|
518
|
-
// worktree: 143 of 199 children across 16 pursuits, every one at `iterations: 0`, and the
|
|
519
|
-
// enumerate and extract stages that fetch papers were the ones that died.
|
|
440
|
+
// Text is content. Identity, accounting and interaction state retain their
|
|
441
|
+
// stricter metadata bounds. The projection does not mutate the native source.
|
|
520
442
|
assertBoundedJson(Object.fromEntries(Object.entries(record).filter(([field]) => field !== "response" &&
|
|
521
443
|
field !== "text" &&
|
|
522
|
-
field !== "finalText"
|
|
523
|
-
field !== "toolInvocations")), "Tangle prompt result");
|
|
444
|
+
field !== "finalText")), "Tangle prompt result");
|
|
524
445
|
if (typeof record.success !== "boolean") {
|
|
525
446
|
throw new Error("Tangle prompt result omitted its success status");
|
|
526
447
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-provider-tangle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"dist/model-credential-capacity.d.ts"
|
|
121
121
|
],
|
|
122
122
|
"dependencies": {
|
|
123
|
-
"@tangle-network/agent-interface": "^2.
|
|
123
|
+
"@tangle-network/agent-interface": "^2.17.0"
|
|
124
124
|
},
|
|
125
125
|
"peerDependencies": {
|
|
126
126
|
"@tangle-network/sandbox": ">=0.58.7 <1.0.0"
|