@tylertech/forge-ai 0.15.2 → 0.15.3-dev.1

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.
Files changed (88) hide show
  1. package/custom-elements.json +4501 -1781
  2. package/dist/ai-artifact-card/ai-artifact-card.d.ts +75 -0
  3. package/dist/ai-artifact-card/ai-artifact-card.mjs +142 -0
  4. package/dist/ai-artifact-card/ai-artifact-card.scss.mjs +283 -0
  5. package/dist/ai-artifact-card/index.d.ts +1 -0
  6. package/dist/ai-artifact-card/index.mjs +5 -0
  7. package/dist/ai-artifact-card-group/ai-artifact-card-group.d.ts +57 -0
  8. package/dist/ai-artifact-card-group/ai-artifact-card-group.mjs +137 -0
  9. package/dist/ai-artifact-card-group/ai-artifact-card-group.scss.mjs +173 -0
  10. package/dist/ai-artifact-card-group/index.d.ts +1 -0
  11. package/dist/ai-artifact-card-group/index.mjs +5 -0
  12. package/dist/ai-assistant-response/ai-assistant-response.d.ts +2 -2
  13. package/dist/ai-assistant-response/ai-assistant-response.mjs +26 -2
  14. package/dist/ai-canvas/ai-canvas.d.ts +43 -0
  15. package/dist/ai-canvas/ai-canvas.mjs +95 -0
  16. package/dist/ai-canvas/ai-canvas.scss.mjs +4 -0
  17. package/dist/ai-canvas/index.d.ts +1 -0
  18. package/dist/ai-canvas/index.mjs +5 -0
  19. package/dist/ai-chatbot/ag-ui-adapter.d.ts +2 -2
  20. package/dist/ai-chatbot/ag-ui-adapter.mjs +1 -1
  21. package/dist/ai-chatbot/agent-adapter.d.ts +111 -4
  22. package/dist/ai-chatbot/agent-adapter.mjs +22 -0
  23. package/dist/ai-chatbot/agent-runner.d.ts +2 -2
  24. package/dist/ai-chatbot/ai-chatbot-base.d.ts +29 -2
  25. package/dist/ai-chatbot/ai-chatbot-base.mjs +147 -3
  26. package/dist/ai-chatbot/ai-chatbot-tool-call.d.ts +2 -2
  27. package/dist/ai-chatbot/ai-chatbot-tool-call.mjs +88 -10
  28. package/dist/ai-chatbot/ai-chatbot.d.ts +24 -1
  29. package/dist/ai-chatbot/ai-chatbot.mjs +102 -2
  30. package/dist/ai-chatbot/ai-chatbot.scss.mjs +1 -1
  31. package/dist/ai-chatbot/create-tool-renderer.d.ts +5 -5
  32. package/dist/ai-chatbot/index.d.ts +3 -2
  33. package/dist/ai-chatbot/index.mjs +3 -0
  34. package/dist/ai-chatbot/message-state-controller.d.ts +10 -1
  35. package/dist/ai-chatbot/message-state-controller.mjs +78 -20
  36. package/dist/ai-chatbot/tool-canvas.d.ts +60 -0
  37. package/dist/ai-chatbot/tool-canvas.mjs +128 -0
  38. package/dist/ai-chatbot/types.d.ts +325 -15
  39. package/dist/ai-chatbot/utils.d.ts +8 -3
  40. package/dist/ai-chatbot/utils.mjs +7 -1
  41. package/dist/ai-chatbot-launcher/ai-chatbot-launcher.d.ts +40 -2
  42. package/dist/ai-chatbot-launcher/ai-chatbot-launcher.mjs +224 -7
  43. package/dist/ai-chatbot-launcher/ai-chatbot-launcher.scss.mjs +1 -1
  44. package/dist/ai-embedded-chat/ai-embedded-chat.mjs +1 -0
  45. package/dist/ai-message-thread/ai-message-thread.d.ts +3 -2
  46. package/dist/ai-message-thread/ai-message-thread.mjs +36 -3
  47. package/dist/ai-steps/ai-steps.d.ts +67 -0
  48. package/dist/ai-steps/ai-steps.mjs +163 -0
  49. package/dist/ai-steps/ai-steps.scss.mjs +4 -0
  50. package/dist/ai-steps/index.d.ts +1 -0
  51. package/dist/ai-steps/index.mjs +5 -0
  52. package/dist/ai-tool-call-indicator/ai-tool-call-indicator.d.ts +2 -2
  53. package/dist/ai-tool-call-indicator/ai-tool-call-indicator.mjs +1 -1
  54. package/dist/core/canvas-controller.d.ts +81 -0
  55. package/dist/core/canvas-controller.mjs +221 -0
  56. package/dist/core/chatbot-core-controller.d.ts +4 -2
  57. package/dist/core/chatbot-core-controller.mjs +121 -4
  58. package/dist/core/index.d.ts +2 -1
  59. package/dist/core/index.mjs +2 -0
  60. package/dist/core/resize-controller.d.ts +5 -0
  61. package/dist/core/resize-controller.mjs +7 -5
  62. package/dist/index.d.ts +4 -0
  63. package/dist/index.mjs +15 -0
  64. package/dist/tools/ai-data-table/ai-data-table-definition.mjs +1 -0
  65. package/dist/tools/ai-mcp-app/ai-mcp-app.d.ts +70 -0
  66. package/dist/tools/ai-mcp-app/ai-mcp-app.mjs +589 -0
  67. package/dist/tools/ai-mcp-app/ai-mcp-app.scss.mjs +4 -0
  68. package/dist/tools/ai-mcp-app/index.d.ts +3 -0
  69. package/dist/tools/ai-mcp-app/index.mjs +6 -0
  70. package/dist/tools/ai-mcp-app/mcp-app-bridge-controller.d.ts +60 -0
  71. package/dist/tools/ai-mcp-app/mcp-app-bridge-controller.mjs +147 -0
  72. package/dist/tools/ai-mcp-app/mcp-app-bridge-types.d.ts +124 -0
  73. package/dist/tools/ai-mcp-app/mcp-app-bridge.d.ts +41 -0
  74. package/dist/tools/ai-mcp-app/mcp-app-bridge.mjs +293 -0
  75. package/dist/tools/ai-mcp-app/mcp-app-context.d.ts +46 -0
  76. package/dist/tools/ai-mcp-app/mcp-app-context.mjs +5 -0
  77. package/dist/tools/ai-steps/ai-steps-definition.d.ts +2 -0
  78. package/dist/tools/ai-steps/ai-steps-definition.mjs +51 -0
  79. package/dist/tools/ai-steps/ai-steps.d.ts +28 -0
  80. package/dist/tools/ai-steps/ai-steps.mjs +49 -0
  81. package/dist/tools/ai-steps/ai-steps.scss.mjs +4 -0
  82. package/dist/tools/ai-steps/index.d.ts +2 -0
  83. package/dist/tools/ai-steps/index.mjs +6 -0
  84. package/dist/tools/index.d.ts +1 -0
  85. package/dist/tools/index.mjs +5 -1
  86. package/dist/utils/inert-outside.d.ts +7 -0
  87. package/dist/utils/inert-outside.mjs +28 -0
  88. package/package.json +4 -1
@@ -0,0 +1,70 @@
1
+ import { LitElement, PropertyValues, TemplateResult, nothing, CSSResult } from 'lit';
2
+ import { IToolRenderer, McpAppDisplayMode, McpModelContextUpdateParams, ToolCall, ToolDefinition } from '../../ai-chatbot';
3
+ import { McpAppLoggingMessage } from './mcp-app-bridge-types.js';
4
+ import { McpAppHost } from './mcp-app-context.js';
5
+ declare global {
6
+ interface HTMLElementTagNameMap {
7
+ 'forge-ai-mcp-app': McpAppToolElement;
8
+ }
9
+ interface HTMLElementEventMap {
10
+ 'forge-ai-mcp-app-open-link': CustomEvent<{
11
+ url: string;
12
+ }>;
13
+ 'forge-ai-mcp-app-message': CustomEvent<{
14
+ content: unknown[];
15
+ role: 'user';
16
+ }>;
17
+ 'forge-ai-mcp-app-logging-message': CustomEvent<McpAppLoggingMessage>;
18
+ 'forge-ai-mcp-app-request-teardown': CustomEvent<{
19
+ toolCallId: string;
20
+ }>;
21
+ 'forge-ai-mcp-app-request-display-mode': CustomEvent<{
22
+ mode: McpAppDisplayMode;
23
+ }>;
24
+ 'forge-ai-mcp-app-update-model-context': CustomEvent<McpModelContextUpdateParams>;
25
+ }
26
+ }
27
+ /**
28
+ * Renders an MCP-app UI resource stamped onto a {@link ToolCall} as a sandboxed,
29
+ * cross-origin widget. The iframe + bridge are mounted once and survive every `toolCall`
30
+ * delta (Lit reuses this node at its keyed position), so args stream live without
31
+ * remounting. While `uiResourceStatus` is `loading` it renders a skeleton placeholder in the
32
+ * same position, and connects once `uiResource` is stamped onto the same element.
33
+ *
34
+ * The cross-origin sandbox is mandatory: when no `sandboxUrl` is available the element
35
+ * renders an error artifact rather than an insecure same-origin iframe.
36
+ *
37
+ * @tag forge-ai-mcp-app
38
+ * @internal
39
+ *
40
+ * @event {CustomEvent<{ url: string }>} forge-ai-mcp-app-open-link - Fired (cancelable) when the app requests to open an http(s)/mailto link; unless `preventDefault()` is called, the user is asked to confirm and the link opens in a new tab
41
+ * @event {CustomEvent<{ content: unknown[]; role: 'user' }>} forge-ai-mcp-app-message - Fired when the app sends a `ui/message`, before its text is placed in the prompt for the user to send
42
+ * @event {CustomEvent<McpAppLoggingMessage>} forge-ai-mcp-app-logging-message - Fired (cancelable) when the app sends a logging message; logged to the console unless `preventDefault()` is called
43
+ * @event {CustomEvent<{ toolCallId: string }>} forge-ai-mcp-app-request-teardown - Fired (cancelable) when the app asks to be torn down; the host tears the widget down unless `preventDefault()` is called
44
+ * @event {CustomEvent<{ mode: McpAppDisplayMode }>} forge-ai-mcp-app-request-display-mode - Fired when the app's display mode changes
45
+ * @event {CustomEvent<McpModelContextUpdateParams>} forge-ai-mcp-app-update-model-context - Fired when the app updates model context; detail carries `toolCallId`, `content` and `structuredContent`
46
+ */
47
+ export declare class McpAppToolElement extends LitElement implements IToolRenderer {
48
+ #private;
49
+ static styles: CSSResult;
50
+ toolCall: ToolCall;
51
+ /** Client-side definition of the tool, when one is registered; supplies `toolInfo.tool`. */
52
+ toolDefinition?: ToolDefinition;
53
+ host?: McpAppHost;
54
+ private _iframe;
55
+ private _container;
56
+ private _displayMode;
57
+ private _lifecycle;
58
+ private _pendingLink;
59
+ firstUpdated(): void;
60
+ updated(changedProperties: PropertyValues): void;
61
+ connectedCallback(): void;
62
+ disconnectedCallback(): void;
63
+ /**
64
+ * Send `ui/resource-teardown` to the View and release the bridge without waiting for the
65
+ * ack. The chatbot calls this when removing widgets; it also runs on disconnect as a
66
+ * fallback. A later `toolCall` update remounts the widget.
67
+ */
68
+ teardown(): void;
69
+ render(): TemplateResult | typeof nothing;
70
+ }
@@ -0,0 +1,589 @@
1
+ import { consume } from "@lit/context";
2
+ import { unsafeCSS, LitElement, html, nothing } from "lit";
3
+ import { property, query, state, customElement } from "lit/decorators.js";
4
+ import { classMap } from "lit/directives/class-map.js";
5
+ import { inertOutside } from "../../utils/inert-outside.mjs";
6
+ import { McpAppBridge } from "./mcp-app-bridge.mjs";
7
+ import { mcpAppHostContext } from "./mcp-app-context.mjs";
8
+ import { McpAppBridgeController, enforcedPermissions } from "./mcp-app-bridge-controller.mjs";
9
+ import "../../ai-empty-state/ai-empty-state.mjs";
10
+ import "../../ai-confirmation-prompt/ai-confirmation-prompt.mjs";
11
+ import styles from "./ai-mcp-app.scss.mjs";
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __typeError = (msg) => {
15
+ throw TypeError(msg);
16
+ };
17
+ var __decorateClass = (decorators, target, key, kind) => {
18
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
19
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
20
+ if (decorator = decorators[i])
21
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
22
+ if (kind && result) __defProp(target, key, result);
23
+ return result;
24
+ };
25
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
26
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
27
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
28
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
29
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
30
+ var _controller, _lastHostContext, _unregisterView, _containerDimensions, _hostStyles, _restorePage, _resizeFrame, _resizeObserver, _McpAppToolElement_instances, uiResource_get, hasPolicy_get, canRender_get, canConnect_get, isLoading_get, errorBody_get, hostContext_get, toolInfo_get, hostCapabilities_get, handlers_get, setDisplayMode_fn, applyDisplayMode_fn, releasePage_fn, connect_fn, syncHostContext_fn, resolveHostStyles_fn, scheduleContainerMeasure_fn, cancelContainerMeasure_fn, readContainerDimensions_fn, measureContainer_fn, openLink_fn, settlePendingLink_fn, confirmLink_fn, dispatchMessage_fn, handleLoggingMessage_fn, handleRequestTeardown_fn, dispatchRequestDisplayMode_fn, dispatchUpdateModelContext_fn, _iframe, _promotedToolbar, linkConfirmation_get, isPromoted_get, exitToInline_fn, handleContainerKeydown_fn, bordered_get, _loadingPlaceholder, errorArtifact_get;
31
+ const HOST_INFO = { name: "forge-ai", version: "1.0.0" };
32
+ const MAX_INLINE_HEIGHT = 2e3;
33
+ const OPEN_LINK_PROTOCOLS = ["http:", "https:", "mailto:"];
34
+ const HOST_STYLE_KEYS = [
35
+ "color-background-primary",
36
+ "color-background-secondary",
37
+ "color-background-tertiary",
38
+ "color-background-inverse",
39
+ "color-background-info",
40
+ "color-background-danger",
41
+ "color-background-success",
42
+ "color-background-warning",
43
+ "color-text-primary",
44
+ "color-text-secondary",
45
+ "color-text-tertiary",
46
+ "color-text-inverse",
47
+ "color-text-info",
48
+ "color-text-danger",
49
+ "color-text-success",
50
+ "color-text-warning",
51
+ "color-text-disabled",
52
+ "color-border-primary",
53
+ "color-border-secondary",
54
+ "color-border-info",
55
+ "color-border-danger",
56
+ "color-border-success",
57
+ "color-border-warning",
58
+ "color-ring-primary",
59
+ "font-sans",
60
+ "font-weight-normal",
61
+ "font-weight-medium",
62
+ "font-weight-bold",
63
+ "font-text-xs-size",
64
+ "font-text-sm-size",
65
+ "font-text-md-size",
66
+ "font-text-lg-size",
67
+ "font-text-xs-line-height",
68
+ "font-text-sm-line-height",
69
+ "font-text-md-line-height",
70
+ "font-text-lg-line-height",
71
+ "font-heading-sm-size",
72
+ "font-heading-md-size",
73
+ "font-heading-lg-size",
74
+ "font-heading-xl-size",
75
+ "font-heading-2xl-size",
76
+ "font-heading-3xl-size",
77
+ "font-heading-sm-line-height",
78
+ "font-heading-md-line-height",
79
+ "font-heading-lg-line-height",
80
+ "font-heading-xl-line-height",
81
+ "font-heading-2xl-line-height",
82
+ "font-heading-3xl-line-height",
83
+ "border-radius-xs",
84
+ "border-radius-sm",
85
+ "border-radius-md",
86
+ "border-radius-lg",
87
+ "border-radius-xl",
88
+ "border-radius-full",
89
+ "border-width-regular",
90
+ "shadow-sm",
91
+ "shadow-md",
92
+ "shadow-lg"
93
+ ];
94
+ const CONSOLE_LEVELS = {
95
+ debug: "debug",
96
+ info: "info",
97
+ notice: "info",
98
+ warning: "warn",
99
+ error: "error",
100
+ critical: "error",
101
+ alert: "error",
102
+ emergency: "error"
103
+ };
104
+ function asOpenableUrl(url) {
105
+ try {
106
+ const parsed = new URL(url);
107
+ return OPEN_LINK_PROTOCOLS.includes(parsed.protocol) ? parsed.href : null;
108
+ } catch {
109
+ return null;
110
+ }
111
+ }
112
+ let McpAppToolElement = class extends LitElement {
113
+ constructor() {
114
+ super(...arguments);
115
+ __privateAdd(this, _McpAppToolElement_instances);
116
+ this._displayMode = "inline";
117
+ this._lifecycle = "live";
118
+ this._pendingLink = null;
119
+ __privateAdd(this, _controller, null);
120
+ __privateAdd(this, _lastHostContext, null);
121
+ __privateAdd(this, _unregisterView, null);
122
+ __privateAdd(this, _containerDimensions, { maxHeight: MAX_INLINE_HEIGHT });
123
+ __privateAdd(this, _hostStyles, {});
124
+ __privateAdd(this, _restorePage, null);
125
+ __privateAdd(this, _resizeFrame, null);
126
+ __privateAdd(this, _resizeObserver, new ResizeObserver(() => __privateMethod(this, _McpAppToolElement_instances, scheduleContainerMeasure_fn).call(this)));
127
+ __privateAdd(this, _iframe, html`<iframe title="MCP application" sandbox="allow-scripts allow-same-origin"></iframe>`);
128
+ __privateAdd(this, _promotedToolbar, html`
129
+ <div class="promoted-toolbar">
130
+ <button
131
+ class="forge-icon-button forge-icon-button--medium exit-button"
132
+ aria-label="Exit to inline view"
133
+ @click=${() => __privateMethod(this, _McpAppToolElement_instances, exitToInline_fn).call(this)}>
134
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
135
+ <path fill="none" d="M0 0h24v24H0z" />
136
+ <path
137
+ d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
138
+ </svg>
139
+ </button>
140
+ </div>
141
+ `);
142
+ __privateAdd(this, _loadingPlaceholder, html`
143
+ <div class="container loading" role="status" aria-label="Loading app">
144
+ <div class="forge-skeleton"></div>
145
+ </div>
146
+ `);
147
+ }
148
+ firstUpdated() {
149
+ __privateMethod(this, _McpAppToolElement_instances, connect_fn).call(this);
150
+ }
151
+ updated(changedProperties) {
152
+ if (!__privateGet(this, _controller)) {
153
+ __privateMethod(this, _McpAppToolElement_instances, connect_fn).call(this);
154
+ return;
155
+ }
156
+ __privateGet(this, _controller).syncToolCall(this.toolCall);
157
+ if (changedProperties.has("_displayMode")) {
158
+ __privateMethod(this, _McpAppToolElement_instances, applyDisplayMode_fn).call(this);
159
+ __privateSet(this, _containerDimensions, __privateMethod(this, _McpAppToolElement_instances, readContainerDimensions_fn).call(this) ?? __privateGet(this, _containerDimensions));
160
+ }
161
+ __privateMethod(this, _McpAppToolElement_instances, syncHostContext_fn).call(this, changedProperties);
162
+ }
163
+ connectedCallback() {
164
+ super.connectedCallback();
165
+ if (this.hasUpdated && !__privateGet(this, _controller)) {
166
+ this.requestUpdate();
167
+ }
168
+ }
169
+ disconnectedCallback() {
170
+ super.disconnectedCallback();
171
+ __privateGet(this, _resizeObserver).disconnect();
172
+ __privateMethod(this, _McpAppToolElement_instances, cancelContainerMeasure_fn).call(this);
173
+ __privateMethod(this, _McpAppToolElement_instances, releasePage_fn).call(this);
174
+ this.teardown();
175
+ }
176
+ /**
177
+ * Send `ui/resource-teardown` to the View and release the bridge without waiting for the
178
+ * ack. The chatbot calls this when removing widgets; it also runs on disconnect as a
179
+ * fallback. A later `toolCall` update remounts the widget.
180
+ */
181
+ teardown() {
182
+ var _a;
183
+ __privateMethod(this, _McpAppToolElement_instances, settlePendingLink_fn).call(this, { isError: true });
184
+ (_a = __privateGet(this, _unregisterView)) == null ? void 0 : _a.call(this);
185
+ __privateSet(this, _unregisterView, null);
186
+ const controller = __privateGet(this, _controller);
187
+ __privateSet(this, _controller, null);
188
+ controller?.teardown();
189
+ }
190
+ render() {
191
+ if (this._lifecycle === "closed") {
192
+ return nothing;
193
+ }
194
+ if (__privateGet(this, _McpAppToolElement_instances, isLoading_get)) {
195
+ return __privateGet(this, _loadingPlaceholder);
196
+ }
197
+ if (!__privateGet(this, _McpAppToolElement_instances, canRender_get)) {
198
+ return __privateGet(this, _McpAppToolElement_instances, errorArtifact_get);
199
+ }
200
+ return html`
201
+ <div
202
+ class=${classMap({
203
+ container: true,
204
+ bordered: __privateGet(this, _McpAppToolElement_instances, bordered_get),
205
+ fullscreen: this._displayMode === "fullscreen",
206
+ pip: this._displayMode === "pip"
207
+ })}
208
+ popover="manual"
209
+ role=${__privateGet(this, _McpAppToolElement_instances, isPromoted_get) ? "dialog" : nothing}
210
+ aria-label=${__privateGet(this, _McpAppToolElement_instances, isPromoted_get) ? "MCP application" : nothing}
211
+ data-handles-escape
212
+ @keydown=${__privateMethod(this, _McpAppToolElement_instances, handleContainerKeydown_fn)}>
213
+ ${__privateGet(this, _McpAppToolElement_instances, isPromoted_get) ? __privateGet(this, _promotedToolbar) : nothing} ${__privateGet(this, _iframe)} ${__privateGet(this, _McpAppToolElement_instances, linkConfirmation_get)}
214
+ </div>
215
+ `;
216
+ }
217
+ };
218
+ _controller = /* @__PURE__ */ new WeakMap();
219
+ _lastHostContext = /* @__PURE__ */ new WeakMap();
220
+ _unregisterView = /* @__PURE__ */ new WeakMap();
221
+ _containerDimensions = /* @__PURE__ */ new WeakMap();
222
+ _hostStyles = /* @__PURE__ */ new WeakMap();
223
+ _restorePage = /* @__PURE__ */ new WeakMap();
224
+ _resizeFrame = /* @__PURE__ */ new WeakMap();
225
+ _resizeObserver = /* @__PURE__ */ new WeakMap();
226
+ _McpAppToolElement_instances = /* @__PURE__ */ new WeakSet();
227
+ uiResource_get = function() {
228
+ return this.toolCall?.uiResource;
229
+ };
230
+ hasPolicy_get = function() {
231
+ const resource = __privateGet(this, _McpAppToolElement_instances, uiResource_get);
232
+ return !!resource && resource.csp !== void 0 && resource.permissions !== void 0;
233
+ };
234
+ canRender_get = function() {
235
+ return !!__privateGet(this, _McpAppToolElement_instances, uiResource_get)?.html && !!this.host?.sandboxUrl && __privateGet(this, _McpAppToolElement_instances, hasPolicy_get);
236
+ };
237
+ canConnect_get = function() {
238
+ return this._lifecycle === "live" && __privateGet(this, _McpAppToolElement_instances, canRender_get);
239
+ };
240
+ isLoading_get = function() {
241
+ return !__privateGet(this, _McpAppToolElement_instances, uiResource_get) && this.toolCall?.uiResourceStatus === "loading";
242
+ };
243
+ errorBody_get = function() {
244
+ if (!__privateGet(this, _McpAppToolElement_instances, uiResource_get) && this.toolCall?.uiResourceStatus === "error") {
245
+ return "This interactive app can't be shown because it failed to load.";
246
+ }
247
+ if (!this.host?.sandboxUrl) {
248
+ return "This interactive app can't be shown because no secure sandbox is configured.";
249
+ }
250
+ return "This interactive app can't be shown because its security policy is missing.";
251
+ };
252
+ hostContext_get = function() {
253
+ return {
254
+ ...this.host?.hostContext ?? { theme: "light" },
255
+ styles: __privateGet(this, _hostStyles),
256
+ toolInfo: __privateGet(this, _McpAppToolElement_instances, toolInfo_get),
257
+ containerDimensions: __privateGet(this, _containerDimensions),
258
+ displayMode: this._displayMode
259
+ };
260
+ };
261
+ toolInfo_get = function() {
262
+ const definition = this.toolDefinition;
263
+ return {
264
+ id: this.toolCall.id,
265
+ tool: {
266
+ name: this.toolCall.name,
267
+ ...definition?.description ? { description: definition.description } : {},
268
+ ...definition?.displayName ? { title: definition.displayName } : {},
269
+ inputSchema: { ...definition?.parameters, type: "object" }
270
+ }
271
+ };
272
+ };
273
+ hostCapabilities_get = function() {
274
+ const resource = __privateGet(this, _McpAppToolElement_instances, uiResource_get);
275
+ return {
276
+ ...this.host?.hostCapabilities,
277
+ sandbox: {
278
+ csp: resource?.csp ?? {},
279
+ permissions: enforcedPermissions(resource?.permissions ?? {})
280
+ }
281
+ };
282
+ };
283
+ handlers_get = function() {
284
+ const unavailable = () => Promise.reject(new Error("MCP app host is unavailable"));
285
+ return {
286
+ oncalltool: (params) => this.host?.callTool({ ...params, toolCallId: this.toolCall.id }) ?? unavailable(),
287
+ onreadresource: (params) => this.host?.readResource({ ...params, toolCallId: this.toolCall.id }) ?? unavailable(),
288
+ onopenlink: ({ url }) => __privateMethod(this, _McpAppToolElement_instances, openLink_fn).call(this, url),
289
+ onmessage: async ({ content, role }) => {
290
+ __privateMethod(this, _McpAppToolElement_instances, dispatchMessage_fn).call(this, content, role);
291
+ return this.host?.draftMessage({ toolCallId: this.toolCall.id, content }) ?? { isError: true };
292
+ },
293
+ onloggingmessage: (message) => __privateMethod(this, _McpAppToolElement_instances, handleLoggingMessage_fn).call(this, message),
294
+ onsizechange: ({ height }) => {
295
+ if (height > 0 && this._displayMode === "inline") {
296
+ this.style.height = `${Math.min(height, MAX_INLINE_HEIGHT)}px`;
297
+ }
298
+ },
299
+ onrequestdisplaymode: async ({ mode, appDisplayModes }) => {
300
+ const resultMode = __privateMethod(this, _McpAppToolElement_instances, setDisplayMode_fn).call(this, mode, appDisplayModes);
301
+ __privateMethod(this, _McpAppToolElement_instances, dispatchRequestDisplayMode_fn).call(this, resultMode);
302
+ return { mode: resultMode };
303
+ },
304
+ onupdatemodelcontext: async ({ content, structuredContent }) => {
305
+ const params = { toolCallId: this.toolCall.id, content, structuredContent };
306
+ __privateMethod(this, _McpAppToolElement_instances, dispatchUpdateModelContext_fn).call(this, params);
307
+ await this.host?.updateModelContext(params);
308
+ },
309
+ onrequestteardown: () => __privateMethod(this, _McpAppToolElement_instances, handleRequestTeardown_fn).call(this)
310
+ };
311
+ };
312
+ setDisplayMode_fn = function(requested, appDisplayModes) {
313
+ const hostModes = this.host?.hostContext.availableDisplayModes ?? [];
314
+ const allowed = requested === "inline" || hostModes.includes(requested) && appDisplayModes.includes(requested);
315
+ if (allowed) {
316
+ this._displayMode = requested;
317
+ }
318
+ return this._displayMode;
319
+ };
320
+ applyDisplayMode_fn = function() {
321
+ const container = this._container;
322
+ if (!container) {
323
+ return;
324
+ }
325
+ if (this._displayMode === "inline") {
326
+ if (container.matches(":popover-open")) {
327
+ container.hidePopover();
328
+ }
329
+ } else if (!container.matches(":popover-open")) {
330
+ container.showPopover();
331
+ }
332
+ __privateMethod(this, _McpAppToolElement_instances, releasePage_fn).call(this);
333
+ if (this._displayMode === "fullscreen") {
334
+ __privateSet(this, _restorePage, inertOutside(this));
335
+ }
336
+ if (__privateGet(this, _McpAppToolElement_instances, isPromoted_get)) {
337
+ this.updateComplete.then(() => this.renderRoot.querySelector(".exit-button")?.focus());
338
+ }
339
+ };
340
+ releasePage_fn = function() {
341
+ var _a;
342
+ (_a = __privateGet(this, _restorePage)) == null ? void 0 : _a.call(this);
343
+ __privateSet(this, _restorePage, null);
344
+ };
345
+ connect_fn = function() {
346
+ if (__privateGet(this, _controller) || !__privateGet(this, _McpAppToolElement_instances, canConnect_get)) {
347
+ return;
348
+ }
349
+ const iframe = this._iframe;
350
+ const resource = __privateGet(this, _McpAppToolElement_instances, uiResource_get);
351
+ const host = this.host;
352
+ if (!iframe || !resource || !host?.sandboxUrl) {
353
+ return;
354
+ }
355
+ const controller = new McpAppBridgeController(new McpAppBridge(HOST_INFO));
356
+ __privateSet(this, _controller, controller);
357
+ __privateSet(this, _containerDimensions, __privateMethod(this, _McpAppToolElement_instances, readContainerDimensions_fn).call(this) ?? __privateGet(this, _containerDimensions));
358
+ if (this._container) {
359
+ __privateGet(this, _resizeObserver).observe(this._container);
360
+ }
361
+ __privateSet(this, _lastHostContext, host.hostContext);
362
+ __privateSet(this, _hostStyles, __privateMethod(this, _McpAppToolElement_instances, resolveHostStyles_fn).call(this));
363
+ __privateSet(this, _unregisterView, host.registerView({ toolCallId: this.toolCall.id, teardown: () => this.teardown() }));
364
+ controller.connect({
365
+ iframe,
366
+ sandboxUrl: host.sandboxUrl,
367
+ html: resource.html,
368
+ hostContext: __privateGet(this, _McpAppToolElement_instances, hostContext_get),
369
+ hostCapabilities: __privateGet(this, _McpAppToolElement_instances, hostCapabilities_get),
370
+ csp: resource.csp,
371
+ permissions: resource.permissions,
372
+ handlers: __privateGet(this, _McpAppToolElement_instances, handlers_get)
373
+ }).then(() => controller.syncToolCall(this.toolCall)).catch((error) => console.warn("[forge-ai-mcp-app] Failed to connect widget:", error));
374
+ };
375
+ syncHostContext_fn = function(changedProperties) {
376
+ const next = this.host?.hostContext;
377
+ if (next && (next !== __privateGet(this, _lastHostContext) || changedProperties.has("_displayMode"))) {
378
+ __privateSet(this, _lastHostContext, next);
379
+ __privateSet(this, _hostStyles, __privateMethod(this, _McpAppToolElement_instances, resolveHostStyles_fn).call(this));
380
+ __privateGet(this, _controller)?.sendHostContextChange(__privateGet(this, _McpAppToolElement_instances, hostContext_get));
381
+ }
382
+ };
383
+ resolveHostStyles_fn = function() {
384
+ const computed = getComputedStyle(this);
385
+ const variables = {};
386
+ for (const key of HOST_STYLE_KEYS) {
387
+ const value = computed.getPropertyValue(`--_mcp-host-${key}`).trim();
388
+ if (value) {
389
+ variables[`--${key}`] = value;
390
+ }
391
+ }
392
+ return { variables };
393
+ };
394
+ scheduleContainerMeasure_fn = function() {
395
+ if (__privateGet(this, _resizeFrame) !== null) {
396
+ return;
397
+ }
398
+ __privateSet(this, _resizeFrame, requestAnimationFrame(() => {
399
+ __privateSet(this, _resizeFrame, null);
400
+ __privateMethod(this, _McpAppToolElement_instances, measureContainer_fn).call(this);
401
+ }));
402
+ };
403
+ cancelContainerMeasure_fn = function() {
404
+ if (__privateGet(this, _resizeFrame) !== null) {
405
+ cancelAnimationFrame(__privateGet(this, _resizeFrame));
406
+ __privateSet(this, _resizeFrame, null);
407
+ }
408
+ };
409
+ readContainerDimensions_fn = function() {
410
+ const container = this._container;
411
+ if (!container) {
412
+ return null;
413
+ }
414
+ const width = Math.round(container.clientWidth);
415
+ return this._displayMode === "inline" ? { width, maxHeight: MAX_INLINE_HEIGHT } : { width, height: Math.round(this._iframe?.clientHeight ?? container.clientHeight) };
416
+ };
417
+ measureContainer_fn = function() {
418
+ const next = __privateMethod(this, _McpAppToolElement_instances, readContainerDimensions_fn).call(this);
419
+ if (!next || JSON.stringify(next) === JSON.stringify(__privateGet(this, _containerDimensions))) {
420
+ return;
421
+ }
422
+ __privateSet(this, _containerDimensions, next);
423
+ __privateGet(this, _controller)?.sendHostContextChange(__privateGet(this, _McpAppToolElement_instances, hostContext_get));
424
+ };
425
+ openLink_fn = function(url) {
426
+ const href = asOpenableUrl(url);
427
+ if (!href) {
428
+ return Promise.resolve({ isError: true });
429
+ }
430
+ const event = new CustomEvent("forge-ai-mcp-app-open-link", {
431
+ detail: { url: href },
432
+ bubbles: true,
433
+ composed: true,
434
+ cancelable: true
435
+ });
436
+ if (!this.dispatchEvent(event)) {
437
+ return Promise.resolve({});
438
+ }
439
+ __privateMethod(this, _McpAppToolElement_instances, settlePendingLink_fn).call(this, { isError: true });
440
+ return new Promise((settle) => {
441
+ this._pendingLink = { href, settle };
442
+ });
443
+ };
444
+ settlePendingLink_fn = function(result) {
445
+ this._pendingLink?.settle(result);
446
+ this._pendingLink = null;
447
+ };
448
+ confirmLink_fn = function() {
449
+ const href = this._pendingLink?.href;
450
+ if (href) {
451
+ window.open(href, "_blank", "noopener,noreferrer");
452
+ }
453
+ __privateMethod(this, _McpAppToolElement_instances, settlePendingLink_fn).call(this, {});
454
+ };
455
+ dispatchMessage_fn = function(content, role) {
456
+ this.dispatchEvent(
457
+ new CustomEvent("forge-ai-mcp-app-message", { detail: { content, role }, bubbles: true, composed: true })
458
+ );
459
+ };
460
+ handleLoggingMessage_fn = function(message) {
461
+ const event = new CustomEvent("forge-ai-mcp-app-logging-message", {
462
+ detail: message,
463
+ bubbles: true,
464
+ composed: true,
465
+ cancelable: true
466
+ });
467
+ if (this.dispatchEvent(event)) {
468
+ const method = CONSOLE_LEVELS[message.level] ?? "info";
469
+ console[method](`[forge-ai-mcp-app]${message.logger ? ` [${message.logger}]` : ""}`, message.data);
470
+ }
471
+ };
472
+ handleRequestTeardown_fn = function() {
473
+ if (this._lifecycle !== "live") {
474
+ return;
475
+ }
476
+ const event = new CustomEvent("forge-ai-mcp-app-request-teardown", {
477
+ detail: { toolCallId: this.toolCall.id },
478
+ bubbles: true,
479
+ composed: true,
480
+ cancelable: true
481
+ });
482
+ if (!this.dispatchEvent(event)) {
483
+ return;
484
+ }
485
+ this._lifecycle = "closing";
486
+ __privateGet(this, _resizeObserver).disconnect();
487
+ __privateMethod(this, _McpAppToolElement_instances, cancelContainerMeasure_fn).call(this);
488
+ if (this.host) {
489
+ this.host.teardownView({ toolCallId: this.toolCall.id });
490
+ } else {
491
+ this.teardown();
492
+ }
493
+ this.style.removeProperty("height");
494
+ this._lifecycle = "closed";
495
+ };
496
+ dispatchRequestDisplayMode_fn = function(mode) {
497
+ this.dispatchEvent(
498
+ new CustomEvent("forge-ai-mcp-app-request-display-mode", { detail: { mode }, bubbles: true, composed: true })
499
+ );
500
+ };
501
+ dispatchUpdateModelContext_fn = function(detail) {
502
+ this.dispatchEvent(
503
+ new CustomEvent("forge-ai-mcp-app-update-model-context", { detail, bubbles: true, composed: true })
504
+ );
505
+ };
506
+ _iframe = /* @__PURE__ */ new WeakMap();
507
+ _promotedToolbar = /* @__PURE__ */ new WeakMap();
508
+ linkConfirmation_get = function() {
509
+ const link = this._pendingLink;
510
+ if (!link) {
511
+ return nothing;
512
+ }
513
+ return html`
514
+ <forge-ai-confirmation-prompt
515
+ text=${`Open this link in a new tab? ${link.href}`}
516
+ confirm-text="Open"
517
+ deny-text="Cancel"
518
+ @forge-ai-confirmation-prompt-confirm=${() => __privateMethod(this, _McpAppToolElement_instances, confirmLink_fn).call(this)}
519
+ @forge-ai-confirmation-prompt-deny=${() => __privateMethod(this, _McpAppToolElement_instances, settlePendingLink_fn).call(this, { isError: true })}>
520
+ </forge-ai-confirmation-prompt>
521
+ `;
522
+ };
523
+ isPromoted_get = function() {
524
+ return this._displayMode !== "inline";
525
+ };
526
+ exitToInline_fn = function() {
527
+ if (!__privateGet(this, _McpAppToolElement_instances, isPromoted_get)) {
528
+ return;
529
+ }
530
+ this._displayMode = "inline";
531
+ __privateMethod(this, _McpAppToolElement_instances, dispatchRequestDisplayMode_fn).call(this, "inline");
532
+ };
533
+ handleContainerKeydown_fn = function(evt) {
534
+ if (evt.key === "Escape" && __privateGet(this, _McpAppToolElement_instances, isPromoted_get)) {
535
+ evt.stopPropagation();
536
+ evt.preventDefault();
537
+ __privateMethod(this, _McpAppToolElement_instances, exitToInline_fn).call(this);
538
+ }
539
+ };
540
+ bordered_get = function() {
541
+ return __privateGet(this, _McpAppToolElement_instances, uiResource_get)?.prefersBorder !== false;
542
+ };
543
+ _loadingPlaceholder = /* @__PURE__ */ new WeakMap();
544
+ errorArtifact_get = function() {
545
+ return html`
546
+ <div class="container bordered">
547
+ <forge-ai-empty-state>
548
+ <svg slot="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="error-icon" aria-hidden="true">
549
+ <path fill="none" d="M0 0h24v24H0z" />
550
+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m1 15h-2v-2h2zm0-4h-2V7h2z" />
551
+ </svg>
552
+ <h3 slot="heading">Unable to display app</h3>
553
+ <p slot="body">${__privateGet(this, _McpAppToolElement_instances, errorBody_get)}</p>
554
+ </forge-ai-empty-state>
555
+ </div>
556
+ `;
557
+ };
558
+ McpAppToolElement.styles = unsafeCSS(styles);
559
+ __decorateClass([
560
+ property({ attribute: false })
561
+ ], McpAppToolElement.prototype, "toolCall", 2);
562
+ __decorateClass([
563
+ property({ attribute: false })
564
+ ], McpAppToolElement.prototype, "toolDefinition", 2);
565
+ __decorateClass([
566
+ consume({ context: mcpAppHostContext, subscribe: true }),
567
+ property({ attribute: false })
568
+ ], McpAppToolElement.prototype, "host", 2);
569
+ __decorateClass([
570
+ query("iframe")
571
+ ], McpAppToolElement.prototype, "_iframe", 2);
572
+ __decorateClass([
573
+ query(".container")
574
+ ], McpAppToolElement.prototype, "_container", 2);
575
+ __decorateClass([
576
+ state()
577
+ ], McpAppToolElement.prototype, "_displayMode", 2);
578
+ __decorateClass([
579
+ state()
580
+ ], McpAppToolElement.prototype, "_lifecycle", 2);
581
+ __decorateClass([
582
+ state()
583
+ ], McpAppToolElement.prototype, "_pendingLink", 2);
584
+ McpAppToolElement = __decorateClass([
585
+ customElement("forge-ai-mcp-app")
586
+ ], McpAppToolElement);
587
+ export {
588
+ McpAppToolElement
589
+ };