@notis_ai/cli 0.2.25 → 0.2.27
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/README.md +186 -5
- package/config/notis_app_design_rules.json +36 -14
- package/config/portal-route-roots.json +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +2866 -553
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/SKILL.md +0 -1
- package/dist/base-skills/notis-query/references/documents.md +7 -0
- package/dist/base-skills/notis-query/references/query.md +1 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +96 -24
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
- package/dist/base-skills/notis-spaces/references/context.md +3 -0
- package/dist/base-skills/notis-spaces/references/design.md +37 -18
- package/dist/base-skills/notis-spaces/references/reading.md +8 -1
- package/dist/base-skills/notis-spaces/references/reports.md +6 -6
- package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
- package/dist/base-skills/notis-spaces/references/store.md +22 -13
- package/dist/base-skills/notis-spaces/references/views.md +99 -6
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/src/cloudComputerWords.ts +53 -0
- package/dist/sdk/src/components/Audience.tsx +76 -0
- package/dist/sdk/src/components/DocumentPage.tsx +15 -4
- package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
- package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
- package/dist/sdk/src/components/NotisSelectionBoundary.tsx +79 -25
- package/dist/sdk/src/components/Skeleton.tsx +162 -6
- package/dist/sdk/src/hooks/useAction.ts +12 -2
- package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
- package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
- package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
- package/dist/sdk/src/hooks/useItemThread.ts +58 -0
- package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
- package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
- package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
- package/dist/sdk/src/hooks/useQuery.ts +67 -10
- package/dist/sdk/src/hooks/useViewParams.ts +47 -11
- package/dist/sdk/src/index.ts +31 -4
- package/dist/sdk/src/interactions.ts +2 -0
- package/dist/sdk/src/nativeData.ts +2 -0
- package/dist/sdk/src/optimisticRows.ts +329 -0
- package/dist/sdk/src/perf.ts +188 -0
- package/dist/sdk/src/provider.tsx +2 -1
- package/dist/sdk/src/queryCache.ts +366 -17
- package/dist/sdk/src/runtime.ts +55 -4
- package/dist/sdk/src/skeleton.ts +103 -0
- package/dist/sdk/src/space.ts +662 -28
- package/dist/sdk/src/spacePublicUI.ts +36 -0
- package/dist/sdk/src/ui/engine/step.ts +54 -0
- package/dist/sdk/src/ui/icons.tsx +3 -1
- package/dist/sdk/src/words/shell.ts +1 -0
- package/dist/skill-sync/index.js +88 -13
- package/dist/skill-sync-worker.mjs +127 -38
- package/dist/space-harness/host.js +272 -105
- package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
- package/dist/space-sdk/dist/index.js +9 -4
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/package.json +3 -0
- package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
- package/dist/space-sdk/src/components/Audience.d.ts +46 -0
- package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
- package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
- package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
- package/dist/space-sdk/src/components/NotisSelectionBoundary.d.ts +19 -2
- package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
- package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
- package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
- package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
- package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
- package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
- package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
- package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
- package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
- package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
- package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
- package/dist/space-sdk/src/index.d.ts +24 -4
- package/dist/space-sdk/src/nativeData.d.ts +6 -0
- package/dist/space-sdk/src/queryCache.d.ts +97 -2
- package/dist/space-sdk/src/runtime.d.ts +53 -4
- package/dist/space-sdk/src/skeleton.d.ts +42 -0
- package/dist/space-sdk/src/space.ts +662 -28
- package/dist/space-sdk/src/tailwind-candidates.d.ts +761 -6
- package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
- package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
- package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
- package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
- package/dist/space-sdk/src/ui/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
- package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
- package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
- package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
- package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
- package/dist/space-sdk/src/words/shell.ts +1 -0
- package/dist/view-renderer/dist/host.js +355 -188
- package/dist/view-renderer/dist/theme.css +1 -1
- package/dist/view-renderer/src/dom.js +15 -2
- package/dist/view-renderer/src/host.tsx +4 -1
- package/dist/view-renderer/src/index.js +3 -0
- package/dist/view-renderer/src/pool.js +8 -4
- package/dist/view-renderer/src/renderer.js +92 -23
- package/dist/view-renderer/src/skeleton.js +450 -0
- package/package.json +4 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
- package/skills/notis-onboarding/BRIEF.md +15 -9
- package/skills/notis-spaces/cli.md +43 -4
- package/src/command-specs/auth.js +5 -3
- package/src/command-specs/cc.js +410 -0
- package/src/command-specs/computer.js +320 -0
- package/src/command-specs/diagnostics.js +2 -13
- package/src/command-specs/documents.js +22 -4
- package/src/command-specs/index.js +7 -0
- package/src/command-specs/onboarding.js +127 -7
- package/src/command-specs/skills.js +2 -2
- package/src/command-specs/spaces.js +162 -30
- package/src/command-specs/tools.js +26 -8
- package/src/command-specs/views.js +4 -1
- package/src/runtime/agent-setup.js +20 -2
- package/src/runtime/app-boundary-validator.js +2 -1
- package/src/runtime/app-platform.js +13 -0
- package/src/runtime/auth-recovery.js +5 -0
- package/src/runtime/channel.js +16 -2
- package/src/runtime/cloud-transfer.js +587 -0
- package/src/runtime/computer-ssh.js +127 -0
- package/src/runtime/oauth.js +50 -4
- package/src/runtime/skill-sync/cloud-client.ts +98 -15
- package/src/runtime/skill-sync/index.ts +42 -4
- package/src/runtime/skill-sync/local-scanner.ts +1 -0
- package/src/runtime/skill-sync/types.ts +6 -0
- package/src/runtime/space-audience.js +94 -0
- package/src/runtime/space-collection-scaffold.js +2 -1
- package/src/runtime/space-fixture-broker.js +2 -1
- package/src/runtime/space-lock.js +1 -4
- package/src/runtime/space-platform.js +18 -2
- package/src/runtime/space-source.js +105 -7
- package/src/runtime/space-test-server.js +13 -2
- package/src/runtime/space-verification.js +99 -6
- package/src/runtime/space-view-manifest.js +22 -4
- package/src/runtime/sync-skills.js +24 -20
- package/src/runtime/transport.js +19 -0
- package/src/runtime/view-render.js +2 -2
- package/src/skill-sync-worker.js +5 -1
- package/template/.harness/index.html.tmpl +1 -1
- package/dist/skill-sync/index.js.map +0 -7
- package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
--secondary: 210 40% 96.1%;
|
|
21
21
|
--secondary-foreground: 222.2 47.4% 11.2%;
|
|
22
22
|
--muted: 210 40% 96.1%;
|
|
23
|
-
--muted-foreground: 0 0%
|
|
23
|
+
--muted-foreground: 0 0% 40%;
|
|
24
24
|
--accent: 210 40% 96.1%;
|
|
25
25
|
--accent-foreground: 222.2 47.4% 11.2%;
|
|
26
26
|
--destructive: 0 84.2% 60.2%;
|
|
@@ -62,9 +62,10 @@ export function extractRenderedMarkdown({ baseUrl = document.baseURI } = {}) {
|
|
|
62
62
|
flush();
|
|
63
63
|
return '\n\n' + lines.join('\n') + '\n\n';
|
|
64
64
|
};
|
|
65
|
+
let skipped = null;
|
|
65
66
|
function walk(node) {
|
|
66
67
|
if (node.nodeType === Node.TEXT_NODE) return node.textContent || '';
|
|
67
|
-
if (node.nodeType !== Node.ELEMENT_NODE) return '';
|
|
68
|
+
if (node.nodeType !== Node.ELEMENT_NODE || node === skipped) return '';
|
|
68
69
|
const tag = node.tagName;
|
|
69
70
|
if (['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEMPLATE', 'LINK', 'META'].includes(tag)) return '';
|
|
70
71
|
const semantic = node.getAttribute('data-notis-render');
|
|
@@ -100,7 +101,19 @@ export function extractRenderedMarkdown({ baseUrl = document.baseURI } = {}) {
|
|
|
100
101
|
const content = children(node);
|
|
101
102
|
return ['P', 'DIV', 'SECTION', 'ARTICLE', 'HEADER', 'FOOTER', 'MAIN', 'UL', 'OL', 'FIGURE'].includes(tag) ? '\n\n' + content + '\n\n' : content;
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
const tidy = value => value.replace(/[ \t]+\n/g, '\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
105
|
+
// A link that opens one item of a list (the SDK ListReader's reader) is a link to that item: its
|
|
106
|
+
// Markdown comes first, then the rest of the page. A reader that keeps only the start of a long
|
|
107
|
+
// page (a voice call keeps 12,000 characters) otherwise got the list and never the item.
|
|
108
|
+
const shown = node => {
|
|
109
|
+
for (let current = node; current; current = current.parentElement) if (!visible(current)) return false;
|
|
110
|
+
return node.getClientRects().length > 0;
|
|
111
|
+
};
|
|
112
|
+
const reader = [...document.querySelectorAll('.nui-lr-reader-body')].find(shown);
|
|
113
|
+
if (!reader) return tidy(walk(document.body));
|
|
114
|
+
const item = walk(reader);
|
|
115
|
+
skipped = reader;
|
|
116
|
+
return tidy(item + '\n\n' + walk(document.body));
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
/** Bounded capture expands clipped content; no 1500px crop or hidden inner scroll tail. */
|
|
@@ -134,7 +134,10 @@ function HtmlRecord({ recordKey, title, className, onReady }) {
|
|
|
134
134
|
const loaded = useRead({ operation: 'html', record_key: recordKey });
|
|
135
135
|
// As live, a record that cannot load is ready too, so a view waiting on it does not stay blank.
|
|
136
136
|
useEffect(() => { if (loaded.failed) onReady?.(); }, [loaded.failed]);
|
|
137
|
-
|
|
137
|
+
if (loaded.value) return <HtmlValue html={loaded.value.html} title={title || loaded.value.title} className={className} onReady={onReady} />;
|
|
138
|
+
// While the file read is held (a loading capture), the frame shows that it is opening, like a record body: an
|
|
139
|
+
// empty root never reads as mounted, and the capture would wait out its whole timeout for nothing.
|
|
140
|
+
return loaded.failed ? null : <div role="status" className={className}>{text('opening')}</div>;
|
|
138
141
|
}
|
|
139
142
|
// The live sandbox (HtmlDocumentFrame): the same flags and the same viewer CSP prepended to the HTML. As live, a
|
|
140
143
|
// className sizes a box the frame fills (a 1920x1080 slide box); without one the frame keeps its full-page height.
|
|
@@ -2,3 +2,6 @@ export { renderView, RENDER_ORIGIN } from './renderer.js';
|
|
|
2
2
|
export { createBrowserPool, browserEnvironment } from './pool.js';
|
|
3
3
|
export { createRemoteRenderBroker } from './remote-broker.js';
|
|
4
4
|
export { ViewRenderError } from './errors.js';
|
|
5
|
+
export { SKELETON_SCHEMA, SKELETON_PATH, SKELETON_WIDTHS, SKELETON_LOCALES, SKELETON_LIMITS, SKELETON_REGION_KEY,
|
|
6
|
+
skeletonProbe, foldRepeatRows, capBones, buildSkeletonEntry, buildSkeletonDocument, canonicalSkeletonJson,
|
|
7
|
+
validateSkeletonDocument, runSkeletonChecks } from './skeleton.js';
|
|
@@ -54,7 +54,7 @@ export function createBrowserPool({ concurrency = 2, maxQueue = 8, recycleAfter
|
|
|
54
54
|
// A container's small /dev/shm cannot hold a tall page's shared memory.
|
|
55
55
|
'--disable-dev-shm-usage'] });
|
|
56
56
|
} catch (error) {
|
|
57
|
-
if (/Executable doesn't exist/.test(String(error?.message))) throw new ViewRenderError('render_browser_missing', 'Install the pinned Chromium browser with npx playwright-core@1.
|
|
57
|
+
if (/Executable doesn't exist/.test(String(error?.message))) throw new ViewRenderError('render_browser_missing', 'Install the pinned Chromium browser with npx playwright-core@1.64.1 install chromium.', 503);
|
|
58
58
|
throw new ViewRenderError('render_browser_unavailable', 'Sandboxed Chromium could not start.', 503);
|
|
59
59
|
}
|
|
60
60
|
return browser;
|
|
@@ -75,8 +75,12 @@ export function createBrowserPool({ concurrency = 2, maxQueue = 8, recycleAfter
|
|
|
75
75
|
},
|
|
76
76
|
async use(operation, { signal, width = 1440, locale = 'en', timezone = 'UTC' } = {}) {
|
|
77
77
|
await acquire(signal);
|
|
78
|
-
let context, launched = false;
|
|
79
|
-
|
|
78
|
+
let context, closed, launched = false;
|
|
79
|
+
// One close per context, settled before the slot is released: Playwright returns a second close() at once
|
|
80
|
+
// while the first is in flight, so a close started on cancellation could still be running when the owner
|
|
81
|
+
// closes the browser, and reject unhandled.
|
|
82
|
+
const closeContext = () => (closed ??= context.close().catch(() => {}));
|
|
83
|
+
const abort = () => { if (context) void closeContext(); };
|
|
80
84
|
try {
|
|
81
85
|
const browser = await getBrowser();
|
|
82
86
|
launched = true;
|
|
@@ -88,7 +92,7 @@ export function createBrowserPool({ concurrency = 2, maxQueue = 8, recycleAfter
|
|
|
88
92
|
return await operation(context);
|
|
89
93
|
} finally {
|
|
90
94
|
signal?.removeEventListener('abort', abort);
|
|
91
|
-
if (context) { contexts.delete(context); served++; renders++; await
|
|
95
|
+
if (context) { contexts.delete(context); served++; renders++; await closeContext(); }
|
|
92
96
|
// A browser that failed to open a context still counts, so recycling closes it too.
|
|
93
97
|
else if (launched) served++;
|
|
94
98
|
release();
|
|
@@ -3,6 +3,7 @@ import { createBrowserPool } from './pool.js';
|
|
|
3
3
|
import { expandScrollAreas, freezeAnimations, extractRenderedMarkdown, restrictBrowserTransports, freezeFrameViewportSizes, settleFrameImages } from './dom.js';
|
|
4
4
|
import { ViewRenderError, renderFailure } from './errors.js';
|
|
5
5
|
import { createPngStitcher } from './png.js';
|
|
6
|
+
import { skeletonProbe, waitForQuietDom, LANDMARK_SELECTOR, LOADING_WORDS } from './skeleton.js';
|
|
6
7
|
|
|
7
8
|
export const RENDER_ORIGIN = 'http://notis-render.invalid';
|
|
8
9
|
const READ_OPERATIONS = new Set(['action', 'shown', 'viewer_read', 'document_body', 'record', 'html', 'report', 'resolve_links']);
|
|
@@ -97,9 +98,23 @@ function diagnosticFailure(error, stage, fallback = 'render_failed') {
|
|
|
97
98
|
return failure;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Shared by CLI and warm service. No broad credential is an argument to this library.
|
|
103
|
+
*
|
|
104
|
+
* Skeleton capture options, all absent by default (the render is then unchanged):
|
|
105
|
+
* - `pending: true` holds every `/__read` until the render ends, waits until the view is mounted with a read
|
|
106
|
+
* pending and its DOM is quiet for 300 ms, and returns `pending` (the loading-state probe) and a viewport
|
|
107
|
+
* `screenshot` instead of the usual outputs. A view that never reads is reported as `pending.static`.
|
|
108
|
+
* - `measure: { regions }` answers reads as usual and returns `skeleton_measure`, the bones measured inside each
|
|
109
|
+
* region box before the page is expanded for a full-page capture.
|
|
110
|
+
* - `locale` ('en' or 'fr') overrides the snapshot locale; `skeleton` is injected as `descriptor.context.skeleton`.
|
|
111
|
+
*/
|
|
112
|
+
export async function renderView({ broker, outputs, width, timeoutMs, signal, pool, host, maxHeight = 60000, maxPixels = 80000000, sliceHeight = 2048, maxPngBytes = PNG_LIMIT,
|
|
113
|
+
pending = false, measure, locale, skeleton }) {
|
|
102
114
|
const config = inputs({ outputs, width, timeoutMs });
|
|
115
|
+
if (pending && measure) throw new TypeError('Choose a pending or a measuring render, not both.');
|
|
116
|
+
if (locale !== undefined && !['en', 'fr'].includes(locale)) throw new TypeError('Override the locale with en or fr.');
|
|
117
|
+
if (measure !== undefined && !Array.isArray(measure?.regions)) throw new TypeError('Measure a list of skeleton regions.');
|
|
103
118
|
if (!Number.isInteger(sliceHeight) || sliceHeight < 256 || sliceHeight > 16384) throw new TypeError('Use a bounded screenshot slice height.');
|
|
104
119
|
if (!Number.isInteger(maxPngBytes) || maxPngBytes < 1 || maxPngBytes > PNG_LIMIT) throw new TypeError('Use a PNG limit within the render transport limit.');
|
|
105
120
|
const deadline = AbortSignal.timeout(config.timeoutMs);
|
|
@@ -113,6 +128,15 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
113
128
|
|| JSON.stringify([...snapshot.render_options.outputs].sort()) !== JSON.stringify([...config.outputs].sort()))) {
|
|
114
129
|
throw new ViewRenderError('render_options_changed', 'Use the outputs and width authorized for this render.', 409);
|
|
115
130
|
}
|
|
131
|
+
if (locale) snapshot.locale = locale;
|
|
132
|
+
if (skeleton !== undefined) {
|
|
133
|
+
const descriptor = snapshot.descriptor;
|
|
134
|
+
snapshot.descriptor = { ...descriptor, context: { ...(descriptor.context || {}), skeleton } };
|
|
135
|
+
}
|
|
136
|
+
// Pending renders hold reads until the operation ends; releasing aborts them quietly.
|
|
137
|
+
let release = () => {};
|
|
138
|
+
const held = new Promise(resolve => { release = resolve; });
|
|
139
|
+
if (pending) cancellation.addEventListener('abort', () => release(), { once: true });
|
|
116
140
|
const hostSource = host?.script ?? await readFile(new URL('../dist/host.js', import.meta.url), 'utf8');
|
|
117
141
|
snapshot.hostCss = host ? host.css || '' : await readFile(new URL('../dist/host.css', import.meta.url), 'utf8');
|
|
118
142
|
snapshot.theme_css ||= host ? host.themeCss || '' : await readFile(new URL('../dist/theme.css', import.meta.url), 'utf8');
|
|
@@ -169,6 +193,7 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
169
193
|
return respond(403, { error: 'render_read_only', message: 'Rendering never changes records or runs write actions.' });
|
|
170
194
|
}
|
|
171
195
|
if (++readRequests > 128) throw new ViewRenderError('render_read_limit', 'This render exceeded its read limit.', 429);
|
|
196
|
+
if (pending) { await held; return route.abort('aborted').catch(() => {}); }
|
|
172
197
|
// The server independently reconstructs and classifies every call.
|
|
173
198
|
const result = await broker.read(payload, { signal: cancellation });
|
|
174
199
|
return respond(200, { result });
|
|
@@ -183,10 +208,63 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
183
208
|
await respond(error?.status === 401 || error?.status === 404 ? error.status : 403, { error: code, message: 'This read is unavailable in the current render.' }).catch(() => {});
|
|
184
209
|
}
|
|
185
210
|
});
|
|
211
|
+
const complete = async () => {
|
|
212
|
+
stage = 'read_completion';
|
|
213
|
+
if (blocked.some(value => value.code === 'render_paid_background_denied')) throw new ViewRenderError('render_paid_background_denied', 'Background snapshots cannot run paid reads.', 403);
|
|
214
|
+
for (const code of await page.evaluate(() => (window.__notisRenderState.blocked || []).filter(value => value === 'render_read_only').slice(0, 100))) {
|
|
215
|
+
if (blocked.length < 100) blocked.push({ code });
|
|
216
|
+
}
|
|
217
|
+
if (transientFailure && !authorityLost && !cancellation.aborted) {
|
|
218
|
+
const failure = new ViewRenderError('render_temporarily_unavailable', 'The view could not be rendered right now. Try again in a moment.', 503);
|
|
219
|
+
Object.defineProperty(failure, 'cause', { value: transientFailure });
|
|
220
|
+
throw failure;
|
|
221
|
+
}
|
|
222
|
+
if (authorityLost || cancellation.aborted || await page.evaluate(() => Boolean(window.__notisRenderState.failed))) {
|
|
223
|
+
const failure = renderFailure('render_access_changed');
|
|
224
|
+
if (authorityFailure) Object.defineProperty(failure, 'cause', { value: authorityFailure });
|
|
225
|
+
throw failure;
|
|
226
|
+
}
|
|
227
|
+
// Do not release Markdown or image bytes after revocation/source changes.
|
|
228
|
+
stage = 'authorize_finish';
|
|
229
|
+
const finalAuthority = await broker.finish({ signal: cancellation });
|
|
230
|
+
if (finalAuthority?.valid !== true) throw renderFailure('render_access_changed');
|
|
231
|
+
return finalAuthority;
|
|
232
|
+
};
|
|
186
233
|
const page = await context.newPage();
|
|
187
|
-
context.on('page', child => { if (child !== page) void child.close(); });
|
|
234
|
+
context.on('page', child => { if (child !== page) void child.close().catch(() => {}); });
|
|
188
235
|
stage = 'host_navigation';
|
|
189
236
|
await page.goto(RENDER_ORIGIN, { waitUntil: 'domcontentloaded' });
|
|
237
|
+
if (pending) {
|
|
238
|
+
stage = 'pending_ready';
|
|
239
|
+
// Ready: mounted with a read held (the source load also counts as pending), or idle with no read at all.
|
|
240
|
+
let isStatic = false;
|
|
241
|
+
for (;;) {
|
|
242
|
+
if (cancellation.aborted) throw renderFailure('render_timeout');
|
|
243
|
+
const now = await page.evaluate(() => {
|
|
244
|
+
const value = window.__notisRenderState || {};
|
|
245
|
+
return { mounted: Boolean(value.mounted), pending: value.pending || 0, idle: performance.now() - (value.lastActivity || 0), failed: Boolean(value.failed) };
|
|
246
|
+
});
|
|
247
|
+
if (now.failed) break;
|
|
248
|
+
if (now.mounted && now.pending > 0 && readRequests > 0) break;
|
|
249
|
+
if (now.mounted && now.pending === 0 && now.idle > 100) { isStatic = readRequests === 0; break; }
|
|
250
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
251
|
+
}
|
|
252
|
+
stage = 'pending_settle';
|
|
253
|
+
await page.evaluate(waitForQuietDom, { quietMs: 300, capMs: 5000 });
|
|
254
|
+
await page.evaluate(async () => {
|
|
255
|
+
await Promise.race([document.fonts.ready, new Promise(resolve => setTimeout(resolve, 2000))]);
|
|
256
|
+
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
257
|
+
});
|
|
258
|
+
stage = 'pending_probe';
|
|
259
|
+
const probe = await page.evaluate(skeletonProbe, { mode: 'pending', landmarkSelector: LANDMARK_SELECTOR, loadingPattern: LOADING_WORDS.source });
|
|
260
|
+
const png = await page.screenshot(CAPTURE);
|
|
261
|
+
const finalAuthority = await complete();
|
|
262
|
+
release();
|
|
263
|
+
return { url: snapshot.url, view: snapshot.view, ...(typeof finalAuthority.render_id === 'string' ? { render_id: finalAuthority.render_id } : {}),
|
|
264
|
+
pending: { static: isStatic, reads: readRequests, ...probe },
|
|
265
|
+
screenshot: { mime_type: 'image/png', viewport_width: config.width, data_base64: png.toString('base64'), width: png.readUInt32BE(16), height: png.readUInt32BE(20) },
|
|
266
|
+
rendered_at: new Date().toISOString() };
|
|
267
|
+
}
|
|
190
268
|
stage = 'host_ready';
|
|
191
269
|
await page.waitForFunction(() => window.__notisRenderState?.mounted && window.__notisRenderState.pending === 0 && performance.now() - window.__notisRenderState.lastActivity > 100, undefined, { timeout: config.timeoutMs });
|
|
192
270
|
// A committed data response must settle React layout and browser fonts.
|
|
@@ -195,6 +273,15 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
195
273
|
await Promise.race([document.fonts.ready, new Promise(resolve => setTimeout(resolve, 2000))]);
|
|
196
274
|
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
197
275
|
});
|
|
276
|
+
if (measure) {
|
|
277
|
+
// Bones are measured on the viewport layout the skeleton stands in for, before any expansion.
|
|
278
|
+
stage = 'skeleton_measure';
|
|
279
|
+
const regions = measure.regions.map(({ key, x, y, width, height }) => ({ key, x, y, width, height }));
|
|
280
|
+
const skeletonMeasure = await page.evaluate(skeletonProbe, { mode: 'final', regions, landmarkSelector: LANDMARK_SELECTOR });
|
|
281
|
+
const finalAuthority = await complete();
|
|
282
|
+
return { url: snapshot.url, view: snapshot.view, ...(typeof finalAuthority.render_id === 'string' ? { render_id: finalAuthority.render_id } : {}),
|
|
283
|
+
skeleton_measure: skeletonMeasure, rendered_at: new Date().toISOString() };
|
|
284
|
+
}
|
|
198
285
|
let lastHeight = -1, settled = false;
|
|
199
286
|
const frozenFrames = new WeakSet();
|
|
200
287
|
stage = 'layout_expansion';
|
|
@@ -249,25 +336,7 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
249
336
|
if (png.length > maxPngBytes) throw new ViewRenderError('render_too_large', 'The PNG exceeds the render transport limit; nothing was cropped.', 413);
|
|
250
337
|
screenshot = { mime_type: 'image/png', viewport_width: config.width, data_base64: png.toString('base64'), width: png.readUInt32BE(16), height: png.readUInt32BE(20) };
|
|
251
338
|
}
|
|
252
|
-
|
|
253
|
-
if (blocked.some(value => value.code === 'render_paid_background_denied')) throw new ViewRenderError('render_paid_background_denied', 'Background snapshots cannot run paid reads.', 403);
|
|
254
|
-
for (const code of await page.evaluate(() => (window.__notisRenderState.blocked || []).filter(value => value === 'render_read_only').slice(0, 100))) {
|
|
255
|
-
if (blocked.length < 100) blocked.push({ code });
|
|
256
|
-
}
|
|
257
|
-
if (transientFailure && !authorityLost && !cancellation.aborted) {
|
|
258
|
-
const failure = new ViewRenderError('render_temporarily_unavailable', 'The view could not be rendered right now. Try again in a moment.', 503);
|
|
259
|
-
Object.defineProperty(failure, 'cause', { value: transientFailure });
|
|
260
|
-
throw failure;
|
|
261
|
-
}
|
|
262
|
-
if (authorityLost || cancellation.aborted || await page.evaluate(() => Boolean(window.__notisRenderState.failed))) {
|
|
263
|
-
const failure = renderFailure('render_access_changed');
|
|
264
|
-
if (authorityFailure) Object.defineProperty(failure, 'cause', { value: authorityFailure });
|
|
265
|
-
throw failure;
|
|
266
|
-
}
|
|
267
|
-
// Do not release Markdown or image bytes after revocation/source changes.
|
|
268
|
-
stage = 'authorize_finish';
|
|
269
|
-
const finalAuthority = await broker.finish({ signal: cancellation });
|
|
270
|
-
if (finalAuthority?.valid !== true) throw renderFailure('render_access_changed');
|
|
339
|
+
const finalAuthority = await complete();
|
|
271
340
|
return { url: snapshot.url, view: snapshot.view, ...(snapshot.record_key ? { record_key: snapshot.record_key } : {}),
|
|
272
341
|
...(typeof finalAuthority.render_id === 'string' ? { render_id: finalAuthority.render_id } : {}),
|
|
273
342
|
params: snapshot.params || {}, ...(markdown !== undefined ? { markdown } : {}), ...(screenshot ? { screenshot } : {}),
|
|
@@ -275,5 +344,5 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
275
344
|
}, { signal: cancellation, width: config.width, locale: snapshot.locale || 'en', timezone: snapshot.timezone || 'UTC' });
|
|
276
345
|
} catch (error) {
|
|
277
346
|
throw diagnosticFailure(error, stage, cancellation.aborted ? 'render_timeout' : 'render_failed');
|
|
278
|
-
} finally { if (ownPool) await pool.close(); }
|
|
347
|
+
} finally { release(); if (ownPool) await pool.close(); }
|
|
279
348
|
}
|