wave-agent-sdk 0.0.8 → 0.0.10
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/dist/agent.d.ts +92 -23
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +340 -137
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/managers/aiManager.d.ts +14 -36
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +74 -77
- package/dist/managers/backgroundBashManager.d.ts.map +1 -1
- package/dist/managers/backgroundBashManager.js +4 -3
- package/dist/managers/hookManager.d.ts +3 -8
- package/dist/managers/hookManager.d.ts.map +1 -1
- package/dist/managers/hookManager.js +39 -29
- package/dist/managers/liveConfigManager.d.ts +55 -18
- package/dist/managers/liveConfigManager.d.ts.map +1 -1
- package/dist/managers/liveConfigManager.js +372 -90
- package/dist/managers/lspManager.d.ts +43 -0
- package/dist/managers/lspManager.d.ts.map +1 -0
- package/dist/managers/lspManager.js +326 -0
- package/dist/managers/messageManager.d.ts +8 -16
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +52 -74
- package/dist/managers/permissionManager.d.ts +66 -0
- package/dist/managers/permissionManager.d.ts.map +1 -0
- package/dist/managers/permissionManager.js +208 -0
- package/dist/managers/skillManager.d.ts +1 -0
- package/dist/managers/skillManager.d.ts.map +1 -1
- package/dist/managers/skillManager.js +2 -1
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +0 -1
- package/dist/managers/subagentManager.d.ts +8 -23
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +97 -117
- package/dist/managers/toolManager.d.ts +38 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +66 -2
- package/dist/services/aiService.d.ts +3 -1
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +123 -30
- package/dist/services/configurationService.d.ts +116 -0
- package/dist/services/configurationService.d.ts.map +1 -0
- package/dist/services/configurationService.js +585 -0
- package/dist/services/fileWatcher.d.ts.map +1 -1
- package/dist/services/fileWatcher.js +5 -6
- package/dist/services/hook.d.ts +7 -124
- package/dist/services/hook.d.ts.map +1 -1
- package/dist/services/hook.js +46 -458
- package/dist/services/jsonlHandler.d.ts +24 -15
- package/dist/services/jsonlHandler.d.ts.map +1 -1
- package/dist/services/jsonlHandler.js +67 -88
- package/dist/services/memory.d.ts +0 -9
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +2 -49
- package/dist/services/session.d.ts +82 -33
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +275 -181
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +72 -13
- package/dist/tools/deleteFileTool.d.ts.map +1 -1
- package/dist/tools/deleteFileTool.js +25 -0
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +30 -6
- package/dist/tools/lspTool.d.ts +6 -0
- package/dist/tools/lspTool.d.ts.map +1 -0
- package/dist/tools/lspTool.js +589 -0
- package/dist/tools/multiEditTool.d.ts.map +1 -1
- package/dist/tools/multiEditTool.js +26 -7
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +111 -2
- package/dist/tools/skillTool.js +2 -2
- package/dist/tools/todoWriteTool.d.ts.map +1 -1
- package/dist/tools/todoWriteTool.js +23 -0
- package/dist/tools/types.d.ts +11 -8
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +25 -9
- package/dist/types/commands.d.ts +0 -1
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/config.d.ts +4 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/configuration.d.ts +69 -0
- package/dist/types/configuration.d.ts.map +1 -0
- package/dist/types/configuration.js +8 -0
- package/dist/types/core.d.ts +10 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/environment.d.ts +41 -0
- package/dist/types/environment.d.ts.map +1 -1
- package/dist/types/fileSearch.d.ts +5 -0
- package/dist/types/fileSearch.d.ts.map +1 -0
- package/dist/types/fileSearch.js +1 -0
- package/dist/types/hooks.d.ts +11 -2
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/hooks.js +1 -7
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +5 -0
- package/dist/types/lsp.d.ts +90 -0
- package/dist/types/lsp.d.ts.map +1 -0
- package/dist/types/lsp.js +4 -0
- package/dist/types/messaging.d.ts +6 -11
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/permissions.d.ts +35 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/permissions.js +12 -0
- package/dist/types/session.d.ts +1 -6
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/skills.d.ts +1 -0
- package/dist/types/skills.d.ts.map +1 -1
- package/dist/types/tools.d.ts +35 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +4 -0
- package/dist/utils/abortUtils.d.ts +34 -0
- package/dist/utils/abortUtils.d.ts.map +1 -0
- package/dist/utils/abortUtils.js +92 -0
- package/dist/utils/bashHistory.d.ts +4 -0
- package/dist/utils/bashHistory.d.ts.map +1 -1
- package/dist/utils/bashHistory.js +21 -4
- package/dist/utils/builtinSubagents.d.ts +7 -0
- package/dist/utils/builtinSubagents.d.ts.map +1 -0
- package/dist/utils/builtinSubagents.js +65 -0
- package/dist/utils/cacheControlUtils.d.ts +8 -33
- package/dist/utils/cacheControlUtils.d.ts.map +1 -1
- package/dist/utils/cacheControlUtils.js +83 -126
- package/dist/utils/constants.d.ts +0 -12
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +1 -13
- package/dist/utils/convertMessagesForAPI.d.ts +2 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +33 -14
- package/dist/utils/fileSearch.d.ts +14 -0
- package/dist/utils/fileSearch.d.ts.map +1 -0
- package/dist/utils/fileSearch.js +88 -0
- package/dist/utils/fileUtils.d.ts +14 -2
- package/dist/utils/fileUtils.d.ts.map +1 -1
- package/dist/utils/fileUtils.js +101 -17
- package/dist/utils/globalLogger.d.ts +0 -14
- package/dist/utils/globalLogger.d.ts.map +1 -1
- package/dist/utils/globalLogger.js +0 -16
- package/dist/utils/largeOutputHandler.d.ts +15 -0
- package/dist/utils/largeOutputHandler.d.ts.map +1 -0
- package/dist/utils/largeOutputHandler.js +40 -0
- package/dist/utils/markdownParser.d.ts.map +1 -1
- package/dist/utils/markdownParser.js +1 -17
- package/dist/utils/messageOperations.d.ts +1 -11
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +7 -24
- package/dist/utils/pathEncoder.d.ts +4 -0
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +16 -9
- package/dist/utils/subagentParser.d.ts +2 -2
- package/dist/utils/subagentParser.d.ts.map +1 -1
- package/dist/utils/subagentParser.js +10 -7
- package/dist/utils/tokenEstimator.d.ts +39 -0
- package/dist/utils/tokenEstimator.d.ts.map +1 -0
- package/dist/utils/tokenEstimator.js +55 -0
- package/package.json +5 -8
- package/src/agent.ts +460 -216
- package/src/index.ts +2 -0
- package/src/managers/aiManager.ts +107 -111
- package/src/managers/backgroundBashManager.ts +4 -3
- package/src/managers/hookManager.ts +44 -39
- package/src/managers/liveConfigManager.ts +524 -138
- package/src/managers/lspManager.ts +434 -0
- package/src/managers/messageManager.ts +73 -103
- package/src/managers/permissionManager.ts +276 -0
- package/src/managers/skillManager.ts +3 -1
- package/src/managers/slashCommandManager.ts +1 -2
- package/src/managers/subagentManager.ts +116 -159
- package/src/managers/toolManager.ts +95 -3
- package/src/services/aiService.ts +207 -26
- package/src/services/configurationService.ts +762 -0
- package/src/services/fileWatcher.ts +5 -6
- package/src/services/hook.ts +50 -631
- package/src/services/jsonlHandler.ts +84 -100
- package/src/services/memory.ts +2 -59
- package/src/services/session.ts +338 -213
- package/src/tools/bashTool.ts +89 -16
- package/src/tools/deleteFileTool.ts +36 -0
- package/src/tools/editTool.ts +41 -7
- package/src/tools/lspTool.ts +760 -0
- package/src/tools/multiEditTool.ts +37 -8
- package/src/tools/readTool.ts +125 -2
- package/src/tools/skillTool.ts +2 -2
- package/src/tools/todoWriteTool.ts +33 -1
- package/src/tools/types.ts +15 -9
- package/src/tools/writeTool.ts +36 -10
- package/src/types/commands.ts +0 -1
- package/src/types/config.ts +5 -0
- package/src/types/configuration.ts +73 -0
- package/src/types/core.ts +11 -0
- package/src/types/environment.ts +44 -0
- package/src/types/fileSearch.ts +4 -0
- package/src/types/hooks.ts +14 -11
- package/src/types/index.ts +5 -0
- package/src/types/lsp.ts +96 -0
- package/src/types/messaging.ts +8 -13
- package/src/types/permissions.ts +48 -0
- package/src/types/session.ts +3 -8
- package/src/types/skills.ts +1 -0
- package/src/types/tools.ts +38 -0
- package/src/utils/abortUtils.ts +118 -0
- package/src/utils/bashHistory.ts +28 -4
- package/src/utils/builtinSubagents.ts +71 -0
- package/src/utils/cacheControlUtils.ts +106 -171
- package/src/utils/constants.ts +1 -16
- package/src/utils/convertMessagesForAPI.ts +38 -14
- package/src/utils/fileSearch.ts +107 -0
- package/src/utils/fileUtils.ts +114 -19
- package/src/utils/globalLogger.ts +0 -17
- package/src/utils/largeOutputHandler.ts +55 -0
- package/src/utils/markdownParser.ts +1 -19
- package/src/utils/messageOperations.ts +7 -35
- package/src/utils/pathEncoder.ts +24 -9
- package/src/utils/subagentParser.ts +11 -8
- package/src/utils/tokenEstimator.ts +68 -0
- package/dist/constants/events.d.ts +0 -28
- package/dist/constants/events.d.ts.map +0 -1
- package/dist/constants/events.js +0 -27
- package/dist/services/configurationWatcher.d.ts +0 -120
- package/dist/services/configurationWatcher.d.ts.map +0 -1
- package/dist/services/configurationWatcher.js +0 -439
- package/dist/services/memoryStore.d.ts +0 -81
- package/dist/services/memoryStore.d.ts.map +0 -1
- package/dist/services/memoryStore.js +0 -200
- package/dist/types/memoryStore.d.ts +0 -82
- package/dist/types/memoryStore.d.ts.map +0 -1
- package/dist/types/memoryStore.js +0 -7
- package/dist/utils/configResolver.d.ts +0 -65
- package/dist/utils/configResolver.d.ts.map +0 -1
- package/dist/utils/configResolver.js +0 -210
- package/src/constants/events.ts +0 -38
- package/src/services/configurationWatcher.ts +0 -622
- package/src/services/memoryStore.ts +0 -279
- package/src/types/memoryStore.ts +0 -94
- package/src/utils/configResolver.ts +0 -302
|
@@ -50,12 +50,19 @@ function getModelConfig(modelName, baseConfig = {}) {
|
|
|
50
50
|
return config;
|
|
51
51
|
}
|
|
52
52
|
export async function callAgent(options) {
|
|
53
|
-
const { gatewayConfig, modelConfig, messages, abortSignal, memory, workdir, tools, model, systemPrompt, onContentUpdate, onToolUpdate, } = options;
|
|
53
|
+
const { gatewayConfig, modelConfig, messages, abortSignal, memory, workdir, tools, model, systemPrompt, onContentUpdate, onToolUpdate, onReasoningUpdate, } = options;
|
|
54
|
+
// Declare variables outside try block for error handling access
|
|
55
|
+
let openaiMessages;
|
|
56
|
+
let createParams;
|
|
57
|
+
let processedTools;
|
|
54
58
|
try {
|
|
55
59
|
// Create OpenAI client with injected configuration
|
|
56
60
|
const openai = new OpenAI({
|
|
57
61
|
apiKey: gatewayConfig.apiKey,
|
|
58
62
|
baseURL: gatewayConfig.baseURL,
|
|
63
|
+
defaultHeaders: gatewayConfig.defaultHeaders,
|
|
64
|
+
fetchOptions: gatewayConfig.fetchOptions,
|
|
65
|
+
fetch: gatewayConfig.fetch,
|
|
59
66
|
});
|
|
60
67
|
// Build system prompt content
|
|
61
68
|
let systemContent = systemPrompt ||
|
|
@@ -89,36 +96,34 @@ Today's date: ${new Date().toISOString().split("T")[0]}
|
|
|
89
96
|
content: systemContent,
|
|
90
97
|
};
|
|
91
98
|
// ChatCompletionMessageParam[] is already in OpenAI format, add system prompt to the beginning
|
|
92
|
-
|
|
93
|
-
systemMessage,
|
|
94
|
-
...messages,
|
|
95
|
-
];
|
|
99
|
+
openaiMessages = [systemMessage, ...messages];
|
|
96
100
|
// Apply cache control for Claude models
|
|
97
101
|
const currentModel = model || modelConfig.agentModel;
|
|
102
|
+
processedTools = tools;
|
|
98
103
|
if (isClaudeModel(currentModel)) {
|
|
99
104
|
openaiMessages = transformMessagesForClaudeCache(openaiMessages, currentModel);
|
|
105
|
+
// Apply cache control to tools separately
|
|
106
|
+
if (tools && tools.length > 0) {
|
|
107
|
+
processedTools = addCacheControlToLastTool(tools);
|
|
108
|
+
}
|
|
100
109
|
}
|
|
101
110
|
// Get model configuration - use injected modelConfig with optional override
|
|
102
111
|
const openaiModelConfig = getModelConfig(model || modelConfig.agentModel, {
|
|
103
112
|
temperature: 0,
|
|
104
113
|
});
|
|
105
114
|
// Determine if streaming is needed
|
|
106
|
-
const isStreaming = !!(onContentUpdate ||
|
|
115
|
+
const isStreaming = !!(onContentUpdate ||
|
|
116
|
+
onToolUpdate ||
|
|
117
|
+
onReasoningUpdate);
|
|
107
118
|
// Prepare API call parameters
|
|
108
|
-
|
|
119
|
+
createParams = {
|
|
109
120
|
...openaiModelConfig,
|
|
110
121
|
messages: openaiMessages,
|
|
111
122
|
stream: isStreaming,
|
|
112
123
|
};
|
|
113
124
|
// Only add tools if they exist
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
if (isClaudeModel(currentModel)) {
|
|
117
|
-
createParams.tools = addCacheControlToLastTool(tools);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
createParams.tools = tools;
|
|
121
|
-
}
|
|
125
|
+
if (processedTools && processedTools.length > 0) {
|
|
126
|
+
createParams.tools = processedTools;
|
|
122
127
|
}
|
|
123
128
|
if (isStreaming) {
|
|
124
129
|
// Handle streaming response
|
|
@@ -132,7 +137,7 @@ Today's date: ${new Date().toISOString().split("T")[0]}
|
|
|
132
137
|
response.headers.forEach((value, key) => {
|
|
133
138
|
responseHeaders[key] = value;
|
|
134
139
|
});
|
|
135
|
-
return await processStreamingResponse(stream, onContentUpdate, onToolUpdate, abortSignal, responseHeaders, currentModel);
|
|
140
|
+
return await processStreamingResponse(stream, onContentUpdate, onToolUpdate, onReasoningUpdate, abortSignal, responseHeaders, currentModel);
|
|
136
141
|
}
|
|
137
142
|
else {
|
|
138
143
|
// Handle non-streaming response
|
|
@@ -161,22 +166,26 @@ Today's date: ${new Date().toISOString().split("T")[0]}
|
|
|
161
166
|
}
|
|
162
167
|
const result = {};
|
|
163
168
|
if (finalMessage) {
|
|
164
|
-
const { content: finalContent, tool_calls: finalToolCalls, ...otherFields } = finalMessage;
|
|
169
|
+
const { content: finalContent, tool_calls: finalToolCalls, reasoning_content: finalReasoningContent, ...otherFields } = finalMessage;
|
|
165
170
|
if (typeof finalContent === "string" && finalContent.length > 0) {
|
|
166
171
|
result.content = finalContent;
|
|
167
172
|
}
|
|
173
|
+
if (typeof finalReasoningContent === "string" &&
|
|
174
|
+
finalReasoningContent.length > 0) {
|
|
175
|
+
result.reasoning_content = finalReasoningContent;
|
|
176
|
+
}
|
|
168
177
|
if (Array.isArray(finalToolCalls) && finalToolCalls.length > 0) {
|
|
169
178
|
result.tool_calls = finalToolCalls;
|
|
170
179
|
}
|
|
171
180
|
if (Object.keys(otherFields).length > 0) {
|
|
172
|
-
const
|
|
181
|
+
const additionalFields = {};
|
|
173
182
|
for (const [key, value] of Object.entries(otherFields)) {
|
|
174
|
-
if (value !== undefined) {
|
|
175
|
-
|
|
183
|
+
if (value !== undefined && key !== "role") {
|
|
184
|
+
additionalFields[key] = value;
|
|
176
185
|
}
|
|
177
186
|
}
|
|
178
|
-
if (Object.keys(
|
|
179
|
-
result.
|
|
187
|
+
if (Object.keys(additionalFields).length > 0) {
|
|
188
|
+
result.additionalFields = additionalFields;
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
}
|
|
@@ -196,6 +205,76 @@ Today's date: ${new Date().toISOString().split("T")[0]}
|
|
|
196
205
|
if (error.name === "AbortError") {
|
|
197
206
|
throw new Error("Request was aborted");
|
|
198
207
|
}
|
|
208
|
+
// Check if it's a 400 error and save messages to temp directory
|
|
209
|
+
if (error &&
|
|
210
|
+
typeof error === "object" &&
|
|
211
|
+
"status" in error &&
|
|
212
|
+
error.status === 400) {
|
|
213
|
+
try {
|
|
214
|
+
// Create temp directory for error debugging
|
|
215
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "callAgent-400-error-"));
|
|
216
|
+
const messagesFile = path.join(tempDir, "messages.json");
|
|
217
|
+
const errorFile = path.join(tempDir, "error.json");
|
|
218
|
+
// Save complete messages to temp file
|
|
219
|
+
const debugData = {
|
|
220
|
+
originalMessages: messages,
|
|
221
|
+
timestamp: new Date().toISOString(),
|
|
222
|
+
model: model || modelConfig.agentModel,
|
|
223
|
+
workdir,
|
|
224
|
+
sessionId: options.sessionId,
|
|
225
|
+
gatewayConfig: {
|
|
226
|
+
baseURL: gatewayConfig.baseURL,
|
|
227
|
+
// Don't include apiKey for security
|
|
228
|
+
defaultHeaders: gatewayConfig.defaultHeaders,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
// Add processed messages if they exist
|
|
232
|
+
if (typeof openaiMessages !== "undefined") {
|
|
233
|
+
debugData.processedMessages = openaiMessages;
|
|
234
|
+
}
|
|
235
|
+
// Add create params if they exist
|
|
236
|
+
if (typeof createParams !== "undefined") {
|
|
237
|
+
debugData.createParams = createParams;
|
|
238
|
+
}
|
|
239
|
+
// Add tools if they exist
|
|
240
|
+
if (processedTools) {
|
|
241
|
+
debugData.tools = processedTools;
|
|
242
|
+
}
|
|
243
|
+
fs.writeFileSync(messagesFile, JSON.stringify(debugData, null, 2));
|
|
244
|
+
// Save error details
|
|
245
|
+
const errorData = {
|
|
246
|
+
error: {
|
|
247
|
+
message: error && typeof error === "object" && "message" in error
|
|
248
|
+
? String(error.message)
|
|
249
|
+
: undefined,
|
|
250
|
+
status: error && typeof error === "object" && "status" in error
|
|
251
|
+
? Number(error.status)
|
|
252
|
+
: undefined,
|
|
253
|
+
type: error && typeof error === "object" && "type" in error
|
|
254
|
+
? String(error.type)
|
|
255
|
+
: undefined,
|
|
256
|
+
code: error && typeof error === "object" && "code" in error
|
|
257
|
+
? String(error.code)
|
|
258
|
+
: undefined,
|
|
259
|
+
body: error && typeof error === "object" && "body" in error
|
|
260
|
+
? error.body
|
|
261
|
+
: undefined,
|
|
262
|
+
stack: error && typeof error === "object" && "stack" in error
|
|
263
|
+
? String(error.stack)
|
|
264
|
+
: undefined,
|
|
265
|
+
},
|
|
266
|
+
timestamp: new Date().toISOString(),
|
|
267
|
+
};
|
|
268
|
+
fs.writeFileSync(errorFile, JSON.stringify(errorData, null, 2));
|
|
269
|
+
logger.error("callAgent 400 error occurred. Debug files saved to:", tempDir);
|
|
270
|
+
logger.error("Messages file:", messagesFile);
|
|
271
|
+
logger.error("Error file:", errorFile);
|
|
272
|
+
logger.error("Error details:", error);
|
|
273
|
+
}
|
|
274
|
+
catch (saveError) {
|
|
275
|
+
logger.error("Failed to save 400 error debug files:", saveError);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
199
278
|
logger.error("Failed to call OpenAI:", error);
|
|
200
279
|
throw error;
|
|
201
280
|
}
|
|
@@ -210,8 +289,9 @@ Today's date: ${new Date().toISOString().split("T")[0]}
|
|
|
210
289
|
* @param modelName Model name for cache control processing
|
|
211
290
|
* @returns Final result with accumulated content and tool calls
|
|
212
291
|
*/
|
|
213
|
-
async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, abortSignal, responseHeaders, modelName) {
|
|
292
|
+
async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, onReasoningUpdate, abortSignal, responseHeaders, modelName) {
|
|
214
293
|
let accumulatedContent = "";
|
|
294
|
+
let accumulatedReasoningContent = "";
|
|
215
295
|
const toolCalls = [];
|
|
216
296
|
const additionalDeltaFields = {};
|
|
217
297
|
let usage = undefined;
|
|
@@ -244,7 +324,7 @@ async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, a
|
|
|
244
324
|
if (!delta) {
|
|
245
325
|
continue;
|
|
246
326
|
}
|
|
247
|
-
const { content, tool_calls: toolCallUpdates, ...deltaMetadata } = delta;
|
|
327
|
+
const { content, tool_calls: toolCallUpdates, reasoning_content, ...deltaMetadata } = delta;
|
|
248
328
|
if (Object.keys(deltaMetadata).length > 0) {
|
|
249
329
|
Object.assign(additionalDeltaFields, deltaMetadata);
|
|
250
330
|
}
|
|
@@ -256,6 +336,13 @@ async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, a
|
|
|
256
336
|
onContentUpdate(accumulatedContent);
|
|
257
337
|
}
|
|
258
338
|
}
|
|
339
|
+
if (typeof reasoning_content === "string" &&
|
|
340
|
+
reasoning_content.length > 0) {
|
|
341
|
+
accumulatedReasoningContent += reasoning_content;
|
|
342
|
+
if (onReasoningUpdate) {
|
|
343
|
+
onReasoningUpdate(accumulatedReasoningContent);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
259
346
|
if (Array.isArray(toolCallUpdates)) {
|
|
260
347
|
for (const rawToolCall of toolCallUpdates) {
|
|
261
348
|
const toolCallDelta = rawToolCall;
|
|
@@ -330,7 +417,10 @@ async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, a
|
|
|
330
417
|
// Prepare final result
|
|
331
418
|
const result = {};
|
|
332
419
|
if (accumulatedContent) {
|
|
333
|
-
result.content = accumulatedContent;
|
|
420
|
+
result.content = accumulatedContent.trim();
|
|
421
|
+
}
|
|
422
|
+
if (accumulatedReasoningContent) {
|
|
423
|
+
result.reasoning_content = accumulatedReasoningContent.trim();
|
|
334
424
|
}
|
|
335
425
|
if (toolCalls.length > 0) {
|
|
336
426
|
result.tool_calls = toolCalls;
|
|
@@ -345,14 +435,14 @@ async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, a
|
|
|
345
435
|
result.response_headers = responseHeaders;
|
|
346
436
|
}
|
|
347
437
|
if (Object.keys(additionalDeltaFields).length > 0) {
|
|
348
|
-
result.
|
|
438
|
+
result.additionalFields = {};
|
|
349
439
|
for (const [key, value] of Object.entries(additionalDeltaFields)) {
|
|
350
|
-
if (value !== undefined) {
|
|
351
|
-
result.
|
|
440
|
+
if (value !== undefined && key !== "role") {
|
|
441
|
+
result.additionalFields[key] = value;
|
|
352
442
|
}
|
|
353
443
|
}
|
|
354
|
-
if (Object.keys(result.
|
|
355
|
-
delete result.
|
|
444
|
+
if (Object.keys(result.additionalFields).length === 0) {
|
|
445
|
+
delete result.additionalFields;
|
|
356
446
|
}
|
|
357
447
|
}
|
|
358
448
|
return result;
|
|
@@ -363,6 +453,9 @@ export async function compressMessages(options) {
|
|
|
363
453
|
const openai = new OpenAI({
|
|
364
454
|
apiKey: gatewayConfig.apiKey,
|
|
365
455
|
baseURL: gatewayConfig.baseURL,
|
|
456
|
+
defaultHeaders: gatewayConfig.defaultHeaders,
|
|
457
|
+
fetchOptions: gatewayConfig.fetchOptions,
|
|
458
|
+
fetch: gatewayConfig.fetch,
|
|
366
459
|
});
|
|
367
460
|
// Get model configuration - use injected fast model
|
|
368
461
|
const openaiModelConfig = getModelConfig(modelConfig.fastModel, {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Service
|
|
3
|
+
*
|
|
4
|
+
* Centralized service for loading, validating, and managing Wave configuration files.
|
|
5
|
+
* Replaces distributed configuration logic previously embedded in hook.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { WaveConfiguration } from "../types/hooks.js";
|
|
8
|
+
import type { ConfigurationLoadResult, ValidationResult, ConfigurationPaths } from "../types/configuration.js";
|
|
9
|
+
import { type EnvironmentValidationResult, type MergedEnvironmentContext, type EnvironmentMergeOptions } from "../types/environment.js";
|
|
10
|
+
import { GatewayConfig, ModelConfig } from "../types/index.js";
|
|
11
|
+
import { ClientOptions } from "openai";
|
|
12
|
+
/**
|
|
13
|
+
* Default ConfigurationService implementation
|
|
14
|
+
*
|
|
15
|
+
* Provides centralized configuration loading, validation, and management.
|
|
16
|
+
* Extracted from distributed logic in hook.ts with improved error handling.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ConfigurationService {
|
|
19
|
+
private currentConfiguration;
|
|
20
|
+
private env;
|
|
21
|
+
/**
|
|
22
|
+
* Load and merge configuration with comprehensive validation
|
|
23
|
+
*/
|
|
24
|
+
loadMergedConfiguration(workdir: string): Promise<ConfigurationLoadResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Validate configuration object structure and values
|
|
27
|
+
*/
|
|
28
|
+
validateConfiguration(config: WaveConfiguration): ValidationResult;
|
|
29
|
+
/**
|
|
30
|
+
* Validate configuration file without loading
|
|
31
|
+
*/
|
|
32
|
+
validateConfigurationFile(filePath: string): ValidationResult;
|
|
33
|
+
/**
|
|
34
|
+
* Get currently loaded configuration
|
|
35
|
+
*/
|
|
36
|
+
getCurrentConfiguration(): WaveConfiguration | null;
|
|
37
|
+
/**
|
|
38
|
+
* Set environment variables from configuration
|
|
39
|
+
* This replaces direct process.env modification
|
|
40
|
+
*/
|
|
41
|
+
setEnvironmentVars(env: Record<string, string>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get current environment variables
|
|
44
|
+
*/
|
|
45
|
+
getEnvironmentVars(): Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Resolves gateway configuration from constructor args and environment
|
|
48
|
+
* Resolution priority: options > env (from settings.json) > process.env > error
|
|
49
|
+
* @param apiKey - API key from constructor (optional)
|
|
50
|
+
* @param baseURL - Base URL from constructor (optional)
|
|
51
|
+
* @param defaultHeaders - HTTP headers from constructor (optional)
|
|
52
|
+
* @param fetchOptions - Fetch options from constructor (optional)
|
|
53
|
+
* @param fetch - Custom fetch implementation from constructor (optional)
|
|
54
|
+
* @returns Resolved gateway configuration
|
|
55
|
+
* @throws ConfigurationError if required configuration is missing after fallbacks
|
|
56
|
+
*/
|
|
57
|
+
resolveGatewayConfig(apiKey?: string, baseURL?: string, defaultHeaders?: Record<string, string>, fetchOptions?: ClientOptions["fetchOptions"], fetch?: ClientOptions["fetch"]): GatewayConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Resolves model configuration with fallbacks
|
|
60
|
+
* Resolution priority: options > env (from settings.json) > process.env > default
|
|
61
|
+
* @param agentModel - Agent model from constructor (optional)
|
|
62
|
+
* @param fastModel - Fast model from constructor (optional)
|
|
63
|
+
* @returns Resolved model configuration with defaults
|
|
64
|
+
*/
|
|
65
|
+
resolveModelConfig(agentModel?: string, fastModel?: string): ModelConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Resolves token limit with fallbacks
|
|
68
|
+
* Resolution priority: options > env (from settings.json) > process.env > default
|
|
69
|
+
* @param constructorLimit - Token limit from constructor (optional)
|
|
70
|
+
* @returns Resolved token limit
|
|
71
|
+
*/
|
|
72
|
+
resolveTokenLimit(constructorLimit?: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve all configuration file paths
|
|
75
|
+
*/
|
|
76
|
+
getConfigurationPaths(workdir: string): ConfigurationPaths;
|
|
77
|
+
/**
|
|
78
|
+
* Add a permission rule to the project's settings.local.json
|
|
79
|
+
*/
|
|
80
|
+
addAllowedRule(workdir: string, rule: string): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validate environment variable configuration
|
|
84
|
+
*/
|
|
85
|
+
export declare function validateEnvironmentConfig(env: unknown, configPath?: string): EnvironmentValidationResult;
|
|
86
|
+
/**
|
|
87
|
+
* Merge environment configurations with project taking precedence over user
|
|
88
|
+
*/
|
|
89
|
+
export declare function mergeEnvironmentConfig(userEnv: Record<string, string> | undefined, projectEnv: Record<string, string> | undefined, options?: EnvironmentMergeOptions): MergedEnvironmentContext;
|
|
90
|
+
/**
|
|
91
|
+
* Load Wave configuration from a JSON file
|
|
92
|
+
* Supports both hooks and environment variables with proper validation
|
|
93
|
+
*/
|
|
94
|
+
export declare function loadWaveConfigFromFile(filePath: string): WaveConfiguration | null;
|
|
95
|
+
/**
|
|
96
|
+
* Load Wave configuration from multiple file paths in priority order
|
|
97
|
+
* Returns the first valid configuration found, or null if none exist
|
|
98
|
+
*/
|
|
99
|
+
export declare function loadWaveConfigFromFiles(filePaths: string[]): WaveConfiguration | null;
|
|
100
|
+
/**
|
|
101
|
+
* Load user-specific Wave configuration
|
|
102
|
+
* Checks .local.json first, then falls back to .json
|
|
103
|
+
*/
|
|
104
|
+
export declare function loadUserWaveConfig(): WaveConfiguration | null;
|
|
105
|
+
/**
|
|
106
|
+
* Load project-specific Wave configuration
|
|
107
|
+
* Checks .local.json first, then falls back to .json
|
|
108
|
+
*/
|
|
109
|
+
export declare function loadProjectWaveConfig(workdir: string): WaveConfiguration | null;
|
|
110
|
+
/**
|
|
111
|
+
* Load and merge Wave configuration from both user and project sources
|
|
112
|
+
* Project configuration takes precedence over user configuration
|
|
113
|
+
* Checks .local.json files first, then falls back to .json files
|
|
114
|
+
*/
|
|
115
|
+
export declare function loadMergedWaveConfig(workdir: string): WaveConfiguration | null;
|
|
116
|
+
//# sourceMappingURL=configurationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurationService.d.ts","sourceRoot":"","sources":["../../src/services/configurationService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EACV,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAE7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,aAAa,EACb,WAAW,EAGZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,GAAG,CAA8B;IAIzC;;OAEG;IACG,uBAAuB,CAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,uBAAuB,CAAC;IA0EnC;;OAEG;IACH,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB;IA8FlE;;OAEG;IACH,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAwC7D;;OAEG;IACH,uBAAuB,IAAI,iBAAiB,GAAG,IAAI;IAInD;;;OAGG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAIrD;;OAEG;IACH,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQ5C;;;;;;;;;;OAUG;IACH,oBAAoB,CAClB,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,YAAY,CAAC,EAAE,aAAa,CAAC,cAAc,CAAC,EAC5C,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAC7B,aAAa;IA4DhB;;;;;;OAMG;IACH,kBAAkB,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW;IAyBxE;;;;;OAKG;IACH,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM;IAmBpD;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB;IAY1D;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmCnE;AAKD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,2BAA2B,CAsD7B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC9C,OAAO,GAAE,uBAA4B,GACpC,wBAAwB,CAoC1B;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,GACf,iBAAiB,GAAG,IAAI,CA8C1B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EAAE,GAClB,iBAAiB,GAAG,IAAI,CAQ1B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,GAAG,IAAI,CAE7D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GACd,iBAAiB,GAAG,IAAI,CAE1B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,GACd,iBAAiB,GAAG,IAAI,CAsE1B"}
|