@xpert-ai/plugin-live-dashboard 0.7.0 → 0.7.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.
Files changed (61) hide show
  1. package/.xpertai-plugin/plugin.json +1 -1
  2. package/README.md +2 -2
  3. package/dist/lib/analysis-scene-tool.d.ts +8 -8
  4. package/dist/lib/analysis-scene.schema.d.ts +6 -6
  5. package/dist/lib/bundled-example-source.d.ts +11 -0
  6. package/dist/lib/bundled-example-source.js +60 -0
  7. package/dist/lib/certification.schema.d.ts +4 -0
  8. package/dist/lib/certification.schema.js +14 -0
  9. package/dist/lib/content-capability.js +1 -0
  10. package/dist/lib/dashboard-delivery.d.ts +11 -0
  11. package/dist/lib/dashboard-delivery.js +55 -0
  12. package/dist/lib/dashboard-navigation.d.ts +5 -5
  13. package/dist/lib/dashboard-queries.d.ts +2 -2
  14. package/dist/lib/dashboard-queries.js +2 -2
  15. package/dist/lib/dashboard-view.schema.d.ts +10 -10
  16. package/dist/lib/dashboard.schema.d.ts +18 -0
  17. package/dist/lib/dashboard.schema.js +2 -1
  18. package/dist/lib/dashboard.service.d.ts +11 -2
  19. package/dist/lib/dashboard.service.js +17 -4
  20. package/dist/lib/definition-tools.d.ts +14 -54
  21. package/dist/lib/definition-tools.js +29 -9
  22. package/dist/lib/editing-session.d.ts +4 -4
  23. package/dist/lib/evidence/evidence-diff.d.ts +17 -0
  24. package/dist/lib/evidence/evidence-diff.js +30 -0
  25. package/dist/lib/evidence/evidence-transfers.d.ts +14 -0
  26. package/dist/lib/evidence/evidence-transfers.js +41 -0
  27. package/dist/lib/evidence/evidence-view.provider.d.ts +91 -0
  28. package/dist/lib/evidence/evidence-view.provider.js +92 -0
  29. package/dist/lib/evidence/evidence.entity.d.ts +14 -0
  30. package/dist/lib/evidence/evidence.entity.js +62 -0
  31. package/dist/lib/evidence/evidence.provider.d.ts +43 -0
  32. package/dist/lib/evidence/evidence.provider.js +91 -0
  33. package/dist/lib/evidence/evidence.service.d.ts +67 -0
  34. package/dist/lib/evidence/evidence.service.js +218 -0
  35. package/dist/lib/middleware.d.ts +6 -2
  36. package/dist/lib/middleware.js +95 -11
  37. package/dist/lib/monitor.js +2 -2
  38. package/dist/lib/plugin.js +6 -1
  39. package/dist/lib/query-session.d.ts +1 -1
  40. package/dist/lib/query-session.js +13 -8
  41. package/dist/lib/remote-entry.d.ts +1 -1
  42. package/dist/lib/runtime-context.d.ts +2 -0
  43. package/dist/lib/runtime-context.js +21 -0
  44. package/dist/lib/source-executions.d.ts +36 -18
  45. package/dist/lib/source-executions.js +2 -1
  46. package/dist/lib/templates.js +5 -5
  47. package/dist/lib/view.provider.js +7 -1
  48. package/dist/remote/app.css +1 -1
  49. package/dist/remote/app.js +23 -23
  50. package/dist/remote/build-manifest.json +45 -35
  51. package/dist/sandbox-actions/action.json +1 -1
  52. package/dist/sandbox-actions/bundle/host.js +2 -2
  53. package/docs/editing.mdx +6 -0
  54. package/docs/html-mode.md +1 -1
  55. package/package.json +5 -5
  56. package/skills/live-dashboard/SKILL.md +1 -1
  57. package/skills/live-dashboard/examples/README.md +2 -2
  58. package/skills/live-dashboard/examples/production-quality/README.md +2 -2
  59. package/skills/live-dashboard/examples/regional-sales/README.md +3 -3
  60. package/skills/live-dashboard/examples/regional-sales/query.json +49 -1
  61. package/skills/live-dashboard/examples/sales-overview/README.md +2 -2
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-live-dashboard",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "level": "system",
5
5
  "artifactNamespace": "live_dashboard",
6
6
  "sandboxActions": "./dist/sandbox-actions/action.json",
package/README.md CHANGED
@@ -208,11 +208,11 @@ HTML is capped at 300 KB; the whole saved definition remains capped at 600 KB. H
208
208
 
209
209
  Build reads the compressed renderer assets from the published `@xpert-ai/community-data-analytics@0.1.35` package, copies original renderer bytes into `dist/remote/renderer.html`, and records SHA-256 in `renderer-source.json`. Never edit minified assets. One adapter translates Dataset fields into Data Analytics v1 encodings and snapshots.
210
210
 
211
- The renderer runs in a script-only sandbox with no-network CSP. A small in-memory fetch adapter provides manifest/snapshot/package endpoints because srcDoc has no HTTP origin. Exact table rows are preserved; chart copies convert supported numeric strings and reject precision loss. Render payloads are capped at 3 MB.
211
+ The standard viewer iframe allows scripts and browser file downloads. Its document keeps the renderer CSP, including the no-network fetch policy. A small in-memory fetch adapter provides manifest/snapshot/package endpoints because srcDoc has no HTTP origin. Exact table rows are preserved; chart copies convert supported numeric strings and reject precision loss. Render payloads are capped at 3 MB.
212
212
 
213
213
  ## Build and validation
214
214
 
215
- Use the xpertai workspace's declared Corepack/pnpm. Live Dashboard uses published SDK/contracts 3.35.0 for resource discovery, group sharing and inline widget presentation. Development dependencies pin the Data Analytics renderer to 0.1.35. SDK 3.33.0 supplies the host-owned online resource policy, bounded query scheduler and grouped query runtime without a local SDK patch. Rebuild both the viewer and HTML preflight assets after changing the SDK; `verify:dist` checks their source fingerprints.
215
+ Use the xpertai workspace's declared Corepack/pnpm. The viewer and HTML preflight bundles are built with published `@xpert-ai/plugin-sdk` 3.38.0 and `@xpert-ai/contracts` 3.38.0. SDK 3.38.0 is the first release that applies `allowDownloads` while mounting an artifact document; 3.37.2 and earlier always set `sandbox="allow-scripts"`. Its type surface depends on contracts 3.38.0, so the dashboard build pins that same contracts version and does not keep a second 3.36.0 copy. Host peer ranges stay `^3.36.0`: the Nest plugin does not apply the document sandbox, and the browser bundles do. The interactive HTML viewer passes `allowDownloads: true`. HTML preflight calls the same mount without that option, so its sandbox stays script-only. The standard viewer sets `allow-scripts allow-downloads` on its own iframe and does not call the artifact-document mount. Development dependencies pin the Data Analytics renderer to 0.1.35. SDK 3.33.0 supplies the host-owned online resource policy, bounded query scheduler and grouped query runtime without a local SDK patch. Rebuild both the viewer and HTML preflight assets after changing the SDK; `verify:dist` checks their source fingerprints.
216
216
 
217
217
  ```sh
218
218
  corepack pnpm install --frozen-lockfile
@@ -11,10 +11,10 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
11
11
  direction: import("zod").ZodEnum<["asc", "desc"]>;
12
12
  }, "strict", import("zod").ZodTypeAny, {
13
13
  field: string;
14
- direction: "desc" | "asc";
14
+ direction: "asc" | "desc";
15
15
  }, {
16
16
  field: string;
17
- direction: "desc" | "asc";
17
+ direction: "asc" | "desc";
18
18
  }>>;
19
19
  language: import("zod").ZodOptional<import("zod").ZodEnum<["zh-Hans", "en"]>>;
20
20
  maxRows: import("zod").ZodDefault<import("zod").ZodNumber>;
@@ -26,7 +26,7 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
26
26
  maxRows: number;
27
27
  orderBy?: {
28
28
  field: string;
29
- direction: "desc" | "asc";
29
+ direction: "asc" | "desc";
30
30
  } | undefined;
31
31
  language?: "en" | "zh-Hans" | undefined;
32
32
  }, {
@@ -36,7 +36,7 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
36
36
  previewId: string;
37
37
  orderBy?: {
38
38
  field: string;
39
- direction: "desc" | "asc";
39
+ direction: "asc" | "desc";
40
40
  } | undefined;
41
41
  language?: "en" | "zh-Hans" | undefined;
42
42
  maxRows?: number | undefined;
@@ -48,7 +48,7 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
48
48
  maxRows: number;
49
49
  orderBy?: {
50
50
  field: string;
51
- direction: "desc" | "asc";
51
+ direction: "asc" | "desc";
52
52
  } | undefined;
53
53
  language?: "en" | "zh-Hans" | undefined;
54
54
  }, {
@@ -58,7 +58,7 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
58
58
  previewId: string;
59
59
  orderBy?: {
60
60
  field: string;
61
- direction: "desc" | "asc";
61
+ direction: "asc" | "desc";
62
62
  } | undefined;
63
63
  language?: "en" | "zh-Hans" | undefined;
64
64
  maxRows?: number | undefined;
@@ -70,7 +70,7 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
70
70
  maxRows: number;
71
71
  orderBy?: {
72
72
  field: string;
73
- direction: "desc" | "asc";
73
+ direction: "asc" | "desc";
74
74
  } | undefined;
75
75
  language?: "en" | "zh-Hans" | undefined;
76
76
  }, {
@@ -80,7 +80,7 @@ export declare function createAnalysisSceneTool(query: (previewId: string) => Pr
80
80
  previewId: string;
81
81
  orderBy?: {
82
82
  field: string;
83
- direction: "desc" | "asc";
83
+ direction: "asc" | "desc";
84
84
  } | undefined;
85
85
  language?: "en" | "zh-Hans" | undefined;
86
86
  maxRows?: number | undefined;
@@ -10,10 +10,10 @@ export declare const analysisSceneSchema: z.ZodEffects<z.ZodObject<{
10
10
  direction: z.ZodEnum<["asc", "desc"]>;
11
11
  }, "strict", z.ZodTypeAny, {
12
12
  field: string;
13
- direction: "desc" | "asc";
13
+ direction: "asc" | "desc";
14
14
  }, {
15
15
  field: string;
16
- direction: "desc" | "asc";
16
+ direction: "asc" | "desc";
17
17
  }>>;
18
18
  language: z.ZodOptional<z.ZodEnum<["zh-Hans", "en"]>>;
19
19
  maxRows: z.ZodDefault<z.ZodNumber>;
@@ -25,7 +25,7 @@ export declare const analysisSceneSchema: z.ZodEffects<z.ZodObject<{
25
25
  maxRows: number;
26
26
  orderBy?: {
27
27
  field: string;
28
- direction: "desc" | "asc";
28
+ direction: "asc" | "desc";
29
29
  } | undefined;
30
30
  language?: "en" | "zh-Hans" | undefined;
31
31
  }, {
@@ -35,7 +35,7 @@ export declare const analysisSceneSchema: z.ZodEffects<z.ZodObject<{
35
35
  previewId: string;
36
36
  orderBy?: {
37
37
  field: string;
38
- direction: "desc" | "asc";
38
+ direction: "asc" | "desc";
39
39
  } | undefined;
40
40
  language?: "en" | "zh-Hans" | undefined;
41
41
  maxRows?: number | undefined;
@@ -47,7 +47,7 @@ export declare const analysisSceneSchema: z.ZodEffects<z.ZodObject<{
47
47
  maxRows: number;
48
48
  orderBy?: {
49
49
  field: string;
50
- direction: "desc" | "asc";
50
+ direction: "asc" | "desc";
51
51
  } | undefined;
52
52
  language?: "en" | "zh-Hans" | undefined;
53
53
  }, {
@@ -57,7 +57,7 @@ export declare const analysisSceneSchema: z.ZodEffects<z.ZodObject<{
57
57
  previewId: string;
58
58
  orderBy?: {
59
59
  field: string;
60
- direction: "desc" | "asc";
60
+ direction: "asc" | "desc";
61
61
  } | undefined;
62
62
  language?: "en" | "zh-Hans" | undefined;
63
63
  maxRows?: number | undefined;
@@ -0,0 +1,11 @@
1
+ import type { AnalyticsBinding } from '@xpert-ai/contracts';
2
+ import { z } from 'zod/v3';
3
+ import { type AnalyticsDefinitionAuthoringApi, type AnalyticsAuthoringScope, type WorkspaceFilesApi } from '@xpert-ai/plugin-sdk';
4
+ export declare const exampleIdSchema: z.ZodEnum<["regional-sales", "sales-overview", "production-quality"]>;
5
+ export declare const EXAMPLE_SOURCE_GUIDANCE = "For an explicitly requested bundled demo (regional-sales, sales-overview, production-quality), including a choice made earlier in this conversation, first call analytics_definition_register with only exampleId set to that exact key. When the request matches a returned prepared query, pass its previewRequest unchanged to dashboard_preview_binding. For other requests start from the returned canonical binding. Preserve its source, datasetId, revision and contractHash. Use its actual fields as aggregate inputs, and the aggregate alias as output.sourceField. Preview the requested query before saving. A registered source with similar fields or a similar name is a different dataset. For named registered business sources use dashboard_list_sources as usual.";
6
+ export declare function registerExampleSource(exampleId: z.infer<typeof exampleIdSchema>, projectId: string | undefined, runtime: AnalyticsDefinitionAuthoringApi, scope: AnalyticsAuthoringScope, files: WorkspaceFilesApi): Promise<import("@xpert-ai/plugin-sdk").AnalyticsDefinitionReceipt>;
7
+ export declare function exampleSummaryQuery(exampleId: z.infer<typeof exampleIdSchema>, binding: AnalyticsBinding): Promise<{
8
+ key: string;
9
+ description: string;
10
+ binding: AnalyticsBinding;
11
+ } | undefined>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXAMPLE_SOURCE_GUIDANCE = exports.exampleIdSchema = void 0;
4
+ exports.registerExampleSource = registerExampleSource;
5
+ exports.exampleSummaryQuery = exampleSummaryQuery;
6
+ const node_crypto_1 = require("node:crypto");
7
+ const promises_1 = require("node:fs/promises");
8
+ const node_path_1 = require("node:path");
9
+ const v3_1 = require("zod/v3");
10
+ const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
11
+ // These skill recipes ship a synthetic CSV and a file.table definition. The Superstore recipe uses a governed ontology.
12
+ exports.exampleIdSchema = v3_1.z.enum(['regional-sales', 'sales-overview', 'production-quality']);
13
+ exports.EXAMPLE_SOURCE_GUIDANCE = 'For an explicitly requested bundled demo (regional-sales, sales-overview, production-quality), including a choice made earlier in this conversation, first call analytics_definition_register with only exampleId set to that exact key. When the request matches a returned prepared query, pass its previewRequest unchanged to dashboard_preview_binding. For other requests start from the returned canonical binding. Preserve its source, datasetId, revision and contractHash. Use its actual fields as aggregate inputs, and the aggregate alias as output.sourceField. Preview the requested query before saving. A registered source with similar fields or a similar name is a different dataset. For named registered business sources use dashboard_list_sources as usual.';
14
+ const recipeMetadata = v3_1.z.object({ path: v3_1.z.string(), name: v3_1.z.string().min(1) });
15
+ async function registerExampleSource(exampleId, projectId, runtime, scope, files) {
16
+ if (!projectId)
17
+ throw new Error('DASHBOARD_EXAMPLE_PROJECT_REQUIRED');
18
+ const dir = (0, node_path_1.join)(__dirname, '../../skills/live-dashboard/examples', exports.exampleIdSchema.parse(exampleId));
19
+ const [csv, json] = await Promise.all([(0, promises_1.readFile)((0, node_path_1.join)(dir, 'demo.csv')), (0, promises_1.readFile)((0, node_path_1.join)(dir, 'definition.json'), 'utf8')]);
20
+ const definition = plugin_sdk_1.analyticsOptionsSchema.parse(JSON.parse(json));
21
+ const { path, name } = recipeMetadata.parse(definition);
22
+ const selection = (await runtime.catalog(scope)).find(item => item.providerId === 'file.table');
23
+ if (!selection)
24
+ throw new Error('DASHBOARD_EXAMPLE_FILE_PROVIDER_UNAVAILABLE');
25
+ // Recipes belong to the Project root even when the Agent has a conversation-specific working directory.
26
+ const runtimePath = `/workspace/${path}`;
27
+ const ref = await files.resolveRuntimeReference(runtimePath);
28
+ if (ref.catalog !== 'projects' || ref.projectId !== projectId)
29
+ throw new Error('DASHBOARD_EXAMPLE_PROJECT_MISMATCH');
30
+ try {
31
+ const existing = await files.readBuffer(ref);
32
+ if (!existing.buffer.equals(csv))
33
+ throw new Error('DASHBOARD_EXAMPLE_FILE_CHANGED: the project file differs from the packaged sample.');
34
+ }
35
+ catch (error) {
36
+ if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
37
+ throw error;
38
+ await files.writeRuntimeBuffer({ path: runtimePath, buffer: csv, mimeType: 'text/csv' });
39
+ }
40
+ const hash = (0, node_crypto_1.createHash)('sha256').update(json).update(csv).digest('hex');
41
+ return runtime.register(scope, {
42
+ providerId: selection.providerId, connectionKey: selection.connectionKey,
43
+ requestId: `example-${projectId}-${hash}`, name, definition: { ...definition, path: runtimePath }
44
+ });
45
+ }
46
+ // Prepared queries are authored alongside each bundled sample. Attach them to the registered,
47
+ // inspected binding so source and contract identity always come from the active project.
48
+ async function exampleSummaryQuery(exampleId, binding) {
49
+ const path = (0, node_path_1.join)(__dirname, '../../skills/live-dashboard/examples', exports.exampleIdSchema.parse(exampleId), 'query.json');
50
+ const { summary } = JSON.parse(await (0, promises_1.readFile)(path, 'utf8'));
51
+ if (!summary)
52
+ return;
53
+ const prepared = plugin_sdk_1.analyticsBindingSchema.parse({
54
+ ...binding, parameters: [],
55
+ payload: { ...plugin_sdk_1.analyticsOptionsSchema.parse(binding.payload), select: summary.payloadFields.select, groupBy: summary.payloadFields.groupBy,
56
+ aggregates: summary.payloadFields.aggregates, orderBy: summary.payloadFields.orderBy },
57
+ output: { ...binding.output, grain: summary.grain, fields: summary.fields }
58
+ });
59
+ return { key: `${exampleId}/${summary.key}`, description: String(summary.description), binding: prepared };
60
+ }
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod/v3';
2
+ import type { AnalyticsCertification } from '@xpert-ai/contracts';
3
+ /** Host-response boundary only; authored dashboard JSON cannot supply this proof. */
4
+ export declare const certificationSchema: z.ZodType<AnalyticsCertification>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.certificationSchema = void 0;
4
+ const v3_1 = require("zod/v3");
5
+ /** Host-response boundary only; authored dashboard JSON cannot supply this proof. */
6
+ exports.certificationSchema = v3_1.z.discriminatedUnion('status', [
7
+ v3_1.z.object({ kind: v3_1.z.literal('business_metric'), subjectId: v3_1.z.string().min(1).max(160),
8
+ verifiedAt: v3_1.z.string().datetime(), status: v3_1.z.literal('legacy_unverified') }).strict(),
9
+ v3_1.z.object({ kind: v3_1.z.literal('business_metric'), subjectId: v3_1.z.string().min(1).max(160),
10
+ verifiedAt: v3_1.z.string().datetime(), status: v3_1.z.literal('verified'),
11
+ definitionHash: v3_1.z.string().regex(/^[a-f0-9]{64}$/),
12
+ dependency: v3_1.z.object({ id: v3_1.z.string().min(1).max(160), version: v3_1.z.number().int().nonnegative() }).strict(),
13
+ certifiedBy: v3_1.z.string().min(1).max(160), certifiedAt: v3_1.z.string().datetime() }).strict()
14
+ ]);
@@ -23,6 +23,7 @@ let DashboardCapability = class DashboardCapability {
23
23
  isEnabled(draft) { return (0, plugin_sdk_1.hasAssistantMiddleware)(draft, 'LiveDashboard'); }
24
24
  async check() { return { available: true }; }
25
25
  async apply({ draft }) {
26
+ (0, plugin_sdk_1.applyAssistantMiddleware)(draft, { provider: 'ProjectMiddleware', key: 'Capability_Project', title: 'Projects', instructions: '', preserveToolConcurrency: true });
26
27
  (0, plugin_sdk_1.applyAssistantMiddleware)(draft, { provider: 'LiveDashboard', key: 'Capability_DashboardCapability', title: 'Live dashboards', instructions: 'Maintain live dashboard definitions in the current Project using Live Dashboard tools and registered Analytics providers. Discover and validate current data bindings before saving. Read the current draft revision and handle conflicts without overwriting another editor. Query with the current actor permissions; never copy credentials or query rows into the shared definition. Publishing a definition is separate from saving and refreshing data.' });
27
28
  }
28
29
  };
@@ -0,0 +1,11 @@
1
+ import { type BaseMessage } from '@langchain/core/messages';
2
+ /** Use this turn's actual delivery receipt, including after a checkpoint resume. */
3
+ export declare function dashboardDelivery(messages?: BaseMessage[]): {
4
+ guidance: string;
5
+ verifiedDraft: {
6
+ status: "draft";
7
+ artifactId: string;
8
+ draftRevision: number;
9
+ title?: string | undefined;
10
+ } | undefined;
11
+ } | null;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dashboardDelivery = dashboardDelivery;
4
+ const messages_1 = require("@langchain/core/messages");
5
+ const v3_1 = require("zod/v3");
6
+ const dashboard_receipt_1 = require("./dashboard-receipt");
7
+ const savedCard = v3_1.z.object({
8
+ dashboard: v3_1.z.object({ artifactId: v3_1.z.string().uuid(), title: v3_1.z.string().optional(), draftRevision: v3_1.z.number().int().positive(), status: v3_1.z.literal('draft') }),
9
+ resourceCard: v3_1.z.object({ status: v3_1.z.enum(['emitted', 'unavailable']) })
10
+ });
11
+ const openedDraft = v3_1.z.object({ artifactId: v3_1.z.string().uuid(), state: v3_1.z.literal('draft'), expectedRevision: v3_1.z.number(), readVersionId: v3_1.z.undefined() });
12
+ function output(content) {
13
+ if (typeof content !== 'string')
14
+ return null;
15
+ try {
16
+ return JSON.parse(content);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ /** Use this turn's actual delivery receipt, including after a checkpoint resume. */
23
+ function dashboardDelivery(messages = []) {
24
+ let lastRead;
25
+ let lastTool = true;
26
+ for (let i = messages.length - 1; i >= 0; i--) {
27
+ const message = messages[i];
28
+ if (message.getType() === 'human')
29
+ break;
30
+ if (!(0, messages_1.isToolMessage)(message))
31
+ continue;
32
+ if (lastTool && message.name === 'dashboard_open' && message.status !== 'error') {
33
+ const read = openedDraft.safeParse(output(message.content));
34
+ if (read.success)
35
+ lastRead = read.data;
36
+ }
37
+ lastTool = false;
38
+ if (message.status === 'error' || !message.name || !dashboard_receipt_1.DASHBOARD_MUTATION_TOOLS.includes(message.name))
39
+ continue;
40
+ const result = savedCard.safeParse(output(message.content));
41
+ if (!result.success)
42
+ continue;
43
+ const { dashboard, resourceCard } = result.data;
44
+ return {
45
+ guidance: `Draft ${dashboard.artifactId} revision ${dashboard.draftRevision} is saved. ` +
46
+ (resourceCard.status === 'emitted'
47
+ ? 'Its clickable Open card has already been delivered to this conversation. A request for an openable dashboard or a card is fulfilled by that delivery.'
48
+ : 'Card delivery was unavailable. The saved dashboard is available in the Workbench picker.') +
49
+ ' Reply with the result when this fulfills the request. Use editing tools only for outstanding changes.',
50
+ verifiedDraft: resourceCard.status === 'emitted' && lastRead?.artifactId === dashboard.artifactId &&
51
+ lastRead.expectedRevision === dashboard.draftRevision ? dashboard : undefined
52
+ };
53
+ }
54
+ return null;
55
+ }
@@ -38,11 +38,11 @@ export declare const dashboardNavigationSchema: z.ZodEffects<z.ZodObject<{
38
38
  mode?: "draft" | "published" | undefined;
39
39
  versionId?: string | undefined;
40
40
  draftRevision?: number | undefined;
41
+ contentId?: string | undefined;
41
42
  pipelineInstanceId?: string | undefined;
42
43
  pipelineRoundId?: string | undefined;
43
44
  pipelineNodeId?: string | undefined;
44
45
  contentProvider?: string | undefined;
45
- contentId?: string | undefined;
46
46
  contentTitle?: string | undefined;
47
47
  contentEditor?: string | undefined;
48
48
  newDashboard?: boolean | undefined;
@@ -52,11 +52,11 @@ export declare const dashboardNavigationSchema: z.ZodEffects<z.ZodObject<{
52
52
  mode?: "draft" | "published" | undefined;
53
53
  versionId?: string | undefined;
54
54
  draftRevision?: number | undefined;
55
+ contentId?: string | undefined;
55
56
  pipelineInstanceId?: string | undefined;
56
57
  pipelineRoundId?: string | undefined;
57
58
  pipelineNodeId?: string | undefined;
58
59
  contentProvider?: string | undefined;
59
- contentId?: string | undefined;
60
60
  contentTitle?: string | undefined;
61
61
  contentEditor?: string | undefined;
62
62
  newDashboard?: boolean | undefined;
@@ -68,11 +68,11 @@ export declare const dashboardNavigationSchema: z.ZodEffects<z.ZodObject<{
68
68
  mode?: "draft" | "published" | undefined;
69
69
  versionId?: string | undefined;
70
70
  draftRevision?: number | undefined;
71
+ contentId?: string | undefined;
71
72
  pipelineInstanceId?: string | undefined;
72
73
  pipelineRoundId?: string | undefined;
73
74
  pipelineNodeId?: string | undefined;
74
75
  contentProvider?: string | undefined;
75
- contentId?: string | undefined;
76
76
  contentTitle?: string | undefined;
77
77
  contentEditor?: string | undefined;
78
78
  newDashboard?: boolean | undefined;
@@ -87,11 +87,11 @@ export declare const dashboardNavigationSchema: z.ZodEffects<z.ZodObject<{
87
87
  mode?: "draft" | "published" | undefined;
88
88
  versionId?: string | undefined;
89
89
  draftRevision?: number | undefined;
90
+ contentId?: string | undefined;
90
91
  pipelineInstanceId?: string | undefined;
91
92
  pipelineRoundId?: string | undefined;
92
93
  pipelineNodeId?: string | undefined;
93
94
  contentProvider?: string | undefined;
94
- contentId?: string | undefined;
95
95
  contentTitle?: string | undefined;
96
96
  contentEditor?: string | undefined;
97
97
  newDashboard?: boolean | undefined;
@@ -115,11 +115,11 @@ export declare const dashboardNavigationSchema: z.ZodEffects<z.ZodObject<{
115
115
  mode?: "draft" | "published" | undefined;
116
116
  versionId?: string | undefined;
117
117
  draftRevision?: number | undefined;
118
+ contentId?: string | undefined;
118
119
  pipelineInstanceId?: string | undefined;
119
120
  pipelineRoundId?: string | undefined;
120
121
  pipelineNodeId?: string | undefined;
121
122
  contentProvider?: string | undefined;
122
- contentId?: string | undefined;
123
123
  contentTitle?: string | undefined;
124
124
  contentEditor?: string | undefined;
125
125
  newDashboard?: boolean | undefined;
@@ -1,10 +1,10 @@
1
- import type { AnalyticalDataset, AnalyticsValue } from '@xpert-ai/contracts';
1
+ import type { AnalyticalDataset, AnalyticsValue, AnalyticsQueryRequest } from '@xpert-ai/contracts';
2
2
  import { type DataSourceActor, type RuntimeCapabilityRegistry } from '@xpert-ai/plugin-sdk';
3
3
  import type { DashboardManifest } from './dashboard.schema';
4
4
  export declare function validateControls(manifest: DashboardManifest, input: Record<string, AnalyticsValue>): {
5
5
  [x: string]: AnalyticsValue;
6
6
  };
7
- export declare function queryDashboardBinding(runtime: RuntimeCapabilityRegistry, actor: DataSourceActor, manifest: DashboardManifest, bindingId: string, input: Record<string, AnalyticsValue>): Promise<AnalyticalDataset>;
7
+ export declare function queryDashboardBinding(runtime: RuntimeCapabilityRegistry, actor: DataSourceActor, manifest: DashboardManifest, bindingId: string, input: Record<string, AnalyticsValue>, cache?: AnalyticsQueryRequest['cache']): Promise<AnalyticalDataset>;
8
8
  export declare function queryDashboard(runtime: RuntimeCapabilityRegistry, actor: DataSourceActor, manifest: DashboardManifest, input: Record<string, AnalyticsValue>, progress?: (completed: number) => Promise<void>): Promise<AnalyticalDataset[]>;
9
9
  /** Read-only rendering can show independent successful bindings. Saving/publishing still
10
10
  * uses queryDashboard and requires every binding to validate. Never return native error
@@ -22,13 +22,13 @@ function validateControls(manifest, input) {
22
22
  }
23
23
  return values;
24
24
  }
25
- async function queryDashboardBinding(runtime, actor, manifest, bindingId, input) {
25
+ async function queryDashboardBinding(runtime, actor, manifest, bindingId, input, cache) {
26
26
  const binding = manifest.bindings.find(item => item.id === bindingId);
27
27
  if (!binding)
28
28
  throw new common_1.ForbiddenException('DASHBOARD_BINDING_DENIED');
29
29
  const controls = validateControls(manifest, input);
30
30
  const selected = Object.fromEntries(Object.entries(controls).filter(([id]) => binding.parameters.some(parameter => parameter.controlId === id)));
31
- return runtime.require(plugin_sdk_1.AnalyticsRuntimeCapability).query(actor, { binding, controls: selected });
31
+ return runtime.require(plugin_sdk_1.AnalyticsRuntimeCapability).query(actor, { binding, controls: selected, ...(cache ? { cache } : {}) });
32
32
  }
33
33
  async function queryDashboard(runtime, actor, manifest, input, progress) {
34
34
  validateControls(manifest, input);
@@ -801,23 +801,23 @@ export declare const dashboardSavedSchema: z.ZodObject<{
801
801
  source: z.ZodString;
802
802
  }, "strict", z.ZodTypeAny, {
803
803
  id?: string;
804
+ source?: string;
804
805
  version?: string;
805
806
  sha256?: string;
806
- source?: string;
807
807
  format?: "classic-script";
808
808
  global?: string;
809
809
  }, {
810
810
  id?: string;
811
+ source?: string;
811
812
  version?: string;
812
813
  sha256?: string;
813
- source?: string;
814
814
  format?: "classic-script";
815
815
  global?: string;
816
816
  }>, import("@xpert-ai/plugin-sdk/artifact-document").ArtifactDocumentDependencyAsset, {
817
817
  id?: string;
818
+ source?: string;
818
819
  version?: string;
819
820
  sha256?: string;
820
- source?: string;
821
821
  format?: "classic-script";
822
822
  global?: string;
823
823
  }>, "many">>;
@@ -1010,9 +1010,9 @@ export declare const dashboardSavedSchema: z.ZodObject<{
1010
1010
  title?: string | null | undefined;
1011
1011
  dependencies?: {
1012
1012
  id?: string;
1013
+ source?: string;
1013
1014
  version?: string;
1014
1015
  sha256?: string;
1015
- source?: string;
1016
1016
  format?: "classic-script";
1017
1017
  global?: string;
1018
1018
  }[] | undefined;
@@ -1853,23 +1853,23 @@ export declare const dashboardViewDataSchema: z.ZodObject<{
1853
1853
  source: z.ZodString;
1854
1854
  }, "strict", z.ZodTypeAny, {
1855
1855
  id?: string;
1856
+ source?: string;
1856
1857
  version?: string;
1857
1858
  sha256?: string;
1858
- source?: string;
1859
1859
  format?: "classic-script";
1860
1860
  global?: string;
1861
1861
  }, {
1862
1862
  id?: string;
1863
+ source?: string;
1863
1864
  version?: string;
1864
1865
  sha256?: string;
1865
- source?: string;
1866
1866
  format?: "classic-script";
1867
1867
  global?: string;
1868
1868
  }>, import("@xpert-ai/plugin-sdk/artifact-document").ArtifactDocumentDependencyAsset, {
1869
1869
  id?: string;
1870
+ source?: string;
1870
1871
  version?: string;
1871
1872
  sha256?: string;
1872
- source?: string;
1873
1873
  format?: "classic-script";
1874
1874
  global?: string;
1875
1875
  }>, "many">>;
@@ -2062,9 +2062,9 @@ export declare const dashboardViewDataSchema: z.ZodObject<{
2062
2062
  title?: string | null | undefined;
2063
2063
  dependencies?: {
2064
2064
  id?: string;
2065
+ source?: string;
2065
2066
  version?: string;
2066
2067
  sha256?: string;
2067
- source?: string;
2068
2068
  format?: "classic-script";
2069
2069
  global?: string;
2070
2070
  }[] | undefined;
@@ -2382,9 +2382,9 @@ export declare const dashboardViewDataSchema: z.ZodObject<{
2382
2382
  title?: string | null | undefined;
2383
2383
  dependencies?: {
2384
2384
  id?: string;
2385
+ source?: string;
2385
2386
  version?: string;
2386
2387
  sha256?: string;
2387
- source?: string;
2388
2388
  format?: "classic-script";
2389
2389
  global?: string;
2390
2390
  }[] | undefined;
@@ -2717,9 +2717,9 @@ export declare const dashboardViewDataSchema: z.ZodObject<{
2717
2717
  title?: string | null | undefined;
2718
2718
  dependencies?: {
2719
2719
  id?: string;
2720
+ source?: string;
2720
2721
  version?: string;
2721
2722
  sha256?: string;
2722
- source?: string;
2723
2723
  format?: "classic-script";
2724
2724
  global?: string;
2725
2725
  }[] | undefined;
@@ -1819,16 +1819,34 @@ export declare const queryBindingSchema: z.ZodObject<{
1819
1819
  controls: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
1820
1820
  } & {
1821
1821
  bindingId: z.ZodString;
1822
+ cache: z.ZodOptional<z.ZodObject<{
1823
+ maxAgeMs: z.ZodNumber;
1824
+ forceRefresh: z.ZodOptional<z.ZodBoolean>;
1825
+ }, "strict", z.ZodTypeAny, {
1826
+ maxAgeMs: number;
1827
+ forceRefresh?: boolean | undefined;
1828
+ }, {
1829
+ maxAgeMs: number;
1830
+ forceRefresh?: boolean | undefined;
1831
+ }>>;
1822
1832
  }, "strict", z.ZodTypeAny, {
1823
1833
  bindingId: string;
1824
1834
  artifactId: string;
1825
1835
  controls: Record<string, string | number | boolean | null>;
1826
1836
  versionId?: string | undefined;
1827
1837
  draftRevision?: number | undefined;
1838
+ cache?: {
1839
+ maxAgeMs: number;
1840
+ forceRefresh?: boolean | undefined;
1841
+ } | undefined;
1828
1842
  }, {
1829
1843
  bindingId: string;
1830
1844
  artifactId: string;
1831
1845
  controls?: Record<string, string | number | boolean | null> | undefined;
1832
1846
  versionId?: string | undefined;
1833
1847
  draftRevision?: number | undefined;
1848
+ cache?: {
1849
+ maxAgeMs: number;
1850
+ forceRefresh?: boolean | undefined;
1851
+ } | undefined;
1834
1852
  }>;
@@ -96,4 +96,5 @@ exports.controlsSchema = v3_1.z.record(v3_1.z.union([v3_1.z.string().max(4000),
96
96
  exports.saveSchema = v3_1.z.object({ manifest: exports.dashboardSchema, expectedVersionId: v3_1.z.string().uuid().nullable(), expectedRevision: v3_1.z.number().int().nonnegative().default(0) }).strict();
97
97
  exports.querySchema = v3_1.z.object({ artifactId: v3_1.z.string().uuid(), versionId: v3_1.z.string().uuid().optional(), draftRevision: v3_1.z.number().int().positive().optional(), controls: exports.controlsSchema.default({}) }).strict();
98
98
  /** Generated pages select a saved Binding by ID. Query text, provider and source overrides are rejected. */
99
- exports.queryBindingSchema = exports.querySchema.extend({ bindingId: id }).strict();
99
+ exports.queryBindingSchema = exports.querySchema.extend({ bindingId: id,
100
+ cache: v3_1.z.object({ maxAgeMs: v3_1.z.number().int().min(0).max(60000), forceRefresh: v3_1.z.boolean().optional() }).strict().optional() }).strict();
@@ -131,7 +131,7 @@ export declare class DashboardService {
131
131
  status: "draft";
132
132
  title: string;
133
133
  } | null>;
134
- save(context: XpertResolvedViewHostContext, manifest: DashboardManifest, expectedVersionId: string | null, expectedRevision?: number, importedDependencies?: ArtifactDocumentDependencyAsset[], task?: SaveOptions): Promise<{
134
+ save(context: XpertResolvedViewHostContext, manifest: DashboardManifest, expectedVersionId: string | null, expectedRevision?: number, importedDependencies?: ArtifactDocumentDependencyAsset[], task?: SaveOptions, restoreVersionId?: string): Promise<{
135
135
  artifactId: string;
136
136
  draftId: string;
137
137
  draftRevision: number;
@@ -347,6 +347,15 @@ export declare class DashboardService {
347
347
  status: "draft";
348
348
  title: string;
349
349
  }>;
350
+ /** Historical bytes become a freshly validated draft; published versions and shares stay unchanged. */
351
+ restore(context: XpertResolvedViewHostContext, artifactId: string, versionId: string, expectedRevision: number, expectedCurrentVersionId: string | null): Promise<{
352
+ artifactId: string;
353
+ draftId: string;
354
+ draftRevision: number;
355
+ baseVersionId: string | null;
356
+ status: "draft";
357
+ title: string;
358
+ }>;
350
359
  publish(context: XpertResolvedViewHostContext, artifactId: string, expectedRevision: number, expectedCurrentVersionId: string | null): Promise<{
351
360
  artifactId: string;
352
361
  versionId: string;
@@ -511,7 +520,7 @@ export declare class DashboardService {
511
520
  versionId: string | null | undefined;
512
521
  versionNumber: number | undefined;
513
522
  }>;
514
- queryBinding(context: XpertResolvedViewHostContext, artifactId: string, versionId: string | undefined, bindingId: string, input: Record<string, AnalyticsValue>, draftRevision?: number): Promise<import("@xpert-ai/contracts").AnalyticalDataset>;
523
+ queryBinding(context: XpertResolvedViewHostContext, artifactId: string, versionId: string | undefined, bindingId: string, input: Record<string, AnalyticsValue>, draftRevision?: number, cache?: AnalyticsQueryRequest['cache']): Promise<import("@xpert-ai/contracts").AnalyticalDataset>;
515
524
  /** Every operation uses the current human's Project role; data queries still use actor(context). */
516
525
  authorizeProject(context: XpertResolvedViewHostContext, operation?: 'read' | 'write' | 'manage'): Promise<import("@xpert-ai/plugin-sdk").ProjectHumanAccess | undefined>;
517
526
  private execute;
@@ -158,7 +158,7 @@ let DashboardService = class DashboardService {
158
158
  return null;
159
159
  return { artifactId: artifact.id, draftId: draft.id, draftRevision: draft.revision, baseVersionId: draft.baseVersionId, status: 'draft', title: draft.title ?? artifact.title ?? '' };
160
160
  }
161
- async save(context, manifest, expectedVersionId, expectedRevision = 0, importedDependencies, task) {
161
+ async save(context, manifest, expectedVersionId, expectedRevision = 0, importedDependencies, task, restoreVersionId) {
162
162
  await task?.progress('authorization', 0, manifest.bindings.length);
163
163
  await this.authorizeProject(context, 'write');
164
164
  const scopedActor = actor(context);
@@ -177,8 +177,10 @@ let DashboardService = class DashboardService {
177
177
  this.assertCapacity(parsed.bindings.length, previous?.manifest.bindings.length ?? 0);
178
178
  if (importedDependencies && existing)
179
179
  throw new common_1.BadRequestException('DASHBOARD_IMPORT_NEW_ID_REQUIRED');
180
+ const restored = restoreVersionId && existing ? await this.openDocument(context, existing.id, restoreVersionId) : undefined;
180
181
  const dependencies = importedDependencies ? (0, artifact_document_1.verifyArtifactDocumentDependencies)(importedDependencies, parsed.presentation?.dependencies ?? [])
181
- : await (0, document_libraries_1.resolveLibraryAssets)(parsed.presentation?.dependencies ?? [], previous?.dependencies);
182
+ : restored ? (0, artifact_document_1.verifyArtifactDocumentDependencies)(restored.dependencies, parsed.presentation?.dependencies ?? [])
183
+ : await (0, document_libraries_1.resolveLibraryAssets)(parsed.presentation?.dependencies ?? [], previous?.dependencies);
182
184
  const buffer = (0, document_package_1.encodeDashboardPackage)(parsed, dependencies);
183
185
  if (buffer.byteLength > document_package_1.MAX_DASHBOARD_PACKAGE_BYTES)
184
186
  throw new common_1.BadRequestException('DASHBOARD_MANIFEST_TOO_LARGE');
@@ -260,6 +262,15 @@ let DashboardService = class DashboardService {
260
262
  throw new common_1.ConflictException('DASHBOARD_DRAFT_CONFLICT');
261
263
  return this.save(context, dashboard_schema_1.dashboardSchema.parse({ ...saved.manifest, ...dashboard_schema_1.dashboardChangesSchema.parse(changes) }), saved.baseVersionId ?? saved.versionId ?? null, expectedRevision);
262
264
  }
265
+ /** Historical bytes become a freshly validated draft; published versions and shares stay unchanged. */
266
+ async restore(context, artifactId, versionId, expectedRevision, expectedCurrentVersionId) {
267
+ await this.authorizeProject(context, 'write');
268
+ const current = await this.open(context, artifactId);
269
+ if ((current.draftRevision ?? 0) !== expectedRevision || (current.baseVersionId ?? current.versionId ?? null) !== expectedCurrentVersionId)
270
+ throw new common_1.ConflictException('DASHBOARD_DRAFT_CONFLICT');
271
+ const historical = await this.openDocument(context, artifactId, versionId);
272
+ return this.save(context, historical.manifest, expectedCurrentVersionId, expectedRevision, undefined, undefined, versionId);
273
+ }
263
274
  async publish(context, artifactId, expectedRevision, expectedCurrentVersionId) {
264
275
  await this.authorizeProject(context, 'manage');
265
276
  return this.publishDraft(context, artifactId, expectedRevision, expectedCurrentVersionId);
@@ -287,9 +298,11 @@ let DashboardService = class DashboardService {
287
298
  const { datasets, failures } = await (0, dashboard_queries_1.queryDashboardPartial)(this.runtime, actor(context), saved.manifest, controls);
288
299
  return { ...saved, datasets, failures, ...(saved.manifest.presentation ? {} : { payload: (0, renderer_1.toDataAnalyticsPayload)(saved.manifest, datasets) }) };
289
300
  }
290
- async queryBinding(context, artifactId, versionId, bindingId, input, draftRevision) {
301
+ async queryBinding(context, artifactId, versionId, bindingId, input, draftRevision, cache) {
291
302
  const saved = await this.open(context, artifactId, versionId, draftRevision);
292
- return (0, dashboard_queries_1.queryDashboardBinding)(this.runtime, actor(context), saved.manifest, bindingId, input);
303
+ const result = await (0, dashboard_queries_1.queryDashboardBinding)(this.runtime, actor(context), saved.manifest, bindingId, input, cache);
304
+ await this.authorizeProject(context);
305
+ return result;
293
306
  }
294
307
  /** Every operation uses the current human's Project role; data queries still use actor(context). */
295
308
  async authorizeProject(context, operation = 'read') {