@lobu/runtime-server 20.2.0 → 21.0.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/dist/component.json +1 -1
- package/dist/connectors/README.md +15 -16
- package/dist/connectors/github.ts +15 -9
- package/dist/connectors/google_calendar.ts +21 -31
- package/dist/connectors/google_drive.ts +106 -131
- package/dist/connectors/google_gmail.ts +53 -30
- package/dist/connectors/hackernews.ts +2 -5
- package/dist/connectors/jira.ts +62 -27
- package/dist/connectors/linear.ts +55 -21
- package/dist/connectors/microsoft_outlook.ts +151 -110
- package/dist/connectors/postgres.ts +19 -11
- package/dist/connectors/producthunt.ts +8 -6
- package/dist/connectors/reddit.ts +2 -2
- package/dist/connectors/rss.ts +2 -2
- package/dist/connectors/whatsapp_web.ts +5 -4
- package/dist/connectors/x.ts +32 -17
- package/dist/connectors/youtube.ts +18 -5
- package/dist/db/migrations/20260917000000_views.sql +271 -0
- package/dist/db/migrations/20260917000001_views_attach_index.sql +14 -0
- package/dist/db/migrations/20260918000000_runs_turn_tool_event_uniq.sql +51 -0
- package/dist/db/migrations/20260923230000_runs_connector_artifact_hash.sql +32 -0
- package/dist/db/migrations/20260924000000_resource_source_files.sql +17 -0
- package/dist/dependencies.bun.lock +109 -98
- package/dist/guest.bundle.js +78 -10
- package/dist/owletto/dist/assets/_-CwFknmeA.js +1 -0
- package/dist/owletto/dist/assets/_-DrcppoWh.js +2 -0
- package/dist/owletto/dist/assets/_agentId-Cr57JKYx.js +1 -0
- package/dist/owletto/dist/assets/_agentId-HNcmgH56.js +1 -0
- package/dist/owletto/dist/assets/_automationId-BCfrLnUS.js +1 -0
- package/dist/owletto/dist/assets/{_connectorKey._connectionId-BAJGfcy7.js → _connectorKey._connectionId-126-iG9w.js} +1 -1
- package/dist/owletto/dist/assets/{_connectorKey.index-BBF8vGJS.js → _connectorKey.index-CywE9A3N.js} +1 -1
- package/dist/owletto/dist/assets/_conversationId-CNETA_rY.js +1 -0
- package/dist/owletto/dist/assets/_deploymentId-CAVpXf8s.js +1 -0
- package/dist/owletto/dist/assets/_name-BP7OlVxL.js +1 -0
- package/dist/owletto/dist/assets/_owner-D2eh4R90.js +1 -0
- package/dist/owletto/dist/assets/_shape-BqV8tSfw.js +1 -0
- package/dist/owletto/dist/assets/_skillKey-2xTjhL_C.js +1 -0
- package/dist/owletto/dist/assets/_slug-DoIaJBbh.js +1 -0
- package/dist/owletto/dist/assets/_viewKey-8ePnWEg-.js +1 -0
- package/dist/owletto/dist/assets/_viewKey-D8rjUFLV.js +1 -0
- package/dist/owletto/dist/assets/_viewKey-DhVOkzYd.js +1 -0
- package/dist/owletto/dist/assets/accept-invitation-BWRiEUsd.js +1 -0
- package/dist/owletto/dist/assets/activity-route-view-rVdTeVXN.js +1 -0
- package/dist/owletto/dist/assets/{agent-card-controls-CZO6GI0s.js → agent-card-controls-JubkhcHt.js} +1 -1
- package/dist/owletto/dist/assets/{agent-client-setup-list-_chLOorY.js → agent-client-setup-list-Btcy4Cu1.js} +1 -1
- package/dist/owletto/dist/assets/{agent-connect-pages-DWBgSIYT.js → agent-connect-pages-Chfqn8iL.js} +1 -1
- package/dist/owletto/dist/assets/{agent-editor-form-BTNlg0kQ.js → agent-editor-form-BrOkwfg8.js} +1 -1
- package/dist/owletto/dist/assets/{agent-guardrails-route-B5uoMC6o.js → agent-guardrails-route-CHM7JbIl.js} +1 -1
- package/dist/owletto/dist/assets/{agent-loading-shells-CLoLeFcB.js → agent-loading-shells-DsiGx1fn.js} +1 -1
- package/dist/owletto/dist/assets/{agent-permissions-matrix-TP00-MYL.js → agent-permissions-matrix-L_gFvSu1.js} +1 -1
- package/dist/owletto/dist/assets/{agent-skill-context-D4a2QCoZ.js → agent-skill-context-D7tOJ8Pb.js} +1 -1
- package/dist/owletto/dist/assets/{agent-skills-route-KVDDTbJB.js → agent-skills-route-AylS-B9v.js} +1 -1
- package/dist/owletto/dist/assets/{agent-subpage-shell-DuVYZvBE.js → agent-subpage-shell-B7tCQ9zd.js} +1 -1
- package/dist/owletto/dist/assets/agent-thread-DOYh7WLW.js +8 -0
- package/dist/owletto/dist/assets/agents-0ncYwbz6.js +1 -0
- package/dist/owletto/dist/assets/agents-workbench-DOwn78eL.js +1 -0
- package/dist/owletto/dist/assets/app-bridge-BH3g2mKG.js +127 -0
- package/dist/owletto/dist/assets/{app._appId-D0_LQTJU.js → app._appId-fJ_RRn1Z.js} +1 -1
- package/dist/owletto/dist/assets/automation-detail-content-CMprQht5.js +1 -0
- package/dist/owletto/dist/assets/automations-0ncYwbz6.js +1 -0
- package/dist/owletto/dist/assets/{calendar-C0XpOHd8.js → calendar-BbD1N97u.js} +1 -1
- package/dist/owletto/dist/assets/{callback-CO_K9eR-.js → callback-PELM84Lh.js} +1 -1
- package/dist/owletto/dist/assets/{card-DeFQuU_J.js → card-DpLjEqIc.js} +1 -1
- package/dist/owletto/dist/assets/{claim-CUpWOSie.js → claim-BLLvLOBM.js} +1 -1
- package/dist/owletto/dist/assets/clients-Bd8WpHSV.js +1 -0
- package/dist/owletto/dist/assets/{code-editor-BqGUZFt6.js → code-editor-DGJQDoHD.js} +1 -1
- package/dist/owletto/dist/assets/connect-Cx49f4J0.js +1 -0
- package/dist/owletto/dist/assets/connect._clientId-BDFBqKSA.js +1 -0
- package/dist/owletto/dist/assets/connected._clientId-BYGmFRCF.js +1 -0
- package/dist/owletto/dist/assets/{connection-BgAlYjeV.js → connection-B0O8OZuK.js} +1 -1
- package/dist/owletto/dist/assets/{connection-feed-detail-B3ePAinf.js → connection-feed-detail-DZjtoEfm.js} +1 -1
- package/dist/owletto/dist/assets/{connector-provenance-DgsDg0Z9.js → connector-provenance-D_g9gGXU.js} +1 -1
- package/dist/owletto/dist/assets/{connectors-CqPQPo9U.js → connectors-BiMMm_QQ.js} +1 -1
- package/dist/owletto/dist/assets/{consent-bswcIzsf.js → consent-CIzW-960.js} +1 -1
- package/dist/owletto/dist/assets/{core.esm-DsLgjoel.js → core.esm-Ds4Nuq9d.js} +1 -1
- package/dist/owletto/dist/assets/create--fsxroj2.js +1 -0
- package/dist/owletto/dist/assets/create-BqL-ahEf.js +1 -0
- package/dist/owletto/dist/assets/{create-Dwo04oWV.js → create-BvCaqhwK.js} +1 -1
- package/dist/owletto/dist/assets/create-automation-form-DN2w080o.js +2 -0
- package/dist/owletto/dist/assets/{create._connectorKey-CCBb2pil.js → create._connectorKey--qDi1h6S.js} +1 -1
- package/dist/owletto/dist/assets/{cronstrue-ChFyC9ps.js → cronstrue-h8_zIyZD.js} +1 -1
- package/dist/owletto/dist/assets/deployments-BROg1Te8.js +1 -0
- package/dist/owletto/dist/assets/deployments-ICDss7yS.js +1 -0
- package/dist/owletto/dist/assets/deployments-body-DulCUAMt.js +1 -0
- package/dist/owletto/dist/assets/device-kTL2l_cz.js +1 -0
- package/dist/owletto/dist/assets/{device-pin-tombstone-1ikyqSdb.js → device-pin-tombstone-BmD4pv_e.js} +1 -1
- package/dist/owletto/dist/assets/device-rows-BqudjhFu.js +1 -0
- package/dist/owletto/dist/assets/{device._deviceId-DTYKGBY8.js → device._deviceId-CsLJJ6jv.js} +1 -1
- package/dist/owletto/dist/assets/entity-options-ErxYvMDH.js +1 -0
- package/dist/owletto/dist/assets/entity-page-CYRAwUGO.js +1 -0
- package/dist/owletto/dist/assets/entity-type-page-BlAizGlz.js +1 -0
- package/dist/owletto/dist/assets/event-page-DTXPxc-E.js +1 -0
- package/dist/owletto/dist/assets/events-feed-L3c-LLiJ.js +1 -0
- package/dist/owletto/dist/assets/{full-page-spinner-BN2G_YiM.js → full-page-spinner-BxcYpJXx.js} +1 -1
- package/dist/owletto/dist/assets/guardrails-Dh4adTXY.js +1 -0
- package/dist/owletto/dist/assets/identity-B8lKn0je.js +1 -0
- package/dist/owletto/dist/assets/{index-C6VAJ8Ku.js → index--lEHrFE4.js} +1 -1
- package/dist/owletto/dist/assets/{index-hSE2E46p.js → index-13rywWam.js} +1 -1
- package/dist/owletto/dist/assets/{index-C-u4yR8Z.js → index-BRvT0VV9.js} +1 -1
- package/dist/owletto/dist/assets/index-BUp24ZJr.js +1 -0
- package/dist/owletto/dist/assets/index-B_-MLsof.js +1 -0
- package/dist/owletto/dist/assets/index-Bq-q4Y7E.js +1 -0
- package/dist/owletto/dist/assets/index-C8CR2-Ck.css +1 -0
- package/dist/owletto/dist/assets/{index-OUb5Mlez.js → index-CDz3-ieP.js} +10 -10
- package/dist/owletto/dist/assets/index-CFkj9iR_.js +1 -0
- package/dist/owletto/dist/assets/index-CgBgOElA.js +1 -0
- package/dist/owletto/dist/assets/{index-C2oCgDX7.js → index-CheCJomo.js} +1 -1
- package/dist/owletto/dist/assets/index-CpiW66xK.js +1 -0
- package/dist/owletto/dist/assets/index-DAv5S2aK.js +1 -0
- package/dist/owletto/dist/assets/index-DBi2Xr3i.js +1 -0
- package/dist/owletto/dist/assets/index-DHOha5OJ.js +1 -0
- package/dist/owletto/dist/assets/index-DdGjY1Hb.js +7898 -0
- package/dist/owletto/dist/assets/index-Dkyl7l6E.js +1 -0
- package/dist/owletto/dist/assets/{index-vdqhlocx.js → index-QcHQZI87.js} +1 -1
- package/dist/owletto/dist/assets/index-kq4537-S.js +1 -0
- package/dist/owletto/dist/assets/{json-diff-DnsW7Pin.js → json-diff-BV2STDGj.js} +2 -2
- package/dist/owletto/dist/assets/{list-skeleton-CHzLN7GK.js → list-skeleton-CT5n4ND_.js} +1 -1
- package/dist/owletto/dist/assets/login-DKsgABYt.js +1 -0
- package/dist/owletto/dist/assets/logout-D_CP-emw.js +1 -0
- package/dist/owletto/dist/assets/member-scope-gate-BTgmlfFJ.js +1 -0
- package/dist/owletto/dist/assets/memory-browse-page-FHaJC3ML.js +101 -0
- package/dist/owletto/dist/assets/missing-view-Bve6pJP-.js +1 -0
- package/dist/owletto/dist/assets/{model-selector-DfbmHjLu.js → model-selector-BLCEahny.js} +1 -1
- package/dist/owletto/dist/assets/models-C4N7LQAW.js +1 -0
- package/dist/owletto/dist/assets/new-BAIGSdfp.js +1 -0
- package/dist/owletto/dist/assets/{new-Df_dY6Z5.js → new-CirOK0Sw.js} +1 -1
- package/dist/owletto/dist/assets/new-DzapH2sV.js +1 -0
- package/dist/owletto/dist/assets/{oauth-workspace-access-D9GmiMfK.js → oauth-workspace-access-BF7jaswv.js} +1 -1
- package/dist/owletto/dist/assets/{organization-uSDYkJpX.js → organization-D9RPsWG-.js} +1 -1
- package/dist/owletto/dist/assets/{permissions-Fe0DP6b8.js → permissions-BlRONw-u.js} +1 -1
- package/dist/owletto/dist/assets/{proposal-review-shell-D9HwnDda.js → proposal-review-shell-uskeFIUr.js} +1 -1
- package/dist/owletto/dist/assets/{recent-C03LhMD7.js → recent-CmJ4Is6V.js} +1 -1
- package/dist/owletto/dist/assets/{renderer-CHNejd95.js → renderer-Dyf4t8kR.js} +2 -2
- package/dist/owletto/dist/assets/{reset-password-CuISnlG_.js → reset-password-BVIeE1Zm.js} +1 -1
- package/dist/owletto/dist/assets/runs-CzBeUzlQ.js +1 -0
- package/dist/owletto/dist/assets/{runs-panel-DsdESupx.js → runs-panel-D7l1uLGm.js} +1 -1
- package/dist/owletto/dist/assets/runs-table-dATyiBg2.js +1 -0
- package/dist/owletto/dist/assets/{schema-value-normalization-B--OWDL8.js → schema-value-normalization-DgMkyVVE.js} +1 -1
- package/dist/owletto/dist/assets/settings-BK1GHmzb.js +1 -0
- package/dist/owletto/dist/assets/{settings-wGNHtsDP.js → settings-Co1wj_m6.js} +1 -1
- package/dist/owletto/dist/assets/skills-DF53JcYt.js +1 -0
- package/dist/owletto/dist/assets/{switch-Dzse_XFM.js → switch-DDkPrV3p.js} +1 -1
- package/dist/owletto/dist/assets/use-applied-views-DELwQQh7.js +1 -0
- package/dist/owletto/dist/assets/{use-mention-search-uyW1Uwf6.js → use-mention-search-CGA3AaKm.js} +1 -1
- package/dist/owletto/dist/assets/view-frame-DDr-Xtet.js +1 -0
- package/dist/owletto/dist/index.html +2 -2
- package/dist/server-main.bundle.mjs +6703 -3581
- package/npm-shrinkwrap.json +530 -472
- package/package.json +5 -2
- package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
- package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
- package/vendor/connector-sdk/dist/connector-types.d.ts +28 -13
- package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
- package/vendor/connector-sdk/dist/define-connector.js +4 -1
- package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
- package/vendor/connector-sdk/dist/http-client.js +15 -13
- package/vendor/connector-sdk/dist/index.d.ts +1 -1
- package/vendor/connector-sdk/dist/retry.d.ts +15 -3
- package/vendor/connector-sdk/dist/retry.js +40 -64
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/agent-policy.js +3 -0
- package/vendor/core/dist/connector-query-errors.d.ts +3 -3
- package/vendor/core/dist/connector-query-errors.js +8 -3
- package/vendor/core/dist/contracts/tools/manage-connections.d.ts +24 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +13 -0
- package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +15 -25
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +3 -5
- package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
- package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
- package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
- package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
- package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
- package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
- package/vendor/core/dist/contracts/tools/source-files.js +55 -0
- package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
- package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
- package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
- package/vendor/core/dist/contracts/tools/view-path.js +24 -0
- package/vendor/core/dist/contracts/worker/protocol.d.ts +73 -8
- package/vendor/core/dist/contracts/worker/protocol.js +58 -9
- package/vendor/core/dist/reserved.d.ts +3 -3
- package/vendor/core/dist/reserved.js +9 -1
- package/vendor/core/dist/utils/secret-redaction.js +2 -0
- package/vendor/core/package.json +25 -5
- package/vendor/views/dist/api.d.ts +179 -0
- package/vendor/views/dist/api.js +406 -0
- package/vendor/views/dist/bridge.d.ts +141 -0
- package/vendor/views/dist/bridge.js +330 -0
- package/vendor/views/dist/index.d.ts +12 -0
- package/vendor/views/dist/index.js +10 -0
- package/vendor/views/package.json +35 -0
- package/dist/owletto/dist/assets/_-Ds4DyQjj.js +0 -2
- package/dist/owletto/dist/assets/_-VmyR6aN_.js +0 -1
- package/dist/owletto/dist/assets/_agentId-BAVnp0c7.js +0 -1
- package/dist/owletto/dist/assets/_agentId-Df-3rGi5.js +0 -1
- package/dist/owletto/dist/assets/_automationId-D696vOjd.js +0 -1
- package/dist/owletto/dist/assets/_conversationId-Ci4rgrHm.js +0 -1
- package/dist/owletto/dist/assets/_deploymentId-Iy-D5PDq.js +0 -1
- package/dist/owletto/dist/assets/_name-CeGwb0oK.js +0 -1
- package/dist/owletto/dist/assets/_owner-CFR1G8OX.js +0 -1
- package/dist/owletto/dist/assets/_skillKey-DuLcQWBu.js +0 -1
- package/dist/owletto/dist/assets/_slug-CDSO20ac.js +0 -1
- package/dist/owletto/dist/assets/accept-invitation-Db5jklHT.js +0 -1
- package/dist/owletto/dist/assets/activity-route-view-DVW3DoB7.js +0 -1
- package/dist/owletto/dist/assets/agent-thread-CzCJU3-R.js +0 -134
- package/dist/owletto/dist/assets/agents-DFs57C3c.js +0 -1
- package/dist/owletto/dist/assets/agents-workbench-C2bUlJP2.js +0 -1
- package/dist/owletto/dist/assets/automation-detail-content-DWkdhnv2.js +0 -1
- package/dist/owletto/dist/assets/automations-DFs57C3c.js +0 -1
- package/dist/owletto/dist/assets/clients-DhYr4lyL.js +0 -1
- package/dist/owletto/dist/assets/connect-Dtb-E5An.js +0 -1
- package/dist/owletto/dist/assets/connect._clientId-DWtceAAw.js +0 -1
- package/dist/owletto/dist/assets/connected._clientId-CMe-wTuV.js +0 -1
- package/dist/owletto/dist/assets/create-CcXUdke7.js +0 -1
- package/dist/owletto/dist/assets/create-Cp6hMoeU.js +0 -1
- package/dist/owletto/dist/assets/create-automation-form-CJ4meayB.js +0 -1
- package/dist/owletto/dist/assets/deployments-CjfFxyDA.js +0 -1
- package/dist/owletto/dist/assets/deployments-body-Cg0KiWGr.js +0 -1
- package/dist/owletto/dist/assets/device-DpY67Jaj.js +0 -1
- package/dist/owletto/dist/assets/device-rows-Cp3yMcuV.js +0 -1
- package/dist/owletto/dist/assets/entity-options-1EaSGMX4.js +0 -1
- package/dist/owletto/dist/assets/entity-page-DJmM70dv.js +0 -1
- package/dist/owletto/dist/assets/entity-type-page-C3mT7tXn.js +0 -1
- package/dist/owletto/dist/assets/events-feed-iliGfjit.js +0 -1
- package/dist/owletto/dist/assets/guardrails-CLlnRRy9.js +0 -1
- package/dist/owletto/dist/assets/identity-MSLryUi8.js +0 -1
- package/dist/owletto/dist/assets/index-3o4Eepb4.js +0 -1
- package/dist/owletto/dist/assets/index-BUr8321-.js +0 -7898
- package/dist/owletto/dist/assets/index-Bulu5ldM.js +0 -1
- package/dist/owletto/dist/assets/index-BvbfITqH.js +0 -1
- package/dist/owletto/dist/assets/index-ChcQMdod.css +0 -1
- package/dist/owletto/dist/assets/index-Clw9ZBj-.js +0 -1
- package/dist/owletto/dist/assets/index-D2oL4Ydo.js +0 -1
- package/dist/owletto/dist/assets/index-D7wulT4y.js +0 -1
- package/dist/owletto/dist/assets/index-DOLFe19K.js +0 -1
- package/dist/owletto/dist/assets/index-DTSA0Xh1.js +0 -1
- package/dist/owletto/dist/assets/index-DxXXVPU0.js +0 -1
- package/dist/owletto/dist/assets/index-nzvsA3hT.js +0 -1
- package/dist/owletto/dist/assets/login-CCKNM0gV.js +0 -1
- package/dist/owletto/dist/assets/logout-B-N2aodZ.js +0 -1
- package/dist/owletto/dist/assets/member-scope-gate-B560Wg-t.js +0 -1
- package/dist/owletto/dist/assets/memory-browse-page-DMDqKJn7.js +0 -101
- package/dist/owletto/dist/assets/models-M51OGDRE.js +0 -1
- package/dist/owletto/dist/assets/new-BVQS9H-Y.js +0 -1
- package/dist/owletto/dist/assets/new-DxDVE9nL.js +0 -1
- package/dist/owletto/dist/assets/runs-BnYdToDc.js +0 -1
- package/dist/owletto/dist/assets/runs-table-B7jKuILd.js +0 -1
- package/dist/owletto/dist/assets/settings-Bg9yCCoN.js +0 -1
- package/dist/owletto/dist/assets/skills-CN5Ube7A.js +0 -1
- package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
- package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@lobu/views` authoring surface (brief §1.4): `defineView`, `useParams`,
|
|
3
|
+
* `useScope`, `useQuery`, `useAction`, `sql`, plus the `mountView` entry the
|
|
4
|
+
* compiled bundle calls once. Thin layer over the hand-written `ViewBridge` —
|
|
5
|
+
* nothing here talks to the API directly; every read and action goes through
|
|
6
|
+
* the host as `tools/call`, every param change through
|
|
7
|
+
* `ui/update-model-context`.
|
|
8
|
+
*
|
|
9
|
+
* Contract with the host (our web host, Claude, any MCP Apps host):
|
|
10
|
+
* - `ui/notifications/tool-input` `arguments` = `{ scope, params }`
|
|
11
|
+
* (in Claude these are the `open_view` tool arguments).
|
|
12
|
+
* - reads: any tool with an `outputSchema` (`query_sql`, `query_sdk`,
|
|
13
|
+
* `manage_connections`, …); actions: `invoke_view_action`.
|
|
14
|
+
* - `setParams` → `ui/update-model-context` `{ structuredContent: { view,
|
|
15
|
+
* params } }`; the web host mirrors it into the address bar. Hosts without
|
|
16
|
+
* that capability keep params local to the frame.
|
|
17
|
+
*/
|
|
18
|
+
import { type ReactNode } from "react";
|
|
19
|
+
import { ViewBridge, type ToolResult } from "./bridge.js";
|
|
20
|
+
export type ParamValue = string | number | boolean;
|
|
21
|
+
export type Params = Record<string, ParamValue>;
|
|
22
|
+
/**
|
|
23
|
+
* What the view is rendering. `type` on a type page, `entity` (plus its
|
|
24
|
+
* `type`) on a record page, `event` on an event's page, nothing on the Data hub.
|
|
25
|
+
*
|
|
26
|
+
* `event` is an `events.id` and, like the event's permalink, names its whole
|
|
27
|
+
* supersede lineage. There is no event hook: read it with the same exact-id
|
|
28
|
+
* read the event page renders, and render the current version, the row that
|
|
29
|
+
* nothing superseded (the result is the lineage, oldest first):
|
|
30
|
+
*
|
|
31
|
+
* ```tsx
|
|
32
|
+
* export const view = defineView({
|
|
33
|
+
* key: "deal-won",
|
|
34
|
+
* attach: [{ event_kind: "deal.won", type: "deal" }],
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* export default function DealWon() {
|
|
38
|
+
* const { event } = useScope();
|
|
39
|
+
* const read = useQuery<{ content: Array<{ superseded_by?: number | null;
|
|
40
|
+
* title: string | null; metadata: Record<string, unknown> }> }>(
|
|
41
|
+
* event === undefined ? null : tool("read_knowledge", { content_ids: [event] })
|
|
42
|
+
* );
|
|
43
|
+
* const current = read.data?.content.find((row) => row.superseded_by == null);
|
|
44
|
+
* return <h1>{current?.title}</h1>;
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface Scope {
|
|
49
|
+
type?: string;
|
|
50
|
+
entity?: number | string;
|
|
51
|
+
event?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface ParamDef {
|
|
54
|
+
type: "string" | "number" | "boolean";
|
|
55
|
+
default?: ParamValue;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Where a view appears: exactly one subject per entry. `{ type }`,
|
|
59
|
+
* `{ entity }` and `{ workspace: true }` take a `placement`; an event
|
|
60
|
+
* attachment `{ event_kind, type }` matches events of that kind linked to at
|
|
61
|
+
* least one entity of `type`, renders on the event's page, and takes none.
|
|
62
|
+
*/
|
|
63
|
+
export type Attachment = {
|
|
64
|
+
type: string;
|
|
65
|
+
placement?: "tab" | "overview";
|
|
66
|
+
} | {
|
|
67
|
+
entity: number | string;
|
|
68
|
+
placement?: "tab" | "overview";
|
|
69
|
+
} | {
|
|
70
|
+
workspace: true;
|
|
71
|
+
placement?: "tab" | "overview";
|
|
72
|
+
} | {
|
|
73
|
+
event_kind: string;
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
export interface ViewDefinition {
|
|
77
|
+
/** View key: the single namespace of keys (no `custom:` prefix). Required —
|
|
78
|
+
* it is the identity `invoke_view_action` and the shell route key on. */
|
|
79
|
+
key: string;
|
|
80
|
+
/** Where the view appears. The attach line lives in the module; there are
|
|
81
|
+
* no attach/detach verbs. */
|
|
82
|
+
attach: Attachment[];
|
|
83
|
+
params?: Record<string, ParamDef>;
|
|
84
|
+
actions?: Record<string, {
|
|
85
|
+
emits: string;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export declare function defineView(def: ViewDefinition): ViewDefinition;
|
|
89
|
+
export declare function useParams(): readonly [
|
|
90
|
+
Params,
|
|
91
|
+
(patch: Partial<Params>) => void
|
|
92
|
+
];
|
|
93
|
+
export declare function useScope(): Scope;
|
|
94
|
+
export declare function useHost(): {
|
|
95
|
+
connected: boolean;
|
|
96
|
+
ready: boolean;
|
|
97
|
+
theme: "light" | "dark";
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Tagged template: scalar values are rendered as escaped SQL literals,
|
|
101
|
+
* never spliced raw. Numbers must be finite, booleans map to true/false,
|
|
102
|
+
* null/undefined become NULL, strings are single-quote escaped; anything
|
|
103
|
+
* else (objects, arrays) throws rather than stringifying a blob into the
|
|
104
|
+
* query. `query_sql` takes no bind parameters, so the guest escapes and the
|
|
105
|
+
* server validates tables — server-side binding stays a one-paragraph
|
|
106
|
+
* proposal until a use case needs it.
|
|
107
|
+
*/
|
|
108
|
+
export interface SqlQuery {
|
|
109
|
+
kind: "sql";
|
|
110
|
+
text: string;
|
|
111
|
+
}
|
|
112
|
+
export declare function sql(strings: TemplateStringsArray, ...values: unknown[]): SqlQuery;
|
|
113
|
+
export declare function escapeLiteral(value: unknown): string;
|
|
114
|
+
/** Direct tool read: for tools that return their JSON as `structuredContent`
|
|
115
|
+
* on MCP hosts (any tool with an `outputSchema`, e.g. `manage_connections`). */
|
|
116
|
+
export interface ToolQuery {
|
|
117
|
+
kind: "tool";
|
|
118
|
+
name: string;
|
|
119
|
+
args: Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
export declare function tool(name: string, args?: Record<string, unknown>): ToolQuery;
|
|
122
|
+
/**
|
|
123
|
+
* Read one `useQuery` result. A failed read is an error, never an empty
|
|
124
|
+
* result: `query_sql` answers a rejected statement (unknown table, bad column)
|
|
125
|
+
* with a normal result carrying `error` beside `rows: []`, and `query_sdk`
|
|
126
|
+
* reports a thrown script as `success: false` — both would otherwise render as
|
|
127
|
+
* "no rows".
|
|
128
|
+
*/
|
|
129
|
+
export declare function queryResult<T>(kind: "sql" | "sdk" | "tool", result: ToolResult): {
|
|
130
|
+
data: T | null;
|
|
131
|
+
error: string | null;
|
|
132
|
+
};
|
|
133
|
+
export interface QueryState<T> {
|
|
134
|
+
data: T | null;
|
|
135
|
+
error: string | null;
|
|
136
|
+
loading: boolean;
|
|
137
|
+
refetch: () => void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Run a read through the host. `sql\`…\`` → `query_sql`; a string →
|
|
141
|
+
* `query_sdk` script; `tool(name, args)` → that tool; `null` skips. The first
|
|
142
|
+
* fetch waits for the host's first `tool-input`: reads before it run against
|
|
143
|
+
* defaults and double-fetch when the real scope lands.
|
|
144
|
+
*/
|
|
145
|
+
export declare function useQuery<T = unknown>(query: SqlQuery | ToolQuery | string | null): QueryState<T>;
|
|
146
|
+
export interface ActionResult {
|
|
147
|
+
ok: boolean;
|
|
148
|
+
error: string | null;
|
|
149
|
+
result: unknown;
|
|
150
|
+
}
|
|
151
|
+
/** Mint the per-click interaction id the action tool requires (browser retry
|
|
152
|
+
* id on web): a UUID where available, else a time + random fallback. */
|
|
153
|
+
export declare function mintInteractionId(): string;
|
|
154
|
+
/** A declared action → `invoke_view_action { view, action, value }`. The name
|
|
155
|
+
* must exist on the CURRENT view definition; a removed button throws here
|
|
156
|
+
* instead of emitting a stale event. */
|
|
157
|
+
export declare function useAction(name: string): (value?: Record<string, unknown>) => Promise<ActionResult>;
|
|
158
|
+
export declare function defaultsFor(def: ViewDefinition): Params;
|
|
159
|
+
export declare function coerceParams(def: ViewDefinition, raw: unknown): Params;
|
|
160
|
+
export declare function coerceScope(raw: unknown): Scope;
|
|
161
|
+
/**
|
|
162
|
+
* Host bridge provider: seeds scope/params from the first tool-input,
|
|
163
|
+
* exposes reads/actions over tools/call, mirrors params through
|
|
164
|
+
* update-model-context. The server bootstrap renders this around the view's
|
|
165
|
+
* default export; `mountView` does the same for CLI-bundled entries.
|
|
166
|
+
*/
|
|
167
|
+
export declare function Provider({ def, bridge, children, }: {
|
|
168
|
+
def: ViewDefinition;
|
|
169
|
+
bridge?: ViewBridge;
|
|
170
|
+
children: ReactNode;
|
|
171
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
172
|
+
export interface MountOptions {
|
|
173
|
+
/** Test seam: drive the view against a fake parent instead of `window.parent`. */
|
|
174
|
+
bridge?: ViewBridge;
|
|
175
|
+
}
|
|
176
|
+
/** Entry point the compiled bundle calls once. Mounts the component into
|
|
177
|
+
* `#root` and connects to the host. */
|
|
178
|
+
export declare function mountView(def: ViewDefinition, Component: () => ReactNode, opts?: MountOptions): void;
|
|
179
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `@lobu/views` authoring surface (brief §1.4): `defineView`, `useParams`,
|
|
4
|
+
* `useScope`, `useQuery`, `useAction`, `sql`, plus the `mountView` entry the
|
|
5
|
+
* compiled bundle calls once. Thin layer over the hand-written `ViewBridge` —
|
|
6
|
+
* nothing here talks to the API directly; every read and action goes through
|
|
7
|
+
* the host as `tools/call`, every param change through
|
|
8
|
+
* `ui/update-model-context`.
|
|
9
|
+
*
|
|
10
|
+
* Contract with the host (our web host, Claude, any MCP Apps host):
|
|
11
|
+
* - `ui/notifications/tool-input` `arguments` = `{ scope, params }`
|
|
12
|
+
* (in Claude these are the `open_view` tool arguments).
|
|
13
|
+
* - reads: any tool with an `outputSchema` (`query_sql`, `query_sdk`,
|
|
14
|
+
* `manage_connections`, …); actions: `invoke_view_action`.
|
|
15
|
+
* - `setParams` → `ui/update-model-context` `{ structuredContent: { view,
|
|
16
|
+
* params } }`; the web host mirrors it into the address bar. Hosts without
|
|
17
|
+
* that capability keep params local to the frame.
|
|
18
|
+
*/
|
|
19
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
20
|
+
import { createRoot } from "react-dom/client";
|
|
21
|
+
import { ViewBridge } from "./bridge.js";
|
|
22
|
+
export function defineView(def) {
|
|
23
|
+
if (!def || typeof def.key !== "string" || def.key.length === 0) {
|
|
24
|
+
throw new Error("defineView({ key, attach, ... }) requires a non-empty key");
|
|
25
|
+
}
|
|
26
|
+
if (!Array.isArray(def.attach)) {
|
|
27
|
+
throw new Error(`defineView("${def.key}") requires attach to be an array`);
|
|
28
|
+
}
|
|
29
|
+
return def;
|
|
30
|
+
}
|
|
31
|
+
const Ctx = createContext(null);
|
|
32
|
+
function useRuntime() {
|
|
33
|
+
const rt = useContext(Ctx);
|
|
34
|
+
if (!rt)
|
|
35
|
+
throw new Error("@lobu/views hooks must run inside mountView()");
|
|
36
|
+
return rt;
|
|
37
|
+
}
|
|
38
|
+
export function useParams() {
|
|
39
|
+
const rt = useRuntime();
|
|
40
|
+
return [rt.params, rt.setParams];
|
|
41
|
+
}
|
|
42
|
+
export function useScope() {
|
|
43
|
+
return useRuntime().scope;
|
|
44
|
+
}
|
|
45
|
+
export function useHost() {
|
|
46
|
+
const rt = useRuntime();
|
|
47
|
+
return { connected: rt.connected, ready: rt.ready, theme: rt.theme };
|
|
48
|
+
}
|
|
49
|
+
function resultError(result) {
|
|
50
|
+
if (result.isError !== true)
|
|
51
|
+
return null;
|
|
52
|
+
const content = Array.isArray(result.content) ? result.content : [];
|
|
53
|
+
const text = content
|
|
54
|
+
.map((c) => c && typeof c === "object" && c.type === "text"
|
|
55
|
+
? String(c.text ?? "")
|
|
56
|
+
: "")
|
|
57
|
+
.join("\n")
|
|
58
|
+
.trim();
|
|
59
|
+
return text || "The host reported a tool error.";
|
|
60
|
+
}
|
|
61
|
+
export function sql(strings, ...values) {
|
|
62
|
+
let text = "";
|
|
63
|
+
strings.forEach((s, i) => {
|
|
64
|
+
text += s;
|
|
65
|
+
if (i < values.length)
|
|
66
|
+
text += escapeLiteral(values[i]);
|
|
67
|
+
});
|
|
68
|
+
return { kind: "sql", text };
|
|
69
|
+
}
|
|
70
|
+
export function escapeLiteral(value) {
|
|
71
|
+
if (value === null || value === undefined)
|
|
72
|
+
return "NULL";
|
|
73
|
+
if (typeof value === "number") {
|
|
74
|
+
if (!Number.isFinite(value))
|
|
75
|
+
throw new Error("sql: only finite numbers can be bound");
|
|
76
|
+
return String(value);
|
|
77
|
+
}
|
|
78
|
+
if (typeof value === "boolean")
|
|
79
|
+
return value ? "TRUE" : "FALSE";
|
|
80
|
+
if (typeof value === "string")
|
|
81
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
82
|
+
throw new Error("sql: only string, number, boolean, null values can be bound");
|
|
83
|
+
}
|
|
84
|
+
export function tool(name, args = {}) {
|
|
85
|
+
if (!name)
|
|
86
|
+
throw new Error("tool() requires a tool name");
|
|
87
|
+
return { kind: "tool", name, args };
|
|
88
|
+
}
|
|
89
|
+
function parseTextJson(result) {
|
|
90
|
+
const content = Array.isArray(result.content) ? result.content : [];
|
|
91
|
+
for (const c of content) {
|
|
92
|
+
if (!c || typeof c !== "object" || c.type !== "text")
|
|
93
|
+
continue;
|
|
94
|
+
let text = String(c.text ?? "").trim();
|
|
95
|
+
const fence = /```(?:json)?\s*([\s\S]*?)```/.exec(text);
|
|
96
|
+
if (fence?.[1])
|
|
97
|
+
text = fence[1].trim();
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(text);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// not JSON — keep looking
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Read one `useQuery` result. A failed read is an error, never an empty
|
|
109
|
+
* result: `query_sql` answers a rejected statement (unknown table, bad column)
|
|
110
|
+
* with a normal result carrying `error` beside `rows: []`, and `query_sdk`
|
|
111
|
+
* reports a thrown script as `success: false` — both would otherwise render as
|
|
112
|
+
* "no rows".
|
|
113
|
+
*/
|
|
114
|
+
export function queryResult(kind, result) {
|
|
115
|
+
const err = resultError(result);
|
|
116
|
+
if (err)
|
|
117
|
+
return { data: null, error: err };
|
|
118
|
+
// structuredContent when the tool declares an outputSchema (query_sql,
|
|
119
|
+
// query_sdk, every read tool on MCP hosts); otherwise the text body.
|
|
120
|
+
const sc = (result.structuredContent ??
|
|
121
|
+
parseTextJson(result) ??
|
|
122
|
+
{});
|
|
123
|
+
if (kind === "sql" && typeof sc.error === "string" && sc.error)
|
|
124
|
+
return { data: null, error: sc.error };
|
|
125
|
+
if (kind === "sdk" && sc.success === false) {
|
|
126
|
+
const e = sc.error;
|
|
127
|
+
const message = typeof e === "string" ? e : e?.message;
|
|
128
|
+
return {
|
|
129
|
+
data: null,
|
|
130
|
+
error: typeof message === "string" && message
|
|
131
|
+
? message
|
|
132
|
+
: "Query script failed",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// query_sdk → { success, return_value }, query_sql → { rows }, a named
|
|
136
|
+
// tool → its whole body.
|
|
137
|
+
const data = (kind === "sdk" ? sc.return_value : kind === "tool" ? sc : sc.rows);
|
|
138
|
+
return { data: data ?? null, error: null };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Run a read through the host. `sql\`…\`` → `query_sql`; a string →
|
|
142
|
+
* `query_sdk` script; `tool(name, args)` → that tool; `null` skips. The first
|
|
143
|
+
* fetch waits for the host's first `tool-input`: reads before it run against
|
|
144
|
+
* defaults and double-fetch when the real scope lands.
|
|
145
|
+
*/
|
|
146
|
+
export function useQuery(query) {
|
|
147
|
+
const rt = useRuntime();
|
|
148
|
+
const [state, setState] = useState({
|
|
149
|
+
data: null,
|
|
150
|
+
error: null,
|
|
151
|
+
loading: query !== null,
|
|
152
|
+
});
|
|
153
|
+
const [tick, setTick] = useState(0);
|
|
154
|
+
const key = query === null
|
|
155
|
+
? null
|
|
156
|
+
: typeof query === "string"
|
|
157
|
+
? `sdk:${query}`
|
|
158
|
+
: query.kind === "tool"
|
|
159
|
+
? `tool:${query.name}:${JSON.stringify(query.args)}`
|
|
160
|
+
: `sql:${query.text}`;
|
|
161
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: key is the stable identity of query (listing query itself refetches every render); rt.callTool is stable and tick is the intentional refetch trigger.
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
// A skipped query is idle, even when the previous request is in flight.
|
|
164
|
+
if (key === null) {
|
|
165
|
+
setState((s) => (s.loading ? { ...s, loading: false } : s));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// Queries still wait for the host to seed scope and params.
|
|
169
|
+
if (!rt.ready)
|
|
170
|
+
return;
|
|
171
|
+
let cancelled = false;
|
|
172
|
+
setState((s) => ({ ...s, loading: true }));
|
|
173
|
+
const q = query;
|
|
174
|
+
const call = typeof q === "string"
|
|
175
|
+
? rt.callTool("query_sdk", { script: q })
|
|
176
|
+
: q.kind === "tool"
|
|
177
|
+
? rt.callTool(q.name, q.args)
|
|
178
|
+
: rt.callTool("query_sql", { sql: q.text, limit: 500 });
|
|
179
|
+
call
|
|
180
|
+
.then((result) => {
|
|
181
|
+
if (cancelled)
|
|
182
|
+
return;
|
|
183
|
+
const out = queryResult(typeof q === "string" ? "sdk" : q.kind === "tool" ? "tool" : "sql", result);
|
|
184
|
+
setState({ ...out, loading: false });
|
|
185
|
+
})
|
|
186
|
+
.catch((e) => {
|
|
187
|
+
if (cancelled)
|
|
188
|
+
return;
|
|
189
|
+
setState({
|
|
190
|
+
data: null,
|
|
191
|
+
error: e instanceof Error ? e.message : String(e),
|
|
192
|
+
loading: false,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
return () => {
|
|
196
|
+
cancelled = true;
|
|
197
|
+
};
|
|
198
|
+
}, [key, rt.ready, tick]);
|
|
199
|
+
const refetch = useCallback(() => setTick((t) => t + 1), []);
|
|
200
|
+
return { ...state, refetch };
|
|
201
|
+
}
|
|
202
|
+
/** Mint the per-click interaction id the action tool requires (browser retry
|
|
203
|
+
* id on web): a UUID where available, else a time + random fallback. */
|
|
204
|
+
export function mintInteractionId() {
|
|
205
|
+
if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
|
|
206
|
+
return crypto.randomUUID();
|
|
207
|
+
}
|
|
208
|
+
return `${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
|
|
209
|
+
}
|
|
210
|
+
/** A declared action → `invoke_view_action { view, action, value }`. The name
|
|
211
|
+
* must exist on the CURRENT view definition; a removed button throws here
|
|
212
|
+
* instead of emitting a stale event. */
|
|
213
|
+
export function useAction(name) {
|
|
214
|
+
const rt = useRuntime();
|
|
215
|
+
if (!rt.def.actions?.[name]) {
|
|
216
|
+
throw new Error(`Action "${name}" is not declared on view "${rt.def.key}"`);
|
|
217
|
+
}
|
|
218
|
+
return useCallback(async (value = {}) => {
|
|
219
|
+
try {
|
|
220
|
+
// The tool requires an interaction id (browser retry id on web):
|
|
221
|
+
// mint one per click so retries stay idempotent.
|
|
222
|
+
const result = await rt.callTool("invoke_view_action", {
|
|
223
|
+
view: rt.def.key,
|
|
224
|
+
action: name,
|
|
225
|
+
value,
|
|
226
|
+
interaction_id: mintInteractionId(),
|
|
227
|
+
});
|
|
228
|
+
const err = resultError(result);
|
|
229
|
+
return {
|
|
230
|
+
ok: !err,
|
|
231
|
+
error: err,
|
|
232
|
+
result: result.structuredContent ?? null,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
return {
|
|
237
|
+
ok: false,
|
|
238
|
+
error: e instanceof Error ? e.message : String(e),
|
|
239
|
+
result: null,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}, [rt, name]);
|
|
243
|
+
}
|
|
244
|
+
export function defaultsFor(def) {
|
|
245
|
+
const out = {};
|
|
246
|
+
for (const [k, p] of Object.entries(def.params ?? {})) {
|
|
247
|
+
if (p.default !== undefined)
|
|
248
|
+
out[k] = p.default;
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
export function coerceParams(def, raw) {
|
|
253
|
+
const out = defaultsFor(def);
|
|
254
|
+
if (!raw || typeof raw !== "object")
|
|
255
|
+
return out;
|
|
256
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
257
|
+
const decl = def.params?.[k];
|
|
258
|
+
if (!decl)
|
|
259
|
+
continue; // unknown params ignored (§1.6)
|
|
260
|
+
if (decl.type === "number") {
|
|
261
|
+
const n = typeof v === "number" ? v : Number(v);
|
|
262
|
+
if (Number.isFinite(n))
|
|
263
|
+
out[k] = n;
|
|
264
|
+
}
|
|
265
|
+
else if (decl.type === "boolean") {
|
|
266
|
+
out[k] = v === true || v === "true";
|
|
267
|
+
}
|
|
268
|
+
else if (v !== undefined && v !== null) {
|
|
269
|
+
out[k] = String(v);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
export function coerceScope(raw) {
|
|
275
|
+
if (!raw || typeof raw !== "object")
|
|
276
|
+
return {};
|
|
277
|
+
const scope = raw;
|
|
278
|
+
const out = {};
|
|
279
|
+
if (typeof scope.type === "string" && scope.type.length > 0)
|
|
280
|
+
out.type = scope.type;
|
|
281
|
+
if (typeof scope.entity === "number" || typeof scope.entity === "string") {
|
|
282
|
+
out.entity = scope.entity;
|
|
283
|
+
}
|
|
284
|
+
if (typeof scope.event === "number" && Number.isInteger(scope.event)) {
|
|
285
|
+
out.event = scope.event;
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
function themeFromContext(ctx) {
|
|
290
|
+
return ctx.theme === "dark" ? "dark" : "light";
|
|
291
|
+
}
|
|
292
|
+
function applyTheme(theme) {
|
|
293
|
+
document.documentElement.classList.toggle("dark", theme === "dark");
|
|
294
|
+
document.documentElement.style.colorScheme = theme;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Host bridge provider: seeds scope/params from the first tool-input,
|
|
298
|
+
* exposes reads/actions over tools/call, mirrors params through
|
|
299
|
+
* update-model-context. The server bootstrap renders this around the view's
|
|
300
|
+
* default export; `mountView` does the same for CLI-bundled entries.
|
|
301
|
+
*/
|
|
302
|
+
export function Provider({ def, bridge, children, }) {
|
|
303
|
+
const [connected, setConnected] = useState(false);
|
|
304
|
+
const [ready, setReady] = useState(false);
|
|
305
|
+
const [scope, setScope] = useState({});
|
|
306
|
+
const [params, setParamsState] = useState(() => defaultsFor(def));
|
|
307
|
+
const [theme, setTheme] = useState("light");
|
|
308
|
+
const bridgeRef = useRef(bridge ?? null);
|
|
309
|
+
if (bridge)
|
|
310
|
+
bridgeRef.current = bridge;
|
|
311
|
+
if (bridgeRef.current === null)
|
|
312
|
+
bridgeRef.current = new ViewBridge();
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
const b = bridgeRef.current;
|
|
315
|
+
// Unreachable in practice (the body above always installs a bridge
|
|
316
|
+
// before effects run); fail loud instead of dereferencing null.
|
|
317
|
+
if (!b)
|
|
318
|
+
throw new Error("@lobu/views provider has no host bridge");
|
|
319
|
+
const offInput = b.onToolInput((args) => {
|
|
320
|
+
const input = (args ?? {});
|
|
321
|
+
setScope(coerceScope(input.scope));
|
|
322
|
+
setParamsState(coerceParams(def, input.params));
|
|
323
|
+
setReady(true);
|
|
324
|
+
});
|
|
325
|
+
const offCtx = b.onHostContext((ctx) => {
|
|
326
|
+
const next = themeFromContext(ctx);
|
|
327
|
+
setTheme(next);
|
|
328
|
+
applyTheme(next);
|
|
329
|
+
});
|
|
330
|
+
b.connect()
|
|
331
|
+
.then((ctx) => {
|
|
332
|
+
const next = themeFromContext(ctx);
|
|
333
|
+
setTheme(next);
|
|
334
|
+
applyTheme(next);
|
|
335
|
+
setConnected(true);
|
|
336
|
+
setReady(b.hasToolInput());
|
|
337
|
+
document.documentElement.setAttribute("data-ready", "true");
|
|
338
|
+
})
|
|
339
|
+
.catch((e) => console.error("[lobu-views] connect failed", e));
|
|
340
|
+
return () => {
|
|
341
|
+
offInput();
|
|
342
|
+
offCtx();
|
|
343
|
+
};
|
|
344
|
+
}, [def]);
|
|
345
|
+
const setParams = useCallback((patch) => {
|
|
346
|
+
setParamsState((prev) => {
|
|
347
|
+
const next = coerceParams(def, { ...prev, ...patch });
|
|
348
|
+
const b = bridgeRef.current;
|
|
349
|
+
if (b) {
|
|
350
|
+
b.updateModelContext({ view: def.key, params: next }).catch(() => {
|
|
351
|
+
/* host without update-model-context: params stay frame-local */
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return next;
|
|
355
|
+
});
|
|
356
|
+
}, [def]);
|
|
357
|
+
const callTool = useCallback(async (name, args) => {
|
|
358
|
+
const b = bridgeRef.current;
|
|
359
|
+
if (!b?.isConnected()) {
|
|
360
|
+
// No handshake yet — fail loud instead of queueing into a dead host.
|
|
361
|
+
throw new Error("Not connected to a host");
|
|
362
|
+
}
|
|
363
|
+
return b.callTool(name, args);
|
|
364
|
+
}, []);
|
|
365
|
+
const value = useMemo(() => ({
|
|
366
|
+
def,
|
|
367
|
+
connected,
|
|
368
|
+
ready,
|
|
369
|
+
scope,
|
|
370
|
+
params,
|
|
371
|
+
setParams,
|
|
372
|
+
theme,
|
|
373
|
+
callTool,
|
|
374
|
+
}), [def, connected, ready, scope, params, setParams, theme, callTool]);
|
|
375
|
+
return _jsx(Ctx.Provider, { value: value, children: children });
|
|
376
|
+
}
|
|
377
|
+
/** Entry point the compiled bundle calls once. Mounts the component into
|
|
378
|
+
* `#root` and connects to the host. */
|
|
379
|
+
export function mountView(def, Component, opts) {
|
|
380
|
+
const valid = defineView(def);
|
|
381
|
+
const el = document.getElementById("root");
|
|
382
|
+
if (!el)
|
|
383
|
+
throw new Error("#root missing in view shell");
|
|
384
|
+
const bridge = opts?.bridge ?? new ViewBridge();
|
|
385
|
+
let reported = false;
|
|
386
|
+
const reportSize = () => {
|
|
387
|
+
if (!reported) {
|
|
388
|
+
reported = true;
|
|
389
|
+
document.documentElement.setAttribute("data-mounted", "true");
|
|
390
|
+
}
|
|
391
|
+
const doc = document.documentElement;
|
|
392
|
+
const prev = doc.style.height;
|
|
393
|
+
doc.style.height = "max-content";
|
|
394
|
+
const height = Math.ceil(doc.getBoundingClientRect().height);
|
|
395
|
+
doc.style.height = prev;
|
|
396
|
+
bridge.notifySize(Math.ceil(window.innerWidth), height);
|
|
397
|
+
};
|
|
398
|
+
createRoot(el).render(_jsx(Provider, { def: valid, bridge: bridge, children: _jsx(Component, {}) }));
|
|
399
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
400
|
+
const observer = new ResizeObserver(reportSize);
|
|
401
|
+
observer.observe(document.documentElement);
|
|
402
|
+
observer.observe(document.body);
|
|
403
|
+
}
|
|
404
|
+
reportSize();
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=api.js.map
|