@yeaft/webchat-agent 1.0.94 → 1.0.95

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.94",
3
+ "version": "1.0.95",
4
4
  "description": "Remote worker agent for Yeaft Web Code Agent — connects the native Yeaft engine, CLI providers, and workbench tools",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -168,9 +168,7 @@ function normalizeExtractedSegment({ item, scope, now }) {
168
168
  if (!body) return null;
169
169
  const kind = VALID_KINDS.has(String(item.kind || '')) ? String(item.kind) : 'context';
170
170
  const tags = Array.isArray(item.tags) ? item.tags.map(t => String(t).trim()).filter(Boolean) : [];
171
- const sourceMessages = Array.isArray(item.sourceMessages)
172
- ? item.sourceMessages.map(id => String(id).trim()).filter(Boolean)
173
- : [];
171
+ const sourceMessages = normalizeSourceMessageIds(item.sourceMessages);
174
172
  return makeSegment({
175
173
  scope,
176
174
  kind,
@@ -182,6 +180,23 @@ function normalizeExtractedSegment({ item, scope, now }) {
182
180
  });
183
181
  }
184
182
 
183
+ function normalizeSourceMessageIds(value) {
184
+ if (!Array.isArray(value)) return [];
185
+ const ids = [];
186
+ for (const item of value) {
187
+ if (typeof item === 'string' || typeof item === 'number') {
188
+ const id = String(item).trim();
189
+ if (id) ids.push(id);
190
+ continue;
191
+ }
192
+ if (item && typeof item === 'object') {
193
+ const id = String(item.id || item.messageId || item.uuid || '').trim();
194
+ if (id) ids.push(id);
195
+ }
196
+ }
197
+ return ids;
198
+ }
199
+
185
200
  function buildRecentSegment({ scope, messages, now }) {
186
201
  const recentMessages = messages.slice(-RECENT_MESSAGE_COUNT);
187
202
  const body = [
@@ -313,6 +313,24 @@ function normalizeSessionJsonlMessage(row, sessionId) {
313
313
  function stringifyMessageBody(value) {
314
314
  if (typeof value === 'string') return value;
315
315
  if (value == null) return '';
316
+ if (Array.isArray(value)) return value.map(stringifyMessageBody).filter(Boolean).join('\n');
317
+ if (typeof value === 'object') {
318
+ if (typeof value.text === 'string') return value.text;
319
+ if (typeof value.content === 'string') return value.content;
320
+ if (typeof value.body === 'string') return value.body;
321
+ if (typeof value.value === 'string') return value.value;
322
+ if (Array.isArray(value.content)) return stringifyMessageBody(value.content);
323
+ if (Array.isArray(value.parts)) return stringifyMessageBody(value.parts);
324
+ if (Array.isArray(value.blocks)) return stringifyMessageBody(value.blocks);
325
+ if (value.type && (value.type === 'image' || value.type === 'image_url')) return '[image]';
326
+ if (value.type && (value.type === 'tool_use' || value.type === 'tool_call')) {
327
+ const name = value.name || value.toolName || value.function?.name || 'tool';
328
+ return `[tool call: ${name}]`;
329
+ }
330
+ if (value.type && (value.type === 'tool_result' || value.type === 'function_result')) {
331
+ return stringifyMessageBody(value.result ?? value.output ?? value.content ?? '[tool result]');
332
+ }
333
+ }
316
334
  try { return JSON.stringify(value); } catch { return String(value); }
317
335
  }
318
336
 
@@ -93,9 +93,7 @@ export function makeSegment(raw) {
93
93
  const tags = Array.isArray(raw.tags)
94
94
  ? raw.tags.map(t => String(t).trim()).filter(Boolean)
95
95
  : [];
96
- const sourceMessages = Array.isArray(raw.sourceMessages)
97
- ? raw.sourceMessages.map(t => String(t).trim()).filter(Boolean)
98
- : [];
96
+ const sourceMessages = normalizeSourceMessages(raw.sourceMessages);
99
97
 
100
98
  const now = new Date().toISOString();
101
99
  const createdAt = raw.createdAt || now;
@@ -105,6 +103,23 @@ export function makeSegment(raw) {
105
103
  return { id, scope, kind, tags, sourceMessages, createdAt, updatedAt, body };
106
104
  }
107
105
 
106
+ function normalizeSourceMessages(value) {
107
+ if (!Array.isArray(value)) return [];
108
+ const out = [];
109
+ for (const item of value) {
110
+ if (typeof item === 'string' || typeof item === 'number') {
111
+ const id = String(item).trim();
112
+ if (id && id !== '[object Object]') out.push(id);
113
+ continue;
114
+ }
115
+ if (item && typeof item === 'object') {
116
+ const id = String(item.id || item.messageId || item.uuid || '').trim();
117
+ if (id) out.push(id);
118
+ }
119
+ }
120
+ return out;
121
+ }
122
+
108
123
  /**
109
124
  * Parse a memory.md text into segments. Tolerant by design:
110
125
  * - Empty / whitespace input → [].