@lotics/app-sdk 0.131.16 → 0.132.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-JV4BYIBG.js} +226 -163
- package/dist/download.d.ts +9 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +20 -5
- package/dist/router.js +19 -6
- package/dist/rpc.d.ts +65 -8
- package/dist/upload/optimize.d.ts +7 -1
- package/docs/runtime.md +16 -3
- 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`, `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);
|
|
@@ -1516,7 +1540,7 @@ function ensureListener() {
|
|
|
1516
1540
|
pending.delete(msg.id);
|
|
1517
1541
|
if (msg.type === "result") handler.resolve(msg.data);
|
|
1518
1542
|
else handler.reject(new Error(msg.message ?? "RPC failed"));
|
|
1519
|
-
if (handler.holdsCover) scheduleDrawn(
|
|
1543
|
+
if (handler.holdsCover) scheduleDrawn();
|
|
1520
1544
|
return;
|
|
1521
1545
|
}
|
|
1522
1546
|
const stream = streaming.get(msg.id);
|
|
@@ -1539,9 +1563,19 @@ var coverRequestsSent = 0;
|
|
|
1539
1563
|
var drawnPosted = false;
|
|
1540
1564
|
var drawnScheduled = false;
|
|
1541
1565
|
var coverHolds = 0;
|
|
1542
|
-
var
|
|
1543
|
-
|
|
1544
|
-
|
|
1566
|
+
var pageHostCoverPending = 0;
|
|
1567
|
+
var coverPendingCount = () => pageHostCoverPending + [...pending.values()].filter((one) => one.holdsCover).length;
|
|
1568
|
+
function drawnSink() {
|
|
1569
|
+
if (installedHost !== null) {
|
|
1570
|
+
const { notify } = installedHost;
|
|
1571
|
+
return notify === void 0 ? null : () => notify({ type: "drawn" });
|
|
1572
|
+
}
|
|
1573
|
+
const host = getHostOrigin();
|
|
1574
|
+
return host ? () => window.parent.postMessage({ type: "drawn" }, host) : null;
|
|
1575
|
+
}
|
|
1576
|
+
function scheduleDrawn() {
|
|
1577
|
+
const post = drawnSink();
|
|
1578
|
+
if (post === null || drawnPosted || drawnScheduled || coverHolds > 0 || coverPendingCount() > 0) return;
|
|
1545
1579
|
drawnScheduled = true;
|
|
1546
1580
|
const sentAtStart = coverRequestsSent;
|
|
1547
1581
|
requestAnimationFrame(
|
|
@@ -1550,9 +1584,9 @@ function scheduleDrawn(host) {
|
|
|
1550
1584
|
if (coverHolds > 0 || coverPendingCount() > 0) return;
|
|
1551
1585
|
if (coverRequestsSent === sentAtStart) {
|
|
1552
1586
|
drawnPosted = true;
|
|
1553
|
-
|
|
1587
|
+
post();
|
|
1554
1588
|
} else {
|
|
1555
|
-
scheduleDrawn(
|
|
1589
|
+
scheduleDrawn();
|
|
1556
1590
|
}
|
|
1557
1591
|
})
|
|
1558
1592
|
);
|
|
@@ -1563,8 +1597,7 @@ function holdDrawn() {
|
|
|
1563
1597
|
const release = () => {
|
|
1564
1598
|
if (!outstandingHolds.delete(release)) return;
|
|
1565
1599
|
coverHolds -= 1;
|
|
1566
|
-
|
|
1567
|
-
if (host) scheduleDrawn(host);
|
|
1600
|
+
scheduleDrawn();
|
|
1568
1601
|
};
|
|
1569
1602
|
outstandingHolds.add(release);
|
|
1570
1603
|
return release;
|
|
@@ -1572,6 +1605,16 @@ function holdDrawn() {
|
|
|
1572
1605
|
function releaseAllHolds() {
|
|
1573
1606
|
for (const release of [...outstandingHolds]) release();
|
|
1574
1607
|
}
|
|
1608
|
+
function rpcPageHost(host, op, payload, holdsCover) {
|
|
1609
|
+
if (!holdsCover) return host.transport(op, payload);
|
|
1610
|
+
pageHostCoverPending += 1;
|
|
1611
|
+
coverRequestsSent += 1;
|
|
1612
|
+
const settled2 = () => {
|
|
1613
|
+
pageHostCoverPending -= 1;
|
|
1614
|
+
scheduleDrawn();
|
|
1615
|
+
};
|
|
1616
|
+
return host.transport(op, payload).finally(settled2);
|
|
1617
|
+
}
|
|
1575
1618
|
function rpcBridged(op, payload, host, holdsCover) {
|
|
1576
1619
|
ensureListener();
|
|
1577
1620
|
return new Promise((resolve, reject) => {
|
|
@@ -1589,9 +1632,17 @@ function rpcBridged(op, payload, host, holdsCover) {
|
|
|
1589
1632
|
});
|
|
1590
1633
|
}
|
|
1591
1634
|
function rpcAgentRun(payload, onText, onRunId) {
|
|
1635
|
+
if (installedHost !== null) return agentRunPageHost(installedHost, { op: "agentRun", payload }, { onText, ...onRunId === void 0 ? {} : { onRunId } });
|
|
1592
1636
|
const hostOrigin = getHostOrigin();
|
|
1593
1637
|
return hostOrigin ? agentRunBridged(payload, onText, hostOrigin, onRunId) : agentRunStandalone(payload, onText, onRunId);
|
|
1594
1638
|
}
|
|
1639
|
+
function agentRunPageHost(host, run, stream) {
|
|
1640
|
+
if (host.agentRun === void 0) {
|
|
1641
|
+
return { done: Promise.reject(new PageHostRefusal("This page's host runs no app agent.")), abort: () => {
|
|
1642
|
+
} };
|
|
1643
|
+
}
|
|
1644
|
+
return host.agentRun(run, stream);
|
|
1645
|
+
}
|
|
1595
1646
|
function agentRunBridged(payload, onText, host, onRunId) {
|
|
1596
1647
|
ensureListener();
|
|
1597
1648
|
const id = nextRpcId++;
|
|
@@ -1613,6 +1664,7 @@ function agentRunBridged(payload, onText, host, onRunId) {
|
|
|
1613
1664
|
};
|
|
1614
1665
|
}
|
|
1615
1666
|
function rpcAgentRunContinue(payload, onText) {
|
|
1667
|
+
if (installedHost !== null) return agentRunPageHost(installedHost, { op: "agentRunContinue", payload }, { onText });
|
|
1616
1668
|
const hostOrigin = getHostOrigin();
|
|
1617
1669
|
if (hostOrigin) {
|
|
1618
1670
|
ensureListener();
|
|
@@ -1778,11 +1830,16 @@ async function boot() {
|
|
|
1778
1830
|
var ApiRefusal = class extends Error {
|
|
1779
1831
|
constructor(status, parsed, field_errors) {
|
|
1780
1832
|
super(transportErrorMessage(status, parsed));
|
|
1833
|
+
this.status = status;
|
|
1781
1834
|
this.field_errors = field_errors;
|
|
1782
1835
|
this.telemetryMessage = telemetryErrorMessage(status, parsed);
|
|
1836
|
+
this.code = parsed !== null && typeof parsed === "object" && "code" in parsed && typeof parsed.code === "string" && parsed.code !== "" ? parsed.code : null;
|
|
1783
1837
|
}
|
|
1838
|
+
status;
|
|
1784
1839
|
field_errors;
|
|
1785
1840
|
telemetryMessage;
|
|
1841
|
+
/** The envelope's `code`, the one field a caller may branch on; `null` where the body is not the API's. */
|
|
1842
|
+
code;
|
|
1786
1843
|
};
|
|
1787
1844
|
function readFieldErrors(parsed) {
|
|
1788
1845
|
if (parsed === null || typeof parsed !== "object" || !("field_errors" in parsed)) {
|
|
@@ -2153,7 +2210,9 @@ export {
|
|
|
2153
2210
|
AGGREGATE_COUNT_COLUMN,
|
|
2154
2211
|
AGGREGATE_SUM_COLUMN,
|
|
2155
2212
|
aggregateRows,
|
|
2213
|
+
IMAGE_FIDELITIES,
|
|
2156
2214
|
DEFAULT_IMAGE_FIDELITY,
|
|
2215
|
+
preparedForUpload,
|
|
2157
2216
|
recordingsVersion,
|
|
2158
2217
|
subscribeRecordings,
|
|
2159
2218
|
recordingStateOf,
|
|
@@ -2166,7 +2225,10 @@ export {
|
|
|
2166
2225
|
applyPatch,
|
|
2167
2226
|
paramsEqual,
|
|
2168
2227
|
isEmbedded,
|
|
2169
|
-
|
|
2228
|
+
PageHostRefusal,
|
|
2229
|
+
installPageHost,
|
|
2230
|
+
pageAddress,
|
|
2231
|
+
pageSave,
|
|
2170
2232
|
hostSpec,
|
|
2171
2233
|
rpc,
|
|
2172
2234
|
getUrlParams,
|
|
@@ -2181,5 +2243,6 @@ export {
|
|
|
2181
2243
|
holdDrawn,
|
|
2182
2244
|
releaseAllHolds,
|
|
2183
2245
|
rpcAgentRun,
|
|
2184
|
-
rpcAgentRunContinue
|
|
2246
|
+
rpcAgentRunContinue,
|
|
2247
|
+
ApiRefusal
|
|
2185
2248
|
};
|
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, 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,13 @@ 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,
|
|
40
45
|
readRecordingSnapshot,
|
|
41
46
|
recordingStateOf,
|
|
42
47
|
recordingsVersion,
|
|
@@ -55,7 +60,7 @@ import {
|
|
|
55
60
|
subtractDecimal,
|
|
56
61
|
sumDecimal,
|
|
57
62
|
urlParam
|
|
58
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-JV4BYIBG.js";
|
|
59
64
|
|
|
60
65
|
// src/mount.tsx
|
|
61
66
|
import { createRoot } from "react-dom/client";
|
|
@@ -11520,7 +11525,7 @@ function useAgentRuns(sessionId, opts) {
|
|
|
11520
11525
|
import { useCallback as useCallback5, useMemo as useMemo3, useState as useState3 } from "react";
|
|
11521
11526
|
|
|
11522
11527
|
// ../shared/src/iam_helpers.ts
|
|
11523
|
-
var ORGANIZATION_OWNER_ROLES = ["owner", "
|
|
11528
|
+
var ORGANIZATION_OWNER_ROLES = ["owner", "co_owner"];
|
|
11524
11529
|
function isOrganizationOwner(role) {
|
|
11525
11530
|
return ORGANIZATION_OWNER_ROLES.some((one) => one === role);
|
|
11526
11531
|
}
|
|
@@ -11529,7 +11534,7 @@ function organizationRole(stored) {
|
|
|
11529
11534
|
return isCoOwner(stored) ? "co_owner" : "member";
|
|
11530
11535
|
}
|
|
11531
11536
|
function isCoOwner(role) {
|
|
11532
|
-
return
|
|
11537
|
+
return role === "co_owner";
|
|
11533
11538
|
}
|
|
11534
11539
|
|
|
11535
11540
|
// ../shared/src/app_screen/cells.ts
|
|
@@ -15357,6 +15362,11 @@ function downloadFile(filename, data, mimeType) {
|
|
|
15357
15362
|
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
15358
15363
|
}
|
|
15359
15364
|
}
|
|
15365
|
+
async function saveFileFromUrl(file, download) {
|
|
15366
|
+
const save = pageSave();
|
|
15367
|
+
if (save !== void 0) return save(file);
|
|
15368
|
+
await download(file.url, file.filename);
|
|
15369
|
+
}
|
|
15360
15370
|
|
|
15361
15371
|
// src/rename_file.ts
|
|
15362
15372
|
function renameFile(file_id, filename) {
|
|
@@ -15484,7 +15494,10 @@ function useFolderPick(table) {
|
|
|
15484
15494
|
return { picked: data !== void 0 ? data : error === null ? void 0 : null, pick: pick2 };
|
|
15485
15495
|
}
|
|
15486
15496
|
export {
|
|
15497
|
+
ApiRefusal,
|
|
15498
|
+
IMAGE_FIDELITIES,
|
|
15487
15499
|
PENDING,
|
|
15500
|
+
PageHostRefusal,
|
|
15488
15501
|
askAi,
|
|
15489
15502
|
askAppContext,
|
|
15490
15503
|
buildChoiceOutput,
|
|
@@ -15493,13 +15506,14 @@ export {
|
|
|
15493
15506
|
exportQuery,
|
|
15494
15507
|
holdDrawn,
|
|
15495
15508
|
hostSpec,
|
|
15496
|
-
|
|
15509
|
+
installPageHost,
|
|
15497
15510
|
isEmbedded,
|
|
15498
15511
|
isWithinZone,
|
|
15499
15512
|
mount,
|
|
15500
15513
|
newRecordId,
|
|
15501
15514
|
openExternal,
|
|
15502
15515
|
openRequested,
|
|
15516
|
+
preparedForUpload,
|
|
15503
15517
|
queryAll,
|
|
15504
15518
|
readCreatedAt,
|
|
15505
15519
|
readFiles,
|
|
@@ -15514,6 +15528,7 @@ export {
|
|
|
15514
15528
|
requestGeofencedLocation,
|
|
15515
15529
|
row,
|
|
15516
15530
|
rpc,
|
|
15531
|
+
saveFileFromUrl,
|
|
15517
15532
|
subscribeOpen,
|
|
15518
15533
|
urlParam,
|
|
15519
15534
|
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-JV4BYIBG.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;
|
|
@@ -157,5 +202,17 @@ export declare function rpcAgentRunContinue(payload: AgentRunContinuePayload, on
|
|
|
157
202
|
export declare const APP_PUBLIC_SESSION_HEADER = "x-lotics-app-session";
|
|
158
203
|
/** Mirrored server-side. */
|
|
159
204
|
export declare const APP_AGENT_RUN_TOKEN_HEADER = "x-app-agent-run-token";
|
|
205
|
+
/**
|
|
206
|
+
* A route's refusal, with the per-input `field_errors` it named, if any — whichever transport carried it. `message` is
|
|
207
|
+
* what a person reads, a table check's own sentence included; `telemetryMessage` is what an error report may say of it.
|
|
208
|
+
*/
|
|
209
|
+
export declare class ApiRefusal extends Error {
|
|
210
|
+
readonly status: number;
|
|
211
|
+
readonly field_errors?: Record<string, string> | undefined;
|
|
212
|
+
readonly telemetryMessage: string;
|
|
213
|
+
/** The envelope's `code`, the one field a caller may branch on; `null` where the body is not the API's. */
|
|
214
|
+
readonly code: string | null;
|
|
215
|
+
constructor(status: number, parsed: unknown, field_errors?: Record<string, string> | undefined);
|
|
216
|
+
}
|
|
160
217
|
/** A stream refused before its first byte: the body's `message`, never its raw text. */
|
|
161
218
|
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
|
@@ -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. `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