@tangle-network/agent-provider-tangle 3.1.1 → 3.1.3

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 CHANGED
@@ -30,6 +30,16 @@ const provider = createTangleProvider({
30
30
  `Sandbox` requires an explicit `baseUrl`.
31
31
  Set `TANGLE_SANDBOX_URL` to use another deployment.
32
32
 
33
+ Exact execution replay preserves the admitted request and its digest.
34
+ An explicit replay override cannot replace the selected account, credential channel, or harness.
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
+
33
43
  ## Named model credentials at creation
34
44
 
35
45
  `modelCredentials` sends a stored credential reference and explicit endpoint before Sandbox provisions the backend.
@@ -123,7 +133,12 @@ Sandbox metadata records the public selection under `modelCredentials`.
123
133
  This metadata key is reserved for the Provider selection.
124
134
  Account labels are supplied bindings, not verified native principals.
125
135
  Token values and native credential files never enter that selection or receipt.
126
- The same public native reference can travel in a per-turn `backend.model.cliAuth` with an explicit matching backend type.
136
+ The Provider carries the selected native reference in every new stream, detached dispatch, and session prompt.
137
+ Model-only or profile-only turns retain that exact account and harness.
138
+ The bound reference participates in the admitted request digest before dispatch.
139
+ Reconstructed environments recover it from persisted metadata and the observed backend.
140
+ Replacing the account, harness, or credential channel requires a separate environment.
141
+ Exact replay preserves the already admitted request without adding new credential fields.
127
142
  A turn carrying a profile must preserve its environment's credential source, including after recovery.
128
143
  Changing credential sources requires a separate environment because retained Sandbox defaults cannot safely clear a native binding.
129
144
 
@@ -23,5 +23,5 @@ type ExactExecutionEventStream = (options: {
23
23
  * environment observation reads it, because Sandbox reports usage per
24
24
  * execution result and never for the environment.
25
25
  */
26
- export declare function sandboxSessionAsAgentSession(session: SandboxSessionLike, controlRef: AgentRunControlRef | undefined, provider: string, environmentId: string, dispatch: ((input: AgentTurnInput) => Promise<AgentSessionRef>) | undefined, exactExecutionEvents: ExactExecutionEventStream | undefined, retainedControl: boolean, interactionResponses: boolean, usageLog?: ExecutionUsageLog, nativeContinuation?: boolean, beforePrompt?: (input: AgentTurnInput) => void, onExecution?: (executionId: string) => void): AgentSession;
26
+ export declare function sandboxSessionAsAgentSession(session: SandboxSessionLike, controlRef: AgentRunControlRef | undefined, provider: string, environmentId: string, dispatch: ((input: AgentTurnInput) => Promise<AgentSessionRef>) | undefined, exactExecutionEvents: ExactExecutionEventStream | undefined, retainedControl: boolean, interactionResponses: boolean, usageLog?: ExecutionUsageLog, nativeContinuation?: boolean, beforePrompt?: (input: AgentTurnInput) => AgentTurnInput | void, onExecution?: (executionId: string) => void): AgentSession;
27
27
  export {};
@@ -317,7 +317,7 @@ export function sandboxSessionAsAgentSession(session, controlRef, provider, envi
317
317
  }));
318
318
  },
319
319
  async prompt(input) {
320
- beforePrompt?.(input);
320
+ input = beforePrompt?.(input) ?? input;
321
321
  AgentTurnInputSchema.parse(input);
322
322
  input.signal?.throwIfAborted();
323
323
  if (promptInFlight) {
@@ -1,3 +1,4 @@
1
+ import { type CliAuthReference } from "@tangle-network/sandbox/auth";
1
2
  import type { AgentEnvironment, AgentEnvironmentCapabilities, ResourceProfile } from "@tangle-network/agent-interface/environment-provider";
2
3
  import type { SandboxClientLike, SandboxInstanceLike, SandboxRuntimeCapabilityDocument } from "./tangle-types.js";
3
4
  import { type ProfileCredentialSource } from "./model-credential-source.js";
@@ -33,6 +34,11 @@ export declare function sandboxInstanceAsEnvironment(box: SandboxInstanceLike, p
33
34
  requireNativeSessionCapture?: boolean;
34
35
  requireCliAuthReferences?: boolean;
35
36
  credentialSource?: ProfileCredentialSource;
37
+ credentialHarness?: string;
38
+ nativeAuth?: {
39
+ harness: string;
40
+ cliAuth: CliAuthReference;
41
+ };
36
42
  captureCapabilities?: SandboxRuntimeCapabilityDocument;
37
43
  captureHarness?: string;
38
44
  }): Promise<AgentEnvironment>;
@@ -1,3 +1,6 @@
1
+ import { assertCliAuthReferenceSupported } from "@tangle-network/sandbox/auth";
2
+ import { canonicalCandidateDigest } from "@tangle-network/agent-interface";
3
+ import { captureModelCredentials } from "./tangle-create-options.js";
1
4
  import { AgentTurnInputSchema, deepFreeze } from "@tangle-network/agent-interface";
2
5
  import { AgentEnvironmentCapabilitiesSchema } from "@tangle-network/agent-interface/environment-provider";
3
6
  import { environmentEventFromSandboxEvent } from "./tangle-events.js";
@@ -7,7 +10,7 @@ import { execResultFromSandboxExecResult } from "./tangle-result-values.js";
7
10
  import { capabilitiesForSandbox, frozenCapabilityDocument, sandboxCapabilitySupport, } from "./tangle-capabilities.js";
8
11
  import { profileCredentialSource } from "./model-credential-source.js";
9
12
  import { deploymentCapabilitySupport, readDeploymentCapabilitySupport } from "./tangle-deployment-capabilities.js";
10
- 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";
11
14
  import { assertExecOptions, assertOptionKeys, } from "./tangle-environment-validation.js";
12
15
  import { interruptExecutionAfterAbort, } from "./tangle-environment-control.js";
13
16
  import { dispatchEnvironmentRun } from "./tangle-environment-dispatch.js";
@@ -63,6 +66,17 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
63
66
  if ((request?.requireCliAuthReferences || recordedNativeReference) && !deployment.cliAuthReferences) {
64
67
  throw new Error("Tangle selected sandbox does not prove native credential reference support");
65
68
  }
69
+ const persistedNative = recordedNativeReference
70
+ ? captureModelCredentials(recordedCredentials)
71
+ : undefined;
72
+ const persistedReference = persistedNative !== undefined && "cliAuth" in persistedNative
73
+ ? persistedNative.cliAuth : undefined;
74
+ if (request?.nativeAuth !== undefined && persistedReference !== undefined &&
75
+ canonicalCandidateDigest(request.nativeAuth.cliAuth) !== canonicalCandidateDigest(persistedReference)) {
76
+ throw new Error("Tangle persisted native credential differs from its selected creation reference");
77
+ }
78
+ const nativeReference = request?.nativeAuth?.cliAuth ?? persistedReference;
79
+ const credentialHarness = request?.nativeAuth?.harness ?? request?.credentialHarness;
66
80
  const boundCredentialSource = request?.credentialSource ??
67
81
  (recordedCredentials !== undefined ? "subscription" : "managed");
68
82
  const capabilities = frozenCapabilityDocument(AgentEnvironmentCapabilitiesSchema.parse(capabilitiesForSandbox(declaredCapabilities, support, deployment, confidentialVerifierOption(request?.confidentialAttestationVerifier))));
@@ -107,6 +121,38 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
107
121
  }
108
122
  assertNativeCaptureHarness(request.captureCapabilities, backend?.type ?? profileHarness ?? request.captureHarness);
109
123
  };
124
+ const prepareTurn = (input) => {
125
+ assertCaptureInput(input);
126
+ if (nativeReference === undefined)
127
+ return input;
128
+ const replay = input.lastEventId !== undefined || input.controlRef !== undefined;
129
+ const backend = promptOptionsFromTurnInput(input, { provider: providerName, environmentId }).backend;
130
+ // A plain exact read supplies no backend override and keeps its admitted request unchanged.
131
+ if (replay && backend === undefined)
132
+ return input;
133
+ const harness = backend?.type ?? backend?.profile?.harness ?? credentialHarness;
134
+ if (credentialHarness === undefined || harness !== credentialHarness ||
135
+ (backend?.profile?.harness !== undefined && backend.profile.harness !== harness)) {
136
+ throw new Error("Tangle native credential turn must preserve its selected environment harness");
137
+ }
138
+ const model = backend?.model ?? {};
139
+ if (model.cliAuth !== undefined &&
140
+ canonicalCandidateDigest(model.cliAuth) !== canonicalCandidateDigest(nativeReference)) {
141
+ throw new Error("Tangle native credential turn cannot replace its selected account reference");
142
+ }
143
+ const selectedModel = { ...model, cliAuth: nativeReference };
144
+ assertCliAuthReferenceSupported(harness, selectedModel);
145
+ // Validate explicit substitutions even on replay, without rewriting its admitted digest.
146
+ if (replay)
147
+ return input;
148
+ return {
149
+ ...input,
150
+ providerOptions: {
151
+ ...input.providerOptions,
152
+ backend: { ...backend, type: harness, model: { ...selectedModel, authMode: "oauth" } },
153
+ },
154
+ };
155
+ };
110
156
  // The single destroy this handle performs, once it has been asked for.
111
157
  let destruction;
112
158
  const terminals = capabilities.interactiveTerminal?.attach === true
@@ -120,8 +166,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
120
166
  ? dispatchEnvironmentRun(box, providerName, environmentId)
121
167
  : undefined;
122
168
  const dispatch = dispatchRun === undefined ? undefined : (input) => {
123
- assertCaptureInput(input);
124
- return dispatchRun(input);
169
+ return dispatchRun(prepareTurn(input));
125
170
  };
126
171
  const exactExecutionEvents = (options) => box.streamPrompt("", {
127
172
  sessionId: options.sessionId,
@@ -151,7 +196,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
151
196
  async *stream(input) {
152
197
  AgentTurnInputSchema.parse(input);
153
198
  input.signal?.throwIfAborted();
154
- assertCaptureInput(input);
199
+ input = prepareTurn(input);
155
200
  const expectedExecutionId = executionIdFromTurnInput(input);
156
201
  const expectedSessionId = input.sessionId ?? input.controlRef?.sessionId;
157
202
  if (expectedSessionId)
@@ -224,7 +269,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
224
269
  if (session.id !== id) {
225
270
  throw new Error("sandbox session(id) returned an unrelated session");
226
271
  }
227
- const agentSession = sandboxSessionAsAgentSession(session, options?.controlRef, providerName, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, capabilities.nativeContinuation !== undefined, assertCaptureInput, (executionId) => noteTangleSession(environment, id, executionId));
272
+ const agentSession = sandboxSessionAsAgentSession(session, options?.controlRef, providerName, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, capabilities.nativeContinuation !== undefined, prepareTurn, (executionId) => noteTangleSession(environment, id, executionId));
228
273
  // sessions.continue was granted from the probe session and the
229
274
  // deployment document together; this backstop holds every
230
275
  // concrete session to that grant, so a client whose sessions
@@ -272,7 +317,11 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
272
317
  options?.signal?.throwIfAborted();
273
318
  const content = await awaitWithSignal(box.read?.(path, options), options?.signal);
274
319
  options?.signal?.throwIfAborted();
275
- return boundedString(content, "Tangle file content");
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;
276
325
  },
277
326
  }
278
327
  : {}),
@@ -208,6 +208,9 @@ export function createTangleProvider(options) {
208
208
  ? {}
209
209
  : { resources: requestedResources }),
210
210
  credentialSource,
211
+ ...(createOptions.backend?.model?.cliAuth === undefined ? {} : {
212
+ nativeAuth: { harness: createOptions.backend.type, cliAuth: createOptions.backend.model.cliAuth },
213
+ }),
211
214
  ...(createOptions.backend?.model?.cliAuth === undefined ? {} : { requireCliAuthReferences: true }),
212
215
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
213
216
  ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
@@ -318,7 +321,7 @@ export function createTangleProvider(options) {
318
321
  ...confidentialVerifierOption(options.confidentialAttestationVerifier),
319
322
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
320
323
  ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
321
- ...(backendType === undefined ? {} : { captureHarness: backendType }),
324
+ ...(backendType === undefined ? {} : { captureHarness: backendType, credentialHarness: backendType }),
322
325
  });
323
326
  },
324
327
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",