Get started
Embedded Studio

AI co-pilot

AI co-pilot

The co-pilot is a chat panel inside the studio. A member asks in plain words, such as "make day two shorter" or "add a waypoint at the refuge", and the model edits the open itinerary or zone.

Opt-in

Before you turn it on

  1. An AI provider for the organization. An owner or admin configures the provider, model and API key under Organization → AI co-pilot in the Mountaya app. Runs are billed by your provider, on that key.
  2. The copilot feature in your agreement, for members with a write role.
  3. A member token. The co-pilot acts as the member the session token names, like every edit.

Turn it on

State behavior.copilot on the host, and give the host a viewer that holds the copilot feature. The editor then offers a co-pilot tab.

import { createMemoryViewer } from "@mountaya/studio";
import {
  MountayaStudio,
  MountayaStudioHost,
  type StudioCopilotSeam,
  usePlatformViewer,
} from "@mountaya/studio-react";
import { QueryClient } from "@tanstack/react-query";
import { useState } from "react";

// Module scope: the host reads it on every render, so its identity must hold.
const copilot: StudioCopilotSeam = () => ({
  availability: {
    canConfigure: false,
    configured: true,
    loading: false,
    notConfigured: false,
    writable: true,
  },
  modelLine: null,
  setupAction: null,
  withheldNotice: null,
});

export const StudioWithCopilot = () => {
  const [cache] = useState(() => new QueryClient());
  const [person] = useState(() => createMemoryViewer({}, { getUserId: () => userId }));
  const { viewer } = usePlatformViewer({
    client: mountaya,
    organizationId,
    queryClient: cache,
    viewer: person,
  });

  return (
    <MountayaStudioHost behavior={{ copilot }} client={mountaya} data={{ queryClient: cache, viewer }}>
      <MountayaStudio />
    </MountayaStudioHost>
  );
};

Your function answers per organization. Report configured and writable from what you know, and return a withheldNotice to explain, in your words, why the co-pilot is off.

What the co-pilot may do

The co-pilot changes the studio only by dispatching verbs on the tool bus, as a click does. It sees the verbs the member's grants allow, minus a few the studio keeps for people, such as publishing and share links.

While a run is driving, the studio's other controls go inert until it ends.

Confirmations

A destructive verb asks the member first, whether a click or the co-pilot dispatched it. The model cannot approve its own call: the member sees the same confirm dialog, and a "no" refuses the call.

Lay out the panel yourself

MountayaStudio places the co-pilot panel for you. In a layout of your own, mount CopilotPanel from @mountaya/studio-react/copilot, and open a co-pilot tab by dispatching studio.tabs.open with { kind: "copilot" }.

Run the co-pilot without the studio

AgentEngine of @mountaya/elements/agent runs a conversation over any bus and context, for a product that draws its own chat. When the run's stream answers 503, the engine keeps reopening it for up to two minutes before it reports the error.

import { AgentEngine } from "@mountaya/elements/agent";
import { recoveryFor } from "@mountaya/studio/agent";

const run = new AgentEngine({
  bus: agentBus,
  confirmServerTool: askTheReader,
  ctx: studioContext,
  observer: watchTheRun,
  recoveryFor,
  transport: agentTransport,
});

Next steps

Last updated