@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,270 @@
|
|
|
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.LibraryCatalogService = exports.versionItem = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const dashboard_service_1 = require("../dashboard.service");
|
|
20
|
+
const access_1 = require("./access");
|
|
21
|
+
const entities_1 = require("./entities");
|
|
22
|
+
const resource_contract_1 = require("./resource-contract");
|
|
23
|
+
const resource_json_1 = require("./resource-json");
|
|
24
|
+
const archive_1 = require("./archive");
|
|
25
|
+
const files_service_1 = require("./files.service");
|
|
26
|
+
const versionTable = (0, resource_contract_1.libraryTable)('resource_version_v2'), publicationTable = (0, resource_contract_1.libraryTable)('resource_publication_v2');
|
|
27
|
+
const versionItem = (row) => ({ releaseId: row.id, logicalId: row.logicalId, version: row.version,
|
|
28
|
+
kind: row.kind, title: row.title, description: row.description, categories: row.categories, sha256: row.sha256, formatVersion: 2,
|
|
29
|
+
...row.catalogMetadata,
|
|
30
|
+
createdAt: row.createdAt.toISOString() });
|
|
31
|
+
exports.versionItem = versionItem;
|
|
32
|
+
/** @beta Canonical V2 catalog. Legacy V1 entries remain read-only migration inputs, not silently reinterpreted. */
|
|
33
|
+
let LibraryCatalogService = class LibraryCatalogService {
|
|
34
|
+
constructor(versions, dashboards, files) {
|
|
35
|
+
this.versions = versions;
|
|
36
|
+
this.dashboards = dashboards;
|
|
37
|
+
this.files = files;
|
|
38
|
+
}
|
|
39
|
+
actor(context, write = false) { return (0, access_1.libraryActor)(this.dashboards, context, write); }
|
|
40
|
+
async list(context, input) {
|
|
41
|
+
const actor = await this.actor(context), query = resource_contract_1.catalogV2Query.parse(input);
|
|
42
|
+
const qb = this.versions.createQueryBuilder('v').where('v.state = :ready', { ready: 'ready' });
|
|
43
|
+
const publicClause = (alias) => `EXISTS (SELECT 1 FROM ${publicationTable} p WHERE p."versionId" = ${alias}.id AND p.active = true AND p."tenantId" = ${alias}."tenantId" AND p."organizationId" = ${alias}."organizationId" AND p."ownerId" = ${alias}."ownerId")`;
|
|
44
|
+
if (query.audience === 'public')
|
|
45
|
+
qb.andWhere(publicClause('v'));
|
|
46
|
+
else
|
|
47
|
+
qb.andWhere('v."tenantId" = :tenantId AND v."organizationId" = :organizationId AND v."ownerId" = :ownerId', actor);
|
|
48
|
+
qb.andWhere(`NOT EXISTS (SELECT 1 FROM ${versionTable} n WHERE n."resourceId" = v."resourceId" AND n.state = 'ready' AND string_to_array(n.version, '.')::int[] > string_to_array(v.version, '.')::int[] ${query.audience === 'public' ? `AND ${publicClause('n')}` : ''})`);
|
|
49
|
+
if (query.kind)
|
|
50
|
+
qb.andWhere('v.kind = :kind', { kind: query.kind });
|
|
51
|
+
if (query.appearance !== 'all')
|
|
52
|
+
qb.andWhere("v.\"catalogMetadata\"->'presentation'->>'appearance' = :appearance", { appearance: query.appearance });
|
|
53
|
+
if (query.category)
|
|
54
|
+
qb.andWhere('v.categories @> CAST(:category AS jsonb)', { category: JSON.stringify([query.category]) });
|
|
55
|
+
if (query.search)
|
|
56
|
+
qb.andWhere(`(COALESCE(v."catalogMetadata"->'translations'->:locale->>'title', v.title) ILIKE :search OR COALESCE(v."catalogMetadata"->'translations'->:locale->>'description', v.description) ILIKE :search)`, { locale: query.locale, search: `%${query.search.replace(/[\\%_]/g, '\\$&')}%` });
|
|
57
|
+
// The catalog query never fetches large JSON definitions or file bytes.
|
|
58
|
+
qb.select(['v.id', 'v.logicalId', 'v.version', 'v.kind', 'v.title', 'v.description', 'v.categories', 'v.catalogMetadata', 'v.sha256', 'v.createdAt']);
|
|
59
|
+
const [rows, total] = await qb.orderBy('v.createdAt', 'DESC').addOrderBy('v.id', 'DESC').skip((query.page - 1) * query.pageSize).take(query.pageSize).getManyAndCount();
|
|
60
|
+
return { items: rows.map(exports.versionItem), total, page: query.page, pageSize: query.pageSize };
|
|
61
|
+
}
|
|
62
|
+
async matchOwned(context, entries) {
|
|
63
|
+
const actor = await this.actor(context);
|
|
64
|
+
if (!entries.length || entries.length > 50)
|
|
65
|
+
return [];
|
|
66
|
+
return this.versions.createQueryBuilder('v').where({ ...actor, state: 'ready', logicalId: (0, typeorm_2.In)(entries.map(item => item.logicalId)) })
|
|
67
|
+
.andWhere(`NOT EXISTS (SELECT 1 FROM ${versionTable} n WHERE n."resourceId" = v."resourceId" AND n.state = 'ready' AND string_to_array(n.version, '.')::int[] > string_to_array(v.version, '.')::int[])`)
|
|
68
|
+
.select(['v.id', 'v.logicalId', 'v.version', 'v.kind', 'v.title', 'v.description', 'v.categories', 'v.catalogMetadata', 'v.sha256', 'v.createdAt']).getMany();
|
|
69
|
+
}
|
|
70
|
+
async resolve(context, id, write = false) {
|
|
71
|
+
const actor = await this.actor(context, write), row = await this.versions.findOneBy({ id, state: 'ready' });
|
|
72
|
+
if (!row)
|
|
73
|
+
throw new common_1.ForbiddenException('LIBRARY_RESOURCE_DENIED');
|
|
74
|
+
const own = (0, access_1.ownedBy)(row, actor);
|
|
75
|
+
if (!own && (write || !await this.versions.manager.getRepository(entities_1.LibraryPublicationRecord).existsBy({
|
|
76
|
+
tenantId: row.tenantId, organizationId: row.organizationId, ownerId: row.ownerId, versionId: row.id, active: true
|
|
77
|
+
})))
|
|
78
|
+
throw new common_1.ForbiddenException('LIBRARY_RESOURCE_DENIED');
|
|
79
|
+
const document = resource_contract_1.resourceV2Schema.parse(row.document);
|
|
80
|
+
if ((0, resource_json_1.resourceHash)(document) !== row.sha256 || (0, resource_contract_1.identity)(document) !== (0, resource_contract_1.identity)(row) || document.kind !== row.kind)
|
|
81
|
+
throw new common_1.BadRequestException('LIBRARY_RESOURCE_INTEGRITY');
|
|
82
|
+
return { row, own, actor, document };
|
|
83
|
+
}
|
|
84
|
+
async read(context, id) {
|
|
85
|
+
const { row, document, own } = await this.resolve(context, id);
|
|
86
|
+
let canPublish = false;
|
|
87
|
+
if (own && (await this.dashboards.access(context)).canEdit) {
|
|
88
|
+
try {
|
|
89
|
+
canPublish = (await this.closure(context, [id], true)).resources.every(resource => !resource.assets.length);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
canPublish = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const canWithdraw = own && await this.versions.manager.getRepository(entities_1.LibraryPublicationRecord).existsBy({ versionId: id, active: true, ...await this.actor(context) });
|
|
96
|
+
return { item: (0, exports.versionItem)(row), document, capabilities: { canExport: own || !document.assets.length, canPublish, canWithdraw,
|
|
97
|
+
reasons: !own && document.assets.length ? ['LIBRARY_PUBLIC_FILE_COPY_UNAVAILABLE'] : [] } };
|
|
98
|
+
}
|
|
99
|
+
/** @beta Reads a bounded preview asset of an authorized fixed resource version. */
|
|
100
|
+
async thumbnail(context, releaseId, assetId) {
|
|
101
|
+
const { document, actor, own } = await this.resolve(context, releaseId);
|
|
102
|
+
if (!own)
|
|
103
|
+
throw new common_1.BadRequestException('LIBRARY_PUBLIC_FILE_COPY_UNAVAILABLE');
|
|
104
|
+
const asset = document.assets.find(item => item.id === assetId && ['cover', 'preview'].includes(item.purpose));
|
|
105
|
+
if (!asset || asset.size > 2_000_000 || !asset.mimeType.startsWith('image/'))
|
|
106
|
+
throw new common_1.BadRequestException('LIBRARY_PREVIEW_UNAVAILABLE');
|
|
107
|
+
const bytes = await this.files.read(actor, asset);
|
|
108
|
+
await this.resolve(context, releaseId);
|
|
109
|
+
return { src: `data:${asset.mimeType};base64,${bytes.toString('base64')}` };
|
|
110
|
+
}
|
|
111
|
+
async closure(context, ids, ownOnly = false) {
|
|
112
|
+
const resources = [], rows = [], seen = new Set(), active = new Set();
|
|
113
|
+
const visit = async (id) => {
|
|
114
|
+
if (active.has(id))
|
|
115
|
+
throw new common_1.BadRequestException('LIBRARY_DEPENDENCY_CYCLE');
|
|
116
|
+
if (seen.has(id))
|
|
117
|
+
return;
|
|
118
|
+
if (seen.size + active.size >= resource_contract_1.limits.resources)
|
|
119
|
+
throw new common_1.BadRequestException('LIBRARY_ARCHIVE_LIMIT');
|
|
120
|
+
const { row, document, own } = await this.resolve(context, id, ownOnly);
|
|
121
|
+
if (!own && document.assets.length)
|
|
122
|
+
throw new common_1.BadRequestException('LIBRARY_PUBLIC_FILE_COPY_UNAVAILABLE');
|
|
123
|
+
active.add(id);
|
|
124
|
+
for (const dep of document.dependencies) {
|
|
125
|
+
const child = await this.versions.findOneBy({ tenantId: row.tenantId, organizationId: row.organizationId, ownerId: row.ownerId,
|
|
126
|
+
logicalId: dep.logicalId, version: dep.version, state: 'ready' });
|
|
127
|
+
if (!child || child.sha256 !== dep.sha256 || child.kind !== dep.kind)
|
|
128
|
+
throw new common_1.BadRequestException('LIBRARY_DEPENDENCY_MISSING');
|
|
129
|
+
await visit(child.id);
|
|
130
|
+
}
|
|
131
|
+
active.delete(id);
|
|
132
|
+
seen.add(id);
|
|
133
|
+
rows.push(row);
|
|
134
|
+
resources.push(document);
|
|
135
|
+
};
|
|
136
|
+
for (const id of ids)
|
|
137
|
+
await visit(id);
|
|
138
|
+
return { resources, rows, roots: ids.map(id => (0, archive_1.reference)(resources[rows.findIndex(row => row.id === id)])) };
|
|
139
|
+
}
|
|
140
|
+
async exportPackage(context, ids) {
|
|
141
|
+
const actor = await this.actor(context), closure = await this.closure(context, ids), blobs = new Map();
|
|
142
|
+
for (const document of closure.resources)
|
|
143
|
+
for (const asset of document.assets) {
|
|
144
|
+
if (!blobs.has(asset.sha256))
|
|
145
|
+
blobs.set(asset.sha256, await this.files.read(actor, asset));
|
|
146
|
+
}
|
|
147
|
+
for (const row of closure.rows)
|
|
148
|
+
await this.resolve(context, row.id);
|
|
149
|
+
const result = { resources: closure.resources, roots: closure.roots, blobs };
|
|
150
|
+
(0, archive_1.validatePackage)(result);
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
async upload(context, asset, bytes) {
|
|
154
|
+
await this.files.store(await this.actor(context, true), asset, bytes);
|
|
155
|
+
return { sha256: asset.sha256, size: asset.size, mimeType: asset.mimeType };
|
|
156
|
+
}
|
|
157
|
+
async resource(manager, actor, document) {
|
|
158
|
+
const repository = manager.getRepository(entities_1.LibraryResourceRecord), where = { ...actor, logicalId: document.logicalId };
|
|
159
|
+
await repository.createQueryBuilder().insert().values({ ...where, kind: document.kind }).orIgnore().execute();
|
|
160
|
+
const row = await repository.findOne({ where, lock: { mode: 'pessimistic_write' } });
|
|
161
|
+
if (!row || row.kind !== document.kind)
|
|
162
|
+
throw new common_1.ConflictException('LIBRARY_RESOURCE_KIND_CONFLICT');
|
|
163
|
+
return row;
|
|
164
|
+
}
|
|
165
|
+
async saveDraft(context, document, expectedRevision) {
|
|
166
|
+
const actor = await this.actor(context, true);
|
|
167
|
+
document = resource_contract_1.resourceV2Schema.parse(document);
|
|
168
|
+
(0, resource_json_1.resourceBytes)(document);
|
|
169
|
+
return this.versions.manager.transaction(async (manager) => {
|
|
170
|
+
const resource = await this.resource(manager, actor, document), repository = manager.getRepository(entities_1.LibraryDraftRecord);
|
|
171
|
+
const previous = await repository.findOneBy({ ...actor, resourceId: resource.id });
|
|
172
|
+
if ((previous?.revision ?? 0) !== expectedRevision)
|
|
173
|
+
throw new common_1.ConflictException('LIBRARY_DRAFT_CONFLICT');
|
|
174
|
+
await this.files.lockReferences(manager, actor, document.assets);
|
|
175
|
+
const draft = await repository.save(repository.create({ ...previous, ...actor, resourceId: resource.id, document, revision: expectedRevision + 1 }));
|
|
176
|
+
return { draftId: draft.id, resourceId: resource.id, revision: draft.revision, document: draft.document };
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async getDraft(context, id) {
|
|
180
|
+
const actor = await this.actor(context), draft = await this.versions.manager.getRepository(entities_1.LibraryDraftRecord).findOneBy({ id, ...actor });
|
|
181
|
+
if (!draft)
|
|
182
|
+
throw new common_1.ForbiddenException('LIBRARY_DRAFT_DENIED');
|
|
183
|
+
return { draftId: draft.id, resourceId: draft.resourceId, revision: draft.revision, document: resource_contract_1.resourceV2Schema.parse(draft.document) };
|
|
184
|
+
}
|
|
185
|
+
async releaseDraft(context, id, expectedRevision) {
|
|
186
|
+
const actor = await this.actor(context, true);
|
|
187
|
+
return this.versions.manager.transaction(async (manager) => {
|
|
188
|
+
const repository = manager.getRepository(entities_1.LibraryDraftRecord), initial = await repository.findOneBy({ id, ...actor });
|
|
189
|
+
if (!initial)
|
|
190
|
+
throw new common_1.ForbiddenException('LIBRARY_DRAFT_DENIED');
|
|
191
|
+
await this.resource(manager, actor, initial.document);
|
|
192
|
+
const draft = await repository.findOneBy({ id, ...actor });
|
|
193
|
+
if (!draft || draft.revision !== expectedRevision)
|
|
194
|
+
throw new common_1.ConflictException('LIBRARY_DRAFT_CONFLICT');
|
|
195
|
+
const row = await this.persistVersion(manager, actor, draft.document, null);
|
|
196
|
+
return (0, exports.versionItem)(row);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/** Used by release and import within their transaction. No public caller controls storage identities. */
|
|
200
|
+
async persistVersion(manager, actor, input, jobId) {
|
|
201
|
+
const document = resource_contract_1.resourceV2Schema.parse(input), sha256 = (0, resource_json_1.resourceHash)(document);
|
|
202
|
+
const resource = await this.resource(manager, actor, document), repository = manager.getRepository(entities_1.LibraryVersionRecord);
|
|
203
|
+
const where = { ...actor, logicalId: document.logicalId, version: document.version };
|
|
204
|
+
const existing = await repository.findOneBy(where);
|
|
205
|
+
if (existing) {
|
|
206
|
+
if (existing.sha256 !== sha256 || existing.state === 'staging' && existing.jobId !== jobId)
|
|
207
|
+
throw new common_1.ConflictException('LIBRARY_VERSION_CONFLICT');
|
|
208
|
+
return existing;
|
|
209
|
+
}
|
|
210
|
+
await this.files.lockReferences(manager, actor, document.assets);
|
|
211
|
+
for (const dep of document.dependencies) {
|
|
212
|
+
const child = await repository.findOneBy({ ...actor, logicalId: dep.logicalId, version: dep.version });
|
|
213
|
+
if (!child || child.sha256 !== dep.sha256 || child.kind !== dep.kind || child.state !== 'ready' && (!jobId || child.jobId !== jobId))
|
|
214
|
+
throw new common_1.BadRequestException('LIBRARY_DEPENDENCY_MISSING');
|
|
215
|
+
}
|
|
216
|
+
const row = await repository.save(repository.create({ ...where, resourceId: resource.id, kind: document.kind, title: document.title,
|
|
217
|
+
description: document.description, categories: document.categories,
|
|
218
|
+
catalogMetadata: { locale: document.locale, translations: document.translations, tags: document.tags, license: document.license, presentation: document.presentation,
|
|
219
|
+
...(document.kind === 'example-task' && document.content.dataRequirement ? { taskData: document.content.dataRequirement } : {}) },
|
|
220
|
+
document, sha256, jobId, state: jobId ? 'staging' : 'ready' }));
|
|
221
|
+
if (!jobId)
|
|
222
|
+
await this.promote(manager, actor, [row]);
|
|
223
|
+
return row;
|
|
224
|
+
}
|
|
225
|
+
async promote(manager, actor, rows) {
|
|
226
|
+
for (const row of [...rows].sort((a, b) => a.resourceId.localeCompare(b.resourceId))) {
|
|
227
|
+
const resources = manager.getRepository(entities_1.LibraryResourceRecord);
|
|
228
|
+
const resource = await resources.findOne({ where: { id: row.resourceId, ...actor }, lock: { mode: 'pessimistic_write' } });
|
|
229
|
+
if (!resource)
|
|
230
|
+
throw new common_1.ForbiddenException('LIBRARY_RESOURCE_DENIED');
|
|
231
|
+
const current = resource.currentVersionId ? await manager.getRepository(entities_1.LibraryVersionRecord).findOneBy({ id: resource.currentVersionId, ...actor }) : null;
|
|
232
|
+
const parts = row.version.split('.').map(Number), old = current?.version.split('.').map(Number);
|
|
233
|
+
const comparison = old ? parts.map((n, i) => n - old[i]).find(n => n !== 0) ?? 0 : 1;
|
|
234
|
+
await manager.getRepository(entities_1.LibraryVersionRecord).update({ id: row.id, ...actor }, { state: 'ready' });
|
|
235
|
+
if (comparison > 0)
|
|
236
|
+
await resources.update({ id: resource.id, ...actor }, { currentVersionId: row.id });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async publish(context, id, confirmed) {
|
|
240
|
+
if (!confirmed)
|
|
241
|
+
throw new common_1.BadRequestException('LIBRARY_PUBLIC_CONFIRMATION_REQUIRED');
|
|
242
|
+
const actor = await this.actor(context, true), closure = await this.closure(context, [id], true);
|
|
243
|
+
if (closure.resources.some(r => r.assets.length))
|
|
244
|
+
throw new common_1.BadRequestException('LIBRARY_PUBLIC_FILE_COPY_UNAVAILABLE');
|
|
245
|
+
await this.versions.manager.transaction(async (manager) => {
|
|
246
|
+
for (const row of [...closure.rows].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
247
|
+
const current = await manager.getRepository(entities_1.LibraryVersionRecord).findOne({ where: { id: row.id, ...actor, state: 'ready' }, lock: { mode: 'pessimistic_write' } });
|
|
248
|
+
if (!current || current.sha256 !== row.sha256)
|
|
249
|
+
throw new common_1.ConflictException('LIBRARY_VERSION_CONFLICT');
|
|
250
|
+
await manager.getRepository(entities_1.LibraryPublicationRecord).upsert({ ...actor, versionId: row.id, active: true }, ['tenantId', 'organizationId', 'ownerId', 'versionId']);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return this.read(context, id);
|
|
254
|
+
}
|
|
255
|
+
async withdraw(context, id) {
|
|
256
|
+
const { actor } = await this.resolve(context, id, true);
|
|
257
|
+
await this.versions.manager.transaction(async (manager) => {
|
|
258
|
+
await manager.getRepository(entities_1.LibraryVersionRecord).findOne({ where: { id, ...actor }, lock: { mode: 'pessimistic_write' } });
|
|
259
|
+
await manager.getRepository(entities_1.LibraryPublicationRecord).update({ ...actor, versionId: id }, { active: false });
|
|
260
|
+
});
|
|
261
|
+
return { releaseId: id };
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
exports.LibraryCatalogService = LibraryCatalogService;
|
|
265
|
+
exports.LibraryCatalogService = LibraryCatalogService = __decorate([
|
|
266
|
+
(0, common_1.Injectable)(),
|
|
267
|
+
__param(0, (0, typeorm_1.InjectRepository)(entities_1.LibraryVersionRecord)),
|
|
268
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
269
|
+
dashboard_service_1.DashboardService, files_service_1.LibraryFilesService])
|
|
270
|
+
], LibraryCatalogService);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { XpertResolvedViewHostContext } from '@xpert-ai/contracts';
|
|
2
|
+
import { type RuntimeCapabilityRegistry } from '@xpert-ai/plugin-sdk';
|
|
3
|
+
import { DashboardService } from '../dashboard.service';
|
|
4
|
+
import { DashboardDatasetService } from '../dataset.service';
|
|
5
|
+
import { LibraryCatalogService } from './catalog.service';
|
|
6
|
+
import type { TemplateInput } from './execution-contract';
|
|
7
|
+
import type { AnalysisTemplate, LibraryDataset } from './execution-resolution';
|
|
8
|
+
export declare function workspaceScope(context: XpertResolvedViewHostContext): {
|
|
9
|
+
tenantId: string;
|
|
10
|
+
organizationId: string | null | undefined;
|
|
11
|
+
userId: string;
|
|
12
|
+
xpertId: string;
|
|
13
|
+
catalog: "projects";
|
|
14
|
+
projectId: string;
|
|
15
|
+
} | {
|
|
16
|
+
tenantId: string;
|
|
17
|
+
organizationId: string | null | undefined;
|
|
18
|
+
userId: string;
|
|
19
|
+
xpertId: string;
|
|
20
|
+
catalog: "user-xperts";
|
|
21
|
+
};
|
|
22
|
+
/** Registers exact authorized file copies through the existing file.table authoring protocol. */
|
|
23
|
+
export declare class LibraryDatasetBindingService {
|
|
24
|
+
private readonly catalog;
|
|
25
|
+
private readonly dashboards;
|
|
26
|
+
private readonly datasets;
|
|
27
|
+
private readonly runtime;
|
|
28
|
+
constructor(catalog: LibraryCatalogService, dashboards: DashboardService, datasets: DashboardDatasetService, runtime: RuntimeCapabilityRegistry);
|
|
29
|
+
copy(context: XpertResolvedViewHostContext, dataset: LibraryDataset, folder: string): Promise<{
|
|
30
|
+
file: import("@xpert-ai/plugin-sdk").WorkspaceFile & {
|
|
31
|
+
reference: import("@xpert-ai/plugin-sdk").WorkspacePortableFileReference;
|
|
32
|
+
};
|
|
33
|
+
descriptor: {
|
|
34
|
+
id: string;
|
|
35
|
+
sha256: string;
|
|
36
|
+
size: number;
|
|
37
|
+
mimeType: "image/png" | "image/jpeg" | "image/webp" | "image/svg+xml" | "application/json" | "text/csv" | "text/html" | "text/plain";
|
|
38
|
+
fileName: string;
|
|
39
|
+
purpose: "cover" | "preview" | "data" | "document" | "supporting";
|
|
40
|
+
license: {
|
|
41
|
+
identifier: string;
|
|
42
|
+
attribution: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
buffer: Buffer<ArrayBufferLike>;
|
|
46
|
+
}>;
|
|
47
|
+
private register;
|
|
48
|
+
bind(context: XpertResolvedViewHostContext, input: TemplateInput, slot: AnalysisTemplate['content']['inputSlots'][number], executionId: string, allowedProviders?: string[]): Promise<{
|
|
49
|
+
binding: import("@xpert-ai/contracts").AnalyticsBinding;
|
|
50
|
+
origin: ({
|
|
51
|
+
type: "library";
|
|
52
|
+
} & {
|
|
53
|
+
version: string;
|
|
54
|
+
logicalId: string;
|
|
55
|
+
sha256: string;
|
|
56
|
+
}) | {
|
|
57
|
+
type: "dataset";
|
|
58
|
+
artifactId: string;
|
|
59
|
+
revision: number;
|
|
60
|
+
};
|
|
61
|
+
synthetic: boolean;
|
|
62
|
+
}>;
|
|
63
|
+
/** Retry authorization does not rewrite files or register definitions again. */
|
|
64
|
+
authorizeInput(context: XpertResolvedViewHostContext, input: TemplateInput): Promise<void>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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.LibraryDatasetBindingService = void 0;
|
|
16
|
+
exports.workspaceScope = workspaceScope;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
|
|
19
|
+
const analytics_1 = require("@xpert-ai/plugin-sdk/analytics");
|
|
20
|
+
const v3_1 = require("zod/v3");
|
|
21
|
+
const dashboard_service_1 = require("../dashboard.service");
|
|
22
|
+
const dataset_service_1 = require("../dataset.service");
|
|
23
|
+
const catalog_service_1 = require("./catalog.service");
|
|
24
|
+
const archive_1 = require("./archive");
|
|
25
|
+
function workspaceScope(context) {
|
|
26
|
+
const project = (0, dashboard_service_1.projectId)(context);
|
|
27
|
+
return { ...(project ? { catalog: 'projects', projectId: project } : { catalog: 'user-xperts' }),
|
|
28
|
+
tenantId: context.tenantId, organizationId: context.organizationId, userId: context.userId, xpertId: context.hostId };
|
|
29
|
+
}
|
|
30
|
+
/** Registers exact authorized file copies through the existing file.table authoring protocol. */
|
|
31
|
+
let LibraryDatasetBindingService = class LibraryDatasetBindingService {
|
|
32
|
+
constructor(catalog, dashboards, datasets, runtime) {
|
|
33
|
+
this.catalog = catalog;
|
|
34
|
+
this.dashboards = dashboards;
|
|
35
|
+
this.datasets = datasets;
|
|
36
|
+
this.runtime = runtime;
|
|
37
|
+
}
|
|
38
|
+
async copy(context, dataset, folder) {
|
|
39
|
+
const descriptor = dataset.assets.find(asset => asset.id === dataset.content.dataAssetId);
|
|
40
|
+
const buffer = await this.catalog.files.read(await this.catalog.actor(context, true), descriptor);
|
|
41
|
+
const file = await this.runtime.require(plugin_sdk_1.WorkspaceFilesRuntimeCapability).writeRuntimeBuffer({ ...workspaceScope(context), folder,
|
|
42
|
+
fileName: `${dataset.logicalId}-${descriptor.sha256}.${dataset.content.format}`, buffer, mimeType: descriptor.mimeType });
|
|
43
|
+
return { file, descriptor, buffer };
|
|
44
|
+
}
|
|
45
|
+
async register(context, dataset, executionId, slot) {
|
|
46
|
+
if (!context.workspaceId || !context.organizationId)
|
|
47
|
+
throw new common_1.BadRequestException('ANALYTICS_ASSISTANT_SCOPE_REQUIRED');
|
|
48
|
+
// Older V2 documents remain portable, but authoring needs an explicit Analytics field role.
|
|
49
|
+
if (dataset.content.columns.some(column => !column.role))
|
|
50
|
+
throw new common_1.BadRequestException('LIBRARY_DATASET_FIELD_ROLE_REQUIRED');
|
|
51
|
+
const files = this.runtime.require(plugin_sdk_1.WorkspaceFilesRuntimeCapability), authoring = this.runtime.require(plugin_sdk_1.AnalyticsDefinitionAuthoringCapability);
|
|
52
|
+
const scope = { actor: { tenantId: context.tenantId, organizationId: context.organizationId, userId: context.userId },
|
|
53
|
+
workspaceId: context.workspaceId, xpertId: context.assistant?.currentId ?? context.hostId, files };
|
|
54
|
+
if (!(await authoring.catalog(scope)).some(item => item.providerId === 'file.table' && item.connectionKey === 'workspace'))
|
|
55
|
+
throw new common_1.BadRequestException('LIBRARY_FILE_ANALYTICS_REQUIRED');
|
|
56
|
+
const { file } = await this.copy(context, dataset, `dashboards/library-instances/${executionId}/${slot}`);
|
|
57
|
+
const receipt = await authoring.register({ ...scope, files: {
|
|
58
|
+
resolveRuntimeReference: async (path) => {
|
|
59
|
+
if (path !== file.workspacePath)
|
|
60
|
+
throw new common_1.BadRequestException('LIBRARY_DATASET_PATH_INVALID');
|
|
61
|
+
return files.resolveRuntimeReference(file.reference);
|
|
62
|
+
}, resolveFile: ref => files.resolveFile(ref), readBuffer: ref => files.readBuffer(ref)
|
|
63
|
+
} }, { providerId: 'file.table', connectionKey: 'workspace', requestId: `library-v2/${executionId}/${slot}`, name: dataset.title,
|
|
64
|
+
definition: { name: dataset.title, description: dataset.description || dataset.title, path: file.workspacePath,
|
|
65
|
+
reader: dataset.content.format === 'json' ? { format: 'json', rowsPath: dataset.content.readerOptions.rowsPath ?? [] }
|
|
66
|
+
: { format: 'csv', delimiter: dataset.content.readerOptions.delimiter ?? ',', headerRow: 1 },
|
|
67
|
+
columns: dataset.content.columns.map(column => ({ ...column, path: [column.key], description: column.label,
|
|
68
|
+
role: column.role, nullValues: [] })) } });
|
|
69
|
+
const discovery = await this.dashboards.discover(context, receipt.discoveryRequest);
|
|
70
|
+
// An authoring receipt must identify a single authored definition, not a guessed first search hit.
|
|
71
|
+
if (discovery.items.length !== 1 || !discovery.items[0].inspectRequest)
|
|
72
|
+
throw new common_1.BadRequestException('LIBRARY_DATASET_INSPECTION_REQUIRED');
|
|
73
|
+
const item = discovery.items[0], inspected = await this.dashboards.discover(context, { ...receipt.discoveryRequest, request: item.inspectRequest });
|
|
74
|
+
return v3_1.z.object({ binding: analytics_1.analyticsBindingSchema }).parse(inspected.items.find(entry => entry.id === item.id)?.metadata).binding;
|
|
75
|
+
}
|
|
76
|
+
async bind(context, input, slot, executionId, allowedProviders) {
|
|
77
|
+
let binding, controls = {}, synthetic = false;
|
|
78
|
+
let origin;
|
|
79
|
+
if (input.source.type === 'dataset') {
|
|
80
|
+
const record = await this.datasets.open(context, input.source.artifactId);
|
|
81
|
+
if (record.revision !== input.source.revision)
|
|
82
|
+
throw new common_1.ConflictException('DASHBOARD_DATASET_CONFLICT');
|
|
83
|
+
binding = record.definition.binding;
|
|
84
|
+
controls = record.definition.controls;
|
|
85
|
+
origin = { type: 'dataset', artifactId: record.artifactId, revision: record.revision };
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (allowedProviders && !allowedProviders.includes('file.table'))
|
|
89
|
+
throw new common_1.BadRequestException('DASHBOARD_PROVIDER_REQUIRED');
|
|
90
|
+
const { document } = await this.catalog.resolve(context, input.source.releaseId);
|
|
91
|
+
if (document.kind !== 'public-dataset')
|
|
92
|
+
throw new common_1.BadRequestException('LIBRARY_DATASET_REQUIRED');
|
|
93
|
+
binding = await this.register(context, document, executionId, input.slot);
|
|
94
|
+
origin = { type: 'library', ...(0, archive_1.reference)(document) };
|
|
95
|
+
synthetic = document.provenance.kind === 'synthetic';
|
|
96
|
+
}
|
|
97
|
+
if (allowedProviders && !allowedProviders.includes(binding.providerId))
|
|
98
|
+
throw new common_1.BadRequestException('DASHBOARD_PROVIDER_REQUIRED');
|
|
99
|
+
for (const role of Object.keys(input.mapping))
|
|
100
|
+
if (!slot.fields.some(field => field.role === role))
|
|
101
|
+
throw new common_1.BadRequestException('LIBRARY_FIELD_MAPPING_INVALID');
|
|
102
|
+
for (const field of slot.fields) {
|
|
103
|
+
const id = input.mapping[field.role], actual = binding.output.fields.find(item => item.id === id);
|
|
104
|
+
if (!id && !field.required)
|
|
105
|
+
continue;
|
|
106
|
+
if (!actual || actual.logicalType !== field.logicalType || !field.nullable && actual.nullable)
|
|
107
|
+
throw new common_1.BadRequestException('LIBRARY_FIELD_TYPE_MISMATCH');
|
|
108
|
+
}
|
|
109
|
+
const grain = slot.grain.map(role => input.mapping[role]);
|
|
110
|
+
if (grain.some(id => !id) || new Set(grain).size !== grain.length || binding.output.grain.some(id => !grain.includes(id)))
|
|
111
|
+
throw new common_1.BadRequestException('LIBRARY_GRAIN_MISMATCH');
|
|
112
|
+
const normalized = analytics_1.analyticsBindingSchema.parse({ ...binding, id: input.slot, output: { ...binding.output, datasetId: input.slot, grain },
|
|
113
|
+
parameters: binding.parameters.map(parameter => ({ ...parameter, controlId: `${input.slot}.${parameter.controlId}`,
|
|
114
|
+
defaultValue: Object.hasOwn(controls, parameter.controlId) ? controls[parameter.controlId] : parameter.defaultValue ?? null })) });
|
|
115
|
+
const result = await this.dashboards.preview(context, { binding: normalized,
|
|
116
|
+
controls: Object.fromEntries(normalized.parameters.map(parameter => [parameter.controlId, parameter.defaultValue ?? null])) });
|
|
117
|
+
if (result.completeness.truncated || result.completeness.scope !== 'full_query_result' || result.completeness.totalAccuracy !== 'exact')
|
|
118
|
+
throw new common_1.BadRequestException('LIBRARY_COMPLETE_DATA_REQUIRED');
|
|
119
|
+
if (grain.length) {
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
for (const row of result.rows) {
|
|
122
|
+
const values = grain.map(id => row[id]);
|
|
123
|
+
if (values.some(value => value === null || value === undefined))
|
|
124
|
+
throw new common_1.BadRequestException('LIBRARY_GRAIN_MISMATCH');
|
|
125
|
+
const key = JSON.stringify(values);
|
|
126
|
+
if (seen.has(key))
|
|
127
|
+
throw new common_1.BadRequestException('LIBRARY_GRAIN_MISMATCH');
|
|
128
|
+
seen.add(key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { binding: normalized, origin, synthetic };
|
|
132
|
+
}
|
|
133
|
+
/** Retry authorization does not rewrite files or register definitions again. */
|
|
134
|
+
async authorizeInput(context, input) {
|
|
135
|
+
if (input.source.type === 'library') {
|
|
136
|
+
if ((await this.catalog.resolve(context, input.source.releaseId)).document.kind !== 'public-dataset')
|
|
137
|
+
throw new common_1.BadRequestException('LIBRARY_DATASET_REQUIRED');
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const record = await this.datasets.open(context, input.source.artifactId);
|
|
141
|
+
if (record.revision !== input.source.revision)
|
|
142
|
+
throw new common_1.ConflictException('DASHBOARD_DATASET_CONFLICT');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
exports.LibraryDatasetBindingService = LibraryDatasetBindingService;
|
|
147
|
+
exports.LibraryDatasetBindingService = LibraryDatasetBindingService = __decorate([
|
|
148
|
+
(0, common_1.Injectable)(),
|
|
149
|
+
__param(3, (0, common_1.Inject)(plugin_sdk_1.XPERT_RUNTIME_CAPABILITIES_TOKEN)),
|
|
150
|
+
__metadata("design:paramtypes", [catalog_service_1.LibraryCatalogService, dashboard_service_1.DashboardService,
|
|
151
|
+
dataset_service_1.DashboardDatasetService, Object])
|
|
152
|
+
], LibraryDatasetBindingService);
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
/** @beta A paged projection of display blueprints and authorized fixed V2 versions. */
|
|
3
|
+
export declare const directoryQuerySchema: z.ZodObject<{
|
|
4
|
+
audience: z.ZodDefault<z.ZodEnum<["catalog", "mine", "public"]>>;
|
|
5
|
+
kind: z.ZodEnum<["example-task", "analysis-template", "visual-theme", "component", "public-dataset"]>;
|
|
6
|
+
page: z.ZodDefault<z.ZodNumber>;
|
|
7
|
+
pageSize: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
search: z.ZodDefault<z.ZodString>;
|
|
9
|
+
category: z.ZodDefault<z.ZodString>;
|
|
10
|
+
appearance: z.ZodDefault<z.ZodEnum<["all", "light", "dark"]>>;
|
|
11
|
+
locale: z.ZodDefault<z.ZodEnum<["en", "zh-Hans", "zh-Hant"]>>;
|
|
12
|
+
}, "strict", z.ZodTypeAny, {
|
|
13
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
14
|
+
locale: "en" | "zh-Hans" | "zh-Hant";
|
|
15
|
+
appearance: "light" | "dark" | "all";
|
|
16
|
+
page: number;
|
|
17
|
+
pageSize: number;
|
|
18
|
+
category: string;
|
|
19
|
+
search: string;
|
|
20
|
+
audience: "mine" | "public" | "catalog";
|
|
21
|
+
}, {
|
|
22
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
23
|
+
locale?: "en" | "zh-Hans" | "zh-Hant" | undefined;
|
|
24
|
+
appearance?: "light" | "dark" | "all" | undefined;
|
|
25
|
+
page?: number | undefined;
|
|
26
|
+
pageSize?: number | undefined;
|
|
27
|
+
category?: string | undefined;
|
|
28
|
+
search?: string | undefined;
|
|
29
|
+
audience?: "mine" | "public" | "catalog" | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const directoryItemSchema: z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
kind: z.ZodEnum<["example-task", "analysis-template", "visual-theme", "component", "public-dataset"]>;
|
|
34
|
+
title: z.ZodString;
|
|
35
|
+
description: z.ZodString;
|
|
36
|
+
categories: z.ZodArray<z.ZodString, "many">;
|
|
37
|
+
state: z.ZodEnum<["planned", "not-installed", "released"]>;
|
|
38
|
+
releaseId: z.ZodNullable<z.ZodString>;
|
|
39
|
+
version: z.ZodNullable<z.ZodString>;
|
|
40
|
+
coverKey: z.ZodOptional<z.ZodString>;
|
|
41
|
+
coverAssetId: z.ZodOptional<z.ZodString>;
|
|
42
|
+
features: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
43
|
+
dataMode: z.ZodOptional<z.ZodEnum<["demo", "web", "external"]>>;
|
|
44
|
+
requirements: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
45
|
+
}, "strict", z.ZodTypeAny, {
|
|
46
|
+
title: string;
|
|
47
|
+
description: string;
|
|
48
|
+
id: string;
|
|
49
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
50
|
+
version: string | null;
|
|
51
|
+
categories: string[];
|
|
52
|
+
requirements: string[];
|
|
53
|
+
state: "planned" | "not-installed" | "released";
|
|
54
|
+
releaseId: string | null;
|
|
55
|
+
features: string[];
|
|
56
|
+
coverAssetId?: string | undefined;
|
|
57
|
+
coverKey?: string | undefined;
|
|
58
|
+
dataMode?: "demo" | "web" | "external" | undefined;
|
|
59
|
+
}, {
|
|
60
|
+
title: string;
|
|
61
|
+
description: string;
|
|
62
|
+
id: string;
|
|
63
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
64
|
+
version: string | null;
|
|
65
|
+
categories: string[];
|
|
66
|
+
state: "planned" | "not-installed" | "released";
|
|
67
|
+
releaseId: string | null;
|
|
68
|
+
coverAssetId?: string | undefined;
|
|
69
|
+
requirements?: string[] | undefined;
|
|
70
|
+
coverKey?: string | undefined;
|
|
71
|
+
features?: string[] | undefined;
|
|
72
|
+
dataMode?: "demo" | "web" | "external" | undefined;
|
|
73
|
+
}>;
|
|
74
|
+
export declare const directoryPageSchema: z.ZodObject<{
|
|
75
|
+
items: z.ZodArray<z.ZodObject<{
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
kind: z.ZodEnum<["example-task", "analysis-template", "visual-theme", "component", "public-dataset"]>;
|
|
78
|
+
title: z.ZodString;
|
|
79
|
+
description: z.ZodString;
|
|
80
|
+
categories: z.ZodArray<z.ZodString, "many">;
|
|
81
|
+
state: z.ZodEnum<["planned", "not-installed", "released"]>;
|
|
82
|
+
releaseId: z.ZodNullable<z.ZodString>;
|
|
83
|
+
version: z.ZodNullable<z.ZodString>;
|
|
84
|
+
coverKey: z.ZodOptional<z.ZodString>;
|
|
85
|
+
coverAssetId: z.ZodOptional<z.ZodString>;
|
|
86
|
+
features: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
87
|
+
dataMode: z.ZodOptional<z.ZodEnum<["demo", "web", "external"]>>;
|
|
88
|
+
requirements: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
89
|
+
}, "strict", z.ZodTypeAny, {
|
|
90
|
+
title: string;
|
|
91
|
+
description: string;
|
|
92
|
+
id: string;
|
|
93
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
94
|
+
version: string | null;
|
|
95
|
+
categories: string[];
|
|
96
|
+
requirements: string[];
|
|
97
|
+
state: "planned" | "not-installed" | "released";
|
|
98
|
+
releaseId: string | null;
|
|
99
|
+
features: string[];
|
|
100
|
+
coverAssetId?: string | undefined;
|
|
101
|
+
coverKey?: string | undefined;
|
|
102
|
+
dataMode?: "demo" | "web" | "external" | undefined;
|
|
103
|
+
}, {
|
|
104
|
+
title: string;
|
|
105
|
+
description: string;
|
|
106
|
+
id: string;
|
|
107
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
108
|
+
version: string | null;
|
|
109
|
+
categories: string[];
|
|
110
|
+
state: "planned" | "not-installed" | "released";
|
|
111
|
+
releaseId: string | null;
|
|
112
|
+
coverAssetId?: string | undefined;
|
|
113
|
+
requirements?: string[] | undefined;
|
|
114
|
+
coverKey?: string | undefined;
|
|
115
|
+
features?: string[] | undefined;
|
|
116
|
+
dataMode?: "demo" | "web" | "external" | undefined;
|
|
117
|
+
}>, "many">;
|
|
118
|
+
page: z.ZodNumber;
|
|
119
|
+
pageSize: z.ZodNumber;
|
|
120
|
+
total: z.ZodNumber;
|
|
121
|
+
}, "strict", z.ZodTypeAny, {
|
|
122
|
+
page: number;
|
|
123
|
+
pageSize: number;
|
|
124
|
+
items: {
|
|
125
|
+
title: string;
|
|
126
|
+
description: string;
|
|
127
|
+
id: string;
|
|
128
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
129
|
+
version: string | null;
|
|
130
|
+
categories: string[];
|
|
131
|
+
requirements: string[];
|
|
132
|
+
state: "planned" | "not-installed" | "released";
|
|
133
|
+
releaseId: string | null;
|
|
134
|
+
features: string[];
|
|
135
|
+
coverAssetId?: string | undefined;
|
|
136
|
+
coverKey?: string | undefined;
|
|
137
|
+
dataMode?: "demo" | "web" | "external" | undefined;
|
|
138
|
+
}[];
|
|
139
|
+
total: number;
|
|
140
|
+
}, {
|
|
141
|
+
page: number;
|
|
142
|
+
pageSize: number;
|
|
143
|
+
items: {
|
|
144
|
+
title: string;
|
|
145
|
+
description: string;
|
|
146
|
+
id: string;
|
|
147
|
+
kind: "example-task" | "analysis-template" | "visual-theme" | "component" | "public-dataset";
|
|
148
|
+
version: string | null;
|
|
149
|
+
categories: string[];
|
|
150
|
+
state: "planned" | "not-installed" | "released";
|
|
151
|
+
releaseId: string | null;
|
|
152
|
+
coverAssetId?: string | undefined;
|
|
153
|
+
requirements?: string[] | undefined;
|
|
154
|
+
coverKey?: string | undefined;
|
|
155
|
+
features?: string[] | undefined;
|
|
156
|
+
dataMode?: "demo" | "web" | "external" | undefined;
|
|
157
|
+
}[];
|
|
158
|
+
total: number;
|
|
159
|
+
}>;
|
|
160
|
+
export type DirectoryItem = z.infer<typeof directoryItemSchema>;
|
|
161
|
+
export type DirectoryQuery = z.infer<typeof directoryQuerySchema>;
|