@nimblebrain/synapse 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{chunk-YOABHZ5F.js → chunk-E7OOOYVR.js} +3 -3
- package/dist/{chunk-YOABHZ5F.js.map → chunk-E7OOOYVR.js.map} +1 -1
- package/dist/{chunk-WCJLRS3H.js → chunk-GNTQJSQX.js} +3 -3
- package/dist/{chunk-WCJLRS3H.js.map → chunk-GNTQJSQX.js.map} +1 -1
- package/dist/{chunk-FMKXRFQ4.js → chunk-J5ICAHK2.js} +2 -6
- package/dist/chunk-J5ICAHK2.js.map +1 -0
- package/dist/{chunk-KK7DWFDF.cjs → chunk-RYWW6EHB.cjs} +2 -6
- package/dist/chunk-RYWW6EHB.cjs.map +1 -0
- package/dist/{chunk-6SV2KTTB.cjs → chunk-SN7YXLAV.cjs} +6 -6
- package/dist/{chunk-6SV2KTTB.cjs.map → chunk-SN7YXLAV.cjs.map} +1 -1
- package/dist/{chunk-DRUHNVEN.cjs → chunk-ZMNYUGSF.cjs} +15 -15
- package/dist/{chunk-DRUHNVEN.cjs.map → chunk-ZMNYUGSF.cjs.map} +1 -1
- package/dist/connect.iife.global.js +1 -1
- package/dist/host/index.cjs +14 -14
- package/dist/host/index.js +2 -2
- package/dist/index.cjs +10 -10
- package/dist/index.js +3 -3
- package/dist/react/index.cjs +5 -5
- package/dist/react/index.js +2 -2
- package/dist/synapse-runtime.iife.global.js +1 -1
- package/dist/synapse-ui.iife.global.js +2 -2
- package/dist/ui/index.cjs +2 -5
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +8 -7
- package/dist/ui/index.d.ts +8 -7
- package/dist/ui/index.js +2 -5
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-FMKXRFQ4.js.map +0 -1
- package/dist/chunk-KK7DWFDF.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { HostUnsupportedError, SYNAPSE_DATA_ELEMENT_ID, connectUI, detectHostKind } from './chunk-
|
|
2
|
-
export { connect, createSynapse } from './chunk-
|
|
3
|
-
export { FONT_FACES_CONTEXT_KEY } from './chunk-
|
|
1
|
+
export { HostUnsupportedError, SYNAPSE_DATA_ELEMENT_ID, connectUI, detectHostKind } from './chunk-E7OOOYVR.js';
|
|
2
|
+
export { connect, createSynapse } from './chunk-GNTQJSQX.js';
|
|
3
|
+
export { FONT_FACES_CONTEXT_KEY } from './chunk-J5ICAHK2.js';
|
|
4
4
|
|
|
5
5
|
// src/store.ts
|
|
6
6
|
function createStore(synapse, config) {
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkZMNYUGSF_cjs = require('../chunk-ZMNYUGSF.cjs');
|
|
4
|
+
var chunkRYWW6EHB_cjs = require('../chunk-RYWW6EHB.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
@@ -12,7 +12,7 @@ function AppProvider({ children, name, version, autoResize }) {
|
|
|
12
12
|
react.useEffect(() => {
|
|
13
13
|
if (connectingRef.current) return;
|
|
14
14
|
connectingRef.current = true;
|
|
15
|
-
|
|
15
|
+
chunkZMNYUGSF_cjs.connect({ name, version, autoResize }).then((a) => {
|
|
16
16
|
setApp(a);
|
|
17
17
|
});
|
|
18
18
|
}, []);
|
|
@@ -72,7 +72,7 @@ var SynapseContext = react.createContext(null);
|
|
|
72
72
|
function SynapseProvider({ children, ...options }) {
|
|
73
73
|
const ref = react.useRef(null);
|
|
74
74
|
if (ref.current === null || ref.current.destroyed) {
|
|
75
|
-
ref.current =
|
|
75
|
+
ref.current = chunkZMNYUGSF_cjs.createSynapse(options);
|
|
76
76
|
}
|
|
77
77
|
return /* @__PURE__ */ jsxRuntime.jsxs(SynapseContext.Provider, { value: ref.current, children: [
|
|
78
78
|
/* @__PURE__ */ jsxRuntime.jsx(ThemeInjector, { synapse: ref.current }),
|
|
@@ -86,7 +86,7 @@ function ThemeInjector({ synapse }) {
|
|
|
86
86
|
return synapse.onThemeChanged(setTheme);
|
|
87
87
|
}, [synapse]);
|
|
88
88
|
react.useEffect(() => {
|
|
89
|
-
|
|
89
|
+
chunkRYWW6EHB_cjs.applyTheme(theme.mode, theme.tokens, theme.fontFaces);
|
|
90
90
|
}, [theme]);
|
|
91
91
|
return null;
|
|
92
92
|
}
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { connect, createSynapse } from '../chunk-
|
|
2
|
-
import { applyTheme } from '../chunk-
|
|
1
|
+
import { connect, createSynapse } from '../chunk-GNTQJSQX.js';
|
|
2
|
+
import { applyTheme } from '../chunk-J5ICAHK2.js';
|
|
3
3
|
import { createContext, useState, useRef, useEffect, useCallback, useSyncExternalStore, useContext } from 'react';
|
|
4
4
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
5
|
|
|
@@ -75,7 +75,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
75
75
|
- omitted: host decides border`)});l.object({method:l.literal("ui/request-display-mode"),params:l.object({mode:mo.describe("The display mode being requested.")})});l.object({mode:mo.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough();var $x=l.union([l.literal("model"),l.literal("app")]).describe("Tool visibility scope - who can access the tool.");l.object({resourceUri:l.string().optional(),visibility:l.array($x).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
76
76
|
- "model": Tool visible to and callable by the agent
|
|
77
77
|
- "app": Tool callable by the app from this server only`)});l.object({mimeTypes:l.array(l.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});l.object({method:l.literal("ui/download-file"),params:l.object({contents:l.array(l.union([td,rd])).describe("Resource contents to download \u2014 embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})});l.object({method:l.literal("ui/message"),params:l.object({role:l.literal("user").describe('Message role, currently only "user" is supported.'),content:l.array(Nr).describe("Message content blocks (text, image, etc.).")})});l.object({method:l.literal("ui/notifications/sandbox-resource-ready"),params:l.object({html:l.string().describe("HTML content to load into the inner iframe."),sandbox:l.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:nd.optional().describe("CSP configuration from resource metadata."),permissions:od.optional().describe("Sandbox permissions from resource metadata.")})});l.object({method:l.literal("ui/notifications/tool-result"),params:lo.describe("Standard MCP tool execution result.")});var Cf=l.object({toolInfo:l.object({id:Er.optional().describe("JSON-RPC id of the tools/call request."),tool:ks.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:gx.optional().describe("Current color theme preference."),styles:_x.optional().describe("Style configuration for theming the app."),displayMode:mo.optional().describe("How the UI is currently displayed."),availableDisplayModes:l.array(mo).optional().describe("Display modes the host supports."),containerDimensions:l.union([l.object({height:l.number().describe("Fixed container height in pixels.")}),l.object({maxHeight:l.union([l.number(),l.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(l.union([l.object({width:l.number().describe("Fixed container width in pixels.")}),l.object({maxWidth:l.union([l.number(),l.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
78
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:l.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:l.string().optional().describe("User's timezone in IANA format."),userAgent:l.string().optional().describe("Host application identifier."),platform:l.union([l.literal("web"),l.literal("desktop"),l.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:l.object({touch:l.boolean().optional().describe("Whether the device supports touch input."),hover:l.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:l.object({top:l.number().describe("Top safe area inset in pixels."),right:l.number().describe("Right safe area inset in pixels."),bottom:l.number().describe("Bottom safe area inset in pixels."),left:l.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough();l.object({method:l.literal("ui/notifications/host-context-changed"),params:Cf.describe("Partial context update containing only changed fields.")});l.object({method:l.literal("ui/update-model-context"),params:l.object({content:l.array(Nr).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:l.record(l.string(),l.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});l.object({method:l.literal("ui/initialize"),params:l.object({appInfo:io.describe("App identification (name and version)."),appCapabilities:bx.describe("Features and capabilities this app provides."),protocolVersion:l.string().describe("Protocol version this app supports.")})});l.object({protocolVersion:l.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:io.describe("Host application identification and version."),hostCapabilities:xx.describe("Features and capabilities provided by the host."),hostContext:Cf.describe("Rich context about the host environment.")}).passthrough();function Af(e){let r=e??{},n=r.structuredContent??null;if(n!=null)return {content:n,structuredContent:n,raw:r};let i=r.content;if(Array.isArray(i)){let t=i.filter(o=>o!=null&&typeof o=="object"&&o.type==="text"&&typeof o.text=="string").map(o=>o.text);if(t.length>0){let o=t.join("");try{return {content:JSON.parse(o),structuredContent:null,raw:r}}catch{return {content:o,structuredContent:null,raw:r}}}return {content:i,structuredContent:null,raw:r}}if(typeof i=="string")try{return {content:JSON.parse(i),structuredContent:null,raw:r}}catch{return {content:i,structuredContent:null,raw:r}}return {content:i??null,structuredContent:null,raw:r}}var kx=new Set(["auto","block","swap","fallback","optional"]),Sx={"--color-background-primary":"#ffffff","--color-background-secondary":"#fafafa","--color-background-tertiary":"#f3f4f6","--color-text-primary":"#111827","--color-text-secondary":"#6b7280","--color-text-tertiary":"#9ca3af","--color-text-accent":"#2563eb","--nb-color-accent-foreground":"#ffffff","--color-border-primary":"#e5e7eb","--color-border-secondary":"#d1d5db","--color-ring-primary":"#2563eb","--nb-color-danger":"#dc2626","--nb-color-success":"#059669","--nb-color-warning":"#f59e0b","--nb-color-
|
|
78
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:l.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:l.string().optional().describe("User's timezone in IANA format."),userAgent:l.string().optional().describe("Host application identifier."),platform:l.union([l.literal("web"),l.literal("desktop"),l.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:l.object({touch:l.boolean().optional().describe("Whether the device supports touch input."),hover:l.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:l.object({top:l.number().describe("Top safe area inset in pixels."),right:l.number().describe("Right safe area inset in pixels."),bottom:l.number().describe("Bottom safe area inset in pixels."),left:l.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough();l.object({method:l.literal("ui/notifications/host-context-changed"),params:Cf.describe("Partial context update containing only changed fields.")});l.object({method:l.literal("ui/update-model-context"),params:l.object({content:l.array(Nr).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:l.record(l.string(),l.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});l.object({method:l.literal("ui/initialize"),params:l.object({appInfo:io.describe("App identification (name and version)."),appCapabilities:bx.describe("Features and capabilities this app provides."),protocolVersion:l.string().describe("Protocol version this app supports.")})});l.object({protocolVersion:l.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:io.describe("Host application identification and version."),hostCapabilities:xx.describe("Features and capabilities provided by the host."),hostContext:Cf.describe("Rich context about the host environment.")}).passthrough();function Af(e){let r=e??{},n=r.structuredContent??null;if(n!=null)return {content:n,structuredContent:n,raw:r};let i=r.content;if(Array.isArray(i)){let t=i.filter(o=>o!=null&&typeof o=="object"&&o.type==="text"&&typeof o.text=="string").map(o=>o.text);if(t.length>0){let o=t.join("");try{return {content:JSON.parse(o),structuredContent:null,raw:r}}catch{return {content:o,structuredContent:null,raw:r}}}return {content:i,structuredContent:null,raw:r}}if(typeof i=="string")try{return {content:JSON.parse(i),structuredContent:null,raw:r}}catch{return {content:i,structuredContent:null,raw:r}}return {content:i??null,structuredContent:null,raw:r}}var kx=new Set(["auto","block","swap","fallback","optional"]),Sx={"--color-background-primary":"#ffffff","--color-background-secondary":"#fafafa","--color-background-tertiary":"#f3f4f6","--color-text-primary":"#111827","--color-text-secondary":"#6b7280","--color-text-tertiary":"#9ca3af","--color-text-accent":"#2563eb","--nb-color-accent-foreground":"#ffffff","--color-border-primary":"#e5e7eb","--color-border-secondary":"#d1d5db","--color-ring-primary":"#2563eb","--nb-color-danger":"#dc2626","--nb-color-success":"#059669","--nb-color-warning":"#f59e0b","--nb-color-processing":"#7c3aed","--nb-color-processing-light":"#f3eeff","--nb-color-info-light":"#eef4ff"},zx={"--color-background-primary":"#18181b","--color-background-secondary":"#27272a","--color-background-tertiary":"#2f2f34","--color-text-primary":"#fafafa","--color-text-secondary":"#a1a1aa","--color-text-tertiary":"#71717a","--color-text-accent":"#818cf8","--nb-color-accent-foreground":"#ffffff","--color-border-primary":"#3f3f46","--color-border-secondary":"#52525b","--color-ring-primary":"#818cf8","--nb-color-danger":"#f87171","--nb-color-success":"#34d399","--nb-color-warning":"#fbbf24","--nb-color-processing":"#a78bfa","--nb-color-processing-light":"#2a2440","--nb-color-info-light":"#1e2a44"},wx={light:Sx,dark:zx},Ix="synapse-defaults",Mf="synapse-theme-defaults",Lf=new Set;function Tx(){return typeof document<"u"&&typeof document.getElementById=="function"&&typeof document.createElement=="function"&&typeof document.head?.prepend=="function"}function Px(e){if(!Tx())return;let r=Object.entries(wx[e]).map(([o,a])=>` ${o}: ${a};`).join(`
|
|
79
79
|
`),n=`@layer ${Ix} {
|
|
80
80
|
:root {
|
|
81
81
|
${r}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(){'use strict';var be=new Set(["auto","block","swap","fallback","optional"]),ke={"--color-background-primary":"#ffffff","--color-background-secondary":"#fafafa","--color-background-tertiary":"#f3f4f6","--color-text-primary":"#111827","--color-text-secondary":"#6b7280","--color-text-tertiary":"#9ca3af","--color-text-accent":"#2563eb","--nb-color-accent-foreground":"#ffffff","--color-border-primary":"#e5e7eb","--color-border-secondary":"#d1d5db","--color-ring-primary":"#2563eb","--nb-color-danger":"#dc2626","--nb-color-success":"#059669","--nb-color-warning":"#f59e0b","--nb-color-
|
|
1
|
+
(function(){'use strict';var be=new Set(["auto","block","swap","fallback","optional"]),ke={"--color-background-primary":"#ffffff","--color-background-secondary":"#fafafa","--color-background-tertiary":"#f3f4f6","--color-text-primary":"#111827","--color-text-secondary":"#6b7280","--color-text-tertiary":"#9ca3af","--color-text-accent":"#2563eb","--nb-color-accent-foreground":"#ffffff","--color-border-primary":"#e5e7eb","--color-border-secondary":"#d1d5db","--color-ring-primary":"#2563eb","--nb-color-danger":"#dc2626","--nb-color-success":"#059669","--nb-color-warning":"#f59e0b","--nb-color-processing":"#7c3aed","--nb-color-processing-light":"#f3eeff","--nb-color-info-light":"#eef4ff"},Pe={"--color-background-primary":"#18181b","--color-background-secondary":"#27272a","--color-background-tertiary":"#2f2f34","--color-text-primary":"#fafafa","--color-text-secondary":"#a1a1aa","--color-text-tertiary":"#71717a","--color-text-accent":"#818cf8","--nb-color-accent-foreground":"#ffffff","--color-border-primary":"#3f3f46","--color-border-secondary":"#52525b","--color-ring-primary":"#818cf8","--nb-color-danger":"#f87171","--nb-color-success":"#34d399","--nb-color-warning":"#fbbf24","--nb-color-processing":"#a78bfa","--nb-color-processing-light":"#2a2440","--nb-color-info-light":"#1e2a44"},Ee={light:ke,dark:Pe},Ie="synapse-defaults",G="synapse-theme-defaults",W=new Set;function ve(){return typeof document<"u"&&typeof document.getElementById=="function"&&typeof document.createElement=="function"&&typeof document.head?.prepend=="function"}function Ce(e){if(!ve())return;let o=Object.entries(Ee[e]).map(([a,p])=>` ${a}: ${p};`).join(`
|
|
2
2
|
`),n=`@layer ${Ie} {
|
|
3
3
|
:root {
|
|
4
4
|
${o}
|
|
5
5
|
}
|
|
6
|
-
}`,s=document.getElementById(G);if(s){s.textContent!==n&&(s.textContent=n);return}let i=document.createElement("style");i.id=G,i.textContent=n,document.head.prepend(i);}function
|
|
6
|
+
}`,s=document.getElementById(G);if(s){s.textContent!==n&&(s.textContent=n);return}let i=document.createElement("style");i.id=G,i.textContent=n,document.head.prepend(i);}function we(e,o){if(typeof document>"u")return;Ce(e);let n={};if(o&&typeof o=="object")for(let[i,a]of Object.entries(o))typeof i=="string"&&typeof a=="string"&&(n[i]=a);let s=document.documentElement.style;if(typeof s.removeProperty=="function")for(let i of W)i in n||s.removeProperty(i);for(let[i,a]of Object.entries(n))s.setProperty(i,a);W=new Set(Object.keys(n));}var F=new Set,Y="";function A(e){return Array.isArray(e)?JSON.stringify(e.map(o=>[o.family,o.src,o.weight,o.style,o.display])):""}function M(e){if(!Array.isArray(e))return;let o=e.filter(Oe);if(!(e.length>0&&o.length===0))return o}function Ae(e){let o=M(e);if(o===void 0||typeof document>"u"||!document.fonts||typeof FontFace>"u")return;let n=A(o);if(n!==Y){Y=n;for(let s of F)try{document.fonts.delete(s);}catch{}F.clear();for(let s of o)try{let i=new FontFace(s.family,s.src,{weight:s.weight,style:s.style,display:s.display&&be.has(s.display)?s.display:"swap"});document.fonts.add(i),F.add(i);}catch{}}}function Oe(e){if(!e||typeof e!="object")return false;let o=e;return typeof o.family=="string"&&typeof o.src=="string"}function V(e,o,n){we(e,o),Ae(n);}function R(e){typeof document<"u"&&document.documentElement.setAttribute("data-theme",e.mode),V(e.mode,e.tokens,e.fontFaces);}function O(e){try{if(e?.matchMedia?.("(prefers-color-scheme: dark)").matches)return "dark"}catch{}return "light"}function h(e,o){return e==="light"||e==="dark"?e:o}var T=class extends Error{constructor(o,n){super(`"${o}" is not supported by the "${n}" host`),this.name="HostUnsupportedError";}},_="synapse-ui-data",Z="ui-lifecycle-iframe-ready",$="ui-lifecycle-iframe-render-data",B="ui-size-change",q="link",Q="prompt",U="openai:set_globals",X="2026-01-26",J="ui/initialize",ee="ui/notifications/initialized",te="ui/notifications/tool-result",ne="ui/notifications/host-context-changed",oe="ui/notifications/size-changed",re="ui/open-link",se="ui/message",ie="ui/resource-teardown",ae="tools/call";function ce(e,o){let n=()=>e.openai,s=n()?.toolOutput??null,i={mode:h(n()?.theme,"light"),tokens:{}},a=new Set,p=new Set,f=false,m=c=>{if(f)return;let l=c.detail?.globals;if(l){if("toolOutput"in l&&l.toolOutput!=null){s=l.toolOutput;for(let u of a)u(s);}if("theme"in l&&l.theme!=null){let u=h(l.theme,i.mode);if(u!==i.mode){i={mode:u,tokens:{}};for(let b of p)b(i);}}}};return {host:"chatgpt",getData:()=>s,onData(c){return a.add(c),()=>a.delete(c)},getTheme:()=>i,onTheme(c){return p.add(c),()=>p.delete(c)},async callTool(c,l){let u=n()?.callTool;if(!u)throw new T("callTool","chatgpt");return await u(c,l??{})},sendPrompt(c){let l=n();(l?.sendFollowUpMessage??l?.sendFollowupMessage)?.({prompt:c});},openLink(c){let l=n()?.openExternal;l?l({href:c}):e.open(c,"_blank","noopener,noreferrer");},resize(){},capabilities(){let c=n();return {pull:typeof c?.callTool=="function",sendPrompt:typeof c?.sendFollowUpMessage=="function"||typeof c?.sendFollowupMessage=="function",openLink:true}},start(){e.addEventListener(U,m,{passive:true}),s=n()?.toolOutput??s;},destroy(){f||(f=true,e.removeEventListener(U,m),a.clear(),p.clear());}}}function S(e,o){if(!e)return null;let s=e.getElementById(o)?.textContent;if(!s)return null;try{return JSON.parse(s)??null}catch{return null}}function L(e){if(e==null||typeof e!="object")return null;let o=e,n=o.renderData,s=n!=null&&typeof n=="object"?n:o;return s.toolOutput!=null?s.toolOutput:s.structuredContent!=null?s.structuredContent:s}function le(e,o){let n=o.dataElementId??_,s=null,i={mode:O(e),tokens:{}},a=new Set,p=false,f=null,m=c=>{if(p)return;let l=h(c.matches?"dark":"light",i.mode);if(l!==i.mode){i={mode:l,tokens:{}};for(let u of a)u(i);}};return {host:"generic",getData:()=>s,onData(){return ()=>{}},getTheme:()=>i,onTheme(c){return a.add(c),()=>a.delete(c)},async callTool(c){throw new T("callTool","generic")},sendPrompt(){},openLink(c){e.open(c,"_blank","noopener,noreferrer");},resize(){},capabilities(){return {pull:false,sendPrompt:false,openLink:true}},start(){s=S(e.document,n);try{f=e.matchMedia?.("(prefers-color-scheme: dark)")??null,f?.addEventListener?.("change",m);}catch{f=null;}},destroy(){p||(p=true,f?.removeEventListener?.("change",m),f=null,a.clear());}}}var _e="synapse/fontFaces";function Se(e){return M(e?.[_e])}function de(e,o){return Se(o)??e}var xe=3e4;function pe(e,o){let n=o.dataElementId??_,s=o.autoResize!==false,i=null,a={mode:O(e),tokens:{}},p=new Set,f=new Set,m=false,c=false,l=1,u=new Map,b=-1,v=null,k=null,H=()=>e.parent??e;function P(t){H().postMessage(t,"*");}function x(t){c||P(t);}function N(t,r){P({jsonrpc:"2.0",method:t,params:r??{}});}function C(t,r){let d=l++;return new Promise((y,g)=>{let I=setTimeout(()=>{u.delete(d),g(new Error(`"${t}" timed out`));},xe);u.set(d,{resolve:y,reject:g,timer:I}),P({jsonrpc:"2.0",id:d,method:t,params:r??{}});})}function z(t){if(t!=null){i=t;for(let r of p)r(t);}}function D(t){if(!t||typeof t!="object")return;let{mode:r,tokens:d,fontFaces:y}=a,g=false;if(t.theme!=null){let w=h(t.theme,r);w!==r&&(r=w,g=true);}let I=t.styles;I?.variables&&typeof I.variables=="object"&&(d={...d,...I.variables},g=true);let K=de(y,t);if(A(K)!==A(y)&&(y=K,g=true),g){a={mode:r,tokens:d,...y?{fontFaces:y}:{}};for(let w of f)w(a);}}function E(t){if(m)return;let r=typeof t=="number"?t:Math.ceil(e.document.body.scrollHeight);r!==b&&(b=r,N(oe,{height:r}),x({type:B,payload:{height:r}}));}function me(t){let r=Number(t.id),d=u.get(r);if(d)if(u.delete(r),clearTimeout(d.timer),t.error!=null){let y=t.error;d.reject(new Error(y.message??"request failed"));}else d.resolve(t.result);}function ye(t,r){if(t===te){let d=r.structuredContent;z(d??L(r));}else t===ne&&D(r);}function ge(t){t.method===ie&&P({jsonrpc:"2.0",id:t.id,result:{}});}function he(t){if(t.type===$||t.type==="renderData"){let{theme:r,...d}=t.payload??{};r!=null&&D({theme:r}),Object.keys(d).length>0&&z(L(d));}}let j=t=>{if(m||t.source&&t.source!==H())return;let r=t.data;if(!(!r||typeof r!="object")){if(r.jsonrpc!=="2.0"){he(r);return}r.id!=null&&("result"in r||"error"in r)?me(r):typeof r.method=="string"&&(r.id!=null?ge(r):ye(r.method,r.params??{}));}};function Te(){k=()=>E(),e.addEventListener("resize",k),typeof e.ResizeObserver<"u"&&(v=new e.ResizeObserver(()=>E()),v.observe(e.document.body));}return {host:"claude",getData:()=>i,onData(t){return p.add(t),()=>p.delete(t)},getTheme:()=>a,onTheme(t){return f.add(t),()=>f.delete(t)},async callTool(t,r){return await C(ae,{name:t,arguments:r??{}})},sendPrompt(t){C(se,{role:"user",content:[{type:"text",text:t}]}).catch(()=>{}),x({type:Q,payload:{prompt:t}});},openLink(t){C(re,{url:t}).catch(()=>{}),x({type:q,payload:{url:t}});},resize(t){E(t);},capabilities(){return {pull:true,sendPrompt:true,openLink:true}},start(){e.addEventListener("message",j),i=S(e.document,n),s&&Te(),P({type:Z}),C(J,{appInfo:{name:o.name??"synapse-ui",version:o.version??"0.0.0"},appCapabilities:{availableDisplayModes:["inline"]},protocolVersion:X}).then(t=>{m||(c=true,D(t?.hostContext),N(ee,{}),b=-1,E());}).catch(()=>{}),E();},destroy(){if(!m){m=true,e.removeEventListener("message",j),k&&e.removeEventListener("resize",k),k=null,v?.disconnect(),v=null;for(let t of u.values())clearTimeout(t.timer),t.reject(new Error("adapter destroyed"));u.clear(),p.clear(),f.clear();}}}}function De(e){if(e.openai!=null)return "chatgpt";try{if(e.parent!=null&&e.parent!==e)return "claude"}catch{return "claude"}return "generic"}function Fe(e,o,n){switch(e){case "chatgpt":return ce(o);case "claude":case "nimblebrain":return pe(o,n);default:return le(o,n)}}function ue(e,o){let n=o.host??De(e);return Fe(n,e,o)}function fe(e={}){let o=e.window??globalThis,n=ue(o,e);R(n.getTheme());let s=n.onTheme(R);n.start();let i=false;return {data:()=>n.getData(),onData:a=>n.onData(a),theme:()=>n.getTheme(),onTheme:a=>n.onTheme(a),callTool:(a,p)=>n.callTool(a,p),sendPrompt:a=>n.sendPrompt(a),openLink:a=>n.openLink(a),resize:a=>n.resize(a),capabilities:()=>n.capabilities(),host:()=>n.host,destroy(){i||(i=true,s(),n.destroy());}}}globalThis.SynapseUI={connect:fe};})();
|
package/dist/ui/index.cjs
CHANGED
|
@@ -24,15 +24,13 @@ var tokens = {
|
|
|
24
24
|
danger: "var(--nb-color-danger, #dc2626)",
|
|
25
25
|
success: "var(--nb-color-success, #059669)",
|
|
26
26
|
warning: "var(--nb-color-warning, #f59e0b)",
|
|
27
|
-
warm: "var(--nb-color-warm, #d4620a)",
|
|
28
|
-
warmLight: "var(--nb-color-warm-light, #fef5ee)",
|
|
29
27
|
processing: "var(--nb-color-processing, #7c3aed)",
|
|
30
28
|
processingLight: "var(--nb-color-processing-light, #f3eeff)",
|
|
31
29
|
infoLight: "var(--nb-color-info-light, #eef4ff)",
|
|
32
30
|
// ── Typography ──
|
|
33
31
|
fontSans: "var(--font-sans, system-ui, -apple-system, BlinkMacSystemFont, sans-serif)",
|
|
34
32
|
fontMono: "var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)",
|
|
35
|
-
fontHeading: "var(--nb-font-heading,
|
|
33
|
+
fontHeading: "var(--nb-font-heading, system-ui, -apple-system, BlinkMacSystemFont, sans-serif)",
|
|
36
34
|
weightNormal: "var(--font-weight-normal, 400)",
|
|
37
35
|
weightMedium: "var(--font-weight-medium, 500)",
|
|
38
36
|
weightSemibold: "var(--font-weight-semibold, 600)",
|
|
@@ -135,8 +133,7 @@ var TONE = {
|
|
|
135
133
|
success: { bg: `color-mix(in oklab, ${tokens.success} 14%, transparent)`, fg: tokens.success },
|
|
136
134
|
warning: { bg: `color-mix(in oklab, ${tokens.warning} 14%, transparent)`, fg: tokens.warning },
|
|
137
135
|
danger: { bg: `color-mix(in oklab, ${tokens.danger} 14%, transparent)`, fg: tokens.danger },
|
|
138
|
-
processing: { bg: tokens.processingLight, fg: tokens.processing }
|
|
139
|
-
warm: { bg: tokens.warmLight, fg: tokens.warm }
|
|
136
|
+
processing: { bg: tokens.processingLight, fg: tokens.processing }
|
|
140
137
|
};
|
|
141
138
|
function Badge({ tone = "neutral", style, children, ...rest }) {
|
|
142
139
|
const { bg, fg } = TONE[tone];
|