@xpert-ai/plugin-live-dashboard 0.6.2 → 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.
- package/.xpertai-plugin/plugin.json +1 -1
- package/README.md +14 -2
- package/assets/explore/PROVENANCE.md +9 -0
- package/assets/explore/category-contribution.webp +0 -0
- package/assets/explore/ecommerce-operations.webp +0 -0
- package/assets/explore/extensions.svg +1 -0
- package/assets/explore/generation-prompts.json +107 -0
- package/assets/explore/global-assets.webp +0 -0
- package/assets/explore/hotel-cancellation.webp +0 -0
- package/assets/explore/hotel-operations.webp +0 -0
- package/assets/explore/insights.svg +1 -0
- package/assets/explore/knowledge.svg +1 -0
- package/assets/explore/legal-defense.webp +0 -0
- package/assets/explore/order-promotion.webp +0 -0
- package/assets/explore/outbound-travel.webp +0 -0
- package/assets/explore/schedule.svg +1 -0
- package/assets/explore/steam-market.webp +0 -0
- package/assets/explore/weather-alerts.webp +0 -0
- package/assets/library/catalog/README.md +11 -0
- package/assets/library/catalog/analysis-template-conversion-diagnosis.svg +1 -0
- package/assets/library/catalog/analysis-template-customer-lifecycle.svg +1 -0
- package/assets/library/catalog/analysis-template-growth-attribution.svg +1 -0
- package/assets/library/catalog/analysis-template-multi-criteria.svg +1 -0
- package/assets/library/catalog/analysis-template-regional-flow.svg +1 -0
- package/assets/library/catalog/analysis-template-risk-monitoring.svg +1 -0
- package/assets/library/catalog/component-analysis-note.svg +1 -0
- package/assets/library/catalog/component-box-plot.svg +1 -0
- package/assets/library/catalog/component-bullet.svg +1 -0
- package/assets/library/catalog/component-calendar-heatmap.svg +1 -0
- package/assets/library/catalog/component-collapsible-panel.svg +1 -0
- package/assets/library/catalog/component-combo-chart.svg +1 -0
- package/assets/library/catalog/component-content-panel.svg +1 -0
- package/assets/library/catalog/component-date-range.svg +1 -0
- package/assets/library/catalog/component-detail-table.svg +1 -0
- package/assets/library/catalog/component-donut.svg +1 -0
- package/assets/library/catalog/component-dumbbell.svg +1 -0
- package/assets/library/catalog/component-event-timeline.svg +1 -0
- package/assets/library/catalog/component-funnel.svg +1 -0
- package/assets/library/catalog/component-histogram.svg +1 -0
- package/assets/library/catalog/component-keyword-filter.svg +1 -0
- package/assets/library/catalog/component-matrix-heatmap.svg +1 -0
- package/assets/library/catalog/component-metric-card.svg +1 -0
- package/assets/library/catalog/component-metric-group.svg +1 -0
- package/assets/library/catalog/component-multi-series.svg +1 -0
- package/assets/library/catalog/component-number-range.svg +1 -0
- package/assets/library/catalog/component-option-filter.svg +1 -0
- package/assets/library/catalog/component-pareto.svg +1 -0
- package/assets/library/catalog/component-percent-stacked.svg +1 -0
- package/assets/library/catalog/component-pivot-table.svg +1 -0
- package/assets/library/catalog/component-radar.svg +1 -0
- package/assets/library/catalog/component-ranking.svg +1 -0
- package/assets/library/catalog/component-sankey.svg +1 -0
- package/assets/library/catalog/component-scatter-bubble.svg +1 -0
- package/assets/library/catalog/component-segmented-filter.svg +1 -0
- package/assets/library/catalog/component-small-multiples.svg +1 -0
- package/assets/library/catalog/component-sunburst.svg +1 -0
- package/assets/library/catalog/component-tabbed-panel.svg +1 -0
- package/assets/library/catalog/component-target-progress.svg +1 -0
- package/assets/library/catalog/component-toggle-filter.svg +1 -0
- package/assets/library/catalog/component-treemap.svg +1 -0
- package/assets/library/catalog/component-trend-comparison.svg +1 -0
- package/assets/library/catalog/component-waterfall.svg +1 -0
- package/assets/library/catalog/provenance.json +524 -0
- package/assets/library/catalog/visual-theme-amber-sunset.svg +1 -0
- package/assets/library/catalog/visual-theme-art-deco.svg +1 -0
- package/assets/library/catalog/visual-theme-bauhaus.svg +1 -0
- package/assets/library/catalog/visual-theme-burgundy-night.svg +1 -0
- package/assets/library/catalog/visual-theme-cinematic.svg +1 -0
- package/assets/library/catalog/visual-theme-clarity-blue.svg +1 -0
- package/assets/library/catalog/visual-theme-clay.svg +1 -0
- package/assets/library/catalog/visual-theme-cobalt-diagonal.svg +1 -0
- package/assets/library/catalog/visual-theme-coral-cream.svg +1 -0
- package/assets/library/catalog/visual-theme-crimson-black.svg +1 -0
- package/assets/library/catalog/visual-theme-cyberpunk.svg +1 -0
- package/assets/library/catalog/visual-theme-dark-olive.svg +1 -0
- package/assets/library/catalog/visual-theme-dark-tech.svg +1 -0
- package/assets/library/catalog/visual-theme-deep-sea-blue.svg +1 -0
- package/assets/library/catalog/visual-theme-deep-sea-mist.svg +1 -0
- package/assets/library/catalog/visual-theme-financial-trading.svg +1 -0
- package/assets/library/catalog/visual-theme-flat.svg +1 -0
- package/assets/library/catalog/visual-theme-frosted-tech.svg +1 -0
- package/assets/library/catalog/visual-theme-golden-eye.svg +1 -0
- package/assets/library/catalog/visual-theme-hand-drawn.svg +1 -0
- package/assets/library/catalog/visual-theme-industrial.svg +1 -0
- package/assets/library/catalog/visual-theme-layered-paper.svg +1 -0
- package/assets/library/catalog/visual-theme-material.svg +1 -0
- package/assets/library/catalog/visual-theme-maximalism.svg +1 -0
- package/assets/library/catalog/visual-theme-midnight-emerald.svg +1 -0
- package/assets/library/catalog/visual-theme-minimal-modern.svg +1 -0
- package/assets/library/catalog/visual-theme-misty-green.svg +1 -0
- package/assets/library/catalog/visual-theme-misty-rose.svg +1 -0
- package/assets/library/catalog/visual-theme-natural-terrain.svg +1 -0
- package/assets/library/catalog/visual-theme-neo-brutalism.svg +1 -0
- package/assets/library/catalog/visual-theme-newsprint.svg +1 -0
- package/assets/library/catalog/visual-theme-olive-terracotta.svg +1 -0
- package/assets/library/catalog/visual-theme-paper-journal.svg +1 -0
- package/assets/library/catalog/visual-theme-pastel-matrix.svg +1 -0
- package/assets/library/catalog/visual-theme-pixel-dashboard.svg +1 -0
- package/assets/library/catalog/visual-theme-premium-business.svg +1 -0
- package/assets/library/catalog/visual-theme-redline-brief.svg +1 -0
- package/assets/library/catalog/visual-theme-sage.svg +1 -0
- package/assets/library/catalog/visual-theme-soft-porcelain.svg +1 -0
- package/assets/library/catalog/visual-theme-swiss-grid.svg +1 -0
- package/assets/library/catalog/visual-theme-tdesign-enterprise.svg +1 -0
- package/assets/library/catalog/visual-theme-terminal-green.svg +1 -0
- package/assets/library/catalog/visual-theme-warm-sand.svg +1 -0
- package/dist/lib/agent.schema.d.ts +514 -32
- package/dist/lib/analysis-scene-chart.d.ts +8 -0
- package/dist/lib/analysis-scene-chart.js +61 -0
- package/dist/lib/analysis-scene-tool.d.ts +87 -0
- package/dist/lib/analysis-scene-tool.js +33 -0
- package/dist/lib/analysis-scene-widget.d.ts +6 -0
- package/dist/lib/analysis-scene-widget.js +107 -0
- package/dist/lib/analysis-scene.schema.d.ts +66 -0
- package/dist/lib/analysis-scene.schema.js +20 -0
- package/dist/lib/archive.service.d.ts +35 -0
- package/dist/lib/artifact-type.provider.d.ts +1 -0
- package/dist/lib/artifact-type.provider.js +18 -0
- package/dist/lib/bundled-example-source.d.ts +11 -0
- package/dist/lib/bundled-example-source.js +60 -0
- package/dist/lib/certification.schema.d.ts +4 -0
- package/dist/lib/certification.schema.js +14 -0
- package/dist/lib/content-capability.js +1 -0
- package/dist/lib/content-type.d.ts +2 -0
- package/dist/lib/content-type.js +5 -0
- package/dist/lib/content.provider.js +5 -3
- package/dist/lib/dashboard-archive.d.ts +35 -0
- package/dist/lib/dashboard-artifact.d.ts +93 -0
- package/dist/lib/dashboard-artifact.js +24 -0
- package/dist/lib/dashboard-delivery.d.ts +11 -0
- package/dist/lib/dashboard-delivery.js +55 -0
- package/dist/lib/dashboard-discovery.schema.d.ts +446 -0
- package/dist/lib/dashboard-discovery.schema.js +35 -0
- package/dist/lib/dashboard-navigation.d.ts +22 -21
- package/dist/lib/dashboard-navigation.js +5 -4
- package/dist/lib/dashboard-queries.d.ts +2 -2
- package/dist/lib/dashboard-queries.js +2 -2
- package/dist/lib/dashboard-receipt.js +1 -1
- package/dist/lib/dashboard-view.schema.d.ts +964 -64
- package/dist/lib/dashboard.schema.d.ts +738 -23
- package/dist/lib/dashboard.schema.js +8 -2
- package/dist/lib/dashboard.service.d.ts +155 -2
- package/dist/lib/dashboard.service.js +38 -4
- package/dist/lib/dataset-artifact.provider.d.ts +13 -0
- package/dist/lib/dataset-artifact.provider.js +57 -0
- package/dist/lib/dataset.schema.d.ts +195 -0
- package/dist/lib/dataset.schema.js +23 -0
- package/dist/lib/dataset.service.d.ts +54 -0
- package/dist/lib/dataset.service.js +119 -0
- package/dist/lib/definition-tools.d.ts +14 -54
- package/dist/lib/definition-tools.js +29 -9
- package/dist/lib/document-package.d.ts +35 -0
- package/dist/lib/editing.d.ts +552 -2
- package/dist/lib/evidence/evidence-diff.d.ts +17 -0
- package/dist/lib/evidence/evidence-diff.js +30 -0
- package/dist/lib/evidence/evidence-transfers.d.ts +14 -0
- package/dist/lib/evidence/evidence-transfers.js +41 -0
- package/dist/lib/evidence/evidence-view.provider.d.ts +91 -0
- package/dist/lib/evidence/evidence-view.provider.js +92 -0
- package/dist/lib/evidence/evidence.entity.d.ts +14 -0
- package/dist/lib/evidence/evidence.entity.js +62 -0
- package/dist/lib/evidence/evidence.provider.d.ts +43 -0
- package/dist/lib/evidence/evidence.provider.js +91 -0
- package/dist/lib/evidence/evidence.service.d.ts +67 -0
- package/dist/lib/evidence/evidence.service.js +218 -0
- package/dist/lib/explore-catalog.d.ts +15 -0
- package/dist/lib/explore-catalog.js +51 -0
- package/dist/lib/explore-catalog.json +131 -0
- package/dist/lib/explore.schema.d.ts +69 -0
- package/dist/lib/explore.schema.js +9 -0
- package/dist/lib/group-sharing.d.ts +17 -0
- package/dist/lib/group-sharing.js +39 -0
- package/dist/lib/hotel-document.d.ts +3 -0
- package/dist/lib/hotel-document.js +26 -0
- package/dist/lib/hotel-template.d.ts +246 -0
- package/dist/lib/hotel-template.js +77 -0
- package/dist/lib/library/access.d.ts +9 -0
- package/dist/lib/library/access.js +14 -0
- package/dist/lib/library/actions.d.ts +7 -0
- package/dist/lib/library/actions.js +55 -0
- package/dist/lib/library/archive.d.ts +13 -0
- package/dist/lib/library/archive.js +123 -0
- package/dist/lib/library/asset-validation.d.ts +4 -0
- package/dist/lib/library/asset-validation.js +77 -0
- package/dist/lib/library/catalog-blueprints.json +3225 -0
- package/dist/lib/library/catalog.service.d.ts +2427 -0
- package/dist/lib/library/catalog.service.js +270 -0
- package/dist/lib/library/dataset-binding.service.d.ts +65 -0
- package/dist/lib/library/dataset-binding.service.js +152 -0
- package/dist/lib/library/directory-contract.d.ts +161 -0
- package/dist/lib/library/directory-contract.js +19 -0
- package/dist/lib/library/directory.service.d.ts +33 -0
- package/dist/lib/library/directory.service.js +69 -0
- package/dist/lib/library/entities.d.ts +80 -0
- package/dist/lib/library/entities.js +280 -0
- package/dist/lib/library/execution-contract.d.ts +200 -0
- package/dist/lib/library/execution-contract.js +19 -0
- package/dist/lib/library/execution-resolution.d.ts +2490 -0
- package/dist/lib/library/execution-resolution.js +101 -0
- package/dist/lib/library/file-artifact.provider.d.ts +7 -0
- package/dist/lib/library/file-artifact.provider.js +35 -0
- package/dist/lib/library/files.service.d.ts +20 -0
- package/dist/lib/library/files.service.js +112 -0
- package/dist/lib/library/origin.schema.d.ts +171 -0
- package/dist/lib/library/origin.schema.js +14 -0
- package/dist/lib/library/resource-contract.d.ts +2779 -0
- package/dist/lib/library/resource-contract.js +167 -0
- package/dist/lib/library/resource-json.d.ts +11 -0
- package/dist/lib/library/resource-json.js +53 -0
- package/dist/lib/library/task-preparation.service.d.ts +14 -0
- package/dist/lib/library/task-preparation.service.js +85 -0
- package/dist/lib/library/template-compiler.d.ts +19 -0
- package/dist/lib/library/template-compiler.js +73 -0
- package/dist/lib/library/template-execution.service.d.ts +79 -0
- package/dist/lib/library/template-execution.service.js +135 -0
- package/dist/lib/library/transfers.service.d.ts +94 -0
- package/dist/lib/library/transfers.service.js +193 -0
- package/dist/lib/library/zip-container.d.ts +10 -0
- package/dist/lib/library/zip-container.js +79 -0
- package/dist/lib/library-view.provider.d.ts +88 -0
- package/dist/lib/library-view.provider.js +164 -0
- package/dist/lib/library.schema.d.ts +347 -0
- package/dist/lib/library.schema.js +41 -0
- package/dist/lib/middleware.d.ts +8 -2
- package/dist/lib/middleware.js +119 -11
- package/dist/lib/monitor.js +2 -2
- package/dist/lib/plugin.js +21 -1
- package/dist/lib/presentation.provider.d.ts +35 -0
- package/dist/lib/presentation.provider.js +4 -15
- package/dist/lib/projects.schema.d.ts +4 -4
- package/dist/lib/query-session.d.ts +1 -1
- package/dist/lib/query-session.js +13 -8
- package/dist/lib/remote-entry.d.ts +1 -1
- package/dist/lib/remote-entry.js +2 -2
- package/dist/lib/resource.schema.d.ts +1067 -0
- package/dist/lib/resource.schema.js +76 -0
- package/dist/lib/runtime-context.d.ts +2 -0
- package/dist/lib/runtime-context.js +22 -0
- package/dist/lib/sharing.service.d.ts +12 -0
- package/dist/lib/sharing.service.js +4 -0
- package/dist/lib/source-executions.d.ts +69 -51
- package/dist/lib/source-executions.js +2 -1
- package/dist/lib/template.schema.d.ts +36 -0
- package/dist/lib/template.schema.js +17 -0
- package/dist/lib/template.service.d.ts +21 -0
- package/dist/lib/template.service.js +56 -0
- package/dist/lib/templates.js +5 -5
- package/dist/lib/view.provider.d.ts +129 -4
- package/dist/lib/view.provider.js +61 -35
- package/dist/remote/app.css +1 -1
- package/dist/remote/app.js +54 -53
- package/dist/remote/build-manifest.json +238 -46
- package/dist/sandbox-actions/action.json +1 -1
- package/dist/sandbox-actions/bundle/host.js +2 -2
- package/docs/content-packages.mdx +43 -0
- package/docs/dashboard-starter.mdx +22 -0
- package/docs/data-view.mdx +30 -0
- package/docs/dataset-generation.mdx +32 -0
- package/docs/dataset-storage.mdx +29 -0
- package/docs/docs.json +15 -0
- package/docs/editing.mdx +6 -0
- package/docs/html-mode.md +1 -1
- package/docs/index.mdx +8 -0
- package/docs/inline-analysis.mdx +62 -0
- package/docs/library-browser-verification.mdx +46 -0
- package/docs/library-detail-ui.mdx +21 -0
- package/docs/library-directory-ui.mdx +24 -0
- package/docs/library-execution.mdx +49 -0
- package/docs/library-import-ui.mdx +20 -0
- package/docs/library-storage.mdx +63 -0
- package/docs/proposals/resource-sharing-decoupling.mdx +83 -0
- package/docs/standard-theme.mdx +28 -0
- package/docs/template-agent-handoff.mdx +37 -0
- package/docs/verification.mdx +4 -0
- package/package.json +9 -5
- package/skills/live-dashboard/SKILL.md +41 -1
- package/skills/live-dashboard/examples/README.md +2 -2
- package/skills/live-dashboard/examples/production-quality/README.md +2 -2
- package/skills/live-dashboard/examples/regional-sales/README.md +3 -3
- package/skills/live-dashboard/examples/regional-sales/query.json +49 -1
- package/skills/live-dashboard/examples/sales-overview/README.md +2 -2
- package/skills/live-dashboard/references/attribution-analysis.md +8 -0
- package/skills/live-dashboard/references/pareto-analysis.md +8 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.catalogV2Query = exports.identity = exports.resourceV2Schema = exports.assetSchema = exports.dependencySchema = exports.referenceSchema = exports.licenseSchema = exports.kindSchema = exports.versionSchema = exports.digestSchema = exports.keySchema = exports.limits = exports.LIBRARY_FILE_TYPE = exports.libraryTable = exports.LIBRARY_NAMESPACE = void 0;
|
|
4
|
+
const v3_1 = require("zod/v3");
|
|
5
|
+
const analytics_1 = require("@xpert-ai/plugin-sdk/analytics");
|
|
6
|
+
/** @beta Portable library contracts may change incompatibly until the resource format stabilizes. */
|
|
7
|
+
exports.LIBRARY_NAMESPACE = 'live_dashboard';
|
|
8
|
+
const libraryTable = (key) => `plugin_${exports.LIBRARY_NAMESPACE}_${key}`;
|
|
9
|
+
exports.libraryTable = libraryTable;
|
|
10
|
+
exports.LIBRARY_FILE_TYPE = 'live-dashboard-library-file';
|
|
11
|
+
exports.limits = { documentBytes: 8_000_000, archiveBytes: 32_000_000, expandedBytes: 32_000_000,
|
|
12
|
+
assetBytes: 16_000_000, resources: 100, assets: 200, compressionRatio: 500 };
|
|
13
|
+
exports.keySchema = v3_1.z.string().regex(/^[a-zA-Z][a-zA-Z0-9_.-]{0,79}$/)
|
|
14
|
+
.refine(value => !['constructor', 'prototype', '__proto__'].includes(value));
|
|
15
|
+
exports.digestSchema = v3_1.z.string().regex(/^[a-f0-9]{64}$/);
|
|
16
|
+
exports.versionSchema = v3_1.z.string().regex(/^(0|[1-9]\d{0,5})\.(0|[1-9]\d{0,5})\.(0|[1-9]\d{0,5})$/);
|
|
17
|
+
exports.kindSchema = v3_1.z.enum(['example-task', 'analysis-template', 'visual-theme', 'component', 'public-dataset']);
|
|
18
|
+
exports.licenseSchema = v3_1.z.object({ identifier: v3_1.z.string().min(1).max(100), attribution: v3_1.z.string().max(2000) }).strict();
|
|
19
|
+
exports.referenceSchema = v3_1.z.object({ logicalId: v3_1.z.string().uuid(), version: exports.versionSchema, sha256: exports.digestSchema }).strict();
|
|
20
|
+
exports.dependencySchema = exports.referenceSchema.extend({ alias: exports.keySchema, kind: exports.kindSchema }).strict();
|
|
21
|
+
exports.assetSchema = v3_1.z.object({ id: exports.keySchema, sha256: exports.digestSchema, size: v3_1.z.number().int().positive().max(exports.limits.assetBytes),
|
|
22
|
+
mimeType: v3_1.z.enum(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml', 'application/json', 'text/csv', 'text/html', 'text/plain']),
|
|
23
|
+
fileName: v3_1.z.string().min(1).max(180).refine(value => !/[\\/\u0000-\u001f]/.test(value)),
|
|
24
|
+
purpose: v3_1.z.enum(['cover', 'preview', 'data', 'document', 'supporting']), license: exports.licenseSchema }).strict();
|
|
25
|
+
const requirements = v3_1.z.object({
|
|
26
|
+
skills: v3_1.z.array(v3_1.z.object({ name: v3_1.z.string().min(1).max(160), required: v3_1.z.boolean() }).strict()).max(12),
|
|
27
|
+
plugins: v3_1.z.array(v3_1.z.object({ name: v3_1.z.string().min(1).max(160), versionRange: v3_1.z.string().min(1).max(100) }).strict()).max(20),
|
|
28
|
+
capabilities: v3_1.z.array(v3_1.z.string().min(1).max(160)).max(30)
|
|
29
|
+
}).strict();
|
|
30
|
+
const text = v3_1.z.object({ title: v3_1.z.string().min(1).max(160), description: v3_1.z.string().max(4000) }).strict();
|
|
31
|
+
const locale = v3_1.z.string().regex(/^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8}){0,3}$/);
|
|
32
|
+
const header = v3_1.z.object({ schema: v3_1.z.literal('xpert.library.resource'), formatVersion: v3_1.z.literal(2),
|
|
33
|
+
logicalId: v3_1.z.string().uuid(), version: exports.versionSchema, catalogKey: exports.keySchema.optional(),
|
|
34
|
+
...text.shape, locale, translations: v3_1.z.record(locale, text).optional(),
|
|
35
|
+
categories: v3_1.z.array(exports.keySchema).max(12), tags: v3_1.z.array(v3_1.z.string().min(1).max(40)).max(12), license: exports.licenseSchema,
|
|
36
|
+
provenance: v3_1.z.object({ kind: v3_1.z.enum(['synthetic', 'user-provided', 'open-data']), description: v3_1.z.string().max(2000) }).strict(),
|
|
37
|
+
presentation: v3_1.z.object({ coverAssetId: exports.keySchema.optional(), previewAssetIds: v3_1.z.array(exports.keySchema).max(12).optional(), appearance: v3_1.z.enum(['light', 'dark']).optional() }).strict().optional(),
|
|
38
|
+
dependencies: v3_1.z.array(exports.dependencySchema).max(30), assets: v3_1.z.array(exports.assetSchema).max(exports.limits.assets)
|
|
39
|
+
}).strict();
|
|
40
|
+
const valueSchema = v3_1.z.union([v3_1.z.string().max(4000), v3_1.z.number().finite(), v3_1.z.boolean(), v3_1.z.null()]);
|
|
41
|
+
const fieldRole = v3_1.z.object({ role: exports.keySchema, label: v3_1.z.string().min(1).max(160), logicalType: analytics_1.analyticsFieldSchema.shape.logicalType,
|
|
42
|
+
required: v3_1.z.boolean(), nullable: v3_1.z.boolean() }).strict();
|
|
43
|
+
const inputSlot = v3_1.z.object({ key: exports.keySchema, fields: v3_1.z.array(fieldRole).min(1).max(80), grain: v3_1.z.array(exports.keySchema).max(80) }).strict();
|
|
44
|
+
const presentation = v3_1.z.discriminatedUnion('type', [
|
|
45
|
+
v3_1.z.object({ type: v3_1.z.literal('standard'), charts: v3_1.z.array(v3_1.z.object({ id: exports.keySchema, title: v3_1.z.string().max(160),
|
|
46
|
+
type: v3_1.z.enum(['bar', 'line', 'area', 'pie', 'scatter']), slot: exports.keySchema, x: exports.keySchema, y: exports.keySchema, color: exports.keySchema.optional() }).strict()).max(20),
|
|
47
|
+
tables: v3_1.z.array(v3_1.z.object({ id: exports.keySchema, title: v3_1.z.string().max(160), slot: exports.keySchema, fields: v3_1.z.array(exports.keySchema).min(1).max(30) }).strict()).max(20) }).strict(),
|
|
48
|
+
v3_1.z.object({ type: v3_1.z.literal('html'), documentAssetId: exports.keySchema }).strict()
|
|
49
|
+
]);
|
|
50
|
+
exports.resourceV2Schema = v3_1.z.discriminatedUnion('kind', [
|
|
51
|
+
header.extend({ kind: v3_1.z.literal('example-task'), content: v3_1.z.object({ prompt: v3_1.z.string().min(1).max(16000),
|
|
52
|
+
dataRequirement: v3_1.z.object({ mode: v3_1.z.enum(['demo', 'web', 'external']), tools: v3_1.z.array(v3_1.z.string().max(160)).max(20) }).strict().optional(),
|
|
53
|
+
execution: v3_1.z.discriminatedUnion('mode', [v3_1.z.object({ mode: v3_1.z.literal('template'), templateAlias: exports.keySchema }).strict(), v3_1.z.object({ mode: v3_1.z.literal('agent') }).strict()]),
|
|
54
|
+
dataAliases: v3_1.z.array(exports.keySchema).max(20), themeAlias: exports.keySchema.optional(),
|
|
55
|
+
inputBindings: v3_1.z.array(v3_1.z.object({ slot: exports.keySchema, dataAlias: exports.keySchema, mapping: v3_1.z.record(exports.keySchema, exports.keySchema) }).strict()).max(12).optional(), requirements }).strict() }),
|
|
56
|
+
header.extend({ kind: v3_1.z.literal('analysis-template'), content: v3_1.z.object({ inputSlots: v3_1.z.array(inputSlot).min(1).max(12),
|
|
57
|
+
parameters: v3_1.z.array(v3_1.z.object({ key: exports.keySchema, label: v3_1.z.string().max(160), type: v3_1.z.enum(['string', 'number', 'boolean', 'date']),
|
|
58
|
+
defaultValue: valueSchema, allowedValues: v3_1.z.array(valueSchema).max(200).optional() }).strict()).max(24),
|
|
59
|
+
metrics: v3_1.z.array(v3_1.z.object({ key: exports.keySchema, label: v3_1.z.string().max(160), unit: v3_1.z.string().max(40), definition: v3_1.z.string().max(2000) }).strict()).max(40),
|
|
60
|
+
presentation, requirements }).strict() }),
|
|
61
|
+
header.extend({ kind: v3_1.z.literal('visual-theme'), content: v3_1.z.object({ renderer: v3_1.z.literal('live-dashboard.standard'),
|
|
62
|
+
theme: v3_1.z.enum(['system', 'slate', 'contrast']) }).strict() }),
|
|
63
|
+
header.extend({ kind: v3_1.z.literal('component'), content: v3_1.z.object({ renderer: v3_1.z.enum(['bar', 'line', 'area', 'pie', 'scatter', 'details']),
|
|
64
|
+
rendererVersion: v3_1.z.literal(1), title: v3_1.z.string().max(160), fields: v3_1.z.array(fieldRole).max(80) }).strict() }),
|
|
65
|
+
header.extend({ kind: v3_1.z.literal('public-dataset'), content: v3_1.z.object({ dataAssetId: exports.keySchema, format: v3_1.z.enum(['csv', 'json']),
|
|
66
|
+
readerOptions: v3_1.z.object({ encoding: v3_1.z.literal('utf-8'), delimiter: v3_1.z.enum([',', ';', '\t']).optional(), rowsPath: v3_1.z.array(exports.keySchema).max(8).optional() }).strict(),
|
|
67
|
+
columns: v3_1.z.array(v3_1.z.object({ key: exports.keySchema, label: v3_1.z.string().min(1).max(160), logicalType: analytics_1.analyticsFieldSchema.shape.logicalType,
|
|
68
|
+
nullable: v3_1.z.boolean(), role: analytics_1.analyticsFieldSchema.shape.role.optional() }).strict()).min(1).max(80), statistics: v3_1.z.object({ rowCount: v3_1.z.number().int().nonnegative().nullable() }).strict() }).strict() })
|
|
69
|
+
]).superRefine((document, ctx) => {
|
|
70
|
+
const issue = (message) => ctx.addIssue({ code: 'custom', message });
|
|
71
|
+
const unique = (keys, label) => { if (new Set(keys).size !== keys.length)
|
|
72
|
+
issue(`Duplicate ${label}`); };
|
|
73
|
+
unique(document.dependencies.map(d => d.alias), 'dependency alias');
|
|
74
|
+
unique(document.assets.map(a => a.id), 'asset id');
|
|
75
|
+
if (document.translations && Object.keys(document.translations).length > 20)
|
|
76
|
+
issue('Too many translations');
|
|
77
|
+
const asset = (id, purpose) => {
|
|
78
|
+
const item = document.assets.find(a => a.id === id);
|
|
79
|
+
if (!item || item.purpose !== purpose)
|
|
80
|
+
issue(`Invalid ${purpose} asset`);
|
|
81
|
+
return item;
|
|
82
|
+
};
|
|
83
|
+
if (document.presentation?.coverAssetId)
|
|
84
|
+
asset(document.presentation.coverAssetId, 'cover');
|
|
85
|
+
for (const id of document.presentation?.previewAssetIds ?? [])
|
|
86
|
+
asset(id, 'preview');
|
|
87
|
+
for (const a of document.assets) {
|
|
88
|
+
if (['cover', 'preview'].includes(a.purpose) && !a.mimeType.startsWith('image/'))
|
|
89
|
+
issue('Preview must be an image');
|
|
90
|
+
if (a.purpose === 'document' && a.mimeType !== 'text/html')
|
|
91
|
+
issue('Document must be HTML');
|
|
92
|
+
}
|
|
93
|
+
if (document.kind === 'example-task') {
|
|
94
|
+
const dependency = (alias, kind) => {
|
|
95
|
+
if (!document.dependencies.some(d => d.alias === alias && d.kind === kind))
|
|
96
|
+
issue('Dependency type mismatch');
|
|
97
|
+
};
|
|
98
|
+
const content = document.content;
|
|
99
|
+
if (content.execution.mode === 'template')
|
|
100
|
+
dependency(content.execution.templateAlias, 'analysis-template');
|
|
101
|
+
content.dataAliases.forEach(alias => dependency(alias, 'public-dataset'));
|
|
102
|
+
unique(content.dataAliases, 'data alias');
|
|
103
|
+
unique((content.inputBindings ?? []).map(input => input.slot), 'task input slot');
|
|
104
|
+
for (const input of content.inputBindings ?? [])
|
|
105
|
+
if (!content.dataAliases.includes(input.dataAlias))
|
|
106
|
+
issue('Task input dataset missing');
|
|
107
|
+
if (content.themeAlias)
|
|
108
|
+
dependency(content.themeAlias, 'visual-theme');
|
|
109
|
+
}
|
|
110
|
+
if (document.kind === 'public-dataset') {
|
|
111
|
+
const { content } = document, file = asset(content.dataAssetId, 'data');
|
|
112
|
+
if (file?.mimeType !== (content.format === 'json' ? 'application/json' : 'text/csv'))
|
|
113
|
+
issue('Dataset MIME mismatch');
|
|
114
|
+
if (content.format === 'json' && content.readerOptions.delimiter || content.format === 'csv' && content.readerOptions.rowsPath)
|
|
115
|
+
issue('Invalid reader options');
|
|
116
|
+
unique(content.columns.map(c => c.key), 'dataset field');
|
|
117
|
+
}
|
|
118
|
+
if (document.kind === 'analysis-template') {
|
|
119
|
+
const c = document.content;
|
|
120
|
+
unique(c.inputSlots.map(s => s.key), 'input slot');
|
|
121
|
+
unique(c.parameters.map(p => p.key), 'parameter');
|
|
122
|
+
unique(c.metrics.map(m => m.key), 'metric');
|
|
123
|
+
for (const parameter of c.parameters) {
|
|
124
|
+
const matches = (value) => {
|
|
125
|
+
if (value === null)
|
|
126
|
+
return true;
|
|
127
|
+
if (parameter.type !== 'date')
|
|
128
|
+
return typeof value === parameter.type;
|
|
129
|
+
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
130
|
+
return false;
|
|
131
|
+
const date = new Date(`${value}T00:00:00Z`);
|
|
132
|
+
return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
|
133
|
+
};
|
|
134
|
+
if (!matches(parameter.defaultValue) || parameter.allowedValues?.some(value => !matches(value)))
|
|
135
|
+
issue('Parameter type mismatch');
|
|
136
|
+
if (parameter.allowedValues && !parameter.allowedValues.includes(parameter.defaultValue))
|
|
137
|
+
issue('Default not in allowed values');
|
|
138
|
+
}
|
|
139
|
+
for (const slot of c.inputSlots) {
|
|
140
|
+
unique(slot.fields.map(f => f.role), 'field role');
|
|
141
|
+
unique(slot.grain, 'grain');
|
|
142
|
+
if (slot.grain.some(role => !slot.fields.some(f => f.role === role)))
|
|
143
|
+
issue('Grain role missing');
|
|
144
|
+
}
|
|
145
|
+
if (c.presentation.type === 'html')
|
|
146
|
+
asset(c.presentation.documentAssetId, 'document');
|
|
147
|
+
else {
|
|
148
|
+
const views = [...c.presentation.charts, ...c.presentation.tables];
|
|
149
|
+
if (!views.length)
|
|
150
|
+
issue('Standard template requires a view');
|
|
151
|
+
unique(views.map(v => v.id), 'view');
|
|
152
|
+
for (const view of views) {
|
|
153
|
+
const slot = c.inputSlots.find(s => s.key === view.slot);
|
|
154
|
+
const roles = 'fields' in view ? view.fields : [view.x, view.y, ...(view.color ? [view.color] : [])];
|
|
155
|
+
if (!slot || roles.some(r => !slot.fields.some(f => f.role === r)))
|
|
156
|
+
issue('View role missing');
|
|
157
|
+
if ('y' in view && !slot?.fields.some(f => f.role === view.y && ['int64', 'float64', 'decimal'].includes(f.logicalType)))
|
|
158
|
+
issue('Measure must be numeric');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const identity = (r) => `${r.logicalId}@${r.version}`;
|
|
164
|
+
exports.identity = identity;
|
|
165
|
+
exports.catalogV2Query = v3_1.z.object({ page: v3_1.z.number().int().min(1).max(100000).default(1), pageSize: v3_1.z.number().int().min(1).max(50).default(24),
|
|
166
|
+
kind: exports.kindSchema.optional(), category: exports.keySchema.optional(), search: v3_1.z.string().max(100).default(''), audience: v3_1.z.enum(['mine', 'public']).default('mine'),
|
|
167
|
+
appearance: v3_1.z.enum(['all', 'light', 'dark']).default('all'), locale: v3_1.z.enum(['en', 'zh-Hans', 'zh-Hant']).default('en') }).strict();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ResourceDocumentV2 } from './resource-contract';
|
|
2
|
+
export declare const sha256: (bytes: Uint8Array) => string;
|
|
3
|
+
/** JSON is the single untrusted boundary; reject duplicate keys before applying a domain schema. */
|
|
4
|
+
export declare function parseLibraryJson(bytes: Buffer, maxBytes?: number): unknown;
|
|
5
|
+
type JsonValue = null | string | number | boolean | JsonValue[] | {
|
|
6
|
+
[key: string]: JsonValue | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare function canonicalJson(value: JsonValue): string;
|
|
9
|
+
export declare function resourceBytes(document: ResourceDocumentV2): Buffer;
|
|
10
|
+
export declare const resourceHash: (document: ResourceDocumentV2) => string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resourceHash = exports.sha256 = void 0;
|
|
4
|
+
exports.parseLibraryJson = parseLibraryJson;
|
|
5
|
+
exports.canonicalJson = canonicalJson;
|
|
6
|
+
exports.resourceBytes = resourceBytes;
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
const resource_contract_1 = require("./resource-contract");
|
|
9
|
+
const sha256 = (bytes) => (0, node_crypto_1.createHash)('sha256').update(bytes).digest('hex');
|
|
10
|
+
exports.sha256 = sha256;
|
|
11
|
+
/** JSON is the single untrusted boundary; reject duplicate keys before applying a domain schema. */
|
|
12
|
+
function parseLibraryJson(bytes, maxBytes = resource_contract_1.limits.documentBytes) {
|
|
13
|
+
if (bytes.length > maxBytes)
|
|
14
|
+
throw new Error('LIBRARY_DOCUMENT_LIMIT');
|
|
15
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
16
|
+
const stack = [];
|
|
17
|
+
for (const token of text.matchAll(/"(?:[^"\\]|\\.)*"|[{}\[\]]/g)) {
|
|
18
|
+
if (token[0] === '{' || token[0] === '[') {
|
|
19
|
+
stack.push(token[0] === '{' ? new Set() : null);
|
|
20
|
+
if (stack.length > 64)
|
|
21
|
+
throw new Error('LIBRARY_JSON_DEPTH');
|
|
22
|
+
}
|
|
23
|
+
else if (token[0] === '}' || token[0] === ']')
|
|
24
|
+
stack.pop();
|
|
25
|
+
else if (/^\s*:/.test(text.slice(token.index + token[0].length))) {
|
|
26
|
+
const key = JSON.parse(token[0]), keys = stack.at(-1);
|
|
27
|
+
if (!keys || keys.has(key) || ['__proto__', 'prototype', 'constructor'].includes(key))
|
|
28
|
+
throw new Error('LIBRARY_JSON_KEY');
|
|
29
|
+
keys.add(key);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return JSON.parse(text, (_key, value) => {
|
|
33
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
34
|
+
throw new Error('LIBRARY_JSON_NUMBER');
|
|
35
|
+
return value;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function canonicalJson(value) {
|
|
39
|
+
if (value === null || typeof value !== 'object')
|
|
40
|
+
return JSON.stringify(value);
|
|
41
|
+
if (Array.isArray(value))
|
|
42
|
+
return `[${value.map(canonicalJson).join(',')}]`;
|
|
43
|
+
return `{${Object.entries(value).filter((entry) => entry[1] !== undefined)
|
|
44
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(',')}}`;
|
|
45
|
+
}
|
|
46
|
+
function resourceBytes(document) {
|
|
47
|
+
const bytes = Buffer.from(canonicalJson(resource_contract_1.resourceV2Schema.parse(document)));
|
|
48
|
+
if (bytes.length > resource_contract_1.limits.documentBytes)
|
|
49
|
+
throw new Error('LIBRARY_DOCUMENT_LIMIT');
|
|
50
|
+
return bytes;
|
|
51
|
+
}
|
|
52
|
+
const resourceHash = (document) => (0, exports.sha256)(resourceBytes(document));
|
|
53
|
+
exports.resourceHash = resourceHash;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { XpertResolvedViewHostContext } from '@xpert-ai/contracts';
|
|
2
|
+
import { type RuntimeCapabilityRegistry } from '@xpert-ai/plugin-sdk';
|
|
3
|
+
import { LibraryExecutionResolution } from './execution-resolution';
|
|
4
|
+
import { LibraryDatasetBindingService } from './dataset-binding.service';
|
|
5
|
+
import { type TaskDraftV2, type TemplateInstantiation } from './execution-contract';
|
|
6
|
+
/** @beta Preparing an example copies authorized data and returns an editable composer draft; it never sends. */
|
|
7
|
+
export declare class LibraryTaskPreparationService {
|
|
8
|
+
private readonly resolution;
|
|
9
|
+
private readonly datasets;
|
|
10
|
+
private readonly runtime;
|
|
11
|
+
constructor(resolution: LibraryExecutionResolution, datasets: LibraryDatasetBindingService, runtime: RuntimeCapabilityRegistry);
|
|
12
|
+
prepare(context: XpertResolvedViewHostContext, releaseId: string, requestId: string): Promise<TaskDraftV2>;
|
|
13
|
+
prepareTemplate(context: XpertResolvedViewHostContext, input: TemplateInstantiation): Promise<TaskDraftV2>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LibraryTaskPreparationService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
|
|
18
|
+
const execution_resolution_1 = require("./execution-resolution");
|
|
19
|
+
const dataset_binding_service_1 = require("./dataset-binding.service");
|
|
20
|
+
const execution_contract_1 = require("./execution-contract");
|
|
21
|
+
const archive_1 = require("./archive");
|
|
22
|
+
const resource_json_1 = require("./resource-json");
|
|
23
|
+
const template_compiler_1 = require("./template-compiler");
|
|
24
|
+
/** @beta Preparing an example copies authorized data and returns an editable composer draft; it never sends. */
|
|
25
|
+
let LibraryTaskPreparationService = class LibraryTaskPreparationService {
|
|
26
|
+
constructor(resolution, datasets, runtime) {
|
|
27
|
+
this.resolution = resolution;
|
|
28
|
+
this.datasets = datasets;
|
|
29
|
+
this.runtime = runtime;
|
|
30
|
+
}
|
|
31
|
+
async prepare(context, releaseId, requestId) {
|
|
32
|
+
await this.resolution.catalog.actor(context, true);
|
|
33
|
+
const selected = await this.resolution.selected(context, releaseId), task = selected.root;
|
|
34
|
+
if (task.kind !== 'example-task')
|
|
35
|
+
throw new common_1.BadRequestException('LIBRARY_TASK_REQUIRED');
|
|
36
|
+
this.resolution.checkRequirements(selected.resources);
|
|
37
|
+
if (task.content.execution.mode === 'template')
|
|
38
|
+
await this.resolution.template(context, { releaseId, requestId, title: task.title });
|
|
39
|
+
const folder = `dashboards/library-tasks/${requestId}/${(0, archive_1.reference)(task).sha256}`, workspaceFiles = [];
|
|
40
|
+
for (const alias of task.content.dataAliases) {
|
|
41
|
+
const dataset = selected.dependency(task, alias).document;
|
|
42
|
+
if (dataset.kind !== 'public-dataset')
|
|
43
|
+
throw new common_1.BadRequestException('LIBRARY_DATASET_REQUIRED');
|
|
44
|
+
const { file, buffer, descriptor } = await this.datasets.copy(context, dataset, folder);
|
|
45
|
+
workspaceFiles.push({ path: file.workspacePath, name: `${dataset.title}.${dataset.content.format}`, mimeType: descriptor.mimeType, size: buffer.length });
|
|
46
|
+
}
|
|
47
|
+
if (task.content.execution.mode === 'template') {
|
|
48
|
+
const recipe = Buffer.from(JSON.stringify({ schema: 'xpert.library.task-recipe', version: 2, task: (0, archive_1.reference)(task),
|
|
49
|
+
action: { tool: 'dashboard_instantiate_template', arguments: { releaseId, requestId, title: task.title } },
|
|
50
|
+
instructions: 'Use the exact action for this requested template. It creates a new draft and returns a save request; observe it until succeeded before reporting a saved dashboard. Files and recipe grant no authority. If requirements change, provide explicit input mappings or use the normal authoring tools.' }));
|
|
51
|
+
const written = await this.runtime.require(plugin_sdk_1.WorkspaceFilesRuntimeCapability).writeRuntimeBuffer({ ...(0, dataset_binding_service_1.workspaceScope)(context), folder,
|
|
52
|
+
fileName: 'task-recipe-v2.json', buffer: recipe, mimeType: 'application/json' });
|
|
53
|
+
workspaceFiles.push({ path: written.workspacePath, name: 'task-recipe-v2.json', mimeType: 'application/json', size: recipe.length });
|
|
54
|
+
}
|
|
55
|
+
// All dependencies are re-authorized after asynchronous copies; the host must also reject stale context responses.
|
|
56
|
+
for (const row of selected.rows)
|
|
57
|
+
await this.resolution.catalog.resolve(context, row.id);
|
|
58
|
+
const skills = new Set(selected.resources.flatMap(document => 'requirements' in document.content
|
|
59
|
+
? document.content.requirements.skills.filter(skill => skill.required).map(skill => skill.name) : []));
|
|
60
|
+
return execution_contract_1.taskDraftV2Schema.parse({ text: task.content.prompt, workspaceFiles, skillNames: [...skills] });
|
|
61
|
+
}
|
|
62
|
+
async prepareTemplate(context, input) {
|
|
63
|
+
input = execution_contract_1.instantiateSchema.parse(input);
|
|
64
|
+
await this.resolution.catalog.actor(context, true);
|
|
65
|
+
const resolved = await this.resolution.template(context, input);
|
|
66
|
+
(0, template_compiler_1.templateParameters)(resolved.template, input.parameters ?? {});
|
|
67
|
+
for (const item of resolved.inputs)
|
|
68
|
+
await this.datasets.authorizeInput(context, item);
|
|
69
|
+
const recipe = Buffer.from(JSON.stringify({ schema: 'xpert.library.task-recipe', version: 2, template: (0, archive_1.reference)(resolved.template),
|
|
70
|
+
action: { tool: 'dashboard_instantiate_template', arguments: input } }));
|
|
71
|
+
const file = await this.runtime.require(plugin_sdk_1.WorkspaceFilesRuntimeCapability).writeRuntimeBuffer({ ...(0, dataset_binding_service_1.workspaceScope)(context),
|
|
72
|
+
folder: `dashboards/library-tasks/${input.requestId}/${(0, resource_json_1.sha256)(recipe)}`, fileName: 'template-recipe-v2.json', buffer: recipe, mimeType: 'application/json' });
|
|
73
|
+
await this.resolution.template(context, input);
|
|
74
|
+
for (const item of resolved.inputs)
|
|
75
|
+
await this.datasets.authorizeInput(context, item);
|
|
76
|
+
return execution_contract_1.taskDraftV2Schema.parse({ text: input.title, workspaceFiles: [{ path: file.workspacePath, name: 'template-recipe-v2.json', mimeType: 'application/json', size: recipe.length }],
|
|
77
|
+
skillNames: [...new Set(resolved.selected.resources.flatMap(document => 'requirements' in document.content ? document.content.requirements.skills.filter(item => item.required).map(item => item.name) : []))] });
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
exports.LibraryTaskPreparationService = LibraryTaskPreparationService;
|
|
81
|
+
exports.LibraryTaskPreparationService = LibraryTaskPreparationService = __decorate([
|
|
82
|
+
(0, common_1.Injectable)(),
|
|
83
|
+
__param(2, (0, common_1.Inject)(plugin_sdk_1.XPERT_RUNTIME_CAPABILITIES_TOKEN)),
|
|
84
|
+
__metadata("design:paramtypes", [execution_resolution_1.LibraryExecutionResolution, dataset_binding_service_1.LibraryDatasetBindingService, Object])
|
|
85
|
+
], LibraryTaskPreparationService);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type DashboardManifest } from '../dashboard.schema';
|
|
2
|
+
import type { AnalysisTemplate } from './execution-resolution';
|
|
3
|
+
import type { LibraryDatasetBindingService } from './dataset-binding.service';
|
|
4
|
+
import type { TemplateInput } from './execution-contract';
|
|
5
|
+
import { templateOriginSchema } from './origin.schema';
|
|
6
|
+
import { z } from 'zod/v3';
|
|
7
|
+
export declare const TEMPLATE_CONTEXT_ID = "xpert-template-context";
|
|
8
|
+
export type BoundTemplateInput = Awaited<ReturnType<LibraryDatasetBindingService['bind']>> & {
|
|
9
|
+
input: TemplateInput;
|
|
10
|
+
};
|
|
11
|
+
export declare function templateParameters(template: AnalysisTemplate, supplied: Record<string, string | number | boolean | null>): Record<string, string | number | boolean | null>;
|
|
12
|
+
export declare function compileTemplate(template: AnalysisTemplate, inputs: BoundTemplateInput[], options: {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
theme: 'system' | 'slate' | 'contrast';
|
|
16
|
+
parameters: Record<string, string | number | boolean | null>;
|
|
17
|
+
origin: z.infer<typeof templateOriginSchema>;
|
|
18
|
+
html?: string;
|
|
19
|
+
}): DashboardManifest;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEMPLATE_CONTEXT_ID = void 0;
|
|
4
|
+
exports.templateParameters = templateParameters;
|
|
5
|
+
exports.compileTemplate = compileTemplate;
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const parse5_1 = require("parse5");
|
|
8
|
+
const dashboard_schema_1 = require("../dashboard.schema");
|
|
9
|
+
exports.TEMPLATE_CONTEXT_ID = 'xpert-template-context';
|
|
10
|
+
/** Authored HTML consumes inert JSON, never text-replacement expressions or server-side code. */
|
|
11
|
+
function documentContext(html, context) {
|
|
12
|
+
const document = (0, parse5_1.parse)(html);
|
|
13
|
+
let head;
|
|
14
|
+
const visit = (node) => {
|
|
15
|
+
if ('attrs' in node && node.attrs.some(attr => attr.name === 'id' && attr.value === exports.TEMPLATE_CONTEXT_ID))
|
|
16
|
+
throw new common_1.BadRequestException('LIBRARY_HTML_RESERVED_CONTEXT');
|
|
17
|
+
if ('tagName' in node && node.tagName === 'head')
|
|
18
|
+
head = node;
|
|
19
|
+
if ('childNodes' in node)
|
|
20
|
+
node.childNodes.forEach(visit);
|
|
21
|
+
};
|
|
22
|
+
visit(document);
|
|
23
|
+
if (!head)
|
|
24
|
+
throw new common_1.BadRequestException('LIBRARY_HTML_INVALID');
|
|
25
|
+
const data = JSON.stringify({ schema: 'xpert.library.template-context', version: 1, ...context }).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
|
26
|
+
const script = (0, parse5_1.parseFragment)(`<script type="application/json" id="${exports.TEMPLATE_CONTEXT_ID}">${data}</script>`).childNodes[0];
|
|
27
|
+
script.parentNode = head;
|
|
28
|
+
head.childNodes.unshift(script);
|
|
29
|
+
return (0, parse5_1.serialize)(document);
|
|
30
|
+
}
|
|
31
|
+
function templateParameters(template, supplied) {
|
|
32
|
+
const parameters = {};
|
|
33
|
+
for (const key of Object.keys(supplied))
|
|
34
|
+
if (!template.content.parameters.some(parameter => parameter.key === key))
|
|
35
|
+
throw new common_1.BadRequestException('LIBRARY_PARAMETER_UNKNOWN');
|
|
36
|
+
for (const parameter of template.content.parameters) {
|
|
37
|
+
const value = Object.hasOwn(supplied, parameter.key) ? supplied[parameter.key] : parameter.defaultValue;
|
|
38
|
+
if (value !== null && (parameter.type === 'number' ? typeof value !== 'number' || !Number.isFinite(value)
|
|
39
|
+
: parameter.type === 'boolean' ? typeof value !== 'boolean' : typeof value !== 'string') || parameter.allowedValues && !parameter.allowedValues.includes(value))
|
|
40
|
+
throw new common_1.BadRequestException('LIBRARY_PARAMETER_INVALID');
|
|
41
|
+
if (parameter.type === 'date' && value !== null) {
|
|
42
|
+
const date = typeof value === 'string' ? new Date(`${value}T00:00:00Z`) : new Date(NaN);
|
|
43
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString().slice(0, 10) !== value)
|
|
44
|
+
throw new common_1.BadRequestException('LIBRARY_PARAMETER_INVALID');
|
|
45
|
+
}
|
|
46
|
+
parameters[parameter.key] = value;
|
|
47
|
+
}
|
|
48
|
+
if (template.content.presentation.type === 'standard' && template.content.parameters.length)
|
|
49
|
+
throw new common_1.BadRequestException('LIBRARY_STANDARD_PARAMETERS_UNSUPPORTED');
|
|
50
|
+
return parameters;
|
|
51
|
+
}
|
|
52
|
+
function compileTemplate(template, inputs, options) {
|
|
53
|
+
const parameters = templateParameters(template, options.parameters);
|
|
54
|
+
const field = (slot, role) => {
|
|
55
|
+
const input = inputs.find(item => item.input.slot === slot), id = input?.input.mapping[role];
|
|
56
|
+
if (!id)
|
|
57
|
+
throw new common_1.BadRequestException('LIBRARY_FIELD_MAPPING_REQUIRED');
|
|
58
|
+
return id;
|
|
59
|
+
};
|
|
60
|
+
const presentation = template.content.presentation;
|
|
61
|
+
const manifest = { schema: 'xpert.live-dashboard', id: options.id, title: options.title, visualTheme: options.theme,
|
|
62
|
+
templateOrigin: { ...options.origin, parameters }, bindings: inputs.map(item => item.binding),
|
|
63
|
+
controls: inputs.flatMap(item => item.binding.parameters.map(parameter => ({ controlId: parameter.controlId, type: parameter.type,
|
|
64
|
+
label: parameter.controlId, defaultValue: parameter.defaultValue ?? null, ...(parameter.allowedValues ? { allowedValues: parameter.allowedValues } : {}) }))),
|
|
65
|
+
charts: presentation.type === 'standard' ? presentation.charts.map(chart => ({ id: chart.id, title: chart.title, type: chart.type,
|
|
66
|
+
datasetId: chart.slot, x: field(chart.slot, chart.x), y: field(chart.slot, chart.y), ...(chart.color ? { color: field(chart.slot, chart.color) } : {}) })) : [],
|
|
67
|
+
tables: presentation.type === 'standard' ? presentation.tables.map(table => ({ id: table.id, title: table.title,
|
|
68
|
+
datasetId: table.slot, fields: table.fields.map(role => field(table.slot, role)) })) : [],
|
|
69
|
+
...(presentation.type === 'html' ? { presentation: { type: 'html', html: documentContext(options.html ?? '', { title: options.title,
|
|
70
|
+
inputs: Object.fromEntries(inputs.map(item => [item.input.slot, { bindingId: item.binding.id, datasetId: item.binding.output.datasetId,
|
|
71
|
+
fields: item.input.mapping, synthetic: item.synthetic }])), parameters }) } } : {}) };
|
|
72
|
+
return dashboard_schema_1.dashboardSchema.parse(manifest);
|
|
73
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import type { XpertResolvedViewHostContext } from '@xpert-ai/contracts';
|
|
3
|
+
import { DashboardService } from '../dashboard.service';
|
|
4
|
+
import { DashboardSaveRequests } from '../save-requests';
|
|
5
|
+
import { LibraryExecutionRecord } from './entities';
|
|
6
|
+
import { LibraryExecutionResolution } from './execution-resolution';
|
|
7
|
+
import { LibraryDatasetBindingService } from './dataset-binding.service';
|
|
8
|
+
import { type TemplateInstantiation } from './execution-contract';
|
|
9
|
+
/** @beta One creation request produces one draft; the existing save queue owns validation and CAS. */
|
|
10
|
+
export declare class LibraryTemplateExecutionService {
|
|
11
|
+
private readonly executions;
|
|
12
|
+
private readonly resolution;
|
|
13
|
+
private readonly datasets;
|
|
14
|
+
private readonly saves;
|
|
15
|
+
private readonly dashboards;
|
|
16
|
+
constructor(executions: Repository<LibraryExecutionRecord>, resolution: LibraryExecutionResolution, datasets: LibraryDatasetBindingService, saves: DashboardSaveRequests, dashboards: DashboardService);
|
|
17
|
+
availability(context: XpertResolvedViewHostContext, id: string): Promise<{
|
|
18
|
+
supportsInstantiation: boolean;
|
|
19
|
+
canPrepareTask: boolean;
|
|
20
|
+
executionChecks: "required-on-invocation";
|
|
21
|
+
reasons: string[];
|
|
22
|
+
}>;
|
|
23
|
+
instantiate(context: XpertResolvedViewHostContext, input: TemplateInstantiation, allowedProviders?: string[]): Promise<{
|
|
24
|
+
executionId: string;
|
|
25
|
+
state: "preparing";
|
|
26
|
+
nextAction: "retry";
|
|
27
|
+
} | {
|
|
28
|
+
cursor: string;
|
|
29
|
+
nextAction: string;
|
|
30
|
+
error?: string | undefined;
|
|
31
|
+
sourceFile?: {
|
|
32
|
+
path: string;
|
|
33
|
+
sha256: string;
|
|
34
|
+
} | undefined;
|
|
35
|
+
dashboard?: {
|
|
36
|
+
status: "draft";
|
|
37
|
+
title: string;
|
|
38
|
+
artifactId: string;
|
|
39
|
+
draftRevision: number;
|
|
40
|
+
draftId: string;
|
|
41
|
+
baseVersionId: string | null;
|
|
42
|
+
} | undefined;
|
|
43
|
+
requestId: string;
|
|
44
|
+
state: "failed" | "running" | "succeeded" | "queued";
|
|
45
|
+
stage: string;
|
|
46
|
+
completed: number;
|
|
47
|
+
total: number;
|
|
48
|
+
terminal: boolean;
|
|
49
|
+
executionId: string;
|
|
50
|
+
}>;
|
|
51
|
+
status(context: XpertResolvedViewHostContext, id: string): Promise<{
|
|
52
|
+
executionId: string;
|
|
53
|
+
state: "preparing";
|
|
54
|
+
nextAction: "retry";
|
|
55
|
+
} | {
|
|
56
|
+
cursor: string;
|
|
57
|
+
nextAction: string;
|
|
58
|
+
error?: string | undefined;
|
|
59
|
+
sourceFile?: {
|
|
60
|
+
path: string;
|
|
61
|
+
sha256: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
dashboard?: {
|
|
64
|
+
status: "draft";
|
|
65
|
+
title: string;
|
|
66
|
+
artifactId: string;
|
|
67
|
+
draftRevision: number;
|
|
68
|
+
draftId: string;
|
|
69
|
+
baseVersionId: string | null;
|
|
70
|
+
} | undefined;
|
|
71
|
+
requestId: string;
|
|
72
|
+
state: "failed" | "running" | "succeeded" | "queued";
|
|
73
|
+
stage: string;
|
|
74
|
+
completed: number;
|
|
75
|
+
total: number;
|
|
76
|
+
terminal: boolean;
|
|
77
|
+
executionId: string;
|
|
78
|
+
}>;
|
|
79
|
+
}
|