🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
chore: merge main into canary (has conflicts to resolve)
lobehubbot6340ab55e997
diff --cc e2e/src/steps/home/chat-input.steps.tsindex bc7936407f9,4092dd52917..6161c9069db--- a/e2e/src/steps/home/chat-input.steps.ts+++ b/e2e/src/steps/home/chat-input.steps.ts@@@ -2,8 -2,7 +2,12 @@@ import { After, Given, Then, When } froimport { expect } from '@playwright/test';import { llmMockManager } from '../../mocks/llm';++<<<<<<< HEAD+import type { CustomWorld } from '../../support/world';+import { WAIT_TIMEOUT } from '../../support/world';++=======+ import { type CustomWorld, WAIT_TIMEOUT } from '../../support/world';++>>>>>>> origin/mainconst COLD_ROUTE_SCRIPT_DELAY = 2500;@@@ -12,30 -11,6 +16,33 @@@ const delay = (ms: number) =setTimeout(resolve, ms);});++<<<<<<< HEAD+const focusHomeChatInput = async (world: CustomWorld): Promise<void> => {+ const candidates = [+ world.page.locator('[data-testid="chat-input"] textarea'),+ world.page.locator('[data-testid="chat-input"] [contenteditable="true"]'),+ world.page.getByRole('textbox'),+ world.page.locator('[data-testid="chat-input"]'),+ ];++ for (const locator of candidates) {+ const count = await locator.count();++ for (let index = 0; index < count; index += 1) {+ const item = locator.nth(index);+ const visible = await item.isVisible().catch(() => false);+ if (!visible) continue;++ await item.click({ force: true });+ return;+ }+ }++ throw new Error('Could not find a visible Home chat input to focus');+};+++=======++>>>>>>> origin/mainGiven('用户在冷启动 Home 页面并延迟 Agent 路由加载',{ timeout: 45_000 },@@@ -81,19 -56,6 +88,22 @@@},);++<<<<<<< HEAD+When(+ '用户在输入框中输入 {string}',+ { timeout: 30_000 },+ async function (this: CustomWorld, text: string) {+ console.log(` 📍 Step: 在 Home 输入框中输入 "${text}"...`);++ await focusHomeChatInput(this);+ await this.page.keyboard.type(text, { delay: 20 });++ console.log(' ✅ 已输入 Home 默认消息');+ },+);+++=======++>>>>>>> origin/mainWhen('用户按 Enter 从 Home 默认输入发送', { timeout: 45_000 }, async function (this: CustomWorld) {console.log(' 📍 Step: 启用冷路由延迟并发送默认 Home 消息...');diff --cc src/routes/(main)/home/features/InputArea/useSend.test.tsindex b92c68b9405,a84b99acf4c..55392936aa5--- a/src/routes/(main)/home/features/InputArea/useSend.test.ts+++ b/src/routes/(main)/home/features/InputArea/useSend.test.ts@@@ -35,31 -35,16 +35,43 @@@ const fileState = vi.hoisted(() => (}));const homeState = vi.hoisted(() => ({++<<<<<<< HEAD+ agentGroups: [],homeInputLoading: false,inputActiveMode: null,+ isAgentListInit: true,+ pinnedAgents: [],++=======++ homeInputLoading: false,++ inputActiveMode: null,++>>>>>>> origin/mainsendAsAgent: vi.fn(),sendAsGroup: vi.fn(),sendAsResearch: vi.fn(),sendAsWrite: vi.fn(),++<<<<<<< HEAD+ ungroupedAgents: [],}));const agentState = vi.hoisted(() => ({+ agentMap: {+ agt_inbox: {},+ },inboxAgentId: 'agt_inbox',+ internal_dispatchAgentMap: vi.fn(),+}));++const globalState = vi.hoisted(() => ({+ systemStatus: {+ homeSelectedAgentId: undefined,+ },+ updateSystemStatus: vi.fn(),++=======++}));++++const agentState = vi.hoisted(() => ({++ inboxAgentId: 'agt_inbox',++>>>>>>> origin/main}));vi.mock('@/hooks/useQueryRoute', () => ({@@@ -67,12 -52,7 +79,16 @@@}));vi.mock('@/store/agent', () => ({++<<<<<<< HEAD+ useAgentStore: Object.assign(+ (selector: (state: typeof agentState) => unknown) => selector(agentState),+ {+ getState: () => agentState,+ },+ ),++=======+ useAgentStore: (selector: (state: typeof agentState) => unknown) => selector(agentState),++>>>>>>> origin/main}));vi.mock('@/store/agent/selectors', () => ({@@@ -81,16 -61,6 +97,19 @@@},}));++<<<<<<< HEAD+vi.mock('@/store/global', () => ({+ useGlobalStore: (selector: (state: typeof globalState) => unknown) => selector(globalState),+}));++vi.mock('@/store/global/selectors', () => ({+ systemStatusSelectors: {+ homeSelectedAgentId: (state: typeof globalState) => state.systemStatus.homeSelectedAgentId,+ },+}));+++=======++>>>>>>> origin/mainvi.mock('@/store/chat', () => {const useChatStore = (selector: (state: typeof chatState) => unknown) => selector(chatState);useChatStore.getState = () => chatState;diff --cc src/routes/(main)/home/features/InputArea/useSend.tsindex c7e500f1791,1e7bb3a9d5c..678e3101c14--- a/src/routes/(main)/home/features/InputArea/useSend.ts+++ b/src/routes/(main)/home/features/InputArea/useSend.ts@@@ -76,22 -53,17 +76,30 @@@ export const useSend = () =>}default: {- // Default inbox behavior- if (!inboxAgentId) return;+ // Default behavior: send to currently selected agent (inbox by default,+ // overridable via the home AgentSelect dropdown).+ if (!activeAgentId) return;++ // First-time selections from AgentSelect have no entry in `agentMap`+ // yet — block on the fetch so sendMessage finds a real config below.+ await ensureAgentConfigLoaded(activeAgentId);sendMessage({++<<<<<<< HEAD+ context: { agentId: activeAgentId, isolatedTopic: true },++=======+ context: { agentId: inboxAgentId, isolatedTopic: true },++>>>>>>> origin/maincontexts: contextList,editorData,files: fileList,message: inputMessage,onTopicCreated: (topicId) => {++<<<<<<< HEAD+ router.replace(SESSION_CHAT_TOPIC_URL(activeAgentId, topicId, false));++=======+ router.replace(SESSION_CHAT_TOPIC_URL(inboxAgentId, topicId, false));++>>>>>>> origin/main},});diff --cc src/server/services/agentSignal/policies/analyzeIntent/feedbackAction.tsindex 3421960abb3,250253ac4d8..39008a437ee--- a/src/server/services/agentSignal/policies/analyzeIntent/feedbackAction.ts+++ b/src/server/services/agentSignal/policies/analyzeIntent/feedbackAction.ts@@@ -1,263 -1,86 +1,295 @@@-import type { BaseAction, BaseSignal, RuntimeProcessorResult } from '@lobechat/agent-signal';+import type {+ RuntimeDispatchProcessorResult,+ RuntimeProcessorResult,+} from '@lobechat/agent-signal';-import { defineSignalHandler } from '../../runtime/middleware';+import type {+ AgentSignalProcedureMarker,+ AgentSignalProcedureRecord,+ ProcedureAccumulatorScoreResult,+} from '../../procedure';+import { createProcedureKey, createProcedureMarker } from '../../procedure';+import type {+ FeedbackDomainSignal,+ ProcedureProcessorStateService,+ SatisfiedSkillFeedbackDomainSignal,+} from '../../processors/procedure';import {- AGENT_SIGNAL_POLICY_ACTION_TYPES,- AGENT_SIGNAL_POLICY_SIGNAL_TYPES,- type AgentSignalFeedbackDomainTarget,- type AgentSignalFeedbackSourceHints,+ accumulateSignal,+ scoreIncrease,+ suppressHandled,+ transitionScoredProcedure,+ transitionSuppressedProcedure,+} from '../../processors/procedure';+import type { RuntimeProcessorContext } from '../../runtime/context';+import { defineSignalHandler } from '../../runtime/middleware';+import type { AgentSignalActionServices } from '../../services/actionServices';+import { createDefaultActionServices } from '../../services/actionServices';+import type { ProcedureMarkerSuppressInput, ProcedureStateService } from '../../services/types';+import type {+ AgentSignalFeedbackSatisfactionResult,+ SignalFeedbackDomainMemory,+ SignalFeedbackDomainSkill,} from '../types';+import { AGENT_SIGNAL_POLICY_SIGNAL_TYPES } from '../types';-const createStableIdempotencyKey = (- signal: BaseSignal,- target: AgentSignalFeedbackDomainTarget,- messageId: string,-) => {- return `${signal.chain.rootSourceId}:${target}:${messageId}`;+/**+ * Weak positive skill feedback needs repeated observations before the accumulator emits.+ */+const SATISFIED_SKILL_CHEAP_SCORE_DELTA = 0.6;++/**+ * Marker reader dependency used by both legacy and procedure-state planner options.+ */+interface FeedbackActionMarkerReader {+ /** Checks whether an active handled marker suppresses the current feedback signal. */+ shouldSuppress: (input: ProcedureMarkerSuppressInput) => Promise<boolean>;+}++/**+ * Procedure dependencies used by the feedback action planner.+ */+export interface FeedbackActionProcedureDeps {+ /** Appends candidate records and optionally scores accumulated buckets. */+ accumulator?: {+ appendAndScore?: (+ record: AgentSignalProcedureRecord,+ ) => Promise<ProcedureAccumulatorScoreResult | undefined>;+ appendRecord: (record: AgentSignalProcedureRecord) => Promise<void>;+ };+ /** Reads handled markers for suppression when a full procedure state service is not supplied. */+ markerReader?: FeedbackActionMarkerReader;+ /** Writes accumulated markers after a bucket score is emitted. */+ markerStore?: { write: (marker: AgentSignalProcedureMarker) => Promise<void> };+ /** Provides a consistent millisecond timestamp for procedure writes. */+ now?: () => number;+ /** Facade used by the migrated procedure processors. */+ procedureState?: ProcedureStateService;+ /** Writes candidate procedure records. */+ recordStore?: { write: (record: AgentSignalProcedureRecord) => Promise<void> };+ /** TTL used for marker expiration. */+ ttlSeconds?: number;+}++/**+ * Options for feedback action planning.+ */+export interface FeedbackActionPlannerOptions {+ /** Optional action services used to prepare runtime action plans. */+ actionServices?: AgentSignalActionServices;+ /** Optional procedure marker reader used to suppress same-source duplicate actions. */+ markerReader?: FeedbackActionMarkerReader;+ /** Optional procedure dependencies used for suppression and weak-signal accumulation. */+ procedure?: FeedbackActionProcedureDeps;+}++const isSatisfiedSkillSignal = (+ signal: FeedbackDomainSignal,+): signal is SatisfiedSkillFeedbackDomainSignal => {+ return signal.payload.target === 'skill' && signal.payload.satisfactionResult === 'satisfied';};-const buildPlannedActions = (signal: BaseSignal): BaseAction[] => {- const payload = signal.payload as {- agentId?: string;- conflictPolicy?: {- forbiddenWith?: AgentSignalFeedbackDomainTarget[];- mode: 'exclusive' | 'fanout';- priority: number;- };- evidence?: Array<{- cue: string;- excerpt: string;- }>;- message: string;- messageId: string;- reason?: string;- satisfactionResult?: 'not_satisfied' | 'neutral' | 'satisfied';- sourceHints?: AgentSignalFeedbackSourceHints;- target: AgentSignalFeedbackDomainTarget;- topicId?: string;+const isMemorySignal = (signal: FeedbackDomainSignal): signal is SignalFeedbackDomainMemory => {+ return signal.payload.target === 'memory';+};++const isNonSatisfiedSkillSignal = (+ signal: FeedbackDomainSignal,+): signal is SignalFeedbackDomainSkill & {+ payload: SignalFeedbackDomainSkill['payload'] & {+ satisfactionResult: Exclude<AgentSignalFeedbackSatisfactionResult, 'satisfied'>;+ target: 'skill';};- const sourcePayload =- signal.source && 'payload' in signal.source && signal.source.payload- ? (signal.source.payload as Record<string, unknown>)- : undefined;- const serializedContext =- typeof sourcePayload?.serializedContext === 'string'- ? sourcePayload.serializedContext- : undefined;+} => {+ return signal.payload.target === 'skill' && signal.payload.satisfactionResult !== 'satisfied';+};- const idempotencyKey = createStableIdempotencyKey(signal, payload.target, payload.messageId);+const createPlannerProcedureState = (+ options: FeedbackActionPlannerOptions,+): ProcedureProcessorStateService | undefined => {+ const markerReader = options.markerReader ?? options.procedure?.markerReader;+ const procedureState = options.procedure?.procedureState;++<<<<<<< HEAD+ if (procedureState) {+ if (!markerReader) return procedureState;++ return {+ ...procedureState,+ markers: {+ ...procedureState.markers,+ shouldSuppress: markerReader.shouldSuppress,++=======+ if (payload.target === 'memory') {+ return [+ {+ actionId: `${signal.signalId}:action:memory`,+ actionType: AGENT_SIGNAL_POLICY_ACTION_TYPES.userMemoryHandle,+ chain: {+ chainId: signal.chain.chainId,+ parentNodeId: signal.signalId,+ parentSignalId: signal.signalId,+ rootSourceId: signal.chain.rootSourceId,+ },+ payload: {+ agentId: payload.agentId,+ conflictPolicy: payload.conflictPolicy,+ evidence: payload.evidence,+ feedbackHint: payload.satisfactionResult === 'satisfied' ? 'satisfied' : 'not_satisfied',+ idempotencyKey,+ message: payload.message,+ reason: payload.reason,+ serializedContext,+ sourceHints: payload.sourceHints,+ topicId: payload.topicId,+ },+ signal: {+ signalId: signal.signalId,+ signalType: signal.signalType,+ },+ source: signal.source,+ timestamp: signal.timestamp,++>>>>>>> origin/main},- ];+ };+ }++ if (!markerReader && (!options.procedure?.recordStore || !options.procedure.accumulator)) {+ return undefined;}- return [];+ return {+ accumulators:+ options.procedure?.accumulator && options.procedure.recordStore+ ? {+ appendAndScore: async (record) => {+ if (options.procedure?.accumulator?.appendAndScore) {+ return options.procedure.accumulator.appendAndScore(record);+ }++ await options.procedure?.accumulator?.appendRecord(record);+ return undefined;+ },+ }+ : undefined,+ markers: markerReader+ ? {+ shouldSuppress: markerReader.shouldSuppress,+ write: options.procedure?.markerStore?.write,+ }+ : undefined,+ records: options.procedure?.recordStore,+ };+};++const createProcedureContext = (+ context: RuntimeProcessorContext,+ options: FeedbackActionPlannerOptions,+): RuntimeProcessorContext => {+ if (!options.procedure?.now) return context;++ return { ...context, now: options.procedure.now };+};++const writeAccumulatedMarker = async (+ signal: SatisfiedSkillFeedbackDomainSignal,+ context: RuntimeProcessorContext,+ options: FeedbackActionPlannerOptions,+ scoredSignalId: string,+ recordId: string,+) => {+ const procedureStateAccumulatedMarkerWriter =+ options.procedure?.procedureState?.markers.writeAccumulated;++ if (procedureStateAccumulatedMarkerWriter) {+ await procedureStateAccumulatedMarkerWriter({+ domainKey: 'skill',+ intentClass: 'implicit_positive',+ procedureKey: createProcedureKey({+ messageId: signal.payload.messageId,+ rootSourceId: signal.chain.rootSourceId,+ }),+ recordId,+ scopeKey: context.scopeKey,+ signalId: scoredSignalId,+ sourceId: signal.source?.sourceId,+ });++ return;+ }++ const markerWriter = options.procedure?.markerStore?.write;+ const ttlSeconds = options.procedure?.ttlSeconds;++ if (!markerWriter || !ttlSeconds) return;++ const now = context.now();++ await markerWriter(+ createProcedureMarker({+ createdAt: now,+ domainKey: 'skill',+ expiresAt: now + ttlSeconds * 1000,+ intentClass: 'implicit_positive',+ markerType: 'accumulated',+ procedureKey: createProcedureKey({+ messageId: signal.payload.messageId,+ rootSourceId: signal.chain.rootSourceId,+ }),+ recordId,+ scopeKey: context.scopeKey,+ signalId: scoredSignalId,+ sourceId: signal.source?.sourceId,+ }),+ );+};++const handleSatisfiedSkillFeedback = async (+ signal: SatisfiedSkillFeedbackDomainSignal,+ context: RuntimeProcessorContext,+ options: FeedbackActionPlannerOptions,+ procedureState: ProcedureProcessorStateService | undefined,+): Promise<RuntimeProcessorResult | undefined> => {+ const accumulated = await accumulateSignal(+ signal,+ context,+ { procedureState },+ {+ domain: 'skill',+ scoreDelta: SATISFIED_SKILL_CHEAP_SCORE_DELTA,+ },+ );++ // Legacy feedbackAction behavior treats procedure-unavailable and score-gate stops as no work.+ if (accumulated.type !== 'continue') return;+ if (!('value' in accumulated)) return;++ const scored = scoreIncrease(accumulated.value.scored, {+ minRecords: 2,+ threshold: 1,+ });++ if (scored.type !== 'continue') return;+ if (!('value' in scored)) return;++ const transitioned = transitionScoredProcedure(signal, scored.value);++ if (transitioned.type !== 'transition') return;+ if (transitioned.result.status !== 'dispatch') return;++ const scoredSignal = transitioned.result.signals?.[0];+ await writeAccumulatedMarker(+ signal,+ context,+ options,+ scoredSignal?.signalId ?? '',+ accumulated.value.record.id,+ );++ return {+ ...transitioned.result,+ actions: transitioned.result.actions ?? [],+ } satisfies RuntimeDispatchProcessorResult;};/**