wtt-connect 0.1.4 → 0.1.5
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/src/runner.js +41 -4
package/package.json
CHANGED
package/src/runner.js
CHANGED
|
@@ -156,7 +156,7 @@ export class Runner {
|
|
|
156
156
|
const transcripts = await this.transcribeAttachments(staged.files);
|
|
157
157
|
const adapter = this.registry.select({ ...m, content });
|
|
158
158
|
await this.wtt.typing(topicId, 'start', { statusText: `${adapterDisplayName(adapter.name)} 正在执行`, statusKind: 'running', adapter: adapter.name, ttlMs: 30000 });
|
|
159
|
-
const agentSoul = renderAgentSoulContext(m.metadata);
|
|
159
|
+
const agentSoul = renderAgentSoulContext(m.metadata, this.config.agentId);
|
|
160
160
|
const discussionRouting = renderDiscussionRoutingInstruction(m, this.config);
|
|
161
161
|
const prompt = [
|
|
162
162
|
'You are replying to a WTT Web conversation. Do not mention implementation internals unless asked.',
|
|
@@ -471,23 +471,32 @@ function parseMetadata(metadata) {
|
|
|
471
471
|
return obj && typeof obj === 'object' ? obj : null;
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
function renderAgentSoulContext(metadata) {
|
|
474
|
+
function renderAgentSoulContext(metadata, currentAgentId = '') {
|
|
475
475
|
const meta = parseMetadata(metadata);
|
|
476
476
|
if (!meta) return '';
|
|
477
477
|
|
|
478
478
|
const lines = [];
|
|
479
479
|
const soul = meta.agent_soul;
|
|
480
480
|
const role = meta.agent_role_template;
|
|
481
|
+
const hasRoleMap = hasAgentRoleTemplateMap(meta);
|
|
482
|
+
const roleByAgent = getRoleTemplateForAgent(meta, currentAgentId);
|
|
481
483
|
const persona = meta.worker_persona;
|
|
482
484
|
const workerContext = meta.worker_context;
|
|
483
485
|
|
|
484
|
-
if (
|
|
486
|
+
if (roleByAgent) {
|
|
487
|
+
if (roleByAgent.label) lines.push(`Adopt this agent role silently: ${roleByAgent.label}.`);
|
|
488
|
+
if (Array.isArray(roleByAgent.skills) && roleByAgent.skills.length) lines.push(`Relevant capabilities: ${roleByAgent.skills.join(', ')}.`);
|
|
489
|
+
const systemPrompt = roleByAgent.system_prompt || roleByAgent.systemPrompt || roleByAgent.instructions;
|
|
490
|
+
if (systemPrompt) lines.push(String(systemPrompt));
|
|
491
|
+
} else if (!hasRoleMap && soul && typeof soul === 'object') {
|
|
485
492
|
if (soul.role) lines.push(`Adopt this agent role silently: ${soul.role}.`);
|
|
486
493
|
if (Array.isArray(soul.skills) && soul.skills.length) lines.push(`Relevant capabilities: ${soul.skills.join(', ')}.`);
|
|
487
494
|
if (soul.instructions) lines.push(String(soul.instructions));
|
|
488
|
-
} else if (role && typeof role === 'object') {
|
|
495
|
+
} else if (!hasRoleMap && role && typeof role === 'object') {
|
|
489
496
|
if (role.label) lines.push(`Adopt this agent role silently: ${role.label}.`);
|
|
490
497
|
if (Array.isArray(role.skills) && role.skills.length) lines.push(`Relevant capabilities: ${role.skills.join(', ')}.`);
|
|
498
|
+
const systemPrompt = role.system_prompt || role.systemPrompt || role.instructions;
|
|
499
|
+
if (systemPrompt) lines.push(String(systemPrompt));
|
|
491
500
|
}
|
|
492
501
|
|
|
493
502
|
if (persona && typeof persona === 'object' && persona.persona_md) {
|
|
@@ -507,6 +516,31 @@ function renderAgentSoulContext(metadata) {
|
|
|
507
516
|
].join('\n');
|
|
508
517
|
}
|
|
509
518
|
|
|
519
|
+
function hasAgentRoleTemplateMap(meta) {
|
|
520
|
+
const byAgent = meta.agent_role_templates_by_agent || meta.agentRoleTemplatesByAgent;
|
|
521
|
+
return Boolean(byAgent && typeof byAgent === 'object');
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function getRoleTemplateForAgent(meta, currentAgentId) {
|
|
525
|
+
const byAgent = meta.agent_role_templates_by_agent || meta.agentRoleTemplatesByAgent;
|
|
526
|
+
if (!byAgent || typeof byAgent !== 'object' || !currentAgentId) return null;
|
|
527
|
+
|
|
528
|
+
const exact = byAgent[currentAgentId];
|
|
529
|
+
if (exact && typeof exact === 'object') return exact;
|
|
530
|
+
|
|
531
|
+
const normalizedCurrent = normalizeAgentRoleMapKey(currentAgentId);
|
|
532
|
+
for (const [agentId, role] of Object.entries(byAgent)) {
|
|
533
|
+
if (normalizeAgentRoleMapKey(agentId) === normalizedCurrent && role && typeof role === 'object') {
|
|
534
|
+
return role;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function normalizeAgentRoleMapKey(value) {
|
|
541
|
+
return String(value || '').trim().toLowerCase();
|
|
542
|
+
}
|
|
543
|
+
|
|
510
544
|
function stripHiddenContextLeak(text) {
|
|
511
545
|
return String(text || '')
|
|
512
546
|
.replace(/\[Agent Role Template\][\s\S]*?\[\/Agent Role Template\]\s*/gi, '')
|
|
@@ -585,11 +619,14 @@ function taskFromEvent(taskId, event) {
|
|
|
585
619
|
function buildTaskPrompt(task, config, staged = { promptBlock: '' }, transcripts = []) {
|
|
586
620
|
const title = task.title || task.name || `Task ${task.id}`;
|
|
587
621
|
const description = task.description || task.content || task.task_request || '';
|
|
622
|
+
const agentSoul = renderAgentSoulContext(task.metadata || task.msg_metadata, config.agentId);
|
|
588
623
|
return [
|
|
589
624
|
'You are executing a WTT task through wtt-connect.',
|
|
590
625
|
`Task ID: ${task.id}`,
|
|
591
626
|
`Title: ${title}`,
|
|
592
627
|
'',
|
|
628
|
+
agentSoul,
|
|
629
|
+
agentSoul ? '' : null,
|
|
593
630
|
'Description:',
|
|
594
631
|
description,
|
|
595
632
|
staged.promptBlock,
|