@prefecthq/prefab-ui 0.19.0 → 0.19.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.
|
@@ -5289,6 +5289,7 @@ class Form(ContainerComponent):
|
|
|
5289
5289
|
fields_only: Literal[True],
|
|
5290
5290
|
submit_label: str = "Submit",
|
|
5291
5291
|
on_submit: Action | list[Action] | None = None,
|
|
5292
|
+
defaults: dict[str, Any] | None = None,
|
|
5292
5293
|
css_class: str | None = None,
|
|
5293
5294
|
) -> list[Any]: ...
|
|
5294
5295
|
|
|
@@ -5301,6 +5302,7 @@ class Form(ContainerComponent):
|
|
|
5301
5302
|
fields_only: Literal[False] = ...,
|
|
5302
5303
|
submit_label: str = "Submit",
|
|
5303
5304
|
on_submit: Action | list[Action] | None = None,
|
|
5305
|
+
defaults: dict[str, Any] | None = None,
|
|
5304
5306
|
css_class: str | None = None,
|
|
5305
5307
|
) -> Form: ...
|
|
5306
5308
|
|
|
@@ -5312,6 +5314,7 @@ class Form(ContainerComponent):
|
|
|
5312
5314
|
fields_only: bool = False,
|
|
5313
5315
|
submit_label: str = "Submit",
|
|
5314
5316
|
on_submit: Action | list[Action] | None = None,
|
|
5317
|
+
defaults: dict[str, Any] | None = None,
|
|
5315
5318
|
css_class: str | None = None,
|
|
5316
5319
|
) -> Form | list[Any]:
|
|
5317
5320
|
"""Generate a form from a Pydantic model.
|
|
@@ -5370,11 +5373,23 @@ class Form(ContainerComponent):
|
|
|
5370
5373
|
submit_label: Text for the submit button.
|
|
5371
5374
|
on_submit: Action(s) fired on submit. A \`CallTool\` with no
|
|
5372
5375
|
arguments gets auto-filled from model fields.
|
|
5376
|
+
defaults: Runtime values keyed by field name. These override the
|
|
5377
|
+
model's class-level \`Field(default=...)\` for this render only,
|
|
5378
|
+
letting callers (e.g. LLM agents) pre-populate the form with
|
|
5379
|
+
context-specific values. Unknown keys raise \`ValueError\`.
|
|
5373
5380
|
css_class: Additional CSS classes on the form container.
|
|
5374
5381
|
"""
|
|
5375
5382
|
from prefab_ui.components.base import _component_stack
|
|
5376
5383
|
from prefab_ui.components.button import Button
|
|
5377
5384
|
|
|
5385
|
+
if defaults:
|
|
5386
|
+
unknown = set(defaults) - set(model.model_fields)
|
|
5387
|
+
if unknown:
|
|
5388
|
+
raise ValueError(
|
|
5389
|
+
f"defaults contains unknown field(s) for "
|
|
5390
|
+
f"{model.__name__}: {sorted(unknown)}"
|
|
5391
|
+
)
|
|
5392
|
+
|
|
5378
5393
|
if fields_only:
|
|
5379
5394
|
# Suppress auto-parenting during creation to avoid duplicates
|
|
5380
5395
|
# (Labels/Inputs would otherwise auto-parent to both the
|
|
@@ -5384,7 +5399,7 @@ class Form(ContainerComponent):
|
|
|
5384
5399
|
with defer():
|
|
5385
5400
|
children: list[Any] = []
|
|
5386
5401
|
for name, field_info in model.model_fields.items():
|
|
5387
|
-
component = _field_to_component(name, field_info)
|
|
5402
|
+
component = _field_to_component(name, field_info, defaults)
|
|
5388
5403
|
if component is not None:
|
|
5389
5404
|
children.append(component)
|
|
5390
5405
|
|
|
@@ -5406,7 +5421,7 @@ class Form(ContainerComponent):
|
|
|
5406
5421
|
children = []
|
|
5407
5422
|
|
|
5408
5423
|
for name, field_info in model.model_fields.items():
|
|
5409
|
-
component = _field_to_component(name, field_info)
|
|
5424
|
+
component = _field_to_component(name, field_info, defaults)
|
|
5410
5425
|
if component is not None:
|
|
5411
5426
|
children.append(component)
|
|
5412
5427
|
|
|
@@ -5452,6 +5467,25 @@ def _maybe_enrich_tool_call(
|
|
|
5452
5467
|
return CallTool(**kwargs)
|
|
5453
5468
|
|
|
5454
5469
|
|
|
5470
|
+
def _format_date_default(value: Any, kind: type) -> str | None:
|
|
5471
|
+
"""Serialize a date/time/datetime default to the HTML input format."""
|
|
5472
|
+
if value is None:
|
|
5473
|
+
return None
|
|
5474
|
+
if isinstance(value, str):
|
|
5475
|
+
return value
|
|
5476
|
+
if kind is datetime.datetime and isinstance(value, datetime.datetime):
|
|
5477
|
+
return value.strftime("%Y-%m-%dT%H:%M")
|
|
5478
|
+
if (
|
|
5479
|
+
kind is datetime.date
|
|
5480
|
+
and isinstance(value, datetime.date)
|
|
5481
|
+
and not isinstance(value, datetime.datetime)
|
|
5482
|
+
):
|
|
5483
|
+
return value.isoformat()
|
|
5484
|
+
if kind is datetime.time and isinstance(value, datetime.time):
|
|
5485
|
+
return value.isoformat(timespec="minutes")
|
|
5486
|
+
return None
|
|
5487
|
+
|
|
5488
|
+
|
|
5455
5489
|
def _humanize(name: str) -> str:
|
|
5456
5490
|
"""Convert snake_case field name to Title Case label."""
|
|
5457
5491
|
return name.replace("_", " ").title()
|
|
@@ -5504,7 +5538,11 @@ def _get_ui_hints(field_info: FieldInfo) -> dict[str, Any]:
|
|
|
5504
5538
|
return {}
|
|
5505
5539
|
|
|
5506
5540
|
|
|
5507
|
-
def _field_to_component(
|
|
5541
|
+
def _field_to_component(
|
|
5542
|
+
name: str,
|
|
5543
|
+
field_info: FieldInfo,
|
|
5544
|
+
defaults: dict[str, Any] | None = None,
|
|
5545
|
+
) -> Any:
|
|
5508
5546
|
"""Map a single Pydantic field to the appropriate form component(s)."""
|
|
5509
5547
|
from prefab_ui.components.checkbox import Checkbox
|
|
5510
5548
|
from prefab_ui.components.column import Column
|
|
@@ -5525,9 +5563,12 @@ def _field_to_component(name: str, field_info: FieldInfo) -> Any:
|
|
|
5525
5563
|
|
|
5526
5564
|
label_text = field_info.title or _humanize(name)
|
|
5527
5565
|
placeholder = field_info.description or label_text
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5566
|
+
if defaults is not None and name in defaults:
|
|
5567
|
+
default = defaults[name]
|
|
5568
|
+
elif field_info.default is not PydanticUndefined:
|
|
5569
|
+
default = field_info.default
|
|
5570
|
+
else:
|
|
5571
|
+
default = None
|
|
5531
5572
|
constraints = _extract_constraints(field_info)
|
|
5532
5573
|
ui_hints = _get_ui_hints(field_info)
|
|
5533
5574
|
|
|
@@ -5590,26 +5631,34 @@ def _field_to_component(name: str, field_info: FieldInfo) -> Any:
|
|
|
5590
5631
|
|
|
5591
5632
|
# date/time types → specialized input
|
|
5592
5633
|
if inner is datetime.date:
|
|
5634
|
+
value = _format_date_default(default, datetime.date)
|
|
5593
5635
|
col = Column(gap=2)
|
|
5594
5636
|
col.children = [
|
|
5595
5637
|
Label(label_text, optional=not required),
|
|
5596
|
-
Input(input_type="date", name=name, required=required),
|
|
5638
|
+
Input(input_type="date", name=name, value=value, required=required),
|
|
5597
5639
|
]
|
|
5598
5640
|
return col
|
|
5599
5641
|
|
|
5600
5642
|
if inner is datetime.time:
|
|
5643
|
+
value = _format_date_default(default, datetime.time)
|
|
5601
5644
|
col = Column(gap=2)
|
|
5602
5645
|
col.children = [
|
|
5603
5646
|
Label(label_text, optional=not required),
|
|
5604
|
-
Input(input_type="time", name=name, required=required),
|
|
5647
|
+
Input(input_type="time", name=name, value=value, required=required),
|
|
5605
5648
|
]
|
|
5606
5649
|
return col
|
|
5607
5650
|
|
|
5608
5651
|
if inner is datetime.datetime:
|
|
5652
|
+
value = _format_date_default(default, datetime.datetime)
|
|
5609
5653
|
col = Column(gap=2)
|
|
5610
5654
|
col.children = [
|
|
5611
5655
|
Label(label_text, optional=not required),
|
|
5612
|
-
Input(
|
|
5656
|
+
Input(
|
|
5657
|
+
input_type="datetime-local",
|
|
5658
|
+
name=name,
|
|
5659
|
+
value=value,
|
|
5660
|
+
required=required,
|
|
5661
|
+
),
|
|
5613
5662
|
]
|
|
5614
5663
|
return col
|
|
5615
5664
|
|
package/dist/app/renderer.js
CHANGED
|
@@ -1284,7 +1284,7 @@ Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Rec
|
|
|
1284
1284
|
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`);pe.object({method:pe.literal("ui/open-link"),params:pe.object({url:pe.string().describe("URL to open in the host's browser")})});var Vre=pe.object({isError:pe.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),Fre=pe.object({isError:pe.boolean().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough();pe.object({method:pe.literal("ui/notifications/sandbox-proxy-ready"),params:pe.object({})});var y1=pe.object({connectDomains:pe.array(pe.string()).optional().describe("Origins for network requests (fetch/XHR/WebSocket)."),resourceDomains:pe.array(pe.string()).optional().describe("Origins for static resources (scripts, images, styles, fonts)."),frameDomains:pe.array(pe.string()).optional().describe("Origins for nested iframes (frame-src directive)."),baseUriDomains:pe.array(pe.string()).optional().describe("Allowed base URIs for the document (base-uri directive).")}),w1=pe.object({camera:pe.object({}).optional().describe("Request camera access (Permission Policy `camera` feature)."),microphone:pe.object({}).optional().describe("Request microphone access (Permission Policy `microphone` feature)."),geolocation:pe.object({}).optional().describe("Request geolocation access (Permission Policy `geolocation` feature)."),clipboardWrite:pe.object({}).optional().describe("Request clipboard write access (Permission Policy `clipboard-write` feature).")});pe.object({method:pe.literal("ui/notifications/size-changed"),params:pe.object({width:pe.number().optional().describe("New width in pixels."),height:pe.number().optional().describe("New height in pixels.")})});var Zre=pe.object({method:pe.literal("ui/notifications/tool-input"),params:pe.object({arguments:pe.record(pe.string(),pe.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),Hre=pe.object({method:pe.literal("ui/notifications/tool-input-partial"),params:pe.object({arguments:pe.record(pe.string(),pe.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),Bre=pe.object({method:pe.literal("ui/notifications/tool-cancelled"),params:pe.object({reason:pe.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),qre=pe.object({fonts:pe.string().optional()}),Gre=pe.object({variables:Lre.optional().describe("CSS variables for theming the app."),css:qre.optional().describe("CSS blocks that apps can inject.")}),Kre=pe.object({method:pe.literal("ui/resource-teardown"),params:pe.object({})});pe.record(pe.string(),pe.unknown());var zC=pe.object({text:pe.object({}).optional().describe("Host supports text content blocks."),image:pe.object({}).optional().describe("Host supports image content blocks."),audio:pe.object({}).optional().describe("Host supports audio content blocks."),resource:pe.object({}).optional().describe("Host supports resource content blocks."),resourceLink:pe.object({}).optional().describe("Host supports resource link content blocks."),structuredContent:pe.object({}).optional().describe("Host supports structured content.")}),Yre=pe.object({experimental:pe.object({}).optional().describe("Experimental features (structure TBD)."),openLinks:pe.object({}).optional().describe("Host supports opening external URLs."),serverTools:pe.object({listChanged:pe.boolean().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:pe.object({listChanged:pe.boolean().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:pe.object({}).optional().describe("Host accepts log messages."),sandbox:pe.object({permissions:w1.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:y1.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:zC.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:zC.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),Jre=pe.object({experimental:pe.object({}).optional().describe("Experimental features (structure TBD)."),tools:pe.object({listChanged:pe.boolean().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:pe.array(Ff).optional().describe("Display modes the app supports.")});pe.object({method:pe.literal("ui/notifications/initialized"),params:pe.object({}).optional()});pe.object({csp:y1.optional().describe("Content Security Policy configuration."),permissions:w1.optional().describe("Sandbox permissions requested by the UI."),domain:pe.string().optional().describe("Dedicated origin for view sandbox."),prefersBorder:pe.boolean().optional().describe("Visual boundary preference - true if UI prefers a visible border.")});pe.object({method:pe.literal("ui/request-display-mode"),params:pe.object({mode:Ff.describe("The display mode being requested.")})});var Xre=pe.object({mode:Ff.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),Wre=pe.union([pe.literal("model"),pe.literal("app")]).describe("Tool visibility scope - who can access the tool.");pe.object({resourceUri:pe.string().optional(),visibility:pe.array(Wre).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
1285
1285
|
- "model": Tool visible to and callable by the agent
|
|
1286
1286
|
- "app": Tool callable by the app from this server only`)});pe.object({mimeTypes:pe.array(pe.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});pe.object({method:pe.literal("ui/message"),params:pe.object({role:pe.literal("user").describe('Message role, currently only "user" is supported.'),content:pe.array(fp).describe("Message content blocks (text, image, etc.).")})});pe.object({method:pe.literal("ui/notifications/sandbox-resource-ready"),params:pe.object({html:pe.string().describe("HTML content to load into the inner iframe."),sandbox:pe.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:y1.optional().describe("CSP configuration from resource metadata."),permissions:w1.optional().describe("Sandbox permissions from resource metadata.")})});var Qre=pe.object({method:pe.literal("ui/notifications/tool-result"),params:qg.describe("Standard MCP tool execution result.")}),u3=pe.object({toolInfo:pe.object({id:ap.optional().describe("JSON-RPC id of the tools/call request."),tool:Sx.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:jre.optional().describe("Current color theme preference."),styles:Gre.optional().describe("Style configuration for theming the app."),displayMode:Ff.optional().describe("How the UI is currently displayed."),availableDisplayModes:pe.array(Ff).optional().describe("Display modes the host supports."),containerDimensions:pe.union([pe.object({height:pe.number().describe("Fixed container height in pixels.")}),pe.object({maxHeight:pe.union([pe.number(),pe.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(pe.union([pe.object({width:pe.number().describe("Fixed container width in pixels.")}),pe.object({maxWidth:pe.union([pe.number(),pe.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
1287
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:pe.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:pe.string().optional().describe("User's timezone in IANA format."),userAgent:pe.string().optional().describe("Host application identifier."),platform:pe.union([pe.literal("web"),pe.literal("desktop"),pe.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:pe.object({touch:pe.boolean().optional().describe("Whether the device supports touch input."),hover:pe.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:pe.object({top:pe.number().describe("Top safe area inset in pixels."),right:pe.number().describe("Right safe area inset in pixels."),bottom:pe.number().describe("Bottom safe area inset in pixels."),left:pe.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),eie=pe.object({method:pe.literal("ui/notifications/host-context-changed"),params:u3.describe("Partial context update containing only changed fields.")});pe.object({method:pe.literal("ui/update-model-context"),params:pe.object({content:pe.array(fp).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:pe.record(pe.string(),pe.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});pe.object({method:pe.literal("ui/initialize"),params:pe.object({appInfo:Hg.describe("App identification (name and version)."),appCapabilities:Jre.describe("Features and capabilities this app provides."),protocolVersion:pe.string().describe("Protocol version this app supports.")})});var tie=pe.object({protocolVersion:pe.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Hg.describe("Host application identification and version."),hostCapabilities:Yre.describe("Features and capabilities provided by the host."),hostContext:u3.describe("Rich context about the host environment.")}).passthrough();class nie extends ree{constructor(n,i={},r={autoResize:!0}){super(r);Jt(this,"_appInfo");Jt(this,"_capabilities");Jt(this,"options");Jt(this,"_hostCapabilities");Jt(this,"_hostInfo");Jt(this,"_hostContext");Jt(this,"sendOpenLink",this.openLink);this._appInfo=n,this._capabilities=i,this.options=r,this.setRequestHandler(Bg,a=>(console.log("Received ping:",a.params),{})),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(n){this.setNotificationHandler(Zre,i=>n(i.params))}set ontoolinputpartial(n){this.setNotificationHandler(Hre,i=>n(i.params))}set ontoolresult(n){this.setNotificationHandler(Qre,i=>n(i.params))}set ontoolcancelled(n){this.setNotificationHandler(Bre,i=>n(i.params))}set onhostcontextchanged(n){this.setNotificationHandler(eie,i=>{this._hostContext={...this._hostContext,...i.params},n(i.params)})}set onteardown(n){this.setRequestHandler(Kre,(i,r)=>n(i.params,r))}set oncalltool(n){this.setRequestHandler(wI,(i,r)=>n(i.params,r))}set onlisttools(n){this.setRequestHandler(yI,(i,r)=>n(i.params,r))}assertCapabilityForMethod(n){}assertRequestHandlerCapability(n){switch(n){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${n})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${n} registered`)}}assertNotificationCapability(n){}assertTaskCapability(n){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(n){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(n,i){return await this.request({method:"tools/call",params:n},qg,i)}sendMessage(n,i){return this.request({method:"ui/message",params:n},Fre,i)}sendLog(n){return this.notification({method:"notifications/message",params:n})}updateModelContext(n,i){return this.request({method:"ui/update-model-context",params:n},sx,i)}openLink(n,i){return this.request({method:"ui/open-link",params:n},Vre,i)}requestDisplayMode(n,i){return this.request({method:"ui/request-display-mode",params:n},Xre,i)}sendSizeChanged(n){return this.notification({method:"ui/notifications/size-changed",params:n})}setupSizeChangedNotifications(){let n=!1,i=0,r=0,a=()=>{n||(n=!0,requestAnimationFrame(()=>{n=!1;let c=document.documentElement,f=c.style.width,p=c.style.height;c.style.width="fit-content",c.style.height="fit-content";let h=c.getBoundingClientRect();c.style.width=f,c.style.height=p;let g=window.innerWidth-c.clientWidth,w=Math.ceil(h.width+g),k=Math.ceil(h.height);(w!==i||k!==r)&&(i=w,r=k,this.sendSizeChanged({width:w,height:k}))}))};a();let s=new ResizeObserver(a);return s.observe(document.documentElement),s.observe(document.body),()=>s.disconnect()}async connect(n=new oee(window.parent,window.parent),i){var r;await super.connect(n);try{let a=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:aee}},tie,i);if(a===void 0)throw Error(`Server sent invalid initialize result: ${a}`);this._hostCapabilities=a.hostCapabilities,this._hostInfo=a.hostInfo,this._hostContext=a.hostContext,await this.notification({method:"ui/notifications/initialized"}),(r=this.options)!=null&&r.autoResize&&this.setupSizeChangedNotifications()}catch(a){throw this.close(),a}}}let Yy=null;function rie(e){Yy=e}function xf(e){Yy&&Yy(e),console.log(`[Pyodide] ${e}`)}let Af=null,kf=null;const iie="https://cdn.jsdelivr.net/pyodide/v0.27.4/full/pyodide.js";function oie(e){return new Promise((t,n)=>{if(document.querySelector(`script[src="${e}"]`)){t();return}const i=document.createElement("script");i.src=e,i.onload=()=>t(),i.onerror=n,document.head.appendChild(i)})}function aie(e){return Af?Promise.resolve(Af):kf||(kf=(async()=>{e("loading"),xf("Loading script from CDN..."),await oie(iie),xf("Script loaded, initializing...");const t=await window.loadPyodide();xf("Initialized, loading pydantic..."),await t.loadPackage(["pydantic"]),xf("Pydantic loaded, installing prefab...");{const{default:n}=await xl(async()=>{const{default:a}=await import("./bundle-
|
|
1287
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:pe.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:pe.string().optional().describe("User's timezone in IANA format."),userAgent:pe.string().optional().describe("Host application identifier."),platform:pe.union([pe.literal("web"),pe.literal("desktop"),pe.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:pe.object({touch:pe.boolean().optional().describe("Whether the device supports touch input."),hover:pe.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:pe.object({top:pe.number().describe("Top safe area inset in pixels."),right:pe.number().describe("Right safe area inset in pixels."),bottom:pe.number().describe("Bottom safe area inset in pixels."),left:pe.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),eie=pe.object({method:pe.literal("ui/notifications/host-context-changed"),params:u3.describe("Partial context update containing only changed fields.")});pe.object({method:pe.literal("ui/update-model-context"),params:pe.object({content:pe.array(fp).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:pe.record(pe.string(),pe.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})});pe.object({method:pe.literal("ui/initialize"),params:pe.object({appInfo:Hg.describe("App identification (name and version)."),appCapabilities:Jre.describe("Features and capabilities this app provides."),protocolVersion:pe.string().describe("Protocol version this app supports.")})});var tie=pe.object({protocolVersion:pe.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:Hg.describe("Host application identification and version."),hostCapabilities:Yre.describe("Features and capabilities provided by the host."),hostContext:u3.describe("Rich context about the host environment.")}).passthrough();class nie extends ree{constructor(n,i={},r={autoResize:!0}){super(r);Jt(this,"_appInfo");Jt(this,"_capabilities");Jt(this,"options");Jt(this,"_hostCapabilities");Jt(this,"_hostInfo");Jt(this,"_hostContext");Jt(this,"sendOpenLink",this.openLink);this._appInfo=n,this._capabilities=i,this.options=r,this.setRequestHandler(Bg,a=>(console.log("Received ping:",a.params),{})),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(n){this.setNotificationHandler(Zre,i=>n(i.params))}set ontoolinputpartial(n){this.setNotificationHandler(Hre,i=>n(i.params))}set ontoolresult(n){this.setNotificationHandler(Qre,i=>n(i.params))}set ontoolcancelled(n){this.setNotificationHandler(Bre,i=>n(i.params))}set onhostcontextchanged(n){this.setNotificationHandler(eie,i=>{this._hostContext={...this._hostContext,...i.params},n(i.params)})}set onteardown(n){this.setRequestHandler(Kre,(i,r)=>n(i.params,r))}set oncalltool(n){this.setRequestHandler(wI,(i,r)=>n(i.params,r))}set onlisttools(n){this.setRequestHandler(yI,(i,r)=>n(i.params,r))}assertCapabilityForMethod(n){}assertRequestHandlerCapability(n){switch(n){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${n})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${n} registered`)}}assertNotificationCapability(n){}assertTaskCapability(n){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(n){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(n,i){return await this.request({method:"tools/call",params:n},qg,i)}sendMessage(n,i){return this.request({method:"ui/message",params:n},Fre,i)}sendLog(n){return this.notification({method:"notifications/message",params:n})}updateModelContext(n,i){return this.request({method:"ui/update-model-context",params:n},sx,i)}openLink(n,i){return this.request({method:"ui/open-link",params:n},Vre,i)}requestDisplayMode(n,i){return this.request({method:"ui/request-display-mode",params:n},Xre,i)}sendSizeChanged(n){return this.notification({method:"ui/notifications/size-changed",params:n})}setupSizeChangedNotifications(){let n=!1,i=0,r=0,a=()=>{n||(n=!0,requestAnimationFrame(()=>{n=!1;let c=document.documentElement,f=c.style.width,p=c.style.height;c.style.width="fit-content",c.style.height="fit-content";let h=c.getBoundingClientRect();c.style.width=f,c.style.height=p;let g=window.innerWidth-c.clientWidth,w=Math.ceil(h.width+g),k=Math.ceil(h.height);(w!==i||k!==r)&&(i=w,r=k,this.sendSizeChanged({width:w,height:k}))}))};a();let s=new ResizeObserver(a);return s.observe(document.documentElement),s.observe(document.body),()=>s.disconnect()}async connect(n=new oee(window.parent,window.parent),i){var r;await super.connect(n);try{let a=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:aee}},tie,i);if(a===void 0)throw Error(`Server sent invalid initialize result: ${a}`);this._hostCapabilities=a.hostCapabilities,this._hostInfo=a.hostInfo,this._hostContext=a.hostContext,await this.notification({method:"ui/notifications/initialized"}),(r=this.options)!=null&&r.autoResize&&this.setupSizeChangedNotifications()}catch(a){throw this.close(),a}}}let Yy=null;function rie(e){Yy=e}function xf(e){Yy&&Yy(e),console.log(`[Pyodide] ${e}`)}let Af=null,kf=null;const iie="https://cdn.jsdelivr.net/pyodide/v0.27.4/full/pyodide.js";function oie(e){return new Promise((t,n)=>{if(document.querySelector(`script[src="${e}"]`)){t();return}const i=document.createElement("script");i.src=e,i.onload=()=>t(),i.onerror=n,document.head.appendChild(i)})}function aie(e){return Af?Promise.resolve(Af):kf||(kf=(async()=>{e("loading"),xf("Loading script from CDN..."),await oie(iie),xf("Script loaded, initializing...");const t=await window.loadPyodide();xf("Initialized, loading pydantic..."),await t.loadPackage(["pydantic"]),xf("Pydantic loaded, installing prefab...");{const{default:n}=await xl(async()=>{const{default:a}=await import("./bundle-BF3CVMKo.js");return{default:a}},[],import.meta.url),i=n,r=new Set;for(const a of Object.keys(i)){const s=a.substring(0,a.lastIndexOf("/"));s&&!r.has(s)&&(t.FS.mkdirTree(`/lib/python3.12/site-packages/${s}`),r.add(s))}for(const[a,s]of Object.entries(i))t.FS.writeFile(`/lib/python3.12/site-packages/${a}`,s);xf("Prefab mounted from bundle")}return Af=t,e("ready"),t})().catch(t=>{throw kf=null,e("error"),t}),kf)}async function lie(e){var n;if(!Af)return{error:"Pyodide not loaded"};const t=`
|
|
1288
1288
|
import json as _json
|
|
1289
1289
|
from prefab_ui.components.base import _component_stack, Component as _C, ContainerComponent as _CC
|
|
1290
1290
|
from prefab_ui.app import PrefabApp as _PA
|