@lotics/app-sdk 0.131.10 → 0.131.11
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 +1 -1
- package/dist/{chunk-KKZIOVCD.js → chunk-T3BXQAFT.js} +28 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -3
- package/dist/router.js +34 -3
- package/dist/rpc.d.ts +9 -0
- package/docs/navigation_and_state.md +7 -0
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -21,7 +21,7 @@ This file is the index. The **exact type** of anything is its shipped declaratio
|
|
|
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
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`). |
|
|
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), `useUrlState` + `urlParam` codecs, `useRecents`, `useFolderPick`. |
|
|
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
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. |
|
|
@@ -1433,6 +1433,26 @@ function subscribeUrlParams(cb) {
|
|
|
1433
1433
|
window.addEventListener("popstate", handler);
|
|
1434
1434
|
return () => window.removeEventListener("popstate", handler);
|
|
1435
1435
|
}
|
|
1436
|
+
var OPEN_KEY = "lotics_open";
|
|
1437
|
+
var openTold;
|
|
1438
|
+
var openSubscribers = /* @__PURE__ */ new Set();
|
|
1439
|
+
function openRequested() {
|
|
1440
|
+
if (!isEmbedded()) return false;
|
|
1441
|
+
openTold ??= new URLSearchParams(window.location.search).has(OPEN_KEY);
|
|
1442
|
+
return openTold;
|
|
1443
|
+
}
|
|
1444
|
+
function settleOpen() {
|
|
1445
|
+
openTold = false;
|
|
1446
|
+
}
|
|
1447
|
+
function subscribeOpen(cb) {
|
|
1448
|
+
if (!isEmbedded()) return () => {
|
|
1449
|
+
};
|
|
1450
|
+
ensureListener();
|
|
1451
|
+
openSubscribers.add(cb);
|
|
1452
|
+
return () => {
|
|
1453
|
+
openSubscribers.delete(cb);
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1436
1456
|
function postHostNotification(message) {
|
|
1437
1457
|
const hostOrigin = getHostOrigin();
|
|
1438
1458
|
if (!hostOrigin) return;
|
|
@@ -1468,6 +1488,11 @@ function ensureListener() {
|
|
|
1468
1488
|
for (const cb of urlStateSubscribers) cb(msg.params);
|
|
1469
1489
|
return;
|
|
1470
1490
|
}
|
|
1491
|
+
if (msg.type === "open") {
|
|
1492
|
+
openTold = true;
|
|
1493
|
+
for (const cb of openSubscribers) cb();
|
|
1494
|
+
return;
|
|
1495
|
+
}
|
|
1471
1496
|
if (msg.type === "queriesChanged" && Array.isArray(msg.aliases)) {
|
|
1472
1497
|
const aliases = msg.aliases.filter((a) => typeof a === "string");
|
|
1473
1498
|
for (const cb of refetchSubscribers) cb(aliases);
|
|
@@ -2128,6 +2153,9 @@ export {
|
|
|
2128
2153
|
setUrlParams,
|
|
2129
2154
|
peekUrlParams,
|
|
2130
2155
|
subscribeUrlParams,
|
|
2156
|
+
openRequested,
|
|
2157
|
+
settleOpen,
|
|
2158
|
+
subscribeOpen,
|
|
2131
2159
|
postHostNotification,
|
|
2132
2160
|
subscribeQueriesChanged,
|
|
2133
2161
|
rpcAgentRun,
|
package/dist/index.d.ts
CHANGED
|
@@ -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 } from "./rpc.js";
|
|
25
|
+
export { rpc, hostSpec, 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
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
moduloDecimal,
|
|
31
31
|
multiplyDecimal,
|
|
32
32
|
multiplyExactly,
|
|
33
|
+
openRequested,
|
|
33
34
|
paramsEqual,
|
|
34
35
|
peekUrlParams,
|
|
35
36
|
percentOf,
|
|
@@ -45,13 +46,14 @@ import {
|
|
|
45
46
|
rpcAgentRunContinue,
|
|
46
47
|
searchWords,
|
|
47
48
|
setUrlParams,
|
|
49
|
+
subscribeOpen,
|
|
48
50
|
subscribeQueriesChanged,
|
|
49
51
|
subscribeRecordings,
|
|
50
52
|
subscribeUrlParams,
|
|
51
53
|
subtractDecimal,
|
|
52
54
|
sumDecimal,
|
|
53
55
|
urlParam
|
|
54
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-T3BXQAFT.js";
|
|
55
57
|
|
|
56
58
|
// src/mount.tsx
|
|
57
59
|
import { createRoot } from "react-dom/client";
|
|
@@ -7707,8 +7709,30 @@ var SafeEvalAstFactory = class extends EvalAstFactory {
|
|
|
7707
7709
|
}
|
|
7708
7710
|
};
|
|
7709
7711
|
var astFactory = new SafeEvalAstFactory();
|
|
7712
|
+
function spacedAfterStrings(expression) {
|
|
7713
|
+
let out = "";
|
|
7714
|
+
let quote = null;
|
|
7715
|
+
for (let at2 = 0; at2 < expression.length; at2++) {
|
|
7716
|
+
const ch = expression.charAt(at2);
|
|
7717
|
+
out += ch;
|
|
7718
|
+
if (quote === null) {
|
|
7719
|
+
if (ch === '"' || ch === "'") quote = ch;
|
|
7720
|
+
continue;
|
|
7721
|
+
}
|
|
7722
|
+
if (ch === "\\") {
|
|
7723
|
+
out += expression.charAt(at2 + 1);
|
|
7724
|
+
at2++;
|
|
7725
|
+
continue;
|
|
7726
|
+
}
|
|
7727
|
+
if (ch !== quote) continue;
|
|
7728
|
+
quote = null;
|
|
7729
|
+
const next = expression.charAt(at2 + 1);
|
|
7730
|
+
if (next !== "" && !/\s/.test(next)) out += " ";
|
|
7731
|
+
}
|
|
7732
|
+
return out;
|
|
7733
|
+
}
|
|
7710
7734
|
function parseWholeExpression(expression, astFactory2) {
|
|
7711
|
-
const parser = new Parser(expression, astFactory2);
|
|
7735
|
+
const parser = new Parser(spacedAfterStrings(expression), astFactory2);
|
|
7712
7736
|
const expr2 = parser.parse();
|
|
7713
7737
|
const leftover = parser._token;
|
|
7714
7738
|
if (leftover !== void 0) {
|
|
@@ -10296,7 +10320,7 @@ async function fieldValues(walk, input) {
|
|
|
10296
10320
|
for (const [field, inner] of Object.entries(input)) {
|
|
10297
10321
|
const one = await attempt(walk, inner);
|
|
10298
10322
|
if (one === UNKNOWN) unknown.push(field);
|
|
10299
|
-
else cells[field] = one;
|
|
10323
|
+
else if (one !== void 0) cells[field] = one;
|
|
10300
10324
|
}
|
|
10301
10325
|
return { cells, unknown };
|
|
10302
10326
|
}
|
|
@@ -15437,6 +15461,7 @@ export {
|
|
|
15437
15461
|
mount,
|
|
15438
15462
|
newRecordId,
|
|
15439
15463
|
openExternal,
|
|
15464
|
+
openRequested,
|
|
15440
15465
|
queryAll,
|
|
15441
15466
|
readCreatedAt,
|
|
15442
15467
|
readFiles,
|
|
@@ -15451,6 +15476,7 @@ export {
|
|
|
15451
15476
|
requestGeofencedLocation,
|
|
15452
15477
|
row,
|
|
15453
15478
|
rpc,
|
|
15479
|
+
subscribeOpen,
|
|
15454
15480
|
urlParam,
|
|
15455
15481
|
useAgentRun,
|
|
15456
15482
|
useAgentRuns,
|
package/dist/router.js
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isEmbedded,
|
|
3
|
+
openRequested,
|
|
3
4
|
postHostNotification,
|
|
4
|
-
setUrlParams
|
|
5
|
-
|
|
5
|
+
setUrlParams,
|
|
6
|
+
settleOpen,
|
|
7
|
+
subscribeOpen
|
|
8
|
+
} from "./chunk-T3BXQAFT.js";
|
|
6
9
|
|
|
7
10
|
// src/router.tsx
|
|
8
|
-
import { useEffect } from "react";
|
|
11
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
9
12
|
import {
|
|
10
13
|
BrowserRouter,
|
|
11
14
|
Link,
|
|
12
15
|
matchRoutes,
|
|
13
16
|
useLocation,
|
|
17
|
+
useNavigate,
|
|
14
18
|
useRoutes
|
|
15
19
|
} from "react-router";
|
|
16
20
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
21
|
var LOC_KEY = "_loc";
|
|
18
22
|
var HOST_KEY = "lotics_host";
|
|
23
|
+
var OPEN_KEY = "lotics_open";
|
|
19
24
|
function screenHref(loc) {
|
|
20
25
|
const search = new URLSearchParams(loc.search);
|
|
21
26
|
search.delete(HOST_KEY);
|
|
27
|
+
search.delete(OPEN_KEY);
|
|
22
28
|
const qs = search.toString();
|
|
23
29
|
return loc.pathname + (qs ? `?${qs}` : "") + loc.hash;
|
|
24
30
|
}
|
|
@@ -66,6 +72,30 @@ function HostScreenMirror({ routes, drawers }) {
|
|
|
66
72
|
}, [pathname, openedAt, route]);
|
|
67
73
|
return null;
|
|
68
74
|
}
|
|
75
|
+
function OpenedFromHost() {
|
|
76
|
+
const navigate = useNavigate();
|
|
77
|
+
const { key } = useLocation();
|
|
78
|
+
const standing = useRef({ navigate, key });
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
standing.current = { navigate, key };
|
|
81
|
+
});
|
|
82
|
+
const requestedAt = useRef(null);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const open = () => {
|
|
85
|
+
requestedAt.current = standing.current.key;
|
|
86
|
+
standing.current.navigate({ pathname: "/", search: "" }, { replace: true });
|
|
87
|
+
};
|
|
88
|
+
if (openRequested()) open();
|
|
89
|
+
return subscribeOpen(open);
|
|
90
|
+
}, []);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (requestedAt.current === null || key === requestedAt.current) return;
|
|
93
|
+
requestedAt.current = null;
|
|
94
|
+
settleOpen();
|
|
95
|
+
postHostNotification({ type: "opened" });
|
|
96
|
+
}, [key]);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
69
99
|
function RoutedRoutes({ routes }) {
|
|
70
100
|
return useRoutes(routes);
|
|
71
101
|
}
|
|
@@ -123,6 +153,7 @@ function AppRouter({
|
|
|
123
153
|
/* @__PURE__ */ jsx(NotFoundScreen, { home: firstScreenPath(routes), words: notFound })
|
|
124
154
|
);
|
|
125
155
|
return /* @__PURE__ */ jsxs(BrowserRouter, { children: [
|
|
156
|
+
embedded ? /* @__PURE__ */ jsx(OpenedFromHost, {}) : null,
|
|
126
157
|
embedded ? /* @__PURE__ */ jsx(HostScreenMirror, { routes: claimed, drawers }) : null,
|
|
127
158
|
/* @__PURE__ */ jsx(RoutedRoutes, { routes: claimed })
|
|
128
159
|
] });
|
package/dist/rpc.d.ts
CHANGED
|
@@ -58,6 +58,9 @@ export type HostNotification = {
|
|
|
58
58
|
type: "screen_view";
|
|
59
59
|
/** The route pattern that claims the screen (`/item/:id`), a `+<key>` per drawer open over it; never its address. */
|
|
60
60
|
route: string;
|
|
61
|
+
} | {
|
|
62
|
+
/** The app replaced its screen with its opening address, as the host's `open` asked. */
|
|
63
|
+
type: "opened";
|
|
61
64
|
};
|
|
62
65
|
/** The app's identity: the host's context when bridged, `/by-subdomain` (no member) standalone. */
|
|
63
66
|
export interface AppContext {
|
|
@@ -104,6 +107,12 @@ export declare function setUrlParams(patch: UrlParamsPatch): Promise<void>;
|
|
|
104
107
|
export declare function peekUrlParams(): UrlParams;
|
|
105
108
|
/** Back/forward and edited URLs: the host's `url-state` embedded, `popstate` standalone. */
|
|
106
109
|
export declare function subscribeUrlParams(cb: (params: UrlParams) => void): () => void;
|
|
110
|
+
/** Whether the person has just opened the app and its first screen has not settled yet. */
|
|
111
|
+
export declare function openRequested(): boolean;
|
|
112
|
+
/** The router has moved to the opening address: what mounts from now on is not the open's. */
|
|
113
|
+
export declare function settleOpen(): void;
|
|
114
|
+
/** Calls `cb` each time the host opens the app again while its frame is kept; inert standalone. */
|
|
115
|
+
export declare function subscribeOpen(cb: () => void): () => void;
|
|
107
116
|
/** No-ops standalone. */
|
|
108
117
|
export declare function postHostNotification(message: HostNotification): void;
|
|
109
118
|
/**
|
|
@@ -49,6 +49,13 @@ routes, and splats all work. Inside the tree, use react-router normally:
|
|
|
49
49
|
- **Its own entry.** `AppRouter` ships from `@lotics/app-sdk/router`
|
|
50
50
|
(signature: `dist/router.d.ts`), apart from the hooks; its
|
|
51
51
|
`react-router` peer is `^7 || ^8`.
|
|
52
|
+
- **Opened from the host, an app opens at its opening address, `/`.** When the person opens the app from the host's
|
|
53
|
+
sidebar or apps list, `AppRouter` replaces the entry stood on with `/` and no search, then tells the host with an
|
|
54
|
+
`opened` notification, which forgets the screen and filters it kept for the app; a reload, a shared link and
|
|
55
|
+
Back/Forward do not. A frame whose SDK predates this ignores the request and stays where it was.
|
|
56
|
+
`openRequested()` is true while that first screen mounts (never standalone), for a screen that restores what the
|
|
57
|
+
person left and must not; `subscribeOpen(cb)` calls `cb` each time the host opens the app again while its frame is
|
|
58
|
+
kept, for state the app holds beside the address. Both are exported from `@lotics/app-sdk`.
|
|
52
59
|
- **An address no route claims says so.** `AppRouter` appends a catch-all at
|
|
53
60
|
every level of the tree, so such a path renders a not-found screen — a
|
|
54
61
|
message naming the path and a link to the first route — instead of an empty
|
package/package.json
CHANGED