@lotics/app-sdk 0.131.17 → 0.133.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/AGENTS.md +1 -1
- package/dist/{chunk-6AR7WS7C.js → chunk-J3UN4AJW.js} +232 -166
- package/dist/download.d.ts +9 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +24 -6
- package/dist/router.js +19 -6
- package/dist/rpc.d.ts +67 -8
- package/dist/upload/optimize.d.ts +7 -1
- package/docs/runtime.md +17 -4
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -24,7 +24,7 @@ This file is the index. The **exact type** of anything is its shipped declaratio
|
|
|
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 its `holdsCover` option), `holdDrawn` (keep the host's loading cover up), `
|
|
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), `installPageHost` (a page that is never an app's answers every op, hears its notifications, keeps its address in memory and saves its files through one host: `PageHost`, `queriesChanged` (what a host tells the app when a table moved), `PageHostRefusal`, `saveFileFromUrl`, `ApiRefusal`, `preparedForUpload` with `IMAGE_FIDELITIES`), 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
|
|
|
@@ -4,6 +4,162 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
// src/upload/optimize.ts
|
|
8
|
+
var IMAGE_FIDELITIES = ["original", "high", "standard"];
|
|
9
|
+
var DEFAULT_IMAGE_FIDELITY = "high";
|
|
10
|
+
var IMAGE_POLICIES = {
|
|
11
|
+
standard: { maxDimensionPx: 1280, jpegQuality: 0.8 },
|
|
12
|
+
high: { maxDimensionPx: 1568, jpegQuality: 0.95 }
|
|
13
|
+
};
|
|
14
|
+
var CONVERTIBLE_EXTENSION_PATTERN = /\.(heic|heif|png|webp)$/i;
|
|
15
|
+
async function preparedForUpload(file, fidelity = DEFAULT_IMAGE_FIDELITY) {
|
|
16
|
+
const prepared = await optimizeImageForUpload(file, fidelity).catch((cause) => {
|
|
17
|
+
console.warn(`The image ${file.name} could not be shrunk before its upload; its original bytes are sent.`, cause);
|
|
18
|
+
return void 0;
|
|
19
|
+
});
|
|
20
|
+
return prepared?.file ?? file;
|
|
21
|
+
}
|
|
22
|
+
async function optimizeImageForUpload(file, fidelity = DEFAULT_IMAGE_FIDELITY) {
|
|
23
|
+
if (fidelity === "original") return unchanged(file, "skipped_original");
|
|
24
|
+
const policy = IMAGE_POLICIES[fidelity];
|
|
25
|
+
const format = getOptimizableFormat(file);
|
|
26
|
+
const mimeType = format?.outputMimeType;
|
|
27
|
+
const unsupportedReason = getUnsupportedReason(mimeType);
|
|
28
|
+
if (unsupportedReason) return unchanged(file, unsupportedReason);
|
|
29
|
+
if (!mimeType || !format) return unchanged(file, "skipped_unsupported_format");
|
|
30
|
+
const loaded = await loadImage(file);
|
|
31
|
+
if (loaded.status === "decode_unavailable") return unchanged(file, "skipped_decode_unavailable");
|
|
32
|
+
const { source, width, height } = loaded;
|
|
33
|
+
if (width <= 0 || height <= 0) {
|
|
34
|
+
closeSource(source);
|
|
35
|
+
return unchanged(file, "skipped_invalid_dimensions");
|
|
36
|
+
}
|
|
37
|
+
if (Math.max(width, height) <= policy.maxDimensionPx) {
|
|
38
|
+
closeSource(source);
|
|
39
|
+
return unchanged(file, "skipped_small_dimensions", width, height);
|
|
40
|
+
}
|
|
41
|
+
const { width: targetWidth, height: targetHeight } = scale(width, height, policy.maxDimensionPx);
|
|
42
|
+
const canvas = document.createElement("canvas");
|
|
43
|
+
canvas.width = targetWidth;
|
|
44
|
+
canvas.height = targetHeight;
|
|
45
|
+
const ctx = canvas.getContext("2d");
|
|
46
|
+
if (!ctx || typeof canvas.toBlob !== "function") {
|
|
47
|
+
closeSource(source);
|
|
48
|
+
return unchanged(file, "skipped_canvas_unavailable", width, height);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
ctx.imageSmoothingEnabled = true;
|
|
52
|
+
ctx.imageSmoothingQuality = "high";
|
|
53
|
+
ctx.drawImage(source, 0, 0, targetWidth, targetHeight);
|
|
54
|
+
} finally {
|
|
55
|
+
closeSource(source);
|
|
56
|
+
}
|
|
57
|
+
const blob = await canvasToBlob(canvas, mimeType, policy.jpegQuality);
|
|
58
|
+
if (blob === null) return unchanged(file, "skipped_canvas_no_data", width, height, targetWidth, targetHeight);
|
|
59
|
+
if (blob.type !== mimeType) {
|
|
60
|
+
return unchanged(file, "skipped_canvas_type_mismatch", width, height, targetWidth, targetHeight);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
file: new File([blob], format.outputFilename, {
|
|
64
|
+
type: mimeType,
|
|
65
|
+
lastModified: file.lastModified
|
|
66
|
+
}),
|
|
67
|
+
optimized: true,
|
|
68
|
+
reason: "optimized",
|
|
69
|
+
originalSizeBytes: file.size,
|
|
70
|
+
optimizedSizeBytes: blob.size,
|
|
71
|
+
width,
|
|
72
|
+
height,
|
|
73
|
+
targetWidth,
|
|
74
|
+
targetHeight
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function getUnsupportedReason(mimeType) {
|
|
78
|
+
if (mimeType === void 0) return "skipped_unsupported_format";
|
|
79
|
+
if (typeof window === "undefined" || typeof document === "undefined" || typeof document.createElement !== "function" || typeof URL.createObjectURL !== "function" || typeof URL.revokeObjectURL !== "function" || typeof Image === "undefined") {
|
|
80
|
+
return "skipped_environment_unsupported";
|
|
81
|
+
}
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
function getOptimizableFormat(file) {
|
|
85
|
+
const mimeType = normalizeMimeType(file.type);
|
|
86
|
+
if (!mimeType) return void 0;
|
|
87
|
+
if (mimeType === "image/jpeg") {
|
|
88
|
+
return { outputMimeType: "image/jpeg", outputFilename: file.name };
|
|
89
|
+
}
|
|
90
|
+
return { outputMimeType: "image/jpeg", outputFilename: replaceExtensionWithJpeg(file.name) };
|
|
91
|
+
}
|
|
92
|
+
function normalizeMimeType(mimeType) {
|
|
93
|
+
const m = mimeType.toLowerCase();
|
|
94
|
+
if (m === "image/jpeg" || m === "image/jpg") return "image/jpeg";
|
|
95
|
+
if (m === "image/heic" || m === "image/heif") return m;
|
|
96
|
+
if (m === "image/png" || m === "image/webp") return m;
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
function replaceExtensionWithJpeg(filename) {
|
|
100
|
+
if (CONVERTIBLE_EXTENSION_PATTERN.test(filename)) {
|
|
101
|
+
return filename.replace(CONVERTIBLE_EXTENSION_PATTERN, ".jpg");
|
|
102
|
+
}
|
|
103
|
+
return `${filename}.jpg`;
|
|
104
|
+
}
|
|
105
|
+
function unchanged(file, reason, width = 0, height = 0, targetWidth = width, targetHeight = height) {
|
|
106
|
+
return {
|
|
107
|
+
file,
|
|
108
|
+
optimized: false,
|
|
109
|
+
reason,
|
|
110
|
+
originalSizeBytes: file.size,
|
|
111
|
+
optimizedSizeBytes: file.size,
|
|
112
|
+
width,
|
|
113
|
+
height,
|
|
114
|
+
targetWidth,
|
|
115
|
+
targetHeight
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function closeSource(source) {
|
|
119
|
+
if ("close" in source && typeof source.close === "function") source.close();
|
|
120
|
+
}
|
|
121
|
+
function scale(width, height, maxDimensionPx) {
|
|
122
|
+
const largest = Math.max(width, height);
|
|
123
|
+
if (largest <= maxDimensionPx) return { width, height };
|
|
124
|
+
const factor = maxDimensionPx / largest;
|
|
125
|
+
return {
|
|
126
|
+
width: Math.max(1, Math.round(width * factor)),
|
|
127
|
+
height: Math.max(1, Math.round(height * factor))
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async function loadImage(file) {
|
|
131
|
+
if (typeof createImageBitmap === "function") {
|
|
132
|
+
try {
|
|
133
|
+
const bitmap = await createImageBitmap(file);
|
|
134
|
+
return { status: "decoded", source: bitmap, width: bitmap.width, height: bitmap.height };
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const objectUrl = URL.createObjectURL(file);
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
const image = new Image();
|
|
141
|
+
const cleanup = () => {
|
|
142
|
+
image.onload = null;
|
|
143
|
+
image.onerror = null;
|
|
144
|
+
URL.revokeObjectURL(objectUrl);
|
|
145
|
+
};
|
|
146
|
+
image.onload = () => {
|
|
147
|
+
cleanup();
|
|
148
|
+
resolve({ status: "decoded", source: image, width: image.naturalWidth, height: image.naturalHeight });
|
|
149
|
+
};
|
|
150
|
+
image.onerror = () => {
|
|
151
|
+
cleanup();
|
|
152
|
+
resolve({ status: "decode_unavailable" });
|
|
153
|
+
};
|
|
154
|
+
image.src = objectUrl;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async function canvasToBlob(canvas, mimeType, jpegQuality) {
|
|
158
|
+
return new Promise((resolve) => {
|
|
159
|
+
canvas.toBlob(resolve, mimeType, jpegQuality);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
7
163
|
// src/url_params.ts
|
|
8
164
|
function first(raw) {
|
|
9
165
|
return Array.isArray(raw) ? raw[0] : raw;
|
|
@@ -1050,154 +1206,6 @@ function measureLoadTiming(sentAt) {
|
|
|
1050
1206
|
};
|
|
1051
1207
|
}
|
|
1052
1208
|
|
|
1053
|
-
// src/upload/optimize.ts
|
|
1054
|
-
var DEFAULT_IMAGE_FIDELITY = "high";
|
|
1055
|
-
var IMAGE_POLICIES = {
|
|
1056
|
-
standard: { maxDimensionPx: 1280, jpegQuality: 0.8 },
|
|
1057
|
-
high: { maxDimensionPx: 1568, jpegQuality: 0.95 }
|
|
1058
|
-
};
|
|
1059
|
-
var CONVERTIBLE_EXTENSION_PATTERN = /\.(heic|heif|png|webp)$/i;
|
|
1060
|
-
async function optimizeImageForUpload(file, fidelity = DEFAULT_IMAGE_FIDELITY) {
|
|
1061
|
-
if (fidelity === "original") return unchanged(file, "skipped_original");
|
|
1062
|
-
const policy = IMAGE_POLICIES[fidelity];
|
|
1063
|
-
const format = getOptimizableFormat(file);
|
|
1064
|
-
const mimeType = format?.outputMimeType;
|
|
1065
|
-
const unsupportedReason = getUnsupportedReason(mimeType);
|
|
1066
|
-
if (unsupportedReason) return unchanged(file, unsupportedReason);
|
|
1067
|
-
if (!mimeType || !format) return unchanged(file, "skipped_unsupported_format");
|
|
1068
|
-
const loaded = await loadImage(file);
|
|
1069
|
-
if (loaded.status === "decode_unavailable") return unchanged(file, "skipped_decode_unavailable");
|
|
1070
|
-
const { source, width, height } = loaded;
|
|
1071
|
-
if (width <= 0 || height <= 0) {
|
|
1072
|
-
closeSource(source);
|
|
1073
|
-
return unchanged(file, "skipped_invalid_dimensions");
|
|
1074
|
-
}
|
|
1075
|
-
if (Math.max(width, height) <= policy.maxDimensionPx) {
|
|
1076
|
-
closeSource(source);
|
|
1077
|
-
return unchanged(file, "skipped_small_dimensions", width, height);
|
|
1078
|
-
}
|
|
1079
|
-
const { width: targetWidth, height: targetHeight } = scale(width, height, policy.maxDimensionPx);
|
|
1080
|
-
const canvas = document.createElement("canvas");
|
|
1081
|
-
canvas.width = targetWidth;
|
|
1082
|
-
canvas.height = targetHeight;
|
|
1083
|
-
const ctx = canvas.getContext("2d");
|
|
1084
|
-
if (!ctx || typeof canvas.toBlob !== "function") {
|
|
1085
|
-
closeSource(source);
|
|
1086
|
-
return unchanged(file, "skipped_canvas_unavailable", width, height);
|
|
1087
|
-
}
|
|
1088
|
-
try {
|
|
1089
|
-
ctx.imageSmoothingEnabled = true;
|
|
1090
|
-
ctx.imageSmoothingQuality = "high";
|
|
1091
|
-
ctx.drawImage(source, 0, 0, targetWidth, targetHeight);
|
|
1092
|
-
} finally {
|
|
1093
|
-
closeSource(source);
|
|
1094
|
-
}
|
|
1095
|
-
const blob = await canvasToBlob(canvas, mimeType, policy.jpegQuality);
|
|
1096
|
-
if (blob === null) return unchanged(file, "skipped_canvas_no_data", width, height, targetWidth, targetHeight);
|
|
1097
|
-
if (blob.type !== mimeType) {
|
|
1098
|
-
return unchanged(file, "skipped_canvas_type_mismatch", width, height, targetWidth, targetHeight);
|
|
1099
|
-
}
|
|
1100
|
-
return {
|
|
1101
|
-
file: new File([blob], format.outputFilename, {
|
|
1102
|
-
type: mimeType,
|
|
1103
|
-
lastModified: file.lastModified
|
|
1104
|
-
}),
|
|
1105
|
-
optimized: true,
|
|
1106
|
-
reason: "optimized",
|
|
1107
|
-
originalSizeBytes: file.size,
|
|
1108
|
-
optimizedSizeBytes: blob.size,
|
|
1109
|
-
width,
|
|
1110
|
-
height,
|
|
1111
|
-
targetWidth,
|
|
1112
|
-
targetHeight
|
|
1113
|
-
};
|
|
1114
|
-
}
|
|
1115
|
-
function getUnsupportedReason(mimeType) {
|
|
1116
|
-
if (mimeType === void 0) return "skipped_unsupported_format";
|
|
1117
|
-
if (typeof window === "undefined" || typeof document === "undefined" || typeof document.createElement !== "function" || typeof URL.createObjectURL !== "function" || typeof URL.revokeObjectURL !== "function" || typeof Image === "undefined") {
|
|
1118
|
-
return "skipped_environment_unsupported";
|
|
1119
|
-
}
|
|
1120
|
-
return void 0;
|
|
1121
|
-
}
|
|
1122
|
-
function getOptimizableFormat(file) {
|
|
1123
|
-
const mimeType = normalizeMimeType(file.type);
|
|
1124
|
-
if (!mimeType) return void 0;
|
|
1125
|
-
if (mimeType === "image/jpeg") {
|
|
1126
|
-
return { outputMimeType: "image/jpeg", outputFilename: file.name };
|
|
1127
|
-
}
|
|
1128
|
-
return { outputMimeType: "image/jpeg", outputFilename: replaceExtensionWithJpeg(file.name) };
|
|
1129
|
-
}
|
|
1130
|
-
function normalizeMimeType(mimeType) {
|
|
1131
|
-
const m = mimeType.toLowerCase();
|
|
1132
|
-
if (m === "image/jpeg" || m === "image/jpg") return "image/jpeg";
|
|
1133
|
-
if (m === "image/heic" || m === "image/heif") return m;
|
|
1134
|
-
if (m === "image/png" || m === "image/webp") return m;
|
|
1135
|
-
return void 0;
|
|
1136
|
-
}
|
|
1137
|
-
function replaceExtensionWithJpeg(filename) {
|
|
1138
|
-
if (CONVERTIBLE_EXTENSION_PATTERN.test(filename)) {
|
|
1139
|
-
return filename.replace(CONVERTIBLE_EXTENSION_PATTERN, ".jpg");
|
|
1140
|
-
}
|
|
1141
|
-
return `${filename}.jpg`;
|
|
1142
|
-
}
|
|
1143
|
-
function unchanged(file, reason, width = 0, height = 0, targetWidth = width, targetHeight = height) {
|
|
1144
|
-
return {
|
|
1145
|
-
file,
|
|
1146
|
-
optimized: false,
|
|
1147
|
-
reason,
|
|
1148
|
-
originalSizeBytes: file.size,
|
|
1149
|
-
optimizedSizeBytes: file.size,
|
|
1150
|
-
width,
|
|
1151
|
-
height,
|
|
1152
|
-
targetWidth,
|
|
1153
|
-
targetHeight
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
function closeSource(source) {
|
|
1157
|
-
if ("close" in source && typeof source.close === "function") source.close();
|
|
1158
|
-
}
|
|
1159
|
-
function scale(width, height, maxDimensionPx) {
|
|
1160
|
-
const largest = Math.max(width, height);
|
|
1161
|
-
if (largest <= maxDimensionPx) return { width, height };
|
|
1162
|
-
const factor = maxDimensionPx / largest;
|
|
1163
|
-
return {
|
|
1164
|
-
width: Math.max(1, Math.round(width * factor)),
|
|
1165
|
-
height: Math.max(1, Math.round(height * factor))
|
|
1166
|
-
};
|
|
1167
|
-
}
|
|
1168
|
-
async function loadImage(file) {
|
|
1169
|
-
if (typeof createImageBitmap === "function") {
|
|
1170
|
-
try {
|
|
1171
|
-
const bitmap = await createImageBitmap(file);
|
|
1172
|
-
return { status: "decoded", source: bitmap, width: bitmap.width, height: bitmap.height };
|
|
1173
|
-
} catch {
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
const objectUrl = URL.createObjectURL(file);
|
|
1177
|
-
return new Promise((resolve) => {
|
|
1178
|
-
const image = new Image();
|
|
1179
|
-
const cleanup = () => {
|
|
1180
|
-
image.onload = null;
|
|
1181
|
-
image.onerror = null;
|
|
1182
|
-
URL.revokeObjectURL(objectUrl);
|
|
1183
|
-
};
|
|
1184
|
-
image.onload = () => {
|
|
1185
|
-
cleanup();
|
|
1186
|
-
resolve({ status: "decoded", source: image, width: image.naturalWidth, height: image.naturalHeight });
|
|
1187
|
-
};
|
|
1188
|
-
image.onerror = () => {
|
|
1189
|
-
cleanup();
|
|
1190
|
-
resolve({ status: "decode_unavailable" });
|
|
1191
|
-
};
|
|
1192
|
-
image.src = objectUrl;
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
async function canvasToBlob(canvas, mimeType, jpegQuality) {
|
|
1196
|
-
return new Promise((resolve) => {
|
|
1197
|
-
canvas.toBlob(resolve, mimeType, jpegQuality);
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
1209
|
// src/upload/transport.ts
|
|
1202
1210
|
var UPLOAD_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
1203
1211
|
var UPLOAD_PUT_MAX_ATTEMPTS = 3;
|
|
@@ -1400,15 +1408,25 @@ function getHostOrigin() {
|
|
|
1400
1408
|
function isEmbedded() {
|
|
1401
1409
|
return Boolean(getHostOrigin());
|
|
1402
1410
|
}
|
|
1403
|
-
var
|
|
1404
|
-
|
|
1405
|
-
|
|
1411
|
+
var PageHostRefusal = class extends Error {
|
|
1412
|
+
name = "PageHostRefusal";
|
|
1413
|
+
telemetryMessage = "The page's host was asked for something it does not carry.";
|
|
1414
|
+
};
|
|
1415
|
+
var installedHost = null;
|
|
1416
|
+
function installPageHost(host) {
|
|
1417
|
+
installedHost = host;
|
|
1418
|
+
}
|
|
1419
|
+
function pageAddress() {
|
|
1420
|
+
return installedHost?.address;
|
|
1421
|
+
}
|
|
1422
|
+
function pageSave() {
|
|
1423
|
+
return installedHost?.save;
|
|
1406
1424
|
}
|
|
1407
1425
|
function hostSpec() {
|
|
1408
1426
|
return rpc("spec", {});
|
|
1409
1427
|
}
|
|
1410
1428
|
function rpc(op, payload, options = {}) {
|
|
1411
|
-
if (
|
|
1429
|
+
if (installedHost !== null) return rpcPageHost(installedHost, op, payload, options.holdsCover ?? true);
|
|
1412
1430
|
const hostOrigin = getHostOrigin();
|
|
1413
1431
|
return hostOrigin ? rpcBridged(op, payload, hostOrigin, options.holdsCover ?? true) : rpcStandalone(op, payload);
|
|
1414
1432
|
}
|
|
@@ -1419,9 +1437,11 @@ function setUrlParams(patch) {
|
|
|
1419
1437
|
return rpc("urlState.set", { params: patch });
|
|
1420
1438
|
}
|
|
1421
1439
|
function peekUrlParams() {
|
|
1422
|
-
return isEmbedded() ? {} : parseSearch(window.location.search);
|
|
1440
|
+
return isEmbedded() || installedHost !== null ? {} : parseSearch(window.location.search);
|
|
1423
1441
|
}
|
|
1424
1442
|
function subscribeUrlParams(cb) {
|
|
1443
|
+
if (installedHost !== null) return () => {
|
|
1444
|
+
};
|
|
1425
1445
|
if (isEmbedded()) {
|
|
1426
1446
|
ensureListener();
|
|
1427
1447
|
urlStateSubscribers.add(cb);
|
|
@@ -1454,6 +1474,10 @@ function subscribeOpen(cb) {
|
|
|
1454
1474
|
};
|
|
1455
1475
|
}
|
|
1456
1476
|
function postHostNotification(message) {
|
|
1477
|
+
if (installedHost !== null) {
|
|
1478
|
+
installedHost.notify?.(message);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1457
1481
|
const hostOrigin = getHostOrigin();
|
|
1458
1482
|
if (!hostOrigin) return;
|
|
1459
1483
|
window.parent.postMessage(message, hostOrigin);
|
|
@@ -1469,7 +1493,10 @@ var mountedAliases = /* @__PURE__ */ new Map();
|
|
|
1469
1493
|
function notifyLocalWrite(reads) {
|
|
1470
1494
|
const aliases = reads === void 0 ? [...mountedAliases.keys()] : [...reads];
|
|
1471
1495
|
if (aliases.length === 0) return;
|
|
1472
|
-
|
|
1496
|
+
queriesChanged(aliases);
|
|
1497
|
+
}
|
|
1498
|
+
function queriesChanged(aliases) {
|
|
1499
|
+
for (const cb of refetchSubscribers) cb([...aliases]);
|
|
1473
1500
|
}
|
|
1474
1501
|
var pending = /* @__PURE__ */ new Map();
|
|
1475
1502
|
var streaming = /* @__PURE__ */ new Map();
|
|
@@ -1494,8 +1521,7 @@ function ensureListener() {
|
|
|
1494
1521
|
return;
|
|
1495
1522
|
}
|
|
1496
1523
|
if (msg.type === "queriesChanged" && Array.isArray(msg.aliases)) {
|
|
1497
|
-
|
|
1498
|
-
for (const cb of refetchSubscribers) cb(aliases);
|
|
1524
|
+
queriesChanged(msg.aliases.filter((a) => typeof a === "string"));
|
|
1499
1525
|
return;
|
|
1500
1526
|
}
|
|
1501
1527
|
if (msg.type === "recordingChanged") {
|
|
@@ -1516,7 +1542,7 @@ function ensureListener() {
|
|
|
1516
1542
|
pending.delete(msg.id);
|
|
1517
1543
|
if (msg.type === "result") handler.resolve(msg.data);
|
|
1518
1544
|
else handler.reject(new Error(msg.message ?? "RPC failed"));
|
|
1519
|
-
if (handler.holdsCover) scheduleDrawn(
|
|
1545
|
+
if (handler.holdsCover) scheduleDrawn();
|
|
1520
1546
|
return;
|
|
1521
1547
|
}
|
|
1522
1548
|
const stream = streaming.get(msg.id);
|
|
@@ -1539,9 +1565,19 @@ var coverRequestsSent = 0;
|
|
|
1539
1565
|
var drawnPosted = false;
|
|
1540
1566
|
var drawnScheduled = false;
|
|
1541
1567
|
var coverHolds = 0;
|
|
1542
|
-
var
|
|
1543
|
-
|
|
1544
|
-
|
|
1568
|
+
var pageHostCoverPending = 0;
|
|
1569
|
+
var coverPendingCount = () => pageHostCoverPending + [...pending.values()].filter((one) => one.holdsCover).length;
|
|
1570
|
+
function drawnSink() {
|
|
1571
|
+
if (installedHost !== null) {
|
|
1572
|
+
const { notify } = installedHost;
|
|
1573
|
+
return notify === void 0 ? null : () => notify({ type: "drawn" });
|
|
1574
|
+
}
|
|
1575
|
+
const host = getHostOrigin();
|
|
1576
|
+
return host ? () => window.parent.postMessage({ type: "drawn" }, host) : null;
|
|
1577
|
+
}
|
|
1578
|
+
function scheduleDrawn() {
|
|
1579
|
+
const post = drawnSink();
|
|
1580
|
+
if (post === null || drawnPosted || drawnScheduled || coverHolds > 0 || coverPendingCount() > 0) return;
|
|
1545
1581
|
drawnScheduled = true;
|
|
1546
1582
|
const sentAtStart = coverRequestsSent;
|
|
1547
1583
|
requestAnimationFrame(
|
|
@@ -1550,9 +1586,9 @@ function scheduleDrawn(host) {
|
|
|
1550
1586
|
if (coverHolds > 0 || coverPendingCount() > 0) return;
|
|
1551
1587
|
if (coverRequestsSent === sentAtStart) {
|
|
1552
1588
|
drawnPosted = true;
|
|
1553
|
-
|
|
1589
|
+
post();
|
|
1554
1590
|
} else {
|
|
1555
|
-
scheduleDrawn(
|
|
1591
|
+
scheduleDrawn();
|
|
1556
1592
|
}
|
|
1557
1593
|
})
|
|
1558
1594
|
);
|
|
@@ -1563,8 +1599,7 @@ function holdDrawn() {
|
|
|
1563
1599
|
const release = () => {
|
|
1564
1600
|
if (!outstandingHolds.delete(release)) return;
|
|
1565
1601
|
coverHolds -= 1;
|
|
1566
|
-
|
|
1567
|
-
if (host) scheduleDrawn(host);
|
|
1602
|
+
scheduleDrawn();
|
|
1568
1603
|
};
|
|
1569
1604
|
outstandingHolds.add(release);
|
|
1570
1605
|
return release;
|
|
@@ -1572,6 +1607,16 @@ function holdDrawn() {
|
|
|
1572
1607
|
function releaseAllHolds() {
|
|
1573
1608
|
for (const release of [...outstandingHolds]) release();
|
|
1574
1609
|
}
|
|
1610
|
+
function rpcPageHost(host, op, payload, holdsCover) {
|
|
1611
|
+
if (!holdsCover) return host.transport(op, payload);
|
|
1612
|
+
pageHostCoverPending += 1;
|
|
1613
|
+
coverRequestsSent += 1;
|
|
1614
|
+
const settled2 = () => {
|
|
1615
|
+
pageHostCoverPending -= 1;
|
|
1616
|
+
scheduleDrawn();
|
|
1617
|
+
};
|
|
1618
|
+
return host.transport(op, payload).finally(settled2);
|
|
1619
|
+
}
|
|
1575
1620
|
function rpcBridged(op, payload, host, holdsCover) {
|
|
1576
1621
|
ensureListener();
|
|
1577
1622
|
return new Promise((resolve, reject) => {
|
|
@@ -1589,9 +1634,17 @@ function rpcBridged(op, payload, host, holdsCover) {
|
|
|
1589
1634
|
});
|
|
1590
1635
|
}
|
|
1591
1636
|
function rpcAgentRun(payload, onText, onRunId) {
|
|
1637
|
+
if (installedHost !== null) return agentRunPageHost(installedHost, { op: "agentRun", payload }, { onText, ...onRunId === void 0 ? {} : { onRunId } });
|
|
1592
1638
|
const hostOrigin = getHostOrigin();
|
|
1593
1639
|
return hostOrigin ? agentRunBridged(payload, onText, hostOrigin, onRunId) : agentRunStandalone(payload, onText, onRunId);
|
|
1594
1640
|
}
|
|
1641
|
+
function agentRunPageHost(host, run, stream) {
|
|
1642
|
+
if (host.agentRun === void 0) {
|
|
1643
|
+
return { done: Promise.reject(new PageHostRefusal("This page's host runs no app agent.")), abort: () => {
|
|
1644
|
+
} };
|
|
1645
|
+
}
|
|
1646
|
+
return host.agentRun(run, stream);
|
|
1647
|
+
}
|
|
1595
1648
|
function agentRunBridged(payload, onText, host, onRunId) {
|
|
1596
1649
|
ensureListener();
|
|
1597
1650
|
const id = nextRpcId++;
|
|
@@ -1613,6 +1666,7 @@ function agentRunBridged(payload, onText, host, onRunId) {
|
|
|
1613
1666
|
};
|
|
1614
1667
|
}
|
|
1615
1668
|
function rpcAgentRunContinue(payload, onText) {
|
|
1669
|
+
if (installedHost !== null) return agentRunPageHost(installedHost, { op: "agentRunContinue", payload }, { onText });
|
|
1616
1670
|
const hostOrigin = getHostOrigin();
|
|
1617
1671
|
if (hostOrigin) {
|
|
1618
1672
|
ensureListener();
|
|
@@ -1778,11 +1832,16 @@ async function boot() {
|
|
|
1778
1832
|
var ApiRefusal = class extends Error {
|
|
1779
1833
|
constructor(status, parsed, field_errors) {
|
|
1780
1834
|
super(transportErrorMessage(status, parsed));
|
|
1835
|
+
this.status = status;
|
|
1781
1836
|
this.field_errors = field_errors;
|
|
1782
1837
|
this.telemetryMessage = telemetryErrorMessage(status, parsed);
|
|
1838
|
+
this.code = parsed !== null && typeof parsed === "object" && "code" in parsed && typeof parsed.code === "string" && parsed.code !== "" ? parsed.code : null;
|
|
1783
1839
|
}
|
|
1840
|
+
status;
|
|
1784
1841
|
field_errors;
|
|
1785
1842
|
telemetryMessage;
|
|
1843
|
+
/** The envelope's `code`, the one field a caller may branch on; `null` where the body is not the API's. */
|
|
1844
|
+
code;
|
|
1786
1845
|
};
|
|
1787
1846
|
function readFieldErrors(parsed) {
|
|
1788
1847
|
if (parsed === null || typeof parsed !== "object" || !("field_errors" in parsed)) {
|
|
@@ -2153,7 +2212,9 @@ export {
|
|
|
2153
2212
|
AGGREGATE_COUNT_COLUMN,
|
|
2154
2213
|
AGGREGATE_SUM_COLUMN,
|
|
2155
2214
|
aggregateRows,
|
|
2215
|
+
IMAGE_FIDELITIES,
|
|
2156
2216
|
DEFAULT_IMAGE_FIDELITY,
|
|
2217
|
+
preparedForUpload,
|
|
2157
2218
|
recordingsVersion,
|
|
2158
2219
|
subscribeRecordings,
|
|
2159
2220
|
recordingStateOf,
|
|
@@ -2166,7 +2227,10 @@ export {
|
|
|
2166
2227
|
applyPatch,
|
|
2167
2228
|
paramsEqual,
|
|
2168
2229
|
isEmbedded,
|
|
2169
|
-
|
|
2230
|
+
PageHostRefusal,
|
|
2231
|
+
installPageHost,
|
|
2232
|
+
pageAddress,
|
|
2233
|
+
pageSave,
|
|
2170
2234
|
hostSpec,
|
|
2171
2235
|
rpc,
|
|
2172
2236
|
getUrlParams,
|
|
@@ -2178,8 +2242,10 @@ export {
|
|
|
2178
2242
|
subscribeOpen,
|
|
2179
2243
|
postHostNotification,
|
|
2180
2244
|
subscribeQueriesChanged,
|
|
2245
|
+
queriesChanged,
|
|
2181
2246
|
holdDrawn,
|
|
2182
2247
|
releaseAllHolds,
|
|
2183
2248
|
rpcAgentRun,
|
|
2184
|
-
rpcAgentRunContinue
|
|
2249
|
+
rpcAgentRunContinue,
|
|
2250
|
+
ApiRefusal
|
|
2185
2251
|
};
|
package/dist/download.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
1
|
export declare function downloadFile(filename: string, data: Uint8Array | Blob | string, mimeType?: string): void;
|
|
2
|
+
/**
|
|
3
|
+
* Save a file the server made, by its link: through the page's host where it saves files itself (a view an assistant's
|
|
4
|
+
* host frames drops a download the page starts), else with `download` — `downloadFileFromUrl` from
|
|
5
|
+
* `@lotics/ui/download`, which this package cannot import.
|
|
6
|
+
*/
|
|
7
|
+
export declare function saveFileFromUrl(file: {
|
|
8
|
+
url: string;
|
|
9
|
+
filename: string;
|
|
10
|
+
}, download: (url: string, filename: string) => Promise<unknown>): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -22,11 +22,12 @@ 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, holdDrawn, isEmbedded,
|
|
26
|
-
export type { RpcOp, RpcTransport, HostSpec, AiContextValue, AiContextRecordRef } from "./rpc.js";
|
|
25
|
+
export { rpc, hostSpec, holdDrawn, isEmbedded, installPageHost, openRequested, subscribeOpen, queriesChanged, ApiRefusal, PageHostRefusal } from "./rpc.js";
|
|
26
|
+
export type { RpcOp, RpcTransport, HostSpec, AiContextValue, AiContextRecordRef, PageHost, PageAgentRun, PageAgentRunStream, HostNotification, AgentRunHandle, AgentRunPayload, AgentRunContinuePayload } from "./rpc.js";
|
|
27
27
|
export { openExternal } from "./open_external.js";
|
|
28
28
|
export { askAi, type AskAiArgs } from "./ask_ai.js";
|
|
29
|
-
export { downloadFile } from "./download.js";
|
|
29
|
+
export { downloadFile, saveFileFromUrl } from "./download.js";
|
|
30
|
+
export { preparedForUpload, IMAGE_FIDELITIES, type ImageFidelity } from "./upload/optimize.js";
|
|
30
31
|
export { renameFile } from "./rename_file.js";
|
|
31
32
|
export { readFiles, readMembers, readSelect } from "./shared_types.js";
|
|
32
33
|
export type { AppFile, PhotoPlace, ResolvedMember, ResolvedOption } from "./shared_types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AGGREGATE_COUNT_COLUMN,
|
|
3
3
|
AGGREGATE_SUM_COLUMN,
|
|
4
|
+
ApiRefusal,
|
|
4
5
|
COMPARE_KEYS,
|
|
5
6
|
DEFAULT_IMAGE_FIDELITY,
|
|
7
|
+
IMAGE_FIDELITIES,
|
|
8
|
+
PageHostRefusal,
|
|
6
9
|
WEEKDAYS,
|
|
7
10
|
__export,
|
|
8
11
|
addDecimal,
|
|
@@ -22,7 +25,7 @@ import {
|
|
|
22
25
|
getUrlParams,
|
|
23
26
|
holdDrawn,
|
|
24
27
|
hostSpec,
|
|
25
|
-
|
|
28
|
+
installPageHost,
|
|
26
29
|
isEmbedded,
|
|
27
30
|
isFieldKey,
|
|
28
31
|
isRecordBound,
|
|
@@ -32,11 +35,14 @@ import {
|
|
|
32
35
|
multiplyDecimal,
|
|
33
36
|
multiplyExactly,
|
|
34
37
|
openRequested,
|
|
38
|
+
pageSave,
|
|
35
39
|
paramsEqual,
|
|
36
40
|
peekUrlParams,
|
|
37
41
|
percentOf,
|
|
38
42
|
postHostNotification,
|
|
39
43
|
powerDecimal,
|
|
44
|
+
preparedForUpload,
|
|
45
|
+
queriesChanged,
|
|
40
46
|
readRecordingSnapshot,
|
|
41
47
|
recordingStateOf,
|
|
42
48
|
recordingsVersion,
|
|
@@ -55,7 +61,7 @@ import {
|
|
|
55
61
|
subtractDecimal,
|
|
56
62
|
sumDecimal,
|
|
57
63
|
urlParam
|
|
58
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-J3UN4AJW.js";
|
|
59
65
|
|
|
60
66
|
// src/mount.tsx
|
|
61
67
|
import { createRoot } from "react-dom/client";
|
|
@@ -173,9 +179,10 @@ function installVisibleErrorHandlers(container) {
|
|
|
173
179
|
releaseAllHolds();
|
|
174
180
|
};
|
|
175
181
|
window.addEventListener("error", (e) => {
|
|
176
|
-
if (e.error
|
|
177
|
-
${e.
|
|
178
|
-
|
|
182
|
+
if (e.error === null || e.error === void 0) return;
|
|
183
|
+
showError(`Uncaught error: ${e.message}
|
|
184
|
+
${e.error instanceof Error ? e.error.stack ?? "" : String(e.error)}`);
|
|
185
|
+
reportAppError("uncaught", e.error);
|
|
179
186
|
});
|
|
180
187
|
window.addEventListener("unhandledrejection", (e) => {
|
|
181
188
|
const reason = e.reason instanceof Error ? `${e.reason.message}
|
|
@@ -15357,6 +15364,11 @@ function downloadFile(filename, data, mimeType) {
|
|
|
15357
15364
|
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
15358
15365
|
}
|
|
15359
15366
|
}
|
|
15367
|
+
async function saveFileFromUrl(file, download) {
|
|
15368
|
+
const save = pageSave();
|
|
15369
|
+
if (save !== void 0) return save(file);
|
|
15370
|
+
await download(file.url, file.filename);
|
|
15371
|
+
}
|
|
15360
15372
|
|
|
15361
15373
|
// src/rename_file.ts
|
|
15362
15374
|
function renameFile(file_id, filename) {
|
|
@@ -15484,7 +15496,10 @@ function useFolderPick(table) {
|
|
|
15484
15496
|
return { picked: data !== void 0 ? data : error === null ? void 0 : null, pick: pick2 };
|
|
15485
15497
|
}
|
|
15486
15498
|
export {
|
|
15499
|
+
ApiRefusal,
|
|
15500
|
+
IMAGE_FIDELITIES,
|
|
15487
15501
|
PENDING,
|
|
15502
|
+
PageHostRefusal,
|
|
15488
15503
|
askAi,
|
|
15489
15504
|
askAppContext,
|
|
15490
15505
|
buildChoiceOutput,
|
|
@@ -15493,13 +15508,15 @@ export {
|
|
|
15493
15508
|
exportQuery,
|
|
15494
15509
|
holdDrawn,
|
|
15495
15510
|
hostSpec,
|
|
15496
|
-
|
|
15511
|
+
installPageHost,
|
|
15497
15512
|
isEmbedded,
|
|
15498
15513
|
isWithinZone,
|
|
15499
15514
|
mount,
|
|
15500
15515
|
newRecordId,
|
|
15501
15516
|
openExternal,
|
|
15502
15517
|
openRequested,
|
|
15518
|
+
preparedForUpload,
|
|
15519
|
+
queriesChanged,
|
|
15503
15520
|
queryAll,
|
|
15504
15521
|
readCreatedAt,
|
|
15505
15522
|
readFiles,
|
|
@@ -15514,6 +15531,7 @@ export {
|
|
|
15514
15531
|
requestGeofencedLocation,
|
|
15515
15532
|
row,
|
|
15516
15533
|
rpc,
|
|
15534
|
+
saveFileFromUrl,
|
|
15517
15535
|
subscribeOpen,
|
|
15518
15536
|
urlParam,
|
|
15519
15537
|
useAgentRun,
|
package/dist/router.js
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isEmbedded,
|
|
3
3
|
openRequested,
|
|
4
|
+
pageAddress,
|
|
4
5
|
postHostNotification,
|
|
5
6
|
setUrlParams,
|
|
6
7
|
settleOpen,
|
|
7
8
|
subscribeOpen
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-J3UN4AJW.js";
|
|
9
10
|
|
|
10
11
|
// src/router.tsx
|
|
11
12
|
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
12
13
|
import {
|
|
13
14
|
BrowserRouter,
|
|
14
15
|
Link,
|
|
16
|
+
MemoryRouter,
|
|
15
17
|
matchRoutes,
|
|
16
18
|
useLocation,
|
|
17
19
|
useNavigate,
|
|
18
20
|
useRoutes
|
|
19
21
|
} from "react-router";
|
|
22
|
+
|
|
23
|
+
// ../shared/src/app_location_param.ts
|
|
24
|
+
var APP_LOCATION_PARAM = "_loc";
|
|
25
|
+
|
|
26
|
+
// src/router.tsx
|
|
20
27
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
-
var LOC_KEY = "_loc";
|
|
22
28
|
var HOST_KEY = "lotics_host";
|
|
23
29
|
var OPEN_KEY = "lotics_open";
|
|
24
30
|
function screenHref(loc) {
|
|
@@ -55,12 +61,12 @@ function routePattern(matches, pathname) {
|
|
|
55
61
|
}
|
|
56
62
|
return `/${shape.join("/")}`;
|
|
57
63
|
}
|
|
58
|
-
function HostScreenMirror({ routes, drawers }) {
|
|
64
|
+
function HostScreenMirror({ routes, drawers, mirrorsAddress }) {
|
|
59
65
|
const location = useLocation();
|
|
60
66
|
const href = screenHref(location);
|
|
61
67
|
useEffect(() => {
|
|
62
|
-
void setUrlParams({ [
|
|
63
|
-
}, [href]);
|
|
68
|
+
if (mirrorsAddress) void setUrlParams({ [APP_LOCATION_PARAM]: href });
|
|
69
|
+
}, [href, mirrorsAddress]);
|
|
64
70
|
const { pathname, search } = location;
|
|
65
71
|
const params = new URLSearchParams(search);
|
|
66
72
|
const opened = drawers.flatMap((key) => params.getAll(key).map((value) => ({ key, value })));
|
|
@@ -148,13 +154,20 @@ function AppRouter({
|
|
|
148
154
|
drawers = []
|
|
149
155
|
}) {
|
|
150
156
|
const embedded = isEmbedded();
|
|
157
|
+
const address = pageAddress();
|
|
151
158
|
const claimed = withNotFound(
|
|
152
159
|
routes,
|
|
153
160
|
/* @__PURE__ */ jsx(NotFoundScreen, { home: firstScreenPath(routes), words: notFound })
|
|
154
161
|
);
|
|
162
|
+
if (address !== void 0) {
|
|
163
|
+
return /* @__PURE__ */ jsxs(MemoryRouter, { initialEntries: [address], children: [
|
|
164
|
+
/* @__PURE__ */ jsx(HostScreenMirror, { routes: claimed, drawers, mirrorsAddress: false }),
|
|
165
|
+
/* @__PURE__ */ jsx(RoutedRoutes, { routes: claimed })
|
|
166
|
+
] });
|
|
167
|
+
}
|
|
155
168
|
return /* @__PURE__ */ jsxs(BrowserRouter, { children: [
|
|
156
169
|
embedded ? /* @__PURE__ */ jsx(OpenedFromHost, {}) : null,
|
|
157
|
-
embedded ? /* @__PURE__ */ jsx(HostScreenMirror, { routes: claimed, drawers }) : null,
|
|
170
|
+
embedded ? /* @__PURE__ */ jsx(HostScreenMirror, { routes: claimed, drawers, mirrorsAddress: true }) : null,
|
|
158
171
|
/* @__PURE__ */ jsx(RoutedRoutes, { routes: claimed })
|
|
159
172
|
] });
|
|
160
173
|
}
|
package/dist/rpc.d.ts
CHANGED
|
@@ -87,14 +87,59 @@ export interface AppContext {
|
|
|
87
87
|
}
|
|
88
88
|
/** Whether a Lotics host embeds the app, rather than it standing alone on its own origin. */
|
|
89
89
|
export declare function isEmbedded(): boolean;
|
|
90
|
+
/** What answers every op of a page that has neither a bridging host nor an app origin of its own. */
|
|
91
|
+
export type RpcTransport = (op: RpcOp, payload: unknown) => Promise<unknown>;
|
|
92
|
+
/** A streamed run a page's host answers: an agent's run started, or a parked one continued. */
|
|
93
|
+
export type PageAgentRun = {
|
|
94
|
+
op: "agentRun";
|
|
95
|
+
payload: AgentRunPayload;
|
|
96
|
+
} | {
|
|
97
|
+
op: "agentRunContinue";
|
|
98
|
+
payload: AgentRunContinuePayload;
|
|
99
|
+
};
|
|
100
|
+
/** Where a page's host delivers a run's stream: its id once known, then each raw chunk in order. */
|
|
101
|
+
export interface PageAgentRunStream {
|
|
102
|
+
onText: (chunk: string) => void;
|
|
103
|
+
onRunId?: (runId: string) => void;
|
|
104
|
+
}
|
|
90
105
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
106
|
+
* A page that is neither bridged nor an app's own origin (the outside page, a view an assistant's host frames): what
|
|
107
|
+
* answers its ops and what it does with what the app tells its host.
|
|
93
108
|
*/
|
|
94
|
-
export
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
109
|
+
export interface PageHost {
|
|
110
|
+
/** Answers every op. */
|
|
111
|
+
transport: RpcTransport;
|
|
112
|
+
/** What the app tells its host and the moment its first screen has its data (`{ type: "drawn" }`). Absent: dropped. */
|
|
113
|
+
notify?: (message: HostNotification | {
|
|
114
|
+
type: "drawn";
|
|
115
|
+
}) => void;
|
|
116
|
+
/** The page has no address of its own: the app's router keeps it in memory, starting here. */
|
|
117
|
+
address?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Runs an app agent: the host answers the run's stream. `done` rejecting before any chunk is a refusal (a refused
|
|
120
|
+
* continuation leaves the run parked); `done` resolving with no `finish` chunk is a cut stream, which `useAgentRun`
|
|
121
|
+
* reads to its end from `agentRun.get` — so a host that carries no stream delivers the run's id and resolves. Absent:
|
|
122
|
+
* an agent run is refused.
|
|
123
|
+
*/
|
|
124
|
+
agentRun?: (run: PageAgentRun, stream: PageAgentRunStream) => AgentRunHandle;
|
|
125
|
+
/** Saves a made file the app holds a link to. Absent: the page downloads it itself. */
|
|
126
|
+
save?: (file: {
|
|
127
|
+
url: string;
|
|
128
|
+
filename: string;
|
|
129
|
+
}) => Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
/** An op the installed page host does not carry. */
|
|
132
|
+
export declare class PageHostRefusal extends Error {
|
|
133
|
+
name: string;
|
|
134
|
+
readonly telemetryMessage = "The page's host was asked for something it does not carry.";
|
|
135
|
+
}
|
|
136
|
+
/** Make `host` answer every op of a page that is never an app's own. Module state, as the fixture is: the last install
|
|
137
|
+
* wins, and a page installs its own before it mounts. */
|
|
138
|
+
export declare function installPageHost(host: PageHost): void;
|
|
139
|
+
/** The address a page with none of its own keeps its app's router at; `undefined` where the page's own address is it. */
|
|
140
|
+
export declare function pageAddress(): string | undefined;
|
|
141
|
+
/** The installed host's way of saving a made file, where it has one. */
|
|
142
|
+
export declare function pageSave(): PageHost["save"];
|
|
98
143
|
/** What the host answers `spec`: the app's compiled spec itself, never the route's wrapper around it. */
|
|
99
144
|
export type HostSpec = AppSpec;
|
|
100
145
|
/** The app's spec, as the host hands it over the bridge. */
|
|
@@ -107,9 +152,9 @@ export declare function rpc<T = unknown>(op: RpcOp, payload: unknown, options?:
|
|
|
107
152
|
export declare function getUrlParams(): Promise<UrlParams>;
|
|
108
153
|
/** A key set to `undefined` is cleared; every other param is kept, and no history entry added. */
|
|
109
154
|
export declare function setUrlParams(patch: UrlParamsPatch): Promise<void>;
|
|
110
|
-
/** Synchronous first-paint snapshot; `{}` when embedded, which hydrates on mount. */
|
|
155
|
+
/** Synchronous first-paint snapshot; `{}` when embedded or under a page host, which hydrates on mount. */
|
|
111
156
|
export declare function peekUrlParams(): UrlParams;
|
|
112
|
-
/** Back/forward and edited URLs: the host's `url-state` embedded, `popstate` standalone. */
|
|
157
|
+
/** Back/forward and edited URLs: the host's `url-state` embedded, `popstate` standalone; a page host keeps them itself. */
|
|
113
158
|
export declare function subscribeUrlParams(cb: (params: UrlParams) => void): () => void;
|
|
114
159
|
/** Whether the person has just opened the app and its first screen has not settled yet. */
|
|
115
160
|
export declare function openRequested(): boolean;
|
|
@@ -133,6 +178,8 @@ export declare function registerQueryAlias(alias: string): () => void;
|
|
|
133
178
|
* tables a workflow touched.
|
|
134
179
|
*/
|
|
135
180
|
export declare function notifyLocalWrite(reads?: readonly string[]): void;
|
|
181
|
+
/** What a host tells the app: the queries named are stale, and every mounted hook of one reads again. */
|
|
182
|
+
export declare function queriesChanged(aliases: readonly string[]): void;
|
|
136
183
|
/**
|
|
137
184
|
* Keeps the loading cover up until the returned release runs, for a page that has not yet drawn what its requests will
|
|
138
185
|
* feed. Releasing the last hold starts the two-frame check; releasing again does nothing.
|
|
@@ -157,5 +204,17 @@ export declare function rpcAgentRunContinue(payload: AgentRunContinuePayload, on
|
|
|
157
204
|
export declare const APP_PUBLIC_SESSION_HEADER = "x-lotics-app-session";
|
|
158
205
|
/** Mirrored server-side. */
|
|
159
206
|
export declare const APP_AGENT_RUN_TOKEN_HEADER = "x-app-agent-run-token";
|
|
207
|
+
/**
|
|
208
|
+
* A route's refusal, with the per-input `field_errors` it named, if any — whichever transport carried it. `message` is
|
|
209
|
+
* what a person reads, a table check's own sentence included; `telemetryMessage` is what an error report may say of it.
|
|
210
|
+
*/
|
|
211
|
+
export declare class ApiRefusal extends Error {
|
|
212
|
+
readonly status: number;
|
|
213
|
+
readonly field_errors?: Record<string, string> | undefined;
|
|
214
|
+
readonly telemetryMessage: string;
|
|
215
|
+
/** The envelope's `code`, the one field a caller may branch on; `null` where the body is not the API's. */
|
|
216
|
+
readonly code: string | null;
|
|
217
|
+
constructor(status: number, parsed: unknown, field_errors?: Record<string, string> | undefined);
|
|
218
|
+
}
|
|
160
219
|
/** A stream refused before its first byte: the body's `message`, never its raw text. */
|
|
161
220
|
export declare function streamStartError(res: Response): Promise<Error>;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* other file, or any browser API gap, passes the original through.
|
|
4
4
|
*/
|
|
5
5
|
/** An ordinal scale, so a caller knows what it costs; `@lotics/shared/image_policy` carries the reasoning. */
|
|
6
|
-
export
|
|
6
|
+
export declare const IMAGE_FIDELITIES: readonly ["original", "high", "standard"];
|
|
7
|
+
export type ImageFidelity = (typeof IMAGE_FIDELITIES)[number];
|
|
7
8
|
/**
|
|
8
9
|
* Mirrors `@lotics/shared/image_policy`, which the published declarations may
|
|
9
10
|
* not name; a test fails on drift. `high`, since most unconsidered uploads carry text.
|
|
@@ -27,4 +28,9 @@ export interface OptimizationResult {
|
|
|
27
28
|
targetWidth: number;
|
|
28
29
|
targetHeight: number;
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* `file` as a member-facing host sends it: an image shrunk per `fidelity`, anything else as it is. Where shrinking
|
|
33
|
+
* fails the original goes, as the product's frame sends it; the server still holds its size limit.
|
|
34
|
+
*/
|
|
35
|
+
export declare function preparedForUpload(file: File, fidelity?: ImageFidelity): Promise<File>;
|
|
30
36
|
export declare function optimizeImageForUpload(file: File, fidelity?: ImageFidelity): Promise<OptimizationResult>;
|
package/docs/runtime.md
CHANGED
|
@@ -25,7 +25,7 @@ mount(<App />);
|
|
|
25
25
|
stack) above the app — a render crash or an unhandled promise rejection is
|
|
26
26
|
visible in the iframe itself. Embedded, each also reaches Lotics through the
|
|
27
27
|
host (`reportAppError`: the error's class, a bounded message and its first
|
|
28
|
-
frame, with no origin, query or fragment; the first five per page load).
|
|
28
|
+
frame, with no origin, query or fragment; the first five per page load). An `error` event that carries no error value is a browser notice and is not reported, nor counted in the five; a thrown value of any kind, and an unhandled rejection, are.
|
|
29
29
|
Banners are informational only; they are not removed automatically.
|
|
30
30
|
4. **Renders the tree** with React 19's `createRoot`.
|
|
31
31
|
|
|
@@ -278,9 +278,22 @@ semantics are documented:
|
|
|
278
278
|
| `recording.start` / `recording.stop` | `{ alias, inputs }` / `{ alias }` | `{ started }` / `void` | [mutations](./mutations.md#recording-into-a-workflow-userecording) |
|
|
279
279
|
| `outsideLink.list/create/revoke` | `{ record_id }` / `{ record_id, outside }` / `{ record_id, link_id }` | links / link or `null` / `{ id }` or `null` | [members & options](./members_and_options.md#outside-links-useoutsidelinks) |
|
|
280
280
|
|
|
281
|
-
`
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
`installPageHost(host)` makes one `PageHost` answer a page that is never an app's own (the page a person with no seat
|
|
282
|
+
opens from a link to one record; an app drawn in an assistant's chat): `transport` answers every op; `notify` receives
|
|
283
|
+
what the app tells its host (`HostNotification`) and `{ type: "drawn" }` once its first screen has its data; `address`,
|
|
284
|
+
where set, keeps the router in memory starting there, since the page has no address of its own; `agentRun` answers a
|
|
285
|
+
run's stream (absent, a run is refused with `PageHostRefusal`): its `done` rejecting before any chunk is a refusal, and
|
|
286
|
+
resolving with no `finish` chunk is a cut stream `useAgentRun` reads to its end from `agentRun.get`, so a host that
|
|
287
|
+
carries no stream hands over the run's id and resolves; `save` saves a made file the app holds a link to. `queriesChanged(aliases)` is what a page host tells its app when a table moved: the queries named are stale, and every mounted hook of one reads again. `agentRun`
|
|
288
|
+
takes a `PageAgentRun` (`agentRun` with an `AgentRunPayload` — `alias`, `session_id`, `input` — or `agentRunContinue` with
|
|
289
|
+
an `AgentRunContinuePayload`) and a `PageAgentRunStream` (`onText` per raw chunk, `onRunId` once the run's id is known),
|
|
290
|
+
and answers an `AgentRunHandle` (`done`, `abort`).
|
|
291
|
+
`preparedForUpload(file, fidelity)` is a file as a member-facing host uploads it: an image shrunk per `fidelity`
|
|
292
|
+
(`ImageFidelity`, one of `IMAGE_FIDELITIES`: `original`, `high`, `standard`), the original where shrinking fails.
|
|
293
|
+
`saveFileFromUrl({ url, filename }, download)` saves through that `save` where the installed host has one, else calls
|
|
294
|
+
`download` (`downloadFileFromUrl`). A route's refusal rejects with `ApiRefusal` (`status`, `code`, `field_errors`)
|
|
295
|
+
whichever transport carried it. The last install wins and a page installs its own before it mounts. An app never calls
|
|
296
|
+
`installPageHost`.
|
|
284
297
|
|
|
285
298
|
The **streaming** agent-run op is *not* reachable through `rpc()` — its
|
|
286
299
|
response is a chunk stream, not a single value; it's internal to `useAgentRun`.
|
package/package.json
CHANGED