@tangle-network/agent-provider-tangle 5.0.16 → 5.0.18
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/dist/model-credential-source.d.ts +1 -1
- package/dist/tangle-prompt.d.ts +8 -4
- package/dist/tangle-provider.js +2 -2
- package/dist/tangle-runtime-attachments.d.ts +1 -1
- package/dist/tangle-workspace-branching.js +10 -10
- package/dist/tangle-workspace-recovery.d.ts +24 -5
- package/dist/tangle-workspace-recovery.js +32 -23
- package/package.json +2 -2
|
@@ -2,4 +2,4 @@ import type { AgentProfile } from "@tangle-network/agent-interface";
|
|
|
2
2
|
/** The credential intent a profile can declare. `managed` is the deprecated spelling of `router`. */
|
|
3
3
|
export type ProfileCredentialSource = "router" | "api-key" | "subscription";
|
|
4
4
|
/** Authored profile intent is independent of the harness, vendor, and available accounts. */
|
|
5
|
-
export declare function profileCredentialSource(profile: AgentProfile): ProfileCredentialSource;
|
|
5
|
+
export declare function profileCredentialSource(profile: AgentProfile | Pick<AgentProfile, "model">): ProfileCredentialSource;
|
package/dist/tangle-prompt.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BackendConfig, PromptOptions, PromptResult } from "@tangle-network/sandbox";
|
|
2
2
|
import type { AgentTurnInput, AgentTurnResult } from "@tangle-network/agent-interface/environment-provider";
|
|
3
|
-
import type { AgentExactRunControlRef, InputPart } from "@tangle-network/agent-interface";
|
|
3
|
+
import type { AgentProfile, AgentExactRunControlRef, InputPart } from "@tangle-network/agent-interface";
|
|
4
4
|
import { type ProxySecretReceipt, type ProxySecretBinding } from "@tangle-network/agent-interface";
|
|
5
5
|
import type { SandboxInstanceLike } from "./tangle-types.js";
|
|
6
6
|
export declare function promptFromTurnInput(input: AgentTurnInput): string | InputPart[];
|
|
@@ -9,7 +9,9 @@ export declare function promptOptionsFromTurnInput(input: AgentTurnInput, target
|
|
|
9
9
|
provider: string;
|
|
10
10
|
environmentId: string;
|
|
11
11
|
sessionId?: string;
|
|
12
|
-
}): PromptOptions
|
|
12
|
+
}): Omit<PromptOptions, "backend"> & {
|
|
13
|
+
backend?: SandboxPromptBackend;
|
|
14
|
+
};
|
|
13
15
|
export declare function proxySecretReceiptFromSandbox(box: SandboxInstanceLike): ProxySecretReceipt | undefined;
|
|
14
16
|
/** Prepare one exact launch; legacy and cursor replay retain their existing path. */
|
|
15
17
|
export declare function preparePromptOptions(box: SandboxInstanceLike, options: PromptOptions, provider: string, bindings?: readonly ProxySecretBinding[]): Promise<PromptOptions>;
|
|
@@ -21,12 +23,14 @@ declare const SANDBOX_AUTH_FILE_FIELD_LIST: readonly ["path", "content", "mode"]
|
|
|
21
23
|
type SandboxAuthFile = NonNullable<SandboxBackendModel["authFiles"]>[number];
|
|
22
24
|
type FieldDifference<T, Fields extends readonly PropertyKey[]> = Exclude<keyof T, Fields[number]> | Exclude<Fields[number], keyof T>;
|
|
23
25
|
export type SandboxBackendFieldCoverage = Exhaustive<FieldDifference<Omit<BackendConfig, Exclude<(typeof SANDBOX_BACKEND_MODEL_FIELD_LIST)[number], "model"> | "modelId">, typeof SANDBOX_BACKEND_FIELD_LIST> | FieldDifference<SandboxBackendModel, typeof SANDBOX_BACKEND_MODEL_FIELD_LIST> | FieldDifference<SandboxAuthFile, typeof SANDBOX_AUTH_FILE_FIELD_LIST>>;
|
|
24
|
-
type SandboxPromptBackend = NonNullable<PromptOptions["backend"]
|
|
26
|
+
type SandboxPromptBackend = Omit<NonNullable<PromptOptions["backend"]>, "profile"> & {
|
|
27
|
+
profile?: AgentProfile;
|
|
28
|
+
};
|
|
25
29
|
/** Validate the exact per-turn backend projection. */
|
|
26
30
|
export declare function backendFromTurnProviderOptions(providerOptions: Record<string, unknown> | undefined): SandboxPromptBackend | undefined;
|
|
27
31
|
export declare function normalizeTangleBackend(value: unknown, allowRouting?: boolean): BackendConfig | undefined;
|
|
28
32
|
/** Request identity excludes bearer bytes; auth files contribute only paths and modes. */
|
|
29
|
-
export declare function backendRequestIdentity(backend:
|
|
33
|
+
export declare function backendRequestIdentity(backend: PromptOptions["backend"]): Record<string, unknown> | undefined;
|
|
30
34
|
export declare function backendFromTurnInput(input: AgentTurnInput): SandboxPromptBackend | undefined;
|
|
31
35
|
type SandboxRunStatus = "success" | "failed" | "blocked_on_approval" | "awaiting_question" | "awaiting_interaction" | "awaiting_plan_decision";
|
|
32
36
|
type ValidatedSandboxPromptResult = Record<string, unknown> & {
|
package/dist/tangle-provider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentEnvironmentCapabilitiesSchema, AgentEnvironmentGetOptionsSchema, createAgentEnvironmentWithIdempotency, } from "@tangle-network/agent-interface/environment-provider";
|
|
2
|
-
import { canonicalCandidateDigest, deepFreeze, harnessTypeSchema } from "@tangle-network/agent-interface";
|
|
2
|
+
import { agentProfileSchema, canonicalCandidateDigest, deepFreeze, harnessTypeSchema } from "@tangle-network/agent-interface";
|
|
3
3
|
import { createTangleExactProcessProvider } from "./exact-process.js";
|
|
4
4
|
import { capabilitiesForClient, defaultTangleSandboxCapabilities, narrowTangleCapabilitiesToBackend, } from "./tangle-capabilities.js";
|
|
5
5
|
import { sandboxInstanceAsEnvironment } from "./tangle-environment.js";
|
|
@@ -140,7 +140,7 @@ export function createTangleProvider(options) {
|
|
|
140
140
|
const mappedInput = mapCreateInput?.(input) ??
|
|
141
141
|
(subscription && resolveModelCredentials !== undefined ? sandboxOptionsFromCreateInput(input, options.defaultBackend, parsedWorkspace, selectedCredentials, true) : defaultOptions);
|
|
142
142
|
const selectedProxySecrets = mergeProxySecrets(requestedProxySecrets, selectedCredentials?.proxySecrets);
|
|
143
|
-
const mappedProxySecrets = mergeProxySecrets(selectedProxySecrets, proxySecretsFromInput({ profile: mappedInput.backend?.profile ?? {}, proxySecrets: mappedInput.proxySecrets }));
|
|
143
|
+
const mappedProxySecrets = mergeProxySecrets(selectedProxySecrets, proxySecretsFromInput({ profile: agentProfileSchema.parse(mappedInput.backend?.profile ?? {}), proxySecrets: mappedInput.proxySecrets }));
|
|
144
144
|
if (canonicalCandidateDigest(mappedProxySecrets ?? []) !== canonicalCandidateDigest(selectedProxySecrets ?? []))
|
|
145
145
|
throw new Error("Tangle mapped proxy-secret declarations differ from the requested bindings");
|
|
146
146
|
const mappedOptions = { ...mappedInput, backend: normalizeTangleBackend(mappedInput.backend, true), ...(selectedProxySecrets === undefined ? {} : { proxySecrets: selectedProxySecrets }) };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type AgentProfile, type AgentRuntimeAttachments } from "@tangle-network/agent-interface";
|
|
2
2
|
/** Runtime bindings retain their own identity and cannot replace profile tools. */
|
|
3
|
-
export declare function tangleRuntimeAttachments(value: unknown, profile?: AgentProfile): AgentRuntimeAttachments;
|
|
3
|
+
export declare function tangleRuntimeAttachments(value: unknown, profile?: Pick<AgentProfile, "mcp">): AgentRuntimeAttachments;
|
|
@@ -246,10 +246,10 @@ export function createTangleWorkspaceBranching(options) {
|
|
|
246
246
|
// rebuilds and re-sorts on every page; on a busy account a page failed or
|
|
247
247
|
// repeated, deletion was never attempted, and the source was kept running.
|
|
248
248
|
const known = await findManagedCheckpoint(box, provider, request.targetId, undefined, operation?.signal);
|
|
249
|
-
if (known === "unknown") {
|
|
250
|
-
return cleanupUnknown(request,
|
|
249
|
+
if (known.state === "unknown") {
|
|
250
|
+
return cleanupUnknown(request, `Sandbox checkpoint lookup answered unknown (${known.reason}); deletion was not attempted`, true);
|
|
251
251
|
}
|
|
252
|
-
if (known ===
|
|
252
|
+
if (known.state === "absent") {
|
|
253
253
|
const acknowledgement = cleanupAlreadyAbsent(request);
|
|
254
254
|
cleanup.set(request.operationId, {
|
|
255
255
|
requestDigest: request.requestDigest,
|
|
@@ -259,19 +259,19 @@ export function createTangleWorkspaceBranching(options) {
|
|
|
259
259
|
}
|
|
260
260
|
let result;
|
|
261
261
|
try {
|
|
262
|
-
result = await awaitWithSignal(box.deleteSnapshot?.(
|
|
262
|
+
result = await awaitWithSignal(box.deleteSnapshot?.(known.snapshotId), operation?.signal);
|
|
263
263
|
}
|
|
264
264
|
catch (error) {
|
|
265
265
|
operation?.signal?.throwIfAborted();
|
|
266
266
|
return cleanupTransportFailure(request, `Sandbox checkpoint deletion failed: ${safeError(error)}`, true);
|
|
267
267
|
}
|
|
268
268
|
const outcome = result &&
|
|
269
|
-
result.snapshotId ===
|
|
269
|
+
result.snapshotId === known.snapshotId &&
|
|
270
270
|
(result.outcome === "deleted" || result.outcome === "already_absent")
|
|
271
271
|
? result.outcome
|
|
272
272
|
: "unknown";
|
|
273
273
|
if (outcome !== "deleted" && outcome !== "already_absent") {
|
|
274
|
-
return cleanupUnknown(request, "Sandbox
|
|
274
|
+
return cleanupUnknown(request, "Sandbox delete answered unknown (deletion not attested)", true);
|
|
275
275
|
}
|
|
276
276
|
const acknowledgement = outcome === "deleted"
|
|
277
277
|
? cleanupDeleted(request)
|
|
@@ -315,12 +315,12 @@ export function createTangleWorkspaceBranching(options) {
|
|
|
315
315
|
}
|
|
316
316
|
const checkpoint = [...checkpoints.values()].some((record) => canonicalCandidateDigest(record.checkpoint) ===
|
|
317
317
|
canonicalCandidateDigest(request.checkpoint))
|
|
318
|
-
?
|
|
318
|
+
? undefined
|
|
319
319
|
: await findManagedCheckpoint(box, provider, request.checkpoint.checkpointId, request.checkpoint, operation?.signal);
|
|
320
|
-
if (checkpoint !==
|
|
321
|
-
return forkUnknown(request, checkpoint ===
|
|
320
|
+
if (checkpoint !== undefined && checkpoint.state !== "found") {
|
|
321
|
+
return forkUnknown(request, checkpoint.state === "absent"
|
|
322
322
|
? "Requested checkpoint is absent"
|
|
323
|
-
:
|
|
323
|
+
: `Sandbox checkpoint lookup answered unknown (${checkpoint.reason})`, true);
|
|
324
324
|
}
|
|
325
325
|
const metadata = forkMarkerMetadata(request);
|
|
326
326
|
let returnedChild;
|
|
@@ -30,13 +30,32 @@ export declare function validSnapshotResult(result: SandboxSnapshotResultLike |
|
|
|
30
30
|
/** Normalize one remote checkpoint recovery attempt for every caller. */
|
|
31
31
|
export declare function reconcileCheckpoint(box: SandboxInstanceLike, provider: string, request: Pick<WorkspaceCheckpointRequest, "idempotencyKey" | "requestDigest">, signal?: AbortSignal): Promise<CheckpointReconciliation>;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* One checkpoint id resolved against its source's inventory. `snapshotId` is
|
|
34
|
+
* the physical id Sandbox lists, which is the id a delete must name: a sealed
|
|
35
|
+
* checkpoint is listed under its physical id with the acknowledged id in its
|
|
36
|
+
* one `seal.<id>` tag. `unknown` names the step that could not decide.
|
|
37
|
+
*/
|
|
38
|
+
export type ManagedCheckpoint = {
|
|
39
|
+
state: "found";
|
|
40
|
+
snapshotId: string;
|
|
41
|
+
} | {
|
|
42
|
+
state: "absent";
|
|
43
|
+
} | {
|
|
44
|
+
state: "unknown";
|
|
45
|
+
reason: "inventory unavailable" | "ambiguous seal alias" | "invalid snapshot metadata" | "not marked by this source" | "operation not confirmed";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Confirm that one checkpoint id is a settled checkpoint this provider created.
|
|
34
49
|
*
|
|
35
|
-
* `expected`
|
|
36
|
-
*
|
|
37
|
-
*
|
|
50
|
+
* Without `expected` (cleanup), a match by id or by its one seal alias is
|
|
51
|
+
* accepted only when the snapshot carries this source's own marker and the
|
|
52
|
+
* marker's operation succeeded; a seal alias also needs that operation's
|
|
53
|
+
* result to name this id with the same marker. Anything less is unknown,
|
|
54
|
+
* never absent. `expected` binds the answer to a specific checkpoint
|
|
55
|
+
* reference (fork): a reference that does not match its marker is absent, not
|
|
56
|
+
* unknown, because the caller supplied a checkpoint this source never produced.
|
|
38
57
|
*/
|
|
39
|
-
export declare function findManagedCheckpoint(box: SandboxInstanceLike, provider: string, id: string, expected?: WorkspaceCheckpointRef, signal?: AbortSignal): Promise<
|
|
58
|
+
export declare function findManagedCheckpoint(box: SandboxInstanceLike, provider: string, id: string, expected?: WorkspaceCheckpointRef, signal?: AbortSignal): Promise<ManagedCheckpoint>;
|
|
40
59
|
export declare function findForkByKey(client: SandboxClientLike, box: SandboxInstanceLike, provider: string, key: string, signal?: AbortSignal): Promise<(RecoveredForkChild & {
|
|
41
60
|
marker: ForkMarker;
|
|
42
61
|
}) | null | undefined>;
|
|
@@ -242,50 +242,59 @@ function snapshotFromOperationResult(snapshot, lookup, marker) {
|
|
|
242
242
|
return { ...snapshot, snapshotId: lookup.result.snapshotId, createdAt: lookup.result.createdAt };
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
|
-
* Confirm that one
|
|
245
|
+
* Confirm that one checkpoint id is a settled checkpoint this provider created.
|
|
246
246
|
*
|
|
247
|
-
* `expected`
|
|
248
|
-
*
|
|
249
|
-
*
|
|
247
|
+
* Without `expected` (cleanup), a match by id or by its one seal alias is
|
|
248
|
+
* accepted only when the snapshot carries this source's own marker and the
|
|
249
|
+
* marker's operation succeeded; a seal alias also needs that operation's
|
|
250
|
+
* result to name this id with the same marker. Anything less is unknown,
|
|
251
|
+
* never absent. `expected` binds the answer to a specific checkpoint
|
|
252
|
+
* reference (fork): a reference that does not match its marker is absent, not
|
|
253
|
+
* unknown, because the caller supplied a checkpoint this source never produced.
|
|
250
254
|
*/
|
|
251
255
|
export async function findManagedCheckpoint(box, provider, id, expected, signal) {
|
|
256
|
+
const unknown = (reason) => ({ state: "unknown", reason });
|
|
257
|
+
const absent = { state: "absent" };
|
|
252
258
|
try {
|
|
253
259
|
const snapshots = await awaitWithSignal(box.listSnapshots?.(), signal);
|
|
254
260
|
if (!Array.isArray(snapshots) || snapshots.length > MAX_LIST_RESULTS) {
|
|
255
|
-
return
|
|
261
|
+
return unknown("inventory unavailable");
|
|
256
262
|
}
|
|
257
263
|
const candidates = snapshots.filter((candidate) => snapshotHasId(candidate, id) !== false);
|
|
258
264
|
if (candidates.length === 0)
|
|
259
|
-
return
|
|
260
|
-
if (candidates.length !== 1)
|
|
261
|
-
return
|
|
265
|
+
return absent;
|
|
266
|
+
if (candidates.length !== 1 || snapshotHasId(candidates[0], id) !== true)
|
|
267
|
+
return unknown("ambiguous seal alias");
|
|
262
268
|
const snapshot = candidates[0];
|
|
263
|
-
if (!validSnapshotInfo(snapshot, box.id)
|
|
264
|
-
return
|
|
265
|
-
// An expected reference can prove a fork source; an alias alone never authorizes cleanup.
|
|
266
|
-
if (snapshot.snapshotId !== id && expected === undefined)
|
|
267
|
-
return "unknown";
|
|
269
|
+
if (!validSnapshotInfo(snapshot, box.id))
|
|
270
|
+
return unknown("invalid snapshot metadata");
|
|
268
271
|
const marker = checkpointMarkerFromTags(snapshot.tags, expected?.idempotencyKey);
|
|
269
|
-
if (!marker)
|
|
270
|
-
return expected ?
|
|
271
|
-
if (marker.request.source.provider !== provider ||
|
|
272
|
-
marker.request.source.environmentId !== box.id) {
|
|
273
|
-
return expected ? false : "unknown";
|
|
272
|
+
if (!marker || !checkpointMarkerBelongsToSource(marker, provider, box.id)) {
|
|
273
|
+
return expected ? absent : unknown("not marked by this source");
|
|
274
274
|
}
|
|
275
275
|
if (expected &&
|
|
276
276
|
(marker.requestDigest !== expected.requestDigest ||
|
|
277
277
|
canonicalCandidateDigest(marker.request.source) !==
|
|
278
278
|
canonicalCandidateDigest(expected.source))) {
|
|
279
|
-
return
|
|
279
|
+
return absent;
|
|
280
|
+
}
|
|
281
|
+
let lookup;
|
|
282
|
+
try {
|
|
283
|
+
lookup = await checkpointOperationLookup(box, marker, signal);
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
signal?.throwIfAborted();
|
|
287
|
+
return unknown("operation not confirmed");
|
|
280
288
|
}
|
|
281
|
-
const lookup = await checkpointOperationLookup(box, marker, signal);
|
|
282
289
|
if (lookup?.outcome !== "found" || lookup.kind !== "checkpoint" || lookup.state !== "succeeded")
|
|
283
|
-
return
|
|
284
|
-
return snapshot.snapshotId === id || snapshotFromOperationResult(snapshot, lookup, marker)?.snapshotId === id
|
|
290
|
+
return unknown("operation not confirmed");
|
|
291
|
+
return snapshot.snapshotId === id || snapshotFromOperationResult(snapshot, lookup, marker)?.snapshotId === id
|
|
292
|
+
? { state: "found", snapshotId: snapshot.snapshotId }
|
|
293
|
+
: unknown("operation not confirmed");
|
|
285
294
|
}
|
|
286
295
|
catch {
|
|
287
296
|
signal?.throwIfAborted();
|
|
288
|
-
return
|
|
297
|
+
return unknown("inventory unavailable");
|
|
289
298
|
}
|
|
290
299
|
}
|
|
291
300
|
export async function findForkByKey(client, box, provider, key, signal) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-provider-tangle",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.18",
|
|
4
4
|
"description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"LICENSE"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tangle-network/agent-interface": "^5.10.
|
|
36
|
+
"@tangle-network/agent-interface": "^5.10.28"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@tangle-network/sandbox": ">=1.0.393 <2.0.0"
|