@myagentroam/agent 0.11.66 → 0.11.68

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.
@@ -78,11 +78,33 @@ export function parseInlineMediaState(value) {
78
78
  /** Recover ordering once at the lifecycle boundary, including GC-omitted sources. */
79
79
  export function inlineMediaHistory(records) {
80
80
  const cursors = [];
81
+ const imageCounts = new Map();
81
82
  let rollouts = 0;
82
83
  let state;
84
+ const present = (cursor) => !cursor || cursor.imageIndex < (imageCounts.get(cursor.sourceId) ?? 0);
85
+ const restoreState = (next) => {
86
+ if (!next || (present(next.consideredThrough) && present(next.evictedThrough))) {
87
+ state = next;
88
+ return;
89
+ }
90
+ // Reuse only a proven eviction; record order cannot prove an image was processed.
91
+ const evictedThrough = present(next.evictedThrough)
92
+ ? next.evictedThrough
93
+ : state?.evictedThrough;
94
+ const consideredThrough = next.consideredThrough && present(next.consideredThrough)
95
+ ? next.consideredThrough
96
+ : evictedThrough;
97
+ state = {
98
+ version: 1,
99
+ ...(consideredThrough ? { consideredThrough } : {}),
100
+ ...(evictedThrough ? { evictedThrough } : {})
101
+ };
102
+ };
83
103
  const add = (sourceId, images) => {
84
104
  if (!sourceId || !Array.isArray(images))
85
105
  return;
106
+ if (images.length > (imageCounts.get(sourceId) ?? 0))
107
+ imageCounts.set(sourceId, images.length);
86
108
  for (let imageIndex = 0; imageIndex < images.length; imageIndex++)
87
109
  cursors.push({ sourceId, imageIndex, rollout: rollouts });
88
110
  };
@@ -96,7 +118,8 @@ export function inlineMediaHistory(records) {
96
118
  rollouts++;
97
119
  if (record.type === 'compact.completed') {
98
120
  cursors.splice(0);
99
- state = parseInlineMediaState(payload.inlineMediaState);
121
+ imageCounts.clear();
122
+ state = undefined;
100
123
  for (const item of (payload.retainedModelContext ?? [])) {
101
124
  const applied = appliedInputRecord({ ...record, type: 'model.context', payload: item });
102
125
  if (applied) {
@@ -106,15 +129,16 @@ export function inlineMediaHistory(records) {
106
129
  const key = inlineMediaSource(item);
107
130
  add(typeof key === 'string' ? key : undefined, item.images);
108
131
  }
132
+ restoreState(parseInlineMediaState(payload.inlineMediaState));
109
133
  }
110
134
  else if (record.type === 'resource.window') {
111
- state = parseInlineMediaState(payload);
135
+ restoreState(parseInlineMediaState(payload));
112
136
  }
113
137
  else if (record.type === 'context.gc.completed' && payload.inlineMedia !== undefined) {
114
138
  const media = parseInlineMediaGc(payload.inlineMedia);
115
139
  if (!media)
116
140
  throw new AgentError('MAR_AGENT_SESSION_CORRUPT', 'Inline media GC state is invalid.');
117
- state = media.state;
141
+ restoreState(media.state);
118
142
  }
119
143
  else if ((record.type === 'turn.user' || record.type === 'extension.input') &&
120
144
  payload.deferred !== true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.11.66",
3
+ "version": "0.11.68",
4
4
  "description": "Embeddable MAR coding agent SDK and CLI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",