@sema-agent/core 1.439.0 → 1.440.0

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.
@@ -1,7 +1,12 @@
1
1
  import { DEFAULT_CHARS_PER_TOKEN, estimateContextTokens, estimateTokens } from "../internal/harness.js";
2
2
  import { isToolResult } from "./message-utils.js";
3
3
  const CLEARED_MARKER = "[tool result cleared to save context]";
4
- const clearedWithRef = (ref) => `[tool result cleared to save context — full content persisted; call ReadToolResult with ref "${ref}" to read it back]`;
4
+ const refNote = (ref) => `full text persisted; call ReadToolResult with ref "${ref}" to read it back`;
5
+ const mediaNote = (n) => `${n} attachment${n === 1 ? "" : "s"} no longer visible after this clear`;
6
+ const clearedMarker = (notes) => {
7
+ const present = notes.filter((n) => n !== undefined);
8
+ return present.length > 0 ? `[tool result cleared to save context — ${present.join("; ")}]` : CLEARED_MARKER;
9
+ };
5
10
  export const EDIT_FRACTION = 0.7;
6
11
  export const CONTEXT_OUTPUT_RESERVE_TOKENS = 20000;
7
12
  export const COMPACTION_TRIGGER_BUFFER_TOKENS = 13000;
@@ -69,24 +74,25 @@ export function clearStaleToolResults(messages, opts) {
69
74
  break;
70
75
  }
71
76
  const before = estimateTokens(out[idx], cpt);
72
- let marker = CLEARED_MARKER;
77
+ const msg = out[idx];
78
+ const rawContent = Array.isArray(msg.content) ? msg.content : [];
79
+ let ref;
73
80
  if (opts.offload) {
74
- const msg = out[idx];
75
- const fullText = Array.isArray(msg.content)
76
- ? msg.content
77
- .filter((c) => c?.type === "text" && typeof c.text === "string")
78
- .map((c) => c.text)
79
- .join("\n")
80
- : "";
81
+ const fullText = rawContent
82
+ .filter((c) => c?.type === "text" && typeof c.text === "string")
83
+ .map((c) => c.text)
84
+ .join("\n");
81
85
  if (msg.toolCallId && fullText.trim().length > 0) {
82
86
  try {
83
- marker = clearedWithRef(opts.offload.persist(msg.toolCallId, fullText));
87
+ ref = refNote(opts.offload.persist(msg.toolCallId, fullText));
84
88
  }
85
89
  catch {
86
- marker = CLEARED_MARKER;
90
+ ref = undefined;
87
91
  }
88
92
  }
89
93
  }
94
+ const mediaCount = rawContent.filter((c) => c?.type !== "text").length;
95
+ const marker = clearedMarker([ref, mediaCount > 0 ? mediaNote(mediaCount) : undefined]);
90
96
  const cleared = {
91
97
  ...out[idx],
92
98
  content: [{ type: "text", text: marker }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/core",
3
- "version": "1.439.0",
3
+ "version": "1.440.0",
4
4
  "description": "Stateless, task-oriented AI agent core",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",