@office-ai/aioncli-core 0.1.21 → 0.2.3
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/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/src/code_assist/converter.d.ts +3 -2
- package/dist/src/code_assist/converter.js +1 -0
- package/dist/src/code_assist/converter.js.map +1 -1
- package/dist/src/code_assist/oauth2.d.ts +2 -0
- package/dist/src/code_assist/oauth2.js +47 -25
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +99 -8
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.js +1 -1
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/setup.js +48 -17
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js +114 -8
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/config/config.d.ts +27 -8
- package/dist/src/config/config.js +56 -25
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +109 -1
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/client.d.ts +18 -15
- package/dist/src/core/client.js +275 -63
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +631 -36
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +20 -12
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +39 -15
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.d.ts +2 -1
- package/dist/src/core/coreToolScheduler.js +26 -4
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +230 -71
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +11 -1
- package/dist/src/core/geminiChat.js +85 -11
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/logger.d.ts +22 -1
- package/dist/src/core/logger.js +103 -17
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/logger.test.js +86 -20
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.d.ts +1 -0
- package/dist/src/core/loggingContentGenerator.js +7 -1
- package/dist/src/core/loggingContentGenerator.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +2 -2
- package/dist/src/core/nonInteractiveToolExecutor.js +11 -3
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +95 -46
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/openaiContentGenerator.js +71 -25
- package/dist/src/core/openaiContentGenerator.js.map +1 -1
- package/dist/src/core/openaiContentGenerator.test.js +1 -1
- package/dist/src/core/openaiContentGenerator.test.js.map +1 -1
- package/dist/src/core/prompts.js +4 -4
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/subagent.js +5 -5
- package/dist/src/core/subagent.js.map +1 -1
- package/dist/src/core/subagent.test.js +3 -3
- package/dist/src/core/subagent.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +7 -0
- package/dist/src/generated/git-commit.js +10 -0
- package/dist/src/generated/git-commit.js.map +1 -0
- package/dist/src/ide/constants.d.ts +6 -0
- package/dist/src/ide/constants.js +7 -0
- package/dist/src/ide/constants.js.map +1 -0
- package/dist/src/ide/detect-ide.d.ts +12 -2
- package/dist/src/ide/detect-ide.js +64 -5
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.d.ts +6 -0
- package/dist/src/ide/detect-ide.test.js +65 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +9 -1
- package/dist/src/ide/ide-client.js +113 -30
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.d.ts +6 -0
- package/dist/src/ide/ide-client.test.js +43 -0
- package/dist/src/ide/ide-client.test.js.map +1 -0
- package/dist/src/ide/ide-installer.js +23 -34
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +6 -8
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/ide/ideContext.d.ts +42 -42
- package/dist/src/ide/process-utils.d.ts +19 -0
- package/dist/src/ide/process-utils.js +140 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.js +6 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.js +9 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.test.js +45 -10
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +0 -1
- package/dist/src/mcp/oauth-provider.js +176 -59
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +132 -62
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +3 -1
- package/dist/src/mcp/oauth-utils.js +50 -12
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +17 -2
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- package/dist/src/mocks/msw.d.ts +6 -0
- package/dist/src/mocks/msw.js +8 -0
- package/dist/src/mocks/msw.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +150 -0
- package/dist/src/services/chatRecordingService.js +318 -0
- package/dist/src/services/chatRecordingService.js.map +1 -0
- package/dist/src/services/chatRecordingService.test.d.ts +6 -0
- package/dist/src/services/chatRecordingService.test.js +288 -0
- package/dist/src/services/chatRecordingService.test.js.map +1 -0
- package/dist/src/services/fileSystemService.d.ts +31 -0
- package/dist/src/services/fileSystemService.js +18 -0
- package/dist/src/services/fileSystemService.js.map +1 -0
- package/dist/src/services/fileSystemService.test.d.ts +6 -0
- package/dist/src/services/fileSystemService.test.js +41 -0
- package/dist/src/services/fileSystemService.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.js +9 -10
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/loopDetectionService.test.js +52 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +8 -10
- package/dist/src/services/shellExecutionService.js +289 -133
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +274 -30
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +61 -17
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +211 -233
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +11 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +250 -94
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +9 -2
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +19 -9
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +1 -0
- package/dist/src/telemetry/constants.js +1 -0
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.js +2 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/integration.test.circular.js +1 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +3 -1
- package/dist/src/telemetry/loggers.js +39 -6
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +37 -7
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +5 -1
- package/dist/src/telemetry/metrics.js +23 -9
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +31 -1
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/sdk.d.ts +1 -1
- package/dist/src/telemetry/sdk.js +80 -44
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/sdk.test.d.ts +6 -0
- package/dist/src/telemetry/sdk.test.js +82 -0
- package/dist/src/telemetry/sdk.test.js.map +1 -0
- package/dist/src/telemetry/telemetry.test.js +2 -2
- package/dist/src/telemetry/telemetry.test.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +41 -14
- package/dist/src/telemetry/types.js +52 -23
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +4 -0
- package/dist/src/telemetry/uiTelemetry.js +14 -1
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +45 -9
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/config.d.ts +16 -0
- package/dist/src/test-utils/config.js +32 -0
- package/dist/src/test-utils/config.js.map +1 -0
- package/dist/src/test-utils/tools.d.ts +29 -8
- package/dist/src/test-utils/tools.js +80 -16
- package/dist/src/test-utils/tools.js.map +1 -1
- package/dist/src/tools/edit.d.ts +1 -1
- package/dist/src/tools/edit.js +23 -19
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +11 -3
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.d.ts +1 -1
- package/dist/src/tools/glob.js +15 -16
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +20 -0
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.d.ts +1 -1
- package/dist/src/tools/grep.js +7 -13
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/ls.d.ts +4 -23
- package/dist/src/tools/ls.js +77 -79
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/ls.test.js +62 -34
- package/dist/src/tools/ls.test.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +38 -0
- package/dist/src/tools/mcp-client-manager.js +74 -0
- package/dist/src/tools/mcp-client-manager.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
- package/dist/src/tools/mcp-client-manager.test.js +39 -0
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +43 -0
- package/dist/src/tools/mcp-client.js +157 -11
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +62 -276
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +6 -13
- package/dist/src/tools/mcp-tool.js +62 -34
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +118 -59
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +9 -13
- package/dist/src/tools/memoryTool.js +122 -121
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/memoryTool.test.js +38 -18
- package/dist/src/tools/memoryTool.test.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +1 -1
- package/dist/src/tools/read-file.js +20 -18
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +8 -0
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +3 -5
- package/dist/src/tools/read-many-files.js +121 -105
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +94 -37
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/shell.d.ts +4 -6
- package/dist/src/tools/shell.js +120 -124
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +63 -65
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/tool-error.d.ts +1 -0
- package/dist/src/tools/tool-error.js +1 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +14 -18
- package/dist/src/tools/tool-registry.js +73 -106
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +24 -192
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +33 -89
- package/dist/src/tools/tools.js +76 -119
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/tools.test.js +91 -2
- package/dist/src/tools/tools.test.js.map +1 -1
- package/dist/src/tools/web-fetch.d.ts +4 -7
- package/dist/src/tools/web-fetch.js +58 -64
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +8 -4
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.d.ts +4 -5
- package/dist/src/tools/web-search.js +47 -51
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/web-search.test.d.ts +6 -0
- package/dist/src/tools/web-search.test.js +139 -0
- package/dist/src/tools/web-search.test.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +15 -10
- package/dist/src/tools/write-file.js +134 -145
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-file.test.js +82 -127
- package/dist/src/tools/write-file.test.js.map +1 -1
- package/dist/src/utils/browser.js +4 -3
- package/dist/src/utils/browser.js.map +1 -1
- package/dist/src/utils/editCorrector.js +21 -22
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editor.js +1 -1
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +10 -10
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/environmentContext.js +2 -2
- package/dist/src/utils/environmentContext.js.map +1 -1
- package/dist/src/utils/environmentContext.test.js +3 -2
- package/dist/src/utils/environmentContext.test.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +8 -0
- package/dist/src/utils/errorParsing.js +93 -0
- package/dist/src/utils/errorParsing.js.map +1 -0
- package/dist/src/utils/errorParsing.test.d.ts +6 -0
- package/dist/src/utils/errorParsing.test.js +172 -0
- package/dist/src/utils/errorParsing.test.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +2 -1
- package/dist/src/utils/fileUtils.js +3 -3
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/fileUtils.test.js +18 -17
- package/dist/src/utils/fileUtils.test.js.map +1 -1
- package/dist/src/utils/filesearch/crawler.d.ts +15 -0
- package/dist/src/utils/filesearch/crawler.js +50 -0
- package/dist/src/utils/filesearch/crawler.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawler.test.js +468 -0
- package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.d.ts +9 -53
- package/dist/src/utils/filesearch/fileSearch.js +63 -118
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
- package/dist/src/utils/filesearch/fileSearch.test.js +95 -197
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
- package/dist/src/utils/filesearch/ignore.d.ts +7 -0
- package/dist/src/utils/filesearch/ignore.js +25 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -1
- package/dist/src/utils/filesearch/ignore.test.js +89 -2
- package/dist/src/utils/filesearch/ignore.test.js.map +1 -1
- package/dist/src/utils/filesearch/result-cache.d.ts +1 -2
- package/dist/src/utils/filesearch/result-cache.js +1 -3
- package/dist/src/utils/filesearch/result-cache.js.map +1 -1
- package/dist/src/utils/filesearch/result-cache.test.js +3 -4
- package/dist/src/utils/filesearch/result-cache.test.js.map +1 -1
- package/dist/src/utils/getPty.d.ts +19 -0
- package/dist/src/utils/getPty.js +23 -0
- package/dist/src/utils/getPty.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.js +3 -3
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +3 -2
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +3 -7
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +17 -20
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/nextSpeakerChecker.js +3 -4
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
- package/dist/src/utils/paths.d.ts +7 -0
- package/dist/src/utils/paths.js +15 -0
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/paths.test.js +74 -2
- package/dist/src/utils/paths.test.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.d.ts +1 -5
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.js +40 -0
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/schemaValidator.d.ts +1 -8
- package/dist/src/utils/schemaValidator.js +1 -32
- package/dist/src/utils/schemaValidator.js.map +1 -1
- package/dist/src/utils/secure-browser-launcher.js +4 -3
- package/dist/src/utils/secure-browser-launcher.js.map +1 -1
- package/dist/src/utils/shell-utils.d.ts +39 -0
- package/dist/src/utils/shell-utils.js +72 -2
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +132 -4
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/systemEncoding.js +1 -1
- package/dist/src/utils/systemEncoding.js.map +1 -1
- package/dist/src/utils/systemEncoding.test.js +23 -23
- package/dist/src/utils/systemEncoding.test.js.map +1 -1
- package/dist/src/utils/user_account.js +58 -48
- package/dist/src/utils/user_account.js.map +1 -1
- package/dist/src/utils/user_account.test.js +76 -9
- package/dist/src/utils/user_account.test.js.map +1 -1
- package/dist/src/utils/workspaceContext.d.ts +22 -7
- package/dist/src/utils/workspaceContext.js +81 -55
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/src/utils/workspaceContext.test.js +221 -137
- package/dist/src/utils/workspaceContext.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -8
|
@@ -5,22 +5,29 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
7
|
import { executeToolCall } from './nonInteractiveToolExecutor.js';
|
|
8
|
+
import { ToolErrorType, } from '../index.js';
|
|
8
9
|
import { MockTool } from '../test-utils/tools.js';
|
|
9
|
-
const mockConfig = {
|
|
10
|
-
getSessionId: () => 'test-session-id',
|
|
11
|
-
getUsageStatisticsEnabled: () => true,
|
|
12
|
-
getDebugMode: () => false,
|
|
13
|
-
};
|
|
14
10
|
describe('executeToolCall', () => {
|
|
15
11
|
let mockToolRegistry;
|
|
16
12
|
let mockTool;
|
|
17
13
|
let abortController;
|
|
14
|
+
let mockConfig;
|
|
18
15
|
beforeEach(() => {
|
|
19
16
|
mockTool = new MockTool();
|
|
20
17
|
mockToolRegistry = {
|
|
21
18
|
getTool: vi.fn(),
|
|
22
19
|
// Add other ToolRegistry methods if needed, or use a more complete mock
|
|
23
20
|
};
|
|
21
|
+
mockConfig = {
|
|
22
|
+
getSessionId: () => 'test-session-id',
|
|
23
|
+
getUsageStatisticsEnabled: () => true,
|
|
24
|
+
getDebugMode: () => false,
|
|
25
|
+
getContentGeneratorConfig: () => ({
|
|
26
|
+
model: 'test-model',
|
|
27
|
+
authType: 'oauth-personal',
|
|
28
|
+
}),
|
|
29
|
+
getToolRegistry: () => mockToolRegistry,
|
|
30
|
+
};
|
|
24
31
|
abortController = new AbortController();
|
|
25
32
|
});
|
|
26
33
|
it('should execute a tool successfully', async () => {
|
|
@@ -36,10 +43,10 @@ describe('executeToolCall', () => {
|
|
|
36
43
|
returnDisplay: 'Success!',
|
|
37
44
|
};
|
|
38
45
|
vi.mocked(mockToolRegistry.getTool).mockReturnValue(mockTool);
|
|
39
|
-
vi.spyOn(mockTool, '
|
|
40
|
-
const response = await executeToolCall(mockConfig, request,
|
|
46
|
+
vi.spyOn(mockTool, 'validateBuildAndExecute').mockResolvedValue(toolResult);
|
|
47
|
+
const response = await executeToolCall(mockConfig, request, abortController.signal);
|
|
41
48
|
expect(mockToolRegistry.getTool).toHaveBeenCalledWith('testTool');
|
|
42
|
-
expect(mockTool.
|
|
49
|
+
expect(mockTool.validateBuildAndExecute).toHaveBeenCalledWith(request.args, abortController.signal);
|
|
43
50
|
expect(response.callId).toBe('call1');
|
|
44
51
|
expect(response.error).toBeUndefined();
|
|
45
52
|
expect(response.resultDisplay).toBe('Success!');
|
|
@@ -60,7 +67,7 @@ describe('executeToolCall', () => {
|
|
|
60
67
|
prompt_id: 'prompt-id-2',
|
|
61
68
|
};
|
|
62
69
|
vi.mocked(mockToolRegistry.getTool).mockReturnValue(undefined);
|
|
63
|
-
const response = await executeToolCall(mockConfig, request,
|
|
70
|
+
const response = await executeToolCall(mockConfig, request, abortController.signal);
|
|
64
71
|
expect(response.callId).toBe('call2');
|
|
65
72
|
expect(response.error).toBeInstanceOf(Error);
|
|
66
73
|
expect(response.error?.message).toBe('Tool "nonexistentTool" not found in registry.');
|
|
@@ -75,32 +82,42 @@ describe('executeToolCall', () => {
|
|
|
75
82
|
},
|
|
76
83
|
]);
|
|
77
84
|
});
|
|
78
|
-
it('should return an error if tool
|
|
85
|
+
it('should return an error if tool validation fails', async () => {
|
|
79
86
|
const request = {
|
|
80
87
|
callId: 'call3',
|
|
81
88
|
name: 'testTool',
|
|
82
|
-
args: { param1: '
|
|
89
|
+
args: { param1: 'invalid' },
|
|
83
90
|
isClientInitiated: false,
|
|
84
91
|
prompt_id: 'prompt-id-3',
|
|
85
92
|
};
|
|
86
|
-
const
|
|
93
|
+
const validationErrorResult = {
|
|
94
|
+
llmContent: 'Error: Invalid parameters',
|
|
95
|
+
returnDisplay: 'Invalid parameters',
|
|
96
|
+
error: {
|
|
97
|
+
message: 'Invalid parameters',
|
|
98
|
+
type: ToolErrorType.INVALID_TOOL_PARAMS,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
87
101
|
vi.mocked(mockToolRegistry.getTool).mockReturnValue(mockTool);
|
|
88
|
-
vi.spyOn(mockTool, '
|
|
89
|
-
const response = await executeToolCall(mockConfig, request,
|
|
90
|
-
expect(response
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
102
|
+
vi.spyOn(mockTool, 'validateBuildAndExecute').mockResolvedValue(validationErrorResult);
|
|
103
|
+
const response = await executeToolCall(mockConfig, request, abortController.signal);
|
|
104
|
+
expect(response).toStrictEqual({
|
|
105
|
+
callId: 'call3',
|
|
106
|
+
error: new Error('Invalid parameters'),
|
|
107
|
+
errorType: ToolErrorType.INVALID_TOOL_PARAMS,
|
|
108
|
+
responseParts: {
|
|
95
109
|
functionResponse: {
|
|
96
|
-
name: 'testTool',
|
|
97
110
|
id: 'call3',
|
|
98
|
-
|
|
111
|
+
name: 'testTool',
|
|
112
|
+
response: {
|
|
113
|
+
output: 'Error: Invalid parameters',
|
|
114
|
+
},
|
|
99
115
|
},
|
|
100
116
|
},
|
|
101
|
-
|
|
117
|
+
resultDisplay: 'Invalid parameters',
|
|
118
|
+
});
|
|
102
119
|
});
|
|
103
|
-
it('should
|
|
120
|
+
it('should return an error if tool execution fails', async () => {
|
|
104
121
|
const request = {
|
|
105
122
|
callId: 'call4',
|
|
106
123
|
name: 'testTool',
|
|
@@ -108,35 +125,67 @@ describe('executeToolCall', () => {
|
|
|
108
125
|
isClientInitiated: false,
|
|
109
126
|
prompt_id: 'prompt-id-4',
|
|
110
127
|
};
|
|
111
|
-
const
|
|
128
|
+
const executionErrorResult = {
|
|
129
|
+
llmContent: 'Error: Execution failed',
|
|
130
|
+
returnDisplay: 'Execution failed',
|
|
131
|
+
error: {
|
|
132
|
+
message: 'Execution failed',
|
|
133
|
+
type: ToolErrorType.EXECUTION_FAILED,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
112
136
|
vi.mocked(mockToolRegistry.getTool).mockReturnValue(mockTool);
|
|
113
|
-
vi.spyOn(mockTool, '
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
vi.spyOn(mockTool, 'validateBuildAndExecute').mockResolvedValue(executionErrorResult);
|
|
138
|
+
const response = await executeToolCall(mockConfig, request, abortController.signal);
|
|
139
|
+
expect(response).toStrictEqual({
|
|
140
|
+
callId: 'call4',
|
|
141
|
+
error: new Error('Execution failed'),
|
|
142
|
+
errorType: ToolErrorType.EXECUTION_FAILED,
|
|
143
|
+
responseParts: {
|
|
144
|
+
functionResponse: {
|
|
145
|
+
id: 'call4',
|
|
146
|
+
name: 'testTool',
|
|
147
|
+
response: {
|
|
148
|
+
output: 'Error: Execution failed',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
resultDisplay: 'Execution failed',
|
|
125
153
|
});
|
|
126
|
-
abortController.abort(); // Abort before calling
|
|
127
|
-
const response = await executeToolCall(mockConfig, request, mockToolRegistry, abortController.signal);
|
|
128
|
-
expect(response.callId).toBe('call4');
|
|
129
|
-
expect(response.error?.message).toBe(cancellationError.message);
|
|
130
|
-
expect(response.resultDisplay).toBe('Operation cancelled');
|
|
131
154
|
});
|
|
132
|
-
it('should
|
|
155
|
+
it('should return an unhandled exception error if execution throws', async () => {
|
|
133
156
|
const request = {
|
|
134
157
|
callId: 'call5',
|
|
135
158
|
name: 'testTool',
|
|
136
|
-
args: {},
|
|
159
|
+
args: { param1: 'value1' },
|
|
137
160
|
isClientInitiated: false,
|
|
138
161
|
prompt_id: 'prompt-id-5',
|
|
139
162
|
};
|
|
163
|
+
const executionError = new Error('Something went very wrong');
|
|
164
|
+
vi.mocked(mockToolRegistry.getTool).mockReturnValue(mockTool);
|
|
165
|
+
vi.spyOn(mockTool, 'validateBuildAndExecute').mockRejectedValue(executionError);
|
|
166
|
+
const response = await executeToolCall(mockConfig, request, abortController.signal);
|
|
167
|
+
expect(response.callId).toBe('call5');
|
|
168
|
+
expect(response.error).toBe(executionError);
|
|
169
|
+
expect(response.errorType).toBe(ToolErrorType.UNHANDLED_EXCEPTION);
|
|
170
|
+
expect(response.resultDisplay).toBe('Something went very wrong');
|
|
171
|
+
expect(response.responseParts).toEqual([
|
|
172
|
+
{
|
|
173
|
+
functionResponse: {
|
|
174
|
+
name: 'testTool',
|
|
175
|
+
id: 'call5',
|
|
176
|
+
response: { error: 'Something went very wrong' },
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
]);
|
|
180
|
+
});
|
|
181
|
+
it('should correctly format llmContent with inlineData', async () => {
|
|
182
|
+
const request = {
|
|
183
|
+
callId: 'call6',
|
|
184
|
+
name: 'testTool',
|
|
185
|
+
args: {},
|
|
186
|
+
isClientInitiated: false,
|
|
187
|
+
prompt_id: 'prompt-id-6',
|
|
188
|
+
};
|
|
140
189
|
const imageDataPart = {
|
|
141
190
|
inlineData: { mimeType: 'image/png', data: 'base64data' },
|
|
142
191
|
};
|
|
@@ -145,14 +194,14 @@ describe('executeToolCall', () => {
|
|
|
145
194
|
returnDisplay: 'Image processed',
|
|
146
195
|
};
|
|
147
196
|
vi.mocked(mockToolRegistry.getTool).mockReturnValue(mockTool);
|
|
148
|
-
vi.spyOn(mockTool, '
|
|
149
|
-
const response = await executeToolCall(mockConfig, request,
|
|
197
|
+
vi.spyOn(mockTool, 'validateBuildAndExecute').mockResolvedValue(toolResult);
|
|
198
|
+
const response = await executeToolCall(mockConfig, request, abortController.signal);
|
|
150
199
|
expect(response.resultDisplay).toBe('Image processed');
|
|
151
200
|
expect(response.responseParts).toEqual([
|
|
152
201
|
{
|
|
153
202
|
functionResponse: {
|
|
154
203
|
name: 'testTool',
|
|
155
|
-
id: '
|
|
204
|
+
id: 'call6',
|
|
156
205
|
response: {
|
|
157
206
|
output: 'Binary content of type image/png was processed.',
|
|
158
207
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nonInteractiveToolExecutor.test.js","sourceRoot":"","sources":["../../../src/core/nonInteractiveToolExecutor.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"nonInteractiveToolExecutor.test.js","sourceRoot":"","sources":["../../../src/core/nonInteractiveToolExecutor.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAKL,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,gBAA8B,CAAC;IACnC,IAAI,QAAkB,CAAC;IACvB,IAAI,eAAgC,CAAC;IACrC,IAAI,UAAkB,CAAC;IAEvB,UAAU,CAAC,GAAG,EAAE;QACd,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAE1B,gBAAgB,GAAG;YACjB,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE;YAChB,wEAAwE;SAC9C,CAAC;QAE7B,UAAU,GAAG;YACX,YAAY,EAAE,GAAG,EAAE,CAAC,iBAAiB;YACrC,yBAAyB,EAAE,GAAG,EAAE,CAAC,IAAI;YACrC,YAAY,EAAE,GAAG,EAAE,CAAC,KAAK;YACzB,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC;gBAChC,KAAK,EAAE,YAAY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C,CAAC;QACF,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9D,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,yBAAyB,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAE5E,MAAM,QAAQ,GAAG,MAAM,eAAe,CACpC,UAAU,EACV,OAAO,EACP,eAAe,CAAC,MAAM,CACvB,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACvD,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC;YACrC;gBACE,gBAAgB,EAAE;oBAChB,IAAI,EAAE,UAAU;oBAChB,EAAE,EAAE,OAAO;oBACX,QAAQ,EAAE;wBACR,MAAM,EAAE,iDAAiD;qBAC1D;iBACF;aACF;YACD,aAAa;SACd,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -16,7 +16,7 @@ export class OpenAIContentGenerator {
|
|
|
16
16
|
constructor(apiKey, model, config) {
|
|
17
17
|
this.model = model;
|
|
18
18
|
this.config = config;
|
|
19
|
-
const baseURL = process.env
|
|
19
|
+
const baseURL = process.env['OPENAI_BASE_URL'] || '';
|
|
20
20
|
// Configure timeout settings - using progressive timeouts
|
|
21
21
|
const timeoutConfig = {
|
|
22
22
|
// Base timeout for most requests (2 minutes)
|
|
@@ -35,7 +35,7 @@ export class OpenAIContentGenerator {
|
|
|
35
35
|
timeoutConfig.maxRetries = contentGeneratorConfig.maxRetries;
|
|
36
36
|
}
|
|
37
37
|
// Set up User-Agent header (same format as contentGenerator.ts)
|
|
38
|
-
const version = process.env
|
|
38
|
+
const version = process.env['CLI_VERSION'] || process.version;
|
|
39
39
|
const userAgent = `QwenCode/${version} (${process.platform}; ${process.arch})`;
|
|
40
40
|
// Check if using OpenRouter and add required headers
|
|
41
41
|
const isOpenRouter = baseURL.includes('openrouter.ai');
|
|
@@ -146,12 +146,27 @@ export class OpenAIContentGenerator {
|
|
|
146
146
|
modelName.includes('gpt4')) {
|
|
147
147
|
createParams.store = true;
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
// Handle JSON schema requests (for generateJson calls)
|
|
150
|
+
if (request.config?.responseJsonSchema && request.config?.responseMimeType === 'application/json') {
|
|
151
|
+
// Convert JSON schema request to tool call (like qwen-code approach)
|
|
152
|
+
const jsonSchemaFunction = {
|
|
153
|
+
type: 'function',
|
|
154
|
+
function: {
|
|
155
|
+
name: 'respond_in_schema',
|
|
156
|
+
description: 'Provide the response in the specified JSON schema format',
|
|
157
|
+
parameters: request.config.responseJsonSchema,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
createParams.tools = [jsonSchemaFunction];
|
|
161
|
+
}
|
|
162
|
+
else if (request.config?.tools) {
|
|
150
163
|
createParams.tools = await this.convertGeminiToolsToOpenAI(request.config.tools);
|
|
151
164
|
}
|
|
152
165
|
// console.log('createParams', createParams);
|
|
153
166
|
const completion = (await this.client.chat.completions.create(createParams));
|
|
154
|
-
|
|
167
|
+
// Check if this was a JSON schema request
|
|
168
|
+
const isJsonSchemaRequest = !!(request.config?.responseJsonSchema && request.config?.responseMimeType === 'application/json');
|
|
169
|
+
const response = this.convertToGeminiFormat(completion, isJsonSchemaRequest);
|
|
155
170
|
const durationMs = Date.now() - startTime;
|
|
156
171
|
// Log API response event for UI telemetry
|
|
157
172
|
const responseEvent = new ApiResponseEvent(this.model, durationMs, userPromptId, this.config.getContentGeneratorConfig()?.authType, response.usageMetadata);
|
|
@@ -232,12 +247,27 @@ export class OpenAIContentGenerator {
|
|
|
232
247
|
modelNameStream.includes('gpt4')) {
|
|
233
248
|
createParams.store = true;
|
|
234
249
|
}
|
|
235
|
-
|
|
250
|
+
// Handle JSON schema requests (for generateJson calls) - same as non-streaming
|
|
251
|
+
if (request.config?.responseJsonSchema && request.config?.responseMimeType === 'application/json') {
|
|
252
|
+
// Convert JSON schema request to tool call (like qwen-code approach)
|
|
253
|
+
const jsonSchemaFunction = {
|
|
254
|
+
type: 'function',
|
|
255
|
+
function: {
|
|
256
|
+
name: 'respond_in_schema',
|
|
257
|
+
description: 'Provide the response in the specified JSON schema format',
|
|
258
|
+
parameters: request.config.responseJsonSchema,
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
createParams.tools = [jsonSchemaFunction];
|
|
262
|
+
}
|
|
263
|
+
else if (request.config?.tools) {
|
|
236
264
|
createParams.tools = await this.convertGeminiToolsToOpenAI(request.config.tools);
|
|
237
265
|
}
|
|
238
266
|
// console.log('createParams', createParams);
|
|
239
267
|
const stream = (await this.client.chat.completions.create(createParams));
|
|
240
|
-
|
|
268
|
+
// Check if this was a JSON schema request
|
|
269
|
+
const isJsonSchemaRequest = !!(request.config?.responseJsonSchema && request.config?.responseMimeType === 'application/json');
|
|
270
|
+
const originalStream = this.streamGenerator(stream, isJsonSchemaRequest);
|
|
241
271
|
// Collect all responses for final logging (don't log during streaming)
|
|
242
272
|
const responses = [];
|
|
243
273
|
// Return a new generator that both yields responses and collects them
|
|
@@ -355,11 +385,11 @@ export class OpenAIContentGenerator {
|
|
|
355
385
|
throw error;
|
|
356
386
|
}
|
|
357
387
|
}
|
|
358
|
-
async *streamGenerator(stream) {
|
|
388
|
+
async *streamGenerator(stream, isJsonSchemaRequest = false) {
|
|
359
389
|
// Reset the accumulator for each new stream
|
|
360
390
|
this.streamingToolCalls.clear();
|
|
361
391
|
for await (const chunk of stream) {
|
|
362
|
-
yield this.convertStreamChunkToGeminiFormat(chunk);
|
|
392
|
+
yield this.convertStreamChunkToGeminiFormat(chunk, isJsonSchemaRequest);
|
|
363
393
|
}
|
|
364
394
|
}
|
|
365
395
|
/**
|
|
@@ -844,7 +874,7 @@ export class OpenAIContentGenerator {
|
|
|
844
874
|
}
|
|
845
875
|
return merged;
|
|
846
876
|
}
|
|
847
|
-
convertToGeminiFormat(openaiResponse) {
|
|
877
|
+
convertToGeminiFormat(openaiResponse, isJsonSchemaRequest = false) {
|
|
848
878
|
const choice = openaiResponse.choices[0];
|
|
849
879
|
const response = new GenerateContentResponse();
|
|
850
880
|
const parts = [];
|
|
@@ -855,18 +885,26 @@ export class OpenAIContentGenerator {
|
|
|
855
885
|
// Handle tool calls
|
|
856
886
|
if (choice.message.tool_calls) {
|
|
857
887
|
for (const toolCall of choice.message.tool_calls) {
|
|
858
|
-
if (toolCall.function) {
|
|
888
|
+
if (toolCall.type === 'function' && toolCall.function) {
|
|
859
889
|
let args = {};
|
|
860
890
|
if (toolCall.function.arguments) {
|
|
861
891
|
args = safeJsonParse(toolCall.function.arguments, {});
|
|
862
892
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
893
|
+
// Special handling for JSON schema requests (like qwen-code)
|
|
894
|
+
if (isJsonSchemaRequest && toolCall.function.name === 'respond_in_schema') {
|
|
895
|
+
// Convert the function call result to a text response (simulate Gemini's JSON response)
|
|
896
|
+
parts.push({ text: JSON.stringify(args) });
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
// Regular tool call handling
|
|
900
|
+
parts.push({
|
|
901
|
+
functionCall: {
|
|
902
|
+
id: toolCall.id,
|
|
903
|
+
name: toolCall.function.name,
|
|
904
|
+
args,
|
|
905
|
+
},
|
|
906
|
+
});
|
|
907
|
+
}
|
|
870
908
|
}
|
|
871
909
|
}
|
|
872
910
|
}
|
|
@@ -912,7 +950,7 @@ export class OpenAIContentGenerator {
|
|
|
912
950
|
}
|
|
913
951
|
return response;
|
|
914
952
|
}
|
|
915
|
-
convertStreamChunkToGeminiFormat(chunk) {
|
|
953
|
+
convertStreamChunkToGeminiFormat(chunk, isJsonSchemaRequest = false) {
|
|
916
954
|
const choice = chunk.choices?.[0];
|
|
917
955
|
const response = new GenerateContentResponse();
|
|
918
956
|
if (choice) {
|
|
@@ -953,13 +991,21 @@ export class OpenAIContentGenerator {
|
|
|
953
991
|
if (accumulatedCall.arguments) {
|
|
954
992
|
args = safeJsonParse(accumulatedCall.arguments, {});
|
|
955
993
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
994
|
+
// Special handling for JSON schema requests (like qwen-code)
|
|
995
|
+
if (isJsonSchemaRequest && accumulatedCall.name === 'respond_in_schema') {
|
|
996
|
+
// Convert the function call result to a text response (simulate Gemini's JSON response)
|
|
997
|
+
parts.push({ text: JSON.stringify(args) });
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
// Regular tool call handling
|
|
1001
|
+
parts.push({
|
|
1002
|
+
functionCall: {
|
|
1003
|
+
id: accumulatedCall.id,
|
|
1004
|
+
name: accumulatedCall.name,
|
|
1005
|
+
args,
|
|
1006
|
+
},
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
963
1009
|
}
|
|
964
1010
|
}
|
|
965
1011
|
// Clear all accumulated tool calls
|