npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@microsoft/agents-copilotstudio-client

v1.1.1

Published

Microsoft Copilot Studio Client for JavaScript. Copilot Studio Client.

Readme

@microsoft/agents-copilotstudio-client

Overview

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.

This package provides exports for CommonJS and ES6 modules, and also a bundle to be used in the browser.

[!NOTE] The Client needs to be initialized with a valid JWT Token.

Installation

To install the package, use npm or yarn:

npm install @microsoft/agents-copilotstudio-client

Prerequisite

To use this library, you will need the following:

  1. An Agent Created in Microsoft Copilot Studio.
  2. Ability to Create or Edit an Application Identity in Azure
    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.
    2. (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.

Create a Agent in Copilot Studio

  1. Create or open an Agent in Copilot Studio
    1. Make sure that the Copilot is Published
    2. Goto Settings => Advanced => Metadata and copy the following values. You will need them later:
      1. Schema name - this is the 'unique name' of your agent inside this environment.
      2. Environment Id - this is the ID of the environment that contains the agent.

Create an Application Registration in Entra ID to support user authentication to Copilot Studio

[!IMPORTANT] 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.

When using this method, you will need to add the CopilotStudio.Copilots.Invoke delegated API permision to your application registration's API privilages

Add the CopilotStudio.Copilots.Invoke permissions to your Application Registration in Entra ID to support User or Service Principal authentication to Copilot Studio

This step will require permissions to edit application identities in your Azure tenant.

  1. In your azure application
    1. Goto Manage
    2. Goto API Permissions
    3. Click Add Permission
      1. In the side pannel that appears, Click the tab API's my organization uses
      2. Search for Power Platform API.
        1. If you do not see Power Platform API see the note at the bottom of this section.
      3. For User Interactive Permissions, choose Delegated Permissions
        1. In the permissions list choose CopilotStudio and Check CopilotStudio.Copilots.Invoke
        2. Click Add Permissions
      4. For Service Principal/Confidential Client, choose Application Permissions
        1. In the permissions list choose CopilotStudio and Check CopilotStudio.Copilots.Invoke
        2. Click Add Permissions
        3. An appropriate administrator must then Grant Admin consent for copilotsdk before the permissions will be available to the application.
    4. Close Azure Portal

[!TIP] 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 and follow the instructions on Step 2 to add the Power Platform Admin API to your Tenant

How-to use

The Copilot Client is configured using the ConnectionSettings class and a jwt token to authenticate to the service. The ConnectionSettings class can be configured using either instantiating the class or loading the settings from a .env.

Using the default class

There are a few options for configuring the ConnectionSettings class. The following are the most common options:

Using Environment ID and Copilot Studio Agent Schema Name:

const settings: ConnectionSettings = {
  environmentId: "your-environment-id",
  agentIdentifier: "your-agent-schema-name",
};

Using the DirectConnectUrl:

const settings: ConnectionSettings = {
  directConnectUrl: "https://direct.connect.url",
};

[!NOTE] 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

Using the .env file

You can use the loadCopilotStudioConnectionSettingsFromEnv function to load the ConnectionSettings from a .env file.

The following are the most common options:

Using Environment ID and Copilot Studio Agent Schema Name:

environmentId=your-environment-id
agentIdentifier=your-agent-schema-name

Using the DirectConnectUrl:

directConnectUrl=https://direct.connect.url

Example of how to create a Copilot client

const createClient = async (): Promise<CopilotStudioClient> => {
  const settings = loadCopilotStudioConnectionSettingsFromEnv()
  const token = await acquireToken(settings)
  const copilotClient = new CopilotStudioClient(settings, token)
  return copilotClient
}
const copilotClient = await createClient()
const replies = await copilotClient.startConversationAsync(true)
replies.forEach(r => console.log(r.text))