hanseol 3.2.7
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/LICENSE +21 -0
- package/README.md +267 -0
- package/dist/agents/base/base-agent.d.ts +38 -0
- package/dist/agents/base/base-agent.d.ts.map +1 -0
- package/dist/agents/base/base-agent.js +69 -0
- package/dist/agents/base/base-agent.js.map +1 -0
- package/dist/agents/docs-search/index.d.ts +33 -0
- package/dist/agents/docs-search/index.d.ts.map +1 -0
- package/dist/agents/docs-search/index.js +244 -0
- package/dist/agents/docs-search/index.js.map +1 -0
- package/dist/agents/index.d.ts +4 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +4 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/planner/index.d.ts +15 -0
- package/dist/agents/planner/index.d.ts.map +1 -0
- package/dist/agents/planner/index.js +270 -0
- package/dist/agents/planner/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +97 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/auth/auth-manager.d.ts +23 -0
- package/dist/core/auth/auth-manager.d.ts.map +1 -0
- package/dist/core/auth/auth-manager.js +159 -0
- package/dist/core/auth/auth-manager.js.map +1 -0
- package/dist/core/auth/index.d.ts +4 -0
- package/dist/core/auth/index.d.ts.map +1 -0
- package/dist/core/auth/index.js +4 -0
- package/dist/core/auth/index.js.map +1 -0
- package/dist/core/auth/jwt-decoder.d.ts +7 -0
- package/dist/core/auth/jwt-decoder.d.ts.map +1 -0
- package/dist/core/auth/jwt-decoder.js +101 -0
- package/dist/core/auth/jwt-decoder.js.map +1 -0
- package/dist/core/auth/sso-client.d.ts +20 -0
- package/dist/core/auth/sso-client.d.ts.map +1 -0
- package/dist/core/auth/sso-client.js +164 -0
- package/dist/core/auth/sso-client.js.map +1 -0
- package/dist/core/auth/types.d.ts +45 -0
- package/dist/core/auth/types.d.ts.map +1 -0
- package/dist/core/auth/types.js +2 -0
- package/dist/core/auth/types.js.map +1 -0
- package/dist/core/compact/compact-manager.d.ts +22 -0
- package/dist/core/compact/compact-manager.d.ts.map +1 -0
- package/dist/core/compact/compact-manager.js +74 -0
- package/dist/core/compact/compact-manager.js.map +1 -0
- package/dist/core/compact/compact-prompts.d.ts +11 -0
- package/dist/core/compact/compact-prompts.d.ts.map +1 -0
- package/dist/core/compact/compact-prompts.js +80 -0
- package/dist/core/compact/compact-prompts.js.map +1 -0
- package/dist/core/compact/context-tracker.d.ts +28 -0
- package/dist/core/compact/context-tracker.d.ts.map +1 -0
- package/dist/core/compact/context-tracker.js +71 -0
- package/dist/core/compact/context-tracker.js.map +1 -0
- package/dist/core/compact/index.d.ts +4 -0
- package/dist/core/compact/index.d.ts.map +1 -0
- package/dist/core/compact/index.js +4 -0
- package/dist/core/compact/index.js.map +1 -0
- package/dist/core/config/config-manager.d.ts +43 -0
- package/dist/core/config/config-manager.d.ts.map +1 -0
- package/dist/core/config/config-manager.js +247 -0
- package/dist/core/config/config-manager.js.map +1 -0
- package/dist/core/config/index.d.ts +2 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +2 -0
- package/dist/core/config/index.js.map +1 -0
- package/dist/core/docs-manager.d.ts +46 -0
- package/dist/core/docs-manager.d.ts.map +1 -0
- package/dist/core/docs-manager.js +475 -0
- package/dist/core/docs-manager.js.map +1 -0
- package/dist/core/llm/index.d.ts +2 -0
- package/dist/core/llm/index.d.ts.map +1 -0
- package/dist/core/llm/index.js +2 -0
- package/dist/core/llm/index.js.map +1 -0
- package/dist/core/llm/llm-client.d.ts +97 -0
- package/dist/core/llm/llm-client.d.ts.map +1 -0
- package/dist/core/llm/llm-client.js +1002 -0
- package/dist/core/llm/llm-client.js.map +1 -0
- package/dist/core/model-sync.d.ts +20 -0
- package/dist/core/model-sync.d.ts.map +1 -0
- package/dist/core/model-sync.js +182 -0
- package/dist/core/model-sync.js.map +1 -0
- package/dist/core/notification-manager.d.ts +23 -0
- package/dist/core/notification-manager.d.ts.map +1 -0
- package/dist/core/notification-manager.js +76 -0
- package/dist/core/notification-manager.js.map +1 -0
- package/dist/core/s3-auto-updater.d.ts +51 -0
- package/dist/core/s3-auto-updater.d.ts.map +1 -0
- package/dist/core/s3-auto-updater.js +292 -0
- package/dist/core/s3-auto-updater.js.map +1 -0
- package/dist/core/session/index.d.ts +2 -0
- package/dist/core/session/index.d.ts.map +1 -0
- package/dist/core/session/index.js +2 -0
- package/dist/core/session/index.js.map +1 -0
- package/dist/core/session/session-manager.d.ts +71 -0
- package/dist/core/session/session-manager.d.ts.map +1 -0
- package/dist/core/session/session-manager.js +235 -0
- package/dist/core/session/session-manager.js.map +1 -0
- package/dist/core/slash-command-handler.d.ts +32 -0
- package/dist/core/slash-command-handler.d.ts.map +1 -0
- package/dist/core/slash-command-handler.js +402 -0
- package/dist/core/slash-command-handler.js.map +1 -0
- package/dist/core/usage-tracker.d.ts +70 -0
- package/dist/core/usage-tracker.d.ts.map +1 -0
- package/dist/core/usage-tracker.js +251 -0
- package/dist/core/usage-tracker.js.map +1 -0
- package/dist/errors/base.d.ts +22 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +43 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/file.d.ts +31 -0
- package/dist/errors/file.d.ts.map +1 -0
- package/dist/errors/file.js +110 -0
- package/dist/errors/file.js.map +1 -0
- package/dist/errors/index.d.ts +10 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +41 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/llm.d.ts +26 -0
- package/dist/errors/llm.d.ts.map +1 -0
- package/dist/errors/llm.js +86 -0
- package/dist/errors/llm.js.map +1 -0
- package/dist/errors/network.d.ts +19 -0
- package/dist/errors/network.d.ts.map +1 -0
- package/dist/errors/network.js +82 -0
- package/dist/errors/network.js.map +1 -0
- package/dist/errors/validation.d.ts +19 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +62 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/eval/eval-runner.d.ts +24 -0
- package/dist/eval/eval-runner.d.ts.map +1 -0
- package/dist/eval/eval-runner.js +291 -0
- package/dist/eval/eval-runner.js.map +1 -0
- package/dist/eval/index.d.ts +3 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +3 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/types.d.ts +77 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +2 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestration/index.d.ts +4 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +3 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/plan-executor.d.ts +28 -0
- package/dist/orchestration/plan-executor.d.ts.map +1 -0
- package/dist/orchestration/plan-executor.js +368 -0
- package/dist/orchestration/plan-executor.js.map +1 -0
- package/dist/orchestration/types.d.ts +65 -0
- package/dist/orchestration/types.d.ts.map +1 -0
- package/dist/orchestration/types.js +2 -0
- package/dist/orchestration/types.js.map +1 -0
- package/dist/orchestration/utils.d.ts +13 -0
- package/dist/orchestration/utils.d.ts.map +1 -0
- package/dist/orchestration/utils.js +81 -0
- package/dist/orchestration/utils.js.map +1 -0
- package/dist/prompts/agents/docs-search-decision.d.ts +6 -0
- package/dist/prompts/agents/docs-search-decision.d.ts.map +1 -0
- package/dist/prompts/agents/docs-search-decision.js +46 -0
- package/dist/prompts/agents/docs-search-decision.js.map +1 -0
- package/dist/prompts/agents/docs-search.d.ts +4 -0
- package/dist/prompts/agents/docs-search.d.ts.map +1 -0
- package/dist/prompts/agents/docs-search.js +70 -0
- package/dist/prompts/agents/docs-search.js.map +1 -0
- package/dist/prompts/agents/planning.d.ts +4 -0
- package/dist/prompts/agents/planning.d.ts.map +1 -0
- package/dist/prompts/agents/planning.js +119 -0
- package/dist/prompts/agents/planning.js.map +1 -0
- package/dist/prompts/index.d.ts +10 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +10 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/shared/codebase-rules.d.ts +4 -0
- package/dist/prompts/shared/codebase-rules.d.ts.map +1 -0
- package/dist/prompts/shared/codebase-rules.js +16 -0
- package/dist/prompts/shared/codebase-rules.js.map +1 -0
- package/dist/prompts/shared/git-rules.d.ts +2 -0
- package/dist/prompts/shared/git-rules.d.ts.map +1 -0
- package/dist/prompts/shared/git-rules.js +87 -0
- package/dist/prompts/shared/git-rules.js.map +1 -0
- package/dist/prompts/shared/language-rules.d.ts +4 -0
- package/dist/prompts/shared/language-rules.d.ts.map +1 -0
- package/dist/prompts/shared/language-rules.js +22 -0
- package/dist/prompts/shared/language-rules.js.map +1 -0
- package/dist/prompts/shared/tool-usage.d.ts +12 -0
- package/dist/prompts/shared/tool-usage.d.ts.map +1 -0
- package/dist/prompts/shared/tool-usage.js +49 -0
- package/dist/prompts/shared/tool-usage.js.map +1 -0
- package/dist/prompts/system/compact.d.ts +3 -0
- package/dist/prompts/system/compact.d.ts.map +1 -0
- package/dist/prompts/system/compact.js +73 -0
- package/dist/prompts/system/compact.js.map +1 -0
- package/dist/prompts/system/plan-execute.d.ts +3 -0
- package/dist/prompts/system/plan-execute.d.ts.map +1 -0
- package/dist/prompts/system/plan-execute.js +83 -0
- package/dist/prompts/system/plan-execute.js.map +1 -0
- package/dist/tools/browser/browser-client.d.ts +107 -0
- package/dist/tools/browser/browser-client.d.ts.map +1 -0
- package/dist/tools/browser/browser-client.js +958 -0
- package/dist/tools/browser/browser-client.js.map +1 -0
- package/dist/tools/browser/browser-tools.d.ts +17 -0
- package/dist/tools/browser/browser-tools.d.ts.map +1 -0
- package/dist/tools/browser/browser-tools.js +888 -0
- package/dist/tools/browser/browser-tools.js.map +1 -0
- package/dist/tools/browser/index.d.ts +7 -0
- package/dist/tools/browser/index.d.ts.map +1 -0
- package/dist/tools/browser/index.js +17 -0
- package/dist/tools/browser/index.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/llm/agents/docs-search-tools.d.ts +17 -0
- package/dist/tools/llm/agents/docs-search-tools.d.ts.map +1 -0
- package/dist/tools/llm/agents/docs-search-tools.js +265 -0
- package/dist/tools/llm/agents/docs-search-tools.js.map +1 -0
- package/dist/tools/llm/agents/index.d.ts +4 -0
- package/dist/tools/llm/agents/index.d.ts.map +1 -0
- package/dist/tools/llm/agents/index.js +3 -0
- package/dist/tools/llm/agents/index.js.map +1 -0
- package/dist/tools/llm/index.d.ts +3 -0
- package/dist/tools/llm/index.d.ts.map +1 -0
- package/dist/tools/llm/index.js +3 -0
- package/dist/tools/llm/index.js.map +1 -0
- package/dist/tools/llm/simple/ask-user-tool.d.ts +5 -0
- package/dist/tools/llm/simple/ask-user-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/ask-user-tool.js +7 -0
- package/dist/tools/llm/simple/ask-user-tool.js.map +1 -0
- package/dist/tools/llm/simple/background-bash-tool.d.ts +30 -0
- package/dist/tools/llm/simple/background-bash-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/background-bash-tool.js +320 -0
- package/dist/tools/llm/simple/background-bash-tool.js.map +1 -0
- package/dist/tools/llm/simple/background-powershell-tool.d.ts +30 -0
- package/dist/tools/llm/simple/background-powershell-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/background-powershell-tool.js +302 -0
- package/dist/tools/llm/simple/background-powershell-tool.js.map +1 -0
- package/dist/tools/llm/simple/bash-tool.d.ts +4 -0
- package/dist/tools/llm/simple/bash-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/bash-tool.js +167 -0
- package/dist/tools/llm/simple/bash-tool.js.map +1 -0
- package/dist/tools/llm/simple/docs-search-agent-tool.d.ts +6 -0
- package/dist/tools/llm/simple/docs-search-agent-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/docs-search-agent-tool.js +104 -0
- package/dist/tools/llm/simple/docs-search-agent-tool.js.map +1 -0
- package/dist/tools/llm/simple/file-tools.d.ts +12 -0
- package/dist/tools/llm/simple/file-tools.d.ts.map +1 -0
- package/dist/tools/llm/simple/file-tools.js +597 -0
- package/dist/tools/llm/simple/file-tools.js.map +1 -0
- package/dist/tools/llm/simple/final-response-tool.d.ts +12 -0
- package/dist/tools/llm/simple/final-response-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/final-response-tool.js +107 -0
- package/dist/tools/llm/simple/final-response-tool.js.map +1 -0
- package/dist/tools/llm/simple/index.d.ts +11 -0
- package/dist/tools/llm/simple/index.d.ts.map +1 -0
- package/dist/tools/llm/simple/index.js +20 -0
- package/dist/tools/llm/simple/index.js.map +1 -0
- package/dist/tools/llm/simple/planning-tools.d.ts +5 -0
- package/dist/tools/llm/simple/planning-tools.d.ts.map +1 -0
- package/dist/tools/llm/simple/planning-tools.js +117 -0
- package/dist/tools/llm/simple/planning-tools.js.map +1 -0
- package/dist/tools/llm/simple/powershell-tool.d.ts +4 -0
- package/dist/tools/llm/simple/powershell-tool.d.ts.map +1 -0
- package/dist/tools/llm/simple/powershell-tool.js +150 -0
- package/dist/tools/llm/simple/powershell-tool.js.map +1 -0
- package/dist/tools/llm/simple/simple-tool-executor.d.ts +38 -0
- package/dist/tools/llm/simple/simple-tool-executor.d.ts.map +1 -0
- package/dist/tools/llm/simple/simple-tool-executor.js +132 -0
- package/dist/tools/llm/simple/simple-tool-executor.js.map +1 -0
- package/dist/tools/llm/simple/todo-tools.d.ts +15 -0
- package/dist/tools/llm/simple/todo-tools.d.ts.map +1 -0
- package/dist/tools/llm/simple/todo-tools.js +145 -0
- package/dist/tools/llm/simple/todo-tools.js.map +1 -0
- package/dist/tools/llm/simple/user-interaction-tools.d.ts +21 -0
- package/dist/tools/llm/simple/user-interaction-tools.d.ts.map +1 -0
- package/dist/tools/llm/simple/user-interaction-tools.js +167 -0
- package/dist/tools/llm/simple/user-interaction-tools.js.map +1 -0
- package/dist/tools/office/common/constants.d.ts +194 -0
- package/dist/tools/office/common/constants.d.ts.map +1 -0
- package/dist/tools/office/common/constants.js +169 -0
- package/dist/tools/office/common/constants.js.map +1 -0
- package/dist/tools/office/common/index.d.ts +4 -0
- package/dist/tools/office/common/index.d.ts.map +1 -0
- package/dist/tools/office/common/index.js +3 -0
- package/dist/tools/office/common/index.js.map +1 -0
- package/dist/tools/office/common/types.d.ts +82 -0
- package/dist/tools/office/common/types.d.ts.map +1 -0
- package/dist/tools/office/common/types.js +2 -0
- package/dist/tools/office/common/types.js.map +1 -0
- package/dist/tools/office/common/utils.d.ts +14 -0
- package/dist/tools/office/common/utils.d.ts.map +1 -0
- package/dist/tools/office/common/utils.js +58 -0
- package/dist/tools/office/common/utils.js.map +1 -0
- package/dist/tools/office/excel-client.d.ts +123 -0
- package/dist/tools/office/excel-client.d.ts.map +1 -0
- package/dist/tools/office/excel-client.js +1037 -0
- package/dist/tools/office/excel-client.js.map +1 -0
- package/dist/tools/office/excel-tools/cells.d.ts +10 -0
- package/dist/tools/office/excel-tools/cells.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/cells.js +279 -0
- package/dist/tools/office/excel-tools/cells.js.map +1 -0
- package/dist/tools/office/excel-tools/charts.d.ts +6 -0
- package/dist/tools/office/excel-tools/charts.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/charts.js +124 -0
- package/dist/tools/office/excel-tools/charts.js.map +1 -0
- package/dist/tools/office/excel-tools/comments.d.ts +6 -0
- package/dist/tools/office/excel-tools/comments.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/comments.js +114 -0
- package/dist/tools/office/excel-tools/comments.js.map +1 -0
- package/dist/tools/office/excel-tools/data-ops.d.ts +10 -0
- package/dist/tools/office/excel-tools/data-ops.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/data-ops.js +266 -0
- package/dist/tools/office/excel-tools/data-ops.js.map +1 -0
- package/dist/tools/office/excel-tools/export.d.ts +5 -0
- package/dist/tools/office/excel-tools/export.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/export.js +75 -0
- package/dist/tools/office/excel-tools/export.js.map +1 -0
- package/dist/tools/office/excel-tools/formatting.d.ts +10 -0
- package/dist/tools/office/excel-tools/formatting.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/formatting.js +276 -0
- package/dist/tools/office/excel-tools/formatting.js.map +1 -0
- package/dist/tools/office/excel-tools/index.d.ts +16 -0
- package/dist/tools/office/excel-tools/index.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/index.js +42 -0
- package/dist/tools/office/excel-tools/index.js.map +1 -0
- package/dist/tools/office/excel-tools/launch.d.ts +10 -0
- package/dist/tools/office/excel-tools/launch.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/launch.js +248 -0
- package/dist/tools/office/excel-tools/launch.js.map +1 -0
- package/dist/tools/office/excel-tools/media.d.ts +5 -0
- package/dist/tools/office/excel-tools/media.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/media.js +84 -0
- package/dist/tools/office/excel-tools/media.js.map +1 -0
- package/dist/tools/office/excel-tools/named-ranges.d.ts +6 -0
- package/dist/tools/office/excel-tools/named-ranges.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/named-ranges.js +113 -0
- package/dist/tools/office/excel-tools/named-ranges.js.map +1 -0
- package/dist/tools/office/excel-tools/protection.d.ts +5 -0
- package/dist/tools/office/excel-tools/protection.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/protection.js +75 -0
- package/dist/tools/office/excel-tools/protection.js.map +1 -0
- package/dist/tools/office/excel-tools/rows-columns.d.ts +11 -0
- package/dist/tools/office/excel-tools/rows-columns.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/rows-columns.js +293 -0
- package/dist/tools/office/excel-tools/rows-columns.js.map +1 -0
- package/dist/tools/office/excel-tools/sheets.d.ts +8 -0
- package/dist/tools/office/excel-tools/sheets.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/sheets.js +177 -0
- package/dist/tools/office/excel-tools/sheets.js.map +1 -0
- package/dist/tools/office/excel-tools/validation.d.ts +7 -0
- package/dist/tools/office/excel-tools/validation.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/validation.js +175 -0
- package/dist/tools/office/excel-tools/validation.js.map +1 -0
- package/dist/tools/office/excel-tools.d.ts +3 -0
- package/dist/tools/office/excel-tools.d.ts.map +1 -0
- package/dist/tools/office/excel-tools.js +3 -0
- package/dist/tools/office/excel-tools.js.map +1 -0
- package/dist/tools/office/index.d.ts +6 -0
- package/dist/tools/office/index.d.ts.map +1 -0
- package/dist/tools/office/index.js +9 -0
- package/dist/tools/office/index.js.map +1 -0
- package/dist/tools/office/office-client-base.d.ts +29 -0
- package/dist/tools/office/office-client-base.d.ts.map +1 -0
- package/dist/tools/office/office-client-base.js +148 -0
- package/dist/tools/office/office-client-base.js.map +1 -0
- package/dist/tools/office/office-client.d.ts +196 -0
- package/dist/tools/office/office-client.d.ts.map +1 -0
- package/dist/tools/office/office-client.js +200 -0
- package/dist/tools/office/office-client.js.map +1 -0
- package/dist/tools/office/powerpoint-client.d.ts +135 -0
- package/dist/tools/office/powerpoint-client.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-client.js +1136 -0
- package/dist/tools/office/powerpoint-client.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/effects.d.ts +9 -0
- package/dist/tools/office/powerpoint-tools/effects.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/effects.js +246 -0
- package/dist/tools/office/powerpoint-tools/effects.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/export.d.ts +6 -0
- package/dist/tools/office/powerpoint-tools/export.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/export.js +108 -0
- package/dist/tools/office/powerpoint-tools/export.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/index.d.ts +13 -0
- package/dist/tools/office/powerpoint-tools/index.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/index.js +33 -0
- package/dist/tools/office/powerpoint-tools/index.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/launch.d.ts +9 -0
- package/dist/tools/office/powerpoint-tools/launch.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/launch.js +214 -0
- package/dist/tools/office/powerpoint-tools/launch.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/media.d.ts +8 -0
- package/dist/tools/office/powerpoint-tools/media.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/media.js +211 -0
- package/dist/tools/office/powerpoint-tools/media.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/notes.d.ts +8 -0
- package/dist/tools/office/powerpoint-tools/notes.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/notes.js +171 -0
- package/dist/tools/office/powerpoint-tools/notes.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/sections.d.ts +6 -0
- package/dist/tools/office/powerpoint-tools/sections.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/sections.js +104 -0
- package/dist/tools/office/powerpoint-tools/sections.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/shapes.d.ts +22 -0
- package/dist/tools/office/powerpoint-tools/shapes.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/shapes.js +681 -0
- package/dist/tools/office/powerpoint-tools/shapes.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/slides.d.ts +11 -0
- package/dist/tools/office/powerpoint-tools/slides.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/slides.js +283 -0
- package/dist/tools/office/powerpoint-tools/slides.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/tables.d.ts +6 -0
- package/dist/tools/office/powerpoint-tools/tables.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/tables.js +132 -0
- package/dist/tools/office/powerpoint-tools/tables.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/text.d.ts +12 -0
- package/dist/tools/office/powerpoint-tools/text.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/text.js +366 -0
- package/dist/tools/office/powerpoint-tools/text.js.map +1 -0
- package/dist/tools/office/powerpoint-tools.d.ts +3 -0
- package/dist/tools/office/powerpoint-tools.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools.js +3 -0
- package/dist/tools/office/powerpoint-tools.js.map +1 -0
- package/dist/tools/office/word-client.d.ts +111 -0
- package/dist/tools/office/word-client.d.ts.map +1 -0
- package/dist/tools/office/word-client.js +995 -0
- package/dist/tools/office/word-client.js.map +1 -0
- package/dist/tools/office/word-tools/bookmarks.d.ts +7 -0
- package/dist/tools/office/word-tools/bookmarks.d.ts.map +1 -0
- package/dist/tools/office/word-tools/bookmarks.js +146 -0
- package/dist/tools/office/word-tools/bookmarks.js.map +1 -0
- package/dist/tools/office/word-tools/comments.d.ts +7 -0
- package/dist/tools/office/word-tools/comments.d.ts.map +1 -0
- package/dist/tools/office/word-tools/comments.js +146 -0
- package/dist/tools/office/word-tools/comments.js.map +1 -0
- package/dist/tools/office/word-tools/content.d.ts +7 -0
- package/dist/tools/office/word-tools/content.d.ts.map +1 -0
- package/dist/tools/office/word-tools/content.js +168 -0
- package/dist/tools/office/word-tools/content.js.map +1 -0
- package/dist/tools/office/word-tools/export.d.ts +5 -0
- package/dist/tools/office/word-tools/export.d.ts.map +1 -0
- package/dist/tools/office/word-tools/export.js +73 -0
- package/dist/tools/office/word-tools/export.js.map +1 -0
- package/dist/tools/office/word-tools/formatting.d.ts +6 -0
- package/dist/tools/office/word-tools/formatting.d.ts.map +1 -0
- package/dist/tools/office/word-tools/formatting.js +129 -0
- package/dist/tools/office/word-tools/formatting.js.map +1 -0
- package/dist/tools/office/word-tools/headers-footers.d.ts +6 -0
- package/dist/tools/office/word-tools/headers-footers.d.ts.map +1 -0
- package/dist/tools/office/word-tools/headers-footers.js +117 -0
- package/dist/tools/office/word-tools/headers-footers.js.map +1 -0
- package/dist/tools/office/word-tools/index.d.ts +16 -0
- package/dist/tools/office/word-tools/index.d.ts.map +1 -0
- package/dist/tools/office/word-tools/index.js +45 -0
- package/dist/tools/office/word-tools/index.js.map +1 -0
- package/dist/tools/office/word-tools/launch.d.ts +10 -0
- package/dist/tools/office/word-tools/launch.d.ts.map +1 -0
- package/dist/tools/office/word-tools/launch.js +255 -0
- package/dist/tools/office/word-tools/launch.js.map +1 -0
- package/dist/tools/office/word-tools/lists.d.ts +5 -0
- package/dist/tools/office/word-tools/lists.d.ts.map +1 -0
- package/dist/tools/office/word-tools/lists.js +73 -0
- package/dist/tools/office/word-tools/lists.js.map +1 -0
- package/dist/tools/office/word-tools/navigation.d.ts +5 -0
- package/dist/tools/office/word-tools/navigation.d.ts.map +1 -0
- package/dist/tools/office/word-tools/navigation.js +85 -0
- package/dist/tools/office/word-tools/navigation.js.map +1 -0
- package/dist/tools/office/word-tools/page-setup.d.ts +7 -0
- package/dist/tools/office/word-tools/page-setup.d.ts.map +1 -0
- package/dist/tools/office/word-tools/page-setup.js +152 -0
- package/dist/tools/office/word-tools/page-setup.js.map +1 -0
- package/dist/tools/office/word-tools/tables.d.ts +8 -0
- package/dist/tools/office/word-tools/tables.d.ts.map +1 -0
- package/dist/tools/office/word-tools/tables.js +197 -0
- package/dist/tools/office/word-tools/tables.js.map +1 -0
- package/dist/tools/office/word-tools/text.d.ts +9 -0
- package/dist/tools/office/word-tools/text.d.ts.map +1 -0
- package/dist/tools/office/word-tools/text.js +235 -0
- package/dist/tools/office/word-tools/text.js.map +1 -0
- package/dist/tools/office/word-tools/undo-redo.d.ts +5 -0
- package/dist/tools/office/word-tools/undo-redo.d.ts.map +1 -0
- package/dist/tools/office/word-tools/undo-redo.js +73 -0
- package/dist/tools/office/word-tools/undo-redo.js.map +1 -0
- package/dist/tools/office/word-tools/watermarks.d.ts +5 -0
- package/dist/tools/office/word-tools/watermarks.d.ts.map +1 -0
- package/dist/tools/office/word-tools/watermarks.js +81 -0
- package/dist/tools/office/word-tools/watermarks.js.map +1 -0
- package/dist/tools/office/word-tools.d.ts +3 -0
- package/dist/tools/office/word-tools.d.ts.map +1 -0
- package/dist/tools/office/word-tools.js +3 -0
- package/dist/tools/office/word-tools.js.map +1 -0
- package/dist/tools/registry.d.ts +46 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +258 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +88 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +19 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/types/index.d.ts +122 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/PlanExecuteView.d.ts +11 -0
- package/dist/ui/PlanExecuteView.d.ts.map +1 -0
- package/dist/ui/PlanExecuteView.js +27 -0
- package/dist/ui/PlanExecuteView.js.map +1 -0
- package/dist/ui/TodoPanel.d.ts +13 -0
- package/dist/ui/TodoPanel.d.ts.map +1 -0
- package/dist/ui/TodoPanel.js +135 -0
- package/dist/ui/TodoPanel.js.map +1 -0
- package/dist/ui/UpdateNotification.d.ts +13 -0
- package/dist/ui/UpdateNotification.d.ts.map +1 -0
- package/dist/ui/UpdateNotification.js +42 -0
- package/dist/ui/UpdateNotification.js.map +1 -0
- package/dist/ui/components/ActivityIndicator.d.ts +25 -0
- package/dist/ui/components/ActivityIndicator.d.ts.map +1 -0
- package/dist/ui/components/ActivityIndicator.js +115 -0
- package/dist/ui/components/ActivityIndicator.js.map +1 -0
- package/dist/ui/components/CommandBrowser.d.ts +10 -0
- package/dist/ui/components/CommandBrowser.d.ts.map +1 -0
- package/dist/ui/components/CommandBrowser.js +53 -0
- package/dist/ui/components/CommandBrowser.js.map +1 -0
- package/dist/ui/components/CustomTextInput.d.ts +13 -0
- package/dist/ui/components/CustomTextInput.d.ts.map +1 -0
- package/dist/ui/components/CustomTextInput.js +245 -0
- package/dist/ui/components/CustomTextInput.js.map +1 -0
- package/dist/ui/components/DocsSearchProgress.d.ts +13 -0
- package/dist/ui/components/DocsSearchProgress.d.ts.map +1 -0
- package/dist/ui/components/DocsSearchProgress.js +37 -0
- package/dist/ui/components/DocsSearchProgress.js.map +1 -0
- package/dist/ui/components/FileBrowser.d.ts +11 -0
- package/dist/ui/components/FileBrowser.d.ts.map +1 -0
- package/dist/ui/components/FileBrowser.js +45 -0
- package/dist/ui/components/FileBrowser.js.map +1 -0
- package/dist/ui/components/LLMSetupWizard.d.ts +8 -0
- package/dist/ui/components/LLMSetupWizard.d.ts.map +1 -0
- package/dist/ui/components/LLMSetupWizard.js +183 -0
- package/dist/ui/components/LLMSetupWizard.js.map +1 -0
- package/dist/ui/components/Logo.d.ts +19 -0
- package/dist/ui/components/Logo.d.ts.map +1 -0
- package/dist/ui/components/Logo.js +99 -0
- package/dist/ui/components/Logo.js.map +1 -0
- package/dist/ui/components/MarkdownRenderer.d.ts +9 -0
- package/dist/ui/components/MarkdownRenderer.d.ts.map +1 -0
- package/dist/ui/components/MarkdownRenderer.js +198 -0
- package/dist/ui/components/MarkdownRenderer.js.map +1 -0
- package/dist/ui/components/ModelSelector.d.ts +8 -0
- package/dist/ui/components/ModelSelector.d.ts.map +1 -0
- package/dist/ui/components/ModelSelector.js +111 -0
- package/dist/ui/components/ModelSelector.js.map +1 -0
- package/dist/ui/components/PlanExecuteApp.d.ts +23 -0
- package/dist/ui/components/PlanExecuteApp.d.ts.map +1 -0
- package/dist/ui/components/PlanExecuteApp.js +1432 -0
- package/dist/ui/components/PlanExecuteApp.js.map +1 -0
- package/dist/ui/components/ProgressBar.d.ts +10 -0
- package/dist/ui/components/ProgressBar.d.ts.map +1 -0
- package/dist/ui/components/ProgressBar.js +26 -0
- package/dist/ui/components/ProgressBar.js.map +1 -0
- package/dist/ui/components/StatusBar.d.ts +23 -0
- package/dist/ui/components/StatusBar.d.ts.map +1 -0
- package/dist/ui/components/StatusBar.js +162 -0
- package/dist/ui/components/StatusBar.js.map +1 -0
- package/dist/ui/components/ThinkingIndicator.d.ts +14 -0
- package/dist/ui/components/ThinkingIndicator.d.ts.map +1 -0
- package/dist/ui/components/ThinkingIndicator.js +63 -0
- package/dist/ui/components/ThinkingIndicator.js.map +1 -0
- package/dist/ui/components/TodoListView.d.ts +11 -0
- package/dist/ui/components/TodoListView.d.ts.map +1 -0
- package/dist/ui/components/TodoListView.js +69 -0
- package/dist/ui/components/TodoListView.js.map +1 -0
- package/dist/ui/components/ToolSelector.d.ts +7 -0
- package/dist/ui/components/ToolSelector.d.ts.map +1 -0
- package/dist/ui/components/ToolSelector.js +112 -0
- package/dist/ui/components/ToolSelector.js.map +1 -0
- package/dist/ui/components/dialogs/ApprovalDialog.d.ts +13 -0
- package/dist/ui/components/dialogs/ApprovalDialog.d.ts.map +1 -0
- package/dist/ui/components/dialogs/ApprovalDialog.js +173 -0
- package/dist/ui/components/dialogs/ApprovalDialog.js.map +1 -0
- package/dist/ui/components/dialogs/AskUserDialog.d.ts +9 -0
- package/dist/ui/components/dialogs/AskUserDialog.d.ts.map +1 -0
- package/dist/ui/components/dialogs/AskUserDialog.js +111 -0
- package/dist/ui/components/dialogs/AskUserDialog.js.map +1 -0
- package/dist/ui/components/dialogs/DocsBrowser.d.ts +8 -0
- package/dist/ui/components/dialogs/DocsBrowser.d.ts.map +1 -0
- package/dist/ui/components/dialogs/DocsBrowser.js +127 -0
- package/dist/ui/components/dialogs/DocsBrowser.js.map +1 -0
- package/dist/ui/components/dialogs/RatingDialog.d.ts +9 -0
- package/dist/ui/components/dialogs/RatingDialog.d.ts.map +1 -0
- package/dist/ui/components/dialogs/RatingDialog.js +54 -0
- package/dist/ui/components/dialogs/RatingDialog.js.map +1 -0
- package/dist/ui/components/dialogs/SettingsDialog.d.ts +10 -0
- package/dist/ui/components/dialogs/SettingsDialog.d.ts.map +1 -0
- package/dist/ui/components/dialogs/SettingsDialog.js +563 -0
- package/dist/ui/components/dialogs/SettingsDialog.js.map +1 -0
- package/dist/ui/components/dialogs/index.d.ts +4 -0
- package/dist/ui/components/dialogs/index.d.ts.map +1 -0
- package/dist/ui/components/dialogs/index.js +4 -0
- package/dist/ui/components/dialogs/index.js.map +1 -0
- package/dist/ui/components/index.d.ts +12 -0
- package/dist/ui/components/index.d.ts.map +1 -0
- package/dist/ui/components/index.js +9 -0
- package/dist/ui/components/index.js.map +1 -0
- package/dist/ui/components/panels/SessionPanel.d.ts +8 -0
- package/dist/ui/components/panels/SessionPanel.d.ts.map +1 -0
- package/dist/ui/components/panels/SessionPanel.js +81 -0
- package/dist/ui/components/panels/SessionPanel.js.map +1 -0
- package/dist/ui/components/panels/index.d.ts +3 -0
- package/dist/ui/components/panels/index.d.ts.map +1 -0
- package/dist/ui/components/panels/index.js +3 -0
- package/dist/ui/components/panels/index.js.map +1 -0
- package/dist/ui/components/views/ChatView.d.ts +12 -0
- package/dist/ui/components/views/ChatView.d.ts.map +1 -0
- package/dist/ui/components/views/ChatView.js +289 -0
- package/dist/ui/components/views/ChatView.js.map +1 -0
- package/dist/ui/components/views/index.d.ts +2 -0
- package/dist/ui/components/views/index.d.ts.map +1 -0
- package/dist/ui/components/views/index.js +2 -0
- package/dist/ui/components/views/index.js.map +1 -0
- package/dist/ui/contexts/TokenContext.d.ts +29 -0
- package/dist/ui/contexts/TokenContext.d.ts.map +1 -0
- package/dist/ui/contexts/TokenContext.js +79 -0
- package/dist/ui/contexts/TokenContext.js.map +1 -0
- package/dist/ui/hooks/atFileProcessor.d.ts +15 -0
- package/dist/ui/hooks/atFileProcessor.d.ts.map +1 -0
- package/dist/ui/hooks/atFileProcessor.js +88 -0
- package/dist/ui/hooks/atFileProcessor.js.map +1 -0
- package/dist/ui/hooks/index.d.ts +8 -0
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +8 -0
- package/dist/ui/hooks/index.js.map +1 -0
- package/dist/ui/hooks/slashCommandProcessor.d.ts +21 -0
- package/dist/ui/hooks/slashCommandProcessor.d.ts.map +1 -0
- package/dist/ui/hooks/slashCommandProcessor.js +100 -0
- package/dist/ui/hooks/slashCommandProcessor.js.map +1 -0
- package/dist/ui/hooks/useCommandBrowserState.d.ts +12 -0
- package/dist/ui/hooks/useCommandBrowserState.d.ts.map +1 -0
- package/dist/ui/hooks/useCommandBrowserState.js +66 -0
- package/dist/ui/hooks/useCommandBrowserState.js.map +1 -0
- package/dist/ui/hooks/useFileBrowserState.d.ts +15 -0
- package/dist/ui/hooks/useFileBrowserState.d.ts.map +1 -0
- package/dist/ui/hooks/useFileBrowserState.js +79 -0
- package/dist/ui/hooks/useFileBrowserState.js.map +1 -0
- package/dist/ui/hooks/useFileList.d.ts +20 -0
- package/dist/ui/hooks/useFileList.d.ts.map +1 -0
- package/dist/ui/hooks/useFileList.js +56 -0
- package/dist/ui/hooks/useFileList.js.map +1 -0
- package/dist/ui/hooks/useInputHistory.d.ts +9 -0
- package/dist/ui/hooks/useInputHistory.d.ts.map +1 -0
- package/dist/ui/hooks/useInputHistory.js +68 -0
- package/dist/ui/hooks/useInputHistory.js.map +1 -0
- package/dist/ui/hooks/usePlanExecution.d.ts +8 -0
- package/dist/ui/hooks/usePlanExecution.d.ts.map +1 -0
- package/dist/ui/hooks/usePlanExecution.js +208 -0
- package/dist/ui/hooks/usePlanExecution.js.map +1 -0
- package/dist/ui/index.d.ts +7 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +7 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/ink-entry.d.ts +3 -0
- package/dist/ui/ink-entry.d.ts.map +1 -0
- package/dist/ui/ink-entry.js +21 -0
- package/dist/ui/ink-entry.js.map +1 -0
- package/dist/utils/file-system.d.ts +9 -0
- package/dist/utils/file-system.d.ts.map +1 -0
- package/dist/utils/file-system.js +99 -0
- package/dist/utils/file-system.js.map +1 -0
- package/dist/utils/git-utils.d.ts +2 -0
- package/dist/utils/git-utils.d.ts.map +1 -0
- package/dist/utils/git-utils.js +16 -0
- package/dist/utils/git-utils.js.map +1 -0
- package/dist/utils/json-stream-logger.d.ts +52 -0
- package/dist/utils/json-stream-logger.d.ts.map +1 -0
- package/dist/utils/json-stream-logger.js +442 -0
- package/dist/utils/json-stream-logger.js.map +1 -0
- package/dist/utils/logger.d.ts +86 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +588 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/platform-utils.d.ts +19 -0
- package/dist/utils/platform-utils.d.ts.map +1 -0
- package/dist/utils/platform-utils.js +134 -0
- package/dist/utils/platform-utils.js.map +1 -0
- package/dist/utils/wsl-utils.d.ts +4 -0
- package/dist/utils/wsl-utils.d.ts.map +1 -0
- package/dist/utils/wsl-utils.js +72 -0
- package/dist/utils/wsl-utils.js.map +1 -0
- package/package.json +150 -0
- package/scripts/patch-yoga.js +48 -0
|
@@ -0,0 +1,1002 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { configManager } from '../config/config-manager.js';
|
|
3
|
+
import { NetworkError, APIError, TimeoutError, ConnectionError, } from '../../errors/network.js';
|
|
4
|
+
import { LLMError, TokenLimitError, RateLimitError, ContextLengthError, } from '../../errors/llm.js';
|
|
5
|
+
import { logger, isLLMLogEnabled } from '../../utils/logger.js';
|
|
6
|
+
import { usageTracker } from '../usage-tracker.js';
|
|
7
|
+
export class LLMClient {
|
|
8
|
+
axiosInstance;
|
|
9
|
+
baseUrl;
|
|
10
|
+
apiKey;
|
|
11
|
+
model;
|
|
12
|
+
modelName;
|
|
13
|
+
currentAbortController = null;
|
|
14
|
+
isInterrupted = false;
|
|
15
|
+
static DEFAULT_MAX_RETRIES = 3;
|
|
16
|
+
constructor() {
|
|
17
|
+
const endpoint = configManager.getCurrentEndpoint();
|
|
18
|
+
const currentModel = configManager.getCurrentModel();
|
|
19
|
+
if (!endpoint || !currentModel) {
|
|
20
|
+
throw new Error('No endpoint or model configured. Run: open config init');
|
|
21
|
+
}
|
|
22
|
+
this.baseUrl = endpoint.baseUrl;
|
|
23
|
+
this.apiKey = endpoint.apiKey || '';
|
|
24
|
+
this.model = currentModel.id;
|
|
25
|
+
this.modelName = currentModel.name;
|
|
26
|
+
this.axiosInstance = axios.create({
|
|
27
|
+
baseURL: this.baseUrl,
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
...(this.apiKey && { Authorization: `Bearer ${this.apiKey}` }),
|
|
31
|
+
},
|
|
32
|
+
timeout: 600000,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
preprocessMessages(messages, modelId) {
|
|
36
|
+
return messages.map((msg) => {
|
|
37
|
+
if (msg.role !== 'assistant') {
|
|
38
|
+
return msg;
|
|
39
|
+
}
|
|
40
|
+
const msgAny = msg;
|
|
41
|
+
let processedMsg = { ...msg };
|
|
42
|
+
if (msgAny.reasoning_content && (!msg.content || msg.content.trim() === '')) {
|
|
43
|
+
processedMsg.content = msgAny.reasoning_content;
|
|
44
|
+
delete processedMsg.reasoning_content;
|
|
45
|
+
}
|
|
46
|
+
if (/^gpt-oss-(120b|20b)$/i.test(modelId)) {
|
|
47
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
48
|
+
if (!processedMsg.content || processedMsg.content.trim() === '') {
|
|
49
|
+
const toolNames = msg.tool_calls.map(tc => tc.function.name).join(', ');
|
|
50
|
+
processedMsg.content = msgAny.reasoning || `Calling tools: ${toolNames}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (processedMsg.content === undefined || processedMsg.content === null) {
|
|
55
|
+
processedMsg.content = '';
|
|
56
|
+
}
|
|
57
|
+
return processedMsg;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async chatCompletion(options, retryConfig) {
|
|
61
|
+
const maxRetries = retryConfig?.disableRetry ? 1 : (retryConfig?.maxRetries ?? LLMClient.DEFAULT_MAX_RETRIES);
|
|
62
|
+
const currentAttempt = retryConfig?.currentAttempt ?? 1;
|
|
63
|
+
logger.enter('chatCompletion', {
|
|
64
|
+
model: options.model || this.model,
|
|
65
|
+
messagesCount: options.messages?.length || 0,
|
|
66
|
+
hasTools: !!options.tools,
|
|
67
|
+
attempt: currentAttempt,
|
|
68
|
+
maxRetries
|
|
69
|
+
});
|
|
70
|
+
const url = '/chat/completions';
|
|
71
|
+
try {
|
|
72
|
+
logger.flow('메시지 전처리 시작');
|
|
73
|
+
const modelId = options.model || this.model;
|
|
74
|
+
const processedMessages = options.messages ?
|
|
75
|
+
this.preprocessMessages(options.messages, modelId) : [];
|
|
76
|
+
logger.vars({ name: 'modelId', value: modelId }, { name: 'originalMessages', value: options.messages?.length || 0 }, { name: 'processedMessages', value: processedMessages.length }, { name: 'temperature', value: options.temperature ?? 0.7 });
|
|
77
|
+
const requestBody = {
|
|
78
|
+
model: modelId,
|
|
79
|
+
messages: processedMessages,
|
|
80
|
+
temperature: options.temperature ?? 0.7,
|
|
81
|
+
max_tokens: options.max_tokens,
|
|
82
|
+
stream: false,
|
|
83
|
+
...(options.tools && {
|
|
84
|
+
tools: options.tools,
|
|
85
|
+
parallel_tool_calls: false,
|
|
86
|
+
...(options.tool_choice && { tool_choice: options.tool_choice }),
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
logger.flow('API 요청 준비 완료');
|
|
90
|
+
logger.httpRequest('POST', `${this.baseUrl}${url}`, {
|
|
91
|
+
model: modelId,
|
|
92
|
+
messages: `${processedMessages.length} messages`,
|
|
93
|
+
temperature: requestBody.temperature,
|
|
94
|
+
max_tokens: requestBody.max_tokens,
|
|
95
|
+
tools: options.tools ? `${options.tools.length} tools` : 'none',
|
|
96
|
+
});
|
|
97
|
+
logger.verbose('Full Request Body', requestBody);
|
|
98
|
+
if (isLLMLogEnabled()) {
|
|
99
|
+
logger.llmRequest(processedMessages, modelId, options.tools);
|
|
100
|
+
}
|
|
101
|
+
logger.startTimer('llm-api-call');
|
|
102
|
+
this.currentAbortController = new AbortController();
|
|
103
|
+
const response = await this.axiosInstance.post(url, requestBody, {
|
|
104
|
+
signal: this.currentAbortController.signal,
|
|
105
|
+
});
|
|
106
|
+
this.currentAbortController = null;
|
|
107
|
+
const elapsed = logger.endTimer('llm-api-call');
|
|
108
|
+
logger.flow('API 응답 수신 완료');
|
|
109
|
+
if (!response.data.choices || !Array.isArray(response.data.choices)) {
|
|
110
|
+
logger.error('Invalid response structure - missing choices array', response.data);
|
|
111
|
+
throw new Error('LLM 응답 형식이 올바르지 않습니다. choices 배열이 없습니다.');
|
|
112
|
+
}
|
|
113
|
+
logger.httpResponse(response.status, response.statusText, {
|
|
114
|
+
choices: response.data.choices.length,
|
|
115
|
+
usage: response.data.usage,
|
|
116
|
+
});
|
|
117
|
+
logger.verbose('Full Response', response.data);
|
|
118
|
+
logger.vars({ name: 'responseChoices', value: response.data.choices.length }, { name: 'tokensUsed', value: response.data.usage?.total_tokens || 0 }, { name: 'responseTime', value: elapsed });
|
|
119
|
+
if (isLLMLogEnabled()) {
|
|
120
|
+
const responseContent = response.data.choices[0]?.message?.content || '';
|
|
121
|
+
const toolCalls = response.data.choices[0]?.message?.tool_calls;
|
|
122
|
+
logger.llmResponse(responseContent, toolCalls);
|
|
123
|
+
}
|
|
124
|
+
const reasoningContent = response.data.choices[0]?.message?.reasoning;
|
|
125
|
+
const maxTokens = options.max_tokens;
|
|
126
|
+
const isInternalCall = maxTokens && maxTokens < 500;
|
|
127
|
+
if (reasoningContent && !isInternalCall) {
|
|
128
|
+
const { emitReasoning } = await import('../../tools/llm/simple/file-tools.js');
|
|
129
|
+
emitReasoning(reasoningContent, false);
|
|
130
|
+
logger.debug('Reasoning content emitted', { length: reasoningContent.length });
|
|
131
|
+
}
|
|
132
|
+
else if (reasoningContent && isInternalCall) {
|
|
133
|
+
logger.debug('Reasoning skipped (internal call)', { maxTokens, length: reasoningContent.length });
|
|
134
|
+
}
|
|
135
|
+
if (response.data.usage) {
|
|
136
|
+
const promptTokens = response.data.usage.prompt_tokens || 0;
|
|
137
|
+
usageTracker.recordUsage(this.model, promptTokens, response.data.usage.completion_tokens || 0, undefined, promptTokens);
|
|
138
|
+
}
|
|
139
|
+
logger.exit('chatCompletion', {
|
|
140
|
+
success: true,
|
|
141
|
+
choices: response.data.choices.length,
|
|
142
|
+
elapsed
|
|
143
|
+
});
|
|
144
|
+
return response.data;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
this.currentAbortController = null;
|
|
148
|
+
if (axios.isCancel(error) || (error instanceof Error && error.name === 'CanceledError')) {
|
|
149
|
+
logger.flow('API 호출 취소됨 (사용자 인터럽트)');
|
|
150
|
+
logger.exit('chatCompletion', { success: false, aborted: true });
|
|
151
|
+
throw new Error('INTERRUPTED');
|
|
152
|
+
}
|
|
153
|
+
if (currentAttempt < maxRetries && this.isRetryableError(error)) {
|
|
154
|
+
const delay = Math.pow(2, currentAttempt - 1) * 1000;
|
|
155
|
+
logger.debug(`LLM 호출 실패 (${currentAttempt}/${maxRetries}), ${delay}ms 후 재시도...`, {
|
|
156
|
+
error: error.message,
|
|
157
|
+
attempt: currentAttempt,
|
|
158
|
+
maxRetries,
|
|
159
|
+
delay
|
|
160
|
+
});
|
|
161
|
+
await this.sleep(delay);
|
|
162
|
+
return this.chatCompletion(options, {
|
|
163
|
+
maxRetries,
|
|
164
|
+
currentAttempt: currentAttempt + 1,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
logger.flow('API 호출 실패 - 에러 처리');
|
|
168
|
+
if (currentAttempt > 1) {
|
|
169
|
+
logger.error(`LLM 호출 ${maxRetries}번 재시도 후 최종 실패`, {
|
|
170
|
+
error: error.message,
|
|
171
|
+
attempts: currentAttempt
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
logger.exit('chatCompletion', { success: false, error: error.message, attempts: currentAttempt });
|
|
175
|
+
throw this.handleError(error, {
|
|
176
|
+
method: 'POST',
|
|
177
|
+
url,
|
|
178
|
+
body: options,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
abort() {
|
|
183
|
+
logger.flow('LLM 인터럽트 - 모든 동작 중단');
|
|
184
|
+
this.isInterrupted = true;
|
|
185
|
+
if (this.currentAbortController) {
|
|
186
|
+
this.currentAbortController.abort();
|
|
187
|
+
this.currentAbortController = null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
checkInterrupted() {
|
|
191
|
+
return this.isInterrupted;
|
|
192
|
+
}
|
|
193
|
+
resetInterrupt() {
|
|
194
|
+
this.isInterrupted = false;
|
|
195
|
+
}
|
|
196
|
+
isRequestActive() {
|
|
197
|
+
return this.currentAbortController !== null;
|
|
198
|
+
}
|
|
199
|
+
isRetryableError(error) {
|
|
200
|
+
if (error instanceof Error && error.message === 'INTERRUPTED') {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (axios.isAxiosError(error)) {
|
|
204
|
+
const axiosError = error;
|
|
205
|
+
if (!axiosError.response) {
|
|
206
|
+
const retryableCodes = ['ECONNREFUSED', 'ETIMEDOUT', 'ECONNRESET', 'ECONNABORTED', 'ENOTFOUND', 'EHOSTUNREACH'];
|
|
207
|
+
if (axiosError.code && retryableCodes.includes(axiosError.code)) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
if (axiosError.message.includes('timeout')) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
const status = axiosError.response.status;
|
|
216
|
+
if (status === 429) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (status >= 500) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
sleep(ms) {
|
|
227
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
228
|
+
}
|
|
229
|
+
async *chatCompletionStream(options) {
|
|
230
|
+
const url = '/chat/completions';
|
|
231
|
+
try {
|
|
232
|
+
const modelId = options.model || this.model;
|
|
233
|
+
const processedMessages = options.messages ?
|
|
234
|
+
this.preprocessMessages(options.messages, modelId) : [];
|
|
235
|
+
const requestBody = {
|
|
236
|
+
model: modelId,
|
|
237
|
+
messages: processedMessages,
|
|
238
|
+
temperature: options.temperature ?? 0.7,
|
|
239
|
+
max_tokens: options.max_tokens,
|
|
240
|
+
stream: true,
|
|
241
|
+
...(options.tools && {
|
|
242
|
+
tools: options.tools,
|
|
243
|
+
...(options.tool_choice && { tool_choice: options.tool_choice }),
|
|
244
|
+
}),
|
|
245
|
+
};
|
|
246
|
+
logger.httpRequest('POST (stream)', `${this.baseUrl}${url}`, {
|
|
247
|
+
model: modelId,
|
|
248
|
+
messages: `${processedMessages.length} messages`,
|
|
249
|
+
temperature: requestBody.temperature,
|
|
250
|
+
max_tokens: requestBody.max_tokens,
|
|
251
|
+
});
|
|
252
|
+
logger.verbose('Full Streaming Request Body', requestBody);
|
|
253
|
+
this.currentAbortController = new AbortController();
|
|
254
|
+
const response = await this.axiosInstance.post(url, requestBody, {
|
|
255
|
+
responseType: 'stream',
|
|
256
|
+
signal: this.currentAbortController.signal,
|
|
257
|
+
});
|
|
258
|
+
logger.debug('Streaming response started', { status: response.status });
|
|
259
|
+
const stream = response.data;
|
|
260
|
+
let buffer = '';
|
|
261
|
+
let chunkCount = 0;
|
|
262
|
+
const maxTokens = options.max_tokens;
|
|
263
|
+
const isInternalCall = maxTokens && maxTokens < 500;
|
|
264
|
+
const { emitReasoning } = await import('../../tools/llm/simple/file-tools.js');
|
|
265
|
+
try {
|
|
266
|
+
for await (const chunk of stream) {
|
|
267
|
+
if (this.isInterrupted) {
|
|
268
|
+
logger.flow('Interrupt detected during streaming - stopping');
|
|
269
|
+
throw new Error('INTERRUPTED');
|
|
270
|
+
}
|
|
271
|
+
buffer += chunk.toString();
|
|
272
|
+
const lines = buffer.split('\n');
|
|
273
|
+
buffer = lines.pop() || '';
|
|
274
|
+
for (const line of lines) {
|
|
275
|
+
const trimmed = line.trim();
|
|
276
|
+
if (!trimmed || trimmed === 'data: [DONE]')
|
|
277
|
+
continue;
|
|
278
|
+
if (trimmed.startsWith('data: ')) {
|
|
279
|
+
try {
|
|
280
|
+
const jsonStr = trimmed.slice(6);
|
|
281
|
+
const data = JSON.parse(jsonStr);
|
|
282
|
+
chunkCount++;
|
|
283
|
+
const reasoningDelta = data.choices[0]?.delta?.reasoning;
|
|
284
|
+
if (reasoningDelta && !isInternalCall) {
|
|
285
|
+
emitReasoning(reasoningDelta, true);
|
|
286
|
+
logger.debug('Reasoning delta emitted', { length: reasoningDelta.length });
|
|
287
|
+
}
|
|
288
|
+
else if (reasoningDelta && isInternalCall) {
|
|
289
|
+
logger.debug('Reasoning delta skipped (internal call)', { maxTokens });
|
|
290
|
+
}
|
|
291
|
+
yield data;
|
|
292
|
+
}
|
|
293
|
+
catch (parseError) {
|
|
294
|
+
logger.debug('Skipping invalid chunk', { line: trimmed });
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
this.currentAbortController = null;
|
|
303
|
+
}
|
|
304
|
+
logger.debug('Streaming response completed', { chunkCount });
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
throw this.handleError(error, {
|
|
308
|
+
method: 'POST (stream)',
|
|
309
|
+
url,
|
|
310
|
+
body: options,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async sendMessage(userMessage, systemPrompt) {
|
|
315
|
+
logger.enter('sendMessage', {
|
|
316
|
+
messageLength: userMessage.length,
|
|
317
|
+
hasSystemPrompt: !!systemPrompt
|
|
318
|
+
});
|
|
319
|
+
logger.flow('메시지 배열 구성');
|
|
320
|
+
const messages = [];
|
|
321
|
+
if (systemPrompt) {
|
|
322
|
+
logger.vars({ name: 'systemPrompt', value: systemPrompt.substring(0, 100) + (systemPrompt.length > 100 ? '...' : '') });
|
|
323
|
+
messages.push({
|
|
324
|
+
role: 'system',
|
|
325
|
+
content: systemPrompt,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
messages.push({
|
|
329
|
+
role: 'user',
|
|
330
|
+
content: userMessage,
|
|
331
|
+
});
|
|
332
|
+
logger.vars({ name: 'totalMessages', value: messages.length }, { name: 'userMessage', value: userMessage.substring(0, 100) + (userMessage.length > 100 ? '...' : '') });
|
|
333
|
+
logger.flow('LLM API 호출');
|
|
334
|
+
logger.startTimer('sendMessage-api');
|
|
335
|
+
const response = await this.chatCompletion({ messages });
|
|
336
|
+
const elapsed = logger.endTimer('sendMessage-api');
|
|
337
|
+
logger.flow('응답 처리');
|
|
338
|
+
if (response.choices.length === 0) {
|
|
339
|
+
logger.flow('응답 없음 - 에러 발생');
|
|
340
|
+
logger.exit('sendMessage', { success: false, reason: 'No response from LLM' });
|
|
341
|
+
throw new Error('No response from LLM');
|
|
342
|
+
}
|
|
343
|
+
const responseContent = response.choices[0]?.message.content || '';
|
|
344
|
+
logger.vars({ name: 'responseLength', value: responseContent.length }, { name: 'apiTime', value: elapsed });
|
|
345
|
+
logger.exit('sendMessage', {
|
|
346
|
+
success: true,
|
|
347
|
+
responseLength: responseContent.length,
|
|
348
|
+
elapsed
|
|
349
|
+
});
|
|
350
|
+
return responseContent;
|
|
351
|
+
}
|
|
352
|
+
async *sendMessageStream(userMessage, systemPrompt) {
|
|
353
|
+
const messages = [];
|
|
354
|
+
if (systemPrompt) {
|
|
355
|
+
messages.push({
|
|
356
|
+
role: 'system',
|
|
357
|
+
content: systemPrompt,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
messages.push({
|
|
361
|
+
role: 'user',
|
|
362
|
+
content: userMessage,
|
|
363
|
+
});
|
|
364
|
+
for await (const chunk of this.chatCompletionStream({ messages })) {
|
|
365
|
+
const content = chunk.choices[0]?.delta?.content;
|
|
366
|
+
if (content) {
|
|
367
|
+
yield content;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async chatCompletionWithTools(messages, tools, options) {
|
|
372
|
+
let workingMessages = [...messages];
|
|
373
|
+
const toolCallHistory = [];
|
|
374
|
+
let iterations = 0;
|
|
375
|
+
let contextLengthRecoveryAttempted = false;
|
|
376
|
+
let noToolCallRetries = 0;
|
|
377
|
+
let finalResponseFailures = 0;
|
|
378
|
+
const MAX_NO_TOOL_CALL_RETRIES = 3;
|
|
379
|
+
const MAX_FINAL_RESPONSE_FAILURES = 3;
|
|
380
|
+
while (true) {
|
|
381
|
+
if (this.isInterrupted) {
|
|
382
|
+
logger.flow('Interrupt detected - stopping tool loop');
|
|
383
|
+
throw new Error('INTERRUPTED');
|
|
384
|
+
}
|
|
385
|
+
iterations++;
|
|
386
|
+
if (options?.getPendingMessage && options?.clearPendingMessage) {
|
|
387
|
+
const pendingMsg = options.getPendingMessage();
|
|
388
|
+
if (pendingMsg) {
|
|
389
|
+
logger.flow('Injecting pending user message into conversation');
|
|
390
|
+
workingMessages.push({ role: 'user', content: pendingMsg });
|
|
391
|
+
options.clearPendingMessage();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
let response;
|
|
395
|
+
try {
|
|
396
|
+
response = await this.chatCompletion({
|
|
397
|
+
messages: workingMessages,
|
|
398
|
+
tools,
|
|
399
|
+
tool_choice: 'required',
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (error instanceof ContextLengthError && !contextLengthRecoveryAttempted) {
|
|
404
|
+
contextLengthRecoveryAttempted = true;
|
|
405
|
+
logger.flow('ContextLengthError detected - attempting recovery with compact');
|
|
406
|
+
let rollbackIdx = workingMessages.length - 1;
|
|
407
|
+
while (rollbackIdx >= 0 && workingMessages[rollbackIdx]?.role === 'tool') {
|
|
408
|
+
rollbackIdx--;
|
|
409
|
+
}
|
|
410
|
+
if (rollbackIdx >= 0 && workingMessages[rollbackIdx]?.tool_calls) {
|
|
411
|
+
workingMessages = workingMessages.slice(0, rollbackIdx);
|
|
412
|
+
logger.debug('Rolled back messages to before last tool execution', {
|
|
413
|
+
removedCount: workingMessages.length - rollbackIdx,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const { CompactManager } = await import('../compact/compact-manager.js');
|
|
417
|
+
const { buildCompactedMessages } = await import('../compact/compact-prompts.js');
|
|
418
|
+
const compactManager = new CompactManager(this);
|
|
419
|
+
const compactResult = await compactManager.compact(workingMessages, {
|
|
420
|
+
workingDirectory: process.cwd(),
|
|
421
|
+
});
|
|
422
|
+
if (compactResult.success && compactResult.compactedSummary) {
|
|
423
|
+
const compactedMessages = buildCompactedMessages(compactResult.compactedSummary, {
|
|
424
|
+
workingDirectory: process.cwd(),
|
|
425
|
+
});
|
|
426
|
+
workingMessages = [...compactedMessages];
|
|
427
|
+
logger.flow('Compact completed, retrying with reduced context', {
|
|
428
|
+
originalCount: compactResult.originalMessageCount,
|
|
429
|
+
newCount: compactedMessages.length,
|
|
430
|
+
});
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
logger.error('Compact failed during recovery', { error: compactResult.error });
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
if (this.isInterrupted) {
|
|
441
|
+
logger.flow('Interrupt detected after LLM call - stopping');
|
|
442
|
+
throw new Error('INTERRUPTED');
|
|
443
|
+
}
|
|
444
|
+
const choice = response.choices[0];
|
|
445
|
+
if (!choice) {
|
|
446
|
+
throw new Error('응답에서 choice를 찾을 수 없습니다.');
|
|
447
|
+
}
|
|
448
|
+
const assistantMessage = choice.message;
|
|
449
|
+
workingMessages.push(assistantMessage);
|
|
450
|
+
if (assistantMessage.tool_calls && assistantMessage.tool_calls.length > 0) {
|
|
451
|
+
if (assistantMessage.tool_calls.length > 1) {
|
|
452
|
+
const toolNames = assistantMessage.tool_calls.map(tc => tc.function.name).join(', ');
|
|
453
|
+
logger.warn(`[MULTI-TOOL DETECTED] LLM returned ${assistantMessage.tool_calls.length} tools: ${toolNames}`);
|
|
454
|
+
}
|
|
455
|
+
for (const toolCall of assistantMessage.tool_calls) {
|
|
456
|
+
const toolName = toolCall.function.name;
|
|
457
|
+
let toolArgs;
|
|
458
|
+
try {
|
|
459
|
+
toolArgs = JSON.parse(toolCall.function.arguments);
|
|
460
|
+
}
|
|
461
|
+
catch (parseError) {
|
|
462
|
+
const errorMsg = `Tool argument parsing failed for ${toolName}`;
|
|
463
|
+
logger.error(errorMsg, parseError);
|
|
464
|
+
logger.debug('Raw arguments', { raw: toolCall.function.arguments });
|
|
465
|
+
workingMessages.push({
|
|
466
|
+
role: 'tool',
|
|
467
|
+
content: `Error: Failed to parse tool arguments - ${parseError instanceof Error ? parseError.message : 'Unknown error'}`,
|
|
468
|
+
tool_call_id: toolCall.id,
|
|
469
|
+
});
|
|
470
|
+
toolCallHistory.push({
|
|
471
|
+
tool: toolName,
|
|
472
|
+
args: { raw: toolCall.function.arguments },
|
|
473
|
+
result: `Error: Argument parsing failed`,
|
|
474
|
+
});
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
const { executeFileTool, requestToolApproval } = await import('../../tools/llm/simple/file-tools.js');
|
|
478
|
+
const approvalResult = await requestToolApproval(toolName, toolArgs);
|
|
479
|
+
if (approvalResult && typeof approvalResult === 'object' && approvalResult.reject) {
|
|
480
|
+
logger.flow(`Tool rejected by user: ${toolName}`);
|
|
481
|
+
const rejectMessage = approvalResult.comment
|
|
482
|
+
? `Tool execution rejected by user. Reason: ${approvalResult.comment}`
|
|
483
|
+
: 'Tool execution rejected by user.';
|
|
484
|
+
workingMessages.push({
|
|
485
|
+
role: 'tool',
|
|
486
|
+
content: rejectMessage,
|
|
487
|
+
tool_call_id: toolCall.id,
|
|
488
|
+
});
|
|
489
|
+
toolCallHistory.push({
|
|
490
|
+
tool: toolName,
|
|
491
|
+
args: toolArgs,
|
|
492
|
+
result: rejectMessage,
|
|
493
|
+
});
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
logger.debug(`Executing tool: ${toolName}`, toolArgs);
|
|
497
|
+
let result;
|
|
498
|
+
try {
|
|
499
|
+
result = await executeFileTool(toolName, toolArgs);
|
|
500
|
+
logger.toolExecution(toolName, toolArgs, result);
|
|
501
|
+
if (isLLMLogEnabled()) {
|
|
502
|
+
logger.llmToolResult(toolName, result.result || '', result.success);
|
|
503
|
+
}
|
|
504
|
+
if (toolName === 'final_response') {
|
|
505
|
+
if (result.success && result.metadata?.['isFinalResponse']) {
|
|
506
|
+
logger.flow('final_response tool executed successfully - returning');
|
|
507
|
+
const { emitAssistantResponse } = await import('../../tools/llm/simple/file-tools.js');
|
|
508
|
+
emitAssistantResponse(result.result || '');
|
|
509
|
+
workingMessages.push({
|
|
510
|
+
role: 'tool',
|
|
511
|
+
content: result.result || '',
|
|
512
|
+
tool_call_id: toolCall.id,
|
|
513
|
+
});
|
|
514
|
+
toolCallHistory.push({
|
|
515
|
+
tool: toolName,
|
|
516
|
+
args: toolArgs,
|
|
517
|
+
result: result.result || '',
|
|
518
|
+
});
|
|
519
|
+
return {
|
|
520
|
+
message: {
|
|
521
|
+
role: 'assistant',
|
|
522
|
+
content: result.result || '',
|
|
523
|
+
},
|
|
524
|
+
toolCalls: toolCallHistory,
|
|
525
|
+
allMessages: workingMessages,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
finalResponseFailures++;
|
|
530
|
+
logger.flow(`final_response failed (attempt ${finalResponseFailures}/${MAX_FINAL_RESPONSE_FAILURES}): ${result.error}`);
|
|
531
|
+
if (finalResponseFailures >= MAX_FINAL_RESPONSE_FAILURES) {
|
|
532
|
+
logger.warn('Max final_response failures exceeded - forcing completion');
|
|
533
|
+
const fallbackMessage = toolArgs['message'] || 'Task completed with incomplete TODOs.';
|
|
534
|
+
const { emitAssistantResponse } = await import('../../tools/llm/simple/file-tools.js');
|
|
535
|
+
emitAssistantResponse(fallbackMessage);
|
|
536
|
+
return {
|
|
537
|
+
message: { role: 'assistant', content: fallbackMessage },
|
|
538
|
+
toolCalls: toolCallHistory,
|
|
539
|
+
allMessages: workingMessages,
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
catch (toolError) {
|
|
546
|
+
logger.toolExecution(toolName, toolArgs, undefined, toolError);
|
|
547
|
+
if (isLLMLogEnabled()) {
|
|
548
|
+
const errorMsg = toolError instanceof Error ? toolError.message : String(toolError);
|
|
549
|
+
logger.llmToolResult(toolName, `Error: ${errorMsg}`, false);
|
|
550
|
+
}
|
|
551
|
+
result = {
|
|
552
|
+
success: false,
|
|
553
|
+
error: toolError instanceof Error ? toolError.message : String(toolError),
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
workingMessages.push({
|
|
557
|
+
role: 'tool',
|
|
558
|
+
content: result.success ? result.result || '' : `Error: ${result.error}`,
|
|
559
|
+
tool_call_id: toolCall.id,
|
|
560
|
+
});
|
|
561
|
+
toolCallHistory.push({
|
|
562
|
+
tool: toolName,
|
|
563
|
+
args: toolArgs,
|
|
564
|
+
result: result.success ? result.result || '' : `Error: ${result.error}`,
|
|
565
|
+
});
|
|
566
|
+
if (this.isInterrupted) {
|
|
567
|
+
logger.flow('Interrupt detected after tool execution - stopping');
|
|
568
|
+
throw new Error('INTERRUPTED');
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
noToolCallRetries++;
|
|
575
|
+
logger.flow(`No tool call - enforcing tool usage (attempt ${noToolCallRetries}/${MAX_NO_TOOL_CALL_RETRIES})`);
|
|
576
|
+
if (noToolCallRetries > MAX_NO_TOOL_CALL_RETRIES) {
|
|
577
|
+
logger.warn('Max no-tool-call retries exceeded - returning content as final response');
|
|
578
|
+
const fallbackContent = assistantMessage.content || 'Task completed.';
|
|
579
|
+
const { emitAssistantResponse } = await import('../../tools/llm/simple/file-tools.js');
|
|
580
|
+
emitAssistantResponse(fallbackContent);
|
|
581
|
+
return {
|
|
582
|
+
message: { role: 'assistant', content: fallbackContent },
|
|
583
|
+
toolCalls: toolCallHistory,
|
|
584
|
+
allMessages: workingMessages,
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
const hasMalformedToolCall = assistantMessage.content &&
|
|
588
|
+
(/<tool_call>/i.test(assistantMessage.content) ||
|
|
589
|
+
/<arg_key>/i.test(assistantMessage.content) ||
|
|
590
|
+
/<arg_value>/i.test(assistantMessage.content) ||
|
|
591
|
+
/<\/tool_call>/i.test(assistantMessage.content) ||
|
|
592
|
+
/bash<arg_key>/i.test(assistantMessage.content));
|
|
593
|
+
const retryMessage = hasMalformedToolCall
|
|
594
|
+
? 'Your previous response contained a malformed tool call (XML tags in content). You MUST use the proper tool_calls API format. Use final_response tool to deliver your message to the user.'
|
|
595
|
+
: 'You must use tools for all actions. Use final_response tool to deliver your final message to the user after completing all tasks.';
|
|
596
|
+
workingMessages.push({
|
|
597
|
+
role: 'user',
|
|
598
|
+
content: retryMessage,
|
|
599
|
+
});
|
|
600
|
+
logger.debug('Enforcing tool call - added retry message');
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
getModelInfo() {
|
|
606
|
+
return {
|
|
607
|
+
model: this.modelName,
|
|
608
|
+
endpoint: this.baseUrl,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
handleError(error, requestContext) {
|
|
612
|
+
logger.error('LLM Client Error', error);
|
|
613
|
+
if (requestContext) {
|
|
614
|
+
logger.debug('Request Context', requestContext);
|
|
615
|
+
}
|
|
616
|
+
if (axios.isAxiosError(error)) {
|
|
617
|
+
const axiosError = error;
|
|
618
|
+
if (axiosError.code === 'ECONNABORTED' || axiosError.message.includes('timeout')) {
|
|
619
|
+
logger.error('Request Timeout', {
|
|
620
|
+
timeout: this.axiosInstance.defaults.timeout,
|
|
621
|
+
endpoint: this.baseUrl,
|
|
622
|
+
});
|
|
623
|
+
return new TimeoutError(this.axiosInstance.defaults.timeout || 60000, {
|
|
624
|
+
cause: axiosError,
|
|
625
|
+
details: {
|
|
626
|
+
endpoint: this.baseUrl,
|
|
627
|
+
method: requestContext?.method,
|
|
628
|
+
url: requestContext?.url,
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
if (axiosError.response) {
|
|
633
|
+
const status = axiosError.response.status;
|
|
634
|
+
const data = axiosError.response.data;
|
|
635
|
+
const errorMessage = data?.error?.message || data?.message || axiosError.message;
|
|
636
|
+
const errorType = data?.error?.type || 'unknown';
|
|
637
|
+
const errorCode = data?.error?.code || data?.code;
|
|
638
|
+
logger.error('=== API ERROR DETAILS ===', {
|
|
639
|
+
status,
|
|
640
|
+
statusText: axiosError.response.statusText,
|
|
641
|
+
endpoint: this.baseUrl,
|
|
642
|
+
model: this.model,
|
|
643
|
+
errorMessage,
|
|
644
|
+
errorType,
|
|
645
|
+
errorCode,
|
|
646
|
+
responseBody: JSON.stringify(data, null, 2),
|
|
647
|
+
requestMethod: requestContext?.method,
|
|
648
|
+
requestUrl: requestContext?.url,
|
|
649
|
+
requestBody: requestContext?.body
|
|
650
|
+
? JSON.stringify(requestContext.body, null, 2).substring(0, 5000)
|
|
651
|
+
: undefined,
|
|
652
|
+
responseHeaders: axiosError.response.headers,
|
|
653
|
+
});
|
|
654
|
+
logger.httpResponse(status, axiosError.response.statusText, data);
|
|
655
|
+
if (errorType === 'invalid_request_error' &&
|
|
656
|
+
(errorMessage.includes('context_length_exceeded') ||
|
|
657
|
+
errorMessage.includes('maximum context length') ||
|
|
658
|
+
errorCode === 'context_length_exceeded')) {
|
|
659
|
+
const maxLength = data?.error?.param?.max_tokens || 'unknown';
|
|
660
|
+
logger.error('Context Length Exceeded', {
|
|
661
|
+
maxLength,
|
|
662
|
+
errorMessage,
|
|
663
|
+
model: this.model,
|
|
664
|
+
});
|
|
665
|
+
return new ContextLengthError(typeof maxLength === 'number' ? maxLength : 0, undefined, {
|
|
666
|
+
cause: axiosError,
|
|
667
|
+
details: {
|
|
668
|
+
model: this.model,
|
|
669
|
+
endpoint: this.baseUrl,
|
|
670
|
+
errorType,
|
|
671
|
+
fullError: data,
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
if (errorMessage.includes('token') &&
|
|
676
|
+
(errorMessage.includes('limit') || errorMessage.includes('exceeded'))) {
|
|
677
|
+
logger.error('Token Limit Error', {
|
|
678
|
+
errorMessage,
|
|
679
|
+
model: this.model,
|
|
680
|
+
});
|
|
681
|
+
return new TokenLimitError(0, undefined, {
|
|
682
|
+
cause: axiosError,
|
|
683
|
+
details: {
|
|
684
|
+
model: this.model,
|
|
685
|
+
endpoint: this.baseUrl,
|
|
686
|
+
fullError: data,
|
|
687
|
+
},
|
|
688
|
+
userMessage: errorMessage,
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
if (status === 429) {
|
|
692
|
+
const retryAfter = axiosError.response.headers['retry-after'];
|
|
693
|
+
const retrySeconds = retryAfter ? parseInt(retryAfter) : undefined;
|
|
694
|
+
logger.error('Rate Limit Exceeded', {
|
|
695
|
+
retryAfter: retrySeconds,
|
|
696
|
+
errorMessage,
|
|
697
|
+
});
|
|
698
|
+
return new RateLimitError(retrySeconds, {
|
|
699
|
+
cause: axiosError,
|
|
700
|
+
details: {
|
|
701
|
+
endpoint: this.baseUrl,
|
|
702
|
+
model: this.model,
|
|
703
|
+
fullError: data,
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
if (status === 401) {
|
|
708
|
+
logger.error('Authentication Failed', {
|
|
709
|
+
endpoint: this.baseUrl,
|
|
710
|
+
errorMessage,
|
|
711
|
+
});
|
|
712
|
+
return new APIError(`인증 실패: ${errorMessage}`, status, this.baseUrl, {
|
|
713
|
+
cause: axiosError,
|
|
714
|
+
details: {
|
|
715
|
+
apiKeyProvided: !!this.apiKey,
|
|
716
|
+
apiKeyLength: this.apiKey?.length || 0,
|
|
717
|
+
fullError: data,
|
|
718
|
+
},
|
|
719
|
+
isRecoverable: false,
|
|
720
|
+
userMessage: `API 키가 유효하지 않습니다. 설정을 확인해주세요.\n상세: ${errorMessage}`,
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
if (status === 403) {
|
|
724
|
+
logger.error('Access Forbidden', {
|
|
725
|
+
endpoint: this.baseUrl,
|
|
726
|
+
errorMessage,
|
|
727
|
+
});
|
|
728
|
+
return new APIError(`접근 거부: ${errorMessage}`, status, this.baseUrl, {
|
|
729
|
+
cause: axiosError,
|
|
730
|
+
details: {
|
|
731
|
+
fullError: data,
|
|
732
|
+
},
|
|
733
|
+
isRecoverable: false,
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
if (status === 404) {
|
|
737
|
+
logger.error('Endpoint Not Found', {
|
|
738
|
+
endpoint: this.baseUrl,
|
|
739
|
+
url: requestContext?.url,
|
|
740
|
+
errorMessage,
|
|
741
|
+
});
|
|
742
|
+
return new APIError(`엔드포인트를 찾을 수 없습니다: ${errorMessage}`, status, this.baseUrl, {
|
|
743
|
+
cause: axiosError,
|
|
744
|
+
details: {
|
|
745
|
+
url: requestContext?.url,
|
|
746
|
+
fullError: data,
|
|
747
|
+
},
|
|
748
|
+
isRecoverable: false,
|
|
749
|
+
userMessage: `API 엔드포인트가 존재하지 않습니다.\nURL: ${this.baseUrl}${requestContext?.url || ''}\n상세: ${errorMessage}`,
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
if (status >= 500) {
|
|
753
|
+
logger.error('Server Error', {
|
|
754
|
+
status,
|
|
755
|
+
endpoint: this.baseUrl,
|
|
756
|
+
errorMessage,
|
|
757
|
+
});
|
|
758
|
+
return new APIError(`서버 에러 (${status}): ${errorMessage}`, status, this.baseUrl, {
|
|
759
|
+
cause: axiosError,
|
|
760
|
+
details: {
|
|
761
|
+
fullError: data,
|
|
762
|
+
},
|
|
763
|
+
isRecoverable: true,
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
logger.error('API Error', {
|
|
767
|
+
status,
|
|
768
|
+
endpoint: this.baseUrl,
|
|
769
|
+
errorMessage,
|
|
770
|
+
errorType,
|
|
771
|
+
errorCode,
|
|
772
|
+
});
|
|
773
|
+
return new APIError(`API 에러 (${status}): ${errorMessage}`, status, this.baseUrl, {
|
|
774
|
+
cause: axiosError,
|
|
775
|
+
details: {
|
|
776
|
+
errorType,
|
|
777
|
+
errorCode,
|
|
778
|
+
fullError: data,
|
|
779
|
+
},
|
|
780
|
+
userMessage: `API 요청 실패 (${status}):\n${errorMessage}\n\n에러 타입: ${errorType}\n에러 코드: ${errorCode}`,
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
else if (axiosError.request) {
|
|
784
|
+
const errorCode = axiosError.code;
|
|
785
|
+
logger.error('Network Error - No Response', {
|
|
786
|
+
code: errorCode,
|
|
787
|
+
endpoint: this.baseUrl,
|
|
788
|
+
message: axiosError.message,
|
|
789
|
+
});
|
|
790
|
+
if (errorCode === 'ECONNREFUSED' ||
|
|
791
|
+
errorCode === 'ENOTFOUND' ||
|
|
792
|
+
errorCode === 'ECONNRESET' ||
|
|
793
|
+
errorCode === 'EHOSTUNREACH') {
|
|
794
|
+
return new ConnectionError(this.baseUrl, {
|
|
795
|
+
cause: axiosError,
|
|
796
|
+
details: {
|
|
797
|
+
code: errorCode,
|
|
798
|
+
message: axiosError.message,
|
|
799
|
+
},
|
|
800
|
+
userMessage: `서버에 연결할 수 없습니다.\n엔드포인트: ${this.baseUrl}\n에러 코드: ${errorCode}\n상세: ${axiosError.message}\n\n네트워크 연결과 엔드포인트 URL을 확인해주세요.`,
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
return new NetworkError(`네트워크 에러: ${axiosError.message}`, {
|
|
804
|
+
cause: axiosError,
|
|
805
|
+
details: {
|
|
806
|
+
code: errorCode,
|
|
807
|
+
endpoint: this.baseUrl,
|
|
808
|
+
},
|
|
809
|
+
userMessage: `네트워크 연결 실패.\n엔드포인트: ${this.baseUrl}\n에러: ${axiosError.message}`,
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
logger.error('Axios Error', {
|
|
813
|
+
code: axiosError.code,
|
|
814
|
+
message: axiosError.message,
|
|
815
|
+
});
|
|
816
|
+
return new LLMError(`LLM 클라이언트 에러: ${axiosError.message}`, {
|
|
817
|
+
cause: axiosError,
|
|
818
|
+
details: {
|
|
819
|
+
code: axiosError.code,
|
|
820
|
+
},
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
if (error instanceof Error) {
|
|
824
|
+
logger.error('Unexpected Error', error);
|
|
825
|
+
return new LLMError(`예상치 못한 에러: ${error.message}`, {
|
|
826
|
+
cause: error,
|
|
827
|
+
userMessage: `오류가 발생했습니다:\n${error.message}\n\n스택:\n${error.stack}`,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
logger.error('Unknown Error Type', { error });
|
|
831
|
+
return new LLMError('알 수 없는 에러가 발생했습니다.', {
|
|
832
|
+
details: { unknownError: error },
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
async chatCompletionWithRetry(options, maxRetries = 3) {
|
|
836
|
+
return this.chatCompletion(options, { maxRetries });
|
|
837
|
+
}
|
|
838
|
+
async healthCheck() {
|
|
839
|
+
const endpoint = configManager.getCurrentEndpoint();
|
|
840
|
+
const model = configManager.getCurrentModel();
|
|
841
|
+
if (!endpoint || !model) {
|
|
842
|
+
return { success: false, error: 'No endpoint or model configured' };
|
|
843
|
+
}
|
|
844
|
+
const startTime = Date.now();
|
|
845
|
+
try {
|
|
846
|
+
const response = await this.axiosInstance.post('/chat/completions', {
|
|
847
|
+
model: model.id,
|
|
848
|
+
messages: [{ role: 'user', content: 'ping' }],
|
|
849
|
+
max_tokens: 5,
|
|
850
|
+
});
|
|
851
|
+
const latency = Date.now() - startTime;
|
|
852
|
+
if (response.status === 200 && response.data.choices?.[0]?.message) {
|
|
853
|
+
return { success: true, latency };
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
return { success: false, latency, error: 'Invalid response format' };
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
catch (error) {
|
|
860
|
+
const latency = Date.now() - startTime;
|
|
861
|
+
const axiosError = error;
|
|
862
|
+
if (axiosError.response) {
|
|
863
|
+
const status = axiosError.response.status;
|
|
864
|
+
return { success: false, latency, error: `HTTP ${status}` };
|
|
865
|
+
}
|
|
866
|
+
else if (axiosError.request) {
|
|
867
|
+
return { success: false, latency, error: 'Connection failed' };
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
return { success: false, latency, error: axiosError.message || 'Unknown error' };
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
static async healthCheckAll() {
|
|
875
|
+
const endpoints = configManager.getAllEndpoints();
|
|
876
|
+
const results = new Map();
|
|
877
|
+
for (const endpoint of endpoints) {
|
|
878
|
+
const modelResults = [];
|
|
879
|
+
for (const model of endpoint.models) {
|
|
880
|
+
if (!model.enabled) {
|
|
881
|
+
modelResults.push({
|
|
882
|
+
modelId: model.id,
|
|
883
|
+
healthy: false,
|
|
884
|
+
error: 'Model disabled',
|
|
885
|
+
});
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
const startTime = Date.now();
|
|
889
|
+
try {
|
|
890
|
+
const axiosInstance = axios.create({
|
|
891
|
+
baseURL: endpoint.baseUrl,
|
|
892
|
+
headers: {
|
|
893
|
+
'Content-Type': 'application/json',
|
|
894
|
+
...(endpoint.apiKey && { Authorization: `Bearer ${endpoint.apiKey}` }),
|
|
895
|
+
},
|
|
896
|
+
timeout: 30000,
|
|
897
|
+
});
|
|
898
|
+
const response = await axiosInstance.post('/chat/completions', {
|
|
899
|
+
model: model.id,
|
|
900
|
+
messages: [{ role: 'user', content: 'ping' }],
|
|
901
|
+
max_tokens: 5,
|
|
902
|
+
});
|
|
903
|
+
const latency = Date.now() - startTime;
|
|
904
|
+
if (response.status === 200 && response.data.choices?.[0]?.message) {
|
|
905
|
+
modelResults.push({ modelId: model.id, healthy: true, latency });
|
|
906
|
+
}
|
|
907
|
+
else {
|
|
908
|
+
modelResults.push({
|
|
909
|
+
modelId: model.id,
|
|
910
|
+
healthy: false,
|
|
911
|
+
latency,
|
|
912
|
+
error: 'Invalid response',
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
catch (error) {
|
|
917
|
+
const latency = Date.now() - startTime;
|
|
918
|
+
const axiosError = error;
|
|
919
|
+
let errorMessage = 'Unknown error';
|
|
920
|
+
if (axiosError.response) {
|
|
921
|
+
errorMessage = `HTTP ${axiosError.response.status}`;
|
|
922
|
+
}
|
|
923
|
+
else if (axiosError.code === 'ECONNREFUSED') {
|
|
924
|
+
errorMessage = 'Connection refused';
|
|
925
|
+
}
|
|
926
|
+
else if (axiosError.code === 'ETIMEDOUT' || axiosError.code === 'ECONNABORTED') {
|
|
927
|
+
errorMessage = 'Timeout';
|
|
928
|
+
}
|
|
929
|
+
else if (axiosError.request) {
|
|
930
|
+
errorMessage = 'Network error';
|
|
931
|
+
}
|
|
932
|
+
modelResults.push({
|
|
933
|
+
modelId: model.id,
|
|
934
|
+
healthy: false,
|
|
935
|
+
latency,
|
|
936
|
+
error: errorMessage,
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
results.set(endpoint.id, modelResults);
|
|
941
|
+
}
|
|
942
|
+
return results;
|
|
943
|
+
}
|
|
944
|
+
static async testConnection(baseUrl, apiKey, model) {
|
|
945
|
+
const startTime = Date.now();
|
|
946
|
+
try {
|
|
947
|
+
const axiosInstance = axios.create({
|
|
948
|
+
baseURL: baseUrl,
|
|
949
|
+
headers: {
|
|
950
|
+
'Content-Type': 'application/json',
|
|
951
|
+
...(apiKey && { Authorization: `Bearer ${apiKey}` }),
|
|
952
|
+
},
|
|
953
|
+
timeout: 60000,
|
|
954
|
+
});
|
|
955
|
+
const response = await axiosInstance.post('/chat/completions', {
|
|
956
|
+
model: model,
|
|
957
|
+
messages: [
|
|
958
|
+
{
|
|
959
|
+
role: 'user',
|
|
960
|
+
content: 'test',
|
|
961
|
+
},
|
|
962
|
+
],
|
|
963
|
+
max_tokens: 10,
|
|
964
|
+
});
|
|
965
|
+
const latency = Date.now() - startTime;
|
|
966
|
+
if (response.status === 200 && response.data.choices?.[0]?.message) {
|
|
967
|
+
return { success: true, latency };
|
|
968
|
+
}
|
|
969
|
+
else {
|
|
970
|
+
return { success: false, latency, error: '유효하지 않은 응답 형식' };
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
catch (error) {
|
|
974
|
+
const latency = Date.now() - startTime;
|
|
975
|
+
const axiosError = error;
|
|
976
|
+
if (axiosError.response) {
|
|
977
|
+
const status = axiosError.response.status;
|
|
978
|
+
const data = axiosError.response.data;
|
|
979
|
+
const message = data?.error?.message || axiosError.message;
|
|
980
|
+
if (status === 401) {
|
|
981
|
+
return { success: false, latency, error: 'API 키가 유효하지 않습니다.' };
|
|
982
|
+
}
|
|
983
|
+
else if (status === 404) {
|
|
984
|
+
return { success: false, latency, error: '엔드포인트 또는 모델을 찾을 수 없습니다.' };
|
|
985
|
+
}
|
|
986
|
+
else {
|
|
987
|
+
return { success: false, latency, error: `API 에러 (${status}): ${message}` };
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
else if (axiosError.request) {
|
|
991
|
+
return { success: false, latency, error: `네트워크 에러: 엔드포인트에 연결할 수 없습니다.` };
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
return { success: false, latency, error: axiosError.message || '알 수 없는 에러' };
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
export function createLLMClient() {
|
|
1000
|
+
return new LLMClient();
|
|
1001
|
+
}
|
|
1002
|
+
//# sourceMappingURL=llm-client.js.map
|