@yeaft/webchat-agent 0.1.955 → 0.1.957

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": "0.1.955",
3
+ "version": "0.1.957",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -56,6 +56,7 @@ export function createRouter(deps = {}) {
56
56
  * taskId?: string|null,
57
57
  * inboundEnvelope?: any, // the envelope the sender is currently handling
58
58
  * // (drives causedBy chain & loop guard)
59
+ * sourceThreadId?: string|null, // sender-side thread that should own the visible forward row
59
60
  * }} args
60
61
  * @param {{ taskMembers?: string[] }} [opts] — forwarded to coordinator.ingest
61
62
  * @returns {{
@@ -148,6 +149,9 @@ export function createRouter(deps = {}) {
148
149
  senderVpId: from,
149
150
  reason: args.reason || null,
150
151
  causedBy: chain,
152
+ sourceThreadId: typeof args.sourceThreadId === 'string' && args.sourceThreadId.trim()
153
+ ? args.sourceThreadId.trim()
154
+ : null,
151
155
  },
152
156
  },
153
157
  opts,
@@ -95,6 +95,7 @@ Returns JSON: { ok, dispatched?, error?, detail? }.`,
95
95
  reason: reason || null,
96
96
  taskId: ctx.taskId ?? null,
97
97
  inboundEnvelope: ctx.inboundEnvelope ?? null,
98
+ sourceThreadId: ctx.threadId ?? null,
98
99
  },
99
100
  { taskMembers: ctx.taskMembers },
100
101
  );
@@ -356,6 +356,18 @@ function buildVpPromptPayload(vpId, envelope) {
356
356
  return { text, prompt, promptParts };
357
357
  }
358
358
 
359
+ export function visibleInboundThreadId(envelope, fallbackThreadId = 'main') {
360
+ const meta = envelope?.msg?.meta || {};
361
+ if (
362
+ meta.injectedBy === 'route_forward'
363
+ && typeof meta.sourceThreadId === 'string'
364
+ && meta.sourceThreadId.trim()
365
+ ) {
366
+ return meta.sourceThreadId.trim();
367
+ }
368
+ return fallbackThreadId || 'main';
369
+ }
370
+
359
371
  function threadSnapshotForClassifier(thread) {
360
372
  return {
361
373
  threadId: thread.threadId,
@@ -833,6 +845,13 @@ export function __testGetVpThreads(sessionId, vpId) {
833
845
  }));
834
846
  }
835
847
 
848
+ /** Test-only: seed a VP thread without starting its engine driver. */
849
+ export function __testSeedVpThread({ sessionId, vpId, threadId, title = 'test thread', status = 'queued' }) {
850
+ const thread = getOrCreateVpThread({ sessionId, vpId, threadId, title });
851
+ thread.status = status;
852
+ return thread.threadId;
853
+ }
854
+
836
855
  /** Test-only: wait for thread classification/routing spawned by a msg id. */
837
856
  export async function __testWaitForRoutePromises(msgId) {
838
857
  await waitForRoutePromises(msgId);
@@ -1016,7 +1035,7 @@ async function routeEnvelopeToVpThread(sessionId, vpId, envelope) {
1016
1035
  msgId: envelope?.msg?.id,
1017
1036
  text,
1018
1037
  sessionId,
1019
- threadId: thread.threadId,
1038
+ threadId: visibleInboundThreadId(envelope, thread.threadId),
1020
1039
  role: envelope?.msg?.meta?.injectedBy === 'route_forward' ? 'assistant' : 'user',
1021
1040
  speakerVpId: envelope?.msg?.meta?.senderVpId || envelope?.msg?.from || null,
1022
1041
  attachments: Array.isArray(envelope?.msg?.meta?.attachments) ? envelope.msg.meta.attachments : [],
@@ -1109,7 +1128,7 @@ function ensureDriverRunning(sessionId, vpId, threadId = 'main') {
1109
1128
  msgId: envMsgId,
1110
1129
  text,
1111
1130
  sessionId,
1112
- threadId: thread.threadId,
1131
+ threadId: visibleInboundThreadId(envelope, thread.threadId),
1113
1132
  role: isForward ? 'assistant' : 'user',
1114
1133
  speakerVpId: senderVpId,
1115
1134
  attachments: Array.isArray(meta.attachments) ? meta.attachments : [],