@tangle-network/agent-interface 5.10.11 → 5.10.12
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.
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failures an environment provider reports, as one closed set.
|
|
3
|
+
*
|
|
4
|
+
* A provider maps every vendor failure into one of these codes before it
|
|
5
|
+
* leaves the adapter, so a consumer decides retry, refusal and cleanup from
|
|
6
|
+
* the code and never from vendor message text.
|
|
7
|
+
*
|
|
8
|
+
* - `refused`: the request names a field, axis, harness or option this
|
|
9
|
+
* provider cannot honor. It is refused before any vendor call, `path` names
|
|
10
|
+
* the refused field, and nothing was provisioned.
|
|
11
|
+
* - `invalid_input`: the request is malformed.
|
|
12
|
+
* - `auth_failed`: the vendor rejected the credential. Terminal; never retried.
|
|
13
|
+
* - `not_found`: the vendor has no such environment or image.
|
|
14
|
+
* - `conflict`: the vendor reports a state conflict, for example a second delete.
|
|
15
|
+
* - `capacity`: upstream capacity, quota or rate limit (status 429, 503, 529 or
|
|
16
|
+
* an upstream capacity code in `upstreamCode`). Retryable later.
|
|
17
|
+
* - `transport`: the network or vendor service failed. Retryable.
|
|
18
|
+
* - `timeout`: a bounded operation ran out of time.
|
|
19
|
+
* - `aborted`: the caller's signal ended the operation.
|
|
20
|
+
* - `provision_failed`: the vendor could not create or start the sandbox.
|
|
21
|
+
* - `materialization_failed`: the harness or profile could not be applied in
|
|
22
|
+
* the sandbox.
|
|
23
|
+
* - `harness_failed`: the harness process failed.
|
|
24
|
+
* - `cleanup_failed`: a sandbox could not be destroyed; `cleanupHandle` names it.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ENVIRONMENT_PROVIDER_ERROR_CODES: readonly ["refused", "invalid_input", "auth_failed", "not_found", "conflict", "capacity", "transport", "timeout", "aborted", "provision_failed", "materialization_failed", "harness_failed", "cleanup_failed"];
|
|
27
|
+
export type EnvironmentProviderErrorCode = (typeof ENVIRONMENT_PROVIDER_ERROR_CODES)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Bound a vendor message and remove credentials from it.
|
|
30
|
+
*
|
|
31
|
+
* Every value in `secrets` is removed wherever it appears, and so is any
|
|
32
|
+
* credential-shaped token. The result is at most 2,000 characters.
|
|
33
|
+
*/
|
|
34
|
+
export declare function scrubEnvironmentProviderMessage(message: string, secrets?: readonly string[]): string;
|
|
35
|
+
export interface EnvironmentProviderErrorOptions {
|
|
36
|
+
/** HTTP status when the failure came from an HTTP service. */
|
|
37
|
+
status?: number;
|
|
38
|
+
/** The refused create or turn field, for `refused` and `invalid_input`. */
|
|
39
|
+
path?: string;
|
|
40
|
+
/** The upstream's own capacity or failure code, for example `rate_limit_exceeded`. */
|
|
41
|
+
upstreamCode?: string;
|
|
42
|
+
/** Name of the provider that raised the error. */
|
|
43
|
+
provider?: string;
|
|
44
|
+
/** The sandbox a failed cleanup left behind, for `cleanup_failed` and for any failure after provisioning. */
|
|
45
|
+
cleanupHandle?: {
|
|
46
|
+
environmentId: string;
|
|
47
|
+
provider?: string;
|
|
48
|
+
};
|
|
49
|
+
/** The vendor error. Kept as `cause`; its message is scrubbed on this error, not on the cause. */
|
|
50
|
+
cause?: unknown;
|
|
51
|
+
/** Secret values removed from the message wherever they appear. */
|
|
52
|
+
secrets?: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
/** A classified provider failure with a stable code and a scrubbed, bounded message. */
|
|
55
|
+
export declare class EnvironmentProviderError extends Error {
|
|
56
|
+
readonly code: EnvironmentProviderErrorCode;
|
|
57
|
+
readonly status?: number;
|
|
58
|
+
readonly path?: string;
|
|
59
|
+
readonly upstreamCode?: string;
|
|
60
|
+
readonly provider?: string;
|
|
61
|
+
readonly cleanupHandle?: {
|
|
62
|
+
environmentId: string;
|
|
63
|
+
provider?: string;
|
|
64
|
+
};
|
|
65
|
+
constructor(code: EnvironmentProviderErrorCode, message: string, options?: EnvironmentProviderErrorOptions);
|
|
66
|
+
/** Whether a caller may retry the same request later. `auth_failed` is never retryable. */
|
|
67
|
+
get retryable(): boolean;
|
|
68
|
+
}
|
|
69
|
+
export declare function isEnvironmentProviderError(value: unknown): value is EnvironmentProviderError;
|
|
70
|
+
/**
|
|
71
|
+
* The code for an HTTP failure status. 429, 503 and 529 are upstream capacity;
|
|
72
|
+
* every other 5xx is transport; 401 and 403 are an authentication failure;
|
|
73
|
+
* 408 is a timeout.
|
|
74
|
+
*/
|
|
75
|
+
export declare function environmentProviderErrorCodeForStatus(status: number): EnvironmentProviderErrorCode;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failures an environment provider reports, as one closed set.
|
|
3
|
+
*
|
|
4
|
+
* A provider maps every vendor failure into one of these codes before it
|
|
5
|
+
* leaves the adapter, so a consumer decides retry, refusal and cleanup from
|
|
6
|
+
* the code and never from vendor message text.
|
|
7
|
+
*
|
|
8
|
+
* - `refused`: the request names a field, axis, harness or option this
|
|
9
|
+
* provider cannot honor. It is refused before any vendor call, `path` names
|
|
10
|
+
* the refused field, and nothing was provisioned.
|
|
11
|
+
* - `invalid_input`: the request is malformed.
|
|
12
|
+
* - `auth_failed`: the vendor rejected the credential. Terminal; never retried.
|
|
13
|
+
* - `not_found`: the vendor has no such environment or image.
|
|
14
|
+
* - `conflict`: the vendor reports a state conflict, for example a second delete.
|
|
15
|
+
* - `capacity`: upstream capacity, quota or rate limit (status 429, 503, 529 or
|
|
16
|
+
* an upstream capacity code in `upstreamCode`). Retryable later.
|
|
17
|
+
* - `transport`: the network or vendor service failed. Retryable.
|
|
18
|
+
* - `timeout`: a bounded operation ran out of time.
|
|
19
|
+
* - `aborted`: the caller's signal ended the operation.
|
|
20
|
+
* - `provision_failed`: the vendor could not create or start the sandbox.
|
|
21
|
+
* - `materialization_failed`: the harness or profile could not be applied in
|
|
22
|
+
* the sandbox.
|
|
23
|
+
* - `harness_failed`: the harness process failed.
|
|
24
|
+
* - `cleanup_failed`: a sandbox could not be destroyed; `cleanupHandle` names it.
|
|
25
|
+
*/
|
|
26
|
+
export const ENVIRONMENT_PROVIDER_ERROR_CODES = [
|
|
27
|
+
"refused",
|
|
28
|
+
"invalid_input",
|
|
29
|
+
"auth_failed",
|
|
30
|
+
"not_found",
|
|
31
|
+
"conflict",
|
|
32
|
+
"capacity",
|
|
33
|
+
"transport",
|
|
34
|
+
"timeout",
|
|
35
|
+
"aborted",
|
|
36
|
+
"provision_failed",
|
|
37
|
+
"materialization_failed",
|
|
38
|
+
"harness_failed",
|
|
39
|
+
"cleanup_failed",
|
|
40
|
+
];
|
|
41
|
+
/** Codes a caller may retry without changing the request. */
|
|
42
|
+
const RETRYABLE_CODES = new Set([
|
|
43
|
+
"capacity",
|
|
44
|
+
"transport",
|
|
45
|
+
]);
|
|
46
|
+
const MAX_MESSAGE_LENGTH = 2_000;
|
|
47
|
+
const MIN_SCRUBBED_SECRET_LENGTH = 6;
|
|
48
|
+
/** Credential-shaped text that is removed from a message even when the caller named no secret. */
|
|
49
|
+
const CREDENTIAL_PATTERNS = [
|
|
50
|
+
/\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/g,
|
|
51
|
+
/\bsk-[A-Za-z0-9_-]{8,}/g,
|
|
52
|
+
/\b(?:ghp|gho|ghs|github_pat)_[A-Za-z0-9_]{12,}/g,
|
|
53
|
+
/\b(?:api[_-]?key|token|secret|password)=[^\s&"']{4,}/gi,
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Bound a vendor message and remove credentials from it.
|
|
57
|
+
*
|
|
58
|
+
* Every value in `secrets` is removed wherever it appears, and so is any
|
|
59
|
+
* credential-shaped token. The result is at most 2,000 characters.
|
|
60
|
+
*/
|
|
61
|
+
export function scrubEnvironmentProviderMessage(message, secrets = []) {
|
|
62
|
+
let scrubbed = message;
|
|
63
|
+
for (const secret of secrets) {
|
|
64
|
+
if (secret.length >= MIN_SCRUBBED_SECRET_LENGTH) {
|
|
65
|
+
scrubbed = scrubbed.split(secret).join("[redacted]");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const pattern of CREDENTIAL_PATTERNS) {
|
|
69
|
+
scrubbed = scrubbed.replace(pattern, "[redacted]");
|
|
70
|
+
}
|
|
71
|
+
return scrubbed.length > MAX_MESSAGE_LENGTH
|
|
72
|
+
? `${scrubbed.slice(0, MAX_MESSAGE_LENGTH)}...`
|
|
73
|
+
: scrubbed;
|
|
74
|
+
}
|
|
75
|
+
/** A classified provider failure with a stable code and a scrubbed, bounded message. */
|
|
76
|
+
export class EnvironmentProviderError extends Error {
|
|
77
|
+
code;
|
|
78
|
+
status;
|
|
79
|
+
path;
|
|
80
|
+
upstreamCode;
|
|
81
|
+
provider;
|
|
82
|
+
cleanupHandle;
|
|
83
|
+
constructor(code, message, options = {}) {
|
|
84
|
+
super(scrubEnvironmentProviderMessage(message, options.secrets), options.cause === undefined ? undefined : { cause: options.cause });
|
|
85
|
+
this.name = "EnvironmentProviderError";
|
|
86
|
+
this.code = code;
|
|
87
|
+
if (options.status !== undefined)
|
|
88
|
+
this.status = options.status;
|
|
89
|
+
if (options.path !== undefined)
|
|
90
|
+
this.path = options.path;
|
|
91
|
+
if (options.upstreamCode !== undefined)
|
|
92
|
+
this.upstreamCode = options.upstreamCode;
|
|
93
|
+
if (options.provider !== undefined)
|
|
94
|
+
this.provider = options.provider;
|
|
95
|
+
if (options.cleanupHandle !== undefined)
|
|
96
|
+
this.cleanupHandle = options.cleanupHandle;
|
|
97
|
+
}
|
|
98
|
+
/** Whether a caller may retry the same request later. `auth_failed` is never retryable. */
|
|
99
|
+
get retryable() {
|
|
100
|
+
return RETRYABLE_CODES.has(this.code);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export function isEnvironmentProviderError(value) {
|
|
104
|
+
return (value instanceof EnvironmentProviderError ||
|
|
105
|
+
(value instanceof Error &&
|
|
106
|
+
value.name === "EnvironmentProviderError" &&
|
|
107
|
+
ENVIRONMENT_PROVIDER_ERROR_CODES.includes(value.code)));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The code for an HTTP failure status. 429, 503 and 529 are upstream capacity;
|
|
111
|
+
* every other 5xx is transport; 401 and 403 are an authentication failure;
|
|
112
|
+
* 408 is a timeout.
|
|
113
|
+
*/
|
|
114
|
+
export function environmentProviderErrorCodeForStatus(status) {
|
|
115
|
+
if (status === 401 || status === 403)
|
|
116
|
+
return "auth_failed";
|
|
117
|
+
if (status === 404)
|
|
118
|
+
return "not_found";
|
|
119
|
+
if (status === 408)
|
|
120
|
+
return "timeout";
|
|
121
|
+
if (status === 409)
|
|
122
|
+
return "conflict";
|
|
123
|
+
if (status === 429 || status === 503 || status === 529)
|
|
124
|
+
return "capacity";
|
|
125
|
+
if (status >= 500)
|
|
126
|
+
return "transport";
|
|
127
|
+
return "invalid_input";
|
|
128
|
+
}
|
|
@@ -7,6 +7,7 @@ export * from "./environment-observation.js";
|
|
|
7
7
|
export * from "./environment-terminal.js";
|
|
8
8
|
export * from "./environment-runtime.js";
|
|
9
9
|
export * from "./environment-command-turn.js";
|
|
10
|
+
export * from "./environment-provider-error.js";
|
|
10
11
|
export * from "./workspace-cwd.js";
|
|
11
12
|
export * from "./workspace-snapshot.js";
|
|
12
13
|
export * from "./proxy-secrets.js";
|
|
@@ -7,6 +7,7 @@ export * from "./environment-observation.js";
|
|
|
7
7
|
export * from "./environment-terminal.js";
|
|
8
8
|
export * from "./environment-runtime.js";
|
|
9
9
|
export * from "./environment-command-turn.js";
|
|
10
|
+
export * from "./environment-provider-error.js";
|
|
10
11
|
export * from "./workspace-cwd.js";
|
|
11
12
|
export * from "./workspace-snapshot.js";
|
|
12
13
|
export * from "./proxy-secrets.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./mcp.js";
|
|
|
10
10
|
export * from "./provider-adapter.js";
|
|
11
11
|
export type * from "./environment-provider.js";
|
|
12
12
|
export { AgentEnvironmentCapabilitiesSchema, AgentEnvironmentReadOnlyGetOptionsSchema, AgentRuntimeAttachmentsSchema, AgentNativeContextContinuationAdmissionSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentEnvironmentCreateInputDigest, agentNativeContextContinuationAdmissionMatchesRequest, agentNativeContextContinuationResultMatchesRequest, AccountUsageSchema, AgentEnvironmentObservationSchema, AgentEnvironmentStatusSchema, ComputeBillingSchema, EnvironmentLifecycleSchema, ModelUsageSchema, ObservationProvenanceSchema, PlacementDescriptorSchema, ProviderIdentitySchema, ResourceProfileSchema, ResourceUseSampleSchema, SafeEndpointSchema, agentEnvironmentObservationIdentityMatches, observationContainsCredential, observationOf, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentInteractiveSessionStopRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, exactAgentInteractiveSessionStart, createAgentEnvironmentWithIdempotency, canonicalWorkspaceCwd, MAX_WORKSPACE_CWD_LENGTH, workspaceCwdSchema, workspaceCwdPathForBase, WorkspaceRequestSchema, ResourceRequestSchema, TerminalAttachRequestSchema, TerminalAttachResultSchema, TerminalDetachAckSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, terminalAttachResultMatchesRequest, terminalSessionUsable, } from "./environment-provider.js";
|
|
13
|
+
export * from "./environment-provider-error.js";
|
|
13
14
|
export * from "./plan.js";
|
|
14
15
|
export * from "./runtime-control.js";
|
|
15
16
|
export * from "./portable-context.js";
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./host-services.js";
|
|
|
9
9
|
export * from "./mcp.js";
|
|
10
10
|
export * from "./provider-adapter.js";
|
|
11
11
|
export { AgentEnvironmentCapabilitiesSchema, AgentEnvironmentReadOnlyGetOptionsSchema, AgentRuntimeAttachmentsSchema, AgentNativeContextContinuationAdmissionSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentEnvironmentCreateInputDigest, agentNativeContextContinuationAdmissionMatchesRequest, agentNativeContextContinuationResultMatchesRequest, AccountUsageSchema, AgentEnvironmentObservationSchema, AgentEnvironmentStatusSchema, ComputeBillingSchema, EnvironmentLifecycleSchema, ModelUsageSchema, ObservationProvenanceSchema, PlacementDescriptorSchema, ProviderIdentitySchema, ResourceProfileSchema, ResourceUseSampleSchema, SafeEndpointSchema, agentEnvironmentObservationIdentityMatches, observationContainsCredential, observationOf, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentInteractiveSessionStopRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, exactAgentInteractiveSessionStart, createAgentEnvironmentWithIdempotency, canonicalWorkspaceCwd, MAX_WORKSPACE_CWD_LENGTH, workspaceCwdSchema, workspaceCwdPathForBase, WorkspaceRequestSchema, ResourceRequestSchema, TerminalAttachRequestSchema, TerminalAttachResultSchema, TerminalDetachAckSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, terminalAttachResultMatchesRequest, terminalSessionUsable, } from "./environment-provider.js";
|
|
12
|
+
export * from "./environment-provider-error.js";
|
|
12
13
|
export * from "./plan.js";
|
|
13
14
|
export * from "./runtime-control.js";
|
|
14
15
|
export * from "./portable-context.js";
|