@tangle-network/agent-interface 1.0.0 → 1.0.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 +7 -0
- package/dist/environment-runtime.d.ts +40 -0
- package/dist/environment-runtime.js +55 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/provider-config.d.ts +10 -1
- package/dist/provider-config.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,13 @@ Every returned resource repeats and validates that identity, lookups recover rem
|
|
|
52
52
|
A checkpoint with dependent forks returns `in_use` plus the blocking environment identifiers and remains recoverable until those forks are destroyed.
|
|
53
53
|
The older `checkpoint()` and `fork()` methods remain source-compatible for providers that have not yet implemented recovery semantics, but clients must not present them as durable workspace branching.
|
|
54
54
|
|
|
55
|
+
`CreateAgentEnvironmentInput.idempotencyKey` makes generic environment creation one retry-safe operation.
|
|
56
|
+
When a caller repeats that key, the provider must canonicalize every create field except the key and attempt signal.
|
|
57
|
+
The same canonical input must return or reconstruct the same environment, including after an ambiguous provider response.
|
|
58
|
+
The same key with any changed create field must reject before a second create effect.
|
|
59
|
+
Providers backed by a remote service must forward the key and retain its canonical input through environment reconstruction.
|
|
60
|
+
The existing `AgentEnvironmentProvider.create()` method carries this contract; it does not add a second create method or capability flag.
|
|
61
|
+
|
|
55
62
|
All new wire values have exported Zod schemas on the package root.
|
|
56
63
|
Omitting `interactions` and `nativeContinuation`, or leaving the three durable branching flags false, is the compatible declaration for existing providers.
|
|
57
64
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
2
3
|
import type { AgentProfileCapabilities, AgentProfileValidationResult } from "./agent-profile.js";
|
|
3
4
|
import type { InputPart } from "./parts.js";
|
|
4
5
|
import type { StreamEvent } from "./stream-events.js";
|
|
@@ -917,15 +918,54 @@ export interface CreateAgentEnvironmentInput {
|
|
|
917
918
|
secrets?: string[] | Record<string, string>;
|
|
918
919
|
metadata?: Record<string, unknown>;
|
|
919
920
|
name?: string;
|
|
921
|
+
/**
|
|
922
|
+
* Stable identity for one logical environment create.
|
|
923
|
+
*
|
|
924
|
+
* When present, the provider must use this key as one idempotent operation:
|
|
925
|
+
* the same key with canonically equal create input must return or reconstruct
|
|
926
|
+
* the same environment, while a different input must be rejected.
|
|
927
|
+
* `signal` controls one attempt and is not part of create identity.
|
|
928
|
+
*/
|
|
920
929
|
idempotencyKey?: string;
|
|
921
930
|
signal?: AbortSignal;
|
|
922
931
|
providerOptions?: Record<string, unknown>;
|
|
923
932
|
}
|
|
933
|
+
/**
|
|
934
|
+
* Compute the canonical identity of a generic environment create request.
|
|
935
|
+
*
|
|
936
|
+
* The operation key names the request and the abort signal controls one
|
|
937
|
+
* attempt, so neither belongs in the input identity. Every other field is
|
|
938
|
+
* canonicalized with the shared RFC 8785 JSON representation.
|
|
939
|
+
* @internal
|
|
940
|
+
*/
|
|
941
|
+
export declare function agentEnvironmentCreateInputDigest(input: CreateAgentEnvironmentInput): Sha256Digest;
|
|
942
|
+
/** @internal State held by one provider adapter for keyed create retries. */
|
|
943
|
+
export interface AgentEnvironmentCreateIdempotencyRecord<T> {
|
|
944
|
+
readonly digest: Sha256Digest;
|
|
945
|
+
readonly pending: Promise<T>;
|
|
946
|
+
environment?: T;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Apply the generic create contract to one provider adapter's keyed requests.
|
|
950
|
+
*
|
|
951
|
+
* The provider's backing service remains responsible for retaining the key
|
|
952
|
+
* across adapter reconstruction. This helper coalesces concurrent retries and
|
|
953
|
+
* rejects collisions before the provider performs another create effect.
|
|
954
|
+
* @internal
|
|
955
|
+
*/
|
|
956
|
+
export declare function createAgentEnvironmentWithIdempotency<T>(records: Map<string, AgentEnvironmentCreateIdempotencyRecord<T>>, input: CreateAgentEnvironmentInput, create: () => Promise<T>): Promise<T>;
|
|
924
957
|
export interface AgentEnvironmentProvider {
|
|
925
958
|
readonly name: string;
|
|
926
959
|
readonly exactProcess?: AgentExactProcessProvider;
|
|
927
960
|
capabilities(): AgentEnvironmentCapabilities | Promise<AgentEnvironmentCapabilities>;
|
|
928
961
|
validateProfile?(profile: AgentProfileRef): AgentProfileValidationResult | Promise<AgentProfileValidationResult>;
|
|
962
|
+
/**
|
|
963
|
+
* Create or reconstruct one environment.
|
|
964
|
+
*
|
|
965
|
+
* With `input.idempotencyKey`, the provider must return the same environment
|
|
966
|
+
* for the same canonical input and reject any changed input before creating.
|
|
967
|
+
* Without a key, each call may create a fresh environment.
|
|
968
|
+
*/
|
|
929
969
|
create(input: CreateAgentEnvironmentInput): Promise<AgentEnvironment>;
|
|
930
970
|
get?(id: string, options?: {
|
|
931
971
|
signal?: AbortSignal;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { canonicalCandidateDigest } from "./agent-candidate-schema-common.js";
|
|
2
3
|
import { InteractionCapabilitiesSchema, RequestedInteractionsSchema } from "./interaction.js";
|
|
3
4
|
import { ContextTransferReceiptSchema, ContextTransferRequestSchema, NativeContextContinuationAcknowledgementSchema, NativeContextContinuationRequestSchema, nativeContextContinuationAcknowledgementMatches } from "./portable-context.js";
|
|
4
5
|
import { AgentExactRunControlRefSchema, AgentRunControlRefSchema, CanonicalStreamEventSchema } from "./runtime-control.js";
|
|
@@ -309,3 +310,57 @@ export const AgentEnvironmentCapabilitiesSchema = z
|
|
|
309
310
|
});
|
|
310
311
|
}
|
|
311
312
|
});
|
|
313
|
+
/**
|
|
314
|
+
* Compute the canonical identity of a generic environment create request.
|
|
315
|
+
*
|
|
316
|
+
* The operation key names the request and the abort signal controls one
|
|
317
|
+
* attempt, so neither belongs in the input identity. Every other field is
|
|
318
|
+
* canonicalized with the shared RFC 8785 JSON representation.
|
|
319
|
+
* @internal
|
|
320
|
+
*/
|
|
321
|
+
export function agentEnvironmentCreateInputDigest(input) {
|
|
322
|
+
const { idempotencyKey: _idempotencyKey, signal: _signal, ...material } = input;
|
|
323
|
+
return canonicalCandidateDigest({
|
|
324
|
+
kind: "agent-environment-create.v1",
|
|
325
|
+
input: material,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Apply the generic create contract to one provider adapter's keyed requests.
|
|
330
|
+
*
|
|
331
|
+
* The provider's backing service remains responsible for retaining the key
|
|
332
|
+
* across adapter reconstruction. This helper coalesces concurrent retries and
|
|
333
|
+
* rejects collisions before the provider performs another create effect.
|
|
334
|
+
* @internal
|
|
335
|
+
*/
|
|
336
|
+
export async function createAgentEnvironmentWithIdempotency(records, input, create) {
|
|
337
|
+
input.signal?.throwIfAborted();
|
|
338
|
+
const key = input.idempotencyKey;
|
|
339
|
+
if (key === undefined)
|
|
340
|
+
return create();
|
|
341
|
+
const digest = agentEnvironmentCreateInputDigest(input);
|
|
342
|
+
const existing = records.get(key);
|
|
343
|
+
if (existing !== undefined) {
|
|
344
|
+
if (existing.digest !== digest) {
|
|
345
|
+
throw new Error("agent environment create idempotency key conflicts with a different create input");
|
|
346
|
+
}
|
|
347
|
+
return existing.environment ?? existing.pending;
|
|
348
|
+
}
|
|
349
|
+
const pending = Promise.resolve().then(create);
|
|
350
|
+
const record = {
|
|
351
|
+
digest,
|
|
352
|
+
pending,
|
|
353
|
+
};
|
|
354
|
+
records.set(key, record);
|
|
355
|
+
try {
|
|
356
|
+
const environment = await pending;
|
|
357
|
+
if (records.get(key) === record)
|
|
358
|
+
record.environment = environment;
|
|
359
|
+
return environment;
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (records.get(key) === record)
|
|
363
|
+
records.delete(key);
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export * from "./host-services.js";
|
|
|
8
8
|
export * from "./mcp.js";
|
|
9
9
|
export * from "./provider-adapter.js";
|
|
10
10
|
export type * from "./environment-provider.js";
|
|
11
|
-
export { AgentEnvironmentCapabilitiesSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentNativeContextContinuationResultMatchesRequest, AccountUsageSchema, AgentEnvironmentObservationSchema, AgentEnvironmentStatusSchema, ComputeBillingSchema, EnvironmentLifecycleSchema, ModelUsageSchema, ObservationProvenanceSchema, ObservationStateSchema, PlacementDescriptorSchema, ProviderIdentitySchema, ResourceProfileSchema, ResourceUseSampleSchema, SafeEndpointSchema, agentEnvironmentObservationIdentityMatches, assertObservationCredentialFree, observationContainsCredential, observationOf, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentInteractiveSessionStopRequestDigest, agentInteractiveSessionRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, exactAgentInteractiveSessionStart, TerminalAttachRequestSchema, TerminalAttachResultSchema, TerminalDetachAckSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, terminalAttachResultMatchesRequest, terminalSessionUsable, } from "./environment-provider.js";
|
|
11
|
+
export { AgentEnvironmentCapabilitiesSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentEnvironmentCreateInputDigest, agentNativeContextContinuationResultMatchesRequest, AccountUsageSchema, AgentEnvironmentObservationSchema, AgentEnvironmentStatusSchema, ComputeBillingSchema, EnvironmentLifecycleSchema, ModelUsageSchema, ObservationProvenanceSchema, ObservationStateSchema, PlacementDescriptorSchema, ProviderIdentitySchema, ResourceProfileSchema, ResourceUseSampleSchema, SafeEndpointSchema, agentEnvironmentObservationIdentityMatches, assertObservationCredentialFree, observationContainsCredential, observationOf, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentInteractiveSessionStopRequestDigest, agentInteractiveSessionRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, exactAgentInteractiveSessionStart, createAgentEnvironmentWithIdempotency, TerminalAttachRequestSchema, TerminalAttachResultSchema, TerminalDetachAckSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, terminalAttachResultMatchesRequest, terminalSessionUsable, } from "./environment-provider.js";
|
|
12
12
|
export * from "./plan.js";
|
|
13
13
|
export * from "./runtime-control.js";
|
|
14
14
|
export * from "./portable-context.js";
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export * from "./provider-config.js";
|
|
|
7
7
|
export * from "./host-services.js";
|
|
8
8
|
export * from "./mcp.js";
|
|
9
9
|
export * from "./provider-adapter.js";
|
|
10
|
-
export { AgentEnvironmentCapabilitiesSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentNativeContextContinuationResultMatchesRequest, AccountUsageSchema, AgentEnvironmentObservationSchema, AgentEnvironmentStatusSchema, ComputeBillingSchema, EnvironmentLifecycleSchema, ModelUsageSchema, ObservationProvenanceSchema, ObservationStateSchema, PlacementDescriptorSchema, ProviderIdentitySchema, ResourceProfileSchema, ResourceUseSampleSchema, SafeEndpointSchema, agentEnvironmentObservationIdentityMatches, assertObservationCredentialFree, observationContainsCredential, observationOf, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentInteractiveSessionStopRequestDigest, agentInteractiveSessionRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, exactAgentInteractiveSessionStart, TerminalAttachRequestSchema, TerminalAttachResultSchema, TerminalDetachAckSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, terminalAttachResultMatchesRequest, terminalSessionUsable, } from "./environment-provider.js";
|
|
10
|
+
export { AgentEnvironmentCapabilitiesSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentEnvironmentCreateInputDigest, agentNativeContextContinuationResultMatchesRequest, AccountUsageSchema, AgentEnvironmentObservationSchema, AgentEnvironmentStatusSchema, ComputeBillingSchema, EnvironmentLifecycleSchema, ModelUsageSchema, ObservationProvenanceSchema, ObservationStateSchema, PlacementDescriptorSchema, ProviderIdentitySchema, ResourceProfileSchema, ResourceUseSampleSchema, SafeEndpointSchema, agentEnvironmentObservationIdentityMatches, assertObservationCredentialFree, observationContainsCredential, observationOf, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentInteractiveSessionStopRequestDigest, agentInteractiveSessionRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, exactAgentInteractiveSessionStart, createAgentEnvironmentWithIdempotency, TerminalAttachRequestSchema, TerminalAttachResultSchema, TerminalDetachAckSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, terminalAttachResultMatchesRequest, terminalSessionUsable, } from "./environment-provider.js";
|
|
11
11
|
export * from "./plan.js";
|
|
12
12
|
export * from "./runtime-control.js";
|
|
13
13
|
export * from "./portable-context.js";
|
|
@@ -47,7 +47,16 @@ export type ModelGatewayDefaults = {
|
|
|
47
47
|
apiKeyEnvVar: string;
|
|
48
48
|
};
|
|
49
49
|
export declare const TANGLE_ROUTER_DEFAULT_ROOT_URL = "https://router.tangle.tools";
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Model a managed run requests when nothing else names one.
|
|
52
|
+
*
|
|
53
|
+
* The router answers a Tangle-funded call only when it both routes the model
|
|
54
|
+
* AND holds a spend-authorizing price for it. A model that fails either test
|
|
55
|
+
* answers 503, which a CLI reads as transient and retries until its own
|
|
56
|
+
* timeout — so an unservable default hangs a run rather than failing it.
|
|
57
|
+
* Confirm both properties against the live router before changing this id.
|
|
58
|
+
*/
|
|
59
|
+
export declare const TANGLE_ROUTER_DEFAULT_MODEL = "zai/glm-5.2";
|
|
51
60
|
export declare function normalizeOpenAiCompatibleBaseUrl(baseUrl: string): string;
|
|
52
61
|
export declare function resolveTangleRouterDefaults(env?: Record<string, string | undefined>): ModelGatewayDefaults;
|
|
53
62
|
export declare function withModelGatewayDefaults<T extends ProviderConfig["model"]>(model: T, defaults?: ModelGatewayDefaults): T;
|
package/dist/provider-config.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export const TANGLE_ROUTER_DEFAULT_ROOT_URL = "https://router.tangle.tools";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Model a managed run requests when nothing else names one.
|
|
4
|
+
*
|
|
5
|
+
* The router answers a Tangle-funded call only when it both routes the model
|
|
6
|
+
* AND holds a spend-authorizing price for it. A model that fails either test
|
|
7
|
+
* answers 503, which a CLI reads as transient and retries until its own
|
|
8
|
+
* timeout — so an unservable default hangs a run rather than failing it.
|
|
9
|
+
* Confirm both properties against the live router before changing this id.
|
|
10
|
+
*/
|
|
11
|
+
export const TANGLE_ROUTER_DEFAULT_MODEL = "zai/glm-5.2";
|
|
3
12
|
export function normalizeOpenAiCompatibleBaseUrl(baseUrl) {
|
|
4
13
|
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
5
14
|
return /\/v\d+$/.test(trimmed) ? trimmed : `${trimmed}/v1`;
|