@tangle-network/agent-provider-cli-bridge 2.0.12 → 2.0.14

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.
@@ -159,6 +159,9 @@ export function narrowCliBridgeCapabilities(adapter, reported, selectedBackend,
159
159
  placement: adapter.placement && reported.placement,
160
160
  usage: adapter.usage && reported.usage,
161
161
  confidential: adapter.confidential && reported.confidential,
162
+ // Bridge discovery documents carry no create block, so they cannot deny
163
+ // the create inputs this adapter forwards (wire.ts runtime_attachments).
164
+ ...(adapter.create === undefined ? {} : { create: adapter.create }),
162
165
  // Observation is measured by this adapter, not by the remote backend document.
163
166
  ...(observation === undefined ? {} : { observation }),
164
167
  };
@@ -1,4 +1,4 @@
1
- import type { Sha256Digest } from "@tangle-network/agent-interface";
1
+ import { type Sha256Digest } from "@tangle-network/agent-interface";
2
2
  export interface CliBridgeEnvironmentRoute {
3
3
  readonly backend?: string;
4
4
  readonly model?: string;
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
+ import { CONTRACT_MAX_IDENTIFIER_LENGTH } from "@tangle-network/agent-interface";
2
3
  const CLI_BRIDGE_ENVIRONMENT_ID_PREFIX = "cb1.";
3
- const MAX_ENVIRONMENT_ID_LENGTH = 512;
4
4
  /**
5
5
  * Keep the exact route and create digest inside the provider-owned id.
6
6
  * The nonce hides a caller idempotency key while repeated creates stay stable.
@@ -17,8 +17,8 @@ export function cliBridgeEnvironmentId(route, createDigest, idempotencyKey) {
17
17
  nonce,
18
18
  ]);
19
19
  const id = `${CLI_BRIDGE_ENVIRONMENT_ID_PREFIX}${Buffer.from(payload).toString("base64url")}`;
20
- if (id.length > MAX_ENVIRONMENT_ID_LENGTH) {
21
- throw new Error("cli-bridge route is too long to retain in an environment id");
20
+ if (id.length > CONTRACT_MAX_IDENTIFIER_LENGTH) {
21
+ throw new Error(`cli-bridge route is too long to retain in an environment id of at most ${CONTRACT_MAX_IDENTIFIER_LENGTH} characters`);
22
22
  }
23
23
  return id;
24
24
  }
@@ -27,7 +27,7 @@ export function cliBridgeEnvironmentRoute(id) {
27
27
  if (!id.startsWith(CLI_BRIDGE_ENVIRONMENT_ID_PREFIX)) {
28
28
  throw new Error("cli-bridge environment id is not a provider-owned retained identity");
29
29
  }
30
- if (id.length > MAX_ENVIRONMENT_ID_LENGTH) {
30
+ if (id.length > CONTRACT_MAX_IDENTIFIER_LENGTH) {
31
31
  throw new Error("cli-bridge environment id has invalid retained route data");
32
32
  }
33
33
  const encoded = id.slice(CLI_BRIDGE_ENVIRONMENT_ID_PREFIX.length);
@@ -72,7 +72,7 @@ function optionalRouteValue(value) {
72
72
  function routeValue(value) {
73
73
  return (typeof value === "string" &&
74
74
  value.length > 0 &&
75
- value.length <= MAX_ENVIRONMENT_ID_LENGTH &&
75
+ value.length <= CONTRACT_MAX_IDENTIFIER_LENGTH &&
76
76
  value.trim() === value);
77
77
  }
78
78
  function sha256Digest(value) {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { agentEnvironmentCreateInputDigest, createAgentEnvironmentWithIdempotency, AgentEnvironmentGetOptionsSchema, } from "@tangle-network/agent-interface/environment-provider";
2
- import { harnessTypeSchema, harnessSystemPromptIntents, snapshotAgentProfile, deepFreeze, ContextTransferReceiptSchema, WorkspaceRequestSchema, workspaceCwdPathForBase, } from "@tangle-network/agent-interface";
2
+ import { CONTRACT_MAX_IDENTIFIER_LENGTH, harnessTypeSchema, harnessSystemPromptIntents, snapshotAgentProfile, deepFreeze, ContextTransferReceiptSchema, WorkspaceRequestSchema, workspaceCwdPathForBase, } from "@tangle-network/agent-interface";
3
3
  import { createCliBridgeEnvironment, } from "./retained-environment.js";
4
4
  import { lookupExactCliBridgeRun, } from "./retained-control.js";
5
5
  import { cachedCliBridgeCapabilityDiscovery, narrowCliBridgeCapabilities, } from "./capability-discovery.js";
@@ -199,9 +199,9 @@ function selectedBackendFromRoute(route) {
199
199
  }
200
200
  function assertRequestedEnvironmentId(value) {
201
201
  if (value.length === 0 ||
202
- value.length > 256 ||
202
+ value.length > CONTRACT_MAX_IDENTIFIER_LENGTH ||
203
203
  !/^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(value)) {
204
- throw new Error("cli-bridge requested environment id must be 1-256 URL-safe characters");
204
+ throw new Error(`cli-bridge requested environment id must be 1-${CONTRACT_MAX_IDENTIFIER_LENGTH} URL-safe characters`);
205
205
  }
206
206
  }
207
207
  /** Bridge capabilities. The adapter forwards an AgentProfile and does not own harness prompt controls. */
@@ -91,9 +91,18 @@ export async function* streamCliBridgeTurn(options, turn, requestBody, transport
91
91
  const error = parsed.error;
92
92
  const message = typeof error.message === "string" ? error.message : "cli-bridge error";
93
93
  const cancelled = error.type === "run_cancelled";
94
+ // The Bridge's machine code and HTTP status classify the failure; the message only describes it.
95
+ const code = typeof error.type === "string" && error.type ? error.type : undefined;
96
+ const status = typeof error.status === "number" && Number.isInteger(error.status) &&
97
+ error.status >= 400 && error.status <= 599 ? error.status : undefined;
94
98
  yield* retainedEventsWithIdentity([{
95
99
  type: "status",
96
- data: { status: cancelled ? "cancelled" : "failed", error: message },
100
+ data: {
101
+ status: cancelled ? "cancelled" : "failed",
102
+ error: message,
103
+ ...(code === undefined ? {} : { errorCode: code }),
104
+ ...(status === undefined ? {} : { statusCode: status }),
105
+ },
97
106
  normalized: {
98
107
  type: "status",
99
108
  status: cancelled ? "cancelled" : "failed",
@@ -147,6 +156,8 @@ export async function* streamCliBridgeTurn(options, turn, requestBody, transport
147
156
  data: {
148
157
  ...identityData,
149
158
  ...(nextModelRequests === undefined ? {} : { modelRequests: nextModelRequests }),
159
+ // The Bridge estimates counters for a CLI that reported none; they are not measured tokens.
160
+ ...(rawUsage?.estimated === true ? { tokensKnown: false } : {}),
150
161
  },
151
162
  ...(nextUsage ? { usage: nextUsage } : {}),
152
163
  usageMode: "delta",
@@ -384,6 +395,7 @@ async function* finishCliBridgeStream([options, turn, requestBody, transport, ru
384
395
  ...(finalModelRequests === undefined
385
396
  ? {}
386
397
  : { modelRequests: finalModelRequests }),
398
+ ...(result.providerUsage?.estimated === true ? { tokensKnown: false } : {}),
387
399
  },
388
400
  ...(result.usage ? { usage: result.usage } : {}),
389
401
  ...(result.providerUsage ? { usageMode: "cumulative" } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-cli-bridge",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "AgentEnvironmentProvider adapter for cli-bridge retained sessions and one-shot turns",
5
5
  "type": "module",
6
6
  "license": "MIT",