@copilotkit/angular 0.2.0 → 0.3.1-canary.1785346263
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.
- package/README.md +146 -6
- package/dist/README.md +146 -6
- package/dist/fesm2022/copilotkit-angular-mcp-apps.mjs +821 -0
- package/dist/fesm2022/copilotkit-angular-mcp-apps.mjs.map +1 -0
- package/dist/fesm2022/copilotkit-angular.mjs +3231 -1361
- package/dist/fesm2022/copilotkit-angular.mjs.map +1 -1
- package/dist/{types/copilotkit-angular.d.ts → index.d.ts} +887 -431
- package/dist/mcp-apps/index.d.ts +343 -0
- package/package.json +59 -24
- package/scripts/normalize-package-exports.mjs +17 -0
- package/tsconfig.json +1 -0
- package/vitest.config.mts +3 -0
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { InjectionToken, inject, PLATFORM_ID, input, computed, viewChild, signal, afterRenderEffect, ChangeDetectionStrategy, Component, makeEnvironmentProviders } from '@angular/core';
|
|
5
|
+
import { CopilotKit, ɵCOPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS as _COPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS } from '@copilotkit/angular';
|
|
6
|
+
import { randomUUID } from '@copilotkit/shared';
|
|
7
|
+
|
|
8
|
+
const annotationsSchema = z.looseObject({
|
|
9
|
+
audience: z.array(z.enum(["user", "assistant"])).optional(),
|
|
10
|
+
priority: z.number().min(0).max(1).optional(),
|
|
11
|
+
lastModified: z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
const base64Schema = z
|
|
14
|
+
.string()
|
|
15
|
+
.refine((value) => value.length % 4 === 0 &&
|
|
16
|
+
/^[A-Za-z0-9+/]*={0,2}$/.test(value) &&
|
|
17
|
+
!/=/.test(value.slice(0, -2)), "Expected base64-encoded data");
|
|
18
|
+
const resourceContentsSchema = z.union([
|
|
19
|
+
z.looseObject({
|
|
20
|
+
uri: z.string(),
|
|
21
|
+
mimeType: z.string().optional(),
|
|
22
|
+
text: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
z.looseObject({
|
|
25
|
+
uri: z.string(),
|
|
26
|
+
mimeType: z.string().optional(),
|
|
27
|
+
blob: base64Schema,
|
|
28
|
+
}),
|
|
29
|
+
]);
|
|
30
|
+
const contentItemSchema = z.discriminatedUnion("type", [
|
|
31
|
+
z.looseObject({
|
|
32
|
+
type: z.literal("text"),
|
|
33
|
+
text: z.string(),
|
|
34
|
+
annotations: annotationsSchema.optional(),
|
|
35
|
+
}),
|
|
36
|
+
z.looseObject({
|
|
37
|
+
type: z.literal("image"),
|
|
38
|
+
data: base64Schema,
|
|
39
|
+
mimeType: z.string(),
|
|
40
|
+
annotations: annotationsSchema.optional(),
|
|
41
|
+
}),
|
|
42
|
+
z.looseObject({
|
|
43
|
+
type: z.literal("audio"),
|
|
44
|
+
data: base64Schema,
|
|
45
|
+
mimeType: z.string(),
|
|
46
|
+
annotations: annotationsSchema.optional(),
|
|
47
|
+
}),
|
|
48
|
+
z.looseObject({
|
|
49
|
+
type: z.literal("resource"),
|
|
50
|
+
resource: resourceContentsSchema,
|
|
51
|
+
annotations: annotationsSchema.optional(),
|
|
52
|
+
}),
|
|
53
|
+
z.looseObject({
|
|
54
|
+
type: z.literal("resource_link"),
|
|
55
|
+
uri: z.string(),
|
|
56
|
+
name: z.string(),
|
|
57
|
+
description: z.string().optional(),
|
|
58
|
+
mimeType: z.string().optional(),
|
|
59
|
+
annotations: annotationsSchema.optional(),
|
|
60
|
+
}),
|
|
61
|
+
]);
|
|
62
|
+
const callToolResultSchema = z.looseObject({
|
|
63
|
+
content: z.array(contentItemSchema).default([]),
|
|
64
|
+
structuredContent: z.record(z.string(), z.unknown()).optional(),
|
|
65
|
+
isError: z.boolean().optional(),
|
|
66
|
+
_meta: z.record(z.string(), z.unknown()).optional(),
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Content schema for `activityType: "mcp-apps"` activity messages: a snapshot
|
|
70
|
+
* of an MCP Apps tool call, carrying the middleware server hash, optional
|
|
71
|
+
* stable server id, the ui:// resource to render, and its tool exchange.
|
|
72
|
+
*
|
|
73
|
+
* Kept local and declared with the `zod/v4` API so the Angular browser bundle
|
|
74
|
+
* validates protocol data without taking a direct MCP client SDK dependency.
|
|
75
|
+
*/
|
|
76
|
+
const mcpAppsSnapshotContentSchema = z.looseObject({
|
|
77
|
+
serverHash: z.string(),
|
|
78
|
+
serverId: z.string().optional(),
|
|
79
|
+
resourceUri: z.string(),
|
|
80
|
+
result: callToolResultSchema,
|
|
81
|
+
toolInput: z.record(z.string(), z.unknown()).optional(),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 30_000;
|
|
85
|
+
const DEFAULT_IDLE_POLL_INTERVAL_MS = 500;
|
|
86
|
+
/** Raised when a renderer cancels MCP work that it owns. */
|
|
87
|
+
class MCPAppsQueueCancelledError extends Error {
|
|
88
|
+
constructor() {
|
|
89
|
+
super("MCP Apps request cancelled because its renderer was destroyed.");
|
|
90
|
+
this.name = "MCPAppsQueueCancelledError";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Raised when an agent does not become idle within the configured limit. */
|
|
94
|
+
class MCPAppsQueueTimeoutError extends Error {
|
|
95
|
+
constructor(timeoutMs) {
|
|
96
|
+
super(`Timed out waiting ${timeoutMs}ms for the agent to become idle.`);
|
|
97
|
+
this.name = "MCPAppsQueueTimeoutError";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Raised when a queued follow-up no longer belongs to the active thread. */
|
|
101
|
+
class MCPAppsQueueThreadChangedError extends Error {
|
|
102
|
+
constructor(originThreadId, currentThreadId) {
|
|
103
|
+
super(`Dropped MCP Apps follow-up after thread changed from "${originThreadId}" to "${currentThreadId}".`);
|
|
104
|
+
this.name = "MCPAppsQueueThreadChangedError";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Serializes MCP requests per agent thread while retaining renderer ownership.
|
|
109
|
+
*
|
|
110
|
+
* An owner can abort its queued and active waits without affecting requests
|
|
111
|
+
* created by another renderer. Follow-ups can additionally opt into a
|
|
112
|
+
* thread-identity check immediately before execution.
|
|
113
|
+
*/
|
|
114
|
+
class MCPAppsRequestQueue {
|
|
115
|
+
queues = new Map();
|
|
116
|
+
processing = new Map();
|
|
117
|
+
idleTimeoutMs;
|
|
118
|
+
idlePollIntervalMs;
|
|
119
|
+
constructor(options = {}) {
|
|
120
|
+
this.idleTimeoutMs = positiveDuration(options.idleTimeoutMs, DEFAULT_IDLE_TIMEOUT_MS, "idleTimeoutMs");
|
|
121
|
+
this.idlePollIntervalMs = positiveDuration(options.idlePollIntervalMs, DEFAULT_IDLE_POLL_INTERVAL_MS, "idlePollIntervalMs");
|
|
122
|
+
}
|
|
123
|
+
/** Enqueues one request and resolves it in FIFO order for its thread. */
|
|
124
|
+
enqueue(request) {
|
|
125
|
+
const capturedThreadId = request.agent.threadId || "default";
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const agentQueues = this.queues.get(request.agent) ?? new Map();
|
|
128
|
+
const queue = agentQueues.get(capturedThreadId) ?? [];
|
|
129
|
+
const item = {
|
|
130
|
+
agent: request.agent,
|
|
131
|
+
capturedThreadId,
|
|
132
|
+
controller: new AbortController(),
|
|
133
|
+
dropAfterThreadSwitch: request.dropAfterThreadSwitch ?? false,
|
|
134
|
+
execute: request.execute,
|
|
135
|
+
ownerId: request.ownerId,
|
|
136
|
+
reject,
|
|
137
|
+
resolve: (result) => resolve(result),
|
|
138
|
+
};
|
|
139
|
+
queue.push(item);
|
|
140
|
+
agentQueues.set(capturedThreadId, queue);
|
|
141
|
+
this.queues.set(request.agent, agentQueues);
|
|
142
|
+
void this.processQueue(request.agent, capturedThreadId);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Cancels only requests associated with the supplied renderer owner. */
|
|
146
|
+
cancelOwner(ownerId) {
|
|
147
|
+
for (const agentQueues of this.queues.values()) {
|
|
148
|
+
for (const queue of agentQueues.values()) {
|
|
149
|
+
for (const item of queue) {
|
|
150
|
+
if (item.ownerId === ownerId && !item.controller.signal.aborted) {
|
|
151
|
+
item.controller.abort();
|
|
152
|
+
item.reject(new MCPAppsQueueCancelledError());
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async processQueue(agent, threadId) {
|
|
159
|
+
const processingThreads = this.processing.get(agent) ?? new Set();
|
|
160
|
+
if (processingThreads.has(threadId))
|
|
161
|
+
return;
|
|
162
|
+
processingThreads.add(threadId);
|
|
163
|
+
this.processing.set(agent, processingThreads);
|
|
164
|
+
try {
|
|
165
|
+
const queue = this.queues.get(agent)?.get(threadId);
|
|
166
|
+
if (!queue)
|
|
167
|
+
return;
|
|
168
|
+
while (queue.length > 0) {
|
|
169
|
+
const item = queue[0];
|
|
170
|
+
try {
|
|
171
|
+
this.throwIfCancelled(item.controller.signal);
|
|
172
|
+
await this.waitForAgentIdle(item.agent, item.controller.signal);
|
|
173
|
+
this.throwIfCancelled(item.controller.signal);
|
|
174
|
+
const currentThreadId = item.agent.threadId || "default";
|
|
175
|
+
if (item.dropAfterThreadSwitch &&
|
|
176
|
+
currentThreadId !== item.capturedThreadId) {
|
|
177
|
+
throw new MCPAppsQueueThreadChangedError(item.capturedThreadId, currentThreadId);
|
|
178
|
+
}
|
|
179
|
+
const result = await raceWithAbort(item.execute(item.controller.signal), item.controller.signal);
|
|
180
|
+
item.resolve(result);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
item.reject(asError$1(error));
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
queue.shift();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
const agentQueues = this.queues.get(agent);
|
|
192
|
+
agentQueues?.delete(threadId);
|
|
193
|
+
if (agentQueues?.size === 0)
|
|
194
|
+
this.queues.delete(agent);
|
|
195
|
+
processingThreads.delete(threadId);
|
|
196
|
+
if (processingThreads.size === 0)
|
|
197
|
+
this.processing.delete(agent);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
waitForAgentIdle(agent, signal) {
|
|
201
|
+
if (!agent.isRunning)
|
|
202
|
+
return Promise.resolve();
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
let settled = false;
|
|
205
|
+
let subscription;
|
|
206
|
+
let interval;
|
|
207
|
+
const cleanup = () => {
|
|
208
|
+
clearTimeout(timeout);
|
|
209
|
+
if (interval !== undefined)
|
|
210
|
+
clearInterval(interval);
|
|
211
|
+
subscription?.unsubscribe();
|
|
212
|
+
signal.removeEventListener("abort", cancel);
|
|
213
|
+
};
|
|
214
|
+
const finish = () => {
|
|
215
|
+
if (settled)
|
|
216
|
+
return;
|
|
217
|
+
settled = true;
|
|
218
|
+
cleanup();
|
|
219
|
+
resolve();
|
|
220
|
+
};
|
|
221
|
+
const fail = (error) => {
|
|
222
|
+
if (settled)
|
|
223
|
+
return;
|
|
224
|
+
settled = true;
|
|
225
|
+
cleanup();
|
|
226
|
+
reject(error);
|
|
227
|
+
};
|
|
228
|
+
const cancel = () => fail(new MCPAppsQueueCancelledError());
|
|
229
|
+
const timeout = setTimeout(() => fail(new MCPAppsQueueTimeoutError(this.idleTimeoutMs)), this.idleTimeoutMs);
|
|
230
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
231
|
+
subscription = agent.subscribe({
|
|
232
|
+
onRunFinalized: finish,
|
|
233
|
+
onRunFailed: finish,
|
|
234
|
+
});
|
|
235
|
+
interval = setInterval(() => {
|
|
236
|
+
if (!agent.isRunning)
|
|
237
|
+
finish();
|
|
238
|
+
}, this.idlePollIntervalMs);
|
|
239
|
+
if (signal.aborted)
|
|
240
|
+
cancel();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
throwIfCancelled(signal) {
|
|
244
|
+
if (signal.aborted)
|
|
245
|
+
throw new MCPAppsQueueCancelledError();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function positiveDuration(value, fallback, name) {
|
|
249
|
+
const resolved = value ?? fallback;
|
|
250
|
+
if (!Number.isFinite(resolved) || resolved <= 0) {
|
|
251
|
+
throw new RangeError(`${name} must be a positive finite number.`);
|
|
252
|
+
}
|
|
253
|
+
return resolved;
|
|
254
|
+
}
|
|
255
|
+
function raceWithAbort(promise, signal) {
|
|
256
|
+
if (signal.aborted)
|
|
257
|
+
return Promise.reject(new MCPAppsQueueCancelledError());
|
|
258
|
+
return new Promise((resolve, reject) => {
|
|
259
|
+
const cancel = () => reject(new MCPAppsQueueCancelledError());
|
|
260
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
261
|
+
promise.then((value) => {
|
|
262
|
+
signal.removeEventListener("abort", cancel);
|
|
263
|
+
resolve(value);
|
|
264
|
+
}, (error) => {
|
|
265
|
+
signal.removeEventListener("abort", cancel);
|
|
266
|
+
reject(error);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function asError$1(error) {
|
|
271
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const DEFAULT_MCP_APPS_CONFIG = {
|
|
275
|
+
idleTimeoutMs: 30_000,
|
|
276
|
+
initializationTimeoutMs: 30_000,
|
|
277
|
+
hostInfo: {
|
|
278
|
+
name: "CopilotKit MCP Apps Host",
|
|
279
|
+
version: "1.0.0",
|
|
280
|
+
},
|
|
281
|
+
hostCapabilities: {
|
|
282
|
+
openLinks: {},
|
|
283
|
+
serverTools: {},
|
|
284
|
+
logging: {},
|
|
285
|
+
},
|
|
286
|
+
hostContext: {
|
|
287
|
+
theme: "light",
|
|
288
|
+
platform: "web",
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
/** Holds renderer behavior configuration registered via `provideMCPApps`. */
|
|
292
|
+
const MCP_APPS_CONFIG = new InjectionToken("MCP_APPS_CONFIG", { factory: () => ({ ...DEFAULT_MCP_APPS_CONFIG }) });
|
|
293
|
+
|
|
294
|
+
const PROTOCOL_VERSION = "2025-06-18";
|
|
295
|
+
const queuesByIdleTimeout = new Map();
|
|
296
|
+
/**
|
|
297
|
+
* Renders one MCP App snapshot through the same agent-mediated protocol used
|
|
298
|
+
* by the other CopilotKit frontends. Each instance owns its queued work and
|
|
299
|
+
* sandbox listener, while requests remain serialized per agent thread.
|
|
300
|
+
*/
|
|
301
|
+
class CopilotMCPAppsWidget {
|
|
302
|
+
config = inject(MCP_APPS_CONFIG);
|
|
303
|
+
copilotKit = inject(CopilotKit);
|
|
304
|
+
platformId = inject(PLATFORM_ID);
|
|
305
|
+
ownerId = randomUUID();
|
|
306
|
+
queue = queueForTimeout(this.config.idleTimeoutMs);
|
|
307
|
+
renderVersion = 0;
|
|
308
|
+
data = input.required(...(ngDevMode ? [{ debugName: "data" }] : []));
|
|
309
|
+
agent = input(...(ngDevMode ? [undefined, { debugName: "agent" }] : []));
|
|
310
|
+
renderSession = computed(() => ({ agent: this.agent(), data: this.data() }), ...(ngDevMode ? [{ debugName: "renderSession", equal: (previous, current) => previous.agent === current.agent &&
|
|
311
|
+
areStructurallyEqual(previous.data, current.data) }] : [{
|
|
312
|
+
equal: (previous, current) => previous.agent === current.agent &&
|
|
313
|
+
areStructurallyEqual(previous.data, current.data),
|
|
314
|
+
}]));
|
|
315
|
+
appFrame = viewChild.required("appFrame");
|
|
316
|
+
loading = signal(true, ...(ngDevMode ? [{ debugName: "loading" }] : []));
|
|
317
|
+
error = signal("", ...(ngDevMode ? [{ debugName: "error" }] : []));
|
|
318
|
+
constructor() {
|
|
319
|
+
afterRenderEffect((onCleanup) => {
|
|
320
|
+
const frame = this.appFrame().nativeElement;
|
|
321
|
+
const { data, agent } = this.renderSession();
|
|
322
|
+
const version = ++this.renderVersion;
|
|
323
|
+
const controller = new AbortController();
|
|
324
|
+
this.queue.cancelOwner(this.ownerId);
|
|
325
|
+
this.resetFrame(frame);
|
|
326
|
+
onCleanup(() => {
|
|
327
|
+
controller.abort();
|
|
328
|
+
this.queue.cancelOwner(this.ownerId);
|
|
329
|
+
frame.removeAttribute("srcdoc");
|
|
330
|
+
frame.removeAttribute("src");
|
|
331
|
+
frame.removeAttribute("data-mcp-app-initialized");
|
|
332
|
+
});
|
|
333
|
+
if (!isPlatformBrowser(this.platformId)) {
|
|
334
|
+
this.loading.set(false);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
void this.renderApp(frame, data, agent, controller, version);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async renderApp(frame, data, agent, controller, version) {
|
|
341
|
+
if (!agent) {
|
|
342
|
+
this.fail("No agent is available to load this MCP App.", frame, version);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const runResult = await this.queue.enqueue({
|
|
347
|
+
agent,
|
|
348
|
+
ownerId: this.ownerId,
|
|
349
|
+
execute: () => agent.runAgent({
|
|
350
|
+
forwardedProps: {
|
|
351
|
+
__proxiedMCPRequest: {
|
|
352
|
+
serverHash: data.serverHash,
|
|
353
|
+
serverId: data.serverId,
|
|
354
|
+
method: "resources/read",
|
|
355
|
+
params: { uri: data.resourceUri },
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
}),
|
|
359
|
+
});
|
|
360
|
+
this.throwIfStale(controller.signal, version);
|
|
361
|
+
const resource = findResource(runResult, data.resourceUri);
|
|
362
|
+
const html = resource.text
|
|
363
|
+
? resource.text
|
|
364
|
+
: resource.blob
|
|
365
|
+
? decodeBase64(resource.blob)
|
|
366
|
+
: undefined;
|
|
367
|
+
if (!html) {
|
|
368
|
+
throw new Error("The MCP App resource has no text or blob content.");
|
|
369
|
+
}
|
|
370
|
+
frame.removeAttribute("data-mcp-app-initialized");
|
|
371
|
+
const sandboxReady = this.connectSandbox(frame, data, agent, controller.signal, version);
|
|
372
|
+
frame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
|
|
373
|
+
frame.removeAttribute("src");
|
|
374
|
+
frame.srcdoc = buildSandboxHTML(resource._meta?.ui?.csp?.resourceDomains);
|
|
375
|
+
await sandboxReady;
|
|
376
|
+
this.throwIfStale(controller.signal, version);
|
|
377
|
+
this.sendNotification(frame, "ui/notifications/sandbox-resource-ready", {
|
|
378
|
+
html,
|
|
379
|
+
});
|
|
380
|
+
this.loading.set(false);
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
if (isCancellation(error))
|
|
384
|
+
return;
|
|
385
|
+
this.fail(asError(error).message, frame, version);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
connectSandbox(frame, data, agent, abortSignal, version) {
|
|
389
|
+
return new Promise((resolve, reject) => {
|
|
390
|
+
let ready = false;
|
|
391
|
+
const timeout = setTimeout(() => {
|
|
392
|
+
cleanup();
|
|
393
|
+
reject(new Error(`Timed out waiting ${this.config.initializationTimeoutMs}ms for the MCP App sandbox.`));
|
|
394
|
+
}, this.config.initializationTimeoutMs);
|
|
395
|
+
const cancel = () => {
|
|
396
|
+
cleanup();
|
|
397
|
+
reject(new MCPAppsQueueCancelledError());
|
|
398
|
+
};
|
|
399
|
+
const onMessage = (event) => {
|
|
400
|
+
if (event.source !== frame.contentWindow)
|
|
401
|
+
return;
|
|
402
|
+
const message = parseJSONRPCMessage(event.data);
|
|
403
|
+
if (!message)
|
|
404
|
+
return;
|
|
405
|
+
if (message.method === "ui/notifications/sandbox-proxy-ready") {
|
|
406
|
+
if (!ready) {
|
|
407
|
+
ready = true;
|
|
408
|
+
clearTimeout(timeout);
|
|
409
|
+
resolve();
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
void this.handleMessage(frame, data, agent, message, abortSignal, version);
|
|
414
|
+
};
|
|
415
|
+
const cleanup = () => {
|
|
416
|
+
clearTimeout(timeout);
|
|
417
|
+
window.removeEventListener("message", onMessage);
|
|
418
|
+
abortSignal.removeEventListener("abort", cancel);
|
|
419
|
+
};
|
|
420
|
+
window.addEventListener("message", onMessage);
|
|
421
|
+
abortSignal.addEventListener("abort", cancel, { once: true });
|
|
422
|
+
if (abortSignal.aborted)
|
|
423
|
+
cancel();
|
|
424
|
+
// Keep protocol messages connected after initialization. Cleanup occurs
|
|
425
|
+
// when this render session's abort signal fires.
|
|
426
|
+
abortSignal.addEventListener("abort", () => window.removeEventListener("message", onMessage), { once: true });
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
async handleMessage(frame, data, agent, message, abortSignal, version) {
|
|
430
|
+
if (abortSignal.aborted || version !== this.renderVersion)
|
|
431
|
+
return;
|
|
432
|
+
if (message.id !== undefined) {
|
|
433
|
+
switch (message.method) {
|
|
434
|
+
case "ui/initialize":
|
|
435
|
+
frame.setAttribute("data-mcp-app-initialized", "true");
|
|
436
|
+
this.sendResponse(frame, message.id, {
|
|
437
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
438
|
+
hostInfo: this.config.hostInfo,
|
|
439
|
+
hostCapabilities: this.config.hostCapabilities,
|
|
440
|
+
hostContext: this.config.hostContext,
|
|
441
|
+
});
|
|
442
|
+
return;
|
|
443
|
+
case "ui/message":
|
|
444
|
+
await this.handleUIMessage(frame, agent, message, version);
|
|
445
|
+
return;
|
|
446
|
+
case "ui/open-link":
|
|
447
|
+
this.handleOpenLink(frame, message);
|
|
448
|
+
return;
|
|
449
|
+
case "tools/call":
|
|
450
|
+
await this.handleToolCall(frame, data, agent, message, abortSignal);
|
|
451
|
+
return;
|
|
452
|
+
default:
|
|
453
|
+
this.sendError(frame, message.id, -32601, `Method not found: ${message.method}`);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
switch (message.method) {
|
|
458
|
+
case "ui/notifications/initialized":
|
|
459
|
+
if (data.toolInput) {
|
|
460
|
+
this.sendNotification(frame, "ui/notifications/tool-input", {
|
|
461
|
+
arguments: data.toolInput,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
this.sendNotification(frame, "ui/notifications/tool-result", data.result);
|
|
465
|
+
break;
|
|
466
|
+
case "ui/notifications/size-changed": {
|
|
467
|
+
const height = message.params?.height;
|
|
468
|
+
if (typeof height === "number" &&
|
|
469
|
+
Number.isFinite(height) &&
|
|
470
|
+
height > 0) {
|
|
471
|
+
frame.style.height = `${Math.ceil(Math.min(height, 5000))}px`;
|
|
472
|
+
}
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
case "notifications/message":
|
|
476
|
+
console.info("[CopilotKit MCP App]", message.params ?? {});
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
async handleUIMessage(frame, agent, message, version) {
|
|
481
|
+
const id = message.id;
|
|
482
|
+
const role = message.params?.role === "assistant" ? "assistant" : "user";
|
|
483
|
+
const content = Array.isArray(message.params?.content)
|
|
484
|
+
? message.params.content
|
|
485
|
+
.filter(isTextContent)
|
|
486
|
+
.map((part) => part.text)
|
|
487
|
+
.join("\n")
|
|
488
|
+
: "";
|
|
489
|
+
if (content) {
|
|
490
|
+
agent.addMessage({ id: randomUUID(), role, content });
|
|
491
|
+
}
|
|
492
|
+
this.sendResponse(frame, id, { isError: false });
|
|
493
|
+
const shouldFollowUp = typeof message.params?.followUp === "boolean"
|
|
494
|
+
? message.params.followUp
|
|
495
|
+
: role === "user";
|
|
496
|
+
if (!shouldFollowUp || !content)
|
|
497
|
+
return;
|
|
498
|
+
try {
|
|
499
|
+
await this.queue.enqueue({
|
|
500
|
+
agent,
|
|
501
|
+
ownerId: this.ownerId,
|
|
502
|
+
dropAfterThreadSwitch: true,
|
|
503
|
+
execute: () => this.copilotKit.core.runAgent({ agent }),
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
catch (error) {
|
|
507
|
+
if (isCancellation(error))
|
|
508
|
+
return;
|
|
509
|
+
this.fail(`MCP App follow-up failed: ${asError(error).message}`, frame, version);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
handleOpenLink(frame, message) {
|
|
513
|
+
const id = message.id;
|
|
514
|
+
const url = safeExternalURL(message.params?.url);
|
|
515
|
+
if (!url) {
|
|
516
|
+
this.sendError(frame, id, -32602, "A valid HTTP(S) URL is required.");
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
520
|
+
this.sendResponse(frame, id, { isError: false });
|
|
521
|
+
}
|
|
522
|
+
async handleToolCall(frame, data, agent, message, abortSignal) {
|
|
523
|
+
const id = message.id;
|
|
524
|
+
try {
|
|
525
|
+
const runResult = await this.queue.enqueue({
|
|
526
|
+
agent,
|
|
527
|
+
ownerId: this.ownerId,
|
|
528
|
+
execute: () => agent.runAgent({
|
|
529
|
+
forwardedProps: {
|
|
530
|
+
__proxiedMCPRequest: {
|
|
531
|
+
serverHash: data.serverHash,
|
|
532
|
+
serverId: data.serverId,
|
|
533
|
+
method: "tools/call",
|
|
534
|
+
params: message.params,
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
}),
|
|
538
|
+
});
|
|
539
|
+
if (!abortSignal.aborted)
|
|
540
|
+
this.sendResponse(frame, id, runResult.result ?? {});
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
if (isCancellation(error))
|
|
544
|
+
return;
|
|
545
|
+
this.sendError(frame, id, -32603, asError(error).message);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
sendResponse(frame, id, result) {
|
|
549
|
+
frame.contentWindow?.postMessage({ jsonrpc: "2.0", id, result }, "*");
|
|
550
|
+
}
|
|
551
|
+
sendError(frame, id, code, message) {
|
|
552
|
+
frame.contentWindow?.postMessage({ jsonrpc: "2.0", id, error: { code, message } }, "*");
|
|
553
|
+
}
|
|
554
|
+
sendNotification(frame, method, params) {
|
|
555
|
+
frame.contentWindow?.postMessage({ jsonrpc: "2.0", method, params }, "*");
|
|
556
|
+
}
|
|
557
|
+
fail(message, frame, version) {
|
|
558
|
+
if (version !== this.renderVersion)
|
|
559
|
+
return;
|
|
560
|
+
this.loading.set(false);
|
|
561
|
+
this.error.set(message);
|
|
562
|
+
frame.removeAttribute("srcdoc");
|
|
563
|
+
frame.removeAttribute("src");
|
|
564
|
+
frame.removeAttribute("data-mcp-app-initialized");
|
|
565
|
+
}
|
|
566
|
+
resetFrame(frame) {
|
|
567
|
+
this.loading.set(true);
|
|
568
|
+
this.error.set("");
|
|
569
|
+
frame.style.removeProperty("height");
|
|
570
|
+
frame.removeAttribute("srcdoc");
|
|
571
|
+
frame.removeAttribute("src");
|
|
572
|
+
frame.removeAttribute("data-mcp-app-initialized");
|
|
573
|
+
}
|
|
574
|
+
throwIfStale(abortSignal, version) {
|
|
575
|
+
if (abortSignal.aborted || version !== this.renderVersion) {
|
|
576
|
+
throw new MCPAppsQueueCancelledError();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.26", ngImport: i0, type: CopilotMCPAppsWidget, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
580
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.26", type: CopilotMCPAppsWidget, isStandalone: true, selector: "copilot-mcp-apps-widget", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null }, agent: { classPropertyName: "agent", publicName: "agent", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "appFrame", first: true, predicate: ["appFrame"], descendants: true, isSignal: true }], ngImport: i0, template: `
|
|
581
|
+
<div class="copilot-mcp-apps-container">
|
|
582
|
+
@if (loading()) {
|
|
583
|
+
<p class="copilot-mcp-apps-status" role="status" aria-live="polite">
|
|
584
|
+
Loading MCP App…
|
|
585
|
+
</p>
|
|
586
|
+
}
|
|
587
|
+
@if (error()) {
|
|
588
|
+
<p class="copilot-mcp-apps-error" role="alert">{{ error() }}</p>
|
|
589
|
+
}
|
|
590
|
+
<iframe
|
|
591
|
+
#appFrame
|
|
592
|
+
class="copilot-mcp-apps-frame"
|
|
593
|
+
data-testid="mcp-app-iframe"
|
|
594
|
+
title="Interactive MCP application"
|
|
595
|
+
></iframe>
|
|
596
|
+
</div>
|
|
597
|
+
`, isInline: true, styles: [".copilot-mcp-apps-container{position:relative;width:100%;min-height:100px;overflow:hidden}.copilot-mcp-apps-frame{display:block;width:100%;min-height:100px;border:0;background:transparent}.copilot-mcp-apps-status,.copilot-mcp-apps-error{margin:0;padding:16px}.copilot-mcp-apps-status{color:#525252}.copilot-mcp-apps-error{color:#991b1b}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
598
|
+
}
|
|
599
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.26", ngImport: i0, type: CopilotMCPAppsWidget, decorators: [{
|
|
600
|
+
type: Component,
|
|
601
|
+
args: [{ selector: "copilot-mcp-apps-widget", changeDetection: ChangeDetectionStrategy.OnPush, template: `
|
|
602
|
+
<div class="copilot-mcp-apps-container">
|
|
603
|
+
@if (loading()) {
|
|
604
|
+
<p class="copilot-mcp-apps-status" role="status" aria-live="polite">
|
|
605
|
+
Loading MCP App…
|
|
606
|
+
</p>
|
|
607
|
+
}
|
|
608
|
+
@if (error()) {
|
|
609
|
+
<p class="copilot-mcp-apps-error" role="alert">{{ error() }}</p>
|
|
610
|
+
}
|
|
611
|
+
<iframe
|
|
612
|
+
#appFrame
|
|
613
|
+
class="copilot-mcp-apps-frame"
|
|
614
|
+
data-testid="mcp-app-iframe"
|
|
615
|
+
title="Interactive MCP application"
|
|
616
|
+
></iframe>
|
|
617
|
+
</div>
|
|
618
|
+
`, styles: [".copilot-mcp-apps-container{position:relative;width:100%;min-height:100px;overflow:hidden}.copilot-mcp-apps-frame{display:block;width:100%;min-height:100px;border:0;background:transparent}.copilot-mcp-apps-status,.copilot-mcp-apps-error{margin:0;padding:16px}.copilot-mcp-apps-status{color:#525252}.copilot-mcp-apps-error{color:#991b1b}\n"] }]
|
|
619
|
+
}], ctorParameters: () => [], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: true }] }], agent: [{ type: i0.Input, args: [{ isSignal: true, alias: "agent", required: false }] }], appFrame: [{ type: i0.ViewChild, args: ["appFrame", { isSignal: true }] }] } });
|
|
620
|
+
function queueForTimeout(idleTimeoutMs) {
|
|
621
|
+
let queue = queuesByIdleTimeout.get(idleTimeoutMs);
|
|
622
|
+
if (!queue) {
|
|
623
|
+
queue = new MCPAppsRequestQueue({ idleTimeoutMs });
|
|
624
|
+
queuesByIdleTimeout.set(idleTimeoutMs, queue);
|
|
625
|
+
}
|
|
626
|
+
return queue;
|
|
627
|
+
}
|
|
628
|
+
function findResource(runResult, resourceUri) {
|
|
629
|
+
const result = runResult.result;
|
|
630
|
+
const resource = result?.contents?.find((candidate) => candidate.uri === resourceUri);
|
|
631
|
+
if (!resource) {
|
|
632
|
+
throw new Error(`No matching MCP App resource was returned for "${resourceUri}".`);
|
|
633
|
+
}
|
|
634
|
+
return resource;
|
|
635
|
+
}
|
|
636
|
+
function parseJSONRPCMessage(value) {
|
|
637
|
+
if (!isRecord(value) ||
|
|
638
|
+
value.jsonrpc !== "2.0" ||
|
|
639
|
+
typeof value.method !== "string") {
|
|
640
|
+
return undefined;
|
|
641
|
+
}
|
|
642
|
+
if (value.id !== undefined &&
|
|
643
|
+
typeof value.id !== "string" &&
|
|
644
|
+
typeof value.id !== "number") {
|
|
645
|
+
return undefined;
|
|
646
|
+
}
|
|
647
|
+
if (value.params !== undefined && !isRecord(value.params))
|
|
648
|
+
return undefined;
|
|
649
|
+
return value;
|
|
650
|
+
}
|
|
651
|
+
function isRecord(value) {
|
|
652
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
653
|
+
}
|
|
654
|
+
function isTextContent(value) {
|
|
655
|
+
return (isRecord(value) && value.type === "text" && typeof value.text === "string");
|
|
656
|
+
}
|
|
657
|
+
function safeExternalURL(value) {
|
|
658
|
+
if (typeof value !== "string")
|
|
659
|
+
return undefined;
|
|
660
|
+
try {
|
|
661
|
+
const url = new URL(value, window.location.href);
|
|
662
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
663
|
+
return undefined;
|
|
664
|
+
if (url.username || url.password)
|
|
665
|
+
return undefined;
|
|
666
|
+
return url.href;
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function decodeBase64(value) {
|
|
673
|
+
try {
|
|
674
|
+
const binary = atob(value);
|
|
675
|
+
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
676
|
+
return new TextDecoder().decode(bytes);
|
|
677
|
+
}
|
|
678
|
+
catch {
|
|
679
|
+
throw new Error("The MCP App resource contains invalid base64 content.");
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function isCancellation(error) {
|
|
683
|
+
return (error instanceof MCPAppsQueueCancelledError ||
|
|
684
|
+
error instanceof MCPAppsQueueThreadChangedError);
|
|
685
|
+
}
|
|
686
|
+
function asError(error) {
|
|
687
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
688
|
+
}
|
|
689
|
+
/** Compares JSON-compatible activity snapshots without relying on object identity. */
|
|
690
|
+
function areStructurallyEqual(left, right) {
|
|
691
|
+
if (Object.is(left, right))
|
|
692
|
+
return true;
|
|
693
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
694
|
+
return (Array.isArray(left) &&
|
|
695
|
+
Array.isArray(right) &&
|
|
696
|
+
left.length === right.length &&
|
|
697
|
+
left.every((value, index) => areStructurallyEqual(value, right[index])));
|
|
698
|
+
}
|
|
699
|
+
if (!isRecord(left) || !isRecord(right))
|
|
700
|
+
return false;
|
|
701
|
+
const leftKeys = Object.keys(left);
|
|
702
|
+
const rightKeys = Object.keys(right);
|
|
703
|
+
return (leftKeys.length === rightKeys.length &&
|
|
704
|
+
leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) &&
|
|
705
|
+
areStructurallyEqual(left[key], right[key])));
|
|
706
|
+
}
|
|
707
|
+
function buildSandboxHTML(extraCspDomains) {
|
|
708
|
+
const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
709
|
+
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
710
|
+
const extra = extraCspDomains?.length ? ` ${extraCspDomains.join(" ")}` : "";
|
|
711
|
+
const scriptSrc = baseScriptSrc + extra;
|
|
712
|
+
const frameSrc = baseFrameSrc + extra;
|
|
713
|
+
return `<!doctype html>
|
|
714
|
+
<html>
|
|
715
|
+
<head>
|
|
716
|
+
<meta charset="utf-8" />
|
|
717
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${scriptSrc}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${frameSrc}; base-uri 'self';" />
|
|
718
|
+
<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>
|
|
719
|
+
</head>
|
|
720
|
+
<body>
|
|
721
|
+
<script>
|
|
722
|
+
if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
|
|
723
|
+
const inner=document.createElement("iframe");
|
|
724
|
+
inner.style="width:100%;height:100%;border:none;";
|
|
725
|
+
inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
|
|
726
|
+
document.body.appendChild(inner);
|
|
727
|
+
window.addEventListener("message",async(event)=>{
|
|
728
|
+
if(event.source===window.parent){
|
|
729
|
+
if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
|
|
730
|
+
const{html,sandbox}=event.data.params;
|
|
731
|
+
if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
|
|
732
|
+
if(typeof html==="string")inner.srcdoc=html;
|
|
733
|
+
}else if(inner&&inner.contentWindow){
|
|
734
|
+
inner.contentWindow.postMessage(event.data,"*");
|
|
735
|
+
}
|
|
736
|
+
}else if(event.source===inner.contentWindow){window.parent.postMessage(event.data,"*")}
|
|
737
|
+
});
|
|
738
|
+
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
|
|
739
|
+
</script>
|
|
740
|
+
</body>
|
|
741
|
+
</html>`;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Activity renderer for `mcp-apps` snapshots. Renders the referenced MCP App
|
|
746
|
+
* inline via {@link CopilotMCPAppsWidget}. Resource and tool requests are
|
|
747
|
+
* proxied through the activity's selected AG-UI agent.
|
|
748
|
+
*/
|
|
749
|
+
class CopilotMCPAppsActivityRenderer {
|
|
750
|
+
activityType = input.required(...(ngDevMode ? [{ debugName: "activityType" }] : []));
|
|
751
|
+
content = input.required(...(ngDevMode ? [{ debugName: "content" }] : []));
|
|
752
|
+
message = input.required(...(ngDevMode ? [{ debugName: "message" }] : []));
|
|
753
|
+
agent = input(...(ngDevMode ? [undefined, { debugName: "agent" }] : []));
|
|
754
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.26", ngImport: i0, type: CopilotMCPAppsActivityRenderer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
755
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "20.3.26", type: CopilotMCPAppsActivityRenderer, isStandalone: true, selector: "copilot-mcp-apps-activity-renderer", inputs: { activityType: { classPropertyName: "activityType", publicName: "activityType", isSignal: true, isRequired: true, transformFunction: null }, content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: true, transformFunction: null }, message: { classPropertyName: "message", publicName: "message", isSignal: true, isRequired: true, transformFunction: null }, agent: { classPropertyName: "agent", publicName: "agent", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: `
|
|
756
|
+
<copilot-mcp-apps-widget [data]="content()" [agent]="agent()" />
|
|
757
|
+
`, isInline: true, dependencies: [{ kind: "component", type: CopilotMCPAppsWidget, selector: "copilot-mcp-apps-widget", inputs: ["data", "agent"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
758
|
+
}
|
|
759
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.26", ngImport: i0, type: CopilotMCPAppsActivityRenderer, decorators: [{
|
|
760
|
+
type: Component,
|
|
761
|
+
args: [{
|
|
762
|
+
selector: "copilot-mcp-apps-activity-renderer",
|
|
763
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
764
|
+
imports: [CopilotMCPAppsWidget],
|
|
765
|
+
template: `
|
|
766
|
+
<copilot-mcp-apps-widget [data]="content()" [agent]="agent()" />
|
|
767
|
+
`,
|
|
768
|
+
}]
|
|
769
|
+
}], propDecorators: { activityType: [{ type: i0.Input, args: [{ isSignal: true, alias: "activityType", required: true }] }], content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: true }] }], message: [{ type: i0.Input, args: [{ isSignal: true, alias: "message", required: true }] }], agent: [{ type: i0.Input, args: [{ isSignal: true, alias: "agent", required: false }] }] } });
|
|
770
|
+
/**
|
|
771
|
+
* Ready-to-register render config for `mcp-apps` activity messages. Pass it
|
|
772
|
+
* to `provideCopilotKit({ renderActivityMessages: [...] })`.
|
|
773
|
+
*/
|
|
774
|
+
const mcpAppsActivityRendererConfig = {
|
|
775
|
+
activityType: "mcp-apps",
|
|
776
|
+
content: mcpAppsSnapshotContentSchema,
|
|
777
|
+
component: CopilotMCPAppsActivityRenderer,
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Configures and registers the built-in MCP Apps renderer.
|
|
782
|
+
*
|
|
783
|
+
* MCP resource and tool requests always travel through the selected AG-UI
|
|
784
|
+
* agent. Server URLs deliberately are not accepted by this browser provider.
|
|
785
|
+
* Application renderers retain precedence over this built-in registration.
|
|
786
|
+
*/
|
|
787
|
+
function provideMCPApps(config = {}) {
|
|
788
|
+
return makeEnvironmentProviders([
|
|
789
|
+
{
|
|
790
|
+
provide: MCP_APPS_CONFIG,
|
|
791
|
+
useValue: {
|
|
792
|
+
...DEFAULT_MCP_APPS_CONFIG,
|
|
793
|
+
...config,
|
|
794
|
+
hostInfo: {
|
|
795
|
+
...DEFAULT_MCP_APPS_CONFIG.hostInfo,
|
|
796
|
+
...config.hostInfo,
|
|
797
|
+
},
|
|
798
|
+
hostCapabilities: {
|
|
799
|
+
...DEFAULT_MCP_APPS_CONFIG.hostCapabilities,
|
|
800
|
+
...config.hostCapabilities,
|
|
801
|
+
},
|
|
802
|
+
hostContext: {
|
|
803
|
+
...DEFAULT_MCP_APPS_CONFIG.hostContext,
|
|
804
|
+
...config.hostContext,
|
|
805
|
+
},
|
|
806
|
+
},
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
provide: _COPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS,
|
|
810
|
+
multi: true,
|
|
811
|
+
useValue: mcpAppsActivityRendererConfig,
|
|
812
|
+
},
|
|
813
|
+
]);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Generated bundle index. Do not edit.
|
|
818
|
+
*/
|
|
819
|
+
|
|
820
|
+
export { CopilotMCPAppsActivityRenderer, CopilotMCPAppsWidget, DEFAULT_MCP_APPS_CONFIG, MCP_APPS_CONFIG, mcpAppsActivityRendererConfig, mcpAppsSnapshotContentSchema, provideMCPApps };
|
|
821
|
+
//# sourceMappingURL=copilotkit-angular-mcp-apps.mjs.map
|