@tangle-network/agent-interface 5.10.11 → 5.10.13

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";
@@ -94,11 +94,11 @@ export declare function harnessSupportsModel(harness: HarnessType, modelId: stri
94
94
  * `openai` → `codex`, `moonshot` → `kimi-code`); `null` when any router-backed harness will do. */
95
95
  export declare function preferredHarnessForModel(modelId: string): HarnessType | null;
96
96
  /**
97
- * Keep `modelId` when the harness can run it; otherwise return the harness's best compatible id from
98
- * `candidateIds` (preferred patterns in order, highest version within a pattern). When nothing in the
99
- * candidate list fits, the original id is returned unchanged so the caller sees the incompatibility
100
- * instead of a silent wrong substitution. `candidateIds` are canonical ("provider/model") ids — the
101
- * caller maps its own catalog shape down to ids, keeping this layer catalog-agnostic.
97
+ * Keep `modelId` when the harness can run it; otherwise return the first compatible id in
98
+ * `candidateIds`. When nothing in the candidate list fits, the original id is returned unchanged
99
+ * so the caller sees the incompatibility instead of a silent wrong substitution. `candidateIds` are
100
+ * canonical ("provider/model") ids — the caller maps its own catalog shape down to ids, keeping
101
+ * this layer catalog-agnostic.
102
102
  */
103
103
  export declare function snapModelToHarness(harness: HarnessType, modelId: string, candidateIds: readonly string[]): string;
104
104
  /**
@@ -41,13 +41,12 @@ export function formatSeatSpec(seat) {
41
41
  * Vendor locks, before the measured {@link harnessModelExclusions}. Absent means router-backed.
42
42
  * Claude Code and Codex run any Router model: their native vendor wire passes through for vendor
43
43
  * models and translates others to chat completions (including images/tools; hosted tools drop).
44
- * A caller's vendor key/login remains vendor-limited; this table does not know credentials.
45
- * NanoClaw also routes every provider through the Router, so it has no Anthropic lock.
46
- * {@link vendorHarness} chooses a default harness; it is not a provider restriction.
44
+ * Kimi Code on a managed box writes an `openai_legacy` provider that sends chat completions to the
45
+ * Router, so it runs any Router model too. A caller's vendor key/login remains vendor-limited;
46
+ * this table does not know credentials. {@link vendorHarness} chooses a default harness; it is not
47
+ * a provider restriction.
47
48
  */
48
- const harnessProviderLock = {
49
- "kimi-code": ["moonshot"],
50
- };
49
+ const harnessProviderLock = {};
51
50
  /**
52
51
  * The harness that natively speaks a vendor's models. A model of that vendor adopts it when the
53
52
  * caller names no harness ({@link preferredHarnessForModel}), and a locked harness handed such a
@@ -203,35 +202,15 @@ export function preferredHarnessForModel(modelId) {
203
202
  }
204
203
  // ── Harness ↔ model snapping (catalog-aware) ─────────────────────────────────
205
204
  /**
206
- * Per-harness ranking patterns for {@link snapModelToHarness}, best first; within one pattern the
207
- * highest version wins (numeric-aware). Only vendor-locked harnesses need an entry — a router-backed
208
- * harness never snaps (it runs the model as-is).
209
- */
210
- const harnessPreferredModelPatterns = {
211
- "kimi-code": [/^moonshot\//],
212
- };
213
- const numericDesc = new Intl.Collator(undefined, {
214
- numeric: true,
215
- sensitivity: "base",
216
- });
217
- /**
218
- * Keep `modelId` when the harness can run it; otherwise return the harness's best compatible id from
219
- * `candidateIds` (preferred patterns in order, highest version within a pattern). When nothing in the
220
- * candidate list fits, the original id is returned unchanged so the caller sees the incompatibility
221
- * instead of a silent wrong substitution. `candidateIds` are canonical ("provider/model") ids — the
222
- * caller maps its own catalog shape down to ids, keeping this layer catalog-agnostic.
205
+ * Keep `modelId` when the harness can run it; otherwise return the first compatible id in
206
+ * `candidateIds`. When nothing in the candidate list fits, the original id is returned unchanged
207
+ * so the caller sees the incompatibility instead of a silent wrong substitution. `candidateIds` are
208
+ * canonical ("provider/model") ids — the caller maps its own catalog shape down to ids, keeping
209
+ * this layer catalog-agnostic.
223
210
  */
224
211
  export function snapModelToHarness(harness, modelId, candidateIds) {
225
212
  if (harnessSupportsModel(harness, modelId))
226
213
  return modelId;
227
- const patterns = harnessPreferredModelPatterns[harness] ?? [];
228
- for (const pattern of patterns) {
229
- const matches = candidateIds
230
- .filter((id) => pattern.test(id))
231
- .sort((a, b) => numericDesc.compare(b, a));
232
- if (matches.length > 0)
233
- return matches[0];
234
- }
235
214
  return candidateIds.find((id) => harnessSupportsModel(harness, id)) ?? modelId;
236
215
  }
237
216
  /**
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "5.10.11",
3
+ "version": "5.10.13",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",