A recent Lighthouse
Newsletter piece put GitHub Copilot's Electron traffic behind
mitmproxy to figure out what the client actually does at
runtime, versus what its source merely allows. It's a legitimate technique —
Electron apps are opaque black boxes when the vendor doesn't ship source. But
it made us ask a narrower question: for Microsoft's new Copilot Studio
"agentic loop" harness — the CLI-authored agent runtime behind
pac copilot, the Copilot Studio plugin, and third-party
streaming-chat playgrounds — do you actually need to intercept traffic at all?
The answer, it turns out, is no. The entire wire protocol is sitting in a
published npm package. No certificate pinning to defeat, no proxy to stand
up — just npm pack and a text editor.
Two things converged
First, Microsoft open-sourced microsoft/copilot-studio-plugin
(the target of aka.ms/CopilotStudioPlugin), the successor to
skills-for-copilot-studio. It's an experimental CLI-agent
authoring plugin, and its scripts/src/chat-with-agent.js is a
complete, commented reference client for talking to a CLI/agentic-loop agent.
Second, a community write-up — "Streaming
Responses in Copilot Studio" — documented, from the outside, the exact
gotchas you hit building a live progressive-response chat UI against this
runtime: bubbles that explode into 150+ fragments, a "cold" observable with
only one subscriber slot, auto-scroll that stalls on in-place updates, and a
Direct Line opt-in you have to know to ask for.
Both are describing the same underlying wire protocol from two different
vantage points — one from the client SDK's source, one from empirical
black-box discovery. We pulled the actual SDK apart to confirm it.
Finding the real source of truth
Neither copilot-studio-plugin nor pac implements
the wire protocol itself. Both depend on
@microsoft/agents-copilotstudio-client, a public npm package.
One npm pack @microsoft/agents-copilotstudio-client later, its
compiled dist/src/copilotStudioClient.js lays out the entire
mechanism in ~500 lines:
const eventSource = createEventSource({
url,
headers: {
Authorization: `Bearer ${token}`,
'User-Agent': UserAgentHelper.getProductInfo(),
'Content-Type': 'application/json',
Accept: 'text/event-stream'
},
body: body ? JSON.stringify(body) : undefined,
method,
});
for await (const { data, event } of eventSource) {
if (data && event === 'activity') {
const activity = Activity.fromJson(data);
const streamingEntity = activity.entities?.find(
e => e.type === 'streaminfo' && e.streamType === 'streaming'
);
// ...accumulate by streamId + streamSequence, yield activity
} else if (event === 'end') {
break; // stream complete
}
}
That's the whole transport: Server-Sent Events carrying Bot Framework
Activity objects, Accept: text/event-stream,
an event: activity per chunk and a terminal event: end.
The streamId/streamSequence trick — confirmed, not guessed
The playground's biggest "gotcha" was that every interim chunk arrives as a
Typing activity with its own unique activity id, while
all chunks belonging to one answer share a streamId. Their fix
was to stamp id = streamId so Web Chat groups chunks into one
growing bubble instead of 150 stacked ones.
Reading the SDK source shows this isn't an incidental workaround — it's
exactly what the SDK itself does internally, one layer down, for its own
text accumulation:
if (id && sequence) {
if (streamMap.has(id)) {
streamMap.get(id).push({ text, sequence });
} else {
streamMap.set(id, [{ text, sequence }]);
}
activity.text = streamMap.get(id)
.sort((a, b) => a.sequence - b.sequence)
.map(item => item.text)
.join('');
}
The SDK also carries a legacy fallback most consumers wouldn't discover
without exactly the kind of empirical, "old style vs. new style" debugging
the playground describes: if entities[].type === "streaminfo"
is absent, it checks activity.channelData.streamType === "streaming"
instead. Two protocol generations, same client, quietly reconciled.
The lesson: before reaching for a MITM proxy, check whether
the client is already public. Microsoft ships the actual protocol
implementation as an npm package consumed by pac, the Copilot
Studio plugin, and any Direct-to-Engine integration. Reading compiled,
sourcemapped JS you can npm pack is strictly easier — and more
authoritative — than reconstructing behavior from captured traffic. Traffic
capture is for verifying the parts nobody ships source for. When they do
ship it, read that first.
What we mapped end-to-end
- Endpoint shape: CLI/agentic-loop agents (recognizer
CLIAgentRecognizer / CLICopilotRecognizer) are
served at https://<env>.<n>.environment.<cloud-suffix>/copilotstudio/agenticruntime/3p/dataverse-backed/authenticated/bots/<schemaName>?api-version=1,
with per-cloud host suffixes and a 30/2 vs. 31/1 environment-GUID split
depending on cloud (Prod/FirstRelease vs. everything else).
- Auth: MSAL device-code, public client, scope
CopilotStudio.Copilots.Invoke, token cached through the OS
keychain with a plaintext-file fallback when native modules can't load.
- Conversation lifecycle:
startConversationStreaming()
opens the SSE stream and optionally emits a start event; a response header
can seed the conversation id if the body didn't; an island-experimental-url
header can hot-swap the connect URL mid-flow.
- Activity taxonomy:
informative (reasoning
steps like "Generating plan…"), streaming (cumulative text
chunks — the playground saw 150+ per answer), final (the
concluded message activity).
Why this matters beyond one SDK
The instinct to reach straight for a proxy is understandable — it's the
general-purpose tool that works regardless of whether source is available.
But for any agent platform built by a vendor that also publishes its
client libraries, static analysis of that published client is faster,
gives you sourcemaps and comments instead of raw bytes on the wire, and
tells you the intended contract rather than one observed session's
incidental behavior. MITM is still the right tool for closed clients like
Claude Desktop or ChatGPT Desktop's Electron shell. It's the wrong first
step when the vendor already shipped you the protocol in node_modules.