@autotest/agent 0.0.4 → 0.0.5

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.
@@ -88,6 +88,37 @@ function summarizeMessageContent(content) {
88
88
  });
89
89
  return `[${summaries.join(' | ')}]`;
90
90
  }
91
+ const MAX_IMAGES_PER_REQUEST = 3;
92
+ function capImagesInMessages(messages) {
93
+ const imagePositions = [];
94
+ for (let i = 0; i < messages.length; i++) {
95
+ const content = messages[i].content;
96
+ if (Array.isArray(content)) {
97
+ for (let j = 0; j < content.length; j++) {
98
+ const part = content[j];
99
+ if (part && typeof part === 'object') {
100
+ const type = part.type;
101
+ if (type === 'image_url' || type === 'image' || type === 'file') {
102
+ imagePositions.push([i, j]);
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+ if (imagePositions.length <= MAX_IMAGES_PER_REQUEST)
109
+ return messages;
110
+ const toRemove = new Set(imagePositions.slice(0, imagePositions.length - MAX_IMAGES_PER_REQUEST).map(([i, j]) => `${i},${j}`));
111
+ if (toRemove.size === 0)
112
+ return messages;
113
+ logger_1.logger.warn(`LLMCaller: capping ${imagePositions.length} images to ${MAX_IMAGES_PER_REQUEST} (removing ${toRemove.size} oldest)`);
114
+ return messages.map((msg, i) => {
115
+ const content = msg.content;
116
+ if (!Array.isArray(content))
117
+ return msg;
118
+ const newContent = content.filter((_, j) => !toRemove.has(`${i},${j}`));
119
+ return { ...msg, content: newContent };
120
+ });
121
+ }
91
122
  class LLMCaller {
92
123
  cacheTransport;
93
124
  recordingFetch;
@@ -205,6 +236,10 @@ class LLMCaller {
205
236
  return crypto.createHash('sha256').update(raw).digest('hex');
206
237
  }
207
238
  async call(opts) {
239
+ if (opts.images && opts.images.length > MAX_IMAGES_PER_REQUEST) {
240
+ logger_1.logger.warn(`LLMCaller: capping ${opts.images.length} images to ${MAX_IMAGES_PER_REQUEST}`);
241
+ opts = { ...opts, images: opts.images.slice(-MAX_IMAGES_PER_REQUEST) };
242
+ }
208
243
  const cacheKey = this.computeCacheKey(opts);
209
244
  const cached = await this.cacheTransport.getCachedResponse(cacheKey);
210
245
  if (cached) {
@@ -374,6 +409,10 @@ class LLMCaller {
374
409
  const model = provider.chat(opts.modelConfig.name);
375
410
  const tokenType = (0, token_usage_1.resolveTokenType)(opts.modelConfig.baseUrl);
376
411
  logger_1.logger.debug(`LLM callWithMessages() input → model=${opts.modelConfig.name} messages=${opts.messages.length}`);
412
+ const cappedMessages = capImagesInMessages(opts.messages);
413
+ if (cappedMessages !== opts.messages) {
414
+ opts = { ...opts, messages: cappedMessages };
415
+ }
377
416
  for (const m of opts.messages) {
378
417
  const content = typeof m.content === 'string'
379
418
  ? m.content
@@ -105,6 +105,7 @@ class GeneralAgent extends base_agent_1.BaseAgent {
105
105
  const textContent = `** Screen Info **\n\n${screenInfo}`;
106
106
  this._context.push(message_builder_1.MessageBuilder.createUserMessage(textContent, screenshot.base64Data));
107
107
  }
108
+ this.manageHistoryImages(this.agentConfig.maxHistoryImage);
108
109
  let thinking = '';
109
110
  let content = '';
110
111
  let rawContent = '';
@@ -141,7 +142,6 @@ class GeneralAgent extends base_agent_1.BaseAgent {
141
142
  stepNumber: this._stepCount,
142
143
  }));
143
144
  }
144
- this.manageHistoryImages(this.agentConfig.maxHistoryImage);
145
145
  this._context.push(message_builder_1.MessageBuilder.createAssistantMessage(rawContent));
146
146
  let result;
147
147
  try {
@@ -57,6 +57,14 @@ const agent_api_1 = require("../api/agent_api");
57
57
  const manager_1 = require("../common/config/manager");
58
58
  const adapter_factory_1 = require("../core/mcp/adapter_factory");
59
59
  const logger_1 = require("../common/logger");
60
+ // EPIPE resilience: when stdout/stderr is a pipe whose read end closed (e.g. the
61
+ // spawning parent process died), writes would throw EPIPE and crash this (detached)
62
+ // batch_runner. Swallow EPIPE so it keeps running — writing per-case agent logs +
63
+ // summary.json — and stays pollable via --status. Other errors still propagate.
64
+ process.stdout.on('error', (err) => { if (err && (err.code === 'EPIPE' || err.code === 'ERR_STREAM_DESTROYED'))
65
+ return; throw err; });
66
+ process.stderr.on('error', (err) => { if (err && (err.code === 'EPIPE' || err.code === 'ERR_STREAM_DESTROYED'))
67
+ return; throw err; });
60
68
  const UTF_8 = 'utf-8';
61
69
  const CASE_TIMEOUT_MS = 10 * 60 * 1000;
62
70
  const PROGRESS_REPORT_INTERVAL = 10;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autotest/agent",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "AutoTest Agent — AI 驱动的自动化测试执行代理,支持 HarmonyOS/Android/iOS",
6
6
  "license": "MIT",