@lobu/runtime-device 24.7.0 → 24.9.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.
Files changed (88) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +35 -51
  3. package/npm-shrinkwrap.json +214 -334
  4. package/package.json +4 -2
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -3
  6. package/vendor/cli/dist/chrome-extension/manifest.json +5 -4
  7. package/vendor/cli/dist/chrome-extension/tools.js +2 -3
  8. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +27 -0
  9. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +16 -5
  10. package/vendor/cli/dist/commands/_lib/apply/client.js +31 -9
  11. package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +8 -12
  12. package/vendor/cli/dist/commands/_lib/apply/deployment.js +14 -1
  13. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +8 -4
  14. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +2 -1
  15. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +26 -7
  16. package/vendor/cli/dist/commands/_lib/apply/diff.js +101 -30
  17. package/vendor/cli/dist/commands/_lib/apply/map-config.js +29 -2
  18. package/vendor/cli/dist/commands/_lib/apply/render.js +2 -0
  19. package/vendor/cli/dist/commands/_lib/apply/shared.d.ts +20 -0
  20. package/vendor/cli/dist/commands/_lib/apply/shared.js +22 -0
  21. package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +14 -0
  22. package/vendor/cli/dist/commands/dev.js +28 -4
  23. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -2
  24. package/vendor/cli/dist/config/define.d.ts +21 -3
  25. package/vendor/cli/dist/connectors/README.md +6 -2
  26. package/vendor/cli/dist/connectors/github.ts +16 -3
  27. package/vendor/cli/dist/connectors/imessage.ts +953 -0
  28. package/vendor/cli/dist/connectors/linkedin.ts +20 -377
  29. package/vendor/cli/dist/connectors/market_quotes.ts +388 -91
  30. package/vendor/cli/dist/connectors/postgres.ts +21 -14
  31. package/vendor/cli/dist/connectors/x-dm-adapter.js +55 -21
  32. package/vendor/cli/dist/connectors/x.ts +1 -1
  33. package/vendor/cli/dist/runtime-components.json +4 -4
  34. package/vendor/cli/dist/templates/AGENTS.md.tmpl +1 -1
  35. package/vendor/cli/package.json +1 -1
  36. package/vendor/connector-sdk/dist/connector-types.d.ts +23 -2
  37. package/vendor/connector-sdk/package.json +1 -1
  38. package/vendor/connector-worker/dist/daemon/automation.js +7 -4
  39. package/vendor/connector-worker/dist/env.d.ts +15 -0
  40. package/vendor/connector-worker/dist/env.js +17 -0
  41. package/vendor/connector-worker/dist/executor/isolate.d.ts +3 -1
  42. package/vendor/connector-worker/dist/executor/isolate.js +32 -8
  43. package/vendor/connector-worker/package.json +1 -1
  44. package/vendor/core/dist/classify-error.d.ts +3 -4
  45. package/vendor/core/dist/classify-error.js +8 -8
  46. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  47. package/vendor/core/dist/connector-query-errors.js +4 -0
  48. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +17 -1
  49. package/vendor/core/dist/contracts/tools/collection-presentation.js +27 -3
  50. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +39 -0
  51. package/vendor/core/dist/contracts/tools/manage-automations.js +11 -1
  52. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
  53. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +2 -0
  54. package/vendor/core/dist/contracts/tools/manage-entity.js +7 -0
  55. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +2 -0
  56. package/vendor/core/dist/contracts/tools/manage-feeds.js +3 -0
  57. package/vendor/core/dist/contracts/tools/manage-views.d.ts +249 -7
  58. package/vendor/core/dist/contracts/tools/manage-views.js +83 -21
  59. package/vendor/core/dist/contracts/tools/navigation.d.ts +248 -0
  60. package/vendor/core/dist/contracts/tools/navigation.js +284 -0
  61. package/vendor/core/dist/contracts/tools/view-attach.d.ts +7 -0
  62. package/vendor/core/dist/contracts/tools/view-attach.js +15 -0
  63. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +4 -1
  64. package/vendor/core/dist/contracts/tools/view-content-hash.js +4 -2
  65. package/vendor/core/dist/contracts/tools/view-definition.d.ts +2 -0
  66. package/vendor/core/dist/contracts/tools/view-definition.js +52 -0
  67. package/vendor/core/dist/contracts/tools/view-host.d.ts +68 -0
  68. package/vendor/core/dist/contracts/tools/view-host.js +30 -1
  69. package/vendor/core/dist/contracts/tools/view-scope.d.ts +31 -0
  70. package/vendor/core/dist/contracts/tools/view-scope.js +45 -0
  71. package/vendor/core/dist/error-report.js +1 -0
  72. package/vendor/core/dist/errors.d.ts +17 -24
  73. package/vendor/core/dist/errors.js +17 -24
  74. package/vendor/core/dist/types.d.ts +0 -6
  75. package/vendor/core/package.json +11 -1
  76. package/vendor/views/dist/api.d.ts +30 -5
  77. package/vendor/views/dist/api.js +22 -8
  78. package/vendor/views/dist/bridge.d.ts +17 -0
  79. package/vendor/views/dist/bridge.js +49 -1
  80. package/vendor/views/dist/components.d.ts +27 -5
  81. package/vendor/views/dist/components.js +57 -7
  82. package/vendor/views/dist/embed.d.ts +98 -0
  83. package/vendor/views/dist/embed.js +418 -0
  84. package/vendor/views/dist/index.d.ts +3 -1
  85. package/vendor/views/dist/index.js +1 -0
  86. package/vendor/views/package.json +1 -1
  87. package/vendor/cli/dist/connectors/linkedin-takeout.ts +0 -577
  88. package/vendor/cli/dist/connectors/takeout-utils.ts +0 -240
@@ -140,22 +140,17 @@ export declare const AGENT_ERRORS: Record<AgentErrorCode, AgentErrorSpec>;
140
140
  * Provider says: the key is VALID, the account just cannot spend — a balance,
141
141
  * credit, or billing-limit wall rather than a windowed rate limit.
142
142
  *
143
- * The native turn classifier maps this wording to
144
- * `PROVIDER_QUOTA_EXHAUSTED`, while `providerQuotaResetNotBefore` parks
145
- * an Automation for a day on the same wording. They were maintained as separate
146
- * literals and drifted in both directions: the parker learned OpenAI's
147
- * "no credits remaining" while the classifier did not, and the classifier
148
- * matched "insufficient quota" while the parker's
149
- * list did not. Because the server gates on the code the worker assigns, the
150
- * first drift silently disabled BOTH the day-park and the provider-health
151
- * writeback for OpenAI balance exhaustion (observed in prod 2026-08-05). This
152
- * union closes both — which deliberately promotes reset-less "insufficient
153
- * quota" wording (OpenAI/Azure billing) into the day-park; the retry-horizon
154
- * guard in `balanceExhaustedNotBefore` keeps windowed 429s out of it.
143
+ * `classifyErrorMessage` maps this wording to `PROVIDER_QUOTA_EXHAUSTED`, and
144
+ * the device daemon stops an OpenCode run that is retrying it, since no retry
145
+ * clears an empty balance. It lives in core because separate copies of this
146
+ * list drifted in both directions: one learned OpenAI's "no credits remaining"
147
+ * while the classifier did not, and the classifier matched "insufficient
148
+ * quota" while the other did not, which left OpenAI balance exhaustion
149
+ * unclassified in prod (2026-08-05). This union closes both.
155
150
  *
156
151
  * Keep this to balance/billing wording only. Windowed limits ("too many
157
- * requests", a bare 429) classify as quota too, but must NOT day-park — they
158
- * self-heal, often within the minute.
152
+ * requests", a bare 429) classify as quota too, but they self-heal, often
153
+ * within the minute, so they belong in {@link PROVIDER_WINDOWED_QUOTA}.
159
154
  */
160
155
  export declare const PROVIDER_BALANCE_EXHAUSTED: RegExp;
161
156
  /**
@@ -165,17 +160,15 @@ export declare const PROVIDER_BALANCE_EXHAUSTED: RegExp;
165
160
  *
166
161
  * Hoisted here for exactly the reason {@link PROVIDER_BALANCE_EXHAUSTED} was.
167
162
  * This alternation was maintained as three independent literals — the turn
168
- * classifier (`classify-error.ts`), the device schedule parker
169
- * (`deviceProviderQuotaResetNotBefore`) and the server's own `INFRA_PATTERNS`
170
- * — and drifted the same way the balance list did: the device parker learned
171
- * ChatGPT's `usage limit` and the other two did not, so over the 30 days to
172
- * 2026-09-15, 47 runs the provider had refused were recorded as the agent's
173
- * fault, rendered to the user with no remediation CTA, and dodged the
174
- * PROVIDER_* alert.
163
+ * classifier (`classify-error.ts`), a since-removed device schedule check and
164
+ * the server's own `INFRA_PATTERNS` — and drifted the same way the balance
165
+ * list did: the device check learned ChatGPT's `usage limit` and the other two
166
+ * did not, so over the 30 days to 2026-09-15, 47 runs the provider had refused
167
+ * were recorded as the agent's fault, rendered to the user with no remediation
168
+ * CTA, and dodged the PROVIDER_* alert.
175
169
  *
176
- * Keep windowed wording ONLY. These must classify as quota but must NOT reach
177
- * the day-park: they often clear within the minute, and the caller decides the
178
- * horizon from the provider's own named reset.
170
+ * Keep windowed wording ONLY. These classify as quota, but they often clear
171
+ * within the minute, so nothing may treat them as a balance wall.
179
172
  */
180
173
  export declare const PROVIDER_WINDOWED_QUOTA: RegExp;
181
174
  /** Parse an `AgentErrorCode` from an unknown value (payload/DB boundary). */
@@ -211,22 +211,17 @@ exports.AGENT_ERRORS = {
211
211
  * Provider says: the key is VALID, the account just cannot spend — a balance,
212
212
  * credit, or billing-limit wall rather than a windowed rate limit.
213
213
  *
214
- * The native turn classifier maps this wording to
215
- * `PROVIDER_QUOTA_EXHAUSTED`, while `providerQuotaResetNotBefore` parks
216
- * an Automation for a day on the same wording. They were maintained as separate
217
- * literals and drifted in both directions: the parker learned OpenAI's
218
- * "no credits remaining" while the classifier did not, and the classifier
219
- * matched "insufficient quota" while the parker's
220
- * list did not. Because the server gates on the code the worker assigns, the
221
- * first drift silently disabled BOTH the day-park and the provider-health
222
- * writeback for OpenAI balance exhaustion (observed in prod 2026-08-05). This
223
- * union closes both — which deliberately promotes reset-less "insufficient
224
- * quota" wording (OpenAI/Azure billing) into the day-park; the retry-horizon
225
- * guard in `balanceExhaustedNotBefore` keeps windowed 429s out of it.
214
+ * `classifyErrorMessage` maps this wording to `PROVIDER_QUOTA_EXHAUSTED`, and
215
+ * the device daemon stops an OpenCode run that is retrying it, since no retry
216
+ * clears an empty balance. It lives in core because separate copies of this
217
+ * list drifted in both directions: one learned OpenAI's "no credits remaining"
218
+ * while the classifier did not, and the classifier matched "insufficient
219
+ * quota" while the other did not, which left OpenAI balance exhaustion
220
+ * unclassified in prod (2026-08-05). This union closes both.
226
221
  *
227
222
  * Keep this to balance/billing wording only. Windowed limits ("too many
228
- * requests", a bare 429) classify as quota too, but must NOT day-park — they
229
- * self-heal, often within the minute.
223
+ * requests", a bare 429) classify as quota too, but they self-heal, often
224
+ * within the minute, so they belong in {@link PROVIDER_WINDOWED_QUOTA}.
230
225
  */
231
226
  exports.PROVIDER_BALANCE_EXHAUSTED = /credit balance is too low|insufficient (?:credits?|balance|funds|quota)\b|no resource package|billing_hard_limit_reached|payment required|exceeded your current quota|out of credits?\b|no credits remaining/i;
232
227
  /**
@@ -236,17 +231,15 @@ exports.PROVIDER_BALANCE_EXHAUSTED = /credit balance is too low|insufficient (?:
236
231
  *
237
232
  * Hoisted here for exactly the reason {@link PROVIDER_BALANCE_EXHAUSTED} was.
238
233
  * This alternation was maintained as three independent literals — the turn
239
- * classifier (`classify-error.ts`), the device schedule parker
240
- * (`deviceProviderQuotaResetNotBefore`) and the server's own `INFRA_PATTERNS`
241
- * — and drifted the same way the balance list did: the device parker learned
242
- * ChatGPT's `usage limit` and the other two did not, so over the 30 days to
243
- * 2026-09-15, 47 runs the provider had refused were recorded as the agent's
244
- * fault, rendered to the user with no remediation CTA, and dodged the
245
- * PROVIDER_* alert.
234
+ * classifier (`classify-error.ts`), a since-removed device schedule check and
235
+ * the server's own `INFRA_PATTERNS` — and drifted the same way the balance
236
+ * list did: the device check learned ChatGPT's `usage limit` and the other two
237
+ * did not, so over the 30 days to 2026-09-15, 47 runs the provider had refused
238
+ * were recorded as the agent's fault, rendered to the user with no remediation
239
+ * CTA, and dodged the PROVIDER_* alert.
246
240
  *
247
- * Keep windowed wording ONLY. These must classify as quota but must NOT reach
248
- * the day-park: they often clear within the minute, and the caller decides the
249
- * horizon from the provider's own named reset.
241
+ * Keep windowed wording ONLY. These classify as quota, but they often clear
242
+ * within the minute, so nothing may treat them as a balance wall.
250
243
  */
251
244
  exports.PROVIDER_WINDOWED_QUOTA = /limit exhausted|usage limit|rate[-\s]?limit|quota (?:exceeded|exhausted)|too many requests|\b429\b|resource_exhausted/i;
252
245
  /** Parse an `AgentErrorCode` from an unknown value (payload/DB boundary). */
@@ -266,12 +266,6 @@ export interface ThreadResponsePayload {
266
266
  * the provider's sentence; `errorCode` selects the CTA link.
267
267
  */
268
268
  error?: string;
269
- /**
270
- * Original terminal error used only for durable run bookkeeping when an
271
- * output guardrail replaces the user-visible error text. Gateway-owned;
272
- * renderers must never expose this field to clients.
273
- */
274
- bookkeepingError?: string;
275
269
  errorCode?: string;
276
270
  /** Non-secret provider/model targeting for the error CTA. */
277
271
  errorContext?: AgentErrorContext;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/core",
3
- "version": "24.7.0",
3
+ "version": "24.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Core types and utilities for Lobu agent platform",
6
6
  "repository": {
@@ -241,6 +241,16 @@
241
241
  "import": "./dist/contracts/tools/pagination.js",
242
242
  "require": "./dist/contracts/tools/pagination.js"
243
243
  },
244
+ "./contracts/tools/navigation": {
245
+ "types": "./dist/contracts/tools/navigation.d.ts",
246
+ "import": "./dist/contracts/tools/navigation.js",
247
+ "require": "./dist/contracts/tools/navigation.js"
248
+ },
249
+ "./contracts/tools/view-scope": {
250
+ "types": "./dist/contracts/tools/view-scope.d.ts",
251
+ "import": "./dist/contracts/tools/view-scope.js",
252
+ "require": "./dist/contracts/tools/view-scope.js"
253
+ },
244
254
  "./contracts/tools/view-host": {
245
255
  "types": "./dist/contracts/tools/view-host.d.ts",
246
256
  "import": "./dist/contracts/tools/view-host.js",
@@ -145,9 +145,33 @@ export interface ViewDefinition {
145
145
  * no attach/detach verbs. */
146
146
  attach: Attachment[];
147
147
  params?: Record<string, ParamDef>;
148
- actions?: Record<string, {
149
- emits: string;
150
- }>;
148
+ actions?: Record<string, ActionDef>;
149
+ /** External origins the view may load images from, such as a map tile
150
+ * server: bare https origins with a public hostname and no path
151
+ * (`"https://tile.openstreetmap.org"`), at most 8. Images only is a
152
+ * save-time check (the validator renders the empty, error and loading
153
+ * states), not a runtime limit: MCP hosts receive these as
154
+ * `resourceDomains`, which also allows scripts, styles, fonts and media
155
+ * from them, and the Lobu web app applies no runtime CSP to views. Declare
156
+ * only image or tile CDN origins you trust. */
157
+ resources?: string[];
158
+ }
159
+ /** A declared action: the event kind it emits, the entity fields it may
160
+ * update, or both (committed in one transaction). */
161
+ export interface ActionDef {
162
+ emits?: string;
163
+ /** Submit `{ entity_id, set: { field: value } }` as the action value. The
164
+ * view must attach to `entityType`. Stamped (x-lobu-stamps) fields are
165
+ * server-owned and refused. */
166
+ updates?: {
167
+ entityType: string;
168
+ fields: string[];
169
+ };
170
+ }
171
+ export interface ActionOptions {
172
+ /** For an `updates` action: metadata field -> the value this view read.
173
+ * The server checks it under the row lock and refuses a stale write (409). */
174
+ expected?: Record<string, unknown>;
151
175
  }
152
176
  export declare function defineView(def: ViewDefinition): ViewDefinition;
153
177
  export declare function useParams(): readonly [
@@ -264,8 +288,9 @@ export interface ActionResult {
264
288
  /** Mint one id for a deliberate submission, retained by its retry closure. */
265
289
  export declare function mintInteractionId(): string;
266
290
  /** Submit a declared action. Failed acknowledgements expose an explicit retry
267
- * that keeps the original value, event subject and interaction id. */
268
- export declare function useAction(name: string): (value?: Record<string, unknown>) => Promise<ActionResult>;
291
+ * that keeps the original value, expected values, event subject and
292
+ * interaction id. */
293
+ export declare function useAction(name: string): (value?: Record<string, unknown>, options?: ActionOptions) => Promise<ActionResult>;
269
294
  export declare function defaultsFor(def: ViewDefinition): Params;
270
295
  export declare function coerceParams(def: ViewDefinition, raw: unknown): Params;
271
296
  export declare function coerceScope(raw: unknown): Scope;
@@ -2,6 +2,7 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Component, createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
3
3
  import { createRoot } from "react-dom/client";
4
4
  import { ViewBridge, ViewBridgeError, } from "./bridge.js";
5
+ import { EmbedProvider, EmbedRegistry } from "./embed.js";
5
6
  export function defineView(def) {
6
7
  if (!def || typeof def.key !== "string" || def.key.length === 0) {
7
8
  throw new Error("defineView({ key, attach, ... }) requires a non-empty key");
@@ -302,13 +303,14 @@ export function mintInteractionId() {
302
303
  return `${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
303
304
  }
304
305
  /** Submit a declared action. Failed acknowledgements expose an explicit retry
305
- * that keeps the original value, event subject and interaction id. */
306
+ * that keeps the original value, expected values, event subject and
307
+ * interaction id. */
306
308
  export function useAction(name) {
307
309
  const rt = useRuntime();
308
310
  if (!rt.def.actions?.[name]) {
309
311
  throw new Error(`Action "${name}" is not declared on view "${rt.def.key}"`);
310
312
  }
311
- return useCallback(async (value = {}) => {
313
+ return useCallback(async (value = {}, options = {}) => {
312
314
  if (!rt.ready) {
313
315
  return {
314
316
  ok: false,
@@ -325,6 +327,9 @@ export function useAction(name) {
325
327
  view: rt.def.key,
326
328
  action: name,
327
329
  value,
330
+ ...(options.expected === undefined
331
+ ? {}
332
+ : { expected: options.expected }),
328
333
  ...(rt.scope.event === undefined
329
334
  ? {}
330
335
  : { scope: { event: rt.scope.event } }),
@@ -446,9 +451,10 @@ function applyTheme(theme) {
446
451
  /**
447
452
  * The MCP Apps standard style variables (`McpUiStyleVariableKey`, protocol
448
453
  * `2026-01-26`). A host sends any subset in `hostContext.styles.variables`;
449
- * the shell's tokens (`--fg`, `--muted`, `--border`, `--accent`, the font and
450
- * radii) derive from them, so a view takes the host's look. Built from the
451
- * spec's own axes rather than imported: the guest carries no ext-apps code.
454
+ * the shell's shadcn tokens (`--foreground`, `--muted-foreground`, `--muted`,
455
+ * `--accent`, `--border`, the font and radii) derive from them, so a view takes
456
+ * the host's look. Built from the spec's own axes rather than imported: the
457
+ * guest carries no ext-apps code.
452
458
  */
453
459
  const SEMANTIC = ["primary", "secondary", "tertiary", "inverse", "ghost"];
454
460
  const STATUS = ["info", "danger", "success", "warning"];
@@ -512,7 +518,7 @@ class RenderBoundary extends Component {
512
518
  render() {
513
519
  if (!this.state.error)
514
520
  return this.props.children;
515
- return (_jsxs("div", { role: "alert", "data-lobu-render-error": "true", style: { padding: 12, color: "var(--fg)" }, children: ["This view failed to render: ", this.state.error.message] }));
521
+ return (_jsxs("div", { role: "alert", "data-lobu-render-error": "true", style: { padding: 12, color: "var(--foreground)" }, children: ["This view failed to render: ", this.state.error.message] }));
516
522
  }
517
523
  }
518
524
  /**
@@ -535,6 +541,10 @@ export function Provider({ def, bridge, children, }) {
535
541
  bridgeRef.current = bridge;
536
542
  if (bridgeRef.current === null)
537
543
  bridgeRef.current = new ViewBridge();
544
+ const embedsRef = useRef(null);
545
+ if (embedsRef.current === null)
546
+ embedsRef.current = new EmbedRegistry(() => bridgeRef.current);
547
+ const embeds = embedsRef.current;
538
548
  useEffect(() => {
539
549
  const b = bridgeRef.current;
540
550
  // Unreachable in practice (the body above always installs a bridge
@@ -565,10 +575,12 @@ export function Provider({ def, bridge, children, }) {
565
575
  };
566
576
  const offCtx = b.onHostContext(adoptContext);
567
577
  const offData = b.onDataChanged(() => setDataVersion((v) => v + 1));
578
+ const offEmbeds = embeds.attach(b);
568
579
  b.connect()
569
580
  .then((ctx) => {
570
581
  adoptContext(ctx);
571
582
  setConnected(true);
583
+ embeds.setConnected(true);
572
584
  setReady(b.hasToolInput());
573
585
  document.documentElement.setAttribute("data-ready", "true");
574
586
  })
@@ -578,8 +590,10 @@ export function Provider({ def, bridge, children, }) {
578
590
  offResult();
579
591
  offCtx();
580
592
  offData();
593
+ offEmbeds();
594
+ embeds.setConnected(false);
581
595
  };
582
- }, [def]);
596
+ }, [def, embeds]);
583
597
  // Report the document height so the host can fit the frame. This lives in
584
598
  // the provider, not `mountView`: the server bootstrap renders the provider
585
599
  // directly, and a frame that never hears a size stays at its minimum height.
@@ -700,7 +714,7 @@ export function Provider({ def, bridge, children, }) {
700
714
  ]);
701
715
  // A host-resolved replacement is a new form, including in MCP hosts that
702
716
  // keep the iframe mounted while delivering the opening result.
703
- return (_jsx(Ctx.Provider, { value: value, children: _jsx(RenderBoundary, { resetKey: `${ready}:${JSON.stringify(scope)}:${JSON.stringify(params)}:${dataVersion}`, children: children }) }, scope.event ?? "unbound"));
717
+ return (_jsx(Ctx.Provider, { value: value, children: _jsx(EmbedProvider, { registry: embeds, children: _jsx(RenderBoundary, { resetKey: `${ready}:${JSON.stringify(scope)}:${JSON.stringify(params)}:${dataVersion}`, children: children }) }) }, scope.event ?? "unbound"));
704
718
  }
705
719
  /** Entry point the compiled bundle calls once. Mounts the component into
706
720
  * `#root` and connects to the host. */
@@ -14,6 +14,7 @@
14
14
  * like the SDK's transport.
15
15
  */
16
16
  import type { EntityGetInput } from "@lobu/core/contracts/tools/manage-entity";
17
+ import { type ViewEmbedSlot, type ViewEmbedStatus, type ViewFocusDirection } from "@lobu/core/contracts/tools/view-host";
17
18
  export declare class ViewBridgeError extends Error {
18
19
  readonly code: number;
19
20
  constructor(message: string, code: number);
@@ -74,6 +75,9 @@ export declare class ViewBridge {
74
75
  private toolCancelledListeners;
75
76
  private hostContextListeners;
76
77
  private dataChangedListeners;
78
+ private embedSizeListeners;
79
+ private embedFocusListeners;
80
+ private focusEnterListeners;
77
81
  /** Set by the first `tool-input` and never cleared: queries must not fire
78
82
  * before it (the host seeds scope + params there; anything read earlier
79
83
  * runs against defaults and double-fetches). */
@@ -103,6 +107,19 @@ export declare class ViewBridge {
103
107
  /** The host saw workspace data change (Lobu hosts only; other hosts never
104
108
  * send it, and reads then refresh on their own triggers). */
105
109
  onDataChanged(listener: () => void): () => void;
110
+ /** A child view's height in a slot (Lobu web host only). */
111
+ onEmbedSize(listener: (id: string, height: number) => void): () => void;
112
+ /** Keyboard focus left a slot's child (Lobu web host only). */
113
+ onEmbedFocus(listener: (id: string, direction: ViewFocusDirection) => void): () => void;
114
+ /** Keyboard focus entered this view as a slot's child (Lobu web host only). */
115
+ onFocusEnter(listener: (direction: ViewFocusDirection) => void): () => void;
116
+ /** Report every slot on screen. Rejects with code -32601 on a host that
117
+ * does not mount embedded views. */
118
+ syncEmbeds(embeds: ViewEmbedSlot[]): Promise<{
119
+ embeds?: ViewEmbedStatus[];
120
+ }>;
121
+ /** Move keyboard focus into a slot's child. */
122
+ focusEmbed(id: string, direction: ViewFocusDirection): Promise<unknown>;
106
123
  /**
107
124
  * Run the `ui/initialize` handshake, then announce readiness. Resolves with
108
125
  * the host context. Rejects when the host answers with an error or stays
@@ -13,7 +13,7 @@
13
13
  * "2.0", method, params }`. Anything else in the inbox is ignored, exactly
14
14
  * like the SDK's transport.
15
15
  */
16
- import { VIEW_OPEN_RECORD_METHOD, VIEW_WORKSPACE_META_KEY, } from "@lobu/core/contracts/tools/view-host";
16
+ import { VIEW_EMBED_FOCUS_NOTIFICATION, VIEW_EMBED_SIZE_NOTIFICATION, VIEW_EMBEDS_FOCUS_METHOD, VIEW_EMBEDS_SYNC_METHOD, VIEW_FOCUS_ENTER_NOTIFICATION, VIEW_OPEN_RECORD_METHOD, VIEW_WORKSPACE_META_KEY, } from "@lobu/core/contracts/tools/view-host";
17
17
  export class ViewBridgeError extends Error {
18
18
  code;
19
19
  constructor(message, code) {
@@ -54,6 +54,9 @@ export class ViewBridge {
54
54
  toolCancelledListeners = new Set();
55
55
  hostContextListeners = new Set();
56
56
  dataChangedListeners = new Set();
57
+ embedSizeListeners = new Set();
58
+ embedFocusListeners = new Set();
59
+ focusEnterListeners = new Set();
57
60
  /** Set by the first `tool-input` and never cleared: queries must not fire
58
61
  * before it (the host seeds scope + params there; anything read earlier
59
62
  * runs against defaults and double-fetches). */
@@ -132,6 +135,30 @@ export class ViewBridge {
132
135
  this.dataChangedListeners.add(listener);
133
136
  return () => this.dataChangedListeners.delete(listener);
134
137
  }
138
+ /** A child view's height in a slot (Lobu web host only). */
139
+ onEmbedSize(listener) {
140
+ this.embedSizeListeners.add(listener);
141
+ return () => this.embedSizeListeners.delete(listener);
142
+ }
143
+ /** Keyboard focus left a slot's child (Lobu web host only). */
144
+ onEmbedFocus(listener) {
145
+ this.embedFocusListeners.add(listener);
146
+ return () => this.embedFocusListeners.delete(listener);
147
+ }
148
+ /** Keyboard focus entered this view as a slot's child (Lobu web host only). */
149
+ onFocusEnter(listener) {
150
+ this.focusEnterListeners.add(listener);
151
+ return () => this.focusEnterListeners.delete(listener);
152
+ }
153
+ /** Report every slot on screen. Rejects with code -32601 on a host that
154
+ * does not mount embedded views. */
155
+ syncEmbeds(embeds) {
156
+ return this.request(VIEW_EMBEDS_SYNC_METHOD, { embeds });
157
+ }
158
+ /** Move keyboard focus into a slot's child. */
159
+ focusEmbed(id, direction) {
160
+ return this.request(VIEW_EMBEDS_FOCUS_METHOD, { id, direction });
161
+ }
135
162
  /**
136
163
  * Run the `ui/initialize` handshake, then announce readiness. Resolves with
137
164
  * the host context. Rejects when the host answers with an error or stays
@@ -354,6 +381,27 @@ export class ViewBridge {
354
381
  listener();
355
382
  break;
356
383
  }
384
+ case VIEW_EMBED_SIZE_NOTIFICATION: {
385
+ if (typeof params.id !== "string" || typeof params.height !== "number")
386
+ break;
387
+ for (const listener of [...this.embedSizeListeners])
388
+ listener(params.id, params.height);
389
+ break;
390
+ }
391
+ case VIEW_EMBED_FOCUS_NOTIFICATION: {
392
+ if (typeof params.id !== "string")
393
+ break;
394
+ const direction = params.direction === "backward" ? "backward" : "forward";
395
+ for (const listener of [...this.embedFocusListeners])
396
+ listener(params.id, direction);
397
+ break;
398
+ }
399
+ case VIEW_FOCUS_ENTER_NOTIFICATION: {
400
+ const direction = params.direction === "backward" ? "backward" : "forward";
401
+ for (const listener of [...this.focusEnterListeners])
402
+ listener(direction);
403
+ break;
404
+ }
357
405
  default:
358
406
  break;
359
407
  }
@@ -8,10 +8,11 @@
8
8
  * what the host returns, plus the honest states (`QueryState.loading`,
9
9
  * `.error`, `.errorCode`, `.truncated`) that `useQuery` reports.
10
10
  *
11
- * Styling follows the shell's theme tokens (`--fg`, `--muted`, `--border`,
12
- * `--accent`, `--font`, `--radius`, `--radius-lg`), which derive from the
13
- * host's MCP Apps style variables and flip with its `.dark` class, so kit
14
- * output takes the host's look without configuration. Theme tokens carry
11
+ * Styling follows the shell's theme tokens (shadcn names: `--foreground`,
12
+ * `--muted-foreground` for secondary text, `--muted`/`--accent` for surfaces,
13
+ * `--border`, `--primary`, `--font-sans`, `--radius`, `--radius-lg`), which
14
+ * derive from the host's MCP Apps style variables and flip with its `.dark`
15
+ * class, so kit output takes the host's look without configuration. Theme tokens carry
15
16
  * light-mode fallbacks; pie series and error accents use fixed colors.
16
17
  *
17
18
  * Server-side compile allowlist: this module is pinned beside `react` and
@@ -144,8 +145,29 @@ export declare function Link({ href, children, }: {
144
145
  href: string;
145
146
  children: ReactNode;
146
147
  }): import("react/jsx-runtime").JSX.Element;
147
- export declare function LoadingState({ text }: {
148
+ export interface SkeletonProps {
149
+ /** CSS width; default the full width. */
150
+ width?: number | string;
151
+ /** CSS height; default one line of text. */
152
+ height?: number | string;
153
+ /** Corner radius; default the host's. */
154
+ radius?: number | string;
155
+ }
156
+ /**
157
+ * A placeholder shaped like what is loading: a pulsing block in the host's
158
+ * muted surface colour. Size it like the content it stands for (a figure,
159
+ * a row, a chart) so the page does not jump when the data lands. Purely
160
+ * visual; announce the wait with `LoadingState` or your own `role="status"`.
161
+ */
162
+ export declare function Skeleton({ width, height, radius, }: SkeletonProps): import("react/jsx-runtime").JSX.Element;
163
+ /**
164
+ * A query's loading state, as skeleton lines in the host's style. `text` is
165
+ * what assistive technology announces; `lines` sets how many lines stand in
166
+ * for the content (default 3).
167
+ */
168
+ export declare function LoadingState({ text, lines, }: {
148
169
  text?: string;
170
+ lines?: number;
149
171
  }): import("react/jsx-runtime").JSX.Element;
150
172
  export declare function EmptyState({ title, hint }: {
151
173
  title: string;
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useRef, useState } from "react";
3
3
  import { resolveViewHref, useHost } from "./api.js";
4
- const FONT_STACK = 'var(--font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif)';
4
+ const FONT_STACK = 'var(--font-sans, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif)';
5
5
  const INK = {
6
- color: "var(--fg, #0a0a0a)",
6
+ color: "var(--foreground, #0a0a0a)",
7
7
  fontFamily: FONT_STACK,
8
8
  fontSize: 13,
9
9
  lineHeight: 1.45,
@@ -87,7 +87,7 @@ function PageButton({ disabled, onClick, label, }) {
87
87
  border: "1px solid var(--border, #e5e7eb)",
88
88
  borderRadius: "var(--radius, 6px)",
89
89
  background: "transparent",
90
- color: "var(--fg, #0a0a0a)",
90
+ color: "var(--foreground, #0a0a0a)",
91
91
  padding: "2px 10px",
92
92
  font: "inherit",
93
93
  }, children: label === "Previous page" ? "‹ Prev" : "Next ›" }));
@@ -115,7 +115,7 @@ const FIELD_BOX = {
115
115
  border: "1px solid var(--border, #e5e7eb)",
116
116
  borderRadius: "var(--radius, 6px)",
117
117
  background: "transparent",
118
- color: "var(--fg, #0a0a0a)",
118
+ color: "var(--foreground, #0a0a0a)",
119
119
  padding: "4px 8px",
120
120
  font: "inherit",
121
121
  maxWidth: "100%",
@@ -323,8 +323,58 @@ export function Link({ href, children, }) {
323
323
  /* ------------------------------------------------------------------ */
324
324
  /* Query states — render `useQuery` honestly */
325
325
  /* ------------------------------------------------------------------ */
326
- export function LoadingState({ text = "Loading…" }) {
327
- return (_jsx("p", { role: "status", style: { ...INK, color: "var(--color-text-secondary, #6b7280)" }, children: text }));
326
+ const VISUALLY_HIDDEN = {
327
+ position: "absolute",
328
+ width: 1,
329
+ height: 1,
330
+ overflow: "hidden",
331
+ clip: "rect(0 0 0 0)",
332
+ whiteSpace: "nowrap",
333
+ };
334
+ /** Pulse an element while it is mounted, unless the reader asked for less
335
+ * motion. The kit ships no stylesheet, so the animation runs from script. */
336
+ function usePulse(ref) {
337
+ useEffect(() => {
338
+ const el = ref.current;
339
+ if (!el || typeof el.animate !== "function")
340
+ return;
341
+ if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)
342
+ return;
343
+ const pulse = el.animate([{ opacity: 1 }, { opacity: 0.45 }, { opacity: 1 }], {
344
+ duration: 1600,
345
+ iterations: Number.POSITIVE_INFINITY,
346
+ easing: "ease-in-out",
347
+ });
348
+ return () => pulse.cancel();
349
+ }, [ref]);
350
+ }
351
+ /**
352
+ * A placeholder shaped like what is loading: a pulsing block in the host's
353
+ * muted surface colour. Size it like the content it stands for (a figure,
354
+ * a row, a chart) so the page does not jump when the data lands. Purely
355
+ * visual; announce the wait with `LoadingState` or your own `role="status"`.
356
+ */
357
+ export function Skeleton({ width = "100%", height = 14, radius, }) {
358
+ const ref = useRef(null);
359
+ usePulse(ref);
360
+ return (_jsx("span", { ref: ref, "aria-hidden": "true", style: {
361
+ display: "block",
362
+ width,
363
+ height,
364
+ borderRadius: radius ?? "var(--radius, 6px)",
365
+ background: "var(--muted, #f3f4f6)",
366
+ } }));
367
+ }
368
+ /**
369
+ * A query's loading state, as skeleton lines in the host's style. `text` is
370
+ * what assistive technology announces; `lines` sets how many lines stand in
371
+ * for the content (default 3).
372
+ */
373
+ export function LoadingState({ text = "Loading…", lines = 3, }) {
374
+ const widths = ["72%", "94%", "56%", "84%", "64%"];
375
+ // Fixed placeholder lines: each keeps its position for the whole wait.
376
+ const placeholders = Array.from({ length: Number.isFinite(lines) ? Math.max(1, Math.floor(lines)) : 3 }, (_, i) => ({ id: `line-${i}`, width: widths[i % widths.length] }));
377
+ return (_jsxs("div", { role: "status", style: { display: "grid", gap: 8, padding: "4px 0" }, children: [_jsx("span", { style: VISUALLY_HIDDEN, children: text }), placeholders.map((line) => (_jsx(Skeleton, { width: line.width, height: 12 }, line.id)))] }));
328
378
  }
329
379
  export function EmptyState({ title, hint }) {
330
380
  return (_jsxs("div", { style: { ...INK, color: "var(--color-text-secondary, #6b7280)" }, children: [_jsx("p", { style: { margin: "4px 0" }, children: title }), hint && _jsx("p", { style: { margin: "0 0 4px", fontSize: 12 }, children: hint })] }));
@@ -344,7 +394,7 @@ export function ErrorState({ message, errorCode, onRetry, }) {
344
394
  border: "1px solid var(--border, #e5e7eb)",
345
395
  borderRadius: "var(--radius, 6px)",
346
396
  background: "transparent",
347
- color: "var(--fg, #0a0a0a)",
397
+ color: "var(--foreground, #0a0a0a)",
348
398
  padding: "2px 10px",
349
399
  font: "inherit",
350
400
  }, children: "Retry" }))] }));