@tangle-network/agent-provider-tangle 4.2.0 → 4.2.2

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
@@ -710,6 +710,14 @@ The command transport accepts the same public capacity body only with exit code
710
710
  Its typed error has no HTTP status.
711
711
  The caller's execution owner decides whether and when to retry.
712
712
 
713
+ A deterministic unsupported subscription route returns only
714
+ `{ error: { code: "model_credential_refused", reason: "unsupported_route" } }`.
715
+ The command transport accepts this fixed envelope only with exit code 78; the HTTP transport
716
+ accepts it only with an actual HTTP 400 response. Both expose `TangleCredentialRefusalError`
717
+ before provisioning, with a fixed public message and no private command diagnostics.
718
+ The command error has no HTTP status. Unknown fields or reasons are rejected; generic
719
+ command failures, network failures and held account capacity do not become this refusal.
720
+
713
721
  ### Completion and native evidence
714
722
 
715
723
  The provider projects terminal results and terminal stream events into bounded completion summaries.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Validate the whole capability list, then project the IDs this client knows.
3
+ * A newer server may advertise additional harnesses without breaking a known
4
+ * selection. An unknown ID never grants support; selected-harness admission is
5
+ * still required. Malformed, sparse, duplicate and unbounded lists fail closed.
6
+ */
7
+ export declare function recognizedCaptureHarnesses<H extends string>(raw: unknown, knownHarnesses: readonly H[]): readonly H[];
@@ -0,0 +1,29 @@
1
+ /** Bound the wire document independently of this client's known vocabulary. */
2
+ const MAX_HARNESS_ENTRIES = 256;
3
+ const MAX_HARNESS_ID_LENGTH = 128;
4
+ const INVALID_ID_CHARACTER = /[\s\u0000-\u001f\u007f]/u;
5
+ /**
6
+ * Validate the whole capability list, then project the IDs this client knows.
7
+ * A newer server may advertise additional harnesses without breaking a known
8
+ * selection. An unknown ID never grants support; selected-harness admission is
9
+ * still required. Malformed, sparse, duplicate and unbounded lists fail closed.
10
+ */
11
+ export function recognizedCaptureHarnesses(raw, knownHarnesses) {
12
+ const fail = () => {
13
+ throw new Error("Tangle deployment has not proven native session capture with a valid harness list");
14
+ };
15
+ if (!Array.isArray(raw) || raw.length > MAX_HARNESS_ENTRIES)
16
+ return fail();
17
+ const known = new Set(knownHarnesses);
18
+ const seen = new Set();
19
+ const recognized = [];
20
+ for (const id of raw) {
21
+ if (typeof id !== "string" || id.length === 0 || id.length > MAX_HARNESS_ID_LENGTH ||
22
+ INVALID_ID_CHARACTER.test(id) || seen.has(id))
23
+ return fail();
24
+ seen.add(id);
25
+ if (known.has(id))
26
+ recognized.push(id);
27
+ }
28
+ return Object.freeze(recognized);
29
+ }
@@ -1,4 +1,4 @@
1
- import { parseCredentialCapacity } from "./model-credential-capacity.js";
1
+ import { parseCredentialCapacity, parseCredentialRefusal } from "./model-credential-capacity.js";
2
2
  import { spawn } from "node:child_process";
3
3
  import { profileCredentialSource } from "./model-credential-source.js";
4
4
  import { captureModelCredentials } from "./tangle-create-options.js";
@@ -96,14 +96,15 @@ export function createCommandModelCredentialResolver(options) {
96
96
  if (settled)
97
97
  return;
98
98
  if (code !== 0) {
99
- if (code === 75) {
100
- let capacity;
99
+ if (code === 75 || code === 78) {
100
+ let refusal;
101
101
  try {
102
- capacity = parseCredentialCapacity(JSON.parse(Buffer.concat(chunks).toString("utf8")));
102
+ const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
103
+ refusal = code === 75 ? parseCredentialCapacity(payload) : parseCredentialRefusal(payload);
103
104
  }
104
105
  catch { /* Malformed command output stays a sanitized generic refusal. */ }
105
- if (capacity !== undefined) {
106
- fail(capacity);
106
+ if (refusal !== undefined) {
107
+ fail(refusal);
107
108
  return;
108
109
  }
109
110
  }
@@ -1,4 +1,4 @@
1
- import { parseCredentialCapacity } from "./model-credential-capacity.js";
1
+ import { parseCredentialCapacity, parseCredentialRefusal } from "./model-credential-capacity.js";
2
2
  import { profileCredentialSource } from "./model-credential-source.js";
3
3
  import { parseModelCredentialResolverRequest } from "./model-credential-request.js";
4
4
  import { captureModelCredentials } from "./tangle-create-options.js";
@@ -102,9 +102,11 @@ export function createHttpModelCredentialResolver(options) {
102
102
  if (!response.ok) {
103
103
  let exitCode;
104
104
  let capacity;
105
+ let refusal;
105
106
  try {
106
107
  const payload = await publicResponse(response);
107
108
  capacity = parseCredentialCapacity(payload, response.status);
109
+ refusal = parseCredentialRefusal(payload, response.status);
108
110
  const detail = payload && typeof payload === "object" && "error" in payload ? payload.error : undefined;
109
111
  if (detail && typeof detail === "object" && "exitCode" in detail &&
110
112
  typeof detail.exitCode === "number" && Number.isSafeInteger(detail.exitCode) && detail.exitCode >= 0 && detail.exitCode <= 255) {
@@ -116,6 +118,8 @@ export function createHttpModelCredentialResolver(options) {
116
118
  }
117
119
  if (capacity !== undefined)
118
120
  throw capacity;
121
+ if (refusal !== undefined)
122
+ throw refusal;
119
123
  throw Object.assign(new Error(`Tangle credential broker refused resolution (HTTP ${response.status}${exitCode === undefined ? "" : `, owner exit ${exitCode}`})`), {
120
124
  status: response.status, ...(exitCode === undefined ? {} : { exitCode }),
121
125
  });
@@ -8,5 +8,14 @@ export declare class TangleCredentialCapacityError extends Error {
8
8
  readonly status?: number;
9
9
  constructor(code: CredentialCapacityCode, reason: CredentialCapacityReason, resetAt?: string, httpStatus?: number);
10
10
  }
11
+ /** A deterministic credential route refusal, before dispatch or account admission. */
12
+ export declare class TangleCredentialRefusalError extends Error {
13
+ readonly code = "model_credential_refused";
14
+ readonly reason = "unsupported_route";
15
+ readonly status?: number;
16
+ constructor(httpStatus?: number);
17
+ }
18
+ /** The fixed public route refusal shares the bounded capacity transport, never private diagnostics. */
19
+ export declare function parseCredentialRefusal(value: unknown, httpStatus?: number): TangleCredentialRefusalError | undefined;
11
20
  /** Only fixed public fields survive parsing; upstream messages and private diagnostics do not. */
12
21
  export declare function parseCredentialCapacity(value: unknown, httpStatus?: number): TangleCredentialCapacityError | undefined;
@@ -17,10 +17,38 @@ export class TangleCredentialCapacityError extends Error {
17
17
  }
18
18
  }
19
19
  }
20
+ /** A deterministic credential route refusal, before dispatch or account admission. */
21
+ export class TangleCredentialRefusalError extends Error {
22
+ code = "model_credential_refused";
23
+ reason = "unsupported_route";
24
+ constructor(httpStatus) {
25
+ super("Subscription credential route is unsupported");
26
+ this.name = "TangleCredentialRefusalError";
27
+ if (httpStatus !== undefined) {
28
+ if (httpStatus !== 400)
29
+ throw new Error("Credential refusal requires a real client-error response");
30
+ Object.defineProperty(this, "status", { value: httpStatus, enumerable: true });
31
+ }
32
+ }
33
+ }
20
34
  function record(value) {
21
35
  return value !== null && typeof value === "object" && !Array.isArray(value)
22
36
  ? value : undefined;
23
37
  }
38
+ /** The fixed public route refusal shares the bounded capacity transport, never private diagnostics. */
39
+ export function parseCredentialRefusal(value, httpStatus) {
40
+ if (httpStatus !== undefined && httpStatus !== 400)
41
+ return undefined;
42
+ const envelope = record(value);
43
+ if (!envelope || Object.keys(envelope).some((key) => key !== "error"))
44
+ return undefined;
45
+ const error = record(envelope.error);
46
+ if (!error || Object.keys(error).some((key) => key !== "code" && key !== "reason"))
47
+ return undefined;
48
+ if (error.code !== "model_credential_refused" || error.reason !== "unsupported_route")
49
+ return undefined;
50
+ return new TangleCredentialRefusalError(httpStatus);
51
+ }
24
52
  /** Only fixed public fields survive parsing; upstream messages and private diagnostics do not. */
25
53
  export function parseCredentialCapacity(value, httpStatus) {
26
54
  if (httpStatus !== undefined && httpStatus !== 429 && httpStatus !== 503)
package/dist/node.d.ts CHANGED
@@ -4,7 +4,7 @@ export { createHttpModelCredentialResolver } from "./http-model-credentials.js";
4
4
  export type { HttpModelCredentialResolverOptions } from "./http-model-credentials.js";
5
5
  export { parseModelCredentialResolverRequest } from "./model-credential-request.js";
6
6
  export type { ModelCredentialResolverRequest } from "./model-credential-request.js";
7
- export { TangleCredentialCapacityError } from "./model-credential-capacity.js";
7
+ export { TangleCredentialCapacityError, TangleCredentialRefusalError } from "./model-credential-capacity.js";
8
8
  export type { CredentialCapacityCode, CredentialCapacityReason } from "./model-credential-capacity.js";
9
9
  export { captureTangleEnvironmentEvidenceToDirectory, captureTangleSandboxEvidenceToDirectory } from "./tangle-evidence.js";
10
10
  export type { TangleDirectoryEvidence } from "./tangle-evidence.js";
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createCommandModelCredentialResolver } from "./command-model-credentials.js";
2
2
  export { createHttpModelCredentialResolver } from "./http-model-credentials.js";
3
3
  export { parseModelCredentialResolverRequest } from "./model-credential-request.js";
4
- export { TangleCredentialCapacityError } from "./model-credential-capacity.js";
4
+ export { TangleCredentialCapacityError, TangleCredentialRefusalError } from "./model-credential-capacity.js";
5
5
  export { captureTangleEnvironmentEvidenceToDirectory, captureTangleSandboxEvidenceToDirectory } from "./tangle-evidence.js";
@@ -2,7 +2,11 @@ import { type HarnessType } from "@tangle-network/agent-interface";
2
2
  import type { NativeCaptureProofLike, SandboxInstanceLike, SandboxRuntimeCapabilityDocument } from "./tangle-types.js";
3
3
  /** Require a current host proof; a create must also prove its receipt names that same container. */
4
4
  export declare function requireNativeCaptureProof(box: SandboxInstanceLike, create?: boolean): NativeCaptureProofLike;
5
- /** Parse the deployment's explicit per-harness admission without inferring from a global flag. */
5
+ /**
6
+ * Read the known subset of a valid deployment list. Newer-server entries neither
7
+ * break a known selection nor grant this client support for an unknown harness.
8
+ * Admission below still requires a recognized, explicitly advertised identity.
9
+ */
6
10
  export declare function nativeCaptureHarnesses(raw: unknown): readonly HarnessType[];
7
11
  /** Require the selected container's native protocol and exact agent backend before dispatch. */
8
12
  export declare function requireNativeCaptureCapability(box: SandboxInstanceLike, harness: string): Promise<SandboxRuntimeCapabilityDocument>;
@@ -1,4 +1,5 @@
1
1
  import { harnessTypeSchema } from "@tangle-network/agent-interface";
2
+ import { recognizedCaptureHarnesses } from "./capture-harness-list.js";
2
3
  const imageId = /^sha256:[0-9a-f]{64}$/;
3
4
  const containerId = /^[0-9a-f]{64}$/;
4
5
  const revision = /^[0-9a-f]{40}$/;
@@ -25,13 +26,13 @@ export function requireNativeCaptureProof(box, create = false) {
25
26
  }
26
27
  return proof;
27
28
  }
28
- /** Parse the deployment's explicit per-harness admission without inferring from a global flag. */
29
+ /**
30
+ * Read the known subset of a valid deployment list. Newer-server entries neither
31
+ * break a known selection nor grant this client support for an unknown harness.
32
+ * Admission below still requires a recognized, explicitly advertised identity.
33
+ */
29
34
  export function nativeCaptureHarnesses(raw) {
30
- const parsed = harnessTypeSchema.array().max(harnessTypeSchema.options.length).safeParse(raw);
31
- if (!parsed.success || new Set(parsed.data).size !== parsed.data.length) {
32
- throw new Error("Tangle deployment has not proven native session capture with a valid harness list");
33
- }
34
- return Object.freeze(parsed.data);
35
+ return recognizedCaptureHarnesses(raw, harnessTypeSchema.options);
35
36
  }
36
37
  /** Require the selected container's native protocol and exact agent backend before dispatch. */
37
38
  export async function requireNativeCaptureCapability(box, harness) {
@@ -31,7 +31,7 @@ export interface SandboxClientLike {
31
31
  /** Authenticated control-plane capability discovery before resolution or allocation. */
32
32
  capabilities?(): Promise<{
33
33
  proxySecrets?: ProxySecretCapabilities;
34
- }>;
34
+ } | null>;
35
35
  create(options?: TangleCreateSandboxOptions, requestOptions?: {
36
36
  signal?: AbortSignal;
37
37
  timeoutMs?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,109 +28,12 @@
28
28
  "registry": "https://registry.npmjs.org"
29
29
  },
30
30
  "files": [
31
- "dist/index.d.ts",
32
- "dist/index.js",
33
- "dist/exact-process.d.ts",
34
- "dist/exact-process.js",
35
- "dist/tangle-exact-process-environment.d.ts",
36
- "dist/tangle-exact-process-environment.js",
37
- "dist/tangle-contract-safety.d.ts",
38
- "dist/tangle-contract-safety.js",
39
- "dist/tangle-failure-reason.d.ts",
40
- "dist/tangle-failure-reason.js",
41
- "dist/tangle-exact-process-runtime.d.ts",
42
- "dist/tangle-exact-process-runtime.js",
43
- "dist/tangle-exact-process-validation.d.ts",
44
- "dist/tangle-exact-process-validation.js",
45
- "dist/tangle-capabilities.d.ts",
46
- "dist/tangle-capabilities.js",
47
- "dist/tangle-deployment-capabilities.d.ts",
48
- "dist/tangle-deployment-capabilities.js",
49
- "dist/tangle-create-options.d.ts",
50
- "dist/tangle-create-options.js",
51
- "dist/tangle-runtime-attachments.d.ts",
52
- "dist/tangle-runtime-attachments.js",
53
- "dist/tangle-environment-values.d.ts",
54
- "dist/tangle-environment-values.js",
55
- "dist/tangle-environment.d.ts",
56
- "dist/tangle-environment.js",
57
- "dist/tangle-evidence.d.ts",
58
- "dist/tangle-evidence.js",
59
- "dist/tangle-evidence-writer.js",
60
- "dist/tangle-evidence-writer.d.ts",
61
- "dist/tangle-evidence-json.js",
62
- "dist/tangle-evidence-json.d.ts",
63
- "dist/tangle-evidence-native-files.js",
64
- "dist/tangle-evidence-native-files.d.ts",
65
- "dist/tangle-retained-attribution.js",
66
- "dist/tangle-retained-attribution.d.ts",
67
- "dist/tangle-native-capture-proof.d.ts",
68
- "dist/tangle-native-capture-proof.js",
69
- "dist/tangle-environment-dispatch.d.ts",
70
- "dist/tangle-environment-dispatch.js",
71
- "dist/tangle-environment-session.d.ts",
72
- "dist/tangle-environment-session.js",
73
- "dist/tangle-interaction-response.d.ts",
74
- "dist/tangle-interaction-response.js",
75
- "dist/tangle-interactive.d.ts",
76
- "dist/tangle-interactive.js",
77
- "dist/tangle-environment-control.d.ts",
78
- "dist/tangle-environment-control.js",
79
- "dist/tangle-environment-validation.d.ts",
80
- "dist/tangle-environment-validation.js",
81
- "dist/tangle-events.d.ts",
82
- "dist/tangle-events.js",
83
- "dist/tangle-observation.d.ts",
84
- "dist/tangle-observation.js",
85
- "dist/tangle-resources.d.ts",
86
- "dist/tangle-resources.js",
87
- "dist/tangle-terminal.d.ts",
88
- "dist/tangle-terminal.js",
89
- "dist/tangle-terminal-frames.d.ts",
90
- "dist/tangle-terminal-frames.js",
91
- "dist/tangle-usage-log.d.ts",
92
- "dist/tangle-usage-log.js",
93
- "dist/tangle-prompt.d.ts",
94
- "dist/tangle-prompt.js",
95
- "dist/tangle-proxy-secrets.d.ts",
96
- "dist/tangle-proxy-secrets.js",
97
- "dist/tangle-provider.d.ts",
98
- "dist/tangle-provider.js",
99
- "dist/tangle-readiness.d.ts",
100
- "dist/tangle-readiness.js",
101
- "dist/tangle-result-values.d.ts",
102
- "dist/tangle-result-values.js",
103
- "dist/tangle-session-control.d.ts",
104
- "dist/tangle-session-control.js",
105
- "dist/tangle-step-usage.d.ts",
106
- "dist/tangle-step-usage.js",
107
- "dist/tangle-types.d.ts",
108
- "dist/tangle-types.js",
109
- "dist/tangle-workspace-branching.d.ts",
110
- "dist/tangle-workspace-branching.js",
111
- "dist/tangle-confidential-attestation.d.ts",
112
- "dist/tangle-confidential-attestation.js",
113
- "dist/tangle-workspace-markers.d.ts",
114
- "dist/tangle-workspace-markers.js",
115
- "dist/tangle-workspace-recovery.d.ts",
116
- "dist/tangle-workspace-recovery.js",
31
+ "dist",
117
32
  "README.md",
118
- "LICENSE",
119
- "dist/node.js",
120
- "dist/node.d.ts",
121
- "dist/command-model-credentials.js",
122
- "dist/command-model-credentials.d.ts",
123
- "dist/model-credential-source.js",
124
- "dist/model-credential-source.d.ts",
125
- "dist/http-model-credentials.js",
126
- "dist/http-model-credentials.d.ts",
127
- "dist/model-credential-request.js",
128
- "dist/model-credential-request.d.ts",
129
- "dist/model-credential-capacity.js",
130
- "dist/model-credential-capacity.d.ts"
33
+ "LICENSE"
131
34
  ],
132
35
  "dependencies": {
133
- "@tangle-network/agent-interface": "^5.3.0"
36
+ "@tangle-network/agent-interface": "^5.6.1"
134
37
  },
135
38
  "peerDependencies": {
136
39
  "@tangle-network/sandbox": ">=0.60.27 <1.0.0"
@@ -149,7 +52,7 @@
149
52
  "vitest": "5.0.2"
150
53
  },
151
54
  "scripts": {
152
- "build": "tsc -p tsconfig.json",
55
+ "build": "pnpm run clean && tsc -p tsconfig.build.json",
153
56
  "check-types": "tsc --noEmit",
154
57
  "clean": "rm -rf dist",
155
58
  "test": "vitest run src"