@frontmcp/ui 0.6.1 → 0.6.2
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/bridge/core/bridge-factory.d.ts +1 -0
- package/bridge/core/bridge-factory.d.ts.map +1 -1
- package/bridge/index.d.ts +1 -1
- package/bridge/index.d.ts.map +1 -1
- package/bridge/index.js +39 -881
- package/bundler/browser-components.d.ts +42 -0
- package/bundler/browser-components.d.ts.map +1 -0
- package/bundler/bundler.d.ts +78 -4
- package/bundler/bundler.d.ts.map +1 -1
- package/bundler/index.d.ts +8 -8
- package/bundler/index.d.ts.map +1 -1
- package/bundler/index.js +1315 -1854
- package/bundler/types.d.ts +188 -7
- package/bundler/types.d.ts.map +1 -1
- package/esm/bridge/{index.js → index.mjs} +40 -877
- package/esm/bundler/{index.js → index.mjs} +1391 -1895
- package/esm/{index.js → index.mjs} +215 -3091
- package/esm/layouts/{index.js → index.mjs} +3 -3
- package/esm/package.json +9 -8
- package/esm/react/index.mjs +1183 -0
- package/esm/renderers/index.mjs +611 -0
- package/esm/universal/{index.js → index.mjs} +266 -70
- package/index.d.ts +1 -4
- package/index.d.ts.map +1 -1
- package/index.js +208 -3113
- package/layouts/base.d.ts.map +1 -1
- package/layouts/index.js +3 -3
- package/layouts/presets.d.ts.map +1 -1
- package/package.json +9 -8
- package/react/Badge.d.ts.map +1 -1
- package/react/hooks/context.d.ts.map +1 -1
- package/react/index.d.ts +0 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +57 -2001
- package/react/types.d.ts.map +1 -1
- package/renderers/index.d.ts +9 -4
- package/renderers/index.d.ts.map +1 -1
- package/renderers/index.js +328 -88
- package/renderers/mdx.renderer.d.ts +99 -0
- package/renderers/mdx.renderer.d.ts.map +1 -0
- package/renderers/react.renderer.d.ts +22 -13
- package/renderers/react.renderer.d.ts.map +1 -1
- package/renderers/transpiler.d.ts +49 -0
- package/renderers/transpiler.d.ts.map +1 -0
- package/universal/cached-runtime.d.ts +25 -1
- package/universal/cached-runtime.d.ts.map +1 -1
- package/universal/index.js +266 -70
- package/universal/runtime-builder.d.ts.map +1 -1
- package/universal/types.d.ts.map +1 -1
- package/web-components/elements/fmcp-input.d.ts.map +1 -1
- package/web-components/elements/fmcp-select.d.ts.map +1 -1
- package/web-components/index.d.ts +0 -1
- package/web-components/index.d.ts.map +1 -1
- package/bundler/cache.d.ts +0 -173
- package/bundler/cache.d.ts.map +0 -1
- package/bundler/file-cache/component-builder.d.ts +0 -167
- package/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/bundler/file-cache/index.d.ts +0 -12
- package/bundler/file-cache/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/bundler/file-cache/storage/index.d.ts +0 -11
- package/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/interface.d.ts +0 -152
- package/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/bundler/file-cache/storage/redis.d.ts +0 -139
- package/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/bundler/sandbox/executor.d.ts +0 -14
- package/bundler/sandbox/executor.d.ts.map +0 -1
- package/bundler/sandbox/policy.d.ts +0 -62
- package/bundler/sandbox/policy.d.ts.map +0 -1
- package/esm/bridge/adapters/base-adapter.d.ts +0 -104
- package/esm/bridge/adapters/base-adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/claude.adapter.d.ts +0 -67
- package/esm/bridge/adapters/claude.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/ext-apps.adapter.d.ts +0 -143
- package/esm/bridge/adapters/ext-apps.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/gemini.adapter.d.ts +0 -64
- package/esm/bridge/adapters/gemini.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/generic.adapter.d.ts +0 -56
- package/esm/bridge/adapters/generic.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/index.d.ts +0 -26
- package/esm/bridge/adapters/index.d.ts.map +0 -1
- package/esm/bridge/adapters/openai.adapter.d.ts +0 -65
- package/esm/bridge/adapters/openai.adapter.d.ts.map +0 -1
- package/esm/bridge/core/adapter-registry.d.ts +0 -122
- package/esm/bridge/core/adapter-registry.d.ts.map +0 -1
- package/esm/bridge/core/bridge-factory.d.ts +0 -199
- package/esm/bridge/core/bridge-factory.d.ts.map +0 -1
- package/esm/bridge/core/index.d.ts +0 -10
- package/esm/bridge/core/index.d.ts.map +0 -1
- package/esm/bridge/index.d.ts +0 -62
- package/esm/bridge/index.d.ts.map +0 -1
- package/esm/bridge/runtime/iife-generator.d.ts +0 -62
- package/esm/bridge/runtime/iife-generator.d.ts.map +0 -1
- package/esm/bridge/runtime/index.d.ts +0 -10
- package/esm/bridge/runtime/index.d.ts.map +0 -1
- package/esm/bridge/types.d.ts +0 -386
- package/esm/bridge/types.d.ts.map +0 -1
- package/esm/bundler/bundler.d.ts +0 -208
- package/esm/bundler/bundler.d.ts.map +0 -1
- package/esm/bundler/cache.d.ts +0 -173
- package/esm/bundler/cache.d.ts.map +0 -1
- package/esm/bundler/file-cache/component-builder.d.ts +0 -167
- package/esm/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/esm/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/esm/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/esm/bundler/file-cache/index.d.ts +0 -12
- package/esm/bundler/file-cache/index.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/esm/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/index.d.ts +0 -11
- package/esm/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/interface.d.ts +0 -152
- package/esm/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/redis.d.ts +0 -139
- package/esm/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/esm/bundler/index.d.ts +0 -43
- package/esm/bundler/index.d.ts.map +0 -1
- package/esm/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/esm/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/esm/bundler/sandbox/executor.d.ts +0 -14
- package/esm/bundler/sandbox/executor.d.ts.map +0 -1
- package/esm/bundler/sandbox/policy.d.ts +0 -62
- package/esm/bundler/sandbox/policy.d.ts.map +0 -1
- package/esm/bundler/types.d.ts +0 -702
- package/esm/bundler/types.d.ts.map +0 -1
- package/esm/components/alert.d.ts +0 -66
- package/esm/components/alert.d.ts.map +0 -1
- package/esm/components/alert.schema.d.ts +0 -98
- package/esm/components/alert.schema.d.ts.map +0 -1
- package/esm/components/avatar.d.ts +0 -77
- package/esm/components/avatar.d.ts.map +0 -1
- package/esm/components/avatar.schema.d.ts +0 -170
- package/esm/components/avatar.schema.d.ts.map +0 -1
- package/esm/components/badge.d.ts +0 -64
- package/esm/components/badge.d.ts.map +0 -1
- package/esm/components/badge.schema.d.ts +0 -91
- package/esm/components/badge.schema.d.ts.map +0 -1
- package/esm/components/button.d.ts +0 -100
- package/esm/components/button.d.ts.map +0 -1
- package/esm/components/button.schema.d.ts +0 -120
- package/esm/components/button.schema.d.ts.map +0 -1
- package/esm/components/card.d.ts +0 -53
- package/esm/components/card.d.ts.map +0 -1
- package/esm/components/card.schema.d.ts +0 -93
- package/esm/components/card.schema.d.ts.map +0 -1
- package/esm/components/form.d.ts +0 -212
- package/esm/components/form.d.ts.map +0 -1
- package/esm/components/form.schema.d.ts +0 -365
- package/esm/components/form.schema.d.ts.map +0 -1
- package/esm/components/index.d.ts +0 -29
- package/esm/components/index.d.ts.map +0 -1
- package/esm/components/list.d.ts +0 -121
- package/esm/components/list.d.ts.map +0 -1
- package/esm/components/list.schema.d.ts +0 -129
- package/esm/components/list.schema.d.ts.map +0 -1
- package/esm/components/modal.d.ts +0 -100
- package/esm/components/modal.d.ts.map +0 -1
- package/esm/components/modal.schema.d.ts +0 -151
- package/esm/components/modal.schema.d.ts.map +0 -1
- package/esm/components/table.d.ts +0 -91
- package/esm/components/table.d.ts.map +0 -1
- package/esm/components/table.schema.d.ts +0 -123
- package/esm/components/table.schema.d.ts.map +0 -1
- package/esm/index.d.ts +0 -40
- package/esm/index.d.ts.map +0 -1
- package/esm/layouts/base.d.ts +0 -86
- package/esm/layouts/base.d.ts.map +0 -1
- package/esm/layouts/index.d.ts +0 -8
- package/esm/layouts/index.d.ts.map +0 -1
- package/esm/layouts/presets.d.ts +0 -134
- package/esm/layouts/presets.d.ts.map +0 -1
- package/esm/pages/consent.d.ts +0 -117
- package/esm/pages/consent.d.ts.map +0 -1
- package/esm/pages/error.d.ts +0 -101
- package/esm/pages/error.d.ts.map +0 -1
- package/esm/pages/index.d.ts +0 -9
- package/esm/pages/index.d.ts.map +0 -1
- package/esm/pages/index.js +0 -1036
- package/esm/react/Alert.d.ts +0 -101
- package/esm/react/Alert.d.ts.map +0 -1
- package/esm/react/Badge.d.ts +0 -100
- package/esm/react/Badge.d.ts.map +0 -1
- package/esm/react/Button.d.ts +0 -108
- package/esm/react/Button.d.ts.map +0 -1
- package/esm/react/Card.d.ts +0 -103
- package/esm/react/Card.d.ts.map +0 -1
- package/esm/react/hooks/context.d.ts +0 -179
- package/esm/react/hooks/context.d.ts.map +0 -1
- package/esm/react/hooks/index.d.ts +0 -42
- package/esm/react/hooks/index.d.ts.map +0 -1
- package/esm/react/hooks/tools.d.ts +0 -284
- package/esm/react/hooks/tools.d.ts.map +0 -1
- package/esm/react/index.d.ts +0 -80
- package/esm/react/index.d.ts.map +0 -1
- package/esm/react/index.js +0 -3124
- package/esm/react/types.d.ts +0 -105
- package/esm/react/types.d.ts.map +0 -1
- package/esm/react/utils.d.ts +0 -43
- package/esm/react/utils.d.ts.map +0 -1
- package/esm/render/index.d.ts +0 -8
- package/esm/render/index.d.ts.map +0 -1
- package/esm/render/prerender.d.ts +0 -57
- package/esm/render/prerender.d.ts.map +0 -1
- package/esm/renderers/index.d.ts +0 -21
- package/esm/renderers/index.d.ts.map +0 -1
- package/esm/renderers/index.js +0 -381
- package/esm/renderers/react.adapter.d.ts +0 -70
- package/esm/renderers/react.adapter.d.ts.map +0 -1
- package/esm/renderers/react.renderer.d.ts +0 -96
- package/esm/renderers/react.renderer.d.ts.map +0 -1
- package/esm/universal/UniversalApp.d.ts +0 -108
- package/esm/universal/UniversalApp.d.ts.map +0 -1
- package/esm/universal/cached-runtime.d.ts +0 -115
- package/esm/universal/cached-runtime.d.ts.map +0 -1
- package/esm/universal/context.d.ts +0 -122
- package/esm/universal/context.d.ts.map +0 -1
- package/esm/universal/index.d.ts +0 -57
- package/esm/universal/index.d.ts.map +0 -1
- package/esm/universal/renderers/html.renderer.d.ts +0 -37
- package/esm/universal/renderers/html.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/index.d.ts +0 -112
- package/esm/universal/renderers/index.d.ts.map +0 -1
- package/esm/universal/renderers/markdown.renderer.d.ts +0 -33
- package/esm/universal/renderers/markdown.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/mdx.renderer.d.ts +0 -38
- package/esm/universal/renderers/mdx.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/react.renderer.d.ts +0 -46
- package/esm/universal/renderers/react.renderer.d.ts.map +0 -1
- package/esm/universal/runtime-builder.d.ts +0 -33
- package/esm/universal/runtime-builder.d.ts.map +0 -1
- package/esm/universal/store.d.ts +0 -135
- package/esm/universal/store.d.ts.map +0 -1
- package/esm/universal/types.d.ts +0 -199
- package/esm/universal/types.d.ts.map +0 -1
- package/esm/web-components/core/attribute-parser.d.ts +0 -82
- package/esm/web-components/core/attribute-parser.d.ts.map +0 -1
- package/esm/web-components/core/base-element.d.ts +0 -197
- package/esm/web-components/core/base-element.d.ts.map +0 -1
- package/esm/web-components/core/index.d.ts +0 -9
- package/esm/web-components/core/index.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-alert.d.ts +0 -46
- package/esm/web-components/elements/fmcp-alert.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-badge.d.ts +0 -47
- package/esm/web-components/elements/fmcp-badge.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-button.d.ts +0 -117
- package/esm/web-components/elements/fmcp-button.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-card.d.ts +0 -53
- package/esm/web-components/elements/fmcp-card.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-input.d.ts +0 -96
- package/esm/web-components/elements/fmcp-input.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-select.d.ts +0 -100
- package/esm/web-components/elements/fmcp-select.d.ts.map +0 -1
- package/esm/web-components/elements/index.d.ts +0 -13
- package/esm/web-components/elements/index.d.ts.map +0 -1
- package/esm/web-components/index.d.ts +0 -50
- package/esm/web-components/index.d.ts.map +0 -1
- package/esm/web-components/register.d.ts +0 -57
- package/esm/web-components/register.d.ts.map +0 -1
- package/esm/web-components/types.d.ts +0 -122
- package/esm/web-components/types.d.ts.map +0 -1
- package/esm/widgets/index.d.ts +0 -8
- package/esm/widgets/index.d.ts.map +0 -1
- package/esm/widgets/index.js +0 -883
- package/esm/widgets/progress.d.ts +0 -133
- package/esm/widgets/progress.d.ts.map +0 -1
- package/esm/widgets/resource.d.ts +0 -163
- package/esm/widgets/resource.d.ts.map +0 -1
- package/pages/consent.d.ts +0 -117
- package/pages/consent.d.ts.map +0 -1
- package/pages/error.d.ts +0 -101
- package/pages/error.d.ts.map +0 -1
- package/pages/index.d.ts +0 -9
- package/pages/index.d.ts.map +0 -1
- package/pages/index.js +0 -1065
- package/react/utils.d.ts +0 -43
- package/react/utils.d.ts.map +0 -1
- package/widgets/index.d.ts +0 -8
- package/widgets/index.d.ts.map +0 -1
- package/widgets/index.js +0 -910
- package/widgets/progress.d.ts +0 -133
- package/widgets/progress.d.ts.map +0 -1
- package/widgets/resource.d.ts +0 -163
- package/widgets/resource.d.ts.map +0 -1
- /package/esm/components/{index.js → index.mjs} +0 -0
- /package/esm/render/{index.js → index.mjs} +0 -0
- /package/esm/web-components/{index.js → index.mjs} +0 -0
package/bridge/index.js
CHANGED
|
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var bridge_exports = {};
|
|
22
22
|
__export(bridge_exports, {
|
|
23
23
|
AdapterRegistry: () => AdapterRegistry,
|
|
24
|
-
BRIDGE_SCRIPT_TAGS: () => BRIDGE_SCRIPT_TAGS,
|
|
24
|
+
BRIDGE_SCRIPT_TAGS: () => import_uipack.BRIDGE_SCRIPT_TAGS,
|
|
25
25
|
BaseAdapter: () => BaseAdapter,
|
|
26
26
|
ClaudeAdapter: () => ClaudeAdapter,
|
|
27
27
|
DEFAULT_CAPABILITIES: () => DEFAULT_CAPABILITIES,
|
|
@@ -31,7 +31,7 @@ __export(bridge_exports, {
|
|
|
31
31
|
GeminiAdapter: () => GeminiAdapter,
|
|
32
32
|
GenericAdapter: () => GenericAdapter,
|
|
33
33
|
OpenAIAdapter: () => OpenAIAdapter,
|
|
34
|
-
UNIVERSAL_BRIDGE_SCRIPT: () => UNIVERSAL_BRIDGE_SCRIPT,
|
|
34
|
+
UNIVERSAL_BRIDGE_SCRIPT: () => import_uipack.UNIVERSAL_BRIDGE_SCRIPT,
|
|
35
35
|
createBridge: () => createBridge,
|
|
36
36
|
createClaudeAdapter: () => createClaudeAdapter,
|
|
37
37
|
createExtAppsAdapter: () => createExtAppsAdapter,
|
|
@@ -40,8 +40,8 @@ __export(bridge_exports, {
|
|
|
40
40
|
createOpenAIAdapter: () => createOpenAIAdapter,
|
|
41
41
|
defaultRegistry: () => defaultRegistry,
|
|
42
42
|
detectAdapter: () => detectAdapter,
|
|
43
|
-
generateBridgeIIFE: () => generateBridgeIIFE,
|
|
44
|
-
generatePlatformBundle: () => generatePlatformBundle,
|
|
43
|
+
generateBridgeIIFE: () => import_uipack.generateBridgeIIFE,
|
|
44
|
+
generatePlatformBundle: () => import_uipack.generatePlatformBundle,
|
|
45
45
|
getAdapter: () => getAdapter,
|
|
46
46
|
getGlobalBridge: () => getGlobalBridge,
|
|
47
47
|
registerAdapter: () => registerAdapter,
|
|
@@ -420,50 +420,50 @@ var FrontMcpBridge = class {
|
|
|
420
420
|
* Get current theme.
|
|
421
421
|
*/
|
|
422
422
|
getTheme() {
|
|
423
|
-
this._ensureInitialized();
|
|
424
|
-
return
|
|
423
|
+
const adapter = this._ensureInitialized();
|
|
424
|
+
return adapter.getTheme();
|
|
425
425
|
}
|
|
426
426
|
/**
|
|
427
427
|
* Get current display mode.
|
|
428
428
|
*/
|
|
429
429
|
getDisplayMode() {
|
|
430
|
-
this._ensureInitialized();
|
|
431
|
-
return
|
|
430
|
+
const adapter = this._ensureInitialized();
|
|
431
|
+
return adapter.getDisplayMode();
|
|
432
432
|
}
|
|
433
433
|
/**
|
|
434
434
|
* Get tool input arguments.
|
|
435
435
|
*/
|
|
436
436
|
getToolInput() {
|
|
437
|
-
this._ensureInitialized();
|
|
438
|
-
return
|
|
437
|
+
const adapter = this._ensureInitialized();
|
|
438
|
+
return adapter.getToolInput();
|
|
439
439
|
}
|
|
440
440
|
/**
|
|
441
441
|
* Get tool output/result.
|
|
442
442
|
*/
|
|
443
443
|
getToolOutput() {
|
|
444
|
-
this._ensureInitialized();
|
|
445
|
-
return
|
|
444
|
+
const adapter = this._ensureInitialized();
|
|
445
|
+
return adapter.getToolOutput();
|
|
446
446
|
}
|
|
447
447
|
/**
|
|
448
448
|
* Get structured content (parsed output).
|
|
449
449
|
*/
|
|
450
450
|
getStructuredContent() {
|
|
451
|
-
this._ensureInitialized();
|
|
452
|
-
return
|
|
451
|
+
const adapter = this._ensureInitialized();
|
|
452
|
+
return adapter.getStructuredContent();
|
|
453
453
|
}
|
|
454
454
|
/**
|
|
455
455
|
* Get persisted widget state.
|
|
456
456
|
*/
|
|
457
457
|
getWidgetState() {
|
|
458
|
-
this._ensureInitialized();
|
|
459
|
-
return
|
|
458
|
+
const adapter = this._ensureInitialized();
|
|
459
|
+
return adapter.getWidgetState();
|
|
460
460
|
}
|
|
461
461
|
/**
|
|
462
462
|
* Get full host context.
|
|
463
463
|
*/
|
|
464
464
|
getHostContext() {
|
|
465
|
-
this._ensureInitialized();
|
|
466
|
-
return
|
|
465
|
+
const adapter = this._ensureInitialized();
|
|
466
|
+
return adapter.getHostContext();
|
|
467
467
|
}
|
|
468
468
|
// ============================================
|
|
469
469
|
// Actions (delegate to adapter)
|
|
@@ -474,53 +474,53 @@ var FrontMcpBridge = class {
|
|
|
474
474
|
* @param args - Tool arguments
|
|
475
475
|
*/
|
|
476
476
|
async callTool(name, args) {
|
|
477
|
-
this._ensureInitialized();
|
|
477
|
+
const adapter = this._ensureInitialized();
|
|
478
478
|
if (!this.hasCapability("canCallTools")) {
|
|
479
479
|
throw new Error("Tool calls are not supported by the current adapter");
|
|
480
480
|
}
|
|
481
|
-
return
|
|
481
|
+
return adapter.callTool(name, args);
|
|
482
482
|
}
|
|
483
483
|
/**
|
|
484
484
|
* Send a follow-up message to the conversation.
|
|
485
485
|
* @param content - Message content
|
|
486
486
|
*/
|
|
487
487
|
async sendMessage(content) {
|
|
488
|
-
this._ensureInitialized();
|
|
488
|
+
const adapter = this._ensureInitialized();
|
|
489
489
|
if (!this.hasCapability("canSendMessages")) {
|
|
490
490
|
throw new Error("Sending messages is not supported by the current adapter");
|
|
491
491
|
}
|
|
492
|
-
return
|
|
492
|
+
return adapter.sendMessage(content);
|
|
493
493
|
}
|
|
494
494
|
/**
|
|
495
495
|
* Open an external link.
|
|
496
496
|
* @param url - URL to open
|
|
497
497
|
*/
|
|
498
498
|
async openLink(url) {
|
|
499
|
-
this._ensureInitialized();
|
|
500
|
-
return
|
|
499
|
+
const adapter = this._ensureInitialized();
|
|
500
|
+
return adapter.openLink(url);
|
|
501
501
|
}
|
|
502
502
|
/**
|
|
503
503
|
* Request a display mode change.
|
|
504
504
|
* @param mode - Desired display mode
|
|
505
505
|
*/
|
|
506
506
|
async requestDisplayMode(mode) {
|
|
507
|
-
this._ensureInitialized();
|
|
508
|
-
return
|
|
507
|
+
const adapter = this._ensureInitialized();
|
|
508
|
+
return adapter.requestDisplayMode(mode);
|
|
509
509
|
}
|
|
510
510
|
/**
|
|
511
511
|
* Request widget close.
|
|
512
512
|
*/
|
|
513
513
|
async requestClose() {
|
|
514
|
-
this._ensureInitialized();
|
|
515
|
-
return
|
|
514
|
+
const adapter = this._ensureInitialized();
|
|
515
|
+
return adapter.requestClose();
|
|
516
516
|
}
|
|
517
517
|
/**
|
|
518
518
|
* Set widget state (persisted across sessions).
|
|
519
519
|
* @param state - State object to persist
|
|
520
520
|
*/
|
|
521
521
|
setWidgetState(state) {
|
|
522
|
-
this._ensureInitialized();
|
|
523
|
-
|
|
522
|
+
const adapter = this._ensureInitialized();
|
|
523
|
+
adapter.setWidgetState(state);
|
|
524
524
|
}
|
|
525
525
|
// ============================================
|
|
526
526
|
// Events (delegate to adapter)
|
|
@@ -531,8 +531,8 @@ var FrontMcpBridge = class {
|
|
|
531
531
|
* @returns Unsubscribe function
|
|
532
532
|
*/
|
|
533
533
|
onContextChange(callback) {
|
|
534
|
-
this._ensureInitialized();
|
|
535
|
-
return
|
|
534
|
+
const adapter = this._ensureInitialized();
|
|
535
|
+
return adapter.onContextChange(callback);
|
|
536
536
|
}
|
|
537
537
|
/**
|
|
538
538
|
* Subscribe to tool result updates.
|
|
@@ -540,19 +540,21 @@ var FrontMcpBridge = class {
|
|
|
540
540
|
* @returns Unsubscribe function
|
|
541
541
|
*/
|
|
542
542
|
onToolResult(callback) {
|
|
543
|
-
this._ensureInitialized();
|
|
544
|
-
return
|
|
543
|
+
const adapter = this._ensureInitialized();
|
|
544
|
+
return adapter.onToolResult(callback);
|
|
545
545
|
}
|
|
546
546
|
// ============================================
|
|
547
547
|
// Private Helpers
|
|
548
548
|
// ============================================
|
|
549
549
|
/**
|
|
550
550
|
* Ensure the bridge is initialized before operations.
|
|
551
|
+
* Returns the adapter for type-safe access.
|
|
551
552
|
*/
|
|
552
553
|
_ensureInitialized() {
|
|
553
554
|
if (!this._initialized || !this._adapter) {
|
|
554
555
|
throw new Error("FrontMcpBridge is not initialized. Call initialize() first.");
|
|
555
556
|
}
|
|
557
|
+
return this._adapter;
|
|
556
558
|
}
|
|
557
559
|
/**
|
|
558
560
|
* Wrap a promise with a timeout.
|
|
@@ -1089,7 +1091,7 @@ var ExtAppsAdapter = class extends BaseAdapter {
|
|
|
1089
1091
|
window.removeEventListener("message", this._messageListener);
|
|
1090
1092
|
this._messageListener = void 0;
|
|
1091
1093
|
}
|
|
1092
|
-
for (const [
|
|
1094
|
+
for (const [_id, pending] of this._pendingRequests) {
|
|
1093
1095
|
clearTimeout(pending.timeout);
|
|
1094
1096
|
pending.reject(new Error("Adapter disposed"));
|
|
1095
1097
|
}
|
|
@@ -1662,852 +1664,8 @@ function registerBuiltInAdapters() {
|
|
|
1662
1664
|
}
|
|
1663
1665
|
registerBuiltInAdapters();
|
|
1664
1666
|
|
|
1665
|
-
// libs/ui/src/bridge/runtime/
|
|
1666
|
-
|
|
1667
|
-
const { debug = false, trustedOrigins = [], minify = false } = options;
|
|
1668
|
-
const adapters = options.adapters || ["openai", "ext-apps", "claude", "gemini", "generic"];
|
|
1669
|
-
const parts = [];
|
|
1670
|
-
parts.push("(function() {");
|
|
1671
|
-
parts.push('"use strict";');
|
|
1672
|
-
parts.push("");
|
|
1673
|
-
if (debug) {
|
|
1674
|
-
parts.push('function log(msg) { console.log("[FrontMcpBridge] " + msg); }');
|
|
1675
|
-
} else {
|
|
1676
|
-
parts.push("function log() {}");
|
|
1677
|
-
}
|
|
1678
|
-
parts.push("");
|
|
1679
|
-
parts.push("var DEFAULT_SAFE_AREA = { top: 0, bottom: 0, left: 0, right: 0 };");
|
|
1680
|
-
parts.push("");
|
|
1681
|
-
parts.push(generateContextDetection());
|
|
1682
|
-
parts.push("");
|
|
1683
|
-
parts.push(generateBaseCapabilities());
|
|
1684
|
-
parts.push("");
|
|
1685
|
-
if (adapters.includes("openai")) {
|
|
1686
|
-
parts.push(generateOpenAIAdapter());
|
|
1687
|
-
parts.push("");
|
|
1688
|
-
}
|
|
1689
|
-
if (adapters.includes("ext-apps")) {
|
|
1690
|
-
parts.push(generateExtAppsAdapter(trustedOrigins));
|
|
1691
|
-
parts.push("");
|
|
1692
|
-
}
|
|
1693
|
-
if (adapters.includes("claude")) {
|
|
1694
|
-
parts.push(generateClaudeAdapter());
|
|
1695
|
-
parts.push("");
|
|
1696
|
-
}
|
|
1697
|
-
if (adapters.includes("gemini")) {
|
|
1698
|
-
parts.push(generateGeminiAdapter());
|
|
1699
|
-
parts.push("");
|
|
1700
|
-
}
|
|
1701
|
-
if (adapters.includes("generic")) {
|
|
1702
|
-
parts.push(generateGenericAdapter());
|
|
1703
|
-
parts.push("");
|
|
1704
|
-
}
|
|
1705
|
-
parts.push(generatePlatformDetection(adapters));
|
|
1706
|
-
parts.push("");
|
|
1707
|
-
parts.push(generateBridgeClass());
|
|
1708
|
-
parts.push("");
|
|
1709
|
-
parts.push("var bridge = new FrontMcpBridge();");
|
|
1710
|
-
parts.push("bridge.initialize().then(function() {");
|
|
1711
|
-
parts.push(' log("Bridge initialized with adapter: " + bridge.adapterId);');
|
|
1712
|
-
parts.push(' window.dispatchEvent(new CustomEvent("bridge:ready", { detail: { adapter: bridge.adapterId } }));');
|
|
1713
|
-
parts.push("}).catch(function(err) {");
|
|
1714
|
-
parts.push(' console.error("[FrontMcpBridge] Init failed:", err);');
|
|
1715
|
-
parts.push(' window.dispatchEvent(new CustomEvent("bridge:error", { detail: { error: err } }));');
|
|
1716
|
-
parts.push("});");
|
|
1717
|
-
parts.push("");
|
|
1718
|
-
parts.push("window.FrontMcpBridge = bridge;");
|
|
1719
|
-
parts.push("})();");
|
|
1720
|
-
const code = parts.join("\n");
|
|
1721
|
-
if (minify) {
|
|
1722
|
-
return minifyJS(code);
|
|
1723
|
-
}
|
|
1724
|
-
return code;
|
|
1725
|
-
}
|
|
1726
|
-
function generateContextDetection() {
|
|
1727
|
-
return `
|
|
1728
|
-
function detectTheme() {
|
|
1729
|
-
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
1730
|
-
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
1731
|
-
}
|
|
1732
|
-
return 'light';
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
function detectLocale() {
|
|
1736
|
-
if (typeof navigator !== 'undefined') {
|
|
1737
|
-
return navigator.language || 'en-US';
|
|
1738
|
-
}
|
|
1739
|
-
return 'en-US';
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
function detectUserAgent() {
|
|
1743
|
-
if (typeof navigator === 'undefined') {
|
|
1744
|
-
return { type: 'web', hover: true, touch: false };
|
|
1745
|
-
}
|
|
1746
|
-
var ua = navigator.userAgent || '';
|
|
1747
|
-
var isMobile = /iPhone|iPad|iPod|Android/i.test(ua);
|
|
1748
|
-
var hasTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
1749
|
-
var hasHover = window.matchMedia && window.matchMedia('(hover: hover)').matches;
|
|
1750
|
-
return { type: isMobile ? 'mobile' : 'web', hover: hasHover !== false, touch: hasTouch };
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
function detectViewport() {
|
|
1754
|
-
if (typeof window !== 'undefined') {
|
|
1755
|
-
return { width: window.innerWidth, height: window.innerHeight };
|
|
1756
|
-
}
|
|
1757
|
-
return undefined;
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
function readInjectedData() {
|
|
1761
|
-
var data = { toolInput: {}, toolOutput: undefined, structuredContent: undefined };
|
|
1762
|
-
if (typeof window !== 'undefined') {
|
|
1763
|
-
if (window.__mcpToolInput) data.toolInput = window.__mcpToolInput;
|
|
1764
|
-
if (window.__mcpToolOutput) data.toolOutput = window.__mcpToolOutput;
|
|
1765
|
-
if (window.__mcpStructuredContent) data.structuredContent = window.__mcpStructuredContent;
|
|
1766
|
-
}
|
|
1767
|
-
return data;
|
|
1768
|
-
}
|
|
1769
|
-
`.trim();
|
|
1770
|
-
}
|
|
1771
|
-
function generateBaseCapabilities() {
|
|
1772
|
-
return `
|
|
1773
|
-
var DEFAULT_CAPABILITIES = {
|
|
1774
|
-
canCallTools: false,
|
|
1775
|
-
canSendMessages: false,
|
|
1776
|
-
canOpenLinks: false,
|
|
1777
|
-
canPersistState: true,
|
|
1778
|
-
hasNetworkAccess: true,
|
|
1779
|
-
supportsDisplayModes: false,
|
|
1780
|
-
supportsTheme: true
|
|
1781
|
-
};
|
|
1782
|
-
`.trim();
|
|
1783
|
-
}
|
|
1784
|
-
function generateOpenAIAdapter() {
|
|
1785
|
-
return `
|
|
1786
|
-
var OpenAIAdapter = {
|
|
1787
|
-
id: 'openai',
|
|
1788
|
-
name: 'OpenAI ChatGPT',
|
|
1789
|
-
priority: 100,
|
|
1790
|
-
capabilities: Object.assign({}, DEFAULT_CAPABILITIES, {
|
|
1791
|
-
canCallTools: true,
|
|
1792
|
-
canSendMessages: true,
|
|
1793
|
-
canOpenLinks: true,
|
|
1794
|
-
supportsDisplayModes: true
|
|
1795
|
-
}),
|
|
1796
|
-
canHandle: function() {
|
|
1797
|
-
if (typeof window === 'undefined') return false;
|
|
1798
|
-
// Check for window.openai.callTool (the actual OpenAI SDK API)
|
|
1799
|
-
if (window.openai && typeof window.openai.callTool === 'function') return true;
|
|
1800
|
-
// Also check if we're being injected with tool metadata (OpenAI injects toolOutput)
|
|
1801
|
-
if (window.openai && (window.openai.toolOutput !== undefined || window.openai.toolInput !== undefined)) return true;
|
|
1802
|
-
return false;
|
|
1803
|
-
},
|
|
1804
|
-
initialize: function(context) {
|
|
1805
|
-
var sdk = window.openai;
|
|
1806
|
-
context.sdk = sdk;
|
|
1807
|
-
// OpenAI SDK exposes theme and displayMode directly as properties
|
|
1808
|
-
if (sdk.theme) {
|
|
1809
|
-
context.hostContext.theme = sdk.theme;
|
|
1810
|
-
}
|
|
1811
|
-
if (sdk.displayMode) {
|
|
1812
|
-
context.hostContext.displayMode = sdk.displayMode;
|
|
1813
|
-
}
|
|
1814
|
-
// Note: OpenAI SDK does not have an onContextChange equivalent
|
|
1815
|
-
return Promise.resolve();
|
|
1816
|
-
},
|
|
1817
|
-
callTool: function(context, name, args) {
|
|
1818
|
-
return context.sdk.callTool(name, args);
|
|
1819
|
-
},
|
|
1820
|
-
sendMessage: function(context, content) {
|
|
1821
|
-
if (typeof context.sdk.sendFollowUpMessage === 'function') {
|
|
1822
|
-
return context.sdk.sendFollowUpMessage(content);
|
|
1823
|
-
}
|
|
1824
|
-
return Promise.reject(new Error('Messages not supported'));
|
|
1825
|
-
},
|
|
1826
|
-
openLink: function(context, url) {
|
|
1827
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
1828
|
-
return Promise.resolve();
|
|
1829
|
-
},
|
|
1830
|
-
requestDisplayMode: function(context, mode) {
|
|
1831
|
-
return Promise.resolve();
|
|
1832
|
-
},
|
|
1833
|
-
requestClose: function(context) {
|
|
1834
|
-
return Promise.resolve();
|
|
1835
|
-
}
|
|
1836
|
-
};
|
|
1837
|
-
`.trim();
|
|
1838
|
-
}
|
|
1839
|
-
function generateExtAppsAdapter(trustedOrigins) {
|
|
1840
|
-
const originsArray = trustedOrigins.length > 0 ? JSON.stringify(trustedOrigins) : "[]";
|
|
1841
|
-
return `
|
|
1842
|
-
var ExtAppsAdapter = {
|
|
1843
|
-
id: 'ext-apps',
|
|
1844
|
-
name: 'ext-apps (SEP-1865)',
|
|
1845
|
-
priority: 80,
|
|
1846
|
-
capabilities: Object.assign({}, DEFAULT_CAPABILITIES, { canPersistState: true, hasNetworkAccess: true }),
|
|
1847
|
-
trustedOrigins: ${originsArray},
|
|
1848
|
-
trustedOrigin: null,
|
|
1849
|
-
pendingRequests: {},
|
|
1850
|
-
requestId: 0,
|
|
1851
|
-
hostCapabilities: {},
|
|
1852
|
-
canHandle: function() {
|
|
1853
|
-
if (typeof window === 'undefined') return false;
|
|
1854
|
-
if (window.parent === window) return false;
|
|
1855
|
-
// Check for OpenAI SDK (window.openai.callTool) - defer to OpenAIAdapter
|
|
1856
|
-
if (window.openai && typeof window.openai.callTool === 'function') return false;
|
|
1857
|
-
if (window.__mcpPlatform === 'ext-apps') return true;
|
|
1858
|
-
return true;
|
|
1859
|
-
},
|
|
1860
|
-
initialize: function(context) {
|
|
1861
|
-
var self = this;
|
|
1862
|
-
context.extApps = this;
|
|
1863
|
-
|
|
1864
|
-
window.addEventListener('message', function(event) {
|
|
1865
|
-
self.handleMessage(context, event);
|
|
1866
|
-
});
|
|
1867
|
-
|
|
1868
|
-
return self.performHandshake(context);
|
|
1869
|
-
},
|
|
1870
|
-
handleMessage: function(context, event) {
|
|
1871
|
-
if (!this.isOriginTrusted(event.origin)) return;
|
|
1872
|
-
var data = event.data;
|
|
1873
|
-
if (!data || typeof data !== 'object' || data.jsonrpc !== '2.0') return;
|
|
1874
|
-
|
|
1875
|
-
if ('id' in data && (data.result !== undefined || data.error !== undefined)) {
|
|
1876
|
-
var pending = this.pendingRequests[data.id];
|
|
1877
|
-
if (pending) {
|
|
1878
|
-
clearTimeout(pending.timeout);
|
|
1879
|
-
delete this.pendingRequests[data.id];
|
|
1880
|
-
if (data.error) {
|
|
1881
|
-
pending.reject(new Error(data.error.message + ' (code: ' + data.error.code + ')'));
|
|
1882
|
-
} else {
|
|
1883
|
-
pending.resolve(data.result);
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
return;
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
if ('method' in data && !('id' in data)) {
|
|
1890
|
-
this.handleNotification(context, data);
|
|
1891
|
-
}
|
|
1892
|
-
},
|
|
1893
|
-
handleNotification: function(context, notification) {
|
|
1894
|
-
var params = notification.params || {};
|
|
1895
|
-
switch (notification.method) {
|
|
1896
|
-
case 'ui/notifications/tool-input':
|
|
1897
|
-
context.toolInput = params.arguments || {};
|
|
1898
|
-
window.dispatchEvent(new CustomEvent('tool:input', { detail: { arguments: context.toolInput } }));
|
|
1899
|
-
break;
|
|
1900
|
-
case 'ui/notifications/tool-result':
|
|
1901
|
-
context.toolOutput = params.content;
|
|
1902
|
-
context.structuredContent = params.structuredContent;
|
|
1903
|
-
context.notifyToolResult(params.content);
|
|
1904
|
-
window.dispatchEvent(new CustomEvent('tool:result', { detail: params }));
|
|
1905
|
-
break;
|
|
1906
|
-
case 'ui/notifications/host-context-changed':
|
|
1907
|
-
Object.assign(context.hostContext, params);
|
|
1908
|
-
context.notifyContextChange(params);
|
|
1909
|
-
break;
|
|
1910
|
-
}
|
|
1911
|
-
},
|
|
1912
|
-
isOriginTrusted: function(origin) {
|
|
1913
|
-
if (this.trustedOrigins.length > 0) {
|
|
1914
|
-
return this.trustedOrigins.indexOf(origin) !== -1;
|
|
1915
|
-
}
|
|
1916
|
-
// When no trusted origins configured, only trust first message in iframe context
|
|
1917
|
-
// This helps mitigate race conditions where a malicious iframe could establish trust
|
|
1918
|
-
if (!this.trustedOrigin) {
|
|
1919
|
-
if (window.parent !== window && origin) {
|
|
1920
|
-
this.trustedOrigin = origin;
|
|
1921
|
-
return true;
|
|
1922
|
-
}
|
|
1923
|
-
return false;
|
|
1924
|
-
}
|
|
1925
|
-
return this.trustedOrigin === origin;
|
|
1926
|
-
},
|
|
1927
|
-
sendRequest: function(method, params) {
|
|
1928
|
-
var self = this;
|
|
1929
|
-
return new Promise(function(resolve, reject) {
|
|
1930
|
-
// Security: Require trusted origin before sending requests to prevent message leaks
|
|
1931
|
-
if (!self.trustedOrigin && self.trustedOrigins.length === 0) {
|
|
1932
|
-
reject(new Error('Cannot send request: no trusted origin established'));
|
|
1933
|
-
return;
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
var id = ++self.requestId;
|
|
1937
|
-
var timeout = setTimeout(function() {
|
|
1938
|
-
delete self.pendingRequests[id];
|
|
1939
|
-
reject(new Error('Request ' + method + ' timed out'));
|
|
1940
|
-
}, 10000);
|
|
1941
|
-
|
|
1942
|
-
self.pendingRequests[id] = { resolve: resolve, reject: reject, timeout: timeout };
|
|
1943
|
-
|
|
1944
|
-
var targetOrigin = self.trustedOrigin || self.trustedOrigins[0];
|
|
1945
|
-
window.parent.postMessage({ jsonrpc: '2.0', id: id, method: method, params: params }, targetOrigin);
|
|
1946
|
-
});
|
|
1947
|
-
},
|
|
1948
|
-
performHandshake: function(context) {
|
|
1949
|
-
var self = this;
|
|
1950
|
-
var params = {
|
|
1951
|
-
appInfo: { name: 'FrontMCP Widget', version: '1.0.0' },
|
|
1952
|
-
appCapabilities: { tools: { listChanged: false } },
|
|
1953
|
-
protocolVersion: '2024-11-05'
|
|
1954
|
-
};
|
|
1955
|
-
|
|
1956
|
-
return this.sendRequest('ui/initialize', params).then(function(result) {
|
|
1957
|
-
self.hostCapabilities = result.hostCapabilities || {};
|
|
1958
|
-
self.capabilities = Object.assign({}, self.capabilities, {
|
|
1959
|
-
canCallTools: Boolean(self.hostCapabilities.serverToolProxy),
|
|
1960
|
-
canSendMessages: true,
|
|
1961
|
-
canOpenLinks: Boolean(self.hostCapabilities.openLink),
|
|
1962
|
-
supportsDisplayModes: true
|
|
1963
|
-
});
|
|
1964
|
-
if (result.hostContext) {
|
|
1965
|
-
Object.assign(context.hostContext, result.hostContext);
|
|
1966
|
-
}
|
|
1967
|
-
});
|
|
1968
|
-
},
|
|
1969
|
-
callTool: function(context, name, args) {
|
|
1970
|
-
if (!this.hostCapabilities.serverToolProxy) {
|
|
1971
|
-
return Promise.reject(new Error('Server tool proxy not supported'));
|
|
1972
|
-
}
|
|
1973
|
-
return this.sendRequest('ui/callServerTool', { name: name, arguments: args });
|
|
1974
|
-
},
|
|
1975
|
-
sendMessage: function(context, content) {
|
|
1976
|
-
return this.sendRequest('ui/message', { content: content });
|
|
1977
|
-
},
|
|
1978
|
-
openLink: function(context, url) {
|
|
1979
|
-
if (!this.hostCapabilities.openLink) {
|
|
1980
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
1981
|
-
return Promise.resolve();
|
|
1982
|
-
}
|
|
1983
|
-
return this.sendRequest('ui/openLink', { url: url });
|
|
1984
|
-
},
|
|
1985
|
-
requestDisplayMode: function(context, mode) {
|
|
1986
|
-
return this.sendRequest('ui/setDisplayMode', { mode: mode });
|
|
1987
|
-
},
|
|
1988
|
-
requestClose: function(context) {
|
|
1989
|
-
return this.sendRequest('ui/close', {});
|
|
1990
|
-
}
|
|
1991
|
-
};
|
|
1992
|
-
`.trim();
|
|
1993
|
-
}
|
|
1994
|
-
function generateClaudeAdapter() {
|
|
1995
|
-
return `
|
|
1996
|
-
var ClaudeAdapter = {
|
|
1997
|
-
id: 'claude',
|
|
1998
|
-
name: 'Claude (Anthropic)',
|
|
1999
|
-
priority: 60,
|
|
2000
|
-
capabilities: Object.assign({}, DEFAULT_CAPABILITIES, {
|
|
2001
|
-
canCallTools: false,
|
|
2002
|
-
canSendMessages: false,
|
|
2003
|
-
canOpenLinks: true,
|
|
2004
|
-
hasNetworkAccess: false,
|
|
2005
|
-
supportsDisplayModes: false
|
|
2006
|
-
}),
|
|
2007
|
-
canHandle: function() {
|
|
2008
|
-
if (typeof window === 'undefined') return false;
|
|
2009
|
-
if (window.__mcpPlatform === 'claude') return true;
|
|
2010
|
-
if (window.claude) return true;
|
|
2011
|
-
if (window.__claudeArtifact) return true;
|
|
2012
|
-
if (typeof location !== 'undefined') {
|
|
2013
|
-
var href = location.href;
|
|
2014
|
-
if (href.indexOf('claude.ai') !== -1 || href.indexOf('anthropic.com') !== -1) return true;
|
|
2015
|
-
}
|
|
2016
|
-
return false;
|
|
2017
|
-
},
|
|
2018
|
-
initialize: function(context) {
|
|
2019
|
-
return Promise.resolve();
|
|
2020
|
-
},
|
|
2021
|
-
callTool: function() {
|
|
2022
|
-
return Promise.reject(new Error('Tool calls not supported in Claude'));
|
|
2023
|
-
},
|
|
2024
|
-
sendMessage: function() {
|
|
2025
|
-
return Promise.reject(new Error('Messages not supported in Claude'));
|
|
2026
|
-
},
|
|
2027
|
-
openLink: function(context, url) {
|
|
2028
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
2029
|
-
return Promise.resolve();
|
|
2030
|
-
},
|
|
2031
|
-
requestDisplayMode: function() {
|
|
2032
|
-
return Promise.resolve();
|
|
2033
|
-
},
|
|
2034
|
-
requestClose: function() {
|
|
2035
|
-
return Promise.resolve();
|
|
2036
|
-
}
|
|
2037
|
-
};
|
|
2038
|
-
`.trim();
|
|
2039
|
-
}
|
|
2040
|
-
function generateGeminiAdapter() {
|
|
2041
|
-
return `
|
|
2042
|
-
var GeminiAdapter = {
|
|
2043
|
-
id: 'gemini',
|
|
2044
|
-
name: 'Google Gemini',
|
|
2045
|
-
priority: 40,
|
|
2046
|
-
capabilities: Object.assign({}, DEFAULT_CAPABILITIES, {
|
|
2047
|
-
canOpenLinks: true,
|
|
2048
|
-
hasNetworkAccess: true
|
|
2049
|
-
}),
|
|
2050
|
-
canHandle: function() {
|
|
2051
|
-
if (typeof window === 'undefined') return false;
|
|
2052
|
-
if (window.__mcpPlatform === 'gemini') return true;
|
|
2053
|
-
if (window.gemini) return true;
|
|
2054
|
-
if (typeof location !== 'undefined') {
|
|
2055
|
-
var href = location.href;
|
|
2056
|
-
if (href.indexOf('gemini.google.com') !== -1 || href.indexOf('bard.google.com') !== -1) return true;
|
|
2057
|
-
}
|
|
2058
|
-
return false;
|
|
2059
|
-
},
|
|
2060
|
-
initialize: function(context) {
|
|
2061
|
-
if (window.gemini && window.gemini.ui && window.gemini.ui.getTheme) {
|
|
2062
|
-
context.hostContext.theme = window.gemini.ui.getTheme() === 'dark' ? 'dark' : 'light';
|
|
2063
|
-
}
|
|
2064
|
-
return Promise.resolve();
|
|
2065
|
-
},
|
|
2066
|
-
callTool: function() {
|
|
2067
|
-
return Promise.reject(new Error('Tool calls not supported in Gemini'));
|
|
2068
|
-
},
|
|
2069
|
-
sendMessage: function(context, content) {
|
|
2070
|
-
if (window.gemini && window.gemini.ui && window.gemini.ui.sendMessage) {
|
|
2071
|
-
return window.gemini.ui.sendMessage(content);
|
|
2072
|
-
}
|
|
2073
|
-
return Promise.reject(new Error('Messages not supported in Gemini'));
|
|
2074
|
-
},
|
|
2075
|
-
openLink: function(context, url) {
|
|
2076
|
-
if (window.gemini && window.gemini.ui && window.gemini.ui.openLink) {
|
|
2077
|
-
return window.gemini.ui.openLink(url);
|
|
2078
|
-
}
|
|
2079
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
2080
|
-
return Promise.resolve();
|
|
2081
|
-
},
|
|
2082
|
-
requestDisplayMode: function() {
|
|
2083
|
-
return Promise.resolve();
|
|
2084
|
-
},
|
|
2085
|
-
requestClose: function() {
|
|
2086
|
-
return Promise.resolve();
|
|
2087
|
-
}
|
|
2088
|
-
};
|
|
2089
|
-
`.trim();
|
|
2090
|
-
}
|
|
2091
|
-
function generateGenericAdapter() {
|
|
2092
|
-
return `
|
|
2093
|
-
var GenericAdapter = {
|
|
2094
|
-
id: 'generic',
|
|
2095
|
-
name: 'Generic Web',
|
|
2096
|
-
priority: 0,
|
|
2097
|
-
capabilities: Object.assign({}, DEFAULT_CAPABILITIES, {
|
|
2098
|
-
canOpenLinks: true,
|
|
2099
|
-
hasNetworkAccess: true
|
|
2100
|
-
}),
|
|
2101
|
-
canHandle: function() {
|
|
2102
|
-
return typeof window !== 'undefined';
|
|
2103
|
-
},
|
|
2104
|
-
initialize: function(context) {
|
|
2105
|
-
return Promise.resolve();
|
|
2106
|
-
},
|
|
2107
|
-
callTool: function() {
|
|
2108
|
-
return Promise.reject(new Error('Tool calls not supported'));
|
|
2109
|
-
},
|
|
2110
|
-
sendMessage: function() {
|
|
2111
|
-
return Promise.reject(new Error('Messages not supported'));
|
|
2112
|
-
},
|
|
2113
|
-
openLink: function(context, url) {
|
|
2114
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
2115
|
-
return Promise.resolve();
|
|
2116
|
-
},
|
|
2117
|
-
requestDisplayMode: function() {
|
|
2118
|
-
return Promise.resolve();
|
|
2119
|
-
},
|
|
2120
|
-
requestClose: function() {
|
|
2121
|
-
return Promise.resolve();
|
|
2122
|
-
}
|
|
2123
|
-
};
|
|
2124
|
-
`.trim();
|
|
2125
|
-
}
|
|
2126
|
-
function generatePlatformDetection(adapters) {
|
|
2127
|
-
const adapterVars = adapters.map((a) => {
|
|
2128
|
-
switch (a) {
|
|
2129
|
-
case "openai":
|
|
2130
|
-
return "OpenAIAdapter";
|
|
2131
|
-
case "ext-apps":
|
|
2132
|
-
return "ExtAppsAdapter";
|
|
2133
|
-
case "claude":
|
|
2134
|
-
return "ClaudeAdapter";
|
|
2135
|
-
case "gemini":
|
|
2136
|
-
return "GeminiAdapter";
|
|
2137
|
-
case "generic":
|
|
2138
|
-
return "GenericAdapter";
|
|
2139
|
-
default:
|
|
2140
|
-
return "";
|
|
2141
|
-
}
|
|
2142
|
-
}).filter(Boolean);
|
|
2143
|
-
return `
|
|
2144
|
-
var ADAPTERS = [${adapterVars.join(", ")}].sort(function(a, b) { return b.priority - a.priority; });
|
|
2145
|
-
|
|
2146
|
-
function detectPlatform() {
|
|
2147
|
-
for (var i = 0; i < ADAPTERS.length; i++) {
|
|
2148
|
-
if (ADAPTERS[i].canHandle()) {
|
|
2149
|
-
log('Detected platform: ' + ADAPTERS[i].id);
|
|
2150
|
-
return ADAPTERS[i];
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
log('No platform detected, using generic');
|
|
2154
|
-
return GenericAdapter;
|
|
2155
|
-
}
|
|
2156
|
-
`.trim();
|
|
2157
|
-
}
|
|
2158
|
-
function generateBridgeClass() {
|
|
2159
|
-
return `
|
|
2160
|
-
function FrontMcpBridge() {
|
|
2161
|
-
this._adapter = null;
|
|
2162
|
-
this._initialized = false;
|
|
2163
|
-
this._context = {
|
|
2164
|
-
hostContext: {
|
|
2165
|
-
theme: detectTheme(),
|
|
2166
|
-
displayMode: 'inline',
|
|
2167
|
-
locale: detectLocale(),
|
|
2168
|
-
userAgent: detectUserAgent(),
|
|
2169
|
-
safeArea: DEFAULT_SAFE_AREA,
|
|
2170
|
-
viewport: detectViewport()
|
|
2171
|
-
},
|
|
2172
|
-
toolInput: {},
|
|
2173
|
-
toolOutput: undefined,
|
|
2174
|
-
structuredContent: undefined,
|
|
2175
|
-
widgetState: {},
|
|
2176
|
-
contextListeners: [],
|
|
2177
|
-
toolResultListeners: [],
|
|
2178
|
-
notifyContextChange: function(changes) {
|
|
2179
|
-
Object.assign(this.hostContext, changes);
|
|
2180
|
-
for (var i = 0; i < this.contextListeners.length; i++) {
|
|
2181
|
-
try { this.contextListeners[i](changes); } catch(e) {}
|
|
2182
|
-
}
|
|
2183
|
-
},
|
|
2184
|
-
notifyToolResult: function(result) {
|
|
2185
|
-
this.toolOutput = result;
|
|
2186
|
-
for (var i = 0; i < this.toolResultListeners.length; i++) {
|
|
2187
|
-
try { this.toolResultListeners[i](result); } catch(e) {}
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
};
|
|
2191
|
-
|
|
2192
|
-
var injected = readInjectedData();
|
|
2193
|
-
this._context.toolInput = injected.toolInput;
|
|
2194
|
-
this._context.toolOutput = injected.toolOutput;
|
|
2195
|
-
this._context.structuredContent = injected.structuredContent;
|
|
2196
|
-
|
|
2197
|
-
this._loadWidgetState();
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
FrontMcpBridge.prototype._loadWidgetState = function() {
|
|
2201
|
-
try {
|
|
2202
|
-
var key = 'frontmcp:widget:' + (window.__mcpToolName || 'unknown');
|
|
2203
|
-
var stored = localStorage.getItem(key);
|
|
2204
|
-
if (stored) this._context.widgetState = JSON.parse(stored);
|
|
2205
|
-
} catch(e) {}
|
|
2206
|
-
};
|
|
2207
|
-
|
|
2208
|
-
FrontMcpBridge.prototype._saveWidgetState = function() {
|
|
2209
|
-
try {
|
|
2210
|
-
var key = 'frontmcp:widget:' + (window.__mcpToolName || 'unknown');
|
|
2211
|
-
localStorage.setItem(key, JSON.stringify(this._context.widgetState));
|
|
2212
|
-
} catch(e) {}
|
|
2213
|
-
};
|
|
2214
|
-
|
|
2215
|
-
FrontMcpBridge.prototype.initialize = function() {
|
|
2216
|
-
if (this._initialized) return Promise.resolve();
|
|
2217
|
-
var self = this;
|
|
2218
|
-
this._adapter = detectPlatform();
|
|
2219
|
-
return this._adapter.initialize(this._context).then(function() {
|
|
2220
|
-
self._initialized = true;
|
|
2221
|
-
// Set up the data-tool-call click handler after initialization
|
|
2222
|
-
self._setupDataToolCallHandler();
|
|
2223
|
-
});
|
|
2224
|
-
};
|
|
2225
|
-
|
|
2226
|
-
Object.defineProperty(FrontMcpBridge.prototype, 'initialized', { get: function() { return this._initialized; } });
|
|
2227
|
-
Object.defineProperty(FrontMcpBridge.prototype, 'adapterId', { get: function() { return this._adapter ? this._adapter.id : undefined; } });
|
|
2228
|
-
Object.defineProperty(FrontMcpBridge.prototype, 'capabilities', { get: function() { return this._adapter ? this._adapter.capabilities : DEFAULT_CAPABILITIES; } });
|
|
2229
|
-
|
|
2230
|
-
FrontMcpBridge.prototype.getTheme = function() { return this._context.hostContext.theme; };
|
|
2231
|
-
FrontMcpBridge.prototype.getDisplayMode = function() { return this._context.hostContext.displayMode; };
|
|
2232
|
-
FrontMcpBridge.prototype.getToolInput = function() { return this._context.toolInput; };
|
|
2233
|
-
FrontMcpBridge.prototype.getToolOutput = function() { return this._context.toolOutput; };
|
|
2234
|
-
FrontMcpBridge.prototype.getStructuredContent = function() { return this._context.structuredContent; };
|
|
2235
|
-
FrontMcpBridge.prototype.getWidgetState = function() { return this._context.widgetState; };
|
|
2236
|
-
FrontMcpBridge.prototype.getHostContext = function() { return Object.assign({}, this._context.hostContext); };
|
|
2237
|
-
FrontMcpBridge.prototype.hasCapability = function(cap) { return this._adapter && this._adapter.capabilities[cap] === true; };
|
|
2238
|
-
|
|
2239
|
-
// Get tool response metadata (platform-agnostic)
|
|
2240
|
-
// Used by inline mode widgets to detect when ui/html arrives
|
|
2241
|
-
FrontMcpBridge.prototype.getToolResponseMetadata = function() {
|
|
2242
|
-
// OpenAI injects toolResponseMetadata for widget-producing tools
|
|
2243
|
-
if (typeof window !== 'undefined' && window.openai && window.openai.toolResponseMetadata) {
|
|
2244
|
-
return window.openai.toolResponseMetadata;
|
|
2245
|
-
}
|
|
2246
|
-
// Claude (future support)
|
|
2247
|
-
if (typeof window !== 'undefined' && window.claude && window.claude.toolResponseMetadata) {
|
|
2248
|
-
return window.claude.toolResponseMetadata;
|
|
2249
|
-
}
|
|
2250
|
-
// FrontMCP direct injection (for testing/ext-apps)
|
|
2251
|
-
if (typeof window !== 'undefined' && window.__mcpToolResponseMetadata) {
|
|
2252
|
-
return window.__mcpToolResponseMetadata;
|
|
2253
|
-
}
|
|
2254
|
-
return null;
|
|
2255
|
-
};
|
|
2256
|
-
|
|
2257
|
-
// Subscribe to tool response metadata changes (for inline mode injection)
|
|
2258
|
-
FrontMcpBridge.prototype.onToolResponseMetadata = function(callback) {
|
|
2259
|
-
var self = this;
|
|
2260
|
-
var called = false;
|
|
2261
|
-
|
|
2262
|
-
// Check if already available
|
|
2263
|
-
var existing = self.getToolResponseMetadata();
|
|
2264
|
-
if (existing) {
|
|
2265
|
-
called = true;
|
|
2266
|
-
callback(existing);
|
|
2267
|
-
}
|
|
2268
|
-
|
|
2269
|
-
// Set up property interceptors for OpenAI
|
|
2270
|
-
if (typeof window !== 'undefined') {
|
|
2271
|
-
// OpenAI: Intercept toolResponseMetadata assignment
|
|
2272
|
-
if (!window.__frontmcpMetadataIntercepted) {
|
|
2273
|
-
window.__frontmcpMetadataIntercepted = true;
|
|
2274
|
-
window.__frontmcpMetadataCallbacks = [];
|
|
2275
|
-
|
|
2276
|
-
// Create openai object if it doesn't exist
|
|
2277
|
-
if (!window.openai) window.openai = {};
|
|
2278
|
-
|
|
2279
|
-
var originalMetadata = window.openai.toolResponseMetadata;
|
|
2280
|
-
Object.defineProperty(window.openai, 'toolResponseMetadata', {
|
|
2281
|
-
get: function() { return originalMetadata; },
|
|
2282
|
-
set: function(val) {
|
|
2283
|
-
originalMetadata = val;
|
|
2284
|
-
log('toolResponseMetadata set, notifying ' + window.__frontmcpMetadataCallbacks.length + ' listeners');
|
|
2285
|
-
for (var i = 0; i < window.__frontmcpMetadataCallbacks.length; i++) {
|
|
2286
|
-
try { window.__frontmcpMetadataCallbacks[i](val); } catch(e) {}
|
|
2287
|
-
}
|
|
2288
|
-
},
|
|
2289
|
-
configurable: true
|
|
2290
|
-
});
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
// Register callback wrapper (store reference for unsubscribe)
|
|
2294
|
-
var wrapper = function(metadata) {
|
|
2295
|
-
if (!called) {
|
|
2296
|
-
called = true;
|
|
2297
|
-
callback(metadata);
|
|
2298
|
-
}
|
|
2299
|
-
};
|
|
2300
|
-
window.__frontmcpMetadataCallbacks.push(wrapper);
|
|
2301
|
-
|
|
2302
|
-
// Return unsubscribe function that removes the wrapper (not the original callback)
|
|
2303
|
-
return function() {
|
|
2304
|
-
if (window.__frontmcpMetadataCallbacks) {
|
|
2305
|
-
var idx = window.__frontmcpMetadataCallbacks.indexOf(wrapper);
|
|
2306
|
-
if (idx !== -1) window.__frontmcpMetadataCallbacks.splice(idx, 1);
|
|
2307
|
-
}
|
|
2308
|
-
};
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
// Return no-op unsubscribe for non-window environments
|
|
2312
|
-
return function() {};
|
|
2313
|
-
};
|
|
2314
|
-
|
|
2315
|
-
FrontMcpBridge.prototype.callTool = function(name, args) {
|
|
2316
|
-
// Priority 1: Direct OpenAI SDK call (most reliable in OpenAI iframe)
|
|
2317
|
-
// This bypasses adapter abstraction for maximum compatibility
|
|
2318
|
-
if (typeof window !== 'undefined' && window.openai && typeof window.openai.callTool === 'function') {
|
|
2319
|
-
log('callTool: Using OpenAI SDK directly');
|
|
2320
|
-
return window.openai.callTool(name, args);
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
// Priority 2: Use adapter (if initialized and supports tool calls)
|
|
2324
|
-
if (this._adapter && this._adapter.capabilities && this._adapter.capabilities.canCallTools) {
|
|
2325
|
-
log('callTool: Using adapter ' + this._adapter.id);
|
|
2326
|
-
return this._adapter.callTool(this._context, name, args);
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
// Not initialized or no tool support
|
|
2330
|
-
if (!this._adapter) {
|
|
2331
|
-
return Promise.reject(new Error('Bridge not initialized. Wait for bridge:ready event.'));
|
|
2332
|
-
}
|
|
2333
|
-
return Promise.reject(new Error('Tool calls not supported on this platform (' + this._adapter.id + ')'));
|
|
2334
|
-
};
|
|
2335
|
-
|
|
2336
|
-
FrontMcpBridge.prototype.sendMessage = function(content) {
|
|
2337
|
-
if (!this._adapter) return Promise.reject(new Error('Not initialized'));
|
|
2338
|
-
return this._adapter.sendMessage(this._context, content);
|
|
2339
|
-
};
|
|
2340
|
-
|
|
2341
|
-
FrontMcpBridge.prototype.openLink = function(url) {
|
|
2342
|
-
if (!this._adapter) return Promise.reject(new Error('Not initialized'));
|
|
2343
|
-
return this._adapter.openLink(this._context, url);
|
|
2344
|
-
};
|
|
2345
|
-
|
|
2346
|
-
FrontMcpBridge.prototype.requestDisplayMode = function(mode) {
|
|
2347
|
-
if (!this._adapter) return Promise.reject(new Error('Not initialized'));
|
|
2348
|
-
var self = this;
|
|
2349
|
-
return this._adapter.requestDisplayMode(this._context, mode).then(function() {
|
|
2350
|
-
self._context.hostContext.displayMode = mode;
|
|
2351
|
-
});
|
|
2352
|
-
};
|
|
2353
|
-
|
|
2354
|
-
FrontMcpBridge.prototype.requestClose = function() {
|
|
2355
|
-
if (!this._adapter) return Promise.reject(new Error('Not initialized'));
|
|
2356
|
-
return this._adapter.requestClose(this._context);
|
|
2357
|
-
};
|
|
2358
|
-
|
|
2359
|
-
FrontMcpBridge.prototype.setWidgetState = function(state) {
|
|
2360
|
-
Object.assign(this._context.widgetState, state);
|
|
2361
|
-
this._saveWidgetState();
|
|
2362
|
-
};
|
|
2363
|
-
|
|
2364
|
-
FrontMcpBridge.prototype.onContextChange = function(callback) {
|
|
2365
|
-
var listeners = this._context.contextListeners;
|
|
2366
|
-
listeners.push(callback);
|
|
2367
|
-
return function() {
|
|
2368
|
-
var idx = listeners.indexOf(callback);
|
|
2369
|
-
if (idx !== -1) listeners.splice(idx, 1);
|
|
2370
|
-
};
|
|
2371
|
-
};
|
|
2372
|
-
|
|
2373
|
-
FrontMcpBridge.prototype.onToolResult = function(callback) {
|
|
2374
|
-
var listeners = this._context.toolResultListeners;
|
|
2375
|
-
listeners.push(callback);
|
|
2376
|
-
return function() {
|
|
2377
|
-
var idx = listeners.indexOf(callback);
|
|
2378
|
-
if (idx !== -1) listeners.splice(idx, 1);
|
|
2379
|
-
};
|
|
2380
|
-
};
|
|
2381
|
-
|
|
2382
|
-
// ==================== data-tool-call Click Handler ====================
|
|
2383
|
-
|
|
2384
|
-
FrontMcpBridge.prototype._setupDataToolCallHandler = function() {
|
|
2385
|
-
var self = this;
|
|
2386
|
-
|
|
2387
|
-
document.addEventListener('click', function(e) {
|
|
2388
|
-
// Find the closest element with data-tool-call attribute
|
|
2389
|
-
var target = e.target;
|
|
2390
|
-
while (target && target !== document) {
|
|
2391
|
-
if (target.hasAttribute && target.hasAttribute('data-tool-call')) {
|
|
2392
|
-
var toolName = target.getAttribute('data-tool-call');
|
|
2393
|
-
var argsAttr = target.getAttribute('data-tool-args');
|
|
2394
|
-
var args = {};
|
|
2395
|
-
|
|
2396
|
-
try {
|
|
2397
|
-
if (argsAttr) {
|
|
2398
|
-
args = JSON.parse(argsAttr);
|
|
2399
|
-
}
|
|
2400
|
-
} catch (parseErr) {
|
|
2401
|
-
console.error('[frontmcp] Failed to parse data-tool-args:', parseErr);
|
|
2402
|
-
}
|
|
2403
|
-
|
|
2404
|
-
log('data-tool-call clicked: ' + toolName);
|
|
2405
|
-
|
|
2406
|
-
// Show loading state - save original content first
|
|
2407
|
-
var originalContent = target.innerHTML;
|
|
2408
|
-
var originalDisabled = target.disabled;
|
|
2409
|
-
target.disabled = true;
|
|
2410
|
-
target.classList.add('opacity-50', 'cursor-not-allowed');
|
|
2411
|
-
|
|
2412
|
-
// Add spinner for buttons
|
|
2413
|
-
var spinner = '<svg class="animate-spin -ml-1 mr-2 h-4 w-4 inline" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>';
|
|
2414
|
-
if (target.tagName === 'BUTTON') {
|
|
2415
|
-
target.innerHTML = spinner + 'Loading...';
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
// Helper to reset button state
|
|
2419
|
-
function resetButton() {
|
|
2420
|
-
target.innerHTML = originalContent;
|
|
2421
|
-
target.disabled = originalDisabled;
|
|
2422
|
-
target.classList.remove('opacity-50', 'cursor-not-allowed');
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
|
-
// Determine how to call the tool
|
|
2426
|
-
var toolCallPromise;
|
|
2427
|
-
|
|
2428
|
-
// Priority 1: Direct OpenAI SDK call (bypasses adapter abstraction)
|
|
2429
|
-
if (typeof window !== 'undefined' && window.openai && typeof window.openai.callTool === 'function') {
|
|
2430
|
-
log('Using OpenAI SDK directly for tool call');
|
|
2431
|
-
toolCallPromise = window.openai.callTool(toolName, args);
|
|
2432
|
-
}
|
|
2433
|
-
// Priority 2: Use adapter (if it supports tool calls)
|
|
2434
|
-
else if (self.hasCapability('canCallTools')) {
|
|
2435
|
-
log('Using adapter for tool call');
|
|
2436
|
-
toolCallPromise = self.callTool(toolName, args);
|
|
2437
|
-
}
|
|
2438
|
-
// No tool call capability
|
|
2439
|
-
else {
|
|
2440
|
-
console.error('[frontmcp] Tool calls not supported on this platform (' + self.adapterId + ')');
|
|
2441
|
-
resetButton();
|
|
2442
|
-
target.dispatchEvent(new CustomEvent('tool:error', {
|
|
2443
|
-
detail: { name: toolName, args: args, error: 'Tool calls not supported on this platform' },
|
|
2444
|
-
bubbles: true
|
|
2445
|
-
}));
|
|
2446
|
-
e.preventDefault();
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
|
|
2450
|
-
// Handle the tool call result
|
|
2451
|
-
toolCallPromise.then(function(result) {
|
|
2452
|
-
log('Tool call succeeded: ' + toolName);
|
|
2453
|
-
resetButton();
|
|
2454
|
-
|
|
2455
|
-
// Update bridge state to trigger widget re-render
|
|
2456
|
-
// React isn't hydrated in OpenAI iframe, so useState doesn't work
|
|
2457
|
-
// Instead, we use the bridge's reactive state system
|
|
2458
|
-
if (result && window.__frontmcp && window.__frontmcp.bridge && typeof window.__frontmcp.bridge.setWidgetState === 'function') {
|
|
2459
|
-
var newData = result.structuredContent || result;
|
|
2460
|
-
log('Updating bridge state with new data');
|
|
2461
|
-
window.__frontmcp.bridge.setWidgetState(newData);
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
// Dispatch success event
|
|
2465
|
-
target.dispatchEvent(new CustomEvent('tool:success', {
|
|
2466
|
-
detail: { name: toolName, args: args, result: result },
|
|
2467
|
-
bubbles: true
|
|
2468
|
-
}));
|
|
2469
|
-
}).catch(function(err) {
|
|
2470
|
-
console.error('[frontmcp] Tool call failed: ' + toolName, err);
|
|
2471
|
-
resetButton();
|
|
2472
|
-
// Dispatch error event
|
|
2473
|
-
target.dispatchEvent(new CustomEvent('tool:error', {
|
|
2474
|
-
detail: { name: toolName, args: args, error: err.message || err },
|
|
2475
|
-
bubbles: true
|
|
2476
|
-
}));
|
|
2477
|
-
});
|
|
2478
|
-
|
|
2479
|
-
// Prevent default behavior (e.g., form submission)
|
|
2480
|
-
e.preventDefault();
|
|
2481
|
-
return;
|
|
2482
|
-
}
|
|
2483
|
-
target = target.parentElement;
|
|
2484
|
-
}
|
|
2485
|
-
}, true); // Use capture phase to handle before React handlers
|
|
2486
|
-
};
|
|
2487
|
-
`.trim();
|
|
2488
|
-
}
|
|
2489
|
-
function minifyJS(code) {
|
|
2490
|
-
return code.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/\s+/g, " ").replace(/\s*([{};,:()[\]])\s*/g, "$1").replace(/;\}/g, "}").trim();
|
|
2491
|
-
}
|
|
2492
|
-
function generatePlatformBundle(platform, options = {}) {
|
|
2493
|
-
const platformAdapters = {
|
|
2494
|
-
chatgpt: ["openai", "generic"],
|
|
2495
|
-
claude: ["claude", "generic"],
|
|
2496
|
-
gemini: ["gemini", "generic"],
|
|
2497
|
-
universal: ["openai", "ext-apps", "claude", "gemini", "generic"]
|
|
2498
|
-
};
|
|
2499
|
-
return generateBridgeIIFE({
|
|
2500
|
-
...options,
|
|
2501
|
-
adapters: platformAdapters[platform]
|
|
2502
|
-
});
|
|
2503
|
-
}
|
|
2504
|
-
var UNIVERSAL_BRIDGE_SCRIPT = generateBridgeIIFE();
|
|
2505
|
-
var BRIDGE_SCRIPT_TAGS = {
|
|
2506
|
-
universal: `<script>${UNIVERSAL_BRIDGE_SCRIPT}</script>`,
|
|
2507
|
-
chatgpt: `<script>${generatePlatformBundle("chatgpt")}</script>`,
|
|
2508
|
-
claude: `<script>${generatePlatformBundle("claude")}</script>`,
|
|
2509
|
-
gemini: `<script>${generatePlatformBundle("gemini")}</script>`
|
|
2510
|
-
};
|
|
1667
|
+
// libs/ui/src/bridge/runtime/index.ts
|
|
1668
|
+
var import_uipack = require("@frontmcp/uipack");
|
|
2511
1669
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2512
1670
|
0 && (module.exports = {
|
|
2513
1671
|
AdapterRegistry,
|