@microsoft/teamsfx-core 3.0.15-beta.2026072312.0 → 3.0.15
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/build/client/aadAppClient.d.ts.map +1 -1
- package/build/client/aadAppClient.js +6 -6
- package/build/client/aadAppClient.js.map +1 -1
- package/build/common/featureFlags.d.ts +5 -0
- package/build/common/featureFlags.d.ts.map +1 -1
- package/build/common/featureFlags.js +5 -0
- package/build/common/featureFlags.js.map +1 -1
- package/build/common/secretmasker/dict.d.ts.map +1 -1
- package/build/common/secretmasker/dict.js +2 -5
- package/build/common/secretmasker/dict.js.map +1 -1
- package/build/common/secretmasker/feature.js.map +1 -1
- package/build/common/templates-config.json +4 -4
- package/build/component/coordinator/index.d.ts.map +1 -1
- package/build/component/coordinator/index.js.map +1 -1
- package/build/component/deps-checker/internal/dotnetChecker.js.map +1 -1
- package/build/component/driver/deploy/azure/impl/AzureZipDeployImpl.d.ts +0 -3
- package/build/component/driver/deploy/azure/impl/AzureZipDeployImpl.d.ts.map +1 -1
- package/build/component/driver/deploy/azure/impl/AzureZipDeployImpl.js +3 -38
- package/build/component/driver/deploy/azure/impl/AzureZipDeployImpl.js.map +1 -1
- package/build/component/driver/script/scriptDriver.js +1 -1
- package/build/component/driver/script/scriptDriver.js.map +1 -1
- package/build/component/driver/teamsApp/create.d.ts.map +1 -1
- package/build/component/driver/teamsApp/create.js +3 -3
- package/build/component/driver/teamsApp/create.js.map +1 -1
- package/build/component/driver/teamsApp/createAppPackage.d.ts +0 -1
- package/build/component/driver/teamsApp/createAppPackage.d.ts.map +1 -1
- package/build/component/driver/teamsApp/createAppPackage.js +0 -23
- package/build/component/driver/teamsApp/createAppPackage.js.map +1 -1
- package/build/component/driver/teamsApp/utils/CopilotGptManifestUtils.js.map +1 -1
- package/build/component/generator/declarativeAgent/helper.js.map +1 -1
- package/build/component/generator/officeAddin/generator.d.ts +0 -1
- package/build/component/generator/officeAddin/generator.d.ts.map +1 -1
- package/build/component/generator/officeAddin/generator.js +2 -109
- package/build/component/generator/officeAddin/generator.js.map +1 -1
- package/build/component/generator/openApiSpec/helper.d.ts +3 -2
- package/build/component/generator/openApiSpec/helper.d.ts.map +1 -1
- package/build/component/generator/openApiSpec/helper.js +56 -6
- package/build/component/generator/openApiSpec/helper.js.map +1 -1
- package/build/component/generator/templateHelper.d.ts +2 -10
- package/build/component/generator/templateHelper.d.ts.map +1 -1
- package/build/component/generator/templateHelper.js +3 -16
- package/build/component/generator/templateHelper.js.map +1 -1
- package/build/component/generator/templates/templateNames.d.ts +0 -2
- package/build/component/generator/templates/templateNames.d.ts.map +1 -1
- package/build/component/generator/templates/templateNames.js +0 -2
- package/build/component/generator/templates/templateNames.js.map +1 -1
- package/build/component/generator/utils.d.ts.map +1 -1
- package/build/component/generator/utils.js +0 -6
- package/build/component/generator/utils.js.map +1 -1
- package/build/component/generator/v4TemplateBridge.d.ts +1 -4
- package/build/component/generator/v4TemplateBridge.d.ts.map +1 -1
- package/build/component/generator/v4TemplateBridge.js +3 -11
- package/build/component/generator/v4TemplateBridge.js.map +1 -1
- package/build/component/utils/envUtil.d.ts.map +1 -1
- package/build/component/utils/envUtil.js +2 -2
- package/build/component/utils/envUtil.js.map +1 -1
- package/build/component/utils/fileOperation.d.ts.map +1 -1
- package/build/component/utils/fileOperation.js +1 -4
- package/build/component/utils/fileOperation.js.map +1 -1
- package/build/component/utils/mcpAuthScaffolder.d.ts.map +1 -1
- package/build/component/utils/mcpAuthScaffolder.js.map +1 -1
- package/build/component/utils/mcpToolFetcher.d.ts +72 -1
- package/build/component/utils/mcpToolFetcher.d.ts.map +1 -1
- package/build/component/utils/mcpToolFetcher.js +227 -1
- package/build/component/utils/mcpToolFetcher.js.map +1 -1
- package/build/component/utils/odrProvider.d.ts +55 -1
- package/build/component/utils/odrProvider.d.ts.map +1 -1
- package/build/component/utils/odrProvider.js +101 -1
- package/build/component/utils/odrProvider.js.map +1 -1
- package/build/core/FxCore.d.ts.map +1 -1
- package/build/core/FxCore.declarativeAgent.d.ts.map +1 -1
- package/build/core/FxCore.declarativeAgent.js +0 -41
- package/build/core/FxCore.declarativeAgent.js.map +1 -1
- package/build/core/FxCore.js +5 -3
- package/build/core/FxCore.js.map +1 -1
- package/build/core/createFrontDoorAdapters.d.ts +25 -1
- package/build/core/createFrontDoorAdapters.d.ts.map +1 -1
- package/build/core/createFrontDoorAdapters.js +155 -4
- package/build/core/createFrontDoorAdapters.js.map +1 -1
- package/build/core/createProjectFrontDoor.d.ts +12 -10
- package/build/core/createProjectFrontDoor.d.ts.map +1 -1
- package/build/core/createProjectFrontDoor.js +106 -141
- package/build/core/createProjectFrontDoor.js.map +1 -1
- package/build/core/modifyProjectFrontDoor.d.ts +1 -0
- package/build/core/modifyProjectFrontDoor.d.ts.map +1 -1
- package/build/core/modifyProjectFrontDoor.js +2 -0
- package/build/core/modifyProjectFrontDoor.js.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/question/inputs/AddKnowledgeInputs.d.ts.map +1 -1
- package/build/question/inputs/CreateProjectInputs.d.ts +0 -4
- package/build/question/inputs/CreateProjectInputs.d.ts.map +1 -1
- package/build/question/options/CreateProjectOptions.d.ts.map +1 -1
- package/build/question/options/CreateProjectOptions.js +0 -14
- package/build/question/options/CreateProjectOptions.js.map +1 -1
- package/build/question/other.d.ts.map +1 -1
- package/build/question/other.js +1 -2
- package/build/question/other.js.map +1 -1
- package/build/question/questionNames.d.ts +0 -2
- package/build/question/questionNames.d.ts.map +1 -1
- package/build/question/questionNames.js +0 -2
- package/build/question/questionNames.js.map +1 -1
- package/build/question/scaffold/constructNode.d.ts +1 -3
- package/build/question/scaffold/constructNode.d.ts.map +1 -1
- package/build/question/scaffold/constructNode.js +0 -50
- package/build/question/scaffold/constructNode.js.map +1 -1
- package/build/question/scaffold/vsc/CapabilityOptions.d.ts +0 -2
- package/build/question/scaffold/vsc/CapabilityOptions.d.ts.map +1 -1
- package/build/question/scaffold/vsc/CapabilityOptions.js +0 -16
- package/build/question/scaffold/vsc/CapabilityOptions.js.map +1 -1
- package/build/question/scaffold/vsc/teamsProjectTypeNode.d.ts.map +1 -1
- package/build/question/scaffold/vsc/teamsProjectTypeNode.js +7 -0
- package/build/question/scaffold/vsc/teamsProjectTypeNode.js.map +1 -1
- package/build/v4/buildTarget/parseSelector.d.ts +2 -6
- package/build/v4/buildTarget/parseSelector.d.ts.map +1 -1
- package/build/v4/buildTarget/parseSelector.js +45 -58
- package/build/v4/buildTarget/parseSelector.js.map +1 -1
- package/build/v4/buildTarget/resolveBuildTarget.d.ts +7 -21
- package/build/v4/buildTarget/resolveBuildTarget.d.ts.map +1 -1
- package/build/v4/buildTarget/resolveBuildTarget.js +52 -97
- package/build/v4/buildTarget/resolveBuildTarget.js.map +1 -1
- package/build/v4/collectInputs/collectInputs.d.ts +9 -50
- package/build/v4/collectInputs/collectInputs.d.ts.map +1 -1
- package/build/v4/collectInputs/collectInputs.js +91 -274
- package/build/v4/collectInputs/collectInputs.js.map +1 -1
- package/build/v4/distribution/createQuestions.d.ts.map +1 -1
- package/build/v4/distribution/createQuestions.js +29 -2
- package/build/v4/distribution/createQuestions.js.map +1 -1
- package/build/v4/distribution/declarativePackage.d.ts.map +1 -1
- package/build/v4/distribution/declarativePackage.js +30 -2
- package/build/v4/distribution/declarativePackage.js.map +1 -1
- package/build/v4/expression/evaluateExpression.d.ts +0 -13
- package/build/v4/expression/evaluateExpression.d.ts.map +1 -1
- package/build/v4/expression/evaluateExpression.js +0 -57
- package/build/v4/expression/evaluateExpression.js.map +1 -1
- package/build/v4/index.d.ts +0 -7
- package/build/v4/index.d.ts.map +1 -1
- package/build/v4/index.js +0 -7
- package/build/v4/index.js.map +1 -1
- package/build/v4/model/dataModel.d.ts +1 -1
- package/build/v4/model/dataModel.d.ts.map +1 -1
- package/build/v4/pipeline/runScaffoldPipeline.d.ts +4 -20
- package/build/v4/pipeline/runScaffoldPipeline.d.ts.map +1 -1
- package/build/v4/pipeline/runScaffoldPipeline.js +9 -61
- package/build/v4/pipeline/runScaffoldPipeline.js.map +1 -1
- package/build/v4/renderContext/buildRenderContext.d.ts.map +1 -1
- package/build/v4/renderContext/buildRenderContext.js +2 -1
- package/build/v4/renderContext/buildRenderContext.js.map +1 -1
- package/build/v4/runtime/inMemoryRuntime.d.ts +1 -4
- package/build/v4/runtime/inMemoryRuntime.d.ts.map +1 -1
- package/build/v4/runtime/inMemoryRuntime.js +3 -22
- package/build/v4/runtime/inMemoryRuntime.js.map +1 -1
- package/build/v4/runtime/packageParse.d.ts.map +1 -1
- package/build/v4/runtime/packageParse.js +8 -64
- package/build/v4/runtime/packageParse.js.map +1 -1
- package/build/v4/runtime/realRuntime.d.ts +1 -2
- package/build/v4/runtime/realRuntime.d.ts.map +1 -1
- package/build/v4/runtime/realRuntime.js +2 -3
- package/build/v4/runtime/realRuntime.js.map +1 -1
- package/build/v4/runtime/renderMustache.d.ts.map +1 -1
- package/build/v4/runtime/renderMustache.js +4 -13
- package/build/v4/runtime/renderMustache.js.map +1 -1
- package/build/v4/runtime/runtimeRegistry.d.ts +3 -12
- package/build/v4/runtime/runtimeRegistry.d.ts.map +1 -1
- package/build/v4/runtime/runtimeRegistry.js +17 -123
- package/build/v4/runtime/runtimeRegistry.js.map +1 -1
- package/build/v4/runtime/scaffold.d.ts +0 -1
- package/build/v4/runtime/scaffold.d.ts.map +1 -1
- package/build/v4/runtime/scaffold.js +20 -1
- package/build/v4/runtime/scaffold.js.map +1 -1
- package/build/v4/runtime/steps/daAction.d.ts.map +1 -1
- package/build/v4/runtime/steps/daAction.js +111 -3
- package/build/v4/runtime/steps/daAction.js.map +1 -1
- package/build/v4/runtime/steps/mcpAuth.d.ts +2 -5
- package/build/v4/runtime/steps/mcpAuth.d.ts.map +1 -1
- package/build/v4/runtime/steps/mcpAuth.js +66 -37
- package/build/v4/runtime/steps/mcpAuth.js.map +1 -1
- package/build/v4/runtime/steps/mcpLocal.d.ts +4 -0
- package/build/v4/runtime/steps/mcpLocal.d.ts.map +1 -1
- package/build/v4/runtime/steps/mcpLocal.js +31 -11
- package/build/v4/runtime/steps/mcpLocal.js.map +1 -1
- package/build/v4/runtime/steps/mcpStatic.d.ts +1 -1
- package/build/v4/runtime/steps/mcpStatic.d.ts.map +1 -1
- package/build/v4/runtime/steps/mcpStatic.js +32 -14
- package/build/v4/runtime/steps/mcpStatic.js.map +1 -1
- package/build/v4/runtime/steps/metaOs.d.ts.map +1 -1
- package/build/v4/runtime/steps/metaOs.js +51 -39
- package/build/v4/runtime/steps/metaOs.js.map +1 -1
- package/build/v4/runtime/steps/officeAddin.d.ts.map +1 -1
- package/build/v4/runtime/steps/officeAddin.js +12 -7
- package/build/v4/runtime/steps/officeAddin.js.map +1 -1
- package/build/v4/runtime/steps/openApi.d.ts.map +1 -1
- package/build/v4/runtime/steps/openApi.js +555 -47
- package/build/v4/runtime/steps/openApi.js.map +1 -1
- package/build/v4/surface/createInputs.d.ts +3 -25
- package/build/v4/surface/createInputs.d.ts.map +1 -1
- package/build/v4/surface/createInputs.js +431 -54
- package/build/v4/surface/createInputs.js.map +1 -1
- package/build/v4/surface/createSelectorWalk.d.ts +3 -8
- package/build/v4/surface/createSelectorWalk.d.ts.map +1 -1
- package/build/v4/surface/createSelectorWalk.js +11 -21
- package/build/v4/surface/createSelectorWalk.js.map +1 -1
- package/build/v4/surface/modifySelectorWalk.d.ts.map +1 -1
- package/build/v4/surface/modifySelectorWalk.js +3 -0
- package/build/v4/surface/modifySelectorWalk.js.map +1 -1
- package/build/v4/surface/uiPromptUI.d.ts.map +1 -1
- package/build/v4/surface/uiPromptUI.js +41 -36
- package/build/v4/surface/uiPromptUI.js.map +1 -1
- package/build/v4/validation/validateTemplatePackage.d.ts +2 -21
- package/build/v4/validation/validateTemplatePackage.d.ts.map +1 -1
- package/build/v4/validation/validateTemplatePackage.js +31 -155
- package/build/v4/validation/validateTemplatePackage.js.map +1 -1
- package/package.json +20 -26
- package/resource/package.nls.cs.json +0 -1
- package/resource/package.nls.de.json +54 -55
- package/resource/package.nls.es.json +0 -1
- package/resource/package.nls.fr.json +0 -1
- package/resource/package.nls.it.json +0 -1
- package/resource/package.nls.ja.json +0 -1
- package/resource/package.nls.json +0 -2
- package/resource/package.nls.ko.json +0 -1
- package/resource/package.nls.pl.json +0 -1
- package/resource/package.nls.pt-BR.json +0 -1
- package/resource/package.nls.ru.json +0 -1
- package/resource/package.nls.tr.json +0 -1
- package/resource/package.nls.zh-Hans.json +0 -1
- package/resource/package.nls.zh-Hant.json +0 -1
- package/resource/templates/package.nls.cs.json +2 -9
- package/resource/templates/package.nls.de.json +2 -9
- package/resource/templates/package.nls.es.json +2 -9
- package/resource/templates/package.nls.fr.json +2 -9
- package/resource/templates/package.nls.it.json +2 -9
- package/resource/templates/package.nls.ja.json +2 -9
- package/resource/templates/package.nls.json +3 -16
- package/resource/templates/package.nls.ko.json +2 -9
- package/resource/templates/package.nls.pl.json +2 -9
- package/resource/templates/package.nls.pt-BR.json +2 -9
- package/resource/templates/package.nls.ru.json +2 -9
- package/resource/templates/package.nls.tr.json +2 -9
- package/resource/templates/package.nls.zh-Hans.json +2 -9
- package/resource/templates/package.nls.zh-Hant.json +2 -9
- package/resource/templates/package.nls.zh-cn.json +1 -7
- package/resource/templates/package.nls.zh-tw.json +1 -7
- package/templates/configs/local/typescript/.gitignore +1 -0
- package/templates/configs/playground/typescript/.gitignore +4 -0
- package/templates/fallback/common.zip +0 -0
- package/templates/fallback/csharp.zip +0 -0
- package/templates/fallback/js.zip +0 -0
- package/templates/fallback/python.zip +0 -0
- package/templates/fallback/ts.zip +0 -0
- package/templates/metadata/allTemplates.json +2 -16
- package/templates/metadata.zip +0 -0
- package/templates/ui/wizardNode.json +0 -24
- package/templates/v4/create-selector.json +5 -12
- package/templates/v4/floor.json +1 -1
- package/templates/v4/modify-selector.json +6 -1
- package/templates/v4/templates-metadata.zip +0 -0
- package/templates/v4/templates.zip +0 -0
- package/build/common/httpProxy.d.ts +0 -21
- package/build/common/httpProxy.d.ts.map +0 -1
- package/build/common/httpProxy.js +0 -117
- package/build/common/httpProxy.js.map +0 -1
- package/build/common/mcpToolFetcher.d.ts +0 -31
- package/build/common/mcpToolFetcher.d.ts.map +0 -1
- package/build/common/mcpToolFetcher.js +0 -182
- package/build/common/mcpToolFetcher.js.map +0 -1
- package/build/common/odrProvider.d.ts +0 -43
- package/build/common/odrProvider.d.ts.map +0 -1
- package/build/common/odrProvider.js +0 -154
- package/build/common/odrProvider.js.map +0 -1
- package/build/common/openApiParserOptions.d.ts +0 -3
- package/build/common/openApiParserOptions.d.ts.map +0 -1
- package/build/common/openApiParserOptions.js +0 -61
- package/build/common/openApiParserOptions.js.map +0 -1
- package/build/v4/distribution/questionFragments.d.ts +0 -11
- package/build/v4/distribution/questionFragments.d.ts.map +0 -1
- package/build/v4/distribution/questionFragments.js +0 -130
- package/build/v4/distribution/questionFragments.js.map +0 -1
- package/build/v4/engineVersion.d.ts +0 -7
- package/build/v4/engineVersion.d.ts.map +0 -1
- package/build/v4/engineVersion.js +0 -12
- package/build/v4/engineVersion.js.map +0 -1
- package/build/v4/inspection/scaffoldCatalog.d.ts +0 -28
- package/build/v4/inspection/scaffoldCatalog.d.ts.map +0 -1
- package/build/v4/inspection/scaffoldCatalog.js +0 -66
- package/build/v4/inspection/scaffoldCatalog.js.map +0 -1
- package/build/v4/inspection/scaffoldMetadataSource.d.ts +0 -6
- package/build/v4/inspection/scaffoldMetadataSource.d.ts.map +0 -1
- package/build/v4/inspection/scaffoldMetadataSource.js +0 -78
- package/build/v4/inspection/scaffoldMetadataSource.js.map +0 -1
- package/build/v4/mcp/mcpAuthAction.d.ts +0 -28
- package/build/v4/mcp/mcpAuthAction.d.ts.map +0 -1
- package/build/v4/mcp/mcpAuthAction.js +0 -162
- package/build/v4/mcp/mcpAuthAction.js.map +0 -1
- package/build/v4/mcp/mcpAuthScaffold.d.ts +0 -37
- package/build/v4/mcp/mcpAuthScaffold.d.ts.map +0 -1
- package/build/v4/mcp/mcpAuthScaffold.js +0 -140
- package/build/v4/mcp/mcpAuthScaffold.js.map +0 -1
- package/build/v4/providers/createOptionsProviders.d.ts +0 -11
- package/build/v4/providers/createOptionsProviders.d.ts.map +0 -1
- package/build/v4/providers/createOptionsProviders.js +0 -268
- package/build/v4/providers/createOptionsProviders.js.map +0 -1
- package/build/v4/runtime/generalSensitivityLabel.d.ts +0 -5
- package/build/v4/runtime/generalSensitivityLabel.d.ts.map +0 -1
- package/build/v4/runtime/generalSensitivityLabel.js +0 -36
- package/build/v4/runtime/generalSensitivityLabel.js.map +0 -1
- package/build/v4/runtime/steps/daSensitivity.d.ts +0 -14
- package/build/v4/runtime/steps/daSensitivity.d.ts.map +0 -1
- package/build/v4/runtime/steps/daSensitivity.js +0 -50
- package/build/v4/runtime/steps/daSensitivity.js.map +0 -1
- package/build/v4/runtime/steps/openApiCustomApi.d.ts +0 -5
- package/build/v4/runtime/steps/openApiCustomApi.d.ts.map +0 -1
- package/build/v4/runtime/steps/openApiCustomApi.js +0 -385
- package/build/v4/runtime/steps/openApiCustomApi.js.map +0 -1
- package/build/v4/runtime/withTempDirectory.d.ts +0 -10
- package/build/v4/runtime/withTempDirectory.d.ts.map +0 -1
- package/build/v4/runtime/withTempDirectory.js +0 -41
- package/build/v4/runtime/withTempDirectory.js.map +0 -1
- package/build/v4/surface/createFloorTail.d.ts +0 -12
- package/build/v4/surface/createFloorTail.d.ts.map +0 -1
- package/build/v4/surface/createFloorTail.js +0 -138
- package/build/v4/surface/createFloorTail.js.map +0 -1
- package/build/v4/surface/localizePrompt.d.ts +0 -11
- package/build/v4/surface/localizePrompt.d.ts.map +0 -1
- package/build/v4/surface/localizePrompt.js +0 -32
- package/build/v4/surface/localizePrompt.js.map +0 -1
- package/build/v4/validation/capabilityCatalog.d.ts +0 -8
- package/build/v4/validation/capabilityCatalog.d.ts.map +0 -1
- package/build/v4/validation/capabilityCatalog.js +0 -61
- package/build/v4/validation/capabilityCatalog.js.map +0 -1
- package/build/v4/validation/templateArchiveValidation.d.ts +0 -15
- package/build/v4/validation/templateArchiveValidation.d.ts.map +0 -1
- package/build/v4/validation/templateArchiveValidation.js +0 -297
- package/build/v4/validation/templateArchiveValidation.js.map +0 -1
- package/build/v4/validators/createInputValidators.d.ts +0 -7
- package/build/v4/validators/createInputValidators.d.ts.map +0 -1
- package/build/v4/validators/createInputValidators.js +0 -75
- package/build/v4/validators/createInputValidators.js.map +0 -1
- package/build/v4/validators/mcpCredentialValidators.d.ts +0 -5
- package/build/v4/validators/mcpCredentialValidators.d.ts.map +0 -1
- package/build/v4/validators/mcpCredentialValidators.js +0 -13
- package/build/v4/validators/mcpCredentialValidators.js.map +0 -1
|
@@ -8,14 +8,12 @@ const m365_spec_parser_1 = require("@microsoft/m365-spec-parser");
|
|
|
8
8
|
const teamsfx_api_1 = require("@microsoft/teamsfx-api");
|
|
9
9
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
10
10
|
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
11
|
+
const os = tslib_1.__importStar(require("os"));
|
|
11
12
|
const path = tslib_1.__importStar(require("path"));
|
|
12
13
|
const neverthrow_1 = require("neverthrow");
|
|
13
|
-
const openApiParserOptions_1 = require("../../../common/openApiParserOptions");
|
|
14
14
|
const stringUtils_1 = require("../../../common/stringUtils");
|
|
15
15
|
const utils_1 = require("../../../common/utils");
|
|
16
16
|
const constants_1 = require("../../../question/constants");
|
|
17
|
-
const withTempDirectory_1 = require("../withTempDirectory");
|
|
18
|
-
const openApiCustomApi_1 = require("./openApiCustomApi");
|
|
19
17
|
/** Generate API plugin files through spec-parser, then copy artifacts back via `ctx.write`. */
|
|
20
18
|
const SOURCE = "Scaffold";
|
|
21
19
|
exports.STEP_GENERATE_OPENAPI_PLUGIN_FILES = "openapi/generate-plugin-files";
|
|
@@ -28,6 +26,17 @@ const ORIGINAL_API_SPEC_PATH = `${API_SPEC_PATH}.original`;
|
|
|
28
26
|
const DEFAULT_ACTION_ID = "action_1";
|
|
29
27
|
const M365_AGENTS_YML = "m365agents.yml";
|
|
30
28
|
const M365_AGENTS_LOCAL_YML = "m365agents.local.yml";
|
|
29
|
+
const TEAMS_AI_OPERATION_METHODS = [
|
|
30
|
+
"get",
|
|
31
|
+
"post",
|
|
32
|
+
"put",
|
|
33
|
+
"delete",
|
|
34
|
+
"patch",
|
|
35
|
+
"head",
|
|
36
|
+
"connect",
|
|
37
|
+
"options",
|
|
38
|
+
"trace",
|
|
39
|
+
];
|
|
31
40
|
function systemError(name, message) {
|
|
32
41
|
return new teamsfx_api_1.SystemError({ source: SOURCE, name, message });
|
|
33
42
|
}
|
|
@@ -42,6 +51,9 @@ function stringArrayParam(params, key) {
|
|
|
42
51
|
}
|
|
43
52
|
return value;
|
|
44
53
|
}
|
|
54
|
+
function isRecord(value) {
|
|
55
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56
|
+
}
|
|
45
57
|
function readRequired(ctx, filePath) {
|
|
46
58
|
const current = ctx.read(filePath);
|
|
47
59
|
if (current === undefined) {
|
|
@@ -52,6 +64,107 @@ function readRequired(ctx, filePath) {
|
|
|
52
64
|
function errorMessage(error) {
|
|
53
65
|
return error instanceof Error ? error.message : String(error);
|
|
54
66
|
}
|
|
67
|
+
function parseJsonObject(json, filePath, errorName) {
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = JSON.parse(json);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return (0, neverthrow_1.err)(systemError(`${errorName}Parse`, `Cannot parse '${filePath}' as JSON: ${errorMessage(error)}`));
|
|
74
|
+
}
|
|
75
|
+
if (!isRecord(parsed)) {
|
|
76
|
+
return (0, neverthrow_1.err)(systemError(`${errorName}Shape`, `'${filePath}' is not a JSON object`));
|
|
77
|
+
}
|
|
78
|
+
return (0, neverthrow_1.ok)(parsed);
|
|
79
|
+
}
|
|
80
|
+
function isConversationStarter(value) {
|
|
81
|
+
return isRecord(value) && typeof value.text === "string";
|
|
82
|
+
}
|
|
83
|
+
function conversationStartersFromUnknown(value) {
|
|
84
|
+
if (!Array.isArray(value)) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
return value.filter(isConversationStarter).map((starter) => ({ text: starter.text }));
|
|
88
|
+
}
|
|
89
|
+
function pluginConversationStarters(plugin) {
|
|
90
|
+
const capabilities = plugin.capabilities;
|
|
91
|
+
if (!isRecord(capabilities)) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
return conversationStartersFromUnknown(capabilities.conversation_starters);
|
|
95
|
+
}
|
|
96
|
+
function pluginOperationIds(plugin) {
|
|
97
|
+
const operationIds = new Set();
|
|
98
|
+
if (!Array.isArray(plugin.functions)) {
|
|
99
|
+
return operationIds;
|
|
100
|
+
}
|
|
101
|
+
for (const func of plugin.functions) {
|
|
102
|
+
if (!isRecord(func) || typeof func.name !== "string") {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
operationIds.add(func.name);
|
|
106
|
+
}
|
|
107
|
+
return operationIds;
|
|
108
|
+
}
|
|
109
|
+
async function specConversationStarters(apiSpecPath, operationIds) {
|
|
110
|
+
if (operationIds.size === 0) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const parser = new m365_spec_parser_1.SpecParser(apiSpecPath, openApiParseOptions());
|
|
114
|
+
const listed = await parser.list();
|
|
115
|
+
const starters = [];
|
|
116
|
+
for (const operation of listed.APIs) {
|
|
117
|
+
if (!operation.isValid || !operation.operationId || !operationIds.has(operation.operationId)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const text = operation.summary || operation.description;
|
|
121
|
+
if (text) {
|
|
122
|
+
starters.push({ text });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return starters;
|
|
126
|
+
}
|
|
127
|
+
function appendConversationStarters(agent, starters) {
|
|
128
|
+
if (starters.length === 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const nextStarters = Array.isArray(agent.conversation_starters)
|
|
132
|
+
? [...agent.conversation_starters]
|
|
133
|
+
: [];
|
|
134
|
+
for (const starter of starters) {
|
|
135
|
+
if (nextStarters.length >= 6) {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
const alreadyExists = nextStarters.some((existingStarter) => isConversationStarter(existingStarter) && existingStarter.text === starter.text);
|
|
139
|
+
if (!alreadyExists) {
|
|
140
|
+
nextStarters.push(starter);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
agent.conversation_starters = nextStarters;
|
|
144
|
+
}
|
|
145
|
+
async function addActionAndConversationStarters(agentJson, pluginJson, apiSpecPath) {
|
|
146
|
+
const agent = parseJsonObject(agentJson, AGENT_PATH, "OpenApiDeclarativeAgent");
|
|
147
|
+
if (agent.isErr()) {
|
|
148
|
+
return (0, neverthrow_1.err)(agent.error);
|
|
149
|
+
}
|
|
150
|
+
const plugin = parseJsonObject(pluginJson, PLUGIN_PATH, "OpenApiPluginManifest");
|
|
151
|
+
if (plugin.isErr()) {
|
|
152
|
+
return (0, neverthrow_1.err)(plugin.error);
|
|
153
|
+
}
|
|
154
|
+
const actions = agent.value.actions;
|
|
155
|
+
if (actions !== undefined && !Array.isArray(actions)) {
|
|
156
|
+
return (0, neverthrow_1.err)(systemError("OpenApiDeclarativeAgentActions", `'${AGENT_PATH}' actions is not an array`));
|
|
157
|
+
}
|
|
158
|
+
const nextActions = Array.isArray(actions) ? [...actions] : [];
|
|
159
|
+
nextActions.push({ id: DEFAULT_ACTION_ID, file: teamsfx_api_1.DefaultPluginManifestFileName });
|
|
160
|
+
agent.value.actions = nextActions;
|
|
161
|
+
let starters = pluginConversationStarters(plugin.value);
|
|
162
|
+
if (starters.length === 0) {
|
|
163
|
+
starters = await specConversationStarters(apiSpecPath, pluginOperationIds(plugin.value));
|
|
164
|
+
}
|
|
165
|
+
appendConversationStarters(agent.value, starters);
|
|
166
|
+
return (0, neverthrow_1.ok)(JSON.stringify(agent.value, null, 4) + "\n");
|
|
167
|
+
}
|
|
55
168
|
function registrationIdEnvName(authName) {
|
|
56
169
|
return m365_spec_parser_1.Utils.getSafeRegistrationIdEnvName(`${authName}_${m365_spec_parser_1.ConstantString.RegistrationIdPostfix}`);
|
|
57
170
|
}
|
|
@@ -68,11 +181,14 @@ function authType(operation) {
|
|
|
68
181
|
}
|
|
69
182
|
return undefined;
|
|
70
183
|
}
|
|
71
|
-
function selectedAuthRegistrations(
|
|
184
|
+
async function selectedAuthRegistrations(apiSpecLocation, apiOperations) {
|
|
185
|
+
const parser = new m365_spec_parser_1.SpecParser(apiSpecLocation, openApiParseOptions());
|
|
186
|
+
const listed = await parser.list();
|
|
187
|
+
const selected = listed.APIs.filter((operation) => apiOperations.includes(operation.api));
|
|
72
188
|
const serverUrls = new Set();
|
|
73
189
|
const authNames = new Set();
|
|
74
190
|
const registrations = [];
|
|
75
|
-
for (const operation of
|
|
191
|
+
for (const operation of selected) {
|
|
76
192
|
const type = authType(operation);
|
|
77
193
|
const authName = operation.auth?.name;
|
|
78
194
|
if (type === undefined || !authName) {
|
|
@@ -100,10 +216,6 @@ function selectedAuthRegistrations(selectedOperations) {
|
|
|
100
216
|
}
|
|
101
217
|
return (0, neverthrow_1.ok)(registrations);
|
|
102
218
|
}
|
|
103
|
-
function conversationStarterText(operation) {
|
|
104
|
-
const text = operation.summary?.trim() || operation.description?.trim();
|
|
105
|
-
return text || undefined;
|
|
106
|
-
}
|
|
107
219
|
function authActionBlock(registration) {
|
|
108
220
|
if (registration.authType === "apiKey") {
|
|
109
221
|
return [
|
|
@@ -160,11 +272,30 @@ function updateAuthYml(ctx, filePath, registrations) {
|
|
|
160
272
|
ctx.write(filePath, Buffer.from(updated, "utf8"));
|
|
161
273
|
}
|
|
162
274
|
function openApiParseOptions() {
|
|
163
|
-
|
|
164
|
-
|
|
275
|
+
return {
|
|
276
|
+
isGptPlugin: true,
|
|
277
|
+
allowAPIKeyAuth: true,
|
|
278
|
+
allowBearerTokenAuth: true,
|
|
279
|
+
allowMultipleParameters: true,
|
|
280
|
+
allowOauth2: true,
|
|
281
|
+
projectType: m365_spec_parser_1.ProjectType.Copilot,
|
|
282
|
+
allowMissingId: true,
|
|
283
|
+
allowSwagger: true,
|
|
284
|
+
allowMethods: ["get", "post", "put", "delete", "patch", "head", "connect", "options", "trace"],
|
|
285
|
+
allowResponseSemantics: true,
|
|
286
|
+
allowConversationStarters: false,
|
|
287
|
+
allowConfirmation: false,
|
|
288
|
+
};
|
|
165
289
|
}
|
|
166
290
|
function teamsAiParseOptions() {
|
|
167
|
-
return
|
|
291
|
+
return {
|
|
292
|
+
allowAPIKeyAuth: true,
|
|
293
|
+
allowBearerTokenAuth: true,
|
|
294
|
+
allowMultipleParameters: true,
|
|
295
|
+
allowOauth2: true,
|
|
296
|
+
projectType: m365_spec_parser_1.ProjectType.TeamsAi,
|
|
297
|
+
allowMethods: ["get", "post", "put", "delete", "patch", "head", "connect", "options", "trace"],
|
|
298
|
+
};
|
|
168
299
|
}
|
|
169
300
|
function languageParam(params) {
|
|
170
301
|
const language = stringParam(params, "language");
|
|
@@ -188,6 +319,384 @@ function teamsAiLanguageFiles(language) {
|
|
|
188
319
|
}
|
|
189
320
|
return { appPath: "src/app.py", handlerPath: "src/handlers.py" };
|
|
190
321
|
}
|
|
322
|
+
function recordProperty(record, key) {
|
|
323
|
+
const value = record[key];
|
|
324
|
+
return isRecord(value) ? value : undefined;
|
|
325
|
+
}
|
|
326
|
+
function stringProperty(record, key) {
|
|
327
|
+
const value = record[key];
|
|
328
|
+
return typeof value === "string" ? value : undefined;
|
|
329
|
+
}
|
|
330
|
+
function stringArrayProperty(record, key) {
|
|
331
|
+
const value = record[key];
|
|
332
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
return value;
|
|
336
|
+
}
|
|
337
|
+
function teamsAiOperationDescription(operation, method, pathUrl) {
|
|
338
|
+
return (stringProperty(operation, "description") ??
|
|
339
|
+
stringProperty(operation, "summary") ??
|
|
340
|
+
`${method.toUpperCase()} ${pathUrl}`);
|
|
341
|
+
}
|
|
342
|
+
function teamsAiOperationPrompt(operation, method, pathUrl) {
|
|
343
|
+
return (stringProperty(operation, "summary") ??
|
|
344
|
+
stringProperty(operation, "description") ??
|
|
345
|
+
`${method.toUpperCase()} ${pathUrl}`);
|
|
346
|
+
}
|
|
347
|
+
function filterJsonSchema(schema) {
|
|
348
|
+
if (!isRecord(schema)) {
|
|
349
|
+
return { type: "object" };
|
|
350
|
+
}
|
|
351
|
+
const filtered = {};
|
|
352
|
+
const type = stringProperty(schema, "type");
|
|
353
|
+
if (type !== undefined) {
|
|
354
|
+
filtered.type = type;
|
|
355
|
+
}
|
|
356
|
+
const description = stringProperty(schema, "description");
|
|
357
|
+
if (description !== undefined) {
|
|
358
|
+
filtered.description = description;
|
|
359
|
+
}
|
|
360
|
+
const required = stringArrayProperty(schema, "required");
|
|
361
|
+
if (required !== undefined) {
|
|
362
|
+
filtered.required = required;
|
|
363
|
+
}
|
|
364
|
+
const properties = recordProperty(schema, "properties");
|
|
365
|
+
if (properties !== undefined) {
|
|
366
|
+
const filteredProperties = {};
|
|
367
|
+
for (const [propertyName, propertySchema] of Object.entries(properties)) {
|
|
368
|
+
filteredProperties[propertyName] = filterJsonSchema(propertySchema);
|
|
369
|
+
}
|
|
370
|
+
filtered.properties = filteredProperties;
|
|
371
|
+
}
|
|
372
|
+
if (schema.items !== undefined) {
|
|
373
|
+
filtered.items = filterJsonSchema(schema.items);
|
|
374
|
+
}
|
|
375
|
+
return Object.keys(filtered).length === 0 ? { type: "object" } : filtered;
|
|
376
|
+
}
|
|
377
|
+
function ensureObjectSection(sections, sectionName) {
|
|
378
|
+
const existing = recordProperty(sections, sectionName);
|
|
379
|
+
if (existing !== undefined) {
|
|
380
|
+
return existing;
|
|
381
|
+
}
|
|
382
|
+
const section = { type: "object", properties: {}, required: [] };
|
|
383
|
+
sections[sectionName] = section;
|
|
384
|
+
return section;
|
|
385
|
+
}
|
|
386
|
+
function addRequiredValue(record, key, value) {
|
|
387
|
+
const required = stringArrayProperty(record, key) ?? [];
|
|
388
|
+
if (!required.includes(value)) {
|
|
389
|
+
required.push(value);
|
|
390
|
+
}
|
|
391
|
+
record[key] = required;
|
|
392
|
+
}
|
|
393
|
+
function teamsAiParametersSchema(operation) {
|
|
394
|
+
const parameterProperties = {};
|
|
395
|
+
const parameters = operation.parameters;
|
|
396
|
+
if (Array.isArray(parameters)) {
|
|
397
|
+
for (const parameter of parameters) {
|
|
398
|
+
if (!isRecord(parameter)) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const name = stringProperty(parameter, "name");
|
|
402
|
+
const location = stringProperty(parameter, "in");
|
|
403
|
+
if (name === undefined || location === undefined) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const section = ensureObjectSection(parameterProperties, location);
|
|
407
|
+
const sectionProperties = recordProperty(section, "properties") ?? {};
|
|
408
|
+
const schema = filterJsonSchema(parameter.schema);
|
|
409
|
+
const description = stringProperty(parameter, "description");
|
|
410
|
+
if (description !== undefined) {
|
|
411
|
+
schema.description = description;
|
|
412
|
+
}
|
|
413
|
+
sectionProperties[name] = schema;
|
|
414
|
+
section.properties = sectionProperties;
|
|
415
|
+
if (parameter.required === true) {
|
|
416
|
+
addRequiredValue(section, "required", name);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const requestBody = recordProperty(operation, "requestBody");
|
|
421
|
+
const content = requestBody === undefined ? undefined : recordProperty(requestBody, "content");
|
|
422
|
+
const jsonMedia = content === undefined ? undefined : recordProperty(content, "application/json");
|
|
423
|
+
if (jsonMedia?.schema !== undefined) {
|
|
424
|
+
const bodySchema = filterJsonSchema(jsonMedia.schema);
|
|
425
|
+
const description = requestBody === undefined ? undefined : stringProperty(requestBody, "description");
|
|
426
|
+
if (description !== undefined) {
|
|
427
|
+
bodySchema.description = description;
|
|
428
|
+
}
|
|
429
|
+
parameterProperties.body = bodySchema;
|
|
430
|
+
}
|
|
431
|
+
const root = {
|
|
432
|
+
type: "object",
|
|
433
|
+
properties: parameterProperties,
|
|
434
|
+
required: [],
|
|
435
|
+
};
|
|
436
|
+
for (const [sectionName, section] of Object.entries(parameterProperties)) {
|
|
437
|
+
if (isRecord(section) && stringArrayProperty(section, "required")?.length) {
|
|
438
|
+
addRequiredValue(root, "required", sectionName);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (requestBody?.required === true) {
|
|
442
|
+
addRequiredValue(root, "required", "body");
|
|
443
|
+
}
|
|
444
|
+
return root;
|
|
445
|
+
}
|
|
446
|
+
function teamsAiSpecOperations(spec) {
|
|
447
|
+
if (!isRecord(spec) || !isRecord(spec.paths)) {
|
|
448
|
+
return [];
|
|
449
|
+
}
|
|
450
|
+
const operations = [];
|
|
451
|
+
for (const [pathUrl, pathItem] of Object.entries(spec.paths)) {
|
|
452
|
+
if (!isRecord(pathItem)) {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
for (const method of TEAMS_AI_OPERATION_METHODS) {
|
|
456
|
+
const operation = pathItem[method];
|
|
457
|
+
if (!isRecord(operation)) {
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
const operationId = stringProperty(operation, "operationId");
|
|
461
|
+
if (operationId === undefined) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
operations.push({
|
|
465
|
+
pathUrl,
|
|
466
|
+
method,
|
|
467
|
+
operationId,
|
|
468
|
+
description: teamsAiOperationDescription(operation, method, pathUrl),
|
|
469
|
+
prompt: teamsAiOperationPrompt(operation, method, pathUrl),
|
|
470
|
+
parametersSchema: teamsAiParametersSchema(operation),
|
|
471
|
+
auth: Array.isArray(operation.security) && operation.security.length > 0,
|
|
472
|
+
source: operation,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return operations;
|
|
477
|
+
}
|
|
478
|
+
function safeFileStem(value) {
|
|
479
|
+
return value.replace(/[^a-zA-Z0-9]/g, "_");
|
|
480
|
+
}
|
|
481
|
+
function teamsAiPromptText(spec) {
|
|
482
|
+
const description = isRecord(spec) ? recordProperty(spec, "info")?.description : undefined;
|
|
483
|
+
return `The following is a conversation with an AI assistant.\nThe assistant can help to call APIs for the open api spec file${typeof description === "string" ? ". " + description : "."}\nIf the API doesn't require parameters, invoke it with default JSON object { "path": null, "body": null, "query": null }.\n\n`;
|
|
484
|
+
}
|
|
485
|
+
function teamsAiFunctionDefinitionCode(operationId) {
|
|
486
|
+
return `.function(
|
|
487
|
+
functionDefs.${operationId}.name,
|
|
488
|
+
functionDefs.${operationId}.description,
|
|
489
|
+
functionDefs.${operationId}.parameters,
|
|
490
|
+
async (parameter) => {
|
|
491
|
+
const result = await functionHandlers.${operationId}Handler(parameter);
|
|
492
|
+
if(result) {
|
|
493
|
+
await send(result);
|
|
494
|
+
return "result showed";
|
|
495
|
+
} else {
|
|
496
|
+
return "no result";
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
)`;
|
|
500
|
+
}
|
|
501
|
+
function teamsAiFunctionHandlerCode(operation, language) {
|
|
502
|
+
const exportPrefix = language === constants_1.ProgrammingLanguage.TS ? "export " : "";
|
|
503
|
+
const parameterName = language === constants_1.ProgrammingLanguage.TS ? "parameter: any" : "parameters";
|
|
504
|
+
const parameterVariable = language === constants_1.ProgrammingLanguage.TS ? "parameter" : "parameters";
|
|
505
|
+
const authConfig = operation.auth ? "addAuthConfig(client);" : "";
|
|
506
|
+
const exportSuffix = language === constants_1.ProgrammingLanguage.JS
|
|
507
|
+
? `\nmodule.exports = { ${operation.operationId}Handler };`
|
|
508
|
+
: "";
|
|
509
|
+
return `${exportPrefix}const ${operation.operationId}Handler = async (
|
|
510
|
+
${parameterName}
|
|
511
|
+
) => {
|
|
512
|
+
const client = await api.getClient();
|
|
513
|
+
${authConfig}
|
|
514
|
+
const apiPath = client.paths["${operation.pathUrl}"];
|
|
515
|
+
if (apiPath && apiPath.${operation.method}) {
|
|
516
|
+
const result = await apiPath.${operation.method}(${parameterVariable}.path, ${parameterVariable}.body, {
|
|
517
|
+
params: ${parameterVariable}.query,
|
|
518
|
+
});
|
|
519
|
+
if (!result || !result.data) {
|
|
520
|
+
throw new Error("Get empty result from api call.");
|
|
521
|
+
}
|
|
522
|
+
const cardName = "${operation.operationId}".replace(/[^a-zA-Z0-9]/g, "_");
|
|
523
|
+
const cardTemplatePath = path.join(__dirname, "../adaptiveCards", cardName + ".json");
|
|
524
|
+
if (await fs.exists(cardTemplatePath)){
|
|
525
|
+
const card = generateAdaptiveCard(cardTemplatePath, result);
|
|
526
|
+
return card;
|
|
527
|
+
} else {
|
|
528
|
+
return JSON.stringify(result.data);
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
return "";
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
};${exportSuffix}`;
|
|
535
|
+
}
|
|
536
|
+
function pythonTeamsAiFunctionDefinitionCode(operationId) {
|
|
537
|
+
return `.with_function(
|
|
538
|
+
Function(
|
|
539
|
+
name=function_defs["${operationId}"]["name"],
|
|
540
|
+
description=function_defs["${operationId}"]["description"],
|
|
541
|
+
parameter_schema=function_defs["${operationId}"]["parameters"],
|
|
542
|
+
handler=make_handler(${operationId}, ctx)
|
|
543
|
+
)
|
|
544
|
+
)`;
|
|
545
|
+
}
|
|
546
|
+
function pythonTeamsAiFunctionHandlerCode(operation) {
|
|
547
|
+
return `async def ${operation.operationId}(
|
|
548
|
+
parameters,
|
|
549
|
+
):
|
|
550
|
+
path = getattr(parameters, "path", {})
|
|
551
|
+
body = getattr(parameters, "body", None)
|
|
552
|
+
query = getattr(parameters, "query", {}) or {}
|
|
553
|
+
resp = client.${operation.operationId}(**path, json=body, _headers={}, _params=query, _cookies={})
|
|
554
|
+
|
|
555
|
+
if resp.status_code != 200:
|
|
556
|
+
return resp.reason
|
|
557
|
+
else:
|
|
558
|
+
card_template_path = os.path.join(current_dir, 'adaptiveCards/${operation.operationId}.json')
|
|
559
|
+
if not os.path.exists(card_template_path):
|
|
560
|
+
json_resoponse_str = resp.text
|
|
561
|
+
return json_resoponse_str
|
|
562
|
+
else:
|
|
563
|
+
with open(card_template_path) as card_template_file:
|
|
564
|
+
adaptive_card_template = card_template_file.read()
|
|
565
|
+
|
|
566
|
+
renderer = AdaptiveCardRenderer(adaptive_card_template)
|
|
567
|
+
|
|
568
|
+
json_resoponse_str = resp.text
|
|
569
|
+
rendered_card_str = renderer.render(json_resoponse_str)
|
|
570
|
+
rendered_card_json = json.loads(rendered_card_str)
|
|
571
|
+
return AdaptiveCard.model_validate(rendered_card_json)
|
|
572
|
+
`;
|
|
573
|
+
}
|
|
574
|
+
function teamsAiAdaptiveCard(operation) {
|
|
575
|
+
return {
|
|
576
|
+
type: "AdaptiveCard",
|
|
577
|
+
version: "1.5",
|
|
578
|
+
body: [
|
|
579
|
+
{ type: "TextBlock", text: operation.description, wrap: true },
|
|
580
|
+
{ type: "TextBlock", text: "${JSON.stringify($root)}", wrap: true },
|
|
581
|
+
],
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
function teamsAiAdaptiveCardWithMockData(operation) {
|
|
585
|
+
try {
|
|
586
|
+
const [card, jsonPath, jsonData] = m365_spec_parser_1.AdaptiveCardGenerator.generateAdaptiveCard(operation.source, true, 5);
|
|
587
|
+
const body = isRecord(card) ? card.body : undefined;
|
|
588
|
+
if (jsonPath !== "$" && Array.isArray(body) && isRecord(body[0])) {
|
|
589
|
+
body[0].$data = `\${${jsonPath}}`;
|
|
590
|
+
}
|
|
591
|
+
return { card, data: jsonData };
|
|
592
|
+
}
|
|
593
|
+
catch {
|
|
594
|
+
return { card: teamsAiAdaptiveCard(operation), data: {} };
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
async function updatePromptSuggestions(destinationPath, operations) {
|
|
598
|
+
const manifestPath = path.join(destinationPath, teamsfx_api_1.AppPackageFolderName, teamsfx_api_1.ManifestTemplateFileName);
|
|
599
|
+
let manifest;
|
|
600
|
+
try {
|
|
601
|
+
const parsed = parseJsonObject(await fs.readFile(manifestPath, "utf8"), MANIFEST_PATH, "TeamsAiManifest");
|
|
602
|
+
if (parsed.isErr()) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
manifest = parsed.value;
|
|
606
|
+
}
|
|
607
|
+
catch {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const bots = manifest.bots;
|
|
611
|
+
if (!Array.isArray(bots) || !isRecord(bots[0])) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
bots[0].commandLists = [
|
|
615
|
+
{
|
|
616
|
+
scopes: ["personal"],
|
|
617
|
+
commands: operations.slice(0, 10).map((operation) => ({
|
|
618
|
+
title: operation.prompt.slice(0, 32),
|
|
619
|
+
description: operation.prompt.slice(0, 128),
|
|
620
|
+
})),
|
|
621
|
+
},
|
|
622
|
+
];
|
|
623
|
+
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 4) + "\n");
|
|
624
|
+
}
|
|
625
|
+
async function updateTypescriptJavascriptTeamsAiCustomApi(spec, language, destinationPath, openapiSpecFileName) {
|
|
626
|
+
const operations = teamsAiSpecOperations(spec);
|
|
627
|
+
if (operations.length === 0) {
|
|
628
|
+
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiOperationsMissing", "Failed to find generated OpenAPI operations for the Teams AI custom API template."));
|
|
629
|
+
}
|
|
630
|
+
const appFolder = path.join(destinationPath, "src", "app");
|
|
631
|
+
const adaptiveCardsFolder = path.join(destinationPath, "src", "adaptiveCards");
|
|
632
|
+
await fs.ensureDir(appFolder);
|
|
633
|
+
await fs.ensureDir(adaptiveCardsFolder);
|
|
634
|
+
await fs.writeFile(path.join(appFolder, "instructions.txt"), teamsAiPromptText(spec));
|
|
635
|
+
const actions = {};
|
|
636
|
+
for (const operation of operations) {
|
|
637
|
+
actions[operation.operationId] = {
|
|
638
|
+
name: operation.operationId,
|
|
639
|
+
description: operation.description,
|
|
640
|
+
parameters: operation.parametersSchema,
|
|
641
|
+
};
|
|
642
|
+
const cardName = safeFileStem(operation.operationId);
|
|
643
|
+
const adaptiveCard = teamsAiAdaptiveCardWithMockData(operation);
|
|
644
|
+
await fs.writeFile(path.join(adaptiveCardsFolder, `${cardName}.json`), JSON.stringify(adaptiveCard.card, null, 2));
|
|
645
|
+
await fs.writeFile(path.join(adaptiveCardsFolder, `${cardName}.data.json`), JSON.stringify(adaptiveCard.data, null, 2));
|
|
646
|
+
}
|
|
647
|
+
await fs.writeFile(path.join(appFolder, "functions.json"), JSON.stringify(actions, null, 2));
|
|
648
|
+
const appFilePath = path.join(appFolder, language === constants_1.ProgrammingLanguage.JS ? "app.js" : "app.ts");
|
|
649
|
+
const handlerFilePath = path.join(appFolder, language === constants_1.ProgrammingLanguage.JS ? "handlers.js" : "handlers.ts");
|
|
650
|
+
const appFileContent = await fs.readFile(appFilePath, "utf8");
|
|
651
|
+
await fs.writeFile(appFilePath, appFileContent.replace("// Replace with function definition code", `${operations.map((operation) => teamsAiFunctionDefinitionCode(operation.operationId)).join("\n")};`));
|
|
652
|
+
const handlerFileContent = await fs.readFile(handlerFilePath, "utf8");
|
|
653
|
+
await fs.writeFile(handlerFilePath, handlerFileContent
|
|
654
|
+
.replace("{{OPENAPI_SPEC_PATH}}", openapiSpecFileName)
|
|
655
|
+
.replace("// Replace with function handler code", operations.map((operation) => teamsAiFunctionHandlerCode(operation, language)).join("\n\n")));
|
|
656
|
+
await updatePromptSuggestions(destinationPath, operations);
|
|
657
|
+
return (0, neverthrow_1.ok)(undefined);
|
|
658
|
+
}
|
|
659
|
+
async function updatePythonTeamsAiCustomApi(spec, destinationPath, openapiSpecFileName) {
|
|
660
|
+
const operations = teamsAiSpecOperations(spec);
|
|
661
|
+
if (operations.length === 0) {
|
|
662
|
+
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiPythonOperationsMissing", "Failed to find generated OpenAPI operations for the Python custom API template."));
|
|
663
|
+
}
|
|
664
|
+
const srcFolder = path.join(destinationPath, "src");
|
|
665
|
+
const adaptiveCardsFolder = path.join(srcFolder, "adaptiveCards");
|
|
666
|
+
await fs.ensureDir(adaptiveCardsFolder);
|
|
667
|
+
await fs.writeFile(path.join(srcFolder, "instructions.txt"), teamsAiPromptText(spec));
|
|
668
|
+
const functions = {};
|
|
669
|
+
const functionDefinitions = [];
|
|
670
|
+
const functionHandlers = [];
|
|
671
|
+
const operationIds = [];
|
|
672
|
+
for (const operation of operations) {
|
|
673
|
+
functions[operation.operationId] = {
|
|
674
|
+
name: operation.operationId,
|
|
675
|
+
description: operation.description,
|
|
676
|
+
parameters: operation.parametersSchema,
|
|
677
|
+
};
|
|
678
|
+
functionDefinitions.push(pythonTeamsAiFunctionDefinitionCode(operation.operationId));
|
|
679
|
+
functionHandlers.push(pythonTeamsAiFunctionHandlerCode(operation));
|
|
680
|
+
operationIds.push(operation.operationId);
|
|
681
|
+
const cardName = safeFileStem(operation.operationId);
|
|
682
|
+
const adaptiveCard = teamsAiAdaptiveCardWithMockData(operation);
|
|
683
|
+
await fs.writeFile(path.join(adaptiveCardsFolder, `${cardName}.json`), JSON.stringify(adaptiveCard.card, null, 2));
|
|
684
|
+
await fs.writeFile(path.join(adaptiveCardsFolder, `${cardName}.data.json`), JSON.stringify(adaptiveCard.data, null, 2));
|
|
685
|
+
}
|
|
686
|
+
await fs.writeFile(path.join(srcFolder, "functions.json"), JSON.stringify(functions, null, 2));
|
|
687
|
+
const appPath = path.join(srcFolder, "app.py");
|
|
688
|
+
const appContent = await fs.readFile(appPath, "utf8");
|
|
689
|
+
await fs.writeFile(appPath, appContent
|
|
690
|
+
.replace("// Replace with function definition code", `prompt${functionDefinitions.join("")}`)
|
|
691
|
+
.replace("//Replace with functions to be imported", operationIds.join(", ")));
|
|
692
|
+
const handlerPath = path.join(srcFolder, "handlers.py");
|
|
693
|
+
const handlerContent = await fs.readFile(handlerPath, "utf8");
|
|
694
|
+
await fs.writeFile(handlerPath, handlerContent
|
|
695
|
+
.replace("{{OPENAPI_SPEC_PATH}}", openapiSpecFileName)
|
|
696
|
+
.replace("// Replace with function handler code", functionHandlers.join("\n\n")));
|
|
697
|
+
await updatePromptSuggestions(destinationPath, operations);
|
|
698
|
+
return (0, neverthrow_1.ok)(undefined);
|
|
699
|
+
}
|
|
191
700
|
async function writeTempFile(root, relativePath, data) {
|
|
192
701
|
const destination = path.join(root, relativePath);
|
|
193
702
|
await fs.ensureDir(path.dirname(destination));
|
|
@@ -259,48 +768,32 @@ exports.openApiGeneratePluginFiles = {
|
|
|
259
768
|
if (agent.isErr()) {
|
|
260
769
|
return (0, neverthrow_1.err)(agent.error);
|
|
261
770
|
}
|
|
262
|
-
|
|
771
|
+
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "m365atk-openapi-"));
|
|
772
|
+
try {
|
|
263
773
|
const temp = await writeTempBaseFiles(tempRoot, manifest.value, agent.value);
|
|
264
774
|
const parser = new m365_spec_parser_1.SpecParser(apiSpecLocation, openApiParseOptions());
|
|
265
|
-
const listed = await parser.list();
|
|
266
|
-
const selectedOperations = listed.APIs.filter((operation) => apiOperations.includes(operation.api));
|
|
267
775
|
await parser.generateForCopilot(temp.manifestPath, apiOperations, temp.apiSpecPath, temp.pluginPath);
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
agentManifest = teamsfx_api_1.DeclarativeAgentManifestWrapper.fromJSON(await fs.readFile(agentManifestPath, "utf8"));
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
return (0, neverthrow_1.err)(systemError("JSONSyntaxError", `The declarative agent manifest is not valid JSON: ${errorMessage(error)}`));
|
|
275
|
-
}
|
|
276
|
-
agentManifest.upsertAction(DEFAULT_ACTION_ID, teamsfx_api_1.DefaultPluginManifestFileName);
|
|
277
|
-
const remainingStarterSlots = Math.max(0, 6 - agentManifest.conversationStarters.length);
|
|
278
|
-
const seenStarterTexts = new Set(agentManifest.conversationStarters.map((starter) => starter.text));
|
|
279
|
-
const starterTexts = selectedOperations
|
|
280
|
-
.map(conversationStarterText)
|
|
281
|
-
.filter((text) => text !== undefined)
|
|
282
|
-
.filter((text) => {
|
|
283
|
-
if (seenStarterTexts.has(text)) {
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
seenStarterTexts.add(text);
|
|
287
|
-
return true;
|
|
288
|
-
})
|
|
289
|
-
.slice(0, remainingStarterSlots);
|
|
290
|
-
for (const text of starterTexts) {
|
|
291
|
-
agentManifest.addConversationStarter(text);
|
|
776
|
+
const updatedAgent = await addActionAndConversationStarters((await fs.readFile(path.join(tempRoot, AGENT_PATH))).toString("utf8"), (await fs.readFile(temp.pluginPath)).toString("utf8"), temp.apiSpecPath);
|
|
777
|
+
if (updatedAgent.isErr()) {
|
|
778
|
+
return (0, neverthrow_1.err)(updatedAgent.error);
|
|
292
779
|
}
|
|
293
|
-
await
|
|
294
|
-
const registrations = selectedAuthRegistrations(selectedOperations);
|
|
780
|
+
const registrations = await selectedAuthRegistrations(apiSpecLocation, apiOperations);
|
|
295
781
|
if (registrations.isErr()) {
|
|
296
782
|
return (0, neverthrow_1.err)(registrations.error);
|
|
297
783
|
}
|
|
784
|
+
await fs.writeFile(path.join(tempRoot, AGENT_PATH), updatedAgent.value);
|
|
298
785
|
await writeTempTreeToContext(tempRoot, ctx);
|
|
299
786
|
ctx.write(ORIGINAL_API_SPEC_PATH, await readOriginalOpenApiSpec(apiSpecLocation));
|
|
300
787
|
updateAuthYml(ctx, M365_AGENTS_YML, registrations.value);
|
|
301
788
|
updateAuthYml(ctx, M365_AGENTS_LOCAL_YML, registrations.value);
|
|
302
789
|
return (0, neverthrow_1.ok)(undefined);
|
|
303
|
-
}
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
return (0, neverthrow_1.err)(systemError("OpenApiGenerateFailed", `Failed to generate OpenAPI plugin files: ${errorMessage(error)}`));
|
|
793
|
+
}
|
|
794
|
+
finally {
|
|
795
|
+
await fs.remove(tempRoot);
|
|
796
|
+
}
|
|
304
797
|
},
|
|
305
798
|
};
|
|
306
799
|
exports.openApiGenerateTeamsAiCustomApiFiles = {
|
|
@@ -323,7 +816,8 @@ exports.openApiGenerateTeamsAiCustomApiFiles = {
|
|
|
323
816
|
if (apiSpecLocation === undefined || apiOperations === undefined || language === undefined) {
|
|
324
817
|
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiParams", "resolved parameters are not all valid"));
|
|
325
818
|
}
|
|
326
|
-
|
|
819
|
+
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "m365atk-openapi-teams-ai-"));
|
|
820
|
+
try {
|
|
327
821
|
const languageFiles = teamsAiLanguageFiles(language);
|
|
328
822
|
const baseFiles = await writeTeamsAiBaseFiles(ctx, tempRoot, languageFiles);
|
|
329
823
|
if (baseFiles.isErr()) {
|
|
@@ -350,13 +844,27 @@ exports.openApiGenerateTeamsAiCustomApiFiles = {
|
|
|
350
844
|
if (filteredSpec === undefined) {
|
|
351
845
|
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiFilteredSpecMissing", "Failed to generate the filtered OpenAPI document for the selected operations."));
|
|
352
846
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
847
|
+
if (language === constants_1.ProgrammingLanguage.PY) {
|
|
848
|
+
const updatePythonResult = await updatePythonTeamsAiCustomApi(filteredSpec, tempRoot, openapiSpecFileName);
|
|
849
|
+
if (updatePythonResult.isErr()) {
|
|
850
|
+
return (0, neverthrow_1.err)(updatePythonResult.error);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
const updateResult = await updateTypescriptJavascriptTeamsAiCustomApi(filteredSpec, language, tempRoot, openapiSpecFileName);
|
|
855
|
+
if (updateResult.isErr()) {
|
|
856
|
+
return (0, neverthrow_1.err)(updateResult.error);
|
|
857
|
+
}
|
|
356
858
|
}
|
|
357
859
|
await writeTempTreeToContext(tempRoot, ctx);
|
|
358
860
|
return (0, neverthrow_1.ok)(undefined);
|
|
359
|
-
}
|
|
861
|
+
}
|
|
862
|
+
catch (error) {
|
|
863
|
+
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiGenerateFailed", `Failed to generate Teams AI custom API files: ${errorMessage(error)}`));
|
|
864
|
+
}
|
|
865
|
+
finally {
|
|
866
|
+
await fs.remove(tempRoot);
|
|
867
|
+
}
|
|
360
868
|
},
|
|
361
869
|
};
|
|
362
870
|
//# sourceMappingURL=openApi.js.map
|