@microsoft/agents-copilotstudio-client 0.5.1-g2e246ff274 → 0.5.12-g2d752e9b13

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.
Files changed (44) hide show
  1. package/README.md +92 -15
  2. package/dist/src/browser/os.d.ts +7 -0
  3. package/dist/src/{directToEngineConnectionSettings.js → browser/os.js} +2 -1
  4. package/dist/src/browser/os.js.map +1 -0
  5. package/dist/src/browser.mjs +10 -0
  6. package/dist/src/browser.mjs.map +7 -0
  7. package/dist/src/connectionSettings.d.ts +10 -3
  8. package/dist/src/connectionSettings.js +11 -5
  9. package/dist/src/connectionSettings.js.map +1 -1
  10. package/dist/src/copilotStudioClient.d.ts +10 -0
  11. package/dist/src/copilotStudioClient.js +39 -5
  12. package/dist/src/copilotStudioClient.js.map +1 -1
  13. package/dist/src/{directToEngineConnectionSettings.d.ts → copilotStudioConnectionSettings.d.ts} +10 -6
  14. package/dist/src/copilotStudioConnectionSettings.js +7 -0
  15. package/dist/src/copilotStudioConnectionSettings.js.map +1 -0
  16. package/dist/src/copilotStudioWebChat.d.ts +65 -0
  17. package/dist/src/copilotStudioWebChat.js +107 -0
  18. package/dist/src/copilotStudioWebChat.js.map +1 -0
  19. package/dist/src/index.d.ts +8 -7
  20. package/dist/src/index.js +8 -7
  21. package/dist/src/index.js.map +1 -1
  22. package/dist/src/powerPlatformEnvironment.js +45 -17
  23. package/dist/src/powerPlatformEnvironment.js.map +1 -1
  24. package/dist/src/strategies/prebuiltBotStrategy.d.ts +15 -0
  25. package/dist/src/strategies/prebuiltBotStrategy.js +25 -0
  26. package/dist/src/strategies/prebuiltBotStrategy.js.map +1 -0
  27. package/dist/src/strategies/publishedBotStrategy.d.ts +15 -0
  28. package/dist/src/strategies/publishedBotStrategy.js +25 -0
  29. package/dist/src/strategies/publishedBotStrategy.js.map +1 -0
  30. package/dist/src/strategies/strategy.d.ts +7 -0
  31. package/dist/src/strategies/strategy.js +7 -0
  32. package/dist/src/strategies/strategy.js.map +1 -0
  33. package/package.json +19 -5
  34. package/src/browser/os.ts +8 -0
  35. package/src/connectionSettings.ts +19 -6
  36. package/src/copilotStudioClient.ts +46 -4
  37. package/src/{directToEngineConnectionSettings.ts → copilotStudioConnectionSettings.ts} +16 -6
  38. package/src/copilotStudioWebChat.ts +164 -0
  39. package/src/index.ts +8 -7
  40. package/src/powerPlatformEnvironment.ts +55 -26
  41. package/src/strategies/prebuiltBotStrategy.ts +37 -0
  42. package/src/strategies/publishedBotStrategy.ts +37 -0
  43. package/src/strategies/strategy.ts +8 -0
  44. package/dist/src/directToEngineConnectionSettings.js.map +0 -1
package/README.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  The `@microsoft/agents-copilotstudio-client` package allows you to interact with Copilot Studio Agents using the Direct Engine Protocol. This client library is designed to facilitate communication with agents, enabling seamless integration and interaction within your JavaScript or TypeScript applications.
6
6
 
7
- > Note: The Client needs to be initialized with a valid JWT Token.
7
+ > [!NOTE]
8
+ > The Client needs to be initialized with a valid JWT Token.
8
9
 
9
10
  ## Installation
10
11
 
@@ -14,24 +15,102 @@ To install the package, use npm or yarn:
14
15
  npm install @microsoft/agents-copilotstudio-client
15
16
  ```
16
17
 
17
- ## Pre-requisites
18
+ ### Prerequisite
18
19
 
19
- Create and deploy an agent in Copilot Studio, see [this guide](https://learn.microsoft.com/en-us/microsoft-copilot-studio/fundamentals-get-started?tabs=web) for a quick start
20
+ To use this library, you will need the following:
20
21
 
21
- Obtain the Agent configuration values from `<YourAgent>/Settings/Advanced/Metadata`, you will need:
22
+ 1. An Agent Created in Microsoft Copilot Studio.
23
+ 1. Ability to Create or Edit an Application Identity in Azure
24
+ 1. (Option 1) for a Public Client/Native App Registration or access to an existing registration (Public Client/Native App) that has the **CopilotStudio.Copilot.Invoke API Delegated Permission assigned**.
25
+ 1. (Option 2) for a Confidential Client/Service Principal App Registration or access to an existing App Registration (Confidential Client/Service Principal) with the **CopilotStudio.Copilot.Invoke API Application Permission assigned**.
22
26
 
23
- - Environment ID
24
- - Tenant ID
25
- - Agent app ID
26
- - Schema name
27
+ ### Create a Agent in Copilot Studio
27
28
 
28
- Create an Entra ID app registration with permissions in the PowerPlatform API: `CopilotStudio.Copilots.Invoke`
29
+ 1. Create or open an Agent in [Copilot Studio](https://copilotstudio.microsoft.com)
30
+ 1. Make sure that the Copilot is Published
31
+ 1. Goto Settings => Advanced => Metadata and copy the following values. You will need them later:
32
+ 1. Schema name - this is the 'unique name' of your agent inside this environment.
33
+ 1. Environment Id - this is the ID of the environment that contains the agent.
29
34
 
30
- > Note: If you do not see `Power Platform API` in the list of API's your organization uses, you need to add the Power Platform API to your tenant. To do that, goto [Power Platform API Authentication](https://learn.microsoft.com/power-platform/admin/programmability-authentication-v2#step-2-configure-api-permissions) and follow the instructions on Step 2 to add the Power Platform Admin API to your Tenant
35
+ ### Create an Application Registration in Entra ID to support user authentication to Copilot Studio
31
36
 
32
- ## Usage
37
+ > [!IMPORTANT]
38
+ > If you are using this client from a service, you will need to exchange the user token used to login to your service for a token for your agent hosted in copilot studio. This is called a On Behalf Of (OBO) authentication token. You can find more information about this authentication flow in [Entra Documentation](https://learn.microsoft.com/entra/msal/dotnet/acquiring-tokens/web-apps-apis/on-behalf-of-flow).
39
+ >
40
+ > When using this method, you will need to add the `CopilotStudio.Copilots.Invoke` _delegated_ API permision to your application registration's API privilages
33
41
 
34
- The client requires the `connectionSettings` and a the `jwt token` to authenticate in the service.
42
+ ### Add the CopilotStudio.Copilots.Invoke permissions to your Application Registration in Entra ID to support User or Service Principal authentication to Copilot Studio
43
+
44
+ This step will require permissions to edit application identities in your Azure tenant.
45
+
46
+ 1. In your azure application
47
+ 1. Goto Manage
48
+ 1. Goto API Permissions
49
+ 1. Click Add Permission
50
+ 1. In the side pannel that appears, Click the tab `API's my organization uses`
51
+ 1. Search for `Power Platform API`.
52
+ 1. _If you do not see `Power Platform API` see the note at the bottom of this section._
53
+ 1. For _User Interactive Permissions_, choose `Delegated Permissions`
54
+ 1. In the permissions list choose `CopilotStudio` and Check `CopilotStudio.Copilots.Invoke`
55
+ 1. Click `Add Permissions`
56
+ 1. For _Service Principal/Confidential Client_, choose `Application Permissions`
57
+ 1. In the permissions list choose `CopilotStudio` and Check `CopilotStudio.Copilots.Invoke`
58
+ 1. Click `Add Permissions`
59
+ 1. An appropriate administrator must then `Grant Admin consent for copilotsdk` before the permissions will be available to the application.
60
+ 1. Close Azure Portal
61
+
62
+ > [!TIP]
63
+ > If you do not see `Power Platform API` in the list of API's your organization uses, you need to add the Power Platform API to your tenant. To do that, goto [Power Platform API Authentication](https://learn.microsoft.com/power-platform/admin/programmability-authentication-v2#step-2-configure-api-permissions) and follow the instructions on Step 2 to add the Power Platform Admin API to your Tenant
64
+
65
+ ## How-to use
66
+
67
+ The Copilot Client is configured using the `ConnectionSettings` class and a `jwt token` to authenticate to the service.
68
+ The `ConnectionSettings` class can be configured using either instantiating the class or loading the settings from a `.env`.
69
+
70
+ #### Using the default class
71
+
72
+ There are a few options for configuring the `ConnectionSettings` class. The following are the most _common_ options:
73
+
74
+ Using Environment ID and Copilot Studio Agent Schema Name:
75
+
76
+ ```ts
77
+ const settings: ConnectionSettings = {
78
+ environmentId: "your-environment-id",
79
+ agentIdentifier: "your-agent-schema-name",
80
+ };
81
+ ```
82
+
83
+ Using the DirectConnectUrl:
84
+
85
+ ```ts
86
+ const settings: ConnectionSettings = {
87
+ directConnectUrl: "https://direct.connect.url",
88
+ };
89
+ ```
90
+
91
+ > [!NOTE]
92
+ > By default, it's assumed your agent is in the Microsoft Public Cloud. If you are using a different cloud, you will need to set the `Cloud` property to the appropriate value. See the `PowerPlatformCloud` enum for the supported values
93
+
94
+ #### Using the .env file
95
+
96
+ You can use the `loadCopilotStudioConnectionSettingsFromEnv` function to load the `ConnectionSettings` from a `.env` file.
97
+
98
+ The following are the most _common_ options:
99
+
100
+ Using Environment ID and Copilot Studio Agent Schema Name:
101
+
102
+ ```env
103
+ environmentId= your-environment-id
104
+ agentIdentifier=your-agent-schema-name
105
+ ```
106
+
107
+ Using the DirectConnectUrl:
108
+
109
+ ```env
110
+ directConnectUrl=https://direct.connect.url
111
+ ```
112
+
113
+ #### Example of how to create a Copilot client
35
114
 
36
115
  ```ts
37
116
  const createClient = async (): Promise<CopilotStudioClient> => {
@@ -43,6 +122,4 @@ const createClient = async (): Promise<CopilotStudioClient> => {
43
122
  const copilotClient = await createClient()
44
123
  const replies = await copilotClient.startConversationAsync(true)
45
124
  replies.forEach(r => console.log(r.text))
46
- ```
47
-
48
-
125
+ ```
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type * as osTypes from 'os';
6
+ declare const _default: typeof osTypes;
7
+ export default _default;
@@ -4,4 +4,5 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=directToEngineConnectionSettings.js.map
7
+ exports.default = {};
8
+ //# sourceMappingURL=os.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"os.js","sourceRoot":"","sources":["../../../src/browser/os.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAIH,kBAAe,EAAoB,CAAA"}