@yeaft/webchat-agent 0.1.479 → 0.1.480
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/unify/engine.js +9 -7
- package/unify/prompts.js +18 -21
- package/unify/tools/registry.js +14 -36
- package/unify/web-bridge.js +10 -13
package/package.json
CHANGED
package/unify/engine.js
CHANGED
|
@@ -141,14 +141,16 @@ export class Engine {
|
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* Get the list of registered tool definitions (for passing to the adapter).
|
|
144
|
-
* Prefers ToolRegistry
|
|
144
|
+
* Prefers ToolRegistry when available, falls back to legacy #tools Map.
|
|
145
|
+
*
|
|
146
|
+
* task-297: mode-based filtering was removed — all registered tools are
|
|
147
|
+
* always exposed to the LLM.
|
|
145
148
|
*
|
|
146
|
-
* @param {string} [mode]
|
|
147
149
|
* @returns {import('./llm/adapter.js').UnifiedToolDef[]}
|
|
148
150
|
*/
|
|
149
|
-
#getToolDefs(
|
|
151
|
+
#getToolDefs() {
|
|
150
152
|
if (this.#toolRegistry) {
|
|
151
|
-
return this.#toolRegistry.getToolDefs(
|
|
153
|
+
return this.#toolRegistry.getToolDefs();
|
|
152
154
|
}
|
|
153
155
|
// Legacy path: no mode filtering
|
|
154
156
|
const defs = [];
|
|
@@ -181,7 +183,7 @@ export class Engine {
|
|
|
181
183
|
|
|
182
184
|
// Get tool names from the appropriate source
|
|
183
185
|
const toolNames = this.#toolRegistry
|
|
184
|
-
? this.#toolRegistry.getToolNames(
|
|
186
|
+
? this.#toolRegistry.getToolNames()
|
|
185
187
|
: Array.from(this.#tools.keys());
|
|
186
188
|
|
|
187
189
|
return buildSystemPrompt({
|
|
@@ -339,7 +341,7 @@ export class Engine {
|
|
|
339
341
|
* @param {{ prompt: string, mode?: string, messages?: Array, signal?: AbortSignal }} params
|
|
340
342
|
* @yields {EngineEvent}
|
|
341
343
|
*/
|
|
342
|
-
async *query({ prompt, mode
|
|
344
|
+
async *query({ prompt, mode, messages = [], signal }) {
|
|
343
345
|
if (!prompt || typeof prompt !== 'string' || !prompt.trim()) {
|
|
344
346
|
yield {
|
|
345
347
|
type: 'error',
|
|
@@ -380,7 +382,7 @@ export class Engine {
|
|
|
380
382
|
{ role: 'user', content: prompt },
|
|
381
383
|
];
|
|
382
384
|
|
|
383
|
-
const toolDefs = this.#getToolDefs(
|
|
385
|
+
const toolDefs = this.#getToolDefs();
|
|
384
386
|
let turnNumber = 0;
|
|
385
387
|
let continueTurns = 0; // auto-continue counter
|
|
386
388
|
let fullResponseText = '';
|
package/unify/prompts.js
CHANGED
|
@@ -95,8 +95,7 @@ function extractLangSection(content, language) {
|
|
|
95
95
|
/** Loaded templates — read once at module load time. */
|
|
96
96
|
const RAW_TEMPLATES = {
|
|
97
97
|
base: readTemplate('base.md'),
|
|
98
|
-
|
|
99
|
-
modeWorker: readTemplate('mode-worker.md'),
|
|
98
|
+
modeUnified: readTemplate('mode-unified.md'),
|
|
100
99
|
modeDream: readTemplate('mode-dream.md'),
|
|
101
100
|
toolGuidance: readTemplate('tool-guidance.md'),
|
|
102
101
|
};
|
|
@@ -118,9 +117,7 @@ function getTemplate(key, language) {
|
|
|
118
117
|
const PROMPTS = {
|
|
119
118
|
en: {
|
|
120
119
|
identity: 'You are Yeaft, a helpful AI assistant.',
|
|
121
|
-
mode: (mode) => `Current mode: ${mode}`,
|
|
122
120
|
date: (d) => `Date: ${d}`,
|
|
123
|
-
work: 'You are in work mode. Break tasks into steps, execute them using tools, and report progress.',
|
|
124
121
|
dream: 'You are in dream mode. Reflect on past conversations and consolidate memories.',
|
|
125
122
|
tools: (names) => `Available tools: ${names}`,
|
|
126
123
|
memoryHeader: '## User Memory',
|
|
@@ -130,9 +127,7 @@ const PROMPTS = {
|
|
|
130
127
|
},
|
|
131
128
|
zh: {
|
|
132
129
|
identity: '你是 Yeaft,一个有用的 AI 助手。',
|
|
133
|
-
mode: (mode) => `当前模式:${mode}`,
|
|
134
130
|
date: (d) => `日期:${d}`,
|
|
135
|
-
work: '你处于工作模式。将任务分解为步骤,使用工具执行,并报告进度。',
|
|
136
131
|
dream: '你处于梦境模式。回顾过去的对话,整理和巩固记忆。',
|
|
137
132
|
tools: (names) => `可用工具:${names}`,
|
|
138
133
|
memoryHeader: '## 用户记忆',
|
|
@@ -146,12 +141,17 @@ const PROMPTS = {
|
|
|
146
141
|
export const SUPPORTED_LANGUAGES = Object.keys(PROMPTS);
|
|
147
142
|
|
|
148
143
|
/**
|
|
149
|
-
* Build the system prompt for a given language
|
|
144
|
+
* Build the system prompt for a given language.
|
|
145
|
+
*
|
|
146
|
+
* task-297: chat/work mode distinction was removed. The prompt now always uses
|
|
147
|
+
* the unified mode template. The `mode` param is retained for backward compat
|
|
148
|
+
* — only `mode === 'dream'` triggers the dream-mode template (used by background
|
|
149
|
+
* memory maintenance); all other values fall through to unified mode.
|
|
150
150
|
*
|
|
151
151
|
* Prompt structure:
|
|
152
152
|
* 1. Core identity (from template or fallback)
|
|
153
|
-
* 2.
|
|
154
|
-
* 3. Mode-specific behavioral instructions (
|
|
153
|
+
* 2. Date metadata
|
|
154
|
+
* 3. Mode-specific behavioral instructions (unified, or dream)
|
|
155
155
|
* 4. Tool list + tool guidance (from template)
|
|
156
156
|
* 5. Skills section
|
|
157
157
|
* 6. Memory section
|
|
@@ -170,7 +170,7 @@ export const SUPPORTED_LANGUAGES = Object.keys(PROMPTS);
|
|
|
170
170
|
*/
|
|
171
171
|
export function buildSystemPrompt({
|
|
172
172
|
language = 'en',
|
|
173
|
-
mode
|
|
173
|
+
mode,
|
|
174
174
|
toolNames = [],
|
|
175
175
|
memory,
|
|
176
176
|
memoryInjection,
|
|
@@ -192,23 +192,20 @@ export function buildSystemPrompt({
|
|
|
192
192
|
parts.push(lang.identity);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
// ─── 2.
|
|
196
|
-
parts.push(lang.mode(mode));
|
|
195
|
+
// ─── 2. Date Metadata ──────────────────────────────────
|
|
197
196
|
parts.push(lang.date(new Date().toISOString().split('T')[0]));
|
|
198
197
|
|
|
199
198
|
// ─── 3. Mode-Specific Instructions ─────────────────────
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
} else if (mode === 'dream') {
|
|
199
|
+
// task-297: single unified mode for all normal operation.
|
|
200
|
+
// `dream` is retained for background memory maintenance.
|
|
201
|
+
if (mode === 'dream') {
|
|
204
202
|
const dreamTemplate = getTemplate('modeDream', effectiveLang);
|
|
205
203
|
parts.push(dreamTemplate || lang.dream);
|
|
206
|
-
} else
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
parts.push(
|
|
204
|
+
} else {
|
|
205
|
+
const unifiedTemplate = getTemplate('modeUnified', effectiveLang);
|
|
206
|
+
if (unifiedTemplate) {
|
|
207
|
+
parts.push(unifiedTemplate);
|
|
210
208
|
}
|
|
211
|
-
// No fallback needed — chat mode previously had no instructions
|
|
212
209
|
}
|
|
213
210
|
|
|
214
211
|
// ─── 4. Tools + Tool Guidance ──────────────────────────
|
package/unify/tools/registry.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* registry.js — Tool registration center for Yeaft Unify
|
|
3
3
|
*
|
|
4
|
-
* Manages tool registration
|
|
4
|
+
* Manages tool registration and execution dispatch.
|
|
5
5
|
* The engine uses this to get tool definitions for the LLM and to execute tool calls.
|
|
6
|
+
*
|
|
7
|
+
* NOTE (task-297): Mode-based filtering (chat/work) has been removed. Unify now runs as
|
|
8
|
+
* a single unified mode where all registered tools are available. Tool definitions may
|
|
9
|
+
* still carry a `modes` field, but the registry ignores it.
|
|
6
10
|
*/
|
|
7
11
|
|
|
8
|
-
/**
|
|
9
|
-
* Mode normalization map.
|
|
10
|
-
* 'coordinator' and 'worker' inherit 'work' tools.
|
|
11
|
-
* 'dream' has no tools by design (returns empty).
|
|
12
|
-
*/
|
|
13
|
-
const MODE_ALIASES = {
|
|
14
|
-
coordinator: 'work',
|
|
15
|
-
worker: 'work',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
12
|
export class ToolRegistry {
|
|
19
13
|
/** @type {Map<string, import('./types.js').ToolDef>} */
|
|
20
14
|
#tools = new Map();
|
|
@@ -69,35 +63,20 @@ export class ToolRegistry {
|
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @param {string} mode
|
|
74
|
-
* @returns {string}
|
|
75
|
-
*/
|
|
76
|
-
static resolveMode(mode) {
|
|
77
|
-
return MODE_ALIASES[mode] || mode;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get all tools available in a given mode.
|
|
82
|
-
* @param {string} mode
|
|
66
|
+
* Get all registered tools (unfiltered).
|
|
83
67
|
* @returns {import('./types.js').ToolDef[]}
|
|
84
68
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const result = [];
|
|
88
|
-
for (const [, tool] of this.#tools) {
|
|
89
|
-
if (tool.modes.includes(effectiveMode)) result.push(tool);
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
69
|
+
getAllTools() {
|
|
70
|
+
return Array.from(this.#tools.values());
|
|
92
71
|
}
|
|
93
72
|
|
|
94
73
|
/**
|
|
95
74
|
* Get tool definitions for the LLM adapter.
|
|
96
|
-
*
|
|
75
|
+
* Returns all registered tools — mode filtering was removed in task-297.
|
|
97
76
|
* @returns {{ name: string, description: string, parameters: object }[]}
|
|
98
77
|
*/
|
|
99
|
-
getToolDefs(
|
|
100
|
-
return this.
|
|
78
|
+
getToolDefs() {
|
|
79
|
+
return this.getAllTools().map(t => ({
|
|
101
80
|
name: t.name,
|
|
102
81
|
description: t.description,
|
|
103
82
|
parameters: t.parameters,
|
|
@@ -105,12 +84,11 @@ export class ToolRegistry {
|
|
|
105
84
|
}
|
|
106
85
|
|
|
107
86
|
/**
|
|
108
|
-
* Get tool names
|
|
109
|
-
* @param {string} mode
|
|
87
|
+
* Get all registered tool names.
|
|
110
88
|
* @returns {string[]}
|
|
111
89
|
*/
|
|
112
|
-
getToolNames(
|
|
113
|
-
return
|
|
90
|
+
getToolNames() {
|
|
91
|
+
return Array.from(this.#tools.keys());
|
|
114
92
|
}
|
|
115
93
|
|
|
116
94
|
/**
|
package/unify/web-bridge.js
CHANGED
|
@@ -29,9 +29,6 @@ const QUERY_TIMEOUT_MS = 120_000;
|
|
|
29
29
|
/** Virtual conversationId for the Unify session */
|
|
30
30
|
let unifyConversationId = null;
|
|
31
31
|
|
|
32
|
-
/** Current query mode: 'chat' or 'work' */
|
|
33
|
-
let currentMode = 'chat';
|
|
34
|
-
|
|
35
32
|
/** Accumulated conversation messages for context continuity across queries.
|
|
36
33
|
* Each entry is { role: 'user'|'assistant', content: string|Array }.
|
|
37
34
|
* Cleared on session reset or consolidation. */
|
|
@@ -79,14 +76,16 @@ function sendUnifyEvent(event) {
|
|
|
79
76
|
* Handle a unify_chat message from the web UI.
|
|
80
77
|
*
|
|
81
78
|
* @param {{ prompt: string, mode?: string, userId?: string, username?: string }} msg
|
|
79
|
+
* NOTE: `mode` is deprecated (task-297) — Unify now runs in a single unified mode.
|
|
80
|
+
* If present, a warning is logged and the field is ignored.
|
|
82
81
|
*/
|
|
83
82
|
export async function handleUnifyChat(msg) {
|
|
84
83
|
const { prompt, mode } = msg;
|
|
85
84
|
if (!prompt?.trim()) return;
|
|
86
85
|
|
|
87
|
-
//
|
|
88
|
-
if (mode
|
|
89
|
-
|
|
86
|
+
// Deprecation warning — task-297 removed chat/work mode distinction
|
|
87
|
+
if (mode !== undefined && mode !== null) {
|
|
88
|
+
console.warn('[Unify] unify_chat.mode is deprecated and ignored — Unify now runs in a single unified mode.');
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
try {
|
|
@@ -150,7 +149,6 @@ export async function handleUnifyChat(msg) {
|
|
|
150
149
|
// ─── Stream Engine events → claude_output format ──
|
|
151
150
|
for await (const event of session.engine.query({
|
|
152
151
|
prompt,
|
|
153
|
-
mode: currentMode,
|
|
154
152
|
messages: conversationMessages,
|
|
155
153
|
signal: currentAbort.signal,
|
|
156
154
|
})) {
|
|
@@ -410,12 +408,12 @@ export async function handleUnifyChat(msg) {
|
|
|
410
408
|
|
|
411
409
|
/**
|
|
412
410
|
* Handle mode switch from the web UI.
|
|
413
|
-
*
|
|
411
|
+
* DEPRECATED (task-297): Unify no longer has chat/work mode distinction.
|
|
412
|
+
* Retained as a no-op with warning for backward compatibility.
|
|
413
|
+
* @param {{ mode?: string }} _msg
|
|
414
414
|
*/
|
|
415
|
-
export function handleUnifyModeSwitch(
|
|
416
|
-
|
|
417
|
-
currentMode = msg.mode;
|
|
418
|
-
}
|
|
415
|
+
export function handleUnifyModeSwitch(_msg) {
|
|
416
|
+
console.warn('[Unify] unify_mode_switch is deprecated and ignored — Unify now runs in a single unified mode.');
|
|
419
417
|
}
|
|
420
418
|
|
|
421
419
|
/**
|
|
@@ -522,7 +520,6 @@ export async function resetUnifySession() {
|
|
|
522
520
|
session = null;
|
|
523
521
|
}
|
|
524
522
|
unifyConversationId = null;
|
|
525
|
-
currentMode = 'chat';
|
|
526
523
|
conversationMessages = [];
|
|
527
524
|
|
|
528
525
|
// Re-initialize session immediately so frontend gets updated config
|