u-foo 3.1.7 → 4.0.1
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 +238 -21
- package/README.zh-CN.md +165 -20
- package/SKILLS/ufoo/SKILL.md +40 -4
- package/SKILLS/ufoo-bus/SKILL.md +46 -3
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +6 -4
- 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 +14 -7
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +140 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +40 -22
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +181 -76
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +96 -14
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +15 -20
- package/src/agents/launch/readyDetector.js +28 -14
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +32 -6
- package/src/agents/prompts/mainAgent.js +48 -0
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +14 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +9 -1
- package/src/agents/providers/claudeThreadProvider.js +47 -4
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +68 -7
- package/src/agents/providers/codexThreadProvider.js +18 -8
- package/src/agents/providers/credentials/claude.js +10 -3
- 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 +1146 -0
- package/src/agents/providers/runtimeConfig.js +188 -0
- package/src/agents/providers/thinkingLevels.js +106 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +504 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +127 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +351 -0
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +259 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +29 -45
- package/src/app/chat/agentDirectory.js +9 -18
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +111 -313
- package/src/app/chat/commands.js +39 -45
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -48
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +21 -35
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +91 -164
- package/src/app/chat/streamState.js +3 -7
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +82 -42
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +34 -17
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +9 -9
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +107 -0
- 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 +104 -2697
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/repl.js +2 -11
- package/src/code/sessionStore.js +27 -99
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolBudget.js +1 -17
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +95 -131
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +14 -9
- package/src/coordination/bus/inject.js +15 -7
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +8 -4
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- 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 +26 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +20 -17
- package/src/runtime/daemon/agentHost.js +407 -0
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +28 -18
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +21 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +120 -375
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +8 -5
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +68 -40
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -570
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +9 -6
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +28 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +6 -0
- package/src/tools/schemaFixtures.js +42 -5
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +9 -15
- 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/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +316 -599
- package/src/ui/rustMultiSession.js +288 -73
- package/src/ui/rustUcodeHost.js +21 -88
- package/src/ui/settingsBridge.js +34 -14
- 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 -472
- package/src/agents/controller/ufooAgent.js +0 -829
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/upstreamTransport.js +0 -689
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- 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/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -1,319 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Live provider model catalog via the OpenAI-compatible / Anthropic models route.
|
|
5
|
-
*
|
|
6
|
-
* Used by /model suggestions and settings validation so ucode only offers
|
|
7
|
-
* (and preferably accepts) models the configured endpoint actually lists.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com/v1";
|
|
11
|
-
const DEFAULT_TIMEOUT_MS = 8000;
|
|
12
|
-
const CACHE_TTL_MS = 60_000;
|
|
13
|
-
const DEFAULT_GROK_CLIENT_VERSION = "0.2.120";
|
|
14
|
-
|
|
15
|
-
/** @type {Map<string, { at: number, result: object }>} */
|
|
16
|
-
const modelsCache = new Map();
|
|
17
|
-
|
|
18
|
-
function clipText(value = "", maxChars = 400) {
|
|
19
|
-
const text = String(value || "");
|
|
20
|
-
if (text.length <= maxChars) return text;
|
|
21
|
-
return `${text.slice(0, maxChars)}…`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function resolveOpenAiModelsUrl(baseUrl = "") {
|
|
25
|
-
const raw = String(baseUrl || "").trim();
|
|
26
|
-
if (!raw) return "";
|
|
27
|
-
const normalized = raw.replace(/\/+$/, "");
|
|
28
|
-
if (/\/models$/i.test(normalized)) return normalized;
|
|
29
|
-
if (/\/chat\/completions$/i.test(normalized)) {
|
|
30
|
-
return normalized.replace(/\/chat\/completions$/i, "/models");
|
|
31
|
-
}
|
|
32
|
-
if (/\/v1$/i.test(normalized)) return `${normalized}/models`;
|
|
33
|
-
if (/\/api$/i.test(normalized)) return `${normalized}/v1/models`;
|
|
34
|
-
return `${normalized}/models`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function resolveAnthropicModelsUrl(baseUrl = "") {
|
|
38
|
-
const raw = String(baseUrl || "").trim() || DEFAULT_ANTHROPIC_BASE_URL;
|
|
39
|
-
const normalized = raw.replace(/\/+$/, "");
|
|
40
|
-
if (/\/models$/i.test(normalized)) return normalized;
|
|
41
|
-
if (/\/messages$/i.test(normalized)) {
|
|
42
|
-
return normalized.replace(/\/messages$/i, "/models");
|
|
43
|
-
}
|
|
44
|
-
if (/\/v1$/i.test(normalized)) return `${normalized}/models`;
|
|
45
|
-
if (/\/api$/i.test(normalized)) return `${normalized}/v1/models`;
|
|
46
|
-
return `${normalized}/models`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function resolveModelsUrl({ transport = "", baseUrl = "", provider = "" } = {}) {
|
|
50
|
-
let url;
|
|
51
|
-
if (String(transport || "") === "anthropic-messages") {
|
|
52
|
-
url = resolveAnthropicModelsUrl(baseUrl);
|
|
53
|
-
} else {
|
|
54
|
-
url = resolveOpenAiModelsUrl(baseUrl);
|
|
55
|
-
}
|
|
56
|
-
const normalizedProvider = String(provider || "").trim().toLowerCase();
|
|
57
|
-
if (normalizedProvider === "grok" || normalizedProvider === "grok-build" || normalizedProvider === "grok-shell") {
|
|
58
|
-
const separator = url.includes("?") ? "&" : "?";
|
|
59
|
-
const version = String(process.env.UFOO_GROK_CLIENT_VERSION || DEFAULT_GROK_CLIENT_VERSION).trim();
|
|
60
|
-
return `${url}${separator}client_version=${encodeURIComponent(version || DEFAULT_GROK_CLIENT_VERSION)}`;
|
|
61
|
-
}
|
|
62
|
-
return url;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function cacheKey({ transport = "", baseUrl = "", apiKey = "", provider = "" } = {}) {
|
|
66
|
-
const keyTail = apiKey ? String(apiKey).slice(-8) : "";
|
|
67
|
-
return `${provider}|${transport}|${baseUrl}|${keyTail}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function extractModelIds(payload) {
|
|
71
|
-
const ids = [];
|
|
72
|
-
const seen = new Set();
|
|
73
|
-
const push = (value) => {
|
|
74
|
-
const id = String(value || "").trim();
|
|
75
|
-
if (!id || seen.has(id)) return;
|
|
76
|
-
seen.add(id);
|
|
77
|
-
ids.push(id);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
if (!payload || typeof payload !== "object") return ids;
|
|
81
|
-
|
|
82
|
-
if (Array.isArray(payload.data)) {
|
|
83
|
-
for (const item of payload.data) {
|
|
84
|
-
if (!item) continue;
|
|
85
|
-
if (typeof item === "string") push(item);
|
|
86
|
-
else push(item.id || item.model || item.name);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (Array.isArray(payload.models)) {
|
|
91
|
-
for (const item of payload.models) {
|
|
92
|
-
if (!item) continue;
|
|
93
|
-
if (typeof item === "string") push(item);
|
|
94
|
-
else push(item.id || item.model || item.name);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return ids;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function buildListHeaders({ transport = "", apiKey = "", provider = "" } = {}) {
|
|
102
|
-
const headers = {
|
|
103
|
-
Accept: "application/json",
|
|
104
|
-
};
|
|
105
|
-
const normalizedProvider = String(provider || "").trim().toLowerCase();
|
|
106
|
-
if (normalizedProvider === "grok" || normalizedProvider === "grok-build" || normalizedProvider === "grok-shell") {
|
|
107
|
-
const version = String(process.env.UFOO_GROK_CLIENT_VERSION || DEFAULT_GROK_CLIENT_VERSION).trim();
|
|
108
|
-
headers["User-Agent"] = `grok-shell/${version || DEFAULT_GROK_CLIENT_VERSION}`;
|
|
109
|
-
}
|
|
110
|
-
const key = String(apiKey || "").trim();
|
|
111
|
-
if (!key) return headers;
|
|
112
|
-
|
|
113
|
-
if (String(transport || "") === "anthropic-messages") {
|
|
114
|
-
headers["x-api-key"] = key;
|
|
115
|
-
headers["anthropic-version"] = "2023-06-01";
|
|
116
|
-
} else {
|
|
117
|
-
headers.Authorization = `Bearer ${key}`;
|
|
118
|
-
}
|
|
119
|
-
return headers;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Fetch the provider's models catalog.
|
|
124
|
-
* @returns {Promise<{
|
|
125
|
-
* ok: boolean,
|
|
126
|
-
* models: string[],
|
|
127
|
-
* url: string,
|
|
128
|
-
* error: string,
|
|
129
|
-
* status: number,
|
|
130
|
-
* cached: boolean,
|
|
131
|
-
* }>}
|
|
132
|
-
*/
|
|
133
|
-
async function listProviderModels(options = {}) {
|
|
134
|
-
const transport = String(options.transport || "openai-chat").trim() || "openai-chat";
|
|
135
|
-
const baseUrl = String(options.baseUrl || "").trim();
|
|
136
|
-
const apiKey = String(options.apiKey || "").trim();
|
|
137
|
-
const provider = String(options.provider || "").trim();
|
|
138
|
-
const timeoutMs = Math.max(1000, Number(options.timeoutMs) || DEFAULT_TIMEOUT_MS);
|
|
139
|
-
const fetchImpl = typeof options.fetchImpl === "function" ? options.fetchImpl : fetch;
|
|
140
|
-
const skipCache = options.skipCache === true;
|
|
141
|
-
const url = resolveModelsUrl({ transport, baseUrl, provider });
|
|
142
|
-
|
|
143
|
-
if (!url) {
|
|
144
|
-
return {
|
|
145
|
-
ok: false,
|
|
146
|
-
models: [],
|
|
147
|
-
url: "",
|
|
148
|
-
error: "models url unavailable (set ucode base url)",
|
|
149
|
-
status: 0,
|
|
150
|
-
cached: false,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const key = cacheKey({ transport, baseUrl, apiKey, provider });
|
|
155
|
-
if (!skipCache) {
|
|
156
|
-
const hit = modelsCache.get(key);
|
|
157
|
-
if (hit && (Date.now() - hit.at) < CACHE_TTL_MS) {
|
|
158
|
-
return { ...hit.result, cached: true };
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const controller = typeof AbortController === "function" ? new AbortController() : null;
|
|
163
|
-
const timer = controller
|
|
164
|
-
? setTimeout(() => {
|
|
165
|
-
try { controller.abort(); } catch { /* ignore */ }
|
|
166
|
-
}, timeoutMs)
|
|
167
|
-
: null;
|
|
168
|
-
if (timer && typeof timer.unref === "function") timer.unref();
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
const response = await fetchImpl(url, {
|
|
172
|
-
method: "GET",
|
|
173
|
-
headers: buildListHeaders({ transport, apiKey, provider }),
|
|
174
|
-
signal: controller ? controller.signal : undefined,
|
|
175
|
-
});
|
|
176
|
-
const status = Number(response && response.status) || 0;
|
|
177
|
-
const bodyText = await response.text().catch(() => "");
|
|
178
|
-
let payload = null;
|
|
179
|
-
try {
|
|
180
|
-
payload = bodyText ? JSON.parse(bodyText) : null;
|
|
181
|
-
} catch {
|
|
182
|
-
payload = null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (!response.ok) {
|
|
186
|
-
const result = {
|
|
187
|
-
ok: false,
|
|
188
|
-
models: [],
|
|
189
|
-
url,
|
|
190
|
-
error: `models route failed (${status}): ${clipText(bodyText || response.statusText || "unknown")}`,
|
|
191
|
-
status,
|
|
192
|
-
cached: false,
|
|
193
|
-
};
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const models = extractModelIds(payload);
|
|
198
|
-
const result = {
|
|
199
|
-
ok: true,
|
|
200
|
-
models,
|
|
201
|
-
url,
|
|
202
|
-
error: models.length === 0 ? "models route returned an empty catalog" : "",
|
|
203
|
-
status,
|
|
204
|
-
cached: false,
|
|
205
|
-
};
|
|
206
|
-
// Cache successful responses even when empty — avoids hammering a broken gateway.
|
|
207
|
-
modelsCache.set(key, { at: Date.now(), result: { ...result, cached: false } });
|
|
208
|
-
return result;
|
|
209
|
-
} catch (err) {
|
|
210
|
-
const message = err && err.name === "AbortError"
|
|
211
|
-
? `models route timed out after ${timeoutMs}ms`
|
|
212
|
-
: (err && err.message ? err.message : String(err || "models route failed"));
|
|
213
|
-
return {
|
|
214
|
-
ok: false,
|
|
215
|
-
models: [],
|
|
216
|
-
url,
|
|
217
|
-
error: message,
|
|
218
|
-
status: 0,
|
|
219
|
-
cached: false,
|
|
220
|
-
};
|
|
221
|
-
} finally {
|
|
222
|
-
if (timer) clearTimeout(timer);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function modelSupported(model = "", models = []) {
|
|
227
|
-
const needle = String(model || "").trim();
|
|
228
|
-
if (!needle) return false;
|
|
229
|
-
const list = Array.isArray(models) ? models : [];
|
|
230
|
-
return list.some((id) => String(id || "").trim() === needle);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Validate a model id against the live catalog.
|
|
235
|
-
* Soft mode: when the catalog cannot be fetched, allow with a warning.
|
|
236
|
-
*/
|
|
237
|
-
async function confirmModelSupported(options = {}) {
|
|
238
|
-
const model = String(options.model || "").trim();
|
|
239
|
-
if (!model) {
|
|
240
|
-
return {
|
|
241
|
-
ok: false,
|
|
242
|
-
allowed: false,
|
|
243
|
-
model: "",
|
|
244
|
-
models: [],
|
|
245
|
-
error: "model id is empty",
|
|
246
|
-
warning: "",
|
|
247
|
-
catalog: null,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const catalog = await listProviderModels(options);
|
|
252
|
-
if (!catalog.ok) {
|
|
253
|
-
return {
|
|
254
|
-
ok: false,
|
|
255
|
-
allowed: options.strict === true ? false : true,
|
|
256
|
-
model,
|
|
257
|
-
models: [],
|
|
258
|
-
error: catalog.error || "models route unavailable",
|
|
259
|
-
warning: options.strict === true
|
|
260
|
-
? ""
|
|
261
|
-
: `could not confirm model via models route (${catalog.error || "unavailable"}); accepting ${model}`,
|
|
262
|
-
catalog,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (catalog.models.length === 0) {
|
|
267
|
-
return {
|
|
268
|
-
ok: false,
|
|
269
|
-
allowed: options.strict === true ? false : true,
|
|
270
|
-
model,
|
|
271
|
-
models: [],
|
|
272
|
-
error: catalog.error || "empty models catalog",
|
|
273
|
-
warning: options.strict === true
|
|
274
|
-
? ""
|
|
275
|
-
: `models route returned no models; accepting ${model}`,
|
|
276
|
-
catalog,
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (!modelSupported(model, catalog.models)) {
|
|
281
|
-
const sample = catalog.models.slice(0, 8).join(", ");
|
|
282
|
-
const more = catalog.models.length > 8 ? ` (+${catalog.models.length - 8} more)` : "";
|
|
283
|
-
return {
|
|
284
|
-
ok: false,
|
|
285
|
-
allowed: false,
|
|
286
|
-
model,
|
|
287
|
-
models: catalog.models,
|
|
288
|
-
error: `model "${model}" is not in the provider catalog${sample ? ` (available: ${sample}${more})` : ""}`,
|
|
289
|
-
warning: "",
|
|
290
|
-
catalog,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return {
|
|
295
|
-
ok: true,
|
|
296
|
-
allowed: true,
|
|
297
|
-
model,
|
|
298
|
-
models: catalog.models,
|
|
299
|
-
error: "",
|
|
300
|
-
warning: "",
|
|
301
|
-
catalog,
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function clearModelsCache() {
|
|
306
|
-
modelsCache.clear();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
module.exports = {
|
|
310
|
-
resolveOpenAiModelsUrl,
|
|
311
|
-
resolveAnthropicModelsUrl,
|
|
312
|
-
resolveModelsUrl,
|
|
313
|
-
listProviderModels,
|
|
314
|
-
confirmModelSupported,
|
|
315
|
-
modelSupported,
|
|
316
|
-
extractModelIds,
|
|
317
|
-
clearModelsCache,
|
|
318
|
-
CACHE_TTL_MS,
|
|
319
|
-
};
|
|
3
|
+
module.exports = require("../../agents/providers/modelsCatalog");
|
|
@@ -1,116 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
extractVisionPayload,
|
|
7
|
-
stripVisionBase64,
|
|
8
|
-
visionSummaryText,
|
|
9
|
-
toOpenAiImagePart,
|
|
10
|
-
} = require("./visionBlocks");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* OpenAI-compatible chat-completions transport adapter.
|
|
14
|
-
* @param {{
|
|
15
|
-
* resolveUrl: Function,
|
|
16
|
-
* runTurn: Function,
|
|
17
|
-
* normalizeToolName: Function,
|
|
18
|
-
* normalizeToolCallArgs: Function,
|
|
19
|
-
* toJsonString: Function,
|
|
20
|
-
* clipText: Function,
|
|
21
|
-
* }} deps
|
|
22
|
-
*/
|
|
23
|
-
function createOpenAiChatTransport(deps = {}) {
|
|
24
|
-
const {
|
|
25
|
-
resolveUrl,
|
|
26
|
-
runTurn,
|
|
27
|
-
normalizeToolName,
|
|
28
|
-
normalizeToolCallArgs,
|
|
29
|
-
toJsonString,
|
|
30
|
-
clipText,
|
|
31
|
-
} = deps;
|
|
32
|
-
|
|
33
|
-
const transport = {
|
|
34
|
-
name: "openai-chat",
|
|
35
|
-
resolveUrl,
|
|
36
|
-
prepareMessages({ messages, systemPrompt, prompt }) {
|
|
37
|
-
const systemText = String(systemPrompt || "").trim();
|
|
38
|
-
const hasSystem = messages.some((entry) => String(entry.role || "").trim() === "system");
|
|
39
|
-
if (systemText && !hasSystem) {
|
|
40
|
-
messages.unshift({ role: "system", content: systemText });
|
|
41
|
-
}
|
|
42
|
-
messages.push({ role: "user", content: String(prompt || "") });
|
|
43
|
-
},
|
|
44
|
-
runTurn,
|
|
45
|
-
getToolCalls(turnResult) {
|
|
46
|
-
return Array.isArray(turnResult.toolCalls)
|
|
47
|
-
? turnResult.toolCalls.filter((call) => call && call.function && typeof call.function === "object")
|
|
48
|
-
: [];
|
|
49
|
-
},
|
|
50
|
-
appendFinalAssistantMessage({ messages, turnResult }) {
|
|
51
|
-
const text = String(turnResult.text || "").trim();
|
|
52
|
-
if (text) {
|
|
53
|
-
messages.push({
|
|
54
|
-
role: "assistant",
|
|
55
|
-
content: text,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
prepareToolCalls({ messages, toolCalls }) {
|
|
60
|
-
const assistantToolCalls = [];
|
|
61
|
-
for (const call of toolCalls) {
|
|
62
|
-
const callId = String(call.id || `call_${randomUUID()}`);
|
|
63
|
-
const name = normalizeToolName(call.function.name || "");
|
|
64
|
-
const args = normalizeToolCallArgs(call.function.arguments || "");
|
|
65
|
-
|
|
66
|
-
assistantToolCalls.push({
|
|
67
|
-
id: callId,
|
|
68
|
-
type: "function",
|
|
69
|
-
function: {
|
|
70
|
-
name: name || String(call.function.name || ""),
|
|
71
|
-
arguments: toJsonString(args),
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (assistantToolCalls.length === 0) return null;
|
|
77
|
-
|
|
78
|
-
messages.push({
|
|
79
|
-
role: "assistant",
|
|
80
|
-
content: null,
|
|
81
|
-
tool_calls: assistantToolCalls,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return assistantToolCalls.map((toolCall) => ({
|
|
85
|
-
name: toolCall.function.name,
|
|
86
|
-
args: normalizeToolCallArgs(toolCall.function.arguments),
|
|
87
|
-
source: toolCall,
|
|
88
|
-
}));
|
|
89
|
-
},
|
|
90
|
-
appendToolResult({ messages, call, toolResult }) {
|
|
91
|
-
const vision = extractVisionPayload(toolResult);
|
|
92
|
-
const payload = vision ? stripVisionBase64(toolResult) : toolResult;
|
|
93
|
-
messages.push({
|
|
94
|
-
role: "tool",
|
|
95
|
-
tool_call_id: call.source.id,
|
|
96
|
-
content: clipText(toJsonString(payload), 12000),
|
|
97
|
-
});
|
|
98
|
-
if (vision) {
|
|
99
|
-
const imagePart = toOpenAiImagePart(vision);
|
|
100
|
-
messages.push({
|
|
101
|
-
role: "user",
|
|
102
|
-
content: [
|
|
103
|
-
{ type: "text", text: visionSummaryText(vision, toolResult) },
|
|
104
|
-
imagePart,
|
|
105
|
-
],
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return assertTransport(transport, "openai-chat");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
module.exports = {
|
|
115
|
-
createOpenAiChatTransport,
|
|
116
|
-
};
|
|
3
|
+
// Existing public entry; implementation belongs to the shared agent layer.
|
|
4
|
+
module.exports = require("../../agents/providers/transports/openaiChatTransport");
|
|
@@ -1,119 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
extractVisionPayload,
|
|
7
|
-
stripVisionBase64,
|
|
8
|
-
visionSummaryText,
|
|
9
|
-
toOpenAiImagePart,
|
|
10
|
-
} = require("./visionBlocks");
|
|
11
|
-
const { attachResponsesReasoningItems } = require("./responsesProtocol");
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* OpenAI Responses transport adapter.
|
|
15
|
-
*
|
|
16
|
-
* The loop keeps the public, provider-neutral message projection in the same
|
|
17
|
-
* shape as the Chat transport. The Responses wire conversion is owned by the
|
|
18
|
-
* request builder, so response-only metadata never gets persisted into the
|
|
19
|
-
* Session Journal.
|
|
20
|
-
*/
|
|
21
|
-
function createOpenAiResponsesTransport(deps = {}) {
|
|
22
|
-
const {
|
|
23
|
-
resolveUrl,
|
|
24
|
-
runTurn,
|
|
25
|
-
normalizeToolName,
|
|
26
|
-
normalizeToolCallArgs,
|
|
27
|
-
toJsonString,
|
|
28
|
-
clipText,
|
|
29
|
-
} = deps;
|
|
30
|
-
|
|
31
|
-
const transport = {
|
|
32
|
-
name: "openai-responses",
|
|
33
|
-
resolveUrl,
|
|
34
|
-
prepareMessages({ messages, prompt }) {
|
|
35
|
-
messages.push({
|
|
36
|
-
role: "user",
|
|
37
|
-
content: String(prompt || ""),
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
runTurn,
|
|
41
|
-
getToolCalls(turnResult) {
|
|
42
|
-
return Array.isArray(turnResult.toolCalls)
|
|
43
|
-
? turnResult.toolCalls.filter((call) => call && call.function && typeof call.function === "object")
|
|
44
|
-
: [];
|
|
45
|
-
},
|
|
46
|
-
appendFinalAssistantMessage({ messages, turnResult }) {
|
|
47
|
-
const text = String(turnResult.text || "").trim();
|
|
48
|
-
if (text) {
|
|
49
|
-
messages.push({
|
|
50
|
-
role: "assistant",
|
|
51
|
-
content: text,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
prepareToolCalls({ messages, turnResult, toolCalls }) {
|
|
56
|
-
const assistantToolCalls = [];
|
|
57
|
-
for (const call of toolCalls) {
|
|
58
|
-
const source = call && call.function && typeof call.function === "object"
|
|
59
|
-
? call.function
|
|
60
|
-
: {};
|
|
61
|
-
const callId = String(call.id || `call_${randomUUID()}`);
|
|
62
|
-
const name = normalizeToolName(source.name || "");
|
|
63
|
-
const args = normalizeToolCallArgs(source.arguments || "");
|
|
64
|
-
assistantToolCalls.push({
|
|
65
|
-
id: callId,
|
|
66
|
-
type: "function",
|
|
67
|
-
function: {
|
|
68
|
-
name: name || String(source.name || ""),
|
|
69
|
-
arguments: toJsonString(args),
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (assistantToolCalls.length === 0) return null;
|
|
75
|
-
const assistantMessage = {
|
|
76
|
-
role: "assistant",
|
|
77
|
-
content: null,
|
|
78
|
-
tool_calls: assistantToolCalls,
|
|
79
|
-
};
|
|
80
|
-
attachResponsesReasoningItems(
|
|
81
|
-
assistantMessage,
|
|
82
|
-
turnResult && Array.isArray(turnResult.outputItems)
|
|
83
|
-
? { output: turnResult.outputItems }
|
|
84
|
-
: (turnResult && turnResult.response),
|
|
85
|
-
);
|
|
86
|
-
messages.push(assistantMessage);
|
|
87
|
-
|
|
88
|
-
return assistantToolCalls.map((toolCall) => ({
|
|
89
|
-
name: toolCall.function.name,
|
|
90
|
-
args: normalizeToolCallArgs(toolCall.function.arguments),
|
|
91
|
-
source: toolCall,
|
|
92
|
-
}));
|
|
93
|
-
},
|
|
94
|
-
appendToolResult({ messages, call, toolResult }) {
|
|
95
|
-
const vision = extractVisionPayload(toolResult);
|
|
96
|
-
const payload = vision ? stripVisionBase64(toolResult) : toolResult;
|
|
97
|
-
messages.push({
|
|
98
|
-
role: "tool",
|
|
99
|
-
tool_call_id: call.source.id,
|
|
100
|
-
content: clipText(toJsonString(payload), 12000),
|
|
101
|
-
});
|
|
102
|
-
if (vision) {
|
|
103
|
-
messages.push({
|
|
104
|
-
role: "user",
|
|
105
|
-
content: [
|
|
106
|
-
{ type: "text", text: visionSummaryText(vision, toolResult) },
|
|
107
|
-
toOpenAiImagePart(vision),
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return assertTransport(transport, "openai-responses");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
module.exports = {
|
|
118
|
-
createOpenAiResponsesTransport,
|
|
119
|
-
};
|
|
3
|
+
// Existing public entry; implementation belongs to the shared agent layer.
|
|
4
|
+
module.exports = require("../../agents/providers/transports/openaiResponsesTransport");
|