u-foo 4.0.0 → 4.0.2
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/OBSERVABILITY.md +65 -0
- package/README.md +90 -30
- package/README.zh-CN.md +76 -26
- package/SKILLS/ufoo/SKILL.md +25 -1
- package/SKILLS/ufoo-bus/SKILL.md +25 -2
- package/bin/ucode.js +4 -0
- package/bin/ufoo.js +3 -3
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +6 -6
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/capabilities/agentManagement/service.js +40 -13
- package/src/agents/capabilities/coordination/index.js +1 -1
- package/src/agents/capabilities/taskReports/index.js +1 -1
- package/src/agents/controller/controllerToolExecutor.js +36 -20
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +90 -56
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +38 -29
- package/src/agents/launch/launcherReadiness.js +35 -0
- package/src/agents/launch/notifier.js +2 -2
- package/src/agents/launch/ptyWrapper.js +5 -2
- package/src/agents/launch/readyDetector.js +2 -2
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +23 -7
- package/src/agents/prompts/mainAgent.js +11 -2
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/ufoo.js +11 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +3 -0
- package/src/agents/providers/claudeThreadProvider.js +3 -2
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +23 -2
- package/src/agents/providers/codexThreadProvider.js +15 -6
- package/src/agents/providers/credentials/index.js +2 -0
- package/src/agents/providers/directAuthStatus.js +1 -1
- package/src/agents/providers/index.js +1 -1
- package/src/agents/providers/modelSettings.js +34 -0
- package/src/agents/providers/modelsCatalog.js +379 -0
- package/src/agents/providers/nativeTransport.js +58 -40
- package/src/agents/providers/runtimeConfig.js +10 -8
- package/src/agents/providers/thinkingLevels.js +10 -36
- package/src/agents/providers/transports/responsesProtocol.js +11 -6
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +2 -1
- package/src/agents/runtime/core/agentLoop.js +99 -18
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/createAgentRuntime.js +16 -4
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/app/chat/ChatController.js +26 -53
- package/src/app/chat/agentDirectory.js +1 -16
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +93 -285
- package/src/app/chat/commands.js +32 -45
- package/src/app/chat/daemonMessageRouter.js +0 -45
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +7 -33
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/multiWindow/paneManager.js +10 -3
- package/src/app/chat/streamState.js +0 -4
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/run.js +42 -3
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +18 -13
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/assembler.js +7 -8
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/internalThread.js +10 -3
- package/src/code/launcher/ucode.js +1 -1
- package/src/code/launcher/ucodeBootstrap.js +1 -1
- package/src/code/modelCommand.js +11 -35
- package/src/code/nativeRunner.js +55 -17
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/repl.js +4 -11
- package/src/code/sessionStore.js +3 -3
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/toolBudget.js +1 -17
- package/src/config.js +22 -72
- package/src/coordination/bus/index.js +12 -3
- package/src/coordination/bus/inject.js +2 -2
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +1 -1
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/state/workspaceAccess.js +1 -1
- package/src/orchestration/controller/index.js +1 -8
- package/src/orchestration/controller/launchRouting.js +1 -1
- package/src/orchestration/solo/commands.js +3 -1
- package/src/runtime/contracts/agentMode.js +11 -2
- package/src/runtime/contracts/uiProtocol.js +18 -19
- package/src/runtime/daemon/agentHost.js +57 -25
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +1 -1
- package/src/runtime/daemon/controlPlaneService.js +1 -1
- package/src/runtime/daemon/groupOrchestrator.js +20 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +19 -44
- package/src/runtime/daemon/mcpHttpServer.js +39 -10
- package/src/runtime/daemon/mcpServer.js +1 -1
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +46 -23
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -589
- package/src/runtime/daemon/status.js +5 -6
- package/src/tools/controllerSchemas.js +6 -2
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/registry.js +4 -0
- package/src/tools/schemaFixtures.js +26 -2
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +1 -1
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +1 -4
- package/src/ui/format/index.js +14 -10
- package/src/ui/format/loopSummary.js +50 -0
- package/src/ui/format/markdownRenderer.js +3 -4
- package/src/ui/rustChatHost.js +191 -206
- package/src/ui/rustMultiSession.js +77 -36
- package/src/ui/rustUcodeHost.js +6 -1
- package/src/ui/settingsBridge.js +33 -16
- package/src/ui/toolMergeBridge.js +0 -4
- package/src/ui/uiHostServer.js +5 -8
- package/src/agents/controller/loopObservability.js +0 -200
- package/src/agents/controller/loopRuntime.js +0 -336
- package/src/agents/controller/ufooAgent.js +0 -830
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/controllerJsonTransport.js +0 -28
- package/src/agents/providers/upstreamTransport.js +0 -698
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/coordination/history/controllerSummary.js +0 -23
- package/src/orchestration/controller/flags.js +0 -167
- package/src/orchestration/controller/gateRouter.js +0 -211
- package/src/orchestration/controller/routerFastPath.js +0 -22
- package/src/orchestration/controller/routerFinalize.js +0 -222
- package/src/orchestration/controller/shadowGuard.js +0 -280
- package/src/runtime/daemon/executionPaths.js +0 -30
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { loadConfig, normalizeControllerMode } = require("../../config");
|
|
4
|
-
|
|
5
|
-
const CONTROLLER_MODES = Object.freeze({
|
|
6
|
-
LEGACY: "legacy",
|
|
7
|
-
SHADOW: "shadow",
|
|
8
|
-
MAIN: "main",
|
|
9
|
-
LOOP: "loop",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const CONTROLLER_MODE_HISTORY_LIMIT = 16;
|
|
13
|
-
|
|
14
|
-
const appliedControllerModes = new Map();
|
|
15
|
-
const appliedControllerModeHistory = new Map();
|
|
16
|
-
|
|
17
|
-
function readProcessControllerMode(env = process.env) {
|
|
18
|
-
const normalized = normalizeControllerMode(env.UFOO_CONTROLLER_MODE);
|
|
19
|
-
if (normalized !== CONTROLLER_MODES.LEGACY || String(env.UFOO_CONTROLLER_MODE || "").trim().toLowerCase() === CONTROLLER_MODES.LEGACY) {
|
|
20
|
-
return normalized;
|
|
21
|
-
}
|
|
22
|
-
return CONTROLLER_MODES.MAIN;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function resolveControllerMode({
|
|
26
|
-
projectRoot,
|
|
27
|
-
requestedMode = "",
|
|
28
|
-
env = process.env,
|
|
29
|
-
config = null,
|
|
30
|
-
} = {}) {
|
|
31
|
-
const explicit = normalizeControllerMode(requestedMode);
|
|
32
|
-
if (explicit !== CONTROLLER_MODES.LEGACY || String(requestedMode || "").trim().toLowerCase() === CONTROLLER_MODES.LEGACY) {
|
|
33
|
-
return explicit;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const hasExplicitConfig = config && typeof config === "object"
|
|
37
|
-
? Object.prototype.hasOwnProperty.call(config, "controllerMode")
|
|
38
|
-
: Boolean(projectRoot) && fs.existsSync(path.join(projectRoot, ".ufoo", "config.json"));
|
|
39
|
-
const loadedConfig = hasExplicitConfig
|
|
40
|
-
? (config && typeof config === "object" ? config : loadConfig(projectRoot))
|
|
41
|
-
: null;
|
|
42
|
-
if (loadedConfig) {
|
|
43
|
-
const projectMode = normalizeControllerMode(loadedConfig.controllerMode);
|
|
44
|
-
if (projectMode !== CONTROLLER_MODES.LEGACY || String(loadedConfig.controllerMode || "").trim().toLowerCase() === CONTROLLER_MODES.LEGACY) {
|
|
45
|
-
return projectMode;
|
|
46
|
-
}
|
|
47
|
-
return CONTROLLER_MODES.MAIN;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return readProcessControllerMode(env);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getControllerModeStateKey(projectRoot = "") {
|
|
54
|
-
const text = String(projectRoot || "").trim();
|
|
55
|
-
return text || "__default__";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function pushModeHistory(key, previousMode, normalizedMode, messageId) {
|
|
59
|
-
if (!previousMode || previousMode === normalizedMode) return;
|
|
60
|
-
const list = appliedControllerModeHistory.get(key) || [];
|
|
61
|
-
list.push({
|
|
62
|
-
from_mode: previousMode,
|
|
63
|
-
to_mode: normalizedMode,
|
|
64
|
-
applied_from_msg_id: String(messageId || "").trim(),
|
|
65
|
-
});
|
|
66
|
-
while (list.length > CONTROLLER_MODE_HISTORY_LIMIT) list.shift();
|
|
67
|
-
appliedControllerModeHistory.set(key, list);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function applyControllerModeForMessage({
|
|
71
|
-
projectRoot,
|
|
72
|
-
nextMode = CONTROLLER_MODES.MAIN,
|
|
73
|
-
messageId = "",
|
|
74
|
-
} = {}) {
|
|
75
|
-
const key = getControllerModeStateKey(projectRoot);
|
|
76
|
-
const normalizedMode = normalizeControllerMode(nextMode);
|
|
77
|
-
const previousMode = appliedControllerModes.get(key) || null;
|
|
78
|
-
appliedControllerModes.set(key, normalizedMode);
|
|
79
|
-
|
|
80
|
-
if (!previousMode || previousMode === normalizedMode) {
|
|
81
|
-
return {
|
|
82
|
-
mode: normalizedMode,
|
|
83
|
-
transition: null,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
pushModeHistory(key, previousMode, normalizedMode, messageId);
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
mode: normalizedMode,
|
|
91
|
-
transition: {
|
|
92
|
-
from_mode: previousMode,
|
|
93
|
-
to_mode: normalizedMode,
|
|
94
|
-
applied_from_msg_id: String(messageId || "").trim(),
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function rollbackControllerModeForMessage({
|
|
100
|
-
projectRoot,
|
|
101
|
-
messageId = "",
|
|
102
|
-
} = {}) {
|
|
103
|
-
const key = getControllerModeStateKey(projectRoot);
|
|
104
|
-
const list = appliedControllerModeHistory.get(key) || [];
|
|
105
|
-
const lastTransition = list.length > 0 ? list[list.length - 1] : null;
|
|
106
|
-
const currentMode = appliedControllerModes.get(key) || CONTROLLER_MODES.MAIN;
|
|
107
|
-
|
|
108
|
-
if (!lastTransition) {
|
|
109
|
-
return {
|
|
110
|
-
mode: currentMode,
|
|
111
|
-
transition: null,
|
|
112
|
-
rolled_back: false,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
list.pop();
|
|
117
|
-
appliedControllerModeHistory.set(key, list);
|
|
118
|
-
|
|
119
|
-
const nextMode = normalizeControllerMode(lastTransition.from_mode);
|
|
120
|
-
appliedControllerModes.set(key, nextMode);
|
|
121
|
-
|
|
122
|
-
if (nextMode === currentMode) {
|
|
123
|
-
return {
|
|
124
|
-
mode: nextMode,
|
|
125
|
-
transition: null,
|
|
126
|
-
rolled_back: true,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
mode: nextMode,
|
|
132
|
-
rolled_back: true,
|
|
133
|
-
transition: {
|
|
134
|
-
from_mode: currentMode,
|
|
135
|
-
to_mode: nextMode,
|
|
136
|
-
applied_from_msg_id: String(messageId || "").trim(),
|
|
137
|
-
rolled_back: true,
|
|
138
|
-
restored_from_msg_id: String(lastTransition.applied_from_msg_id || "").trim(),
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function getAppliedControllerMode(projectRoot) {
|
|
144
|
-
const key = getControllerModeStateKey(projectRoot);
|
|
145
|
-
return appliedControllerModes.get(key) || CONTROLLER_MODES.MAIN;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function getControllerModeHistoryForTests(projectRoot) {
|
|
149
|
-
const key = getControllerModeStateKey(projectRoot);
|
|
150
|
-
return (appliedControllerModeHistory.get(key) || []).slice();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function resetAppliedControllerModesForTests() {
|
|
154
|
-
appliedControllerModes.clear();
|
|
155
|
-
appliedControllerModeHistory.clear();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
module.exports = {
|
|
159
|
-
CONTROLLER_MODES,
|
|
160
|
-
applyControllerModeForMessage,
|
|
161
|
-
getAppliedControllerMode,
|
|
162
|
-
getControllerModeHistoryForTests,
|
|
163
|
-
readProcessControllerMode,
|
|
164
|
-
resetAppliedControllerModesForTests,
|
|
165
|
-
resolveControllerMode,
|
|
166
|
-
rollbackControllerModeForMessage,
|
|
167
|
-
};
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
loadConfig,
|
|
5
|
-
defaultRouterProviderForAgentProvider,
|
|
6
|
-
defaultRouterModelForProvider,
|
|
7
|
-
sameModelProvider,
|
|
8
|
-
} = require("../../config");
|
|
9
|
-
|
|
10
|
-
const DEFAULT_EXECUTION_PATH = "main";
|
|
11
|
-
const DEFAULT_CONFIDENCE_THRESHOLD = 0.6;
|
|
12
|
-
const DEFAULT_TIMEOUT_MS = 5000;
|
|
13
|
-
|
|
14
|
-
const ROUTING_PATTERNS = [
|
|
15
|
-
/\bwho should\b/i,
|
|
16
|
-
/\bwhich agent\b/i,
|
|
17
|
-
/\broute (?:this|it|that|the request)\b/i,
|
|
18
|
-
/\bcontinue with\b/i,
|
|
19
|
-
/\bhand\s+off\b/i,
|
|
20
|
-
/\bsend (?:this|it|that)\b/i,
|
|
21
|
-
/\bassign (?:this|it|that)\b/i,
|
|
22
|
-
/\bforward (?:this|it|that)\b/i,
|
|
23
|
-
/\bshould (?:i|we) ask\b/i,
|
|
24
|
-
/\bnew (?:codex|claude|agy|grok|kimi|ucode)\b/i,
|
|
25
|
-
/交给谁/,
|
|
26
|
-
/继续给/,
|
|
27
|
-
/发送(?:这个|它|这条|这个任务)?给/,
|
|
28
|
-
/让.*(?:接这个任务|接手|处理这个|来处理)/,
|
|
29
|
-
/发给/,
|
|
30
|
-
/转给/,
|
|
31
|
-
/应该找谁/,
|
|
32
|
-
/需要新开.*(?:codex|claude|agy|grok|kimi|ucode)/i,
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const NON_ROUTING_PATTERNS = [
|
|
36
|
-
/\bfix\b/i,
|
|
37
|
-
/\bimplement\b/i,
|
|
38
|
-
/\bwrite\b/i,
|
|
39
|
-
/\bedit\b/i,
|
|
40
|
-
/\brefactor\b/i,
|
|
41
|
-
/\btest\b/i,
|
|
42
|
-
/\binvestigate\b/i,
|
|
43
|
-
/\bdebug\b/i,
|
|
44
|
-
/\bbuild\b/i,
|
|
45
|
-
/\bcreate\b/i,
|
|
46
|
-
/\bsearch\b/i,
|
|
47
|
-
/\bopen\b/i,
|
|
48
|
-
/\bread\b/i,
|
|
49
|
-
/修复/,
|
|
50
|
-
/修正/,
|
|
51
|
-
/实现/,
|
|
52
|
-
/重构/,
|
|
53
|
-
/测试/,
|
|
54
|
-
/排查/,
|
|
55
|
-
/调试/,
|
|
56
|
-
/构建/,
|
|
57
|
-
/搜索/,
|
|
58
|
-
/查看/,
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
function normalizeExecutionPath(value = "") {
|
|
62
|
-
const text = String(value || "").trim().toLowerCase();
|
|
63
|
-
if (text === "router-api") return "main";
|
|
64
|
-
if (text === "main") return "main";
|
|
65
|
-
if (text === "shadow") return "shadow";
|
|
66
|
-
if (text === "loop") return "loop";
|
|
67
|
-
return DEFAULT_EXECUTION_PATH;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function toPositiveNumber(value, fallback) {
|
|
71
|
-
const parsed = Number(value);
|
|
72
|
-
if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
|
|
73
|
-
return parsed;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function resolveExecutionPath({
|
|
77
|
-
projectRoot,
|
|
78
|
-
requestMeta = {},
|
|
79
|
-
env = process.env,
|
|
80
|
-
loadConfigImpl = loadConfig,
|
|
81
|
-
} = {}) {
|
|
82
|
-
const config = loadConfigImpl(projectRoot || process.cwd());
|
|
83
|
-
return normalizeExecutionPath(
|
|
84
|
-
requestMeta.agent_execution_path
|
|
85
|
-
|| env.UFOO_AGENT_EXECUTION_PATH
|
|
86
|
-
|| config.agentExecutionPath
|
|
87
|
-
|| config.controllerMode
|
|
88
|
-
|| DEFAULT_EXECUTION_PATH
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function classifyPromptIntent(prompt = "") {
|
|
93
|
-
const text = String(prompt || "").trim();
|
|
94
|
-
if (!text) return { kind: "general", reason: "empty_prompt" };
|
|
95
|
-
const hasRoutingSignal = ROUTING_PATTERNS.some((pattern) => pattern.test(text));
|
|
96
|
-
if (!hasRoutingSignal) return { kind: "general", reason: "no_routing_signal" };
|
|
97
|
-
const hasNonRoutingSignal = NON_ROUTING_PATTERNS.some((pattern) => pattern.test(text));
|
|
98
|
-
if (hasNonRoutingSignal) return { kind: "general", reason: "contains_execution_language" };
|
|
99
|
-
return { kind: "routing", reason: "routing_signal" };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function shouldUseGateRouter({
|
|
103
|
-
projectRoot,
|
|
104
|
-
prompt,
|
|
105
|
-
requestMeta = {},
|
|
106
|
-
env = process.env,
|
|
107
|
-
loadConfigImpl = loadConfig,
|
|
108
|
-
} = {}) {
|
|
109
|
-
const executionPath = resolveExecutionPath({
|
|
110
|
-
projectRoot,
|
|
111
|
-
requestMeta,
|
|
112
|
-
env,
|
|
113
|
-
loadConfigImpl,
|
|
114
|
-
});
|
|
115
|
-
const intent = classifyPromptIntent(prompt);
|
|
116
|
-
return {
|
|
117
|
-
executionPath,
|
|
118
|
-
intent,
|
|
119
|
-
enabled: executionPath === "main" || executionPath === "loop",
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function resolveGateRouterConfig({
|
|
124
|
-
projectRoot,
|
|
125
|
-
requestMeta = {},
|
|
126
|
-
env = process.env,
|
|
127
|
-
loadConfigImpl = loadConfig,
|
|
128
|
-
} = {}) {
|
|
129
|
-
const config = loadConfigImpl(projectRoot || process.cwd());
|
|
130
|
-
const requestProvider = requestMeta.router_provider || env.UFOO_AGENT_ROUTER_PROVIDER;
|
|
131
|
-
const provider = String(
|
|
132
|
-
requestProvider
|
|
133
|
-
|| config.routerProvider
|
|
134
|
-
|| defaultRouterProviderForAgentProvider(config.agentProvider)
|
|
135
|
-
).trim();
|
|
136
|
-
const configuredRouterModel = !requestProvider || sameModelProvider(config.routerProvider, provider)
|
|
137
|
-
? config.routerModel
|
|
138
|
-
: "";
|
|
139
|
-
return {
|
|
140
|
-
provider,
|
|
141
|
-
model: String(
|
|
142
|
-
requestMeta.router_model
|
|
143
|
-
|| env.UFOO_AGENT_ROUTER_MODEL
|
|
144
|
-
|| configuredRouterModel
|
|
145
|
-
|| defaultRouterModelForProvider(provider)
|
|
146
|
-
).trim(),
|
|
147
|
-
timeoutMs: toPositiveNumber(
|
|
148
|
-
requestMeta.router_timeout_ms
|
|
149
|
-
|| env.UFOO_AGENT_ROUTER_TIMEOUT_MS
|
|
150
|
-
|| config.routerTimeoutMs,
|
|
151
|
-
DEFAULT_TIMEOUT_MS
|
|
152
|
-
),
|
|
153
|
-
confidenceThreshold: Math.min(
|
|
154
|
-
1,
|
|
155
|
-
toPositiveNumber(
|
|
156
|
-
requestMeta.router_confidence_threshold
|
|
157
|
-
|| env.UFOO_AGENT_ROUTER_CONFIDENCE_THRESHOLD
|
|
158
|
-
|| config.routerConfidenceThreshold,
|
|
159
|
-
DEFAULT_CONFIDENCE_THRESHOLD
|
|
160
|
-
)
|
|
161
|
-
),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function normalizeInjectionMode(value = "") {
|
|
166
|
-
const text = String(value || "").trim().toLowerCase();
|
|
167
|
-
return text === "queued" ? "queued" : "immediate";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function normalizeGateRouterResult(payload = {}, fallbackMessage = "") {
|
|
171
|
-
if (!payload || typeof payload !== "object") {
|
|
172
|
-
return {
|
|
173
|
-
decision: "upgrade_to_main_router",
|
|
174
|
-
target: "unknown",
|
|
175
|
-
confidence: 0,
|
|
176
|
-
reason: "",
|
|
177
|
-
message: String(fallbackMessage || ""),
|
|
178
|
-
injection_mode: "immediate",
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const rawConfidence = Number(payload.confidence);
|
|
183
|
-
const normalizedConfidence = Number.isFinite(rawConfidence)
|
|
184
|
-
? Math.max(0, Math.min(1, rawConfidence))
|
|
185
|
-
: 0;
|
|
186
|
-
const rawDecision = String(payload.decision || "").trim().toLowerCase();
|
|
187
|
-
const normalizedDecision = rawDecision === "direct_dispatch"
|
|
188
|
-
|| rawDecision === "upgrade_to_main_router"
|
|
189
|
-
? rawDecision
|
|
190
|
-
: (String(payload.target || "").trim() && String(payload.target || "").trim() !== "unknown"
|
|
191
|
-
? "direct_dispatch"
|
|
192
|
-
: "upgrade_to_main_router");
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
decision: normalizedDecision,
|
|
196
|
-
target: String(payload.target || "unknown").trim() || "unknown",
|
|
197
|
-
confidence: normalizedConfidence,
|
|
198
|
-
reason: String(payload.reason || "").trim(),
|
|
199
|
-
message: String(payload.message || fallbackMessage || "").trim(),
|
|
200
|
-
injection_mode: normalizeInjectionMode(payload.injection_mode),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
module.exports = {
|
|
205
|
-
classifyPromptIntent,
|
|
206
|
-
normalizeExecutionPath,
|
|
207
|
-
normalizeGateRouterResult,
|
|
208
|
-
resolveExecutionPath,
|
|
209
|
-
resolveGateRouterConfig,
|
|
210
|
-
shouldUseGateRouter,
|
|
211
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
classifyPromptIntent,
|
|
5
|
-
normalizeExecutionPath,
|
|
6
|
-
normalizeGateRouterResult,
|
|
7
|
-
resolveExecutionPath,
|
|
8
|
-
resolveGateRouterConfig,
|
|
9
|
-
shouldUseGateRouter,
|
|
10
|
-
} = require("./gateRouter");
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
classifyPromptIntent,
|
|
14
|
-
normalizeExecutionPath,
|
|
15
|
-
normalizeRouteAgentResult: normalizeGateRouterResult,
|
|
16
|
-
resolveExecutionPath,
|
|
17
|
-
resolveRouterFastPathConfig: resolveGateRouterConfig,
|
|
18
|
-
shouldUseRouterFastPath: shouldUseGateRouter,
|
|
19
|
-
normalizeGateRouterResult,
|
|
20
|
-
resolveGateRouterConfig,
|
|
21
|
-
shouldUseGateRouter,
|
|
22
|
-
};
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
normalizeLaunchAgentForNickname,
|
|
5
|
-
stripRoutingPromptMetadata,
|
|
6
|
-
} = require("./launchRouting");
|
|
7
|
-
|
|
8
|
-
const LAUNCH_TARGET_PREFIX = "__ufoo_launch_";
|
|
9
|
-
|
|
10
|
-
function normalizePayload(payload) {
|
|
11
|
-
if (!payload || typeof payload !== "object") {
|
|
12
|
-
return { reply: "", dispatch: [], ops: [] };
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
...payload,
|
|
16
|
-
reply: typeof payload.reply === "string" ? payload.reply : "",
|
|
17
|
-
dispatch: Array.isArray(payload.dispatch) ? payload.dispatch : [],
|
|
18
|
-
ops: Array.isArray(payload.ops) ? payload.ops : [],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isLaunchOp(op) {
|
|
23
|
-
return Boolean(op && op.action === "launch");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function hasDispatchMessage(item) {
|
|
27
|
-
return Boolean(item && String(item.target || "").trim() && String(item.message || "").trim());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function launchPlaceholder(index) {
|
|
31
|
-
return `${LAUNCH_TARGET_PREFIX}${index}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function parseLaunchPlaceholder(target = "") {
|
|
35
|
-
const raw = String(target || "").trim();
|
|
36
|
-
if (!raw.startsWith(LAUNCH_TARGET_PREFIX)) return -1;
|
|
37
|
-
const parsed = Number.parseInt(raw.slice(LAUNCH_TARGET_PREFIX.length), 10);
|
|
38
|
-
return Number.isFinite(parsed) && parsed >= 0 ? parsed : -1;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isLaunchDispatchTarget(target = "", op = {}) {
|
|
42
|
-
const raw = String(target || "").trim();
|
|
43
|
-
if (!raw || raw.includes(":")) return false;
|
|
44
|
-
const normalized = raw.toLowerCase();
|
|
45
|
-
const nickname = String(op.nickname || "").trim();
|
|
46
|
-
if (nickname && raw === nickname) return true;
|
|
47
|
-
const placeholders = new Set([
|
|
48
|
-
"new",
|
|
49
|
-
"new-agent",
|
|
50
|
-
"new-worker",
|
|
51
|
-
"worker",
|
|
52
|
-
"agent",
|
|
53
|
-
"launched",
|
|
54
|
-
"launched-agent",
|
|
55
|
-
"launched-worker",
|
|
56
|
-
]);
|
|
57
|
-
if (placeholders.has(normalized)) return true;
|
|
58
|
-
const launchAgent = normalizeLaunchAgentForNickname(op.agent || "");
|
|
59
|
-
return Boolean(launchAgent && normalizeLaunchAgentForNickname(raw) === launchAgent);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function resolveLaunchResultTarget(op = {}, result = {}) {
|
|
63
|
-
if (result && result.agent_id) return String(result.agent_id);
|
|
64
|
-
if (result && Array.isArray(result.subscriber_ids) && result.subscriber_ids[0]) {
|
|
65
|
-
return String(result.subscriber_ids[0]);
|
|
66
|
-
}
|
|
67
|
-
if (result && result.subscriber_id) return String(result.subscriber_id);
|
|
68
|
-
if (result && result.nickname) return String(result.nickname);
|
|
69
|
-
if (op && op.nickname) return String(op.nickname);
|
|
70
|
-
return "";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function resolveDispatchLaunchIndex(dispatchItem = {}, launchOps = []) {
|
|
74
|
-
const target = String(dispatchItem.target || "").trim();
|
|
75
|
-
const placeholderIndex = parseLaunchPlaceholder(target);
|
|
76
|
-
if (placeholderIndex >= 0) return placeholderIndex;
|
|
77
|
-
|
|
78
|
-
for (let i = 0; i < launchOps.length; i += 1) {
|
|
79
|
-
if (isLaunchDispatchTarget(target, launchOps[i])) return i;
|
|
80
|
-
}
|
|
81
|
-
return -1;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function prepareLaunchDispatchPayload(payload, prompt = "") {
|
|
85
|
-
const normalized = normalizePayload(payload);
|
|
86
|
-
const launchOps = [];
|
|
87
|
-
const otherOps = [];
|
|
88
|
-
for (const op of normalized.ops) {
|
|
89
|
-
if (isLaunchOp(op)) launchOps.push(op);
|
|
90
|
-
else if (op) otherOps.push(op);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (launchOps.length === 0) {
|
|
94
|
-
return {
|
|
95
|
-
payload: normalized,
|
|
96
|
-
launchOps,
|
|
97
|
-
otherOps,
|
|
98
|
-
dispatch: normalized.dispatch.filter(hasDispatchMessage),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let dispatch = normalized.dispatch.filter(hasDispatchMessage).map((item) => ({ ...item }));
|
|
103
|
-
const taskMessage = stripRoutingPromptMetadata(prompt);
|
|
104
|
-
if (dispatch.length === 0 && !taskMessage) {
|
|
105
|
-
return {
|
|
106
|
-
payload: { ...normalized, dispatch: [], ops: otherOps },
|
|
107
|
-
launchOps: [],
|
|
108
|
-
otherOps,
|
|
109
|
-
dispatch: [],
|
|
110
|
-
droppedLaunches: launchOps,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (dispatch.length === 0 && taskMessage) {
|
|
115
|
-
dispatch = launchOps.map((op, index) => ({
|
|
116
|
-
target: op.nickname || launchPlaceholder(index),
|
|
117
|
-
message: taskMessage,
|
|
118
|
-
injection_mode: "immediate",
|
|
119
|
-
source: "ufoo-agent",
|
|
120
|
-
}));
|
|
121
|
-
} else if (launchOps.length === 1) {
|
|
122
|
-
const fallbackTarget = launchOps[0].nickname || launchPlaceholder(0);
|
|
123
|
-
dispatch = dispatch.map((item) => (
|
|
124
|
-
isLaunchDispatchTarget(item.target, launchOps[0])
|
|
125
|
-
? { ...item, target: fallbackTarget }
|
|
126
|
-
: item
|
|
127
|
-
));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
payload: { ...normalized, dispatch, ops: [...launchOps, ...otherOps] },
|
|
132
|
-
launchOps,
|
|
133
|
-
otherOps,
|
|
134
|
-
dispatch,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function bindDispatchToLaunchResults(dispatch = [], launchOps = [], launchResults = []) {
|
|
139
|
-
const resultByIndex = launchResults.filter((item) => item && item.action === "launch");
|
|
140
|
-
return dispatch.map((item) => {
|
|
141
|
-
const index = resolveDispatchLaunchIndex(item, launchOps);
|
|
142
|
-
if (index < 0) return item;
|
|
143
|
-
const target = resolveLaunchResultTarget(launchOps[index], resultByIndex[index] || {});
|
|
144
|
-
return target ? { ...item, target } : item;
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async function finalizeRouterPayload({
|
|
149
|
-
projectRoot,
|
|
150
|
-
payload,
|
|
151
|
-
prompt = "",
|
|
152
|
-
processManager,
|
|
153
|
-
dispatchMessages,
|
|
154
|
-
handleOps,
|
|
155
|
-
markPending = () => {},
|
|
156
|
-
finalizeLocally = true,
|
|
157
|
-
}) {
|
|
158
|
-
const prepared = prepareLaunchDispatchPayload(payload, prompt);
|
|
159
|
-
if (finalizeLocally === false) {
|
|
160
|
-
return {
|
|
161
|
-
ok: true,
|
|
162
|
-
payload: prepared.payload,
|
|
163
|
-
opsResults: [],
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (prepared.launchOps.length === 0) {
|
|
168
|
-
for (const item of prepared.dispatch) {
|
|
169
|
-
if (item && item.target && item.target !== "broadcast") {
|
|
170
|
-
markPending(item.target);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (typeof dispatchMessages === "function") {
|
|
174
|
-
await dispatchMessages(projectRoot, prepared.dispatch);
|
|
175
|
-
}
|
|
176
|
-
const opsResults = typeof handleOps === "function" && prepared.otherOps.length > 0
|
|
177
|
-
? await handleOps(projectRoot, prepared.otherOps, processManager)
|
|
178
|
-
: [];
|
|
179
|
-
return {
|
|
180
|
-
ok: true,
|
|
181
|
-
payload: { ...prepared.payload, dispatch: prepared.dispatch, ops: prepared.otherOps },
|
|
182
|
-
opsResults,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const launchResults = typeof handleOps === "function"
|
|
187
|
-
? await handleOps(projectRoot, prepared.launchOps, processManager)
|
|
188
|
-
: [];
|
|
189
|
-
const boundDispatch = bindDispatchToLaunchResults(prepared.dispatch, prepared.launchOps, launchResults);
|
|
190
|
-
|
|
191
|
-
for (const item of boundDispatch) {
|
|
192
|
-
if (item && item.target && item.target !== "broadcast") {
|
|
193
|
-
markPending(item.target);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (typeof dispatchMessages === "function") {
|
|
197
|
-
await dispatchMessages(projectRoot, boundDispatch);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const otherResults = typeof handleOps === "function" && prepared.otherOps.length > 0
|
|
201
|
-
? await handleOps(projectRoot, prepared.otherOps, processManager)
|
|
202
|
-
: [];
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
ok: true,
|
|
206
|
-
payload: { ...prepared.payload, dispatch: boundDispatch },
|
|
207
|
-
opsResults: [...launchResults, ...otherResults],
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
module.exports = {
|
|
212
|
-
bindDispatchToLaunchResults,
|
|
213
|
-
finalizeRouterPayload,
|
|
214
|
-
normalizePayload,
|
|
215
|
-
prepareLaunchDispatchPayload,
|
|
216
|
-
__private: {
|
|
217
|
-
isLaunchDispatchTarget,
|
|
218
|
-
launchPlaceholder,
|
|
219
|
-
resolveLaunchResultTarget,
|
|
220
|
-
stripRoutingPromptMetadata,
|
|
221
|
-
},
|
|
222
|
-
};
|