shennian 0.2.58 → 0.2.60

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.
@@ -471,12 +471,12 @@ export class PiAdapter extends AgentAdapter {
471
471
  return;
472
472
  this.terminalState = 'error';
473
473
  const message = err instanceof Error ? err.message : String(err);
474
- if (message.includes('429') || message.includes('daily_quota_exceeded')) {
474
+ if (message.includes('429') || message.includes('daily_quota_exceeded') || message.includes('nian_quota_exceeded')) {
475
475
  this.emit('agentEvent', {
476
476
  state: 'error',
477
477
  runId,
478
478
  seq: ++this.seq,
479
- message: '今日免费额度已用完,可在 ~/.shennian/config.json 中配置 apiKey 字段(兼容 OpenAI 格式)继续使用。',
479
+ message: 'Nian 今日额度已用完,次日自动恢复。',
480
480
  });
481
481
  }
482
482
  else {
@@ -257,7 +257,7 @@ export class ManagerRegistry {
257
257
  function readableText(message) {
258
258
  if (!message || isToolPayload(message.payload))
259
259
  return null;
260
- const text = extractPayloadText(message.payload).replace(/\s+/g, ' ').trim();
260
+ const text = extractPayloadText(message.payload).replace(/\r\n/g, '\n').trim();
261
261
  return text || null;
262
262
  }
263
263
  function clip(text, max) {
@@ -29,6 +29,16 @@ function runIdFromMessageId(id) {
29
29
  const match = /^agent-(.+)-\d+$/.exec(id);
30
30
  return match?.[1] ?? null;
31
31
  }
32
+ function seqFromMessageId(id) {
33
+ const match = /^agent-.+-(\d+)$/.exec(id);
34
+ if (!match)
35
+ return null;
36
+ const seq = Number(match[1]);
37
+ return Number.isInteger(seq) && seq >= 0 ? seq : null;
38
+ }
39
+ function normalizeMarkdownForWorkerSummary(text) {
40
+ return text.replace(/\r\n/g, '\n').trim();
41
+ }
32
42
  function toolSummary(payload) {
33
43
  try {
34
44
  const parsed = JSON.parse(payload);
@@ -62,6 +72,7 @@ function compactWorkerTranscript(rawMessages, limit) {
62
72
  const compacted = [];
63
73
  let buffer = null;
64
74
  let bufferRunId = null;
75
+ let bufferSeq = null;
65
76
  let bufferText = '';
66
77
  const flush = () => {
67
78
  if (!buffer)
@@ -76,6 +87,7 @@ function compactWorkerTranscript(rawMessages, limit) {
76
87
  }
77
88
  buffer = null;
78
89
  bufferRunId = null;
90
+ bufferSeq = null;
79
91
  bufferText = '';
80
92
  };
81
93
  for (const message of chronological) {
@@ -96,14 +108,17 @@ function compactWorkerTranscript(rawMessages, limit) {
96
108
  if (!text.trim())
97
109
  continue;
98
110
  const runId = runIdFromMessageId(message.id);
99
- if (buffer && buffer.role === message.role && bufferRunId === runId) {
111
+ const seq = seqFromMessageId(message.id);
112
+ if (buffer && buffer.role === message.role && bufferRunId === runId && runId && seq !== null && bufferSeq !== null && seq === bufferSeq + 1) {
100
113
  bufferText += text;
101
114
  buffer.ts = message.ts;
115
+ bufferSeq = seq;
102
116
  }
103
117
  else {
104
118
  flush();
105
119
  buffer = message;
106
120
  bufferRunId = runId;
121
+ bufferSeq = seq;
107
122
  bufferText = text;
108
123
  }
109
124
  }
@@ -261,14 +276,14 @@ export class ManagerRuntimeService {
261
276
  if (event.state === 'delta' && event.text && !event.thinking) {
262
277
  const nextText = (this.workerTextAcc.get(textKey) ?? '') + event.text;
263
278
  this.workerTextAcc.set(textKey, nextText);
264
- const normalized = nextText.replace(/\s+/g, ' ').trim();
279
+ const normalized = normalizeMarkdownForWorkerSummary(nextText);
265
280
  if (normalized) {
266
281
  patch.summary = normalized.length > 160 ? `${normalized.slice(0, 160)}...` : normalized;
267
282
  }
268
283
  }
269
284
  if (event.state === 'final' || event.state === 'error' || event.state === 'aborted') {
270
285
  patch.status = event.state;
271
- const accumulated = this.workerTextAcc.get(textKey)?.replace(/\s+/g, ' ').trim();
286
+ const accumulated = normalizeMarkdownForWorkerSummary(this.workerTextAcc.get(textKey) ?? '');
272
287
  if (accumulated) {
273
288
  patch.summary = accumulated.length > 240 ? `${accumulated.slice(0, 240)}...` : accumulated;
274
289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shennian",
3
- "version": "0.2.58",
3
+ "version": "0.2.60",
4
4
  "description": "Shennian — AI Agent Control Plane CLI",
5
5
  "type": "module",
6
6
  "bin": {