@yeaft/webchat-agent 0.1.863 → 0.1.864
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 +1 -1
- package/yeaft/web-bridge.js +54 -22
package/package.json
CHANGED
package/yeaft/web-bridge.js
CHANGED
|
@@ -1717,6 +1717,32 @@ function chatErrorPayload(err) {
|
|
|
1717
1717
|
};
|
|
1718
1718
|
}
|
|
1719
1719
|
|
|
1720
|
+
/**
|
|
1721
|
+
* Build the vpPersona payload threaded into engine.query so the worker
|
|
1722
|
+
* system prompt carries the VP's identity/role/persona/planInstruction.
|
|
1723
|
+
* Returns null on miss — callers treat that as "use generic prompt".
|
|
1724
|
+
* Shared by handleYeaftChatSend and the group fan-out path so the field
|
|
1725
|
+
* set stays in lockstep.
|
|
1726
|
+
*/
|
|
1727
|
+
function buildVpPersona(vpId) {
|
|
1728
|
+
if (!vpId) return null;
|
|
1729
|
+
try {
|
|
1730
|
+
const vp = readVp(vpId);
|
|
1731
|
+
if (!vp) return null;
|
|
1732
|
+
return {
|
|
1733
|
+
vpId,
|
|
1734
|
+
displayName: vp.displayName || vpId,
|
|
1735
|
+
displayNameZh: vp.displayNameZh || '',
|
|
1736
|
+
role: vp.role || '',
|
|
1737
|
+
roleZh: vp.roleZh || '',
|
|
1738
|
+
persona: vp.persona || '',
|
|
1739
|
+
planInstruction: typeof vp.planInstruction === 'string' ? vp.planInstruction : '',
|
|
1740
|
+
};
|
|
1741
|
+
} catch {
|
|
1742
|
+
return null;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1720
1746
|
export function handleYeaftListChats(msg) {
|
|
1721
1747
|
const requestId = msg && msg.requestId;
|
|
1722
1748
|
try {
|
|
@@ -1729,19 +1755,34 @@ export function handleYeaftListChats(msg) {
|
|
|
1729
1755
|
|
|
1730
1756
|
export function handleYeaftCreateChat(msg) {
|
|
1731
1757
|
const requestId = msg && msg.requestId;
|
|
1758
|
+
// Accept fields at top-level (current wire shape) AND inside `payload`
|
|
1759
|
+
// (legacy / future) — keeps backwards compatibility cheap.
|
|
1760
|
+
const top = msg || {};
|
|
1732
1761
|
const payload = (msg && msg.payload) || {};
|
|
1762
|
+
const displayName = payload.displayName || top.displayName;
|
|
1763
|
+
const workDir = payload.workDir || top.workDir;
|
|
1764
|
+
const explicitId = payload.id || top.id;
|
|
1765
|
+
// Chat mode is 1:1 with the built-in Omni assistant by default. The
|
|
1766
|
+
// VP picker is gone from the UI; callers may still override vpId to
|
|
1767
|
+
// bind a chat to a specialist, but the default is omni.
|
|
1768
|
+
const vpId = payload.vpId || top.vpId || 'omni';
|
|
1733
1769
|
try {
|
|
1734
1770
|
const yeaftDir = ctx.CONFIG?.yeaftDir;
|
|
1735
1771
|
if (!yeaftDir) throw new Error('no yeaft directory configured');
|
|
1736
|
-
if
|
|
1772
|
+
// Fail loud at create time if the requested VP (default: omni) is
|
|
1773
|
+
// not installed — otherwise the chat would silently degrade to a
|
|
1774
|
+
// generic prompt at first send.
|
|
1775
|
+
if (!buildVpPersona(vpId)) {
|
|
1776
|
+
throw new Error(`VP '${vpId}' is not installed`);
|
|
1777
|
+
}
|
|
1737
1778
|
const root = chatsRootFor(yeaftDir);
|
|
1738
|
-
const chatId = (
|
|
1779
|
+
const chatId = (explicitId && String(explicitId).trim())
|
|
1739
1780
|
|| `chat_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
1740
1781
|
const h = createChatStore(root, {
|
|
1741
1782
|
id: chatId,
|
|
1742
|
-
vpId
|
|
1743
|
-
displayName
|
|
1744
|
-
workDir
|
|
1783
|
+
vpId,
|
|
1784
|
+
displayName,
|
|
1785
|
+
workDir,
|
|
1745
1786
|
});
|
|
1746
1787
|
const meta = h.getMeta();
|
|
1747
1788
|
h.close();
|
|
@@ -1954,6 +1995,11 @@ export async function handleYeaftChatSend(msg) {
|
|
|
1954
1995
|
appendedUserPrompts,
|
|
1955
1996
|
};
|
|
1956
1997
|
|
|
1998
|
+
// Load the VP persona (defaults to omni) so the engine's worker
|
|
1999
|
+
// prompt has the right identity/role/persona blocks. Without this,
|
|
2000
|
+
// chat mode runs with a generic system prompt instead of Omni.
|
|
2001
|
+
const vpPersona = buildVpPersona(vpId);
|
|
2002
|
+
|
|
1957
2003
|
for await (const event of eng.query({
|
|
1958
2004
|
prompt: text,
|
|
1959
2005
|
promptParts: attachmentBundle.promptParts && attachmentBundle.promptParts.length > 0 ? attachmentBundle.promptParts : null,
|
|
@@ -1961,6 +2007,7 @@ export async function handleYeaftChatSend(msg) {
|
|
|
1961
2007
|
userAlreadyPersisted: false,
|
|
1962
2008
|
threadId: 'main',
|
|
1963
2009
|
senderVpId: vpId,
|
|
2010
|
+
vpPersona,
|
|
1964
2011
|
})) {
|
|
1965
2012
|
resetQueryTimer();
|
|
1966
2013
|
handleEngineEvent(event, handlerCtx);
|
|
@@ -2760,23 +2807,8 @@ export function buildVpQueryOpts({ vpId, groupCoordinator, groupId, envelope, th
|
|
|
2760
2807
|
if (groupMeta && typeof groupMeta.workDir === 'string' && groupMeta.workDir.trim()) {
|
|
2761
2808
|
out.workDir = groupMeta.workDir.trim();
|
|
2762
2809
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
if (vp) {
|
|
2766
|
-
out.vpPersona = {
|
|
2767
|
-
vpId: resolvedVpId,
|
|
2768
|
-
displayName: vp.displayName || resolvedVpId,
|
|
2769
|
-
displayNameZh: vp.displayNameZh || '',
|
|
2770
|
-
role: vp.role || '',
|
|
2771
|
-
roleZh: vp.roleZh || '',
|
|
2772
|
-
persona: vp.persona || '',
|
|
2773
|
-
// Optional per-VP planning style for the `StartPlan` tool. Empty
|
|
2774
|
-
// string means "fall back to the default template" — the tool
|
|
2775
|
-
// handles the lookup so callers stay ignorant of the default.
|
|
2776
|
-
planInstruction: typeof vp.planInstruction === 'string' ? vp.planInstruction : '',
|
|
2777
|
-
};
|
|
2778
|
-
}
|
|
2779
|
-
} catch { /* persona load is best-effort */ }
|
|
2810
|
+
const persona = buildVpPersona(resolvedVpId);
|
|
2811
|
+
if (persona) out.vpPersona = persona;
|
|
2780
2812
|
if (groupCoordinator && typeof groupCoordinator.ingest === 'function') {
|
|
2781
2813
|
try {
|
|
2782
2814
|
out.router = createRouter({ coordinator: groupCoordinator });
|