@chengxianglibra/dsh-data-analysis 0.1.2 → 0.2.1
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.en.md +135 -0
- package/README.md +105 -98
- package/cordis.patch.yml +1 -1
- package/lib/bin/environment.js +8 -6
- package/lib/client/credentials/changes.js +74 -0
- package/lib/client/credentials/create-datasource.js +126 -22
- package/lib/client/credentials/credential-draft.js +42 -0
- package/lib/client/credentials/defaults.js +11 -0
- package/lib/client/credentials/descriptions.js +46 -0
- package/lib/client/credentials/install.js +209 -81
- package/lib/client/credentials/model.js +323 -51
- package/lib/client/credentials/report-publishing.js +96 -0
- package/lib/client/credentials/styles.js +13 -9
- package/lib/client/i18n/context.js +22 -0
- package/lib/client/i18n/copy.js +60 -0
- package/lib/client/i18n/credentials.js +475 -0
- package/lib/client/i18n/host.js +28 -0
- package/lib/client/i18n/navigation.js +41 -0
- package/lib/client/i18n/presentation.js +577 -0
- package/lib/client/i18n/python.js +36 -0
- package/lib/client/i18n/semantic.js +441 -0
- package/lib/client/i18n/settings.js +30 -0
- package/lib/client/input-context.js +21 -0
- package/lib/client/python-tool/card.js +35 -0
- package/lib/client/python-tool/execution-error.js +35 -0
- package/lib/client/python-tool/install.js +9 -0
- package/lib/client/python-tool/model.js +101 -0
- package/lib/client/right-tabs/install.js +535 -0
- package/lib/client/right-tabs/live-delivery.js +58 -0
- package/lib/client/right-tabs/navigation.js +47 -0
- package/lib/client/right-tabs/page.js +178 -0
- package/lib/client/right-tabs/styles.js +11 -0
- package/lib/client/rpc.js +5 -0
- package/lib/client/semantic-reference.js +10 -0
- package/lib/client/settings/card.js +90 -0
- package/lib/client/settings/install.js +10 -0
- package/lib/client/workspace-header-action.js +14 -1
- package/lib/client/workspace-shortcuts.js +26 -0
- package/lib/client.js +388 -242
- package/lib/compatibility.js +1 -1
- package/lib/datasource/authoring.js +43 -4
- package/lib/datasource/bridge-programs.js +23 -20
- package/lib/datasource/bridge.js +46 -3
- package/lib/datasource/changes-contract.js +41 -0
- package/lib/datasource/changes.js +49 -0
- package/lib/datasource/configure.js +39 -0
- package/lib/datasource/defaults.js +25 -0
- package/lib/datasource/index.js +2 -1
- package/lib/datasource/python-options.js +15 -0
- package/lib/datasource/python.js +119 -25
- package/lib/datasource/rpc.js +75 -13
- package/lib/datasource/service.js +286 -11
- package/lib/datasource/test.js +3 -2
- package/lib/disclosure/activation.js +19 -7
- package/lib/disclosure/execution-guidance.js +49 -0
- package/lib/disclosure/help.js +4 -1
- package/lib/environment/runtime.js +35 -34
- package/lib/environment/workspace.js +18 -1
- package/lib/lifecycle.js +33 -0
- package/lib/plugin-agents.js +154 -0
- package/lib/plugin.js +98 -172
- package/lib/presentation/asset.js +34 -0
- package/lib/presentation/assets/portable.js +14 -14
- package/lib/presentation/assets/static.js +344 -73
- package/lib/presentation/build/index.js +3 -2
- package/lib/presentation/commit.js +19 -12
- package/lib/presentation/contracts/asset-path.js +9 -0
- package/lib/presentation/contracts/catalog.js +62 -0
- package/lib/presentation/contracts/charts.js +0 -23
- package/lib/presentation/contracts/index.js +17 -5
- package/lib/presentation/contracts/types.js +1 -1
- package/lib/presentation/delivery.js +45 -30
- package/lib/presentation/export-html.js +214 -0
- package/lib/presentation/files.js +4 -5
- package/lib/presentation/projection/index.js +2 -1
- package/lib/presentation/projection/program.js +2 -9
- package/lib/presentation/projection/sql-code.js +13 -13
- package/lib/presentation/reports.js +114 -17
- package/lib/presentation/rpc.js +96 -58
- package/lib/presentation/tool.js +6 -10
- package/lib/report-publishing/adapters.js +111 -0
- package/lib/report-publishing/config.js +69 -0
- package/lib/report-publishing/service.js +180 -0
- package/lib/rpc.js +49 -0
- package/lib/semantic-browser/contracts.js +17 -0
- package/lib/semantic-browser/program.js +10 -0
- package/lib/semantic-browser/service.js +40 -6
- package/lib/semantic-reference/bridge.js +10 -1
- package/lib/semantic-reference/contracts.js +20 -6
- package/lib/semantic-reference/environment.js +56 -0
- package/lib/semantic-reference/labels.js +16 -0
- package/lib/semantic-reference/rpc.js +39 -18
- package/lib/semantic-reference/search.js +5 -4
- package/lib/semantic-reference/usage.js +12 -3
- package/lib/settings.js +21 -0
- package/lib/tool-lifecycle.js +22 -0
- package/lib/types/client/credentials/changes.d.ts +9 -0
- package/lib/types/client/credentials/create-datasource.d.ts +3 -1
- package/lib/types/client/credentials/credential-draft.d.ts +14 -0
- package/lib/types/client/credentials/defaults.d.ts +2 -0
- package/lib/types/client/credentials/descriptions.d.ts +1 -0
- package/lib/types/client/credentials/install.d.ts +19 -1
- package/lib/types/client/credentials/model.d.ts +31 -11
- package/lib/types/client/credentials/report-publishing.d.ts +5 -0
- package/lib/types/client/credentials/styles.d.ts +1 -1
- package/lib/types/client/i18n/context.d.ts +17 -0
- package/lib/types/client/i18n/copy.d.ts +821 -0
- package/lib/types/client/i18n/credentials.d.ts +475 -0
- package/lib/types/client/i18n/host.d.ts +17 -0
- package/lib/types/client/i18n/navigation.d.ts +41 -0
- package/lib/types/client/i18n/presentation.d.ts +577 -0
- package/lib/types/client/i18n/python.d.ts +19 -0
- package/lib/types/client/i18n/semantic.d.ts +441 -0
- package/lib/types/client/i18n/settings.d.ts +16 -0
- package/lib/types/client/input-context.d.ts +19 -0
- package/lib/types/client/presentation/ask-dsh.d.ts +4 -8
- package/lib/types/client/presentation/catalog-model.d.ts +24 -0
- package/lib/types/client/presentation/catalog.d.ts +20 -0
- package/lib/types/client/presentation/chart-tooltip.d.ts +2 -2
- package/lib/types/client/presentation/context-reference.d.ts +12 -0
- package/lib/types/client/presentation/copy-context.d.ts +2 -2
- package/lib/types/client/presentation/delivery-model.d.ts +27 -6
- package/lib/types/client/presentation/delivery.d.ts +8 -7
- package/lib/types/client/presentation/download.d.ts +2 -0
- package/lib/types/client/presentation/export-menu.d.ts +26 -0
- package/lib/types/client/presentation/export-view.d.ts +63 -0
- package/lib/types/client/presentation/host-entry.d.ts +8 -2
- package/lib/types/client/presentation/icons.d.ts +1 -1
- package/lib/types/client/presentation/model.d.ts +14 -15
- package/lib/types/client/presentation/reader.d.ts +15 -2
- package/lib/types/client/presentation/reference-source.d.ts +9 -0
- package/lib/types/client/presentation/source-code-model.d.ts +2 -1
- package/lib/types/client/presentation/source-code.d.ts +0 -5
- package/lib/types/client/presentation/source-dialog.d.ts +1 -2
- package/lib/types/client/presentation/sources.d.ts +5 -5
- package/lib/types/client/presentation/styles.d.ts +1 -1
- package/lib/types/client/presentation/table.d.ts +5 -1
- package/lib/types/client/python-tool/card.d.ts +2 -0
- package/lib/types/client/python-tool/execution-error.d.ts +3 -0
- package/lib/types/client/python-tool/install.d.ts +2 -0
- package/lib/types/client/python-tool/model.d.ts +20 -0
- package/lib/types/client/right-tabs/install.d.ts +18 -0
- package/lib/types/client/right-tabs/live-delivery.d.ts +8 -0
- package/lib/types/client/right-tabs/navigation.d.ts +17 -0
- package/lib/types/client/right-tabs/page.d.ts +36 -0
- package/lib/types/client/right-tabs/styles.d.ts +2 -0
- package/lib/types/client/rpc.d.ts +3 -0
- package/lib/types/client/semantic-reference.d.ts +4 -0
- package/lib/types/client/settings/card.d.ts +9 -0
- package/lib/types/client/settings/install.d.ts +2 -0
- package/lib/types/client/workspace-header-action.d.ts +1 -1
- package/lib/types/client/workspace-shortcuts.d.ts +15 -0
- package/lib/types/client.d.ts +5 -2
- package/lib/types/compatibility.d.ts +1 -1
- package/lib/types/datasource/authoring.d.ts +10 -0
- package/lib/types/datasource/bridge.d.ts +23 -2
- package/lib/types/datasource/changes-contract.d.ts +18 -0
- package/lib/types/datasource/changes.d.ts +15 -0
- package/lib/types/datasource/configure.d.ts +7 -0
- package/lib/types/datasource/defaults.d.ts +7 -0
- package/lib/types/datasource/index.d.ts +6 -1
- package/lib/types/datasource/python-options.d.ts +8 -0
- package/lib/types/datasource/python.d.ts +17 -2
- package/lib/types/datasource/rpc.d.ts +2 -1
- package/lib/types/datasource/service.d.ts +48 -5
- package/lib/types/datasource/test.d.ts +1 -1
- package/lib/types/disclosure/activation.d.ts +2 -1
- package/lib/types/disclosure/execution-guidance.d.ts +6 -0
- package/lib/types/disclosure/help.d.ts +1 -1
- package/lib/types/environment/types.d.ts +2 -1
- package/lib/types/environment/workspace.d.ts +1 -0
- package/lib/types/lifecycle.d.ts +8 -0
- package/lib/types/plugin-agents.d.ts +29 -0
- package/lib/types/plugin.d.ts +12 -28
- package/lib/types/presentation/asset.d.ts +6 -0
- package/lib/types/presentation/build/index.d.ts +7 -2
- package/lib/types/presentation/commit.d.ts +1 -1
- package/lib/types/presentation/contracts/asset-path.d.ts +2 -0
- package/lib/types/presentation/contracts/catalog.d.ts +27 -0
- package/lib/types/presentation/contracts/charts.d.ts +0 -2
- package/lib/types/presentation/contracts/types.d.ts +7 -4
- package/lib/types/presentation/delivery.d.ts +1 -1
- package/lib/types/presentation/export-html.d.ts +13 -0
- package/lib/types/presentation/reports.d.ts +6 -1
- package/lib/types/presentation/rpc.d.ts +3 -2
- package/lib/types/presentation/tool.d.ts +2 -2
- package/lib/types/report-publishing/adapters.d.ts +6 -0
- package/lib/types/report-publishing/config.d.ts +22 -0
- package/lib/types/report-publishing/service.d.ts +68 -0
- package/lib/types/rpc.d.ts +3 -0
- package/lib/types/semantic-browser/contracts.d.ts +7 -0
- package/lib/types/semantic-browser/service.d.ts +7 -1
- package/lib/types/semantic-reference/bridge.d.ts +1 -0
- package/lib/types/semantic-reference/contracts.d.ts +5 -2
- package/lib/types/semantic-reference/environment.d.ts +22 -0
- package/lib/types/semantic-reference/labels.d.ts +16 -0
- package/lib/types/semantic-reference/rpc.d.ts +1 -1
- package/lib/types/semantic-reference/search.d.ts +1 -1
- package/lib/types/settings.d.ts +14 -0
- package/lib/types/tool-lifecycle.d.ts +4 -0
- package/lib/types/workspace-identity.d.ts +6 -0
- package/lib/workspace-identity.js +9 -0
- package/package.json +93 -61
- package/python/presentation-kit/dist/dsh_data_analysis_presentation_kit-1.1.0-py3-none-any.whl +0 -0
- package/skills/dsh-data-analysis-files/SKILL.md +44 -0
- package/skills/dsh-data-analysis-files/references/delivery.md +15 -0
- package/skills/dsh-data-analysis-files/references/examples.md +93 -0
- package/skills/dsh-data-analysis-presentation/SKILL.md +15 -15
- package/skills/dsh-data-analysis-presentation/references/examples/artifact.draft.json +13 -4
- package/skills/dsh-data-analysis-presentation/references/examples/charts.draft.json +3 -2
- package/skills/dsh-data-analysis-presentation/references/examples/comparison.draft.json +3 -2
- package/skills/dsh-data-analysis-presentation/references/examples/computed-sources.draft.json +12 -5
- package/skills/dsh-data-analysis-presentation/references/examples/computed.draft.json +3 -2
- package/skills/dsh-data-analysis-presentation/references/examples/interaction.draft.json +3 -2
- package/skills/dsh-data-analysis-presentation/references/examples/source-only.draft.json +12 -4
- package/skills/dsh-data-analysis-presentation/references/examples.md +3 -1
- package/skills/dsh-data-analysis-presentation/references/export-html.md +7 -0
- package/skills/dsh-data-analysis-presentation/references/interaction.md +1 -1
- package/skills/dsh-data-analysis-presentation/references/narrative.md +1 -1
- package/skills/dsh-data-analysis-presentation/references/publishing.md +3 -0
- package/skills/dsh-data-analysis-presentation/references/schema.md +29 -2
- package/lib/types/client/presentation/install.d.ts +0 -15
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { executionErrorSummary } from "./execution-error.js";
|
|
2
|
+
function record(value) {
|
|
3
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
4
|
+
? value
|
|
5
|
+
: undefined;
|
|
6
|
+
}
|
|
7
|
+
function parse(text) {
|
|
8
|
+
try {
|
|
9
|
+
return record(JSON.parse(text));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Read only the frozen Harness call; never fetch results or infer execution from settlement. */
|
|
16
|
+
export function pythonToolModel(block) {
|
|
17
|
+
const done = 'kind' in block;
|
|
18
|
+
const input = (done ? block.call?.argsRaw : block.argsRaw) ?? '';
|
|
19
|
+
const args = parse(input);
|
|
20
|
+
const code = typeof args?.code === 'string' ? args.code : undefined;
|
|
21
|
+
const output = done
|
|
22
|
+
? block.content
|
|
23
|
+
.map((part) => (part.type === 'text' ? part.text : JSON.stringify(part)))
|
|
24
|
+
.join('\n')
|
|
25
|
+
: undefined;
|
|
26
|
+
const result = output === undefined ? undefined : parse(output);
|
|
27
|
+
const errorExecution = done &&
|
|
28
|
+
block.isError &&
|
|
29
|
+
result === undefined &&
|
|
30
|
+
block.content.length === 1 &&
|
|
31
|
+
block.content[0]?.type === 'text'
|
|
32
|
+
? executionErrorSummary(block.content[0].text)
|
|
33
|
+
: undefined;
|
|
34
|
+
const execution = errorExecution ?? record(result?.execution);
|
|
35
|
+
const reason = execution?.reason;
|
|
36
|
+
let state = 'unknown';
|
|
37
|
+
if (!done)
|
|
38
|
+
state = 'running';
|
|
39
|
+
else if (block.error?.code === 'interrupted')
|
|
40
|
+
state = 'cancelled';
|
|
41
|
+
else if (block.isError) {
|
|
42
|
+
// A failed tool invocation can still leave the Python outcome unknown.
|
|
43
|
+
// A success claim in an error message must never promote the call to success.
|
|
44
|
+
state =
|
|
45
|
+
errorExecution &&
|
|
46
|
+
errorExecution.reason !== 'succeeded' &&
|
|
47
|
+
errorExecution.reason !== 'nonzero-exit'
|
|
48
|
+
? errorExecution.reason
|
|
49
|
+
: 'failed';
|
|
50
|
+
}
|
|
51
|
+
else if (result?.timedOut === true || reason === 'timed-out')
|
|
52
|
+
state = 'timed-out';
|
|
53
|
+
else if (result?.aborted === true || reason === 'cancelled' || result?.status === 'cancelled')
|
|
54
|
+
state = 'cancelled';
|
|
55
|
+
else if (result?.status === 'failed' || reason === 'nonzero-exit')
|
|
56
|
+
state = 'failed';
|
|
57
|
+
else if (reason === 'not-started' ||
|
|
58
|
+
execution?.phase === 'preparing' ||
|
|
59
|
+
['needs-credentials', 'needs-configuration', 'call-ended', 'context-changed'].includes(String(result?.status)))
|
|
60
|
+
state = 'not-started';
|
|
61
|
+
else if (typeof result?.exitCode === 'number' && result.exitCode !== 0)
|
|
62
|
+
state = 'failed';
|
|
63
|
+
else if ((reason === undefined || reason === 'succeeded') &&
|
|
64
|
+
result?.exitCode === 0 &&
|
|
65
|
+
result.timedOut === false &&
|
|
66
|
+
result.aborted === false)
|
|
67
|
+
state = result.codeCaptureError || result.truncated === true ? 'warning' : 'succeeded';
|
|
68
|
+
const facts = [];
|
|
69
|
+
for (const name of ['exitCode', 'timedOut', 'aborted', 'truncated']) {
|
|
70
|
+
const value = result?.[name];
|
|
71
|
+
if (typeof value === 'number' || typeof value === 'boolean' || value === null)
|
|
72
|
+
facts.push({ name, value: String(value) });
|
|
73
|
+
}
|
|
74
|
+
for (const name of ['effectiveTimeoutMs', 'elapsedMs', 'executionElapsedMs']) {
|
|
75
|
+
const value = execution?.[name];
|
|
76
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
77
|
+
facts.push({ name, value: `${value} ms` });
|
|
78
|
+
}
|
|
79
|
+
const notices = [result?.codeCaptureError, execution?.nextAction].filter((value) => typeof value === 'string' && value !== '');
|
|
80
|
+
const stdout = typeof result?.stdout === 'string' ? result.stdout : undefined;
|
|
81
|
+
const stderr = typeof result?.stderr === 'string' ? result.stderr : undefined;
|
|
82
|
+
return {
|
|
83
|
+
state,
|
|
84
|
+
input,
|
|
85
|
+
output,
|
|
86
|
+
code,
|
|
87
|
+
facts,
|
|
88
|
+
summary: (code ?? input).split(/\r?\n/).find((line) => line.trim()) ?? block.callId,
|
|
89
|
+
datasources: Array.isArray(args?.datasources) && args.datasources.every((v) => typeof v === 'string')
|
|
90
|
+
? args.datasources
|
|
91
|
+
: undefined,
|
|
92
|
+
timeoutMs: typeof args?.timeoutMs === 'number' ? args.timeoutMs : undefined,
|
|
93
|
+
stdout,
|
|
94
|
+
stderr,
|
|
95
|
+
notices: [...new Set(notices)],
|
|
96
|
+
// Non-execution results (including credential responses) remain directly readable.
|
|
97
|
+
fallback: done && stdout === undefined && stderr === undefined
|
|
98
|
+
? output || (block.error ? `${block.error.name}: ${block.error.code}` : '')
|
|
99
|
+
: undefined,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { credentialChanges } from "../credentials/changes.js";
|
|
4
|
+
import { CredentialPanel, installCredentials } from "../credentials/install.js";
|
|
5
|
+
import { credentialStyles } from "../credentials/styles.js";
|
|
6
|
+
import { useCopy } from "./../i18n/context.js";
|
|
7
|
+
import { hostCopy, installCopy, localized } from "../i18n/host.js";
|
|
8
|
+
import { appendPresentationContext } from "../presentation/ask-dsh.js";
|
|
9
|
+
import { catalogStyles, ReportCatalogView, ReportHistoryPanel } from "../presentation/catalog.js";
|
|
10
|
+
import { marivoPresentationDeliveryDefinition, PRESENTATION_TURN_DATA_KEY, } from "../presentation/delivery.js";
|
|
11
|
+
import { HostPresentationReader } from "../presentation/host-entry.js";
|
|
12
|
+
import { installPresentationReferenceSource } from "../presentation/reference-source.js";
|
|
13
|
+
import { createPluginRpc } from "../rpc.js";
|
|
14
|
+
import { SemanticBrowserPanel } from "../semantic-browser/panel.js";
|
|
15
|
+
import { installSemanticReferenceSource } from "../semantic-reference-source.js";
|
|
16
|
+
import { WorkspaceHeaderAction } from "../workspace-header-action.js";
|
|
17
|
+
import { WorkspaceShortcuts, workspaceDirectories } from "../workspace-shortcuts.js";
|
|
18
|
+
import { LiveDeliveryObserver } from "./live-delivery.js";
|
|
19
|
+
import { canOpenResource, definitionId, directoryKind, parseResource, resourceAddress, } from "./navigation.js";
|
|
20
|
+
import { TabPage } from "./page.js";
|
|
21
|
+
import { rightTabStyles } from "./styles.js";
|
|
22
|
+
export const inject = [
|
|
23
|
+
'connection',
|
|
24
|
+
'remote',
|
|
25
|
+
'slots',
|
|
26
|
+
'locale',
|
|
27
|
+
'uiConversation',
|
|
28
|
+
'inputTriggers',
|
|
29
|
+
'sessions',
|
|
30
|
+
'workspaces',
|
|
31
|
+
'conversation',
|
|
32
|
+
'sidebarRight',
|
|
33
|
+
'sidebarRightTabs',
|
|
34
|
+
];
|
|
35
|
+
const labels = workspaceDirectories;
|
|
36
|
+
/** Default browser integration. Layout belongs to Harness; mutable content belongs to occurrences. */
|
|
37
|
+
export function installRightTabs(ctx, { diagnostics = false } = {}) {
|
|
38
|
+
installCopy(ctx);
|
|
39
|
+
const rpc = createPluginRpc(ctx.connection.rpc);
|
|
40
|
+
const pages = new Map();
|
|
41
|
+
let indexRevision = 0;
|
|
42
|
+
const indexListeners = new Set();
|
|
43
|
+
const pageIndex = {
|
|
44
|
+
getSnapshot: () => indexRevision,
|
|
45
|
+
subscribe: (listener) => {
|
|
46
|
+
indexListeners.add(listener);
|
|
47
|
+
return () => indexListeners.delete(listener);
|
|
48
|
+
},
|
|
49
|
+
publish: () => {
|
|
50
|
+
indexRevision++;
|
|
51
|
+
for (const listener of indexListeners)
|
|
52
|
+
listener();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const audit = { opens: [], errors: [], changes: [] };
|
|
56
|
+
let notice = '', listeners = new Set();
|
|
57
|
+
const notices = {
|
|
58
|
+
getSnapshot: () => notice,
|
|
59
|
+
subscribe: (fn) => {
|
|
60
|
+
listeners.add(fn);
|
|
61
|
+
return () => listeners.delete(fn);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const fail = (error) => {
|
|
65
|
+
notice = error instanceof Error ? error.message : String(error);
|
|
66
|
+
if (diagnostics)
|
|
67
|
+
audit.errors.push(notice);
|
|
68
|
+
for (const fn of listeners)
|
|
69
|
+
fn();
|
|
70
|
+
};
|
|
71
|
+
const workspaceFor = (sessionId) => ctx.workspaces.list.getSnapshot().items.find((w) => w.sessionIds.includes(sessionId))
|
|
72
|
+
?.workspaceId;
|
|
73
|
+
const check = (sessionId, workspaceId, foreground = false) => {
|
|
74
|
+
const state = ctx.workspaces.list.getSnapshot();
|
|
75
|
+
if (!sessionId ||
|
|
76
|
+
!workspaceId ||
|
|
77
|
+
!ctx.connection.generation.getSnapshot() ||
|
|
78
|
+
state.phase !== 'ready' ||
|
|
79
|
+
state.state === 'error' ||
|
|
80
|
+
workspaceFor(sessionId) !== workspaceId ||
|
|
81
|
+
(foreground && ctx.sessions.list.getSnapshot().current !== sessionId))
|
|
82
|
+
throw new Error('marivo.navigation.the-owning-session-or-workspace-changed-return-to-its');
|
|
83
|
+
};
|
|
84
|
+
const changed = (workspaceId, reportId) => {
|
|
85
|
+
for (const page of pages.values())
|
|
86
|
+
void page.publicationChanged(workspaceId, reportId);
|
|
87
|
+
};
|
|
88
|
+
const openDirectory = (sessionId, workspaceId, page) => {
|
|
89
|
+
check(sessionId, workspaceId, true);
|
|
90
|
+
ctx.sidebarRight.openTab(directoryKind(page), { params: { workspaceId } });
|
|
91
|
+
};
|
|
92
|
+
const navigate = (sessionId, target, actions = ctx.sidebarRight, automatic = false, params = undefined) => {
|
|
93
|
+
check(sessionId, target.workspaceId, actions === ctx.sidebarRight);
|
|
94
|
+
const address = resourceAddress(target);
|
|
95
|
+
actions.openResource(address, { params });
|
|
96
|
+
if (diagnostics)
|
|
97
|
+
audit.opens.push({ sessionId, address, automatic });
|
|
98
|
+
};
|
|
99
|
+
installSemanticReferenceSource(ctx, rpc);
|
|
100
|
+
installPresentationReferenceSource(ctx);
|
|
101
|
+
const credentials = installCredentials(ctx, rpc, credentialChanges(ctx));
|
|
102
|
+
ctx.effect(() => credentials.subscribe(() => {
|
|
103
|
+
const state = credentials.getSnapshot();
|
|
104
|
+
for (const page of pages.values())
|
|
105
|
+
if (page.target.kind === 'datasources' && !page.getSnapshot().error)
|
|
106
|
+
page.datasources.syncRequests(page.sessionId, state);
|
|
107
|
+
if (!state.open || !state.requestId)
|
|
108
|
+
return;
|
|
109
|
+
const request = state.requests.find((item) => item.id === state.requestId);
|
|
110
|
+
credentials.close();
|
|
111
|
+
if (!request)
|
|
112
|
+
return;
|
|
113
|
+
try {
|
|
114
|
+
const workspaceId = workspaceFor(request.sessionId);
|
|
115
|
+
check(request.sessionId, workspaceId, true);
|
|
116
|
+
ctx.sidebarRight.openTab(directoryKind('datasources'), {
|
|
117
|
+
params: { workspaceId, requestId: request.id },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
fail(error);
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
const edit = async (page) => {
|
|
125
|
+
check(page.sessionId, page.target.workspaceId, true);
|
|
126
|
+
await page.reader.beginCurrentEdit(() => check(page.sessionId, page.target.workspaceId, true));
|
|
127
|
+
};
|
|
128
|
+
const save = async (page, tab) => {
|
|
129
|
+
check(page.sessionId, page.target.workspaceId, true);
|
|
130
|
+
const before = page.reader.getSnapshot().document?.buildId;
|
|
131
|
+
await page.reader.saveEdit();
|
|
132
|
+
const state = page.reader.getSnapshot();
|
|
133
|
+
if (state.editError || !state.document || state.document.buildId === before)
|
|
134
|
+
return;
|
|
135
|
+
check(page.sessionId, page.target.workspaceId);
|
|
136
|
+
page.patch({ newer: undefined, notice: '' });
|
|
137
|
+
changed(page.target.workspaceId, page.target.reportId);
|
|
138
|
+
if (page.target.buildId) {
|
|
139
|
+
// A Build address remains immutable. Adopt current in the same pane/strip position after save.
|
|
140
|
+
tab.actions.openResource(resourceAddress({
|
|
141
|
+
kind: 'report',
|
|
142
|
+
workspaceId: page.target.workspaceId,
|
|
143
|
+
reportId: page.target.reportId,
|
|
144
|
+
}), { replaceTab: tab.id, revealIfOpened: false });
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const ask = (page, context) => {
|
|
148
|
+
check(page.sessionId, page.target.workspaceId, true);
|
|
149
|
+
if (page.reader.getSnapshot().editing || page.reader.getSnapshot().saving)
|
|
150
|
+
throw new Error('marivo.presentation.save-or-cancel-edits-first');
|
|
151
|
+
if (!page.reader.getSnapshot().document || page.getSnapshot().error || page.signal.aborted)
|
|
152
|
+
throw new Error('marivo.navigation.the-report-is-unavailable-reopen-it');
|
|
153
|
+
appendPresentationContext(ctx, page.sessionId, page.target.workspaceId, context);
|
|
154
|
+
};
|
|
155
|
+
const act = (page, operation) => {
|
|
156
|
+
Promise.resolve()
|
|
157
|
+
.then(operation)
|
|
158
|
+
.catch((error) => page.patch({ notice: error.message }));
|
|
159
|
+
};
|
|
160
|
+
const acquire = (sessionId, tab, target) => {
|
|
161
|
+
check(sessionId, target.workspaceId);
|
|
162
|
+
const key = JSON.stringify([sessionId, tab.id]);
|
|
163
|
+
let page = pages.get(key);
|
|
164
|
+
if (page &&
|
|
165
|
+
(page.signal !== tab.signal || JSON.stringify(page.target) !== JSON.stringify(target))) {
|
|
166
|
+
page.detachSignal?.();
|
|
167
|
+
page.dispose();
|
|
168
|
+
pages.delete(key);
|
|
169
|
+
page = undefined;
|
|
170
|
+
}
|
|
171
|
+
if (!page) {
|
|
172
|
+
page = new TabPage(sessionId, target, rpc, tab.id);
|
|
173
|
+
page.workspacePath = ctx.workspaces.list
|
|
174
|
+
.getSnapshot()
|
|
175
|
+
.items.find((w) => w.workspaceId === target.workspaceId)?.path;
|
|
176
|
+
page.signal = tab.signal;
|
|
177
|
+
pages.set(key, page);
|
|
178
|
+
pageIndex.publish();
|
|
179
|
+
const owned = page;
|
|
180
|
+
const abort = () => {
|
|
181
|
+
owned.dispose();
|
|
182
|
+
if (pages.get(key) === owned) {
|
|
183
|
+
pages.delete(key);
|
|
184
|
+
pageIndex.publish();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
tab.signal.addEventListener('abort', abort, { once: true });
|
|
188
|
+
page.detachSignal = () => tab.signal.removeEventListener('abort', abort);
|
|
189
|
+
}
|
|
190
|
+
return page;
|
|
191
|
+
};
|
|
192
|
+
function Contents({ page, tab, panelId, workspaces, sessions, currentSession, workspaceReady }) {
|
|
193
|
+
const t = useCopy();
|
|
194
|
+
const owners = workspaces.filter((workspace) => workspace.sessionIds.includes(page.sessionId));
|
|
195
|
+
const canAsk = currentSession === page.sessionId &&
|
|
196
|
+
workspaceReady &&
|
|
197
|
+
owners.length === 1 &&
|
|
198
|
+
owners[0].workspaceId === page.target.workspaceId;
|
|
199
|
+
const state = useSyncExternalStore(page.subscribe, page.getSnapshot);
|
|
200
|
+
const report = useSyncExternalStore(page.reader.subscribe, page.reader.getSnapshot);
|
|
201
|
+
const catalog = useSyncExternalStore(page.catalog.subscribe, page.catalog.getSnapshot);
|
|
202
|
+
const open = (target) => act(page, () => navigate(page.sessionId, target, tab.actions));
|
|
203
|
+
const source = (ref) => navigate(page.sessionId, { kind: 'semantic', workspaceId: page.target.workspaceId, ref }, tab.actions);
|
|
204
|
+
const catalogReader = {
|
|
205
|
+
showReport: (workspaceId, reportId) => open({ kind: 'report', workspaceId, reportId }),
|
|
206
|
+
};
|
|
207
|
+
const historyModel = {
|
|
208
|
+
selectVersion: (buildId) => open({
|
|
209
|
+
kind: 'report',
|
|
210
|
+
workspaceId: page.target.workspaceId,
|
|
211
|
+
reportId: page.target.reportId,
|
|
212
|
+
...(buildId && buildId !== report.history?.currentBuildId ? { buildId } : {}),
|
|
213
|
+
}),
|
|
214
|
+
};
|
|
215
|
+
return (_jsxs("section", { className: "rt-page", "data-rt-tab": tab.id, "data-rt-panel": panelId, "data-rt-kind": page.target.kind, "data-rt-workspace": page.target.workspaceId, "data-rt-build": report.document?.buildId, "data-rt-current": page.target.kind === 'report' && !page.target.buildId ? 'true' : undefined, children: [_jsx("style", { children: catalogStyles + credentialStyles + rightTabStyles }), state.error ? (_jsx("p", { role: "alert", children: t(state.error) })) : (_jsxs(_Fragment, { children: [page.target.kind === 'reports' && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "rt-heading-row", children: [_jsx("h2", { className: "rt-heading", children: t(labels[page.target.kind]) }), page.target.kind === 'reports' && (_jsx("button", { type: "button", disabled: catalog.loading, onClick: () => void page.refresh(), children: t('marivo.presentation.refresh') }))] }), _jsx("p", { className: "rt-caption", children: workspaces.find((w) => w.workspaceId === page.target.workspaceId)?.title ??
|
|
216
|
+
page.target.workspaceId })] })), state.newer && (_jsxs("p", { role: "status", className: "rt-notice", children: [t('marivo.navigation.a-newer-version-exists-the-current-view-is-unchanged'), _jsx("button", { type: "button", onClick: () => void page.refresh(), children: t('marivo.navigation.view-new-version') })] })), state.notice && _jsx("p", { role: "status", children: t(state.notice) }), page.target.kind === 'reports' && (_jsx(ReportCatalogView, { model: page.catalog, reader: catalogReader, sessions: sessions, onOpenSession: (id) => ctx.sessions.open(id) })), page.target.kind === 'semantic' && (_jsx(SemanticBrowserPanel, { model: page.semantic, onAsk: canAsk ? () => page.semantic.addToQuestion(ctx, page.sessionId) : undefined, workspaces: workspaces })), page.target.kind === 'datasources' && (_jsx(CredentialPanel, { model: page.datasources, workspaces: workspaces, onRefresh: () => void page.refresh() })), page.target.kind === 'report' && (_jsxs(_Fragment, { children: [report.editing && (_jsxs("div", { className: "rt-toolbar", role: "toolbar", "aria-label": t('marivo.presentation.report-editing-actions'), children: [_jsx("button", { type: "button", disabled: report.saving || !report.editing.undo.length, onClick: () => page.reader.undoEdit(), children: t('marivo.presentation.undo') }), _jsx("button", { type: "button", disabled: report.saving || !report.editing.redo.length, onClick: () => page.reader.redoEdit(), children: t('marivo.presentation.redo') }), _jsx("button", { type: "button", disabled: report.saving, onClick: () => act(page, () => save(page, tab)), children: report.saving
|
|
217
|
+
? t('marivo.presentation.saving')
|
|
218
|
+
: t('marivo.presentation.save-edits') }), _jsx("button", { type: "button", disabled: report.saving, onClick: () => {
|
|
219
|
+
if (!page.reader.dirty ||
|
|
220
|
+
window.confirm(t('marivo.navigation.there-are-unsaved-edits-discard-them')))
|
|
221
|
+
page.reader.cancelEdit();
|
|
222
|
+
}, children: t('marivo.presentation.cancel-edits') }), _jsx("span", { children: page.reader.dirty
|
|
223
|
+
? t('marivo.presentation.unsaved-edits')
|
|
224
|
+
: t('marivo.presentation.edit-mode') })] })), report.editError && _jsx("p", { role: "alert", children: t(report.editError) }), report.notice && _jsx("p", { role: "status", children: t(report.notice) }), report.publicationUrl && (_jsx("p", { children: _jsx("a", { href: report.publicationUrl, target: "_blank", rel: "noopener noreferrer", children: t('marivo.presentation.open-published-report') }) })), report.loading && _jsx("p", { role: "status", children: t('marivo.navigation.loading-report') }), report.error && (_jsxs("div", { role: "alert", children: [_jsx("p", { children: t(report.error) }), _jsx("button", { type: "button", onClick: () => void page.refresh(), children: t('marivo.navigation.reload-report') })] })), report.historyOpen && (_jsx(ReportHistoryPanel, { state: report, model: historyModel, sessions: sessions, onOpenSession: (id) => ctx.sessions.open(id) })), report.document && (_jsx(HostPresentationReader, { document: report.document, closeSourceOnNavigate: true, viewMemory: page.viewMemory, exportActions: {
|
|
225
|
+
downloadFullReport: () => void page.reader.downloadDisplayed(),
|
|
226
|
+
publishing: report.publishingName
|
|
227
|
+
? {
|
|
228
|
+
name: report.publishingName,
|
|
229
|
+
publish: () => void page.reader.publishDisplayed(),
|
|
230
|
+
publishView: (bytes) => page.reader.publishDisplayed(bytes),
|
|
231
|
+
}
|
|
232
|
+
: undefined,
|
|
233
|
+
publishingUnavailable: report.publishingUnavailable,
|
|
234
|
+
publishingLoading: report.publishingLoading,
|
|
235
|
+
downloading: report.downloading,
|
|
236
|
+
disabled: !!report.error || report.loading,
|
|
237
|
+
report: {
|
|
238
|
+
version: report.document.buildId,
|
|
239
|
+
refresh: () => void page.refresh(),
|
|
240
|
+
edit: () => act(page, () => edit(page)),
|
|
241
|
+
history: () => void page.reader.toggleHistory(),
|
|
242
|
+
historical: report.historical || !!state.newer,
|
|
243
|
+
historyLoading: report.historyLoading,
|
|
244
|
+
busy: report.saving,
|
|
245
|
+
},
|
|
246
|
+
}, editing: report.editing
|
|
247
|
+
? {
|
|
248
|
+
edits: report.editing.edits,
|
|
249
|
+
onChange: (edits) => page.reader.changeEdits(edits),
|
|
250
|
+
disabled: report.saving,
|
|
251
|
+
}
|
|
252
|
+
: undefined, onOpenSemanticRef: source, onAskDsh: (context) => act(page, () => {
|
|
253
|
+
ask(page, context);
|
|
254
|
+
page.patch({ notice: '' });
|
|
255
|
+
}) })), report.downloadError && _jsx("p", { role: "alert", children: t(report.downloadError) })] }))] }))] }));
|
|
256
|
+
}
|
|
257
|
+
function Body({ sessionId, useTabInfo, useWorkspaces, useSessions }) {
|
|
258
|
+
const t = useCopy();
|
|
259
|
+
const { tab, panel } = useTabInfo();
|
|
260
|
+
const workspaces = useWorkspaces((s) => s.items), sessions = useSessions((s) => s.byId), currentSession = useSessions((s) => s.current), workspaceReady = useWorkspaces((s) => s.phase === 'ready' && s.state !== 'error');
|
|
261
|
+
const [page, setPage] = useState(), [error, setError] = useState('');
|
|
262
|
+
useEffect(() => {
|
|
263
|
+
if (tab.signal.aborted)
|
|
264
|
+
return;
|
|
265
|
+
try {
|
|
266
|
+
const directory = Object.keys(labels).find((key) => directoryKind(key) === tab.kind);
|
|
267
|
+
const target = directory
|
|
268
|
+
? { kind: directory, workspaceId: tab.navigation.params?.workspaceId }
|
|
269
|
+
: parseResource(tab.navigation.address);
|
|
270
|
+
const owned = acquire(sessionId, tab, target);
|
|
271
|
+
setPage(owned);
|
|
272
|
+
setError('');
|
|
273
|
+
void owned
|
|
274
|
+
.navigate(tab.navigation.revision, false, tab.navigation.params?.history === true)
|
|
275
|
+
.then(() => {
|
|
276
|
+
if (target.kind !== 'datasources' || owned.getSnapshot().error || tab.signal.aborted)
|
|
277
|
+
return;
|
|
278
|
+
owned.datasources.syncRequests(sessionId, credentials.getSnapshot());
|
|
279
|
+
const requestId = tab.navigation.params?.requestId;
|
|
280
|
+
if (owned.datasources.getSnapshot().requests.some((item) => item.id === requestId))
|
|
281
|
+
owned.datasources.openRequest(requestId);
|
|
282
|
+
});
|
|
283
|
+
pageIndex.publish();
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
setPage(undefined);
|
|
287
|
+
setError(error.message);
|
|
288
|
+
}
|
|
289
|
+
}, [sessionId, tab]);
|
|
290
|
+
return error ? (_jsx("p", { role: "alert", children: t(error) })) : page && page.sessionId === sessionId && page.signal === tab.signal ? (_jsx(Contents, { page: page, tab: tab, panelId: panel.id, workspaces: workspaces, sessions: sessions, currentSession: currentSession, workspaceReady: workspaceReady })) : null;
|
|
291
|
+
}
|
|
292
|
+
ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({
|
|
293
|
+
locale: 'marivo.navigation',
|
|
294
|
+
name: 'conversation.input.dock',
|
|
295
|
+
id: 'marivo-workspace-shortcuts',
|
|
296
|
+
order: 100,
|
|
297
|
+
}, localized(ctx, function HomepageShortcuts({ sessionId, session, useConversation, useWorkspaces }) {
|
|
298
|
+
const conversation = useConversation((value) => value);
|
|
299
|
+
const workspaces = useWorkspaces((value) => value);
|
|
300
|
+
const generation = useSyncExternalStore(ctx.connection.generation.subscribe, ctx.connection.generation.getSnapshot, ctx.connection.generation.getSnapshot);
|
|
301
|
+
const workspaceId = workspaces.items.find((w) => w.sessionIds.includes(sessionId))?.workspaceId;
|
|
302
|
+
const disabled = !generation ||
|
|
303
|
+
workspaces.phase !== 'ready' ||
|
|
304
|
+
workspaces.state === 'error' ||
|
|
305
|
+
!workspaceId;
|
|
306
|
+
return (_jsx(WorkspaceShortcuts, { session: sessionId ? session : undefined, conversation: conversation, disabled: disabled, open: (page) => openDirectory(sessionId, workspaceId, page) }, `${sessionId}:${workspaceId}:${!!generation}`));
|
|
307
|
+
})));
|
|
308
|
+
for (const [page, label] of Object.entries(labels)) {
|
|
309
|
+
const kind = directoryKind(page), id = definitionId(kind);
|
|
310
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({ id, kind, title: () => hostCopy(ctx)(label) }));
|
|
311
|
+
ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({ locale: 'marivo.navigation', name: 'sidebar.right.pane.tab.title', key: id }, localized(ctx, function DirectoryTitle() {
|
|
312
|
+
const t = useCopy();
|
|
313
|
+
return _jsx("span", { children: t(label) });
|
|
314
|
+
})));
|
|
315
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({ locale: 'marivo.navigation', name: 'sidebar.right.pane.tab', key: id }, localized(ctx, Body)));
|
|
316
|
+
ctx.slots.inject('conversation.session.header.actions', () => ctx.slots.register({
|
|
317
|
+
locale: 'marivo.navigation',
|
|
318
|
+
name: 'conversation.session.header.actions',
|
|
319
|
+
id,
|
|
320
|
+
order: 100 + Object.keys(labels).indexOf(page) * 5,
|
|
321
|
+
}, localized(ctx, function Entry({ sessionId, useWorkspaces }) {
|
|
322
|
+
const t = useCopy();
|
|
323
|
+
const workspaceId = useWorkspaces((s) => s.items.find((w) => w.sessionIds.includes(sessionId))?.workspaceId);
|
|
324
|
+
return (_jsx(WorkspaceHeaderAction, { label: t(label), icon: page === 'datasources' ? 'credentials' : page, disabled: !workspaceId, onClick: () => {
|
|
325
|
+
try {
|
|
326
|
+
openDirectory(sessionId, workspaceId, page);
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
fail(error);
|
|
330
|
+
}
|
|
331
|
+
} }));
|
|
332
|
+
})));
|
|
333
|
+
}
|
|
334
|
+
function Title({ sessionId, useTabInfo }) {
|
|
335
|
+
const { tab } = useTabInfo();
|
|
336
|
+
useSyncExternalStore(pageIndex.subscribe, pageIndex.getSnapshot);
|
|
337
|
+
const page = pages.get(JSON.stringify([sessionId, tab.id]));
|
|
338
|
+
const report = useSyncExternalStore(page?.reader.subscribe ?? (() => () => { }), page?.reader.getSnapshot ?? (() => undefined));
|
|
339
|
+
const target = parseResource(tab.navigation.address);
|
|
340
|
+
return target.kind === 'report' ? (_jsxs("span", { children: [report?.document?.title ?? target.reportId.slice(0, 12), " \u00B7", ' ', report?.document?.buildId.slice(0, 8) ?? target.buildId?.slice(0, 8) ?? '…', report?.editing ? ' *' : ''] })) : (_jsx("span", { children: target.ref.path }));
|
|
341
|
+
}
|
|
342
|
+
for (const kind of ['report', 'semantic']) {
|
|
343
|
+
const id = definitionId(kind);
|
|
344
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
345
|
+
id,
|
|
346
|
+
kind: `marivo-${kind}-resource`,
|
|
347
|
+
patterns: [`dsh-resource://marivo-${kind}/**`],
|
|
348
|
+
canOpen: (address) => canOpenResource(address, kind),
|
|
349
|
+
title: (address) => {
|
|
350
|
+
const target = parseResource(address);
|
|
351
|
+
return target.kind === 'report'
|
|
352
|
+
? `${target.reportId.slice(0, 12)} · ${target.buildId?.slice(0, 8) ?? '…'}`
|
|
353
|
+
: target.ref.path;
|
|
354
|
+
},
|
|
355
|
+
}));
|
|
356
|
+
ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({ locale: 'marivo.navigation', name: 'sidebar.right.pane.tab.title', key: id }, localized(ctx, Title)));
|
|
357
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({ locale: 'marivo.navigation', name: 'sidebar.right.pane.tab', key: id }, localized(ctx, Body)));
|
|
358
|
+
}
|
|
359
|
+
ctx.slots.inject('conversation.chat.node', () => {
|
|
360
|
+
const stop = ctx.slots.register({
|
|
361
|
+
locale: 'marivo.navigation',
|
|
362
|
+
name: 'conversation.chat.node',
|
|
363
|
+
key: PRESENTATION_TURN_DATA_KEY,
|
|
364
|
+
}, localized(ctx, function ReportDeliveryNode() {
|
|
365
|
+
const t = useCopy();
|
|
366
|
+
const error = useSyncExternalStore(notices.subscribe, notices.getSnapshot);
|
|
367
|
+
return error ? _jsx("p", { role: "alert", children: t(error) }) : null;
|
|
368
|
+
}));
|
|
369
|
+
const definition = ctx.uiConversation.events.register(marivoPresentationDeliveryDefinition);
|
|
370
|
+
return () => {
|
|
371
|
+
definition();
|
|
372
|
+
stop();
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
const feeds = new Map();
|
|
376
|
+
let selected;
|
|
377
|
+
const stopFeeds = () => {
|
|
378
|
+
for (const feed of feeds.values())
|
|
379
|
+
feed.stop();
|
|
380
|
+
feeds.clear();
|
|
381
|
+
selected = undefined;
|
|
382
|
+
};
|
|
383
|
+
const bind = () => {
|
|
384
|
+
if (!ctx.connection.generation.getSnapshot())
|
|
385
|
+
return stopFeeds();
|
|
386
|
+
const current = ctx.sessions.list.getSnapshot().current;
|
|
387
|
+
const workspaces = ctx.workspaces.list.getSnapshot();
|
|
388
|
+
if (workspaces.phase !== 'ready' || workspaces.state === 'error')
|
|
389
|
+
return stopFeeds();
|
|
390
|
+
// Observe only Workspaces with report readers/catalogs, plus the foreground
|
|
391
|
+
// Session. Resolving a binding never opens its history or creates a Session.
|
|
392
|
+
const watchedWorkspaces = new Set([...pages.values()]
|
|
393
|
+
.filter((page) => ['report', 'reports'].includes(page.target.kind) && !page.getSnapshot().error)
|
|
394
|
+
.map((page) => page.target.workspaceId));
|
|
395
|
+
const ids = new Set(workspaces.items.flatMap((w) => (watchedWorkspaces.has(w.workspaceId) ? w.sessionIds : [])));
|
|
396
|
+
if (current)
|
|
397
|
+
ids.add(current);
|
|
398
|
+
for (const [id, feed] of feeds)
|
|
399
|
+
if (!ids.has(id) ||
|
|
400
|
+
ctx.sessions.binding(id) !== feed.binding ||
|
|
401
|
+
feed.binding.session.getSnapshot().removed) {
|
|
402
|
+
feed.stop();
|
|
403
|
+
feeds.delete(id);
|
|
404
|
+
}
|
|
405
|
+
for (const id of ids) {
|
|
406
|
+
if (feeds.has(id))
|
|
407
|
+
continue;
|
|
408
|
+
const binding = ctx.sessions.binding(id);
|
|
409
|
+
if (!binding || binding.session.getSnapshot().removed)
|
|
410
|
+
continue;
|
|
411
|
+
const observer = new LiveDeliveryObserver(id, (delivery) => {
|
|
412
|
+
const { workspaceId, reportId, buildId } = delivery.receipt;
|
|
413
|
+
try {
|
|
414
|
+
check(id, workspaceId);
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
if (ctx.sessions.list.getSnapshot().current === id)
|
|
418
|
+
fail(error);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
changed(workspaceId, reportId);
|
|
422
|
+
// Publication invalidation is Workspace-wide. Foreground navigation
|
|
423
|
+
// alone is gated, and background deliveries are never queued.
|
|
424
|
+
if (ctx.sessions.list.getSnapshot().current !== id)
|
|
425
|
+
return;
|
|
426
|
+
try {
|
|
427
|
+
navigate(id, { kind: 'report', workspaceId, reportId, buildId }, ctx.sidebarRight, true);
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
fail(error);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
observer.consume(binding.eventSource.getSnapshot(), true);
|
|
434
|
+
const stopFeed = binding.eventSource.subscribe(() => {
|
|
435
|
+
const state = binding.session.getSnapshot();
|
|
436
|
+
const window = binding.eventSource.getSnapshot();
|
|
437
|
+
if (diagnostics)
|
|
438
|
+
audit.changes.push({
|
|
439
|
+
sessionId: id,
|
|
440
|
+
kind: window.change.kind,
|
|
441
|
+
revision: window.revision,
|
|
442
|
+
openState: state.openState,
|
|
443
|
+
});
|
|
444
|
+
observer.consume(window, state.openState !== 'open' || state.removed);
|
|
445
|
+
});
|
|
446
|
+
let running = binding.session.getSnapshot().running;
|
|
447
|
+
const stopLifecycle = binding.session.subscribe(() => {
|
|
448
|
+
const state = binding.session.getSnapshot();
|
|
449
|
+
const settled = running && !state.running;
|
|
450
|
+
running = state.running;
|
|
451
|
+
if (state.removed) {
|
|
452
|
+
feeds.get(id)?.stop();
|
|
453
|
+
feeds.delete(id);
|
|
454
|
+
}
|
|
455
|
+
else if (settled && state.openState !== 'open') {
|
|
456
|
+
// A cold background Session has no event window. Its public run
|
|
457
|
+
// settlement is a hint to re-read publication facts, never to open.
|
|
458
|
+
const workspaceId = workspaceFor(id);
|
|
459
|
+
try {
|
|
460
|
+
check(id, workspaceId);
|
|
461
|
+
changed(workspaceId);
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
/* Revoked context has no publication consumers. */
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
feeds.set(id, {
|
|
469
|
+
binding,
|
|
470
|
+
observer,
|
|
471
|
+
stop: () => {
|
|
472
|
+
stopFeed();
|
|
473
|
+
stopLifecycle();
|
|
474
|
+
},
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (current !== selected) {
|
|
478
|
+
selected = current;
|
|
479
|
+
const feed = feeds.get(current);
|
|
480
|
+
if (feed)
|
|
481
|
+
feed.observer.consume(feed.binding.eventSource.getSnapshot(), true);
|
|
482
|
+
changed(workspaceFor(current));
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
ctx.effect(() => {
|
|
486
|
+
const stop = ctx.sessions.list.subscribe(bind);
|
|
487
|
+
const stopPages = pageIndex.subscribe(bind);
|
|
488
|
+
bind();
|
|
489
|
+
return () => {
|
|
490
|
+
stop();
|
|
491
|
+
stopPages();
|
|
492
|
+
stopFeeds();
|
|
493
|
+
};
|
|
494
|
+
});
|
|
495
|
+
ctx.effect(() => ctx.workspaces.list.subscribe(() => {
|
|
496
|
+
for (const page of pages.values()) {
|
|
497
|
+
try {
|
|
498
|
+
check(page.sessionId, page.target.workspaceId);
|
|
499
|
+
if (ctx.workspaces.list
|
|
500
|
+
.getSnapshot()
|
|
501
|
+
.items.find((w) => w.workspaceId === page.target.workspaceId)?.path !==
|
|
502
|
+
page.workspacePath)
|
|
503
|
+
throw new Error('workspace-changed');
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
page.unavailable('marivo.navigation.workspace-changed-or-is-unavailable-reopen-the-page');
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
bind();
|
|
510
|
+
}));
|
|
511
|
+
ctx.effect(() => ctx.connection.generation.subscribe(() => {
|
|
512
|
+
if (ctx.connection.generation.getSnapshot())
|
|
513
|
+
return;
|
|
514
|
+
stopFeeds();
|
|
515
|
+
for (const page of pages.values())
|
|
516
|
+
page.unavailable('marivo.navigation.host-connection-interrupted-reconnect-and-reopen-the-page');
|
|
517
|
+
}));
|
|
518
|
+
ctx.on('connection/reset', () => {
|
|
519
|
+
for (const page of pages.values())
|
|
520
|
+
page.unavailable('marivo.navigation.host-connection-reset-reopen-the-page');
|
|
521
|
+
stopFeeds();
|
|
522
|
+
bind();
|
|
523
|
+
});
|
|
524
|
+
ctx.effect(() => () => {
|
|
525
|
+
for (const page of pages.values()) {
|
|
526
|
+
page.detachSignal?.();
|
|
527
|
+
page.dispose();
|
|
528
|
+
}
|
|
529
|
+
pages.clear();
|
|
530
|
+
pageIndex.publish();
|
|
531
|
+
indexListeners.clear();
|
|
532
|
+
listeners.clear();
|
|
533
|
+
});
|
|
534
|
+
return { audit, pages, navigate, changed, credentials, resourceAddress, ask };
|
|
535
|
+
}
|