@microsoft/agents-copilotstudio-client 0.6.1 → 0.6.16-gc874f0c9d8

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.
@@ -4,6 +4,10 @@
4
4
  */
5
5
  import { ConnectionSettings } from './connectionSettings';
6
6
  import { Activity } from '@microsoft/agents-activity';
7
+ /**
8
+ * Client for interacting with Microsoft Copilot Studio services.
9
+ * Provides functionality to start conversations and send messages to Copilot Studio bots.
10
+ */
7
11
  export declare class CopilotStudioClient {
8
12
  /** Header key for conversation ID. */
9
13
  private static readonly conversationIdHeaderKey;
@@ -15,11 +19,11 @@ export declare class CopilotStudioClient {
15
19
  private readonly settings;
16
20
  /** The Axios instance used for HTTP requests. */
17
21
  private readonly client;
18
- /** The logger for debugging. */
19
- private readonly logger;
20
22
  /**
21
- * Returns the Scope URL needed to connect to Copilot Studio from the Connection Settings.
22
- * @param settings Copilot Studio Connection Settings.
23
+ * Returns the scope URL needed to connect to Copilot Studio from the connection settings.
24
+ * This is used for authentication token audience configuration.
25
+ * @param settings Copilot Studio connection settings.
26
+ * @returns The scope URL for token audience.
23
27
  */
24
28
  static scopeFromSettings: (settings: ConnectionSettings) => string;
25
29
  /**
@@ -12,9 +12,14 @@ const axios_1 = __importDefault(require("axios"));
12
12
  const powerPlatformEnvironment_1 = require("./powerPlatformEnvironment");
13
13
  const agents_activity_1 = require("@microsoft/agents-activity");
14
14
  const executeTurnRequest_1 = require("./executeTurnRequest");
15
- const debug_1 = __importDefault(require("debug"));
16
- const package_json_1 = __importDefault(require("@microsoft/agents-copilotstudio-client/package.json"));
15
+ const logger_1 = require("@microsoft/agents-activity/logger");
16
+ const package_json_1 = require("../package.json");
17
17
  const os_1 = __importDefault(require("os"));
18
+ const logger = (0, logger_1.debug)('copilot-studio:client');
19
+ /**
20
+ * Client for interacting with Microsoft Copilot Studio services.
21
+ * Provides functionality to start conversations and send messages to Copilot Studio bots.
22
+ */
18
23
  class CopilotStudioClient {
19
24
  /**
20
25
  * Creates an instance of CopilotStudioClient.
@@ -28,39 +33,39 @@ class CopilotStudioClient {
28
33
  this.client = axios_1.default.create();
29
34
  this.client.defaults.headers.common.Authorization = `Bearer ${token}`;
30
35
  this.client.defaults.headers.common['User-Agent'] = CopilotStudioClient.getProductInfo();
31
- this.logger = (0, debug_1.default)('copilot-studio-client');
32
36
  }
33
37
  async postRequestAsync(axiosConfig) {
34
38
  var _a, _b, _c, _d;
35
39
  const activities = [];
36
- this.logger(`>>> SEND TO ${axiosConfig.url}`);
40
+ logger.debug(`>>> SEND TO ${axiosConfig.url}`);
37
41
  const response = await this.client(axiosConfig);
38
42
  if (this.settings.useExperimentalEndpoint && !((_a = this.settings.directConnectUrl) === null || _a === void 0 ? void 0 : _a.trim())) {
39
43
  const islandExperimentalUrl = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[CopilotStudioClient.islandExperimentalUrlHeaderKey];
40
44
  if (islandExperimentalUrl) {
41
45
  this.settings.directConnectUrl = islandExperimentalUrl;
42
- this.logger(`Island Experimental URL: ${islandExperimentalUrl}`);
46
+ logger.debug(`Island Experimental URL: ${islandExperimentalUrl}`);
43
47
  }
44
48
  }
45
49
  this.conversationId = (_d = (_c = response.headers) === null || _c === void 0 ? void 0 : _c[CopilotStudioClient.conversationIdHeaderKey]) !== null && _d !== void 0 ? _d : '';
46
50
  if (this.conversationId) {
47
- this.logger(`Conversation ID: ${this.conversationId}`);
51
+ logger.debug(`Conversation ID: ${this.conversationId}`);
48
52
  }
49
- this.logger('=====================================================');
50
- this.logger(`Headers: ${JSON.stringify(response.headers, null, 2)}`);
51
- this.logger('=====================================================');
53
+ const sanitizedHeaders = { ...response.headers };
54
+ delete sanitizedHeaders['Authorization'];
55
+ delete sanitizedHeaders[CopilotStudioClient.conversationIdHeaderKey];
56
+ logger.debug('Headers received:', sanitizedHeaders);
52
57
  const stream = response.data;
53
58
  const reader = stream.pipeThrough(new TextDecoderStream()).getReader();
54
59
  let result = '';
55
60
  const results = [];
56
61
  const processEvents = async ({ done, value }) => {
57
62
  if (done) {
58
- this.logger('Stream complete');
63
+ logger.debug('Stream complete');
59
64
  result += value;
60
65
  results.push(result);
61
66
  return results;
62
67
  }
63
- this.logger('Agent is typing...');
68
+ logger.info('Agent is typing ...');
64
69
  result += value;
65
70
  return await processEvents(await reader.read());
66
71
  };
@@ -77,15 +82,15 @@ class CopilotStudioClient {
77
82
  if (!this.conversationId.trim()) {
78
83
  // Did not get it from the header.
79
84
  this.conversationId = (_b = (_a = act.conversation) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
80
- this.logger(`Conversation ID: ${this.conversationId}`);
85
+ logger.debug(`Conversation ID: ${this.conversationId}`);
81
86
  }
82
87
  }
83
88
  else {
84
- this.logger('Activity type: ', act.type);
89
+ logger.debug(`Activity type: ${act.type}`);
85
90
  }
86
91
  }
87
92
  catch (e) {
88
- this.logger('Error: ', e);
93
+ logger.error('Error: ', e);
89
94
  throw e;
90
95
  }
91
96
  });
@@ -99,11 +104,16 @@ class CopilotStudioClient {
99
104
  * @returns A string containing the product information, including version and user agent.
100
105
  */
101
106
  static getProductInfo() {
102
- const version = `CopilotStudioClient.agents-sdk-js/${package_json_1.default.version}`;
107
+ const versionString = `CopilotStudioClient.agents-sdk-js/${package_json_1.version}`;
108
+ let userAgent;
103
109
  if (typeof window !== 'undefined' && window.navigator) {
104
- return `${version} ${navigator.userAgent}`;
110
+ userAgent = `${versionString} ${navigator.userAgent}`;
111
+ }
112
+ else {
113
+ userAgent = `${versionString} nodejs/${process.version} ${os_1.default.platform()}-${os_1.default.arch()}/${os_1.default.release()}`;
105
114
  }
106
- return `${version} nodejs/${process.version} ${os_1.default.platform()}-${os_1.default.arch()}/${os_1.default.release()}`;
115
+ logger.debug(`User-Agent: ${userAgent}`);
116
+ return userAgent;
107
117
  }
108
118
  /**
109
119
  * Starts a new conversation with the Copilot Studio service.
@@ -111,6 +121,7 @@ class CopilotStudioClient {
111
121
  * @returns A promise that resolves to the initial activity of the conversation.
112
122
  */
113
123
  async startConversationAsync(emitStartConversationEvent = true) {
124
+ var _a;
114
125
  const uriStart = (0, powerPlatformEnvironment_1.getCopilotStudioConnectionUrl)(this.settings);
115
126
  const body = { emitStartConversationEvent };
116
127
  const config = {
@@ -124,8 +135,10 @@ class CopilotStudioClient {
124
135
  responseType: 'stream',
125
136
  adapter: 'fetch'
126
137
  };
138
+ logger.info('Starting conversation ...');
127
139
  const values = await this.postRequestAsync(config);
128
140
  const act = values[0];
141
+ logger.info(`Conversation '${(_a = act.conversation) === null || _a === void 0 ? void 0 : _a.id}' started. Received ${values.length} activities.`, values);
129
142
  return act;
130
143
  }
131
144
  /**
@@ -159,7 +172,9 @@ class CopilotStudioClient {
159
172
  responseType: 'stream',
160
173
  adapter: 'fetch'
161
174
  };
175
+ logger.info(`Asking question: ${question} ...`);
162
176
  const values = await this.postRequestAsync(config);
177
+ logger.info(`Received ${values.length} activities.`, values);
163
178
  return values;
164
179
  }
165
180
  }
@@ -169,8 +184,10 @@ CopilotStudioClient.conversationIdHeaderKey = 'x-ms-conversationid';
169
184
  /** Island Header key */
170
185
  CopilotStudioClient.islandExperimentalUrlHeaderKey = 'x-ms-d2e-experimental';
171
186
  /**
172
- * Returns the Scope URL needed to connect to Copilot Studio from the Connection Settings.
173
- * @param settings Copilot Studio Connection Settings.
187
+ * Returns the scope URL needed to connect to Copilot Studio from the connection settings.
188
+ * This is used for authentication token audience configuration.
189
+ * @param settings Copilot Studio connection settings.
190
+ * @returns The scope URL for token audience.
174
191
  */
175
192
  CopilotStudioClient.scopeFromSettings = powerPlatformEnvironment_1.getTokenAudience;
176
193
  //# sourceMappingURL=copilotStudioClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copilotStudioClient.js","sourceRoot":"","sources":["../../src/copilotStudioClient.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,kDAAgE;AAChE,yEAA4F;AAC5F,gEAAyF;AACzF,6DAAyD;AACz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;SACnB,CAAA;QACD,MAAM,WAAW,GAAG;YAClB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,mBAAmB;SAClC,CAAA;QACD,MAAM,QAAQ,GAAG,0BAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;QAEjD,MAAM,mBAAmB,GAAG,MAAA,MAAA,QAAQ,CAAC,YAAY,0CAAE,EAAE,mCAAI,cAAc,CAAA;QACvE,MAAM,UAAU,GAAG,IAAA,wDAA6B,EAAC,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;QACpF,MAAM,KAAK,GAAuB,IAAI,uCAAkB,CAAC,QAAQ,CAAC,CAAA;QAElE,MAAM,MAAM,GAAuB;YACjC,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,UAAU;YACf,OAAO,EAAE;gBACP,MAAM,EAAE,mBAAmB;gBAC3B,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,KAAK;YACX,YAAY,EAAE,QAAQ;YACtB,OAAO,EAAE,OAAO;SACjB,CAAA;QACD,MAAM,CAAC,IAAI,CAAC,oBAAoB,QAAQ,MAAM,CAAC,CAAA;QAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAClD,MAAM,CAAC,IAAI,CAAC,YAAY,MAAM,CAAC,MAAM,cAAc,EAAE,MAAM,CAAC,CAAA;QAC5D,OAAO,MAAM,CAAA;IACf,CAAC;;AA3LH,kDA4LC;AA3LC,sCAAsC;AACd,2CAAuB,GAAW,qBAAqB,AAAhC,CAAgC;AAC/E,wBAAwB;AACA,kDAA8B,GAAW,uBAAuB,AAAlC,CAAkC;AASxF;;;;;GAKG;AACI,qCAAiB,GAA6C,2CAAgB,AAA7D,CAA6D"}
@@ -5,61 +5,179 @@
5
5
  import { Activity } from '@microsoft/agents-activity';
6
6
  import { Observable, BehaviorSubject } from 'rxjs';
7
7
  import { CopilotStudioClient } from './copilotStudioClient';
8
+ /**
9
+ * Configuration settings for the Copilot Studio WebChat connection.
10
+ * These settings control the behavior and appearance of the WebChat interface
11
+ * when connected to the Copilot Studio service.
12
+ */
8
13
  export interface CopilotStudioWebChatSettings {
9
14
  /**
10
- * Whether to show typing indicators in the WebChat.
11
- * Defaults to false.
15
+ * Whether to show typing indicators in the WebChat when the agent is processing a response.
16
+ * When enabled, users will see a typing indicator while waiting for the agent's reply,
17
+ * providing visual feedback that their message is being processed.
18
+ * @default false
12
19
  */
13
20
  showTyping?: boolean;
14
21
  }
22
+ /**
23
+ * Represents a connection interface for integrating Copilot Studio with WebChat.
24
+ * This interface provides the necessary methods and observables to facilitate
25
+ * bidirectional communication between a WebChat client and the Copilot Studio service.
26
+ *
27
+ * The connection follows the DirectLine protocol pattern, making it compatible with
28
+ * Microsoft Bot Framework WebChat components.
29
+ */
15
30
  export interface CopilotStudioWebChatConnection {
16
31
  /**
17
- * An observable that emits the connection status.
18
- * 0 - Disconnected
19
- * 1 - Connecting
20
- * 2 - Connected
21
- */
32
+ * An observable that emits the current connection status as numeric values.
33
+ * This allows WebChat clients to monitor and react to connection state changes.
34
+ *
35
+ * Connection status values:
36
+ * - 0: Disconnected - No active connection to the service
37
+ * - 1: Connecting - Attempting to establish connection
38
+ * - 2: Connected - Successfully connected and ready for communication
39
+ */
22
40
  connectionStatus$: BehaviorSubject<number>;
23
41
  /**
24
- * An observable that emits incoming activities.
25
- * The emitted activities will have a 'webchat:sequence-id' in their channelData.
42
+ * An observable stream that emits incoming activities from the Copilot Studio service.
43
+ * Each activity represents a message, card, or other interactive element sent by the agent.
44
+ *
45
+ * All emitted activities include:
46
+ * - A timestamp indicating when the activity was received
47
+ * - A 'webchat:sequence-id' in their channelData for proper message ordering
48
+ * - Standard Bot Framework Activity properties (type, text, attachments, etc.)
26
49
  */
27
50
  activity$: Observable<Partial<Activity>>;
28
51
  /**
29
- * Posts an activity to the Copilot Studio service.
30
- * The activity must have a non-empty text field.
31
- * Returns an observable that emits the activity ID once the activity is posted.
52
+ * Posts a user activity to the Copilot Studio service and returns an observable
53
+ * that emits the activity ID once the message is successfully sent.
54
+ *
55
+ * The method validates that the activity contains meaningful content and handles
56
+ * the complete message flow including optional typing indicators.
32
57
  *
33
- * @param activity - The activity to post.
34
- * @returns An observable that emits the activity ID.
58
+ * @param activity - The user activity to send. Must contain a non-empty text field.
59
+ * @returns An observable that emits the unique activity ID upon successful posting.
60
+ * @throws Error if the activity text is empty or if the connection is not properly initialized.
35
61
  */
36
62
  postActivity(activity: Activity): Observable<string>;
37
63
  /**
38
- * Ends the connection.
39
- * This will complete the connectionStatus$ and activity$ observables.
64
+ * Gracefully terminates the connection to the Copilot Studio service.
65
+ * This method ensures proper cleanup by completing all active observables
66
+ * and releasing associated resources.
67
+ *
68
+ * After calling this method:
69
+ * - The connectionStatus$ observable will be completed
70
+ * - The activity$ observable will stop emitting new activities
71
+ * - No further activities can be posted through this connection
40
72
  */
41
73
  end(): void;
42
74
  }
43
75
  /**
44
- * This class is intended to be used in WebChat applications to connect to the Copilot Studio service.
76
+ * A utility class that provides WebChat integration capabilities for Copilot Studio services.
77
+ * This class acts as a bridge between Microsoft Bot Framework WebChat and Copilot Studio,
78
+ * enabling seamless communication through a DirectLine-compatible interface.
79
+ *
80
+ * ## Key Features:
81
+ * - DirectLine protocol compatibility for easy WebChat integration
82
+ * - Real-time bidirectional messaging with Copilot Studio agents
83
+ * - Automatic conversation management and message sequencing
84
+ * - Optional typing indicators for enhanced user experience
85
+ * - Observable-based architecture for reactive programming patterns
86
+ *
87
+ * ## Usage Scenarios:
88
+ * - Embedding Copilot Studio agents in web applications
89
+ * - Creating custom chat interfaces with WebChat components
90
+ * - Building conversational AI experiences with Microsoft's bot ecosystem
91
+ *
92
+ * @example Basic WebChat Integration
93
+ * ```typescript
94
+ * import { CopilotStudioClient } from '@microsoft/agents-copilotstudio-client';
95
+ * import { CopilotStudioWebChat } from '@microsoft/agents-copilotstudio-client';
96
+ *
97
+ * // Initialize the Copilot Studio client
98
+ * const client = new CopilotStudioClient({
99
+ * botId: 'your-bot-id',
100
+ * tenantId: 'your-tenant-id'
101
+ * });
45
102
  *
46
- * example usage:
47
- * ```javascript
48
- * const client = new CopilotStudioClient(...)
103
+ * // Create a WebChat-compatible connection
104
+ * const directLine = CopilotStudioWebChat.createConnection(client, {
105
+ * showTyping: true
106
+ * });
107
+ *
108
+ * // Integrate with WebChat
49
109
  * window.WebChat.renderWebChat({
50
- * directLine: CopilotStudioWebChat.createConnection(client)
51
- * })
110
+ * directLine: directLine,
111
+ * // ... other WebChat options
112
+ * }, document.getElementById('webchat'));
113
+ * ```
114
+ *
115
+ * @example Advanced Usage with Connection Monitoring
116
+ * ```typescript
117
+ * const connection = CopilotStudioWebChat.createConnection(client);
118
+ *
119
+ * // Monitor connection status
120
+ * connection.connectionStatus$.subscribe(status => {
121
+ * switch (status) {
122
+ * case 0: console.log('Disconnected'); break;
123
+ * case 1: console.log('Connecting...'); break;
124
+ * case 2: console.log('Connected and ready'); break;
125
+ * }
126
+ * });
127
+ *
128
+ * // Listen for incoming activities
129
+ * connection.activity$.subscribe(activity => {
130
+ * console.log('Received activity:', activity);
131
+ * });
52
132
  * ```
53
133
  */
54
134
  export declare class CopilotStudioWebChat {
55
135
  /**
56
- * Creates a new DirectLine-Like connection to WebChat.
57
- * When an activity is posted in WebChat, the connection will send it to the Copilot Studio service, awaiting response.
58
- * After a response is received, it will emit the incoming activity back to WebChat.
136
+ * Creates a DirectLine-compatible connection for integrating Copilot Studio with WebChat.
137
+ *
138
+ * This method establishes a real-time communication channel between WebChat and the
139
+ * Copilot Studio service. The returned connection object implements the DirectLine
140
+ * protocol, making it fully compatible with Microsoft Bot Framework WebChat components.
141
+ *
142
+ * ## Connection Lifecycle:
143
+ * 1. **Initialization**: Creates observables for connection status and activity streaming
144
+ * 2. **Conversation Start**: Automatically initiates conversation when first activity is posted
145
+ * 3. **Message Flow**: Handles bidirectional message exchange with proper sequencing
146
+ * 4. **Cleanup**: Provides graceful connection termination
147
+ *
148
+ * ## Message Processing:
149
+ * - User messages are validated and sent to Copilot Studio
150
+ * - Agent responses are received and formatted for WebChat
151
+ * - All activities include timestamps and sequence IDs for proper ordering
152
+ * - Optional typing indicators provide visual feedback during processing
153
+ *
154
+ * @param client - A configured CopilotStudioClient instance that handles the underlying
155
+ * communication with the Copilot Studio service. This client should be
156
+ * properly authenticated and configured with the target bot details.
157
+ *
158
+ * @param settings - Optional configuration settings that control the behavior of the
159
+ * WebChat connection. These settings allow customization of features
160
+ * like typing indicators and other user experience enhancements.
161
+ *
162
+ * @returns A new CopilotStudioWebChatConnection instance that can be passed directly
163
+ * to WebChat's renderWebChat function as the directLine parameter. The
164
+ * connection is immediately ready for use and will automatically manage
165
+ * the conversation lifecycle.
166
+ *
167
+ * @throws Error if the provided client is not properly configured or if there are
168
+ * issues establishing the initial connection to the Copilot Studio service.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const connection = CopilotStudioWebChat.createConnection(client, {
173
+ * showTyping: true
174
+ * });
59
175
  *
60
- * @param client - The Copilot Studio client instance.
61
- * @param settings - Optional settings for the WebChat connection.
62
- * @returns A new instance of CopilotStudioWebChatConnection.
176
+ * // Use with WebChat
177
+ * window.WebChat.renderWebChat({
178
+ * directLine: connection
179
+ * }, document.getElementById('webchat'));
180
+ * ```
63
181
  */
64
182
  static createConnection(client: CopilotStudioClient, settings?: CopilotStudioWebChatSettings): CopilotStudioWebChatConnection;
65
183
  }