@yeaft/webchat-agent 0.1.399 → 0.1.409
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/crew/role-query.js +10 -6
- package/package.json +3 -1
- package/sdk/query.js +3 -1
- package/unify/cli.js +735 -0
- package/unify/config.js +269 -0
- package/unify/conversation/persist.js +436 -0
- package/unify/conversation/search.js +65 -0
- package/unify/debug-trace.js +398 -0
- package/unify/engine.js +511 -0
- package/unify/index.js +27 -0
- package/unify/init.js +147 -0
- package/unify/llm/adapter.js +186 -0
- package/unify/llm/anthropic.js +322 -0
- package/unify/llm/chat-completions.js +315 -0
- package/unify/memory/consolidate.js +187 -0
- package/unify/memory/extract.js +97 -0
- package/unify/memory/recall.js +243 -0
- package/unify/memory/store.js +507 -0
- package/unify/models.js +167 -0
- package/unify/prompts.js +109 -0
package/unify/prompts.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* prompts.js — Bilingual system prompt templates
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for system prompts. Both engine.js and cli.js
|
|
5
|
+
* import buildSystemPrompt() from here. Supports 'en' and 'zh'.
|
|
6
|
+
*
|
|
7
|
+
* Phase 2 additions:
|
|
8
|
+
* - Memory section (user profile + recalled entries)
|
|
9
|
+
* - Compact summary section (conversation history summary)
|
|
10
|
+
*
|
|
11
|
+
* Reference: yeaft-unify-system-prompt-budget.md — Static + Dynamic + Context layers
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// ─── Prompt Templates ─────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
const PROMPTS = {
|
|
17
|
+
en: {
|
|
18
|
+
identity: 'You are Yeaft, a helpful AI assistant.',
|
|
19
|
+
mode: (mode) => `Current mode: ${mode}`,
|
|
20
|
+
date: (d) => `Date: ${d}`,
|
|
21
|
+
work: 'You are in work mode. Break tasks into steps, execute them using tools, and report progress.',
|
|
22
|
+
dream: 'You are in dream mode. Reflect on past conversations and consolidate memories.',
|
|
23
|
+
tools: (names) => `Available tools: ${names}`,
|
|
24
|
+
memoryHeader: '## User Memory',
|
|
25
|
+
profileHeader: '### User Profile',
|
|
26
|
+
recalledHeader: '### Recalled Memories',
|
|
27
|
+
compactHeader: '## Conversation History Summary',
|
|
28
|
+
},
|
|
29
|
+
zh: {
|
|
30
|
+
identity: '你是 Yeaft,一个有用的 AI 助手。',
|
|
31
|
+
mode: (mode) => `当前模式:${mode}`,
|
|
32
|
+
date: (d) => `日期:${d}`,
|
|
33
|
+
work: '你处于工作模式。将任务分解为步骤,使用工具执行,并报告进度。',
|
|
34
|
+
dream: '你处于梦境模式。回顾过去的对话,整理和巩固记忆。',
|
|
35
|
+
tools: (names) => `可用工具:${names}`,
|
|
36
|
+
memoryHeader: '## 用户记忆',
|
|
37
|
+
profileHeader: '### 用户画像',
|
|
38
|
+
recalledHeader: '### 相关记忆',
|
|
39
|
+
compactHeader: '## 对话历史摘要',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Supported language codes. */
|
|
44
|
+
export const SUPPORTED_LANGUAGES = Object.keys(PROMPTS);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Build the system prompt for a given language and mode.
|
|
48
|
+
*
|
|
49
|
+
* @param {{
|
|
50
|
+
* language?: string,
|
|
51
|
+
* mode?: string,
|
|
52
|
+
* toolNames?: string[],
|
|
53
|
+
* memory?: { profile?: string, entries?: object[] },
|
|
54
|
+
* compactSummary?: string
|
|
55
|
+
* }} params
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
export function buildSystemPrompt({
|
|
59
|
+
language = 'en',
|
|
60
|
+
mode = 'chat',
|
|
61
|
+
toolNames = [],
|
|
62
|
+
memory,
|
|
63
|
+
compactSummary,
|
|
64
|
+
} = {}) {
|
|
65
|
+
// Fallback to English for unknown languages
|
|
66
|
+
const lang = PROMPTS[language] || PROMPTS.en;
|
|
67
|
+
|
|
68
|
+
const parts = [
|
|
69
|
+
lang.identity,
|
|
70
|
+
lang.mode(mode),
|
|
71
|
+
lang.date(new Date().toISOString().split('T')[0]),
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
if (mode === 'work') {
|
|
75
|
+
parts.push(lang.work);
|
|
76
|
+
} else if (mode === 'dream') {
|
|
77
|
+
parts.push(lang.dream);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (toolNames.length > 0) {
|
|
81
|
+
parts.push(lang.tools(toolNames.join(', ')));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ─── Memory Section ─────────────────────────────────────
|
|
85
|
+
if (memory && (memory.profile || (memory.entries && memory.entries.length > 0))) {
|
|
86
|
+
const memoryParts = [lang.memoryHeader];
|
|
87
|
+
|
|
88
|
+
if (memory.profile) {
|
|
89
|
+
memoryParts.push(`${lang.profileHeader}\n${memory.profile}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (memory.entries && memory.entries.length > 0) {
|
|
93
|
+
const entryLines = memory.entries.map(e => {
|
|
94
|
+
const tags = (e.tags && e.tags.length > 0) ? ` [${e.tags.join(', ')}]` : '';
|
|
95
|
+
return `- **${e.name}** (${e.kind}): ${e.content}${tags}`;
|
|
96
|
+
});
|
|
97
|
+
memoryParts.push(`${lang.recalledHeader}\n${entryLines.join('\n')}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
parts.push(memoryParts.join('\n\n'));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ─── Compact Summary Section ────────────────────────────
|
|
104
|
+
if (compactSummary) {
|
|
105
|
+
parts.push(`${lang.compactHeader}\n${compactSummary}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return parts.join('\n\n');
|
|
109
|
+
}
|