genaicode 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -11
- package/dist/ai-service/anthropic.js +7 -2
- package/dist/ai-service/anthropic.js.map +1 -1
- package/dist/ai-service/chat-gpt.d.ts +2 -0
- package/dist/ai-service/chat-gpt.js +7 -4
- package/dist/ai-service/chat-gpt.js.map +1 -1
- package/dist/ai-service/common.test.js +2 -1
- package/dist/ai-service/common.test.js.map +1 -1
- package/dist/ai-service/dall-e.js +1 -0
- package/dist/ai-service/dall-e.js.map +1 -1
- package/dist/ai-service/vertex-ai-claude.js +1 -0
- package/dist/ai-service/vertex-ai-claude.js.map +1 -1
- package/dist/cli/cli-options.js +10 -22
- package/dist/cli/cli-options.js.map +1 -1
- package/dist/cli/cli-params.d.ts +1 -5
- package/dist/cli/cli-params.js +10 -29
- package/dist/cli/cli-params.js.map +1 -1
- package/dist/cli/validate-cli-params.js +16 -11
- package/dist/cli/validate-cli-params.js.map +1 -1
- package/dist/cli/validate-cli-params.test.js +2 -2
- package/dist/cli/validate-cli-params.test.js.map +1 -1
- package/dist/examples/genaicode_plugins/fake_ai_service.d.ts +3 -0
- package/dist/examples/genaicode_plugins/fake_ai_service.js +11 -0
- package/dist/examples/genaicode_plugins/fake_ai_service.js.map +1 -0
- package/dist/examples/genaicode_plugins/grok_ai_service.d.ts +3 -0
- package/dist/examples/genaicode_plugins/grok_ai_service.js +153 -0
- package/dist/examples/genaicode_plugins/grok_ai_service.js.map +1 -0
- package/dist/examples/genaicode_plugins/nonsense_operation.d.ts +3 -0
- package/dist/examples/genaicode_plugins/nonsense_operation.js +23 -0
- package/dist/examples/genaicode_plugins/nonsense_operation.js.map +1 -0
- package/dist/files/path-utils.d.ts +1 -0
- package/dist/files/path-utils.js +12 -0
- package/dist/files/path-utils.js.map +1 -0
- package/dist/files/update-files.d.ts +1 -1
- package/dist/files/update-files.js +8 -183
- package/dist/files/update-files.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/main/codegen-types.d.ts +31 -1
- package/dist/main/codegen-utils.d.ts +3 -0
- package/dist/main/codegen-utils.js +16 -0
- package/dist/main/codegen-utils.js.map +1 -0
- package/dist/main/codegen.js +15 -26
- package/dist/main/codegen.js.map +1 -1
- package/dist/main/codegen.test.js +12 -15
- package/dist/main/codegen.test.js.map +1 -1
- package/dist/main/common/user-actions.d.ts +14 -2
- package/dist/main/common/user-actions.js +16 -1
- package/dist/main/common/user-actions.js.map +1 -1
- package/dist/main/config-lib.d.ts +1 -0
- package/dist/main/config-lib.js +7 -0
- package/dist/main/config-lib.js.map +1 -1
- package/dist/main/config.js +3 -0
- package/dist/main/config.js.map +1 -1
- package/dist/main/interactive/user-action-handlers.js +2 -2
- package/dist/main/interactive/user-action-handlers.js.map +1 -1
- package/dist/main/plugin-loader.d.ts +9 -0
- package/dist/main/plugin-loader.js +55 -0
- package/dist/main/plugin-loader.js.map +1 -0
- package/dist/main/ui/backend/api-utils.js +2 -2
- package/dist/main/ui/backend/api-utils.js.map +1 -1
- package/dist/main/ui/backend/api.js +15 -3
- package/dist/main/ui/backend/api.js.map +1 -1
- package/dist/main/ui/backend/service.d.ts +6 -11
- package/dist/main/ui/backend/service.js +11 -7
- package/dist/main/ui/backend/service.js.map +1 -1
- package/dist/main/ui/common/api-types.d.ts +20 -0
- package/dist/main/ui/common/api-types.js +2 -0
- package/dist/main/ui/common/api-types.js.map +1 -0
- package/dist/main/ui/frontend/assets/{index-Dicb_1yw.js → index-Dk_qaEQg.js} +75 -72
- package/dist/main/ui/frontend/index.html +1 -1
- package/dist/main/ui/user-action-handlers.js +9 -4
- package/dist/main/ui/user-action-handlers.js.map +1 -1
- package/dist/operations/create-directory/create-directory-def.d.ts +9 -0
- package/dist/operations/create-directory/create-directory-def.js +22 -0
- package/dist/operations/create-directory/create-directory-def.js.map +1 -0
- package/dist/operations/create-directory/create-directory-executor.d.ts +6 -0
- package/dist/operations/create-directory/create-directory-executor.js +22 -0
- package/dist/operations/create-directory/create-directory-executor.js.map +1 -0
- package/dist/operations/create-file/create-file-def.d.ts +10 -0
- package/dist/operations/create-file/create-file-def.js +26 -0
- package/dist/operations/create-file/create-file-def.js.map +1 -0
- package/dist/operations/create-file/create-file-executor.d.ts +6 -0
- package/dist/operations/create-file/create-file-executor.js +27 -0
- package/dist/operations/create-file/create-file-executor.js.map +1 -0
- package/dist/operations/delete-file/delete-file-def.d.ts +9 -0
- package/dist/operations/delete-file/delete-file-def.js +22 -0
- package/dist/operations/delete-file/delete-file-def.js.map +1 -0
- package/dist/operations/delete-file/delete-file-executor.d.ts +6 -0
- package/dist/operations/delete-file/delete-file-executor.js +23 -0
- package/dist/operations/delete-file/delete-file-executor.js.map +1 -0
- package/dist/operations/download-file/download-file-def.d.ts +10 -0
- package/dist/operations/download-file/download-file-def.js +26 -0
- package/dist/operations/download-file/download-file-def.js.map +1 -0
- package/dist/operations/download-file/download-file-executor.d.ts +6 -0
- package/dist/operations/download-file/download-file-executor.js +44 -0
- package/dist/operations/download-file/download-file-executor.js.map +1 -0
- package/dist/operations/imgly-remove-background/imgly-remove-background-def.d.ts +10 -0
- package/dist/operations/imgly-remove-background/imgly-remove-background-def.js +26 -0
- package/dist/operations/imgly-remove-background/imgly-remove-background-def.js.map +1 -0
- package/dist/operations/imgly-remove-background/imgly-remove-background-executor.d.ts +6 -0
- package/dist/operations/imgly-remove-background/imgly-remove-background-executor.js +40 -0
- package/dist/operations/imgly-remove-background/imgly-remove-background-executor.js.map +1 -0
- package/dist/operations/move-file/move-file-def.d.ts +10 -0
- package/dist/operations/move-file/move-file-def.js +26 -0
- package/dist/operations/move-file/move-file-def.js.map +1 -0
- package/dist/operations/move-file/move-file-executor.d.ts +6 -0
- package/dist/operations/move-file/move-file-executor.js +29 -0
- package/dist/operations/move-file/move-file-executor.js.map +1 -0
- package/dist/operations/operations-index.d.ts +3 -0
- package/dist/operations/operations-index.js +33 -0
- package/dist/operations/operations-index.js.map +1 -0
- package/dist/operations/patch-file/patch-file-def.d.ts +10 -0
- package/dist/operations/patch-file/patch-file-def.js +39 -0
- package/dist/operations/patch-file/patch-file-def.js.map +1 -0
- package/dist/operations/patch-file/patch-file-executor.d.ts +5 -0
- package/dist/operations/patch-file/patch-file-executor.js +26 -0
- package/dist/operations/patch-file/patch-file-executor.js.map +1 -0
- package/dist/operations/resize-image/resize-image-def.d.ts +13 -0
- package/dist/operations/resize-image/resize-image-def.js +37 -0
- package/dist/operations/resize-image/resize-image-def.js.map +1 -0
- package/dist/operations/resize-image/resize-image-executor.d.ts +5 -0
- package/dist/operations/resize-image/resize-image-executor.js +30 -0
- package/dist/operations/resize-image/resize-image-executor.js.map +1 -0
- package/dist/operations/split-image/split-image-def.d.ts +18 -0
- package/dist/operations/split-image/split-image-def.js +46 -0
- package/dist/operations/split-image/split-image-def.js.map +1 -0
- package/dist/operations/split-image/split-image-executor.d.ts +6 -0
- package/dist/operations/split-image/split-image-executor.js +51 -0
- package/dist/operations/split-image/split-image-executor.js.map +1 -0
- package/dist/operations/update-file/update-file-def.d.ts +10 -0
- package/dist/operations/update-file/update-file-def.js +26 -0
- package/dist/operations/update-file/update-file-def.js.map +1 -0
- package/dist/operations/update-file/update-file-executor.d.ts +5 -0
- package/dist/operations/update-file/update-file-executor.js +22 -0
- package/dist/operations/update-file/update-file-executor.js.map +1 -0
- package/dist/prompt/ai-service-fallback.js.map +1 -1
- package/dist/prompt/function-calling-validate.js +2 -2
- package/dist/prompt/function-calling-validate.js.map +1 -1
- package/dist/prompt/function-calling.d.ts +1 -1
- package/dist/prompt/function-calling.js +29 -44
- package/dist/prompt/function-calling.js.map +1 -1
- package/dist/prompt/function-defs/ask-question-reflect.d.ts +2 -20
- package/dist/prompt/function-defs/ask-question-reflect.js.map +1 -1
- package/dist/prompt/function-defs/ask-question.d.ts +2 -73
- package/dist/prompt/function-defs/ask-question.js +28 -14
- package/dist/prompt/function-defs/ask-question.js.map +1 -1
- package/dist/prompt/function-defs/codegen-summary.d.ts +2 -62
- package/dist/prompt/function-defs/codegen-summary.js +4 -2
- package/dist/prompt/function-defs/codegen-summary.js.map +1 -1
- package/dist/prompt/function-defs/explanation.d.ts +2 -14
- package/dist/prompt/function-defs/explanation.js.map +1 -1
- package/dist/prompt/function-defs/generate-image.d.ts +2 -38
- package/dist/prompt/function-defs/generate-image.js.map +1 -1
- package/dist/prompt/function-defs/get-image-assets.d.ts +2 -17
- package/dist/prompt/function-defs/get-image-assets.js.map +1 -1
- package/dist/prompt/function-defs/get-source-code.d.ts +2 -17
- package/dist/prompt/function-defs/get-source-code.js.map +1 -1
- package/dist/prompt/function-defs/optimize-context.d.ts +2 -43
- package/dist/prompt/function-defs/optimize-context.js.map +1 -1
- package/dist/prompt/function-defs/read-history.d.ts +2 -13
- package/dist/prompt/function-defs/read-history.js.map +1 -1
- package/dist/prompt/function-defs/set-summaries.d.ts +2 -28
- package/dist/prompt/function-defs/set-summaries.js.map +1 -1
- package/dist/prompt/function-defs/update-history.d.ts +2 -18
- package/dist/prompt/function-defs/update-history.js.map +1 -1
- package/dist/prompt/prompt-service.js +6 -6
- package/dist/prompt/prompt-service.js.map +1 -1
- package/dist/prompt/prompt-service.test.js +16 -19
- package/dist/prompt/prompt-service.test.js.map +1 -1
- package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.js +16 -0
- package/dist/prompt/steps/step-ask-question/handlers/cancel-code-generation.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.js +37 -0
- package/dist/prompt/steps/step-ask-question/handlers/confirm-code-generation.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/context-optimization.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/context-optimization.js +36 -0
- package/dist/prompt/steps/step-ask-question/handlers/context-optimization.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/default-action.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/default-action.js +18 -0
- package/dist/prompt/steps/step-ask-question/handlers/default-action.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer.js +20 -0
- package/dist/prompt/steps/step-ask-question/handlers/handle-request-answer.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.js +43 -0
- package/dist/prompt/steps/step-ask-question/handlers/remove-files-from-context.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/request-files-content.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js +49 -0
- package/dist/prompt/steps/step-ask-question/handlers/request-files-content.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/request-permissions.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js +46 -0
- package/dist/prompt/steps/step-ask-question/handlers/request-permissions.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.d.ts +2 -0
- package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.js +16 -0
- package/dist/prompt/steps/step-ask-question/handlers/start-code-generation.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-handlers.d.ts +0 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-handlers.js +2 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-handlers.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.js +91 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-reflect.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-types.d.ts +56 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-types.js +2 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question-types.js.map +1 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question.d.ts +6 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question.js +95 -0
- package/dist/prompt/steps/step-ask-question/step-ask-question.js.map +1 -0
- package/dist/prompt/steps/step-context-optimization.js +9 -2
- package/dist/prompt/steps/step-context-optimization.js.map +1 -1
- package/dist/prompt/steps/step-generate-summary.js +2 -2
- package/dist/prompt/steps/step-generate-summary.js.map +1 -1
- package/dist/prompt/steps/step-history-update.js +2 -2
- package/dist/prompt/steps/step-history-update.js.map +1 -1
- package/dist/prompt/steps/step-summarization.js +2 -2
- package/dist/prompt/steps/step-summarization.js.map +1 -1
- package/dist/src/ai-service/ai-studio.d.ts +6 -0
- package/dist/src/ai-service/ai-studio.js +190 -0
- package/dist/src/ai-service/ai-studio.js.map +1 -0
- package/dist/src/ai-service/anthropic.d.ts +6 -0
- package/dist/src/ai-service/anthropic.js +150 -0
- package/dist/src/ai-service/anthropic.js.map +1 -0
- package/dist/src/ai-service/chat-gpt.d.ts +5 -0
- package/dist/src/ai-service/chat-gpt.js +146 -0
- package/dist/src/ai-service/chat-gpt.js.map +1 -0
- package/dist/src/ai-service/common.d.ts +69 -0
- package/dist/src/ai-service/common.js +38 -0
- package/dist/src/ai-service/common.js.map +1 -0
- package/dist/src/ai-service/common.test.d.ts +1 -0
- package/dist/src/ai-service/common.test.js +86 -0
- package/dist/src/ai-service/common.test.js.map +1 -0
- package/dist/src/ai-service/dall-e.d.ts +14 -0
- package/dist/src/ai-service/dall-e.js +50 -0
- package/dist/src/ai-service/dall-e.js.map +1 -0
- package/dist/src/ai-service/unescape-function-call.d.ts +7 -0
- package/dist/src/ai-service/unescape-function-call.js +59 -0
- package/dist/src/ai-service/unescape-function-call.js.map +1 -0
- package/dist/src/ai-service/unescape-function-call.test.d.ts +1 -0
- package/dist/src/ai-service/unescape-function-call.test.js +18 -0
- package/dist/src/ai-service/unescape-function-call.test.js.map +1 -0
- package/dist/src/ai-service/vertex-ai-claude.d.ts +5 -0
- package/dist/src/ai-service/vertex-ai-claude.js +104 -0
- package/dist/src/ai-service/vertex-ai-claude.js.map +1 -0
- package/dist/src/ai-service/vertex-ai-imagen.d.ts +14 -0
- package/dist/src/ai-service/vertex-ai-imagen.js +77 -0
- package/dist/src/ai-service/vertex-ai-imagen.js.map +1 -0
- package/dist/src/ai-service/vertex-ai.d.ts +6 -0
- package/dist/src/ai-service/vertex-ai.js +202 -0
- package/dist/src/ai-service/vertex-ai.js.map +1 -0
- package/dist/src/cli/cli-options.d.ts +10 -0
- package/dist/src/cli/cli-options.js +132 -0
- package/dist/src/cli/cli-options.js.map +1 -0
- package/dist/src/cli/cli-options.test.d.ts +1 -0
- package/dist/src/cli/cli-options.test.js +34 -0
- package/dist/src/cli/cli-options.test.js.map +1 -0
- package/dist/src/cli/cli-params.d.ts +32 -0
- package/dist/src/cli/cli-params.js +106 -0
- package/dist/src/cli/cli-params.js.map +1 -0
- package/dist/src/cli/cli-params.test.d.ts +1 -0
- package/dist/src/cli/cli-params.test.js +38 -0
- package/dist/src/cli/cli-params.test.js.map +1 -0
- package/dist/src/cli/service-autodetect.d.ts +2 -0
- package/dist/src/cli/service-autodetect.js +17 -0
- package/dist/src/cli/service-autodetect.js.map +1 -0
- package/dist/src/cli/service-autodetect.test.d.ts +1 -0
- package/dist/src/cli/service-autodetect.test.js +38 -0
- package/dist/src/cli/service-autodetect.test.js.map +1 -0
- package/dist/src/cli/validate-cli-params.d.ts +18 -0
- package/dist/src/cli/validate-cli-params.js +145 -0
- package/dist/src/cli/validate-cli-params.js.map +1 -0
- package/dist/src/cli/validate-cli-params.test.d.ts +1 -0
- package/dist/src/cli/validate-cli-params.test.js +106 -0
- package/dist/src/cli/validate-cli-params.test.js.map +1 -0
- package/dist/src/files/cache-file.d.ts +3 -0
- package/dist/src/files/cache-file.js +36 -0
- package/dist/src/files/cache-file.js.map +1 -0
- package/dist/src/files/file-utils.d.ts +2 -0
- package/dist/src/files/file-utils.js +7 -0
- package/dist/src/files/file-utils.js.map +1 -0
- package/dist/src/files/file-utils.test.d.ts +1 -0
- package/dist/src/files/file-utils.test.js +18 -0
- package/dist/src/files/file-utils.test.js.map +1 -0
- package/dist/src/files/find-files.d.ts +9 -0
- package/dist/src/files/find-files.js +81 -0
- package/dist/src/files/find-files.js.map +1 -0
- package/dist/src/files/path-utils.d.ts +1 -0
- package/dist/src/files/path-utils.js +12 -0
- package/dist/src/files/path-utils.js.map +1 -0
- package/dist/src/files/read-files.d.ts +21 -0
- package/dist/src/files/read-files.js +68 -0
- package/dist/src/files/read-files.js.map +1 -0
- package/dist/src/files/read-files.test.d.ts +1 -0
- package/dist/src/files/read-files.test.js +89 -0
- package/dist/src/files/read-files.test.js.map +1 -0
- package/dist/src/files/temp-buffer.d.ts +2 -0
- package/dist/src/files/temp-buffer.js +12 -0
- package/dist/src/files/temp-buffer.js.map +1 -0
- package/dist/src/files/update-files.d.ts +6 -0
- package/dist/src/files/update-files.js +19 -0
- package/dist/src/files/update-files.js.map +1 -0
- package/dist/src/images/ensure-alpha.d.ts +1 -0
- package/dist/src/images/ensure-alpha.js +5 -0
- package/dist/src/images/ensure-alpha.js.map +1 -0
- package/dist/src/images/imgly-remove-background.d.ts +2 -0
- package/dist/src/images/imgly-remove-background.js +21 -0
- package/dist/src/images/imgly-remove-background.js.map +1 -0
- package/dist/src/images/resize-image.d.ts +19 -0
- package/dist/src/images/resize-image.js +22 -0
- package/dist/src/images/resize-image.js.map +1 -0
- package/dist/src/images/split-image.d.ts +18 -0
- package/dist/src/images/split-image.js +25 -0
- package/dist/src/images/split-image.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/main/codegen-types.d.ts +58 -0
- package/dist/src/main/codegen-types.js +2 -0
- package/dist/src/main/codegen-types.js.map +1 -0
- package/dist/src/main/codegen-utils.d.ts +3 -0
- package/dist/src/main/codegen-utils.js +18 -0
- package/dist/src/main/codegen-utils.js.map +1 -0
- package/dist/src/main/codegen.d.ts +4 -0
- package/dist/src/main/codegen.js +201 -0
- package/dist/src/main/codegen.js.map +1 -0
- package/dist/src/main/codegen.test.d.ts +3 -0
- package/dist/src/main/codegen.test.js +288 -0
- package/dist/src/main/codegen.test.js.map +1 -0
- package/dist/src/main/common/content-bus-types.d.ts +21 -0
- package/dist/src/main/common/content-bus-types.js +11 -0
- package/dist/src/main/common/content-bus-types.js.map +1 -0
- package/dist/src/main/common/content-bus.d.ts +10 -0
- package/dist/src/main/common/content-bus.js +39 -0
- package/dist/src/main/common/content-bus.js.map +1 -0
- package/dist/src/main/common/cost-collector.d.ts +11 -0
- package/dist/src/main/common/cost-collector.js +90 -0
- package/dist/src/main/common/cost-collector.js.map +1 -0
- package/dist/src/main/common/user-actions.d.ts +19 -0
- package/dist/src/main/common/user-actions.js +30 -0
- package/dist/src/main/common/user-actions.js.map +1 -0
- package/dist/src/main/config-lib.d.ts +36 -0
- package/dist/src/main/config-lib.js +51 -0
- package/dist/src/main/config-lib.js.map +1 -0
- package/dist/src/main/config-lib.test.d.ts +1 -0
- package/dist/src/main/config-lib.test.js +64 -0
- package/dist/src/main/config-lib.test.js.map +1 -0
- package/dist/src/main/config.d.ts +7 -0
- package/dist/src/main/config.js +51 -0
- package/dist/src/main/config.js.map +1 -0
- package/dist/src/main/interactive/codegen-interactive.d.ts +2 -0
- package/dist/src/main/interactive/codegen-interactive.js +61 -0
- package/dist/src/main/interactive/codegen-interactive.js.map +1 -0
- package/dist/src/main/interactive/codegen-interactive.test.d.ts +5 -0
- package/dist/src/main/interactive/codegen-interactive.test.js +79 -0
- package/dist/src/main/interactive/codegen-interactive.test.js.map +1 -0
- package/dist/src/main/interactive/codegen-worker.d.ts +3 -0
- package/dist/src/main/interactive/codegen-worker.js +54 -0
- package/dist/src/main/interactive/codegen-worker.js.map +1 -0
- package/dist/src/main/interactive/common.d.ts +5 -0
- package/dist/src/main/interactive/common.js +51 -0
- package/dist/src/main/interactive/common.js.map +1 -0
- package/dist/src/main/interactive/configure.d.ts +2 -0
- package/dist/src/main/interactive/configure.js +99 -0
- package/dist/src/main/interactive/configure.js.map +1 -0
- package/dist/src/main/interactive/error-handling.d.ts +1 -0
- package/dist/src/main/interactive/error-handling.js +43 -0
- package/dist/src/main/interactive/error-handling.js.map +1 -0
- package/dist/src/main/interactive/help.d.ts +1 -0
- package/dist/src/main/interactive/help.js +22 -0
- package/dist/src/main/interactive/help.js.map +1 -0
- package/dist/src/main/interactive/process-comments.d.ts +2 -0
- package/dist/src/main/interactive/process-comments.js +39 -0
- package/dist/src/main/interactive/process-comments.js.map +1 -0
- package/dist/src/main/interactive/select-ai-service.d.ts +2 -0
- package/dist/src/main/interactive/select-ai-service.js +27 -0
- package/dist/src/main/interactive/select-ai-service.js.map +1 -0
- package/dist/src/main/interactive/task-file.d.ts +2 -0
- package/dist/src/main/interactive/task-file.js +35 -0
- package/dist/src/main/interactive/task-file.js.map +1 -0
- package/dist/src/main/interactive/text-prompt.d.ts +2 -0
- package/dist/src/main/interactive/text-prompt.js +18 -0
- package/dist/src/main/interactive/text-prompt.js.map +1 -0
- package/dist/src/main/interactive/user-action-handlers.d.ts +1 -0
- package/dist/src/main/interactive/user-action-handlers.js +13 -0
- package/dist/src/main/interactive/user-action-handlers.js.map +1 -0
- package/dist/src/main/interactive/user-interrupt.d.ts +1 -0
- package/dist/src/main/interactive/user-interrupt.js +36 -0
- package/dist/src/main/interactive/user-interrupt.js.map +1 -0
- package/dist/src/main/plugin-loader.d.ts +6 -0
- package/dist/src/main/plugin-loader.js +40 -0
- package/dist/src/main/plugin-loader.js.map +1 -0
- package/dist/src/main/ui/backend/api-utils.d.ts +2 -0
- package/dist/src/main/ui/backend/api-utils.js +18 -0
- package/dist/src/main/ui/backend/api-utils.js.map +1 -0
- package/dist/src/main/ui/backend/api.d.ts +2 -0
- package/dist/src/main/ui/backend/api.js +210 -0
- package/dist/src/main/ui/backend/api.js.map +1 -0
- package/dist/src/main/ui/backend/server.d.ts +7 -0
- package/dist/src/main/ui/backend/server.js +83 -0
- package/dist/src/main/ui/backend/server.js.map +1 -0
- package/dist/src/main/ui/backend/service.d.ts +44 -0
- package/dist/src/main/ui/backend/service.js +171 -0
- package/dist/src/main/ui/backend/service.js.map +1 -0
- package/dist/src/main/ui/codegen-ui.d.ts +2 -0
- package/dist/src/main/ui/codegen-ui.js +13 -0
- package/dist/src/main/ui/codegen-ui.js.map +1 -0
- package/dist/src/main/ui/common/api-types.d.ts +20 -0
- package/dist/src/main/ui/common/api-types.js +2 -0
- package/dist/src/main/ui/common/api-types.js.map +1 -0
- package/dist/src/main/ui/user-action-handlers.d.ts +2 -0
- package/dist/src/main/ui/user-action-handlers.js +14 -0
- package/dist/src/main/ui/user-action-handlers.js.map +1 -0
- package/dist/src/operations/create-directory/create-directory-def.d.ts +9 -0
- package/dist/src/operations/create-directory/create-directory-def.js +22 -0
- package/dist/src/operations/create-directory/create-directory-def.js.map +1 -0
- package/dist/src/operations/create-directory/create-directory-executor.d.ts +6 -0
- package/dist/src/operations/create-directory/create-directory-executor.js +22 -0
- package/dist/src/operations/create-directory/create-directory-executor.js.map +1 -0
- package/dist/src/operations/create-file/create-file-def.d.ts +10 -0
- package/dist/src/operations/create-file/create-file-def.js +26 -0
- package/dist/src/operations/create-file/create-file-def.js.map +1 -0
- package/dist/src/operations/create-file/create-file-executor.d.ts +6 -0
- package/dist/src/operations/create-file/create-file-executor.js +27 -0
- package/dist/src/operations/create-file/create-file-executor.js.map +1 -0
- package/dist/src/operations/delete-file/delete-file-def.d.ts +9 -0
- package/dist/src/operations/delete-file/delete-file-def.js +22 -0
- package/dist/src/operations/delete-file/delete-file-def.js.map +1 -0
- package/dist/src/operations/delete-file/delete-file-executor.d.ts +6 -0
- package/dist/src/operations/delete-file/delete-file-executor.js +23 -0
- package/dist/src/operations/delete-file/delete-file-executor.js.map +1 -0
- package/dist/src/operations/download-file/download-file-def.d.ts +10 -0
- package/dist/src/operations/download-file/download-file-def.js +26 -0
- package/dist/src/operations/download-file/download-file-def.js.map +1 -0
- package/dist/src/operations/download-file/download-file-executor.d.ts +6 -0
- package/dist/src/operations/download-file/download-file-executor.js +44 -0
- package/dist/src/operations/download-file/download-file-executor.js.map +1 -0
- package/dist/src/operations/imgly-remove-background/imgly-remove-background-def.d.ts +10 -0
- package/dist/src/operations/imgly-remove-background/imgly-remove-background-def.js +26 -0
- package/dist/src/operations/imgly-remove-background/imgly-remove-background-def.js.map +1 -0
- package/dist/src/operations/imgly-remove-background/imgly-remove-background-executor.d.ts +6 -0
- package/dist/src/operations/imgly-remove-background/imgly-remove-background-executor.js +40 -0
- package/dist/src/operations/imgly-remove-background/imgly-remove-background-executor.js.map +1 -0
- package/dist/src/operations/move-file/move-file-def.d.ts +10 -0
- package/dist/src/operations/move-file/move-file-def.js +26 -0
- package/dist/src/operations/move-file/move-file-def.js.map +1 -0
- package/dist/src/operations/move-file/move-file-executor.d.ts +6 -0
- package/dist/src/operations/move-file/move-file-executor.js +29 -0
- package/dist/src/operations/move-file/move-file-executor.js.map +1 -0
- package/dist/src/operations/operations-index.d.ts +3 -0
- package/dist/src/operations/operations-index.js +33 -0
- package/dist/src/operations/operations-index.js.map +1 -0
- package/dist/src/operations/patch-file/patch-file-def.d.ts +10 -0
- package/dist/src/operations/patch-file/patch-file-def.js +39 -0
- package/dist/src/operations/patch-file/patch-file-def.js.map +1 -0
- package/dist/src/operations/patch-file/patch-file-executor.d.ts +5 -0
- package/dist/src/operations/patch-file/patch-file-executor.js +26 -0
- package/dist/src/operations/patch-file/patch-file-executor.js.map +1 -0
- package/dist/src/operations/resize-image/resize-image-def.d.ts +13 -0
- package/dist/src/operations/resize-image/resize-image-def.js +37 -0
- package/dist/src/operations/resize-image/resize-image-def.js.map +1 -0
- package/dist/src/operations/resize-image/resize-image-executor.d.ts +5 -0
- package/dist/src/operations/resize-image/resize-image-executor.js +30 -0
- package/dist/src/operations/resize-image/resize-image-executor.js.map +1 -0
- package/dist/src/operations/split-image/split-image-def.d.ts +18 -0
- package/dist/src/operations/split-image/split-image-def.js +46 -0
- package/dist/src/operations/split-image/split-image-def.js.map +1 -0
- package/dist/src/operations/split-image/split-image-executor.d.ts +6 -0
- package/dist/src/operations/split-image/split-image-executor.js +51 -0
- package/dist/src/operations/split-image/split-image-executor.js.map +1 -0
- package/dist/src/operations/update-file/update-file-def.d.ts +10 -0
- package/dist/src/operations/update-file/update-file-def.js +26 -0
- package/dist/src/operations/update-file/update-file-def.js.map +1 -0
- package/dist/src/operations/update-file/update-file-executor.d.ts +5 -0
- package/dist/src/operations/update-file/update-file-executor.js +22 -0
- package/dist/src/operations/update-file/update-file-executor.js.map +1 -0
- package/dist/src/prompt/ai-service-fallback.d.ts +3 -0
- package/dist/src/prompt/ai-service-fallback.js +84 -0
- package/dist/src/prompt/ai-service-fallback.js.map +1 -0
- package/dist/src/prompt/function-calling-validate.d.ts +3 -0
- package/dist/src/prompt/function-calling-validate.js +99 -0
- package/dist/src/prompt/function-calling-validate.js.map +1 -0
- package/dist/src/prompt/function-calling.d.ts +5 -0
- package/dist/src/prompt/function-calling.js +43 -0
- package/dist/src/prompt/function-calling.js.map +1 -0
- package/dist/src/prompt/function-defs/ask-question-reflect.d.ts +2 -0
- package/dist/src/prompt/function-defs/ask-question-reflect.js +21 -0
- package/dist/src/prompt/function-defs/ask-question-reflect.js.map +1 -0
- package/dist/src/prompt/function-defs/ask-question.d.ts +8 -0
- package/dist/src/prompt/function-defs/ask-question.js +100 -0
- package/dist/src/prompt/function-defs/ask-question.js.map +1 -0
- package/dist/src/prompt/function-defs/codegen-summary.d.ts +5 -0
- package/dist/src/prompt/function-defs/codegen-summary.js +82 -0
- package/dist/src/prompt/function-defs/codegen-summary.js.map +1 -0
- package/dist/src/prompt/function-defs/explanation.d.ts +5 -0
- package/dist/src/prompt/function-defs/explanation.js +18 -0
- package/dist/src/prompt/function-defs/explanation.js.map +1 -0
- package/dist/src/prompt/function-defs/generate-image.d.ts +5 -0
- package/dist/src/prompt/function-defs/generate-image.js +42 -0
- package/dist/src/prompt/function-defs/generate-image.js.map +1 -0
- package/dist/src/prompt/function-defs/get-image-assets.d.ts +5 -0
- package/dist/src/prompt/function-defs/get-image-assets.js +21 -0
- package/dist/src/prompt/function-defs/get-image-assets.js.map +1 -0
- package/dist/src/prompt/function-defs/get-source-code.d.ts +5 -0
- package/dist/src/prompt/function-defs/get-source-code.js +22 -0
- package/dist/src/prompt/function-defs/get-source-code.js.map +1 -0
- package/dist/src/prompt/function-defs/optimize-context.d.ts +5 -0
- package/dist/src/prompt/function-defs/optimize-context.js +47 -0
- package/dist/src/prompt/function-defs/optimize-context.js.map +1 -0
- package/dist/src/prompt/function-defs/read-history.d.ts +2 -0
- package/dist/src/prompt/function-defs/read-history.js +14 -0
- package/dist/src/prompt/function-defs/read-history.js.map +1 -0
- package/dist/src/prompt/function-defs/set-summaries.d.ts +5 -0
- package/dist/src/prompt/function-defs/set-summaries.js +32 -0
- package/dist/src/prompt/function-defs/set-summaries.js.map +1 -0
- package/dist/src/prompt/function-defs/update-history.d.ts +5 -0
- package/dist/src/prompt/function-defs/update-history.js +22 -0
- package/dist/src/prompt/function-defs/update-history.js.map +1 -0
- package/dist/src/prompt/limits.d.ts +3 -0
- package/dist/src/prompt/limits.js +21 -0
- package/dist/src/prompt/limits.js.map +1 -0
- package/dist/src/prompt/limits.test.d.ts +1 -0
- package/dist/src/prompt/limits.test.js +35 -0
- package/dist/src/prompt/limits.test.js.map +1 -0
- package/dist/src/prompt/prompt-codegen.d.ts +9 -0
- package/dist/src/prompt/prompt-codegen.js +117 -0
- package/dist/src/prompt/prompt-codegen.js.map +1 -0
- package/dist/src/prompt/prompt-codegen.test.d.ts +1 -0
- package/dist/src/prompt/prompt-codegen.test.js +98 -0
- package/dist/src/prompt/prompt-codegen.test.js.map +1 -0
- package/dist/src/prompt/prompt-consts.d.ts +1 -0
- package/dist/src/prompt/prompt-consts.js +2 -0
- package/dist/src/prompt/prompt-consts.js.map +1 -0
- package/dist/src/prompt/prompt-service-ask-question.test.d.ts +4 -0
- package/dist/src/prompt/prompt-service-ask-question.test.js +215 -0
- package/dist/src/prompt/prompt-service-ask-question.test.js.map +1 -0
- package/dist/src/prompt/prompt-service.d.ts +5 -0
- package/dist/src/prompt/prompt-service.js +214 -0
- package/dist/src/prompt/prompt-service.js.map +1 -0
- package/dist/src/prompt/prompt-service.test.d.ts +2 -0
- package/dist/src/prompt/prompt-service.test.js +553 -0
- package/dist/src/prompt/prompt-service.test.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/cancel-code-generation.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/cancel-code-generation.js +16 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/cancel-code-generation.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/confirm-code-generation.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/confirm-code-generation.js +37 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/confirm-code-generation.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/context-optimization.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/context-optimization.js +36 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/context-optimization.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/default-action.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/default-action.js +18 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/default-action.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/handle-request-answer.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/handle-request-answer.js +20 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/handle-request-answer.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/remove-files-from-context.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/remove-files-from-context.js +43 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/remove-files-from-context.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/request-files-content.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/request-files-content.js +49 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/request-files-content.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/request-permissions.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/request-permissions.js +46 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/request-permissions.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/start-code-generation.d.ts +2 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/start-code-generation.js +16 -0
- package/dist/src/prompt/steps/step-ask-question/handlers/start-code-generation.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-handlers.d.ts +0 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-handlers.js +2 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-handlers.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-reflect.d.ts +4 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-reflect.js +91 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-reflect.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-types.d.ts +55 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-types.js +2 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question-types.js.map +1 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question.d.ts +6 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question.js +88 -0
- package/dist/src/prompt/steps/step-ask-question/step-ask-question.js.map +1 -0
- package/dist/src/prompt/steps/step-context-optimization.d.ts +4 -0
- package/dist/src/prompt/steps/step-context-optimization.js +200 -0
- package/dist/src/prompt/steps/step-context-optimization.js.map +1 -0
- package/dist/src/prompt/steps/step-generate-image.d.ts +2 -0
- package/dist/src/prompt/steps/step-generate-image.js +29 -0
- package/dist/src/prompt/steps/step-generate-image.js.map +1 -0
- package/dist/src/prompt/steps/step-generate-summary.d.ts +3 -0
- package/dist/src/prompt/steps/step-generate-summary.js +41 -0
- package/dist/src/prompt/steps/step-generate-summary.js.map +1 -0
- package/dist/src/prompt/steps/step-history-update.d.ts +5 -0
- package/dist/src/prompt/steps/step-history-update.js +54 -0
- package/dist/src/prompt/steps/step-history-update.js.map +1 -0
- package/dist/src/prompt/steps/step-summarization.d.ts +8 -0
- package/dist/src/prompt/steps/step-summarization.js +75 -0
- package/dist/src/prompt/steps/step-summarization.js.map +1 -0
- package/dist/src/prompt/steps/step-validate-recover.d.ts +2 -0
- package/dist/src/prompt/steps/step-validate-recover.js +51 -0
- package/dist/src/prompt/steps/step-validate-recover.js.map +1 -0
- package/dist/src/prompt/steps/step-verify-patch.d.ts +6 -0
- package/dist/src/prompt/steps/step-verify-patch.js +34 -0
- package/dist/src/prompt/steps/step-verify-patch.js.map +1 -0
- package/dist/src/prompt/steps/steps-types.d.ts +16 -0
- package/dist/src/prompt/steps/steps-types.js +6 -0
- package/dist/src/prompt/steps/steps-types.js.map +1 -0
- package/dist/src/prompt/steps/steps-utils.d.ts +7 -0
- package/dist/src/prompt/steps/steps-utils.js +11 -0
- package/dist/src/prompt/steps/steps-utils.js.map +1 -0
- package/dist/src/prompt/systemprompt.d.ts +3 -0
- package/dist/src/prompt/systemprompt.js +209 -0
- package/dist/src/prompt/systemprompt.js.map +1 -0
- package/dist/src/prompt/systemprompt.test.d.ts +3 -0
- package/dist/src/prompt/systemprompt.test.js +43 -0
- package/dist/src/prompt/systemprompt.test.js.map +1 -0
- package/dist/src/prompt/token-estimator.d.ts +8 -0
- package/dist/src/prompt/token-estimator.js +31 -0
- package/dist/src/prompt/token-estimator.js.map +1 -0
- package/dist/src/vite-genaicode/vite-genaicode-frontend.d.ts +1 -0
- package/dist/src/vite-genaicode/vite-genaicode-frontend.js +142 -0
- package/dist/src/vite-genaicode/vite-genaicode-frontend.js.map +1 -0
- package/dist/src/vite-genaicode/vite-genaicode-plugin.d.ts +7 -0
- package/dist/src/vite-genaicode/vite-genaicode-plugin.js +40 -0
- package/dist/src/vite-genaicode/vite-genaicode-plugin.js.map +1 -0
- package/dist/vite-genaicode/vite-genaicode-plugin.d.ts +2 -1
- package/dist/vite-genaicode/vite-genaicode-plugin.js +20 -5
- package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import OpenAI, { APIError } from 'openai';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { printTokenUsageAndCost, processFunctionCalls, } from '../../src/ai-service/common.js';
|
|
4
|
+
import { abortController } from '../../src/main/interactive/codegen-worker.js';
|
|
5
|
+
import { modelOverrides } from '../../src/main/config.js';
|
|
6
|
+
const grokAiService = {
|
|
7
|
+
name: 'grok-ai-service',
|
|
8
|
+
aiServices: {
|
|
9
|
+
'grok-ai-service': generateContent,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
async function generateContent(prompt, functionDefs, requiredFunctionName, temperature, cheap = false) {
|
|
13
|
+
const openai = new OpenAI({
|
|
14
|
+
apiKey: process.env.GROK_OPENAI_API_KEY,
|
|
15
|
+
baseURL: 'https://api.x.ai/v1',
|
|
16
|
+
});
|
|
17
|
+
const messages = prompt
|
|
18
|
+
.map((item) => {
|
|
19
|
+
if (item.type === 'systemPrompt') {
|
|
20
|
+
return {
|
|
21
|
+
role: 'system',
|
|
22
|
+
content: item.systemPrompt,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else if (item.type === 'user') {
|
|
26
|
+
const messages = [];
|
|
27
|
+
if (item.functionResponses) {
|
|
28
|
+
messages.push(...item.functionResponses.map((response) => ({
|
|
29
|
+
role: 'tool',
|
|
30
|
+
name: response.name,
|
|
31
|
+
content: response.content ?? '',
|
|
32
|
+
tool_call_id: response.name,
|
|
33
|
+
})));
|
|
34
|
+
}
|
|
35
|
+
if ((item.images?.length ?? 0) > 0) {
|
|
36
|
+
messages.push({
|
|
37
|
+
role: 'user',
|
|
38
|
+
content: [
|
|
39
|
+
...item.images.map((image) => ({
|
|
40
|
+
type: 'image_url',
|
|
41
|
+
image_url: {
|
|
42
|
+
url: 'data:' + image.mediaType + ';base64,' + image.base64url,
|
|
43
|
+
},
|
|
44
|
+
})),
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: item.text,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
messages.push({
|
|
54
|
+
role: 'user',
|
|
55
|
+
content: item.text,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return messages;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
assert(item.type === 'assistant');
|
|
62
|
+
const message = {
|
|
63
|
+
role: 'assistant',
|
|
64
|
+
...(item.text ? { content: item.text } : {}),
|
|
65
|
+
tool_calls: item.functionCalls?.map((call) => ({
|
|
66
|
+
type: 'function',
|
|
67
|
+
function: { name: call.name, arguments: JSON.stringify(call.args ?? {}) },
|
|
68
|
+
id: call.name,
|
|
69
|
+
})),
|
|
70
|
+
};
|
|
71
|
+
return message;
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.flat();
|
|
75
|
+
const defaultModel = cheap ? 'grok-2-mini' : 'grok-beta';
|
|
76
|
+
const model = cheap
|
|
77
|
+
? (modelOverrides.chatGpt?.cheap ?? defaultModel)
|
|
78
|
+
: (modelOverrides.chatGpt?.default ?? defaultModel);
|
|
79
|
+
console.log(`Using OpenAI model: ${model}`);
|
|
80
|
+
assert(process.env.OPENAI_API_KEY, 'OPENAI_API_KEY environment variable is not set');
|
|
81
|
+
let retryCount = 0;
|
|
82
|
+
const maxRetries = 3;
|
|
83
|
+
let response = undefined;
|
|
84
|
+
while (retryCount < maxRetries) {
|
|
85
|
+
try {
|
|
86
|
+
response = await openai.chat.completions.create({
|
|
87
|
+
model: model,
|
|
88
|
+
messages,
|
|
89
|
+
tools: functionDefs.map((funDef) => ({ type: 'function', function: funDef })),
|
|
90
|
+
tool_choice: requiredFunctionName
|
|
91
|
+
? { type: 'function', function: { name: requiredFunctionName } }
|
|
92
|
+
: 'required',
|
|
93
|
+
temperature: temperature,
|
|
94
|
+
}, { signal: abortController?.signal });
|
|
95
|
+
break; // Exit loop if successful
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error instanceof APIError && error.status === 429) {
|
|
99
|
+
// Rate limit error
|
|
100
|
+
let retryAfter = error.headers?.['retry-after'] ? parseInt(error.headers['retry-after'], 10) : 60;
|
|
101
|
+
retryAfter = Math.min(retryAfter, 30);
|
|
102
|
+
console.log(`Rate limited. Retrying after ${retryAfter} seconds. Attempt ${retryCount + 1} of ${maxRetries}.`);
|
|
103
|
+
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
|
|
104
|
+
retryCount++;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
console.error('An error occurred:', error);
|
|
108
|
+
throw new Error('API request failed. Operation aborted.');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (retryCount === maxRetries) {
|
|
113
|
+
console.error(`Failed to complete request after ${maxRetries} attempts due to rate limiting.`);
|
|
114
|
+
throw new Error('Rate limit exceeded. Operation aborted.');
|
|
115
|
+
}
|
|
116
|
+
assert(response);
|
|
117
|
+
// Print token usage for chat gpt
|
|
118
|
+
const usage = {
|
|
119
|
+
inputTokens: response.usage.prompt_tokens - (response.usage?.prompt_tokens_details?.cached_tokens ?? 0),
|
|
120
|
+
outputTokens: response.usage.completion_tokens,
|
|
121
|
+
totalTokens: response.usage.total_tokens,
|
|
122
|
+
cacheReadTokens: response.usage?.prompt_tokens_details?.cached_tokens,
|
|
123
|
+
};
|
|
124
|
+
printTokenUsageAndCost({
|
|
125
|
+
aiService: 'chat-gpt',
|
|
126
|
+
usage,
|
|
127
|
+
inputCostPerToken: 0.000005,
|
|
128
|
+
outputCostPerToken: 0.000015,
|
|
129
|
+
cheap,
|
|
130
|
+
});
|
|
131
|
+
const responseMessage = response.choices[0].message;
|
|
132
|
+
if (responseMessage.content) {
|
|
133
|
+
console.log('Message', responseMessage.content);
|
|
134
|
+
}
|
|
135
|
+
const toolCalls = responseMessage.tool_calls;
|
|
136
|
+
if (toolCalls) {
|
|
137
|
+
const functionCalls = toolCalls.map((call) => {
|
|
138
|
+
const name = call.function.name;
|
|
139
|
+
const args = JSON.parse(call.function.arguments);
|
|
140
|
+
return {
|
|
141
|
+
id: call.id,
|
|
142
|
+
name,
|
|
143
|
+
args,
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
return processFunctionCalls(functionCalls, functionDefs);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new Error('No tool calls found in response');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export default grokAiService;
|
|
153
|
+
//# sourceMappingURL=grok_ai_service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok_ai_service.js","sourceRoot":"","sources":["../../../examples/genaicode_plugins/grok_ai_service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAKrB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,aAAa,GAAW;IAC5B,IAAI,EAAE,iBAAiB;IACvB,UAAU,EAAE;QACV,iBAAiB,EAAE,eAAe;KACnC;CACF,CAAC;AAEF,KAAK,UAAU,eAAe,CAC5B,MAAoB,EACpB,YAA2B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AAe,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,SAAS,GAAG,eAAe,CAAC,UAAU,CAAC;IAC7C,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAEjD,OAAO;gBACL,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI;gBACJ,IAAI;aACL,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,oBAAoB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const fakeAiService = {
|
|
2
|
+
name: 'nonsense-operation',
|
|
3
|
+
operations: {
|
|
4
|
+
'nonsense-operation': {
|
|
5
|
+
executor: async (args) => {
|
|
6
|
+
console.log('NONSE OPERATION EXECUTED', args);
|
|
7
|
+
},
|
|
8
|
+
def: {
|
|
9
|
+
name: 'nonsense',
|
|
10
|
+
description: 'nonsense operation',
|
|
11
|
+
parameters: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
input: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
required: ['input'],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export default fakeAiService;
|
|
23
|
+
//# sourceMappingURL=nonsense_operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonsense_operation.js","sourceRoot":"","sources":["../../../examples/genaicode_plugins/nonsense_operation.ts"],"names":[],"mappings":"AAEA,MAAM,aAAa,GAAW;IAC5B,IAAI,EAAE,oBAAoB;IAC1B,UAAU,EAAE;QACV,oBAAoB,EAAE;YACpB,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBACvB,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;YAChD,CAAC;YACD,GAAG,EAAE;gBACH,IAAI,EAAE,UAAU;gBAChB,WAAW,EAAE,oBAAoB;gBACjC,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;qBAC1B;oBACD,QAAQ,EAAE,CAAC,OAAO,CAAC;iBACpB;aACF;SACF;KACF;CACF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isProjectPath(filePath: string): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getSourceFiles } from './find-files.js';
|
|
3
|
+
import { rcConfig } from '../main/config.js';
|
|
4
|
+
import { isAncestorDirectory } from './file-utils.js';
|
|
5
|
+
export function isProjectPath(filePath) {
|
|
6
|
+
const sourceFiles = getSourceFiles();
|
|
7
|
+
return (isAncestorDirectory(rcConfig.rootDir, filePath) ||
|
|
8
|
+
sourceFiles.includes(filePath) ||
|
|
9
|
+
!sourceFiles.some((sourceFile) => path.dirname(filePath) === path.dirname(sourceFile) ||
|
|
10
|
+
isAncestorDirectory(path.dirname(sourceFile), path.dirname(filePath))));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=path-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../../src/files/path-utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,OAAO,CACL,mBAAmB,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;QAC/C,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC9B,CAAC,WAAW,CAAC,IAAI,CACf,CAAC,UAAU,EAAE,EAAE,CACb,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YACnD,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CACxE,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionCall } from '../ai-service/common.js';
|
|
2
1
|
import { CodegenOptions } from '../main/codegen-types.js';
|
|
2
|
+
import { FunctionCall } from '../ai-service/common.js';
|
|
3
3
|
/**
|
|
4
4
|
* @param functionCalls Result of the code generation, a map of file paths to new content
|
|
5
5
|
*/
|
|
@@ -1,194 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import assert from 'node:assert';
|
|
4
|
-
import * as diff from 'diff';
|
|
5
|
-
import { getSourceFiles } from './find-files.js';
|
|
6
|
-
import { isAncestorDirectory } from './file-utils.js';
|
|
7
|
-
import { rcConfig } from '../main/config.js';
|
|
8
|
-
import { getTempBuffer } from './temp-buffer.js';
|
|
9
|
-
import { imglyRemoveBackground } from '../images/imgly-remove-background.js';
|
|
10
|
-
import { splitImage } from '../images/split-image.js';
|
|
11
|
-
import { resizeImageFile } from '../images/resize-image.js';
|
|
1
|
+
import { getOperationExecutor } from '../operations/operations-index.js';
|
|
12
2
|
/**
|
|
13
3
|
* @param functionCalls Result of the code generation, a map of file paths to new content
|
|
14
4
|
*/
|
|
15
5
|
export async function updateFiles(functionCalls, options) {
|
|
16
|
-
const { allowDirectoryCreate, allowFileCreate, allowFileDelete, allowFileMove } = options;
|
|
17
6
|
for (const { name, args } of functionCalls) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (name !== 'moveFile' && name !== 'imglyRemoveBackground' && name !== 'splitImage') {
|
|
22
|
-
assert(filePath);
|
|
23
|
-
filePath = path.isAbsolute(filePath) ? filePath : path.join(rcConfig.rootDir, filePath);
|
|
7
|
+
const executor = getOperationExecutor(name);
|
|
8
|
+
if (!executor) {
|
|
9
|
+
console.warn(`Unknown operation: ${name}`);
|
|
24
10
|
}
|
|
25
|
-
else if (
|
|
26
|
-
|
|
27
|
-
source = path.isAbsolute(source) ? source : path.join(rcConfig.rootDir, source);
|
|
28
|
-
assert(destination);
|
|
29
|
-
destination = path.isAbsolute(destination) ? destination : path.join(rcConfig.rootDir, destination);
|
|
11
|
+
else if (args === undefined) {
|
|
12
|
+
console.warn(`Operation ${name} has no arguments`);
|
|
30
13
|
}
|
|
31
|
-
else
|
|
32
|
-
|
|
33
|
-
inputFilePath = path.isAbsolute(inputFilePath) ? inputFilePath : path.join(rcConfig.rootDir, inputFilePath);
|
|
34
|
-
if (name === 'imglyRemoveBackground') {
|
|
35
|
-
assert(outputFilePath);
|
|
36
|
-
outputFilePath = path.isAbsolute(outputFilePath) ? outputFilePath : path.join(rcConfig.rootDir, outputFilePath);
|
|
37
|
-
}
|
|
38
|
-
else if (name === 'splitImage') {
|
|
39
|
-
parts?.forEach((part) => (part.outputFilePath = part.outputFilePath
|
|
40
|
-
? path.isAbsolute(part.outputFilePath)
|
|
41
|
-
? part.outputFilePath
|
|
42
|
-
: path.join(rcConfig.rootDir, part.outputFilePath)
|
|
43
|
-
: undefined));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// ignore files which are not located inside project directory (sourceFiles)
|
|
47
|
-
if ((name !== 'moveFile' && name !== 'imglyRemoveBackground' && name !== 'splitImage' && !isProjectPath(filePath)) ||
|
|
48
|
-
(name === 'moveFile' && (!isProjectPath(source) || !isProjectPath(destination))) ||
|
|
49
|
-
(name === 'imglyRemoveBackground' && (!isProjectPath(inputFilePath) || !isProjectPath(outputFilePath))) ||
|
|
50
|
-
(name === 'splitImage' &&
|
|
51
|
-
(!isProjectPath(inputFilePath) ||
|
|
52
|
-
parts.some((part) => part.outputFilePath && !isProjectPath(part.outputFilePath))))) {
|
|
53
|
-
console.log(`Skipping file: ${filePath || source || inputFilePath}`);
|
|
54
|
-
throw new Error(`File ${filePath || source || inputFilePath} is not located inside project directory, something is wrong?`);
|
|
55
|
-
}
|
|
56
|
-
if (name === 'deleteFile') {
|
|
57
|
-
assert(filePath);
|
|
58
|
-
assert(allowFileDelete, 'File delete option was not enabled');
|
|
59
|
-
console.log(`Removing file: ${filePath}`);
|
|
60
|
-
fs.unlinkSync(filePath);
|
|
61
|
-
}
|
|
62
|
-
else if (name === 'createDirectory') {
|
|
63
|
-
assert(filePath);
|
|
64
|
-
assert(allowDirectoryCreate, 'Directory create option was not enabled');
|
|
65
|
-
console.log(`Creating directory: ${filePath}`);
|
|
66
|
-
fs.mkdirSync(filePath, { recursive: true });
|
|
67
|
-
}
|
|
68
|
-
else if (name === 'updateFile' || name === 'createFile' || name === 'patchFile') {
|
|
69
|
-
assert(filePath);
|
|
70
|
-
if (name === 'patchFile') {
|
|
71
|
-
assert(patch);
|
|
72
|
-
console.log(`Applying a patch: ${filePath} content`);
|
|
73
|
-
newContent = diff.applyPatch(fs.readFileSync(filePath, 'utf-8'), patch) || '';
|
|
74
|
-
assert(!!newContent, 'Patch was not successful');
|
|
75
|
-
}
|
|
76
|
-
assert(!!newContent, 'newContent must not be empty');
|
|
77
|
-
if (name === 'createFile') {
|
|
78
|
-
console.log(`Creating file: ${filePath}`);
|
|
79
|
-
assert(allowFileCreate, 'File create option was not enabled');
|
|
80
|
-
assert(!fs.existsSync(filePath), 'File already exists');
|
|
81
|
-
if (allowDirectoryCreate) {
|
|
82
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
console.log(`Updating file: ${filePath}`);
|
|
87
|
-
assert(fs.existsSync(filePath), 'File does not exist');
|
|
88
|
-
}
|
|
89
|
-
fs.writeFileSync(filePath, newContent, 'utf-8');
|
|
90
|
-
}
|
|
91
|
-
else if (name === 'moveFile') {
|
|
92
|
-
console.log(`Moving file from ${source} to ${destination}`);
|
|
93
|
-
assert(source);
|
|
94
|
-
assert(destination);
|
|
95
|
-
assert(fs.existsSync(source), 'Source file does not exist');
|
|
96
|
-
assert(!fs.existsSync(destination), 'Destination file already exists');
|
|
97
|
-
assert(allowFileMove, 'File move option was not enabled');
|
|
98
|
-
if (allowDirectoryCreate) {
|
|
99
|
-
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
100
|
-
}
|
|
101
|
-
fs.renameSync(source, destination);
|
|
102
|
-
}
|
|
103
|
-
else if (name === 'downloadFile') {
|
|
104
|
-
console.log(`Downloading image: ${filePath}`);
|
|
105
|
-
assert(filePath);
|
|
106
|
-
assert(fs.existsSync(filePath) || allowFileCreate, 'File create option was not enabled and file does not exist');
|
|
107
|
-
if (allowDirectoryCreate) {
|
|
108
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
const downloadUrl = args?.downloadUrl;
|
|
112
|
-
assert(downloadUrl, 'image url is not empty');
|
|
113
|
-
if (downloadUrl.startsWith('temp://')) {
|
|
114
|
-
assert(getTempBuffer(downloadUrl), 'Temp buffer not present but expected');
|
|
115
|
-
fs.writeFileSync(filePath, getTempBuffer(downloadUrl));
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const imageResponse = await fetch(downloadUrl);
|
|
119
|
-
const arrayBuffer = await imageResponse.arrayBuffer();
|
|
120
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
121
|
-
fs.writeFileSync(filePath, buffer);
|
|
122
|
-
}
|
|
123
|
-
console.log(`Image download and saved to: ${filePath}`);
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
console.error('Failed to download image:', error);
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (name === 'imglyRemoveBackground') {
|
|
131
|
-
console.log(`Removing background from image: ${inputFilePath}`);
|
|
132
|
-
assert(inputFilePath);
|
|
133
|
-
assert(outputFilePath);
|
|
134
|
-
assert(fs.existsSync(inputFilePath), 'Input file does not exist');
|
|
135
|
-
assert(allowFileCreate || fs.existsSync(outputFilePath), 'File create option was not enabled and output file does not exist');
|
|
136
|
-
if (allowDirectoryCreate) {
|
|
137
|
-
fs.mkdirSync(path.dirname(outputFilePath), { recursive: true });
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
await imglyRemoveBackground(inputFilePath, outputFilePath);
|
|
141
|
-
console.log(`Background removed and image saved to: ${outputFilePath}`);
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
console.error('Failed to remove background', error);
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
else if (name === 'splitImage') {
|
|
149
|
-
console.log(`Splitting image: ${inputFilePath}`, parts);
|
|
150
|
-
assert(inputFilePath);
|
|
151
|
-
assert(fs.existsSync(inputFilePath), 'Input file does not exist');
|
|
152
|
-
assert(Array.isArray(parts) && parts.length > 0, 'Parts array must not be empty');
|
|
153
|
-
for (const part of parts) {
|
|
154
|
-
assert(part.outputFilePath);
|
|
155
|
-
assert(allowFileCreate || fs.existsSync(part.outputFilePath), 'File create option was not enabled and output file does not exist');
|
|
156
|
-
if (allowDirectoryCreate) {
|
|
157
|
-
fs.mkdirSync(path.dirname(part.outputFilePath), { recursive: true });
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
await splitImage(inputFilePath, parts.map((part) => ({ outputFilePath: part.outputFilePath, rect: part.rect })));
|
|
162
|
-
console.log(`Image split successfully`);
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
console.error('Failed to split image', error);
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else if (name === 'resizeImage') {
|
|
170
|
-
console.log(`Resizing image: ${filePath}`, size);
|
|
171
|
-
assert(filePath);
|
|
172
|
-
assert(size);
|
|
173
|
-
assert(size.width);
|
|
174
|
-
assert(size.height);
|
|
175
|
-
assert(fs.existsSync(filePath), 'Input file does not exist');
|
|
176
|
-
try {
|
|
177
|
-
await resizeImageFile(filePath, { width: size.width, height: size.height });
|
|
178
|
-
console.log(`Image resized successfully`);
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
console.error('Failed to resize image', error);
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
14
|
+
else {
|
|
15
|
+
await executor(args, options);
|
|
184
16
|
}
|
|
185
17
|
}
|
|
186
18
|
}
|
|
187
|
-
function isProjectPath(filePath) {
|
|
188
|
-
const sourceFiles = getSourceFiles();
|
|
189
|
-
return (isAncestorDirectory(rcConfig.rootDir, filePath) ||
|
|
190
|
-
sourceFiles.includes(filePath) ||
|
|
191
|
-
!sourceFiles.some((sourceFile) => path.dirname(filePath) === path.dirname(sourceFile) ||
|
|
192
|
-
isAncestorDirectory(path.dirname(sourceFile), path.dirname(filePath))));
|
|
193
|
-
}
|
|
194
19
|
//# sourceMappingURL=update-files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-files.js","sourceRoot":"","sources":["../../src/files/update-files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-files.js","sourceRoot":"","sources":["../../src/files/update-files.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,aAA6B,EAAE,OAAuB;IACtF,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,aAAa,EAAE,CAAC;QAC3C,MAAM,QAAQ,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;QAC7C,CAAC;aAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,aAAa,IAAI,mBAAmB,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './main/codegen-types.js';
|
|
2
2
|
export * from './main/codegen.js';
|
|
3
3
|
export * from './prompt/prompt-service.js';
|
|
4
|
+
export * from './ai-service/common.js';
|
|
5
|
+
export * from './prompt/steps/step-ask-question/step-ask-question-types.js';
|
|
6
|
+
export * from './main/common/content-bus.js';
|
|
7
|
+
export * from './prompt/steps/steps-types.js';
|
|
8
|
+
export * from './main/common/user-actions.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export * from './main/codegen-types.js';
|
|
1
2
|
export * from './main/codegen.js';
|
|
2
3
|
export * from './prompt/prompt-service.js';
|
|
4
|
+
export * from './ai-service/common.js';
|
|
5
|
+
export * from './prompt/steps/step-ask-question/step-ask-question-types.js';
|
|
6
|
+
export * from './main/common/content-bus.js';
|
|
7
|
+
export * from './prompt/steps/steps-types.js';
|
|
8
|
+
export * from './main/common/user-actions.js';
|
|
3
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6DAA6D,CAAC;AAC5E,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { FunctionDef, GenerateContentFunction } from '../ai-service/common';
|
|
2
|
+
import { ActionHandler } from '../prompt/steps/step-ask-question/step-ask-question-types';
|
|
3
|
+
/** Example: {@link ../../examples/genaicode_plugins/grok_ai_service.ts} */
|
|
4
|
+
export type PluginAiServiceType = `plugin:${string}`;
|
|
5
|
+
/** Example: {@link ../../examples/genaicode_plugins/nonsense_action_handlers.ts} */
|
|
6
|
+
export type PluginActionType = `plugin:${string}`;
|
|
7
|
+
export type AiServiceType = 'vertex-ai' | 'ai-studio' | 'vertex-ai-claude' | 'chat-gpt' | 'anthropic' | PluginAiServiceType;
|
|
2
8
|
export type ImagenType = 'vertex-ai' | 'dall-e';
|
|
3
9
|
export interface UploadedImage {
|
|
4
10
|
base64url: string;
|
|
@@ -40,3 +46,27 @@ export interface CodegenOptions {
|
|
|
40
46
|
images?: UploadedImage[];
|
|
41
47
|
isDev?: boolean;
|
|
42
48
|
}
|
|
49
|
+
interface ExecutorArgs {
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
export type OperationExecutor = (args: ExecutorArgs, options: CodegenOptions) => Promise<void>;
|
|
53
|
+
export type Operation = {
|
|
54
|
+
executor: OperationExecutor;
|
|
55
|
+
def: FunctionDef;
|
|
56
|
+
};
|
|
57
|
+
export interface Plugin {
|
|
58
|
+
name: string;
|
|
59
|
+
aiServices?: Record<string, GenerateContentFunction>;
|
|
60
|
+
operations?: Record<string, Operation>;
|
|
61
|
+
actionHandlers?: Record<string, {
|
|
62
|
+
/** The action handler implementation */
|
|
63
|
+
handler: ActionHandler;
|
|
64
|
+
/**
|
|
65
|
+
* Description of what this action handler does.
|
|
66
|
+
* This description will be included in the askQuestion function definition
|
|
67
|
+
* to help the AI understand when to use this action.
|
|
68
|
+
*/
|
|
69
|
+
description: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getRegisteredAiServices } from './plugin-loader.js';
|
|
2
|
+
export function getSupportedAiServices() {
|
|
3
|
+
return ['vertex-ai', 'ai-studio', 'vertex-ai-claude', 'chat-gpt', 'anthropic', ...getRegisteredAiServices().keys()];
|
|
4
|
+
}
|
|
5
|
+
export function stringToAiServiceType(aiService) {
|
|
6
|
+
if (!aiService) {
|
|
7
|
+
throw new Error('Please specify which AI service should be used with --ai-service option');
|
|
8
|
+
}
|
|
9
|
+
// Validate that the provided AI service is supported
|
|
10
|
+
const supportedServices = getSupportedAiServices();
|
|
11
|
+
if (!supportedServices.includes(aiService)) {
|
|
12
|
+
throw new Error(`Unsupported AI service: ${aiService}. Supported services are: ${supportedServices.join(', ')}`);
|
|
13
|
+
}
|
|
14
|
+
return aiService;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=codegen-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen-utils.js","sourceRoot":"","sources":["../../src/main/codegen-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,MAAM,UAAU,sBAAsB;IACpC,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,uBAAuB,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,SAAoC;IACxE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IAED,qDAAqD;IACrD,MAAM,iBAAiB,GAAG,sBAAsB,EAAE,CAAC;IACnD,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,SAA0B,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,6BAA6B,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnH,CAAC;IAED,OAAO,SAA0B,CAAC;AACpC,CAAC"}
|
package/dist/main/codegen.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { exec } from 'child_process';
|
|
2
2
|
import util from 'util';
|
|
3
|
-
import assert from 'node:assert';
|
|
4
3
|
import * as cliParams from '../cli/cli-params.js';
|
|
5
4
|
import { validateCliParams } from '../cli/validate-cli-params.js';
|
|
6
5
|
import { generateContent as generateContentVertexAi } from '../ai-service/vertex-ai.js';
|
|
@@ -20,6 +19,8 @@ import { runInteractiveMode } from './interactive/codegen-interactive.js';
|
|
|
20
19
|
import { runCodegenUI } from './ui/codegen-ui.js';
|
|
21
20
|
import { putSystemMessage, putUserMessage, setCurrentIterationId, unsetCurrentIterationId, } from './common/content-bus.js';
|
|
22
21
|
import { refreshFiles } from '../files/find-files.js';
|
|
22
|
+
import { getRegisteredAiServices } from './plugin-loader.js';
|
|
23
|
+
import { stringToAiServiceType } from './codegen-utils.js';
|
|
23
24
|
/** Executes codegen */
|
|
24
25
|
export async function runCodegen(isDev = false) {
|
|
25
26
|
// Print to console the received parameters
|
|
@@ -39,7 +40,7 @@ export async function runCodegen(isDev = false) {
|
|
|
39
40
|
allowFileDelete: cliParams.allowFileDelete,
|
|
40
41
|
allowDirectoryCreate: cliParams.allowDirectoryCreate,
|
|
41
42
|
allowFileMove: cliParams.allowFileMove,
|
|
42
|
-
aiService:
|
|
43
|
+
aiService: stringToAiServiceType(cliParams.aiService),
|
|
43
44
|
vision: cliParams.vision,
|
|
44
45
|
imagen: cliParams.imagen,
|
|
45
46
|
disableContextOptimization: cliParams.disableContextOptimization,
|
|
@@ -103,7 +104,7 @@ export async function runCodegenIteration(options, abortSignal, waitIfPaused = (
|
|
|
103
104
|
await waitIfPaused();
|
|
104
105
|
putSystemMessage('Generating response');
|
|
105
106
|
try {
|
|
106
|
-
const functionCalls = await promptService(
|
|
107
|
+
const functionCalls = await promptService(getGenerateContentFunctions(), GENERATE_IMAGE_FNS, getCodeGenPrompt(options), waitIfPaused);
|
|
107
108
|
console.log('Received function calls:', functionCalls);
|
|
108
109
|
await waitIfPaused();
|
|
109
110
|
if (functionCalls.length === 0) {
|
|
@@ -133,7 +134,7 @@ export async function runCodegenIteration(options, abortSignal, waitIfPaused = (
|
|
|
133
134
|
const firstLintError = error;
|
|
134
135
|
const lintErrorPrompt = getLintFixPrompt(rcConfig.lintCommand, options, firstLintError.stdout, firstLintError.stderr);
|
|
135
136
|
putSystemMessage('Generating response for lint fixes');
|
|
136
|
-
const lintFixFunctionCalls = (await promptService(
|
|
137
|
+
const lintFixFunctionCalls = (await promptService(getGenerateContentFunctions(), GENERATE_IMAGE_FNS, {
|
|
137
138
|
prompt: lintErrorPrompt,
|
|
138
139
|
options: { ...options, considerAllFiles: true },
|
|
139
140
|
}, waitIfPaused));
|
|
@@ -183,30 +184,18 @@ export async function runCodegenIteration(options, abortSignal, waitIfPaused = (
|
|
|
183
184
|
}
|
|
184
185
|
// helper functions and consts
|
|
185
186
|
const execPromise = util.promisify(exec);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
function getGenerateContentFunctions() {
|
|
188
|
+
return {
|
|
189
|
+
'vertex-ai-claude': generateContentVertexAiClaude,
|
|
190
|
+
'vertex-ai': generateContentVertexAi,
|
|
191
|
+
'ai-studio': generateContentAiStudio,
|
|
192
|
+
anthropic: generateContentAnthropic,
|
|
193
|
+
'chat-gpt': generateContentGPT,
|
|
194
|
+
...Object.fromEntries(getRegisteredAiServices().entries()),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
193
197
|
const GENERATE_IMAGE_FNS = {
|
|
194
198
|
'dall-e': generateImageDallE,
|
|
195
199
|
'vertex-ai': generateImageVertexAi,
|
|
196
200
|
};
|
|
197
|
-
function cliParamToAiService() {
|
|
198
|
-
const result = cliParams.vertexAi
|
|
199
|
-
? 'vertex-ai'
|
|
200
|
-
: cliParams.aiStudio
|
|
201
|
-
? 'ai-studio'
|
|
202
|
-
: cliParams.vertexAiClaude
|
|
203
|
-
? 'vertex-ai-claude'
|
|
204
|
-
: cliParams.chatGpt
|
|
205
|
-
? 'chat-gpt'
|
|
206
|
-
: cliParams.anthropic
|
|
207
|
-
? 'anthropic'
|
|
208
|
-
: undefined;
|
|
209
|
-
assert(result, 'Please specify which AI service should be used');
|
|
210
|
-
return result;
|
|
211
|
-
}
|
|
212
201
|
//# sourceMappingURL=codegen.js.map
|