Copilot component

<wy-copilot> | WyCopilot

The copilot component renders a complete and functional user interface for chatting with an AI agent. It needs to be configured with an AI agent and can have instructions and use any contextual data you provide (as long as it's a string).

The copilot chat is agent-to-user which means each user has their own private chat with the agent. Each time the copilot component is loaded a fresh chat is started, but it can optionally be configured with a uid to persist the conversation.

If you specify a uid it needs to be unique per user and agent (if you intend to use several agents). For ease-of-use, you can do this automatically by specifying the autoUid property instead of the uid property.

Importing

If you installed the UIKit with npm you can use the following snippet to import the component into your project. Otherwise, if you installed the UIKit as a <script> you can ignore this section.

import { WyCopilot } from "@weavy/uikit-web";

Examples

Generic copilot

The agent property is required and should correspond to an agent in your environment. You may switch between agents whenever you like, but remember that the conversation also changes.

Here we use the built-in agent with uid assistant.

<wy-copilot agent="assistant"></wy-copilot>

Copilot with instructions and contextual data

<div id="my-sample-content">
  <h1>ACME</h1>
  <ul>
    <li>Wile E. Coyote</li>
    <li>Daffy Duck</li>
    <li>Porky Pig</li>
  </ul>
</div>

<wy-copilot uid="my-copilot" agent="assistant"></wy-copilot>

<script>
  const copilot = document.querySelector("#my-copilot");
  copilot.instructions = "Answer in a whacky way with many emojis.";
  copilot.contextualData =
    document.querySelector("#my-sample-content").innerHTML;
</script>

Copilot with a custom button and suggestions

You may use slots to provide custom functionality to the copilot. This example shows a button to reset the conversation and some custom suggestions.

When the suggestions have the .suggestion class, they automatically get their text inserted into the editor when clicked.

In this example we use the pre-styled weavy sub components, but you may use any elements or components you like.

<wy-copilot uid="my-copilot" agent="assistant">
  <wy-button
    slot="actions"
    kind="icon"
    onclick="document.querySelector('#my-copilot').reset()"
  >
    <wy-icon name="stars"></wy-icon>
  </wy-button>

  <wy-button slot="suggestion-list" class="suggestion"
    >Summarize this page</wy-button
  >
  <wy-button slot="suggestion-list" class="suggestion"
    >What keywords are used?</wy-button
  >
</wy-copilot>

All Weavy sub components can be found by importing WeavyComponents from the UI Kit.

HTML attributes

Attributes can be set when using the component in HTML. All attributes have corresponding Javascript properties.

Most attributes are optional and/or has sensible default values. Any required attributes are indicated with an asterisk (*).

Learn more about attributes and properties.

Attribute Value Description
agent* string The configured uid of the AI agent.
annotations "buttons-inline", "none" Set the appearance of annotations.
contextualData string Contextual data for the agent to reference.
enterToSend "never", "modifier", "auto", "always" Sets whether to use enter to send in the editor. Modifier is enter combined with Ctrl or Cmd. Defaults to "auto".
features string Explicit space separated list of enabled features. All default features are enabled when this property is not defined.
generateUid string Generates a unique uid by appending user and agent identifiers to the supplied string.
instructions string Any specific instructions for the agent. Overrides any pre configured agent instructions.
name string Optional display name for the app (used in notifications etc.)
placeholder string Placeholder text for the editor. Overrides default text.
reactions string Space separated string of unicode emojis to use for reactions.
uid string Optional unique identifier to persist the conversation. The uid should be unique per agent and user.

JavaScript properties

Properties can be used in JavaScript. Some of them have corresponding HTML attributes where applicable.

Property Type Default Description
agent* string The configured uid of the agent for the Weavy component.
instructions string Optional agent instructions appended to submitted messages.
placeholder string Placeholder text for the message editor. Overrides default text.
app AppType The app data.
link LinkType Any provided link that should be loaded, shown and highlighted.
features string Config for only enabling specific features in the weavy component.
contextualData string Contextual data for agents to reference. Provide descriptive data for optimal results.
generateUid string Sets the uid property with automatically appended user and agent name (where applicable).
uid string, number Unique identifier or app id for the Weavy component. The unique identifier should correspond to the uid of the app created using the server-to-server Web API.
name string Optional display name for the app (used in notifications etc.)
annotations "buttons-inline", "none" "buttons-inline" Appearance of annotations.
enterToSend "never", "modifier", "auto", "always" "auto" Enter-to-send keymap in the editor. "modifier" is Enter combined with Ctrl or Cmd.
reactions string "😍 😎 😉 😜 👍" A space separated string of available reaction emojis in unicode.

JavaScript methods

Methods for the component are available in JavaScript. Methods that are async return a promise.

Method Description
setSuggestion(text: string) async Sets the editor input to a suggested text. This replaces the text content of the editor. This can be used to create any custom suggestions.
reset() Sets the component to it's initial state and resets the app state.
async subscribe(subscribe: boolean) async Subscribes or unsubscribes to notification updates from the app. Check .app.is_subscribed to see current state.
async whenApp() async AppType Waits for app data and returns the data when available.

DOM Events

The component triggers custom events that bubbles up the DOM tree. They can be listened to using the addEventListener() method.

Learn more about events.

Event Type Description
wy-app WyAppEventType Emitted when the app changes.
wy-action WyActionEventType Emitted when an action is performed on a conversation or embed.
wy-message WyMessageEventType Emitted when a message is received.
wy-preview-open WyPreviewOpenEventType Emitted when preview is about to be opened. The event may be prevented.
wy-preview-close WyPreviewCloseEventType Emitted when preview is closed.

Slots

The slots can be used to inject elements into the component. All predefined child nodes of the slot will be replaced with the injected content.

Slot Description
actions Floating buttons placed in the top right.
empty All the content for the empty state.
header Header for the empty state.
icon Display icon in the header.
suggestions Suggestion content in the empty state.
suggestion-list Items for the list in the suggestion content.
footer Footer for the empty state.

To prevent child nodes from rendering before the component has loaded you can hide them using CSS.

wy-copilot:not(:defined) {
  display: none;
}

Available features

The following features are available for the component. Configure them with a space separated list using the features attribute. Features that are available but disabled by default are indicated by parenthesis ().

Learn more about features.

Feature Description
(attachments) Possibility to upload local files. The support for files may be restricted by the agent provider.
context_data Possibility to upload contextual data.
embeds Creating embeds from urls in editor text.
(mentions) Possibility to mention other people from the current directory in the editor.
previews Previews of files and attachments.
(reactions) Possibility to add emoji reactions to a message, post or comment. This has currently no effect on the agent.
typing Typing indicators in the chat when the agent types.
Support

To access live chat with our developer success team you need a Weavy account.

Sign in or create a Weavy account