@tangle-network/agent-provider-cli-bridge 0.11.0 → 0.11.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 CHANGED
@@ -85,6 +85,8 @@ The returned `AgentSession` exposes status, cursor-based event replay, the termi
85
85
  Cancellation returns only after cli-bridge confirms the run is terminal.
86
86
  A direct stream treats a finish frame as provisional until cli-bridge returns the same run's aggregate result.
87
87
  A retained replay confirms its terminal state from the retained run endpoint.
88
+ Terminal results retain the newest 1,024 events and preserve full text and usage totals.
89
+ Use `session.events()` when a caller needs the complete retained event history.
88
90
  Retained native runs use canonical runtime envelopes and finish with a terminal status event.
89
91
  Pass any emitted event `id` back as `since` to resume after that event.
90
92
  The canonical envelope identity remains available as `event.data.eventId`.
@@ -1,4 +1,4 @@
1
- import type { TokenUsage } from "@tangle-network/agent-interface";
1
+ import { type TokenUsage } from "@tangle-network/agent-interface";
2
2
  import type { AgentEnvironmentEvent, AgentSessionRef, AgentTurnResult, CreateAgentEnvironmentInput } from "@tangle-network/agent-interface/environment-provider";
3
3
  import type { CliBridgeProviderOptions } from "./provider-options.js";
4
4
  import { type CliBridgeRun, type CliBridgeSessionState, type PreparedCliBridgeRun } from "./retained-run-state.js";
@@ -1,3 +1,4 @@
1
+ import { AgentTurnResultSchema, } from "@tangle-network/agent-interface";
1
2
  import { cancelCliBridgeRun, captureCliBridgeRunIdentity, cliBridgeCancellationSignal, detachCliBridgeReader, getCliBridgeRun, } from "./retained-control.js";
2
3
  import { bindCliBridgeRun, bindCliBridgeSession, exactControlRefForRun, restoreCliBridgeRun, restoreCliBridgeSession, } from "./retained-run-state.js";
3
4
  import { CliBridgeRequestRejectedError, streamCliBridgeTurn, } from "./retained-stream.js";
@@ -5,6 +6,7 @@ import { beginCliBridgeNativeTurn, } from "./retained-native.js";
5
6
  import { MAX_CLI_BRIDGE_CONTROL_RESPONSE_BYTES, readBoundedCliBridgeResponse, requestHeaders, trimSlash, } from "./transport.js";
6
7
  import { modelRequestCount } from "./wire.js";
7
8
  import { lookupCliBridgeContext } from "./context-transfer.js";
9
+ const MAX_CLI_BRIDGE_RESULT_EVENTS = 1_024;
8
10
  export async function* streamTrackedCliBridgeTurn(options, environmentInput, providerName, prepared, transport, runs, sessions, readers, nativeSessions, useNativeInteractions) {
9
11
  const originalTurn = prepared.turn;
10
12
  if (originalTurn.detach) {
@@ -252,6 +254,7 @@ function assertCanonicalEventBinding(event, run, providerName) {
252
254
  }
253
255
  export async function collectCliBridgeTurnResult(source, run, options, transport, signal) {
254
256
  const events = [];
257
+ let eventCount = 0;
255
258
  let text = "";
256
259
  let usage;
257
260
  let observedModelRequests = 0;
@@ -262,7 +265,11 @@ export async function collectCliBridgeTurnResult(source, run, options, transport
262
265
  let streamError;
263
266
  try {
264
267
  for await (const event of source) {
265
- events.push(event);
268
+ if (eventCount < MAX_CLI_BRIDGE_RESULT_EVENTS)
269
+ events.push(event);
270
+ else
271
+ events[eventCount % MAX_CLI_BRIDGE_RESULT_EVENTS] = event;
272
+ eventCount += 1;
266
273
  const finalText = event.data.finalText;
267
274
  if (typeof finalText === "string") {
268
275
  text = finalText;
@@ -307,7 +314,13 @@ export async function collectCliBridgeTurnResult(source, run, options, transport
307
314
  throw new Error(`cli-bridge run "${run.id}" has no terminal result`);
308
315
  }
309
316
  const success = snapshot.status === "done" && streamError === undefined;
310
- return {
317
+ const resultEvents = eventCount <= MAX_CLI_BRIDGE_RESULT_EVENTS
318
+ ? events
319
+ : [
320
+ ...events.slice(eventCount % MAX_CLI_BRIDGE_RESULT_EVENTS),
321
+ ...events.slice(0, eventCount % MAX_CLI_BRIDGE_RESULT_EVENTS),
322
+ ];
323
+ return AgentTurnResultSchema.parse({
311
324
  text,
312
325
  success,
313
326
  ...(!success
@@ -335,8 +348,8 @@ export async function collectCliBridgeTurnResult(source, run, options, transport
335
348
  ...(servedModel === undefined ? {} : { model: servedModel }),
336
349
  ...(systemFingerprint === undefined ? {} : { system_fingerprint: systemFingerprint }),
337
350
  },
338
- events,
339
- };
351
+ events: resultEvents,
352
+ });
340
353
  }
341
354
  /** Keep reasoning and tool updates out of the assistant's visible result text. */
342
355
  export function visibleTextDelta(event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-cli-bridge",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "AgentEnvironmentProvider adapter for cli-bridge retained sessions and one-shot turns",
5
5
  "type": "module",
6
6
  "license": "MIT",