@microsoft/teamsfx-core 3.0.14 → 3.0.15-alpha.3dde8a4002.0
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/mcpToolFetcher.d.ts +31 -0
- package/build/common/mcpToolFetcher.d.ts.map +1 -0
- package/build/common/mcpToolFetcher.js +182 -0
- package/build/common/mcpToolFetcher.js.map +1 -0
- package/build/common/odrProvider.d.ts +43 -0
- package/build/common/odrProvider.d.ts.map +1 -0
- package/build/common/odrProvider.js +154 -0
- package/build/common/odrProvider.js.map +1 -0
- package/build/common/openApiParserOptions.d.ts +3 -0
- package/build/common/openApiParserOptions.d.ts.map +1 -0
- package/build/common/openApiParserOptions.js +61 -0
- package/build/common/openApiParserOptions.js.map +1 -0
- package/build/common/secretmasker/dict.d.ts.map +1 -1
- package/build/common/secretmasker/dict.js +5 -2
- 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/common/wrappedAxiosClient.d.ts +1 -1
- 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 +3 -0
- package/build/component/driver/deploy/azure/impl/AzureZipDeployImpl.d.ts.map +1 -1
- package/build/component/driver/deploy/azure/impl/AzureZipDeployImpl.js +38 -3
- 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.map +1 -1
- 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 +1 -0
- package/build/component/generator/officeAddin/generator.d.ts.map +1 -1
- package/build/component/generator/officeAddin/generator.js +109 -2
- package/build/component/generator/officeAddin/generator.js.map +1 -1
- package/build/component/generator/openApiSpec/helper.d.ts +2 -3
- package/build/component/generator/openApiSpec/helper.d.ts.map +1 -1
- package/build/component/generator/openApiSpec/helper.js +6 -56
- package/build/component/generator/openApiSpec/helper.js.map +1 -1
- package/build/component/generator/templateHelper.d.ts +10 -2
- package/build/component/generator/templateHelper.d.ts.map +1 -1
- package/build/component/generator/templateHelper.js +16 -3
- package/build/component/generator/templateHelper.js.map +1 -1
- package/build/component/generator/templates/templateNames.d.ts +2 -0
- package/build/component/generator/templates/templateNames.d.ts.map +1 -1
- package/build/component/generator/templates/templateNames.js +2 -0
- 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 +6 -0
- package/build/component/generator/utils.js.map +1 -1
- package/build/component/generator/v4TemplateBridge.d.ts +4 -1
- package/build/component/generator/v4TemplateBridge.d.ts.map +1 -1
- package/build/component/generator/v4TemplateBridge.js +11 -3
- 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.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 +1 -72
- package/build/component/utils/mcpToolFetcher.d.ts.map +1 -1
- package/build/component/utils/mcpToolFetcher.js +1 -227
- package/build/component/utils/mcpToolFetcher.js.map +1 -1
- package/build/component/utils/odrProvider.d.ts +1 -55
- package/build/component/utils/odrProvider.d.ts.map +1 -1
- package/build/component/utils/odrProvider.js +1 -101
- 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 +41 -0
- package/build/core/FxCore.declarativeAgent.js.map +1 -1
- package/build/core/FxCore.js +3 -5
- package/build/core/FxCore.js.map +1 -1
- package/build/core/createFrontDoorAdapters.d.ts +1 -25
- package/build/core/createFrontDoorAdapters.d.ts.map +1 -1
- package/build/core/createFrontDoorAdapters.js +4 -155
- package/build/core/createFrontDoorAdapters.js.map +1 -1
- package/build/core/createProjectFrontDoor.d.ts +10 -12
- package/build/core/createProjectFrontDoor.d.ts.map +1 -1
- package/build/core/createProjectFrontDoor.js +141 -106
- package/build/core/createProjectFrontDoor.js.map +1 -1
- package/build/core/modifyProjectFrontDoor.d.ts +0 -1
- package/build/core/modifyProjectFrontDoor.d.ts.map +1 -1
- package/build/core/modifyProjectFrontDoor.js +0 -2
- package/build/core/modifyProjectFrontDoor.js.map +1 -1
- package/build/question/inputs/AddKnowledgeInputs.d.ts.map +1 -1
- package/build/question/inputs/CreateProjectInputs.d.ts +2 -0
- 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 +7 -0
- package/build/question/options/CreateProjectOptions.js.map +1 -1
- package/build/question/other.d.ts.map +1 -1
- package/build/question/other.js +2 -1
- package/build/question/other.js.map +1 -1
- package/build/question/questionNames.d.ts +2 -0
- package/build/question/questionNames.d.ts.map +1 -1
- package/build/question/questionNames.js +2 -0
- package/build/question/questionNames.js.map +1 -1
- package/build/question/scaffold/constructNode.d.ts +3 -1
- package/build/question/scaffold/constructNode.d.ts.map +1 -1
- package/build/question/scaffold/constructNode.js +50 -0
- package/build/question/scaffold/constructNode.js.map +1 -1
- package/build/question/scaffold/vsc/CapabilityOptions.d.ts +2 -0
- package/build/question/scaffold/vsc/CapabilityOptions.d.ts.map +1 -1
- package/build/question/scaffold/vsc/CapabilityOptions.js +16 -0
- 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 +0 -7
- package/build/question/scaffold/vsc/teamsProjectTypeNode.js.map +1 -1
- package/build/v4/buildTarget/parseSelector.d.ts +6 -2
- package/build/v4/buildTarget/parseSelector.d.ts.map +1 -1
- package/build/v4/buildTarget/parseSelector.js +58 -45
- package/build/v4/buildTarget/parseSelector.js.map +1 -1
- package/build/v4/buildTarget/resolveBuildTarget.d.ts +21 -7
- package/build/v4/buildTarget/resolveBuildTarget.d.ts.map +1 -1
- package/build/v4/buildTarget/resolveBuildTarget.js +97 -52
- package/build/v4/buildTarget/resolveBuildTarget.js.map +1 -1
- package/build/v4/collectInputs/collectInputs.d.ts +50 -9
- package/build/v4/collectInputs/collectInputs.d.ts.map +1 -1
- package/build/v4/collectInputs/collectInputs.js +274 -91
- 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 +2 -29
- 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 +2 -30
- package/build/v4/distribution/declarativePackage.js.map +1 -1
- package/build/v4/distribution/questionFragments.d.ts +11 -0
- package/build/v4/distribution/questionFragments.d.ts.map +1 -0
- package/build/v4/distribution/questionFragments.js +130 -0
- package/build/v4/distribution/questionFragments.js.map +1 -0
- package/build/v4/engineVersion.d.ts +7 -0
- package/build/v4/engineVersion.d.ts.map +1 -0
- package/build/v4/engineVersion.js +12 -0
- package/build/v4/engineVersion.js.map +1 -0
- package/build/v4/expression/evaluateExpression.d.ts +13 -0
- package/build/v4/expression/evaluateExpression.d.ts.map +1 -1
- package/build/v4/expression/evaluateExpression.js +57 -0
- package/build/v4/expression/evaluateExpression.js.map +1 -1
- package/build/v4/index.d.ts +7 -0
- package/build/v4/index.d.ts.map +1 -1
- package/build/v4/index.js +7 -0
- package/build/v4/index.js.map +1 -1
- package/build/v4/inspection/scaffoldCatalog.d.ts +28 -0
- package/build/v4/inspection/scaffoldCatalog.d.ts.map +1 -0
- package/build/v4/inspection/scaffoldCatalog.js +66 -0
- package/build/v4/inspection/scaffoldCatalog.js.map +1 -0
- package/build/v4/inspection/scaffoldMetadataSource.d.ts +6 -0
- package/build/v4/inspection/scaffoldMetadataSource.d.ts.map +1 -0
- package/build/v4/inspection/scaffoldMetadataSource.js +78 -0
- package/build/v4/inspection/scaffoldMetadataSource.js.map +1 -0
- package/build/v4/mcp/mcpAuthAction.d.ts +23 -0
- package/build/v4/mcp/mcpAuthAction.d.ts.map +1 -0
- package/build/v4/mcp/mcpAuthAction.js +151 -0
- package/build/v4/mcp/mcpAuthAction.js.map +1 -0
- package/build/v4/mcp/mcpAuthScaffold.d.ts +28 -0
- package/build/v4/mcp/mcpAuthScaffold.d.ts.map +1 -0
- package/build/v4/mcp/mcpAuthScaffold.js +124 -0
- package/build/v4/mcp/mcpAuthScaffold.js.map +1 -0
- 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 +17 -4
- package/build/v4/pipeline/runScaffoldPipeline.d.ts.map +1 -1
- package/build/v4/pipeline/runScaffoldPipeline.js +60 -9
- package/build/v4/pipeline/runScaffoldPipeline.js.map +1 -1
- package/build/v4/providers/createOptionsProviders.d.ts +11 -0
- package/build/v4/providers/createOptionsProviders.d.ts.map +1 -0
- package/build/v4/providers/createOptionsProviders.js +268 -0
- package/build/v4/providers/createOptionsProviders.js.map +1 -0
- package/build/v4/renderContext/buildRenderContext.d.ts.map +1 -1
- package/build/v4/renderContext/buildRenderContext.js +1 -2
- package/build/v4/renderContext/buildRenderContext.js.map +1 -1
- package/build/v4/runtime/generalSensitivityLabel.d.ts +5 -0
- package/build/v4/runtime/generalSensitivityLabel.d.ts.map +1 -0
- package/build/v4/runtime/generalSensitivityLabel.js +36 -0
- package/build/v4/runtime/generalSensitivityLabel.js.map +1 -0
- package/build/v4/runtime/inMemoryRuntime.d.ts +2 -1
- package/build/v4/runtime/inMemoryRuntime.d.ts.map +1 -1
- package/build/v4/runtime/inMemoryRuntime.js +2 -2
- 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 +64 -8
- package/build/v4/runtime/packageParse.js.map +1 -1
- package/build/v4/runtime/realRuntime.d.ts +2 -1
- package/build/v4/runtime/realRuntime.d.ts.map +1 -1
- package/build/v4/runtime/realRuntime.js +2 -2
- 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 +13 -4
- package/build/v4/runtime/renderMustache.js.map +1 -1
- package/build/v4/runtime/runtimeRegistry.d.ts +8 -3
- package/build/v4/runtime/runtimeRegistry.d.ts.map +1 -1
- package/build/v4/runtime/runtimeRegistry.js +122 -17
- package/build/v4/runtime/runtimeRegistry.js.map +1 -1
- package/build/v4/runtime/scaffold.d.ts +1 -0
- package/build/v4/runtime/scaffold.d.ts.map +1 -1
- package/build/v4/runtime/scaffold.js +1 -20
- 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 +3 -111
- package/build/v4/runtime/steps/daAction.js.map +1 -1
- package/build/v4/runtime/steps/daSensitivity.d.ts +14 -0
- package/build/v4/runtime/steps/daSensitivity.d.ts.map +1 -0
- package/build/v4/runtime/steps/daSensitivity.js +50 -0
- package/build/v4/runtime/steps/daSensitivity.js.map +1 -0
- package/build/v4/runtime/steps/mcpAuth.d.ts +5 -2
- package/build/v4/runtime/steps/mcpAuth.d.ts.map +1 -1
- package/build/v4/runtime/steps/mcpAuth.js +13 -63
- package/build/v4/runtime/steps/mcpAuth.js.map +1 -1
- package/build/v4/runtime/steps/mcpLocal.d.ts +0 -4
- package/build/v4/runtime/steps/mcpLocal.d.ts.map +1 -1
- package/build/v4/runtime/steps/mcpLocal.js +11 -31
- 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 +14 -32
- 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 +39 -51
- 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 +7 -12
- 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 +47 -555
- package/build/v4/runtime/steps/openApi.js.map +1 -1
- package/build/v4/runtime/steps/openApiCustomApi.d.ts +5 -0
- package/build/v4/runtime/steps/openApiCustomApi.d.ts.map +1 -0
- package/build/v4/runtime/steps/openApiCustomApi.js +385 -0
- package/build/v4/runtime/steps/openApiCustomApi.js.map +1 -0
- package/build/v4/runtime/withTempDirectory.d.ts +10 -0
- package/build/v4/runtime/withTempDirectory.d.ts.map +1 -0
- package/build/v4/runtime/withTempDirectory.js +41 -0
- package/build/v4/runtime/withTempDirectory.js.map +1 -0
- package/build/v4/surface/createFloorTail.d.ts +12 -0
- package/build/v4/surface/createFloorTail.d.ts.map +1 -0
- package/build/v4/surface/createFloorTail.js +138 -0
- package/build/v4/surface/createFloorTail.js.map +1 -0
- package/build/v4/surface/createInputs.d.ts +25 -3
- package/build/v4/surface/createInputs.d.ts.map +1 -1
- package/build/v4/surface/createInputs.js +54 -431
- package/build/v4/surface/createInputs.js.map +1 -1
- package/build/v4/surface/createSelectorWalk.d.ts +8 -3
- package/build/v4/surface/createSelectorWalk.d.ts.map +1 -1
- package/build/v4/surface/createSelectorWalk.js +21 -11
- package/build/v4/surface/createSelectorWalk.js.map +1 -1
- package/build/v4/surface/localizePrompt.d.ts +11 -0
- package/build/v4/surface/localizePrompt.d.ts.map +1 -0
- package/build/v4/surface/localizePrompt.js +32 -0
- package/build/v4/surface/localizePrompt.js.map +1 -0
- package/build/v4/surface/modifySelectorWalk.d.ts.map +1 -1
- package/build/v4/surface/modifySelectorWalk.js +0 -3
- 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 +36 -41
- package/build/v4/surface/uiPromptUI.js.map +1 -1
- package/build/v4/validation/capabilityCatalog.d.ts +8 -0
- package/build/v4/validation/capabilityCatalog.d.ts.map +1 -0
- package/build/v4/validation/capabilityCatalog.js +58 -0
- package/build/v4/validation/capabilityCatalog.js.map +1 -0
- package/build/v4/validation/templateArchiveValidation.d.ts +15 -0
- package/build/v4/validation/templateArchiveValidation.d.ts.map +1 -0
- package/build/v4/validation/templateArchiveValidation.js +297 -0
- package/build/v4/validation/templateArchiveValidation.js.map +1 -0
- package/build/v4/validation/validateTemplatePackage.d.ts +21 -2
- package/build/v4/validation/validateTemplatePackage.d.ts.map +1 -1
- package/build/v4/validation/validateTemplatePackage.js +155 -31
- package/build/v4/validation/validateTemplatePackage.js.map +1 -1
- package/build/v4/validators/createInputValidators.d.ts +7 -0
- package/build/v4/validators/createInputValidators.d.ts.map +1 -0
- package/build/v4/validators/createInputValidators.js +71 -0
- package/build/v4/validators/createInputValidators.js.map +1 -0
- package/package.json +24 -18
- package/resource/package.nls.cs.json +1 -0
- package/resource/package.nls.de.json +55 -54
- package/resource/package.nls.es.json +1 -0
- package/resource/package.nls.fr.json +1 -0
- package/resource/package.nls.it.json +1 -0
- package/resource/package.nls.ja.json +1 -0
- package/resource/package.nls.json +2 -0
- package/resource/package.nls.ko.json +1 -0
- package/resource/package.nls.pl.json +1 -0
- package/resource/package.nls.pt-BR.json +1 -0
- package/resource/package.nls.ru.json +1 -0
- package/resource/package.nls.tr.json +1 -0
- package/resource/package.nls.zh-Hans.json +1 -0
- package/resource/package.nls.zh-Hant.json +1 -0
- package/resource/templates/package.nls.cs.json +9 -2
- package/resource/templates/package.nls.de.json +9 -2
- package/resource/templates/package.nls.es.json +9 -2
- package/resource/templates/package.nls.fr.json +9 -2
- package/resource/templates/package.nls.it.json +9 -2
- package/resource/templates/package.nls.ja.json +9 -2
- package/resource/templates/package.nls.json +16 -3
- package/resource/templates/package.nls.ko.json +9 -2
- package/resource/templates/package.nls.pl.json +9 -2
- package/resource/templates/package.nls.pt-BR.json +9 -2
- package/resource/templates/package.nls.ru.json +9 -2
- package/resource/templates/package.nls.tr.json +9 -2
- package/resource/templates/package.nls.zh-Hans.json +9 -2
- package/resource/templates/package.nls.zh-Hant.json +9 -2
- package/resource/templates/package.nls.zh-cn.json +7 -1
- package/resource/templates/package.nls.zh-tw.json +7 -1
- 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 +16 -2
- package/templates/metadata.zip +0 -0
- package/templates/ui/wizardNode.json +24 -0
- package/templates/v4/create-selector.json +12 -5
- package/templates/v4/floor.json +1 -1
- package/templates/v4/modify-selector.json +1 -6
- package/templates/v4/templates-metadata.zip +0 -0
- package/templates/v4/templates.zip +0 -0
- package/templates/configs/local/typescript/.gitignore +0 -1
- package/templates/configs/playground/typescript/.gitignore +0 -4
|
@@ -8,12 +8,14 @@ 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"));
|
|
12
11
|
const path = tslib_1.__importStar(require("path"));
|
|
13
12
|
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");
|
|
17
19
|
/** Generate API plugin files through spec-parser, then copy artifacts back via `ctx.write`. */
|
|
18
20
|
const SOURCE = "Scaffold";
|
|
19
21
|
exports.STEP_GENERATE_OPENAPI_PLUGIN_FILES = "openapi/generate-plugin-files";
|
|
@@ -26,17 +28,6 @@ const ORIGINAL_API_SPEC_PATH = `${API_SPEC_PATH}.original`;
|
|
|
26
28
|
const DEFAULT_ACTION_ID = "action_1";
|
|
27
29
|
const M365_AGENTS_YML = "m365agents.yml";
|
|
28
30
|
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
|
-
];
|
|
40
31
|
function systemError(name, message) {
|
|
41
32
|
return new teamsfx_api_1.SystemError({ source: SOURCE, name, message });
|
|
42
33
|
}
|
|
@@ -51,9 +42,6 @@ function stringArrayParam(params, key) {
|
|
|
51
42
|
}
|
|
52
43
|
return value;
|
|
53
44
|
}
|
|
54
|
-
function isRecord(value) {
|
|
55
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56
|
-
}
|
|
57
45
|
function readRequired(ctx, filePath) {
|
|
58
46
|
const current = ctx.read(filePath);
|
|
59
47
|
if (current === undefined) {
|
|
@@ -64,107 +52,6 @@ function readRequired(ctx, filePath) {
|
|
|
64
52
|
function errorMessage(error) {
|
|
65
53
|
return error instanceof Error ? error.message : String(error);
|
|
66
54
|
}
|
|
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
|
-
}
|
|
168
55
|
function registrationIdEnvName(authName) {
|
|
169
56
|
return m365_spec_parser_1.Utils.getSafeRegistrationIdEnvName(`${authName}_${m365_spec_parser_1.ConstantString.RegistrationIdPostfix}`);
|
|
170
57
|
}
|
|
@@ -181,14 +68,11 @@ function authType(operation) {
|
|
|
181
68
|
}
|
|
182
69
|
return undefined;
|
|
183
70
|
}
|
|
184
|
-
|
|
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));
|
|
71
|
+
function selectedAuthRegistrations(selectedOperations) {
|
|
188
72
|
const serverUrls = new Set();
|
|
189
73
|
const authNames = new Set();
|
|
190
74
|
const registrations = [];
|
|
191
|
-
for (const operation of
|
|
75
|
+
for (const operation of selectedOperations) {
|
|
192
76
|
const type = authType(operation);
|
|
193
77
|
const authName = operation.auth?.name;
|
|
194
78
|
if (type === undefined || !authName) {
|
|
@@ -216,6 +100,10 @@ async function selectedAuthRegistrations(apiSpecLocation, apiOperations) {
|
|
|
216
100
|
}
|
|
217
101
|
return (0, neverthrow_1.ok)(registrations);
|
|
218
102
|
}
|
|
103
|
+
function conversationStarterText(operation) {
|
|
104
|
+
const text = operation.summary?.trim() || operation.description?.trim();
|
|
105
|
+
return text || undefined;
|
|
106
|
+
}
|
|
219
107
|
function authActionBlock(registration) {
|
|
220
108
|
if (registration.authType === "apiKey") {
|
|
221
109
|
return [
|
|
@@ -272,30 +160,11 @@ function updateAuthYml(ctx, filePath, registrations) {
|
|
|
272
160
|
ctx.write(filePath, Buffer.from(updated, "utf8"));
|
|
273
161
|
}
|
|
274
162
|
function openApiParseOptions() {
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
};
|
|
163
|
+
// Reuse the v3 Copilot parser options (single source of truth) instead of a v4 copy.
|
|
164
|
+
return (0, openApiParserOptions_1.getParserOptions)(m365_spec_parser_1.ProjectType.Copilot, true);
|
|
289
165
|
}
|
|
290
166
|
function teamsAiParseOptions() {
|
|
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
|
-
};
|
|
167
|
+
return (0, openApiParserOptions_1.getParserOptions)(m365_spec_parser_1.ProjectType.TeamsAi);
|
|
299
168
|
}
|
|
300
169
|
function languageParam(params) {
|
|
301
170
|
const language = stringParam(params, "language");
|
|
@@ -319,384 +188,6 @@ function teamsAiLanguageFiles(language) {
|
|
|
319
188
|
}
|
|
320
189
|
return { appPath: "src/app.py", handlerPath: "src/handlers.py" };
|
|
321
190
|
}
|
|
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
|
-
}
|
|
700
191
|
async function writeTempFile(root, relativePath, data) {
|
|
701
192
|
const destination = path.join(root, relativePath);
|
|
702
193
|
await fs.ensureDir(path.dirname(destination));
|
|
@@ -768,32 +259,48 @@ exports.openApiGeneratePluginFiles = {
|
|
|
768
259
|
if (agent.isErr()) {
|
|
769
260
|
return (0, neverthrow_1.err)(agent.error);
|
|
770
261
|
}
|
|
771
|
-
|
|
772
|
-
try {
|
|
262
|
+
return (0, withTempDirectory_1.withTempDirectory)("m365atk-openapi-", (phase, error) => systemError("OpenApiGenerateFailed", `Failed to generate OpenAPI plugin files during temporary file ${phase}: ${errorMessage(error)}`), async (tempRoot) => {
|
|
773
263
|
const temp = await writeTempBaseFiles(tempRoot, manifest.value, agent.value);
|
|
774
264
|
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));
|
|
775
267
|
await parser.generateForCopilot(temp.manifestPath, apiOperations, temp.apiSpecPath, temp.pluginPath);
|
|
776
|
-
const
|
|
777
|
-
|
|
778
|
-
|
|
268
|
+
const agentManifestPath = path.join(tempRoot, AGENT_PATH);
|
|
269
|
+
let agentManifest;
|
|
270
|
+
try {
|
|
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);
|
|
779
292
|
}
|
|
780
|
-
|
|
293
|
+
await fs.writeFile(agentManifestPath, agentManifest.toJSON(), "utf8");
|
|
294
|
+
const registrations = selectedAuthRegistrations(selectedOperations);
|
|
781
295
|
if (registrations.isErr()) {
|
|
782
296
|
return (0, neverthrow_1.err)(registrations.error);
|
|
783
297
|
}
|
|
784
|
-
await fs.writeFile(path.join(tempRoot, AGENT_PATH), updatedAgent.value);
|
|
785
298
|
await writeTempTreeToContext(tempRoot, ctx);
|
|
786
299
|
ctx.write(ORIGINAL_API_SPEC_PATH, await readOriginalOpenApiSpec(apiSpecLocation));
|
|
787
300
|
updateAuthYml(ctx, M365_AGENTS_YML, registrations.value);
|
|
788
301
|
updateAuthYml(ctx, M365_AGENTS_LOCAL_YML, registrations.value);
|
|
789
302
|
return (0, neverthrow_1.ok)(undefined);
|
|
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
|
-
}
|
|
303
|
+
});
|
|
797
304
|
},
|
|
798
305
|
};
|
|
799
306
|
exports.openApiGenerateTeamsAiCustomApiFiles = {
|
|
@@ -816,8 +323,7 @@ exports.openApiGenerateTeamsAiCustomApiFiles = {
|
|
|
816
323
|
if (apiSpecLocation === undefined || apiOperations === undefined || language === undefined) {
|
|
817
324
|
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiParams", "resolved parameters are not all valid"));
|
|
818
325
|
}
|
|
819
|
-
|
|
820
|
-
try {
|
|
326
|
+
return (0, withTempDirectory_1.withTempDirectory)("m365atk-openapi-teams-ai-", (phase, error) => systemError("OpenApiTeamsAiGenerateFailed", `Failed to generate Teams AI custom API files during temporary file ${phase}: ${errorMessage(error)}`), async (tempRoot) => {
|
|
821
327
|
const languageFiles = teamsAiLanguageFiles(language);
|
|
822
328
|
const baseFiles = await writeTeamsAiBaseFiles(ctx, tempRoot, languageFiles);
|
|
823
329
|
if (baseFiles.isErr()) {
|
|
@@ -844,27 +350,13 @@ exports.openApiGenerateTeamsAiCustomApiFiles = {
|
|
|
844
350
|
if (filteredSpec === undefined) {
|
|
845
351
|
return (0, neverthrow_1.err)(systemError("OpenApiTeamsAiFilteredSpecMissing", "Failed to generate the filtered OpenAPI document for the selected operations."));
|
|
846
352
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
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
|
-
}
|
|
353
|
+
const warnings = await (0, openApiCustomApi_1.generateTeamsAiCustomApiFiles)(filteredSpec, language, tempRoot, openapiSpecFileName);
|
|
354
|
+
for (const warning of warnings) {
|
|
355
|
+
ctx.warn?.(warning.content);
|
|
858
356
|
}
|
|
859
357
|
await writeTempTreeToContext(tempRoot, ctx);
|
|
860
358
|
return (0, neverthrow_1.ok)(undefined);
|
|
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
|
-
}
|
|
359
|
+
});
|
|
868
360
|
},
|
|
869
361
|
};
|
|
870
362
|
//# sourceMappingURL=openApi.js.map
|