@lotics/app-sdk 0.131.11 → 0.131.12

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/AGENTS.md CHANGED
@@ -20,11 +20,11 @@ This file is the index. The **exact type** of anything is its shipped declaratio
20
20
  | [docs/workflows.md](./docs/workflows.md) | **The workflow-BODY reference** — the JS subset a body may use, opaque `fld_*`/`opt_*` keys, every step form, the accepted sugar, helpers, record-write surfaces, the traps and the verify loop. |
21
21
  | [docs/recipes.md](./docs/recipes.md) | Task-shaped how-tos — returning a generated file, returning structured data, parameterized lookups, composable optional filters, cell decoding, testing an AI action without spending credits. |
22
22
  | [docs/files.md](./docs/files.md) | Files end to end — `useFileUpload` and its `fidelity` and a photo's `place`, `renameFile` (a new file over the same bytes), `useAttachments`/`useAttachmentPiles`, `readFiles` and presigned URLs (a bearer credential — never logged or persisted), workflow-generated files, naming a zip's entries, the delivery bounds. |
23
- | [docs/members_and_options.md](./docs/members_and_options.md) | People and select options — `useMembers`, `useFieldOptions`, `useViewer`, `useWorkspaceTimezone`/`useWorkspaceCurrency`, `useAppContext`, the workspace's zone at the root, a member's links to one record for a person with no seat (`useOutsideLinks`). |
23
+ | [docs/members_and_options.md](./docs/members_and_options.md) | People and select options — `useMembers`, `useFieldOptions`, `useViewer`, `useWorkspaceTimezone`/`useWorkspaceCurrency`, `useAppContext`, `askAppContext` (ask the host's context early), the workspace's zone at the root, a member's links to one record for a person with no seat (`useOutsideLinks`). |
24
24
  | [docs/navigation_and_state.md](./docs/navigation_and_state.md) | `AppRouter` (embedded/standalone URL model, the screens and `drawers` it reports to the host, opening at `/` when the person opens the app from the host: `openRequested`, `subscribeOpen`), `useUrlState` + `urlParam` codecs, `useRecents`, `useFolderPick`. |
25
25
  | [docs/ai.md](./docs/ai.md) | `useAgentRun` (structured vs free-text, streaming parts, the agent's ask-back), `askAi`, `useAiContext`, and what the member's own chat agent can do with the app while it is open. |
26
26
  | [docs/security.md](./docs/security.md) | **Read before shipping** — the owner-principal model, `is_current_member` scoping, write attribution, group gates, public-app bounds, why a per-input bound is a tenancy floor rather than an authorization check. |
27
- | [docs/runtime.md](./docs/runtime.md) | `mount()` and the errors it reports to the host (`reportAppError`), the two transports, the API address a standalone bundle reads out of its own page (`<meta name="lotics-api-base">`), `rpc()` and `installRpcTransport` (a page that is never an app's answers every op itself), the mock harness (`fixture` + `?__mock=1` — queries, workflows and agents, a mocked agent's run played line by line), `openExternal`/`downloadFile`, geofencing, the peer dependencies. |
27
+ | [docs/runtime.md](./docs/runtime.md) | `mount()` and the errors it reports to the host (`reportAppError`), the two transports, the API address a standalone bundle reads out of its own page (`<meta name="lotics-api-base">`), `rpc()` (and its `holdsCover` option), `holdDrawn` (keep the host's loading cover up), `installRpcTransport` (a page that is never an app's answers every op itself), the mock harness (`fixture` + `?__mock=1` — queries, workflows and agents, a mocked agent's run played line by line), `openExternal`/`downloadFile`, geofencing, the peer dependencies. |
28
28
 
29
29
  ## Non-negotiables (each detailed in its doc)
30
30
 
@@ -1407,10 +1407,10 @@ function installRpcTransport(transport) {
1407
1407
  function hostSpec() {
1408
1408
  return rpc("spec", {});
1409
1409
  }
1410
- function rpc(op, payload) {
1410
+ function rpc(op, payload, options = {}) {
1411
1411
  if (installedTransport !== null) return installedTransport(op, payload);
1412
1412
  const hostOrigin = getHostOrigin();
1413
- return hostOrigin ? rpcBridged(op, payload, hostOrigin) : rpcStandalone(op, payload);
1413
+ return hostOrigin ? rpcBridged(op, payload, hostOrigin, options.holdsCover ?? true) : rpcStandalone(op, payload);
1414
1414
  }
1415
1415
  function getUrlParams() {
1416
1416
  return rpc("urlState.get", {});
@@ -1516,7 +1516,7 @@ function ensureListener() {
1516
1516
  pending.delete(msg.id);
1517
1517
  if (msg.type === "result") handler.resolve(msg.data);
1518
1518
  else handler.reject(new Error(msg.message ?? "RPC failed"));
1519
- if (pending.size === 0) scheduleDrawn(event.origin);
1519
+ if (handler.holdsCover) scheduleDrawn(event.origin);
1520
1520
  return;
1521
1521
  }
1522
1522
  const stream = streaming.get(msg.id);
@@ -1535,31 +1535,49 @@ function ensureListener() {
1535
1535
  });
1536
1536
  }
1537
1537
  var firstRequestSent = false;
1538
- var requestsSent = 0;
1538
+ var coverRequestsSent = 0;
1539
1539
  var drawnPosted = false;
1540
1540
  var drawnScheduled = false;
1541
+ var coverHolds = 0;
1542
+ var coverPendingCount = () => [...pending.values()].filter((one) => one.holdsCover).length;
1541
1543
  function scheduleDrawn(host) {
1542
- if (drawnPosted || drawnScheduled) return;
1544
+ if (drawnPosted || drawnScheduled || coverHolds > 0 || coverPendingCount() > 0) return;
1543
1545
  drawnScheduled = true;
1544
- const sentAtStart = requestsSent;
1546
+ const sentAtStart = coverRequestsSent;
1545
1547
  requestAnimationFrame(
1546
1548
  () => requestAnimationFrame(() => {
1547
1549
  drawnScheduled = false;
1548
- if (pending.size === 0 && requestsSent === sentAtStart) {
1550
+ if (coverHolds > 0 || coverPendingCount() > 0) return;
1551
+ if (coverRequestsSent === sentAtStart) {
1549
1552
  drawnPosted = true;
1550
1553
  window.parent.postMessage({ type: "drawn" }, host);
1551
- } else if (pending.size === 0) {
1554
+ } else {
1552
1555
  scheduleDrawn(host);
1553
1556
  }
1554
1557
  })
1555
1558
  );
1556
1559
  }
1557
- function rpcBridged(op, payload, host) {
1560
+ var outstandingHolds = /* @__PURE__ */ new Set();
1561
+ function holdDrawn() {
1562
+ coverHolds += 1;
1563
+ const release = () => {
1564
+ if (!outstandingHolds.delete(release)) return;
1565
+ coverHolds -= 1;
1566
+ const host = getHostOrigin();
1567
+ if (host) scheduleDrawn(host);
1568
+ };
1569
+ outstandingHolds.add(release);
1570
+ return release;
1571
+ }
1572
+ function releaseAllHolds() {
1573
+ for (const release of [...outstandingHolds]) release();
1574
+ }
1575
+ function rpcBridged(op, payload, host, holdsCover) {
1558
1576
  ensureListener();
1559
1577
  return new Promise((resolve, reject) => {
1560
1578
  const id = nextRpcId++;
1561
- pending.set(id, { resolve, reject });
1562
- requestsSent += 1;
1579
+ pending.set(id, { resolve, reject, holdsCover });
1580
+ if (holdsCover) coverRequestsSent += 1;
1563
1581
  if (firstRequestSent) {
1564
1582
  window.parent.postMessage({ id, op, payload }, host);
1565
1583
  return;
@@ -2158,6 +2176,8 @@ export {
2158
2176
  subscribeOpen,
2159
2177
  postHostNotification,
2160
2178
  subscribeQueriesChanged,
2179
+ holdDrawn,
2180
+ releaseAllHolds,
2161
2181
  rpcAgentRun,
2162
2182
  rpcAgentRunContinue
2163
2183
  };
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export type { ExportNarrowing } from "./shared_types.js";
13
13
  export type { AttachedFile, AttachmentPiles, AttachmentPilesOptions, AttachmentsOptions, AttachmentsState } from "./attachments.js";
14
14
  export { useComments, useCommentCounts } from "./comments.js";
15
15
  export type { AppComment, AppCommentAuthor, AppCommentFile, CommentsState, UseCommentsArgs, CommentCountsState, UseCommentCountsArgs, } from "./comments.js";
16
- export { useAppContext, useViewer, useWorkspaceCurrency, useWorkspaceTimezone } from "./viewer.js";
16
+ export { askAppContext, useAppContext, useViewer, useWorkspaceCurrency, useWorkspaceTimezone } from "./viewer.js";
17
17
  export type { AppAbsence } from "./shared_types.js";
18
18
  export { useOutsideLinks } from "./outside_link.js";
19
19
  export type { OutsideLinksState } from "./outside_link.js";
@@ -22,7 +22,7 @@ export type { UseRecording, UseRecordings } from "./recording.js";
22
22
  export type { RecordingState, RecordingInputs } from "./recording_state.js";
23
23
  export { requestGeofencedLocation, isWithinZone } from "./geolocation.js";
24
24
  export type { GeofenceZone, GeoCoords, GeofenceOutcome, GeofenceOptions } from "./geolocation.js";
25
- export { rpc, hostSpec, isEmbedded, installRpcTransport, openRequested, subscribeOpen } from "./rpc.js";
25
+ export { rpc, hostSpec, holdDrawn, isEmbedded, installRpcTransport, openRequested, subscribeOpen } from "./rpc.js";
26
26
  export type { RpcOp, RpcTransport, HostSpec, AiContextValue, AiContextRecordRef } from "./rpc.js";
27
27
  export { openExternal } from "./open_external.js";
28
28
  export { askAi, type AskAiArgs } from "./ask_ai.js";
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  fixedDecimal,
21
21
  foldDiacritics,
22
22
  getUrlParams,
23
+ holdDrawn,
23
24
  hostSpec,
24
25
  installRpcTransport,
25
26
  isEmbedded,
@@ -39,6 +40,7 @@ import {
39
40
  readRecordingSnapshot,
40
41
  recordingStateOf,
41
42
  recordingsVersion,
43
+ releaseAllHolds,
42
44
  replaceRecordings,
43
45
  roundDecimal,
44
46
  rpc,
@@ -53,7 +55,7 @@ import {
53
55
  subtractDecimal,
54
56
  sumDecimal,
55
57
  urlParam
56
- } from "./chunk-T3BXQAFT.js";
58
+ } from "./chunk-446OTYGZ.js";
57
59
 
58
60
  // src/mount.tsx
59
61
  import { createRoot } from "react-dom/client";
@@ -168,6 +170,7 @@ function installVisibleErrorHandlers(container) {
168
170
  banner.style.cssText = "position: fixed; top: 0; left: 0; right: 0; padding: 12px 16px; background: #fef2f2; color: #991b1b; font: 13px/1.4 monospace; white-space: pre-wrap; border-bottom: 1px solid #fecaca; margin: 0; z-index: 99999;";
169
171
  banner.textContent = message2;
170
172
  container.parentElement?.insertBefore(banner, container);
173
+ releaseAllHolds();
171
174
  };
172
175
  window.addEventListener("error", (e) => {
173
176
  if (e.error !== null && e.error !== void 0) showError(`Uncaught error: ${e.message}
@@ -10770,6 +10773,9 @@ async function readContext() {
10770
10773
  throw cause;
10771
10774
  }
10772
10775
  }
10776
+ function askAppContext() {
10777
+ readKey(APP_CONTEXT_KEY, readContext).catch(() => void 0);
10778
+ }
10773
10779
  function useAppContext() {
10774
10780
  const { data, error, refetch } = useKey(APP_CONTEXT_KEY, readContext, { focus: false, arrival: false });
10775
10781
  return {
@@ -10806,7 +10812,7 @@ function loadModel() {
10806
10812
  if (loaded !== null || hasMockFlag()) return;
10807
10813
  if (modelPromise !== null && (failedAtMs === null || Date.now() - failedAtMs < MODEL_RETRY_MS)) return;
10808
10814
  failedAtMs = null;
10809
- const attempt2 = Promise.all([rpc("write_model", {}), readKey(APP_CONTEXT_KEY, readContext)]).then(([model, context]) => {
10815
+ const attempt2 = Promise.all([rpc("write_model", {}, { holdsCover: false }), readKey(APP_CONTEXT_KEY, readContext)]).then(([model, context]) => {
10810
10816
  loaded = { model, tables: new Map(model.tables.map((table) => [table.id, table])), context };
10811
10817
  for (const { key, alias, askedAt, rows, since } of early.values()) noteAnswer(key, alias, askedAt, rows, since);
10812
10818
  early.clear();
@@ -11110,7 +11116,7 @@ function unpredicted(workflow, cause) {
11110
11116
  }
11111
11117
  function reportMisses(misses) {
11112
11118
  if (misses.length === 0 || hasMockFlag()) return;
11113
- rpc("prediction_miss", { misses: misses.slice(0, PREDICTION_MISSES_MAX) }).catch(
11119
+ rpc("prediction_miss", { misses: misses.slice(0, PREDICTION_MISSES_MAX) }, { holdsCover: false }).catch(
11114
11120
  (cause) => console.warn("Where the app's writes were drawn wrong or not at all could not be reported", cause)
11115
11121
  );
11116
11122
  }
@@ -15450,10 +15456,12 @@ function useFolderPick(table) {
15450
15456
  export {
15451
15457
  PENDING,
15452
15458
  askAi,
15459
+ askAppContext,
15453
15460
  buildChoiceOutput,
15454
15461
  downloadFile,
15455
15462
  exportApp,
15456
15463
  exportQuery,
15464
+ holdDrawn,
15457
15465
  hostSpec,
15458
15466
  installRpcTransport,
15459
15467
  isEmbedded,
package/dist/router.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  setUrlParams,
6
6
  settleOpen,
7
7
  subscribeOpen
8
- } from "./chunk-T3BXQAFT.js";
8
+ } from "./chunk-446OTYGZ.js";
9
9
 
10
10
  // src/router.tsx
11
11
  import { useEffect, useLayoutEffect, useRef } from "react";
package/dist/rpc.d.ts CHANGED
@@ -9,8 +9,8 @@ import { type UrlParams, type UrlParamsPatch } from "./url_params.js";
9
9
  * no credentials. The bridged wire must match `app_frame.tsx`:
10
10
  * app → host: { id, op, payload }, the first also carrying `reportsDrawn: true` and `load` (`AppLoadTiming`) when
11
11
  * the browser states any
12
- * app → host: { type: "drawn" }, once, after the first answer when no request has been in flight for two frames:
13
- * the app's first screen has its data
12
+ * app → host: { type: "drawn" }, once, when no hold (`holdDrawn`) is outstanding, every request that holds the
13
+ * cover is answered and none was sent for two frames: the app's first screen has its data
14
14
  * host → app: { id, type: "result", data } | { id, type: "error", message }
15
15
  */
16
16
  export type RpcOp = "query" | "export" | "field_options" | "workflow" | "agentRuns" | "agentRun.get" | "agentRun.cancel" | "upload" | "file.rename" | "members" | "context" | "spec" | "write_model" | "prediction_miss" | "openExternal" | "askAi" | "urlState.get" | "urlState.set" | "folder.get" | "folder.set" | "comments.list" | "comments.create" | "comments.update" | "comments.delete" | "comments.counts" | "recording.start" | "recording.stop" | "outsideLink.list" | "outsideLink.create" | "outsideLink.revoke";
@@ -99,7 +99,11 @@ export declare function installRpcTransport(transport: RpcTransport): void;
99
99
  export type HostSpec = AppSpec;
100
100
  /** The app's spec, as the host hands it over the bridge. */
101
101
  export declare function hostSpec(): Promise<HostSpec>;
102
- export declare function rpc<T = unknown>(op: RpcOp, payload: unknown): Promise<T>;
102
+ export interface RpcOptions {
103
+ /** False for a request no screen draws from: the host's loading cover does not wait for it. Default true. */
104
+ holdsCover?: boolean;
105
+ }
106
+ export declare function rpc<T = unknown>(op: RpcOp, payload: unknown, options?: RpcOptions): Promise<T>;
103
107
  export declare function getUrlParams(): Promise<UrlParams>;
104
108
  /** A key set to `undefined` is cleared; every other param is kept, and no history entry added. */
105
109
  export declare function setUrlParams(patch: UrlParamsPatch): Promise<void>;
@@ -129,6 +133,13 @@ export declare function registerQueryAlias(alias: string): () => void;
129
133
  * tables a workflow touched.
130
134
  */
131
135
  export declare function notifyLocalWrite(reads?: readonly string[]): void;
136
+ /**
137
+ * Keeps the loading cover up until the returned release runs, for a page that has not yet drawn what its requests will
138
+ * feed. Releasing the last hold starts the two-frame check; releasing again does nothing.
139
+ */
140
+ export declare function holdDrawn(): () => void;
141
+ /** Lifts every hold still outstanding: an error is a screen, drawn as it is, so the cover has nothing left to wait for. */
142
+ export declare function releaseAllHolds(): void;
132
143
  /** Hands each raw SSE chunk to `onText`; `done` settles when the stream ends. */
133
144
  export declare function rpcAgentRun(payload: AgentRunPayload, onText: (chunk: string) => void, onRunId?: (runId: string) => void): AgentRunHandle;
134
145
  export interface AgentRunContinuePayload {
package/dist/viewer.d.ts CHANGED
@@ -3,6 +3,8 @@ import { type AppContext } from "./rpc.js";
3
3
  /** The store key the host's context is held under, read by every screen and by the write model alike. */
4
4
  export declare const APP_CONTEXT_KEY = "app-context";
5
5
  export declare function readContext(): Promise<AppContext>;
6
+ /** Asks the host for its context now, so the screen's later `useAppContext` finds the request already sent. */
7
+ export declare function askAppContext(): void;
6
8
  /**
7
9
  * The host's context, read once and shared. `settled` once it answered or
8
10
  * failed; on `failure` every fact is unknown, so draw the failure rather than
@@ -254,6 +254,8 @@ signed-in member, whether comments are enabled, the workspace's zone and currenc
254
254
  states — `resolved` once it answered, `settled` once it answered OR failed, and `failure` —
255
255
  `{ message, retry }`, `null` unless the read failed. Where it failed every fact is unknown, so a
256
256
  surface that dates or counts by them draws the failure rather than guessing the reader's zone.
257
+ The slot keeps a failed read until `retry` runs. `askAppContext()` asks the host now, so a page that
258
+ mounts later finds the request already sent.
257
259
 
258
260
  `absences` lists who in the organization is away, or will be (`AppAbsence`; one that has ended is left
259
261
  out): the member, the one standing in (`stand_in`), the first and last day (`starts_on`, `ends_on`,
package/docs/runtime.md CHANGED
@@ -159,12 +159,17 @@ results nor observe payloads. A host error with no message rejects as
159
159
 
160
160
  The host covers the app with its loading skeleton until the app's first screen
161
161
  has its data. The SDK says so for you: its first request carries
162
- `reportsDrawn: true`, and once every request is answered and none has been sent
163
- for two animation frames it posts `{ type: "drawn" }` to the host, once per page.
164
- A screen that issues its reads in its first render or effects is covered until
165
- they land; one that starts a read later than two frames after the previous
166
- answers is shown before it, and the host lifts the cover after a bounded time
167
- following the first request.
162
+ `reportsDrawn: true`, and it posts `{ type: "drawn" }` to the host, once per page,
163
+ when every cover-holding request is answered, no hold is outstanding, and none has
164
+ been sent for two animation frames. A request holds the cover unless it is sent
165
+ with `holdsCover: false` (background traffic: the write model, a prediction report).
166
+ `holdDrawn()` returns a release and keeps the cover up until it runs, for a page
167
+ that has not yet drawn what its requests will feed; releasing twice does nothing.
168
+ The SDK releases every hold when it shows an uncaught error or unhandled
169
+ rejection, so an error is drawn rather than covered. A screen that issues its
170
+ reads in its first render or effects is covered until they land; one that starts
171
+ a read later than two frames after the previous answers is shown before it, and
172
+ the host lifts the cover after a bounded time following the first request.
168
173
 
169
174
  **Warning:** a bridged call has **no timeout**. An op the host doesn't
170
175
  implement does reject (`"Unknown RPC op: …"`), but a message the host drops
@@ -243,8 +248,9 @@ const { rows } = await rpc<{ rows: Record<string, unknown>[] }>("query", {
243
248
  });
244
249
  ```
245
250
 
246
- `rpc<T = unknown>(op: RpcOp, payload: unknown): Promise<T>` sends one op over
247
- whichever transport is active. **Prefer the hooks** — they add the SDK's cache,
251
+ `rpc<T = unknown>(op: RpcOp, payload: unknown, options?: { holdsCover?: boolean }): Promise<T>`
252
+ sends one op over whichever transport is active; `holdsCover: false` marks a request no
253
+ screen draws from, which the loading cover does not wait for (default `true`). **Prefer the hooks** — they add the SDK's cache,
248
254
  loading/error state, analytics, and typing from your declared aliases; a file of
249
255
  every row of a set is `exportQuery`, made by the server ([data_fetching](./data_fetching.md)).
250
256
  `rpc()` exists for the imperative cases neither
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.131.11",
3
+ "version": "0.131.12",
4
4
  "description": "The SDK a Lotics custom-code app reads and writes through — typed hooks over the host bridge, cell readers, mount() and AppRouter",
5
5
  "type": "module",
6
6
  "exports": {