@xpert-ai/plugin-live-dashboard 0.1.3 → 0.2.0
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 +5 -5
- package/dist/lib/agent.schema.d.ts +11 -11
- package/dist/lib/agent.schema.js +3 -3
- package/dist/lib/analytics-source.d.ts +3 -0
- package/dist/lib/analytics-source.js +11 -0
- package/dist/lib/content-capability.d.ts +22 -0
- package/dist/lib/content-capability.js +33 -0
- package/dist/lib/content.provider.d.ts +23 -0
- package/dist/lib/content.provider.js +163 -0
- package/dist/lib/dashboard-icon.d.ts +2 -1
- package/dist/lib/dashboard-icon.js +10 -2
- package/dist/lib/dashboard-navigation.d.ts +24 -0
- package/dist/lib/dashboard-navigation.js +1 -1
- package/dist/lib/dashboard-queries.d.ts +11 -0
- package/dist/lib/dashboard-queries.js +20 -0
- package/dist/lib/dashboard-search.d.ts +5 -0
- package/dist/lib/dashboard-search.js +12 -0
- package/dist/lib/dashboard-sharing.js +2 -1
- package/dist/lib/dashboard-view.schema.d.ts +1249 -0
- package/dist/lib/dashboard-view.schema.js +19 -0
- package/dist/lib/dashboard.schema.d.ts +12 -12
- package/dist/lib/dashboard.schema.js +5 -3
- package/dist/lib/dashboard.service.d.ts +11 -3
- package/dist/lib/dashboard.service.js +55 -21
- package/dist/lib/definition-tools.d.ts +56 -0
- package/dist/lib/definition-tools.js +42 -0
- package/dist/lib/document-host.d.ts +4 -0
- package/dist/lib/document-host.js +13 -0
- package/dist/lib/document-network.d.ts +3 -0
- package/dist/lib/document-network.js +9 -0
- package/dist/lib/document-package.d.ts +1 -1
- package/dist/lib/document-package.js +2 -2
- package/dist/lib/html-guidance.d.ts +1 -1
- package/dist/lib/html-guidance.js +1 -1
- package/dist/lib/middleware.js +54 -18
- package/dist/lib/plugin.js +3 -1
- package/dist/lib/presentation.provider.d.ts +6 -1
- package/dist/lib/presentation.provider.js +2 -2
- package/dist/lib/preview-retry.d.ts +7 -0
- package/dist/lib/preview-retry.js +52 -0
- package/dist/lib/renderer.js +5 -0
- package/dist/lib/resource-card.js +1 -1
- package/dist/lib/save-evidence.d.ts +1 -1
- package/dist/lib/sharing.service.js +2 -0
- package/dist/lib/view.provider.d.ts +7 -2
- package/dist/lib/view.provider.js +5 -4
- package/dist/remote/app.css +1 -1
- package/dist/remote/app.js +36 -36
- package/dist/remote/build-manifest.json +42 -30
- package/dist/sandbox-actions/action.json +1 -1
- package/dist/sandbox-actions/bundle/host.js +2 -2
- package/dist/sandbox-actions/bundle/validate.mjs +24 -3
- package/dist/validation/host-entry.d.ts +3 -1
- package/dist/validation/host-entry.js +5 -2
- package/docs/drafts.mdx +1 -1
- package/docs/frontend-libraries.mdx +3 -3
- package/docs/html-mode.md +5 -5
- package/docs/index.mdx +14 -0
- package/docs/team-sharing.mdx +1 -1
- package/docs/verification.mdx +3 -1
- package/examples/data-xpert-sales.json +6 -3
- package/examples/postgres-sales.json +5 -3
- package/package.json +6 -6
- package/skills/live-dashboard/SKILL.md +1 -1
- package/skills/live-dashboard/references/data-validation.md +4 -0
- package/skills/live-dashboard/references/html-runtime.md +1 -1
package/dist/lib/middleware.js
CHANGED
|
@@ -10,6 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DashboardMiddleware = exports.DASHBOARD_GUIDANCE = void 0;
|
|
13
|
+
const definition_tools_1 = require("./definition-tools");
|
|
14
|
+
const analytics_source_1 = require("./analytics-source");
|
|
15
|
+
const analytics_1 = require("@xpert-ai/plugin-sdk/analytics");
|
|
13
16
|
const messages_1 = require("@langchain/core/messages");
|
|
14
17
|
const tools_1 = require("@langchain/core/tools");
|
|
15
18
|
const node_crypto_1 = require("node:crypto");
|
|
@@ -17,6 +20,7 @@ const v3_1 = require("zod/v3");
|
|
|
17
20
|
const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
|
|
18
21
|
const artifact_document_1 = require("@xpert-ai/plugin-sdk/artifact-document");
|
|
19
22
|
const document_libraries_1 = require("./document-libraries");
|
|
23
|
+
const document_network_1 = require("./document-network");
|
|
20
24
|
const agent_schema_1 = require("./agent.schema");
|
|
21
25
|
const html_guidance_1 = require("./html-guidance");
|
|
22
26
|
const dashboard_service_1 = require("./dashboard.service");
|
|
@@ -28,6 +32,7 @@ const filter_evidence_1 = require("./filter-evidence");
|
|
|
28
32
|
const save_evidence_1 = require("./save-evidence");
|
|
29
33
|
const resource_card_1 = require("./resource-card");
|
|
30
34
|
const dashboard_icon_1 = require("./dashboard-icon");
|
|
35
|
+
const preview_retry_1 = require("./preview-retry");
|
|
31
36
|
const middlewareOptionsSchema = v3_1.z.object({ allowedFinalProviders: v3_1.z.array(v3_1.z.string().min(1)).min(1).max(20).optional() }).strict().default({});
|
|
32
37
|
exports.DASHBOARD_GUIDANCE = `For a new independent dashboard, use a new unused HTML file path. An existing filename or matching title is not authorization to edit another Artifact; do not switch from creation to dashboard_open/update because a file already exists. For a new dashboard, call dashboard_list_sources before searching raw files, reading old scripts or creating transformations. Named governed sources may already provide the required query; inspect their provider contracts first. File-backed sources do not imply that a script must be written. For creating or editing live dashboards, first read the installed live-dashboard skill using read_skill_file and follow only the references relevant to the task. Use SandboxFile tools for all source-file authoring; HTML alone is not a saved dashboard. Follow preview.validation.checks immediately before authoring HTML; each suggestedCall must actually succeed. Business definitions, real data previews and nullable-filter tests are required before saving new or changed Bindings. Do not invent business data or substitute a different metric without agreement. Report completion only from a successful dashboard_create/dashboard_create_html/dashboard_update draft receipt. Human publication is separate. Successful create, update and open tools emit a chat resource card automatically; resourceCard.status reports emission. Its Open button selects the exact dashboard in Workbench. Never fabricate a link, call present_files for dashboard HTML, or output card JSON as text. If card delivery is unavailable, report the saved receipt and use the Workbench picker.`;
|
|
33
38
|
let DashboardMiddleware = class DashboardMiddleware {
|
|
@@ -53,13 +58,37 @@ let DashboardMiddleware = class DashboardMiddleware {
|
|
|
53
58
|
};
|
|
54
59
|
// Evidence belongs to this run and actor, never a process-wide cache of business data.
|
|
55
60
|
const discovered = new Map(), previews = new Map();
|
|
61
|
+
const discovering = new Map();
|
|
56
62
|
let listedSources;
|
|
63
|
+
const assertSourceSelection = (input) => {
|
|
64
|
+
if (listedSources && !listedSources.some(source => (0, analytics_source_1.sameAnalyticsResource)(source.source, input.source) && source.providers.some(provider => provider.id === input.providerId)))
|
|
65
|
+
throw new Error(`DASHBOARD_SOURCE_SELECTION_INVALID: copy an exact source/providerId pair from dashboard_list_sources; do not invent or combine IDs. Known pairs: ${JSON.stringify(listedSources.map(source => ({ source: source.source, name: source.name, providerIds: source.providers.map(provider => provider.id) })))}. Refresh the list if the source changed. Initial requestJson is "{}"; then follow inspectRequest/nextRequest.`);
|
|
66
|
+
};
|
|
67
|
+
const discover = async (input) => {
|
|
68
|
+
assertSourceSelection(input);
|
|
69
|
+
const result = await this.service.discover(scope, input);
|
|
70
|
+
discovered.set(`${(0, analytics_1.analyticsSourceKey)(input.source)}/${input.providerId}`, result.queryContract);
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
const ensureContract = async (input) => {
|
|
74
|
+
assertSourceSelection(input);
|
|
75
|
+
const key = `${(0, analytics_1.analyticsSourceKey)(input.source)}/${input.providerId}`;
|
|
76
|
+
const cached = discovered.get(key);
|
|
77
|
+
if (cached)
|
|
78
|
+
return cached;
|
|
79
|
+
// Parallel previews share discovery, but failures are retryable and never become evidence.
|
|
80
|
+
let pending = discovering.get(key);
|
|
81
|
+
if (!pending) {
|
|
82
|
+
pending = discover({ source: input.source, providerId: input.providerId, request: {} })
|
|
83
|
+
.then(result => result.queryContract).finally(() => discovering.delete(key));
|
|
84
|
+
discovering.set(key, pending);
|
|
85
|
+
}
|
|
86
|
+
return pending;
|
|
87
|
+
};
|
|
57
88
|
const filterEvidence = (0, filter_evidence_1.createFilterEvidence)(this.service, scope, previews);
|
|
58
89
|
const created = new Map();
|
|
59
90
|
const preview = async (binding) => {
|
|
60
|
-
const contract =
|
|
61
|
-
if (!contract)
|
|
62
|
-
throw new Error('DASHBOARD_DISCOVER_REQUIRED');
|
|
91
|
+
const contract = await ensureContract(binding);
|
|
63
92
|
(0, plugin_sdk_1.validateAnalyticsPayload)(binding.payload, contract.payloadSchema);
|
|
64
93
|
const controls = Object.fromEntries(binding.parameters.map((parameter) => [parameter.controlId, parameter.defaultValue ?? null]));
|
|
65
94
|
const dataset = await this.service.preview(scope, { binding, controls });
|
|
@@ -96,7 +125,7 @@ let DashboardMiddleware = class DashboardMiddleware {
|
|
|
96
125
|
const save = async (input, config, html, dependencies = []) => {
|
|
97
126
|
const { previewIds, supersedesPaths, ...definition } = input;
|
|
98
127
|
const bindings = resolvePreviews(previewIds);
|
|
99
|
-
const manifest = dashboard_schema_1.dashboardSchema.parse({ ...definition, bindings, schema: 'xpert.live-dashboard
|
|
128
|
+
const manifest = dashboard_schema_1.dashboardSchema.parse({ ...definition, bindings, schema: 'xpert.live-dashboard', id: (0, node_crypto_1.randomUUID)(),
|
|
100
129
|
...(html ? { presentation: { type: 'html', html, ...(dependencies.length ? { dependencies } : {}) } } : {}) });
|
|
101
130
|
validateFinal(manifest, true);
|
|
102
131
|
const key = hash({ input: { ...definition, previewIds }, html, dependencies });
|
|
@@ -121,6 +150,7 @@ let DashboardMiddleware = class DashboardMiddleware {
|
|
|
121
150
|
throw new Error('DASHBOARD_WORKSPACE_REQUIRED');
|
|
122
151
|
return files;
|
|
123
152
|
});
|
|
153
|
+
const previewRetries = (0, preview_retry_1.createPreviewRetryGuard)();
|
|
124
154
|
let modelCalls = 0;
|
|
125
155
|
return { name: 'LiveDashboard', contextSchema: editing_1.dashboardContextSchema,
|
|
126
156
|
wrapToolCall: async (request, handler) => {
|
|
@@ -131,24 +161,36 @@ let DashboardMiddleware = class DashboardMiddleware {
|
|
|
131
161
|
: name === 'dashboard_create' ? agent_schema_1.createToolSchema.safeParse(args) : undefined;
|
|
132
162
|
const save = dashboard_receipt_1.DASHBOARD_MUTATION_TOOLS.includes(name) ? evidence.beginSave(creation?.success ? creation.data.supersedesPaths : undefined, name === 'dashboard_create' ? 'draft' : 'source') : undefined;
|
|
133
163
|
const result = path && (evidence.has(path) || previews.size > 0 && agent_schema_1.htmlPathSchema.safeParse(path).success)
|
|
134
|
-
? await evidence.trackWrite(path, async () => handler(request)) : await
|
|
164
|
+
? await evidence.trackWrite(path, async () => handler(request)) : await previewRetries.run(request, handler);
|
|
135
165
|
if (save && 'content' in result && (!('status' in result) || result.status !== 'error'))
|
|
136
166
|
await evidence.accept(save, result.content);
|
|
137
167
|
return result;
|
|
138
168
|
}, wrapModelCall: async (request, handler) => {
|
|
169
|
+
if (previewRetries.exhausted) {
|
|
170
|
+
const summary = previewRetries.summary + (evidence.pending ? ` Unsaved Workspace files: ${JSON.stringify(evidence.pendingPaths)}.` : '');
|
|
171
|
+
const result = await handler({ ...request, tools: [], toolChoice: 'none', systemMessage: new messages_1.SystemMessage({ content: [
|
|
172
|
+
...(typeof request.systemMessage?.content === 'string' ? [{ type: 'text', text: request.systemMessage.content }] : request.systemMessage?.content ?? []),
|
|
173
|
+
{ type: 'text', text: summary }
|
|
174
|
+
] }) });
|
|
175
|
+
// A noncompliant model must not restart the failed loop even after tools were removed.
|
|
176
|
+
return result?.tool_calls?.length ? new messages_1.AIMessage(summary) : result;
|
|
177
|
+
}
|
|
139
178
|
const exhausted = ++modelCalls > 24;
|
|
140
179
|
if (exhausted && evidence.pending)
|
|
141
180
|
throw new Error('DASHBOARD_SAVE_NOT_CONFIRMED: no successful draft save receipt; Workspace changes have not been saved to the dashboard.');
|
|
142
181
|
const result = await handler({ ...request, ...(evidence.pending ? { toolChoice: 'required' } : {}), ...(exhausted ? { tools: [] } : {}), systemMessage: new messages_1.SystemMessage({ content: [
|
|
143
182
|
...(typeof request.systemMessage?.content === 'string' ? [{ type: 'text', text: request.systemMessage.content }] : request.systemMessage?.content ?? []),
|
|
144
|
-
{ type: 'text', text: exports.DASHBOARD_GUIDANCE + '\n' + html_guidance_1.HTML_DASHBOARD_GUIDANCE + '\n' + editing_1.EDITING_GUIDANCE + (evidence.pending ? `\nDashboard changes are pending without a matching draft save receipt. Unsaved files: ${JSON.stringify(evidence.pendingPaths)}. Continue reading/repairing and call dashboard_create_html or dashboard_update with the exact file path; do not finish or claim it was saved. When abandoning earlier unsaved HTML creation candidates, explicitly pass their exact paths as supersedesPaths to dashboard_create or dashboard_create_html, matching the requested presentation mode. If a standard dashboard is already saved, repeat dashboard_create with the same definition/previewIds and supersedesPaths; do not create an unwanted HTML dashboard. This only abandons those candidates after a successful save; it never discards another Artifact editing copy.` : '') + (options.allowedFinalProviders ? `\nThis Assistant requires every saved dashboard binding to use one of these providers: ${options.allowedFinalProviders.join(', ')}. Other providers may be previewed only as upstream inputs. Do not save a direct-source substitute.` : '') + (exhausted ? '\nThe dashboard tool budget is exhausted. Stop calls; report only saved receipts or explain the concrete blocker truthfully.' : '') }
|
|
183
|
+
{ type: 'text', text: exports.DASHBOARD_GUIDANCE + '\n' + definition_tools_1.DEFINITION_GUIDANCE + '\n' + html_guidance_1.HTML_DASHBOARD_GUIDANCE + '\n' + editing_1.EDITING_GUIDANCE + (evidence.pending ? `\nDashboard changes are pending without a matching draft save receipt. Unsaved files: ${JSON.stringify(evidence.pendingPaths)}. Continue reading/repairing and call dashboard_create_html or dashboard_update with the exact file path; do not finish or claim it was saved. When abandoning earlier unsaved HTML creation candidates, explicitly pass their exact paths as supersedesPaths to dashboard_create or dashboard_create_html, matching the requested presentation mode. If a standard dashboard is already saved, repeat dashboard_create with the same definition/previewIds and supersedesPaths; do not create an unwanted HTML dashboard. This only abandons those candidates after a successful save; it never discards another Artifact editing copy.` : '') + (options.allowedFinalProviders ? `\nThis Assistant requires every saved dashboard binding to use one of these providers: ${options.allowedFinalProviders.join(', ')}. Other providers may be previewed only as upstream inputs. Do not save a direct-source substitute.` : '') + (exhausted ? '\nThe dashboard tool budget is exhausted. Stop calls; report only saved receipts or explain the concrete blocker truthfully.' : '') }
|
|
145
184
|
] }) });
|
|
146
185
|
if (evidence.pending && result && !result.tool_calls?.length)
|
|
147
186
|
throw new Error('DASHBOARD_SAVE_NOT_CONFIRMED: the model stopped without a successful draft save receipt.');
|
|
148
187
|
return result;
|
|
149
188
|
}, tools: [
|
|
150
189
|
filterEvidence.tool,
|
|
190
|
+
...(0, definition_tools_1.createDefinitionTools)(context, () => { listedSources = undefined; }),
|
|
151
191
|
(0, tools_1.tool)(async () => JSON.stringify({ libraries: await (0, document_libraries_1.libraryLocks)(['echarts', 'three']),
|
|
192
|
+
online: { ...document_network_1.DASHBOARD_NETWORK_POLICY,
|
|
193
|
+
usage: 'HTML may load scripts, stylesheets and fonts directly from these exact HTTPS origins. Use script src and link rel="stylesheet"; pin exact versions where available. Tailwind CDN https://cdn.tailwindcss.com is supported. Online resources require connectivity when saving and viewing; loading failures fail preflight. Keep all business data queries on window.xpertLiveArtifact; fetch/XHR, external images, workers, iframes and eval remain unavailable. Online resources do not belong in the packaged libraries array.' },
|
|
152
194
|
pageRuntime: {
|
|
153
195
|
global: 'window.xpertLiveArtifact',
|
|
154
196
|
bindingIds: [...new Set([...previews.values()].map(binding => binding.id))],
|
|
@@ -158,7 +200,7 @@ let DashboardMiddleware = class DashboardMiddleware {
|
|
|
158
200
|
},
|
|
159
201
|
usage: { echarts: 'window.echarts: init(element, null, {renderer:"svg"}) then setOption(completeOption, {notMerge:true}). Canvas is also available. Derive active series/legend dimensions from each received Dataset, including filtered results; never retain excluded groups as zero-valued series. Aggregate repeated categories using all grain dimensions, clear empty results, and redraw KPI, chart and details together in subscribe. Use ResizeObserver to resize and reuse the instance on filter/refresh.',
|
|
160
202
|
three: 'window.THREE: bundled core including WebGLRenderer. Requires WebGL2; catch unavailable GPU contexts and show a clear fallback. External textures/models, loaders/addons, WebGPU and workers are not bundled.' },
|
|
161
|
-
lifecycle: 'Pass
|
|
203
|
+
lifecycle: 'Pass packaged library IDs to dashboard_create_html or dashboard_update. Actual version and bytes are pinned on save; omitted libraries on update preserves saved locks. Online resources are listed separately under online, are not pinned in the Artifact, and must load successfully when saving and viewing.' }), { name: 'dashboard_libraries', description: 'Discover packaged frontend libraries, exact versions and allowed HTTPS origins for online scripts, stylesheets and fonts. Read before using Tailwind CDN or ECharts/Three.js. Returns metadata, never library source.',
|
|
162
204
|
schema: v3_1.z.object({}).strict(), verboseParsingErrors: true, metadata: { toolName: { en_US: 'Discover dashboard libraries', zh_Hans: '查看看板前端图库' } } }),
|
|
163
205
|
...(0, editing_1.createEditingTools)(this.service, scope, context, resolvePreviews, validateFinal, (path, artifactId) => evidence.opened(path, artifactId)),
|
|
164
206
|
(0, tools_1.tool)(async () => {
|
|
@@ -169,24 +211,18 @@ let DashboardMiddleware = class DashboardMiddleware {
|
|
|
169
211
|
schema: v3_1.z.object({}).strict(), verboseParsingErrors: true, metadata: { toolName: { en_US: 'List analytics sources', zh_Hans: '发现分析数据源' } }
|
|
170
212
|
}),
|
|
171
213
|
(0, tools_1.tool)(async (input) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const parsed = { dataSourceId: input.dataSourceId, providerId: input.providerId, request: (0, agent_schema_1.parseObjectJson)(input.requestJson) };
|
|
175
|
-
const result = await this.service.discover(scope, parsed);
|
|
176
|
-
discovered.set(`${parsed.dataSourceId}/${parsed.providerId}`, result.queryContract);
|
|
177
|
-
return JSON.stringify(result);
|
|
214
|
+
const parsed = { source: input.source, providerId: input.providerId, request: (0, agent_schema_1.parseObjectJson)(input.requestJson) };
|
|
215
|
+
return JSON.stringify(await discover(parsed));
|
|
178
216
|
}, { name: 'dashboard_discover', description: 'Discover provider-owned business metadata. Start requestJson="{}" then serialize inspectRequest/nextRequest. Inspect dataset fields, comments, measures and native query format before preview.',
|
|
179
217
|
schema: agent_schema_1.discoverToolSchema, verboseParsingErrors: true, metadata: { toolName: { en_US: 'Inspect business data', zh_Hans: '理解业务数据与指标' } } }),
|
|
180
218
|
(0, tools_1.tool)(async (input) => {
|
|
181
|
-
const contract =
|
|
182
|
-
if (!contract)
|
|
183
|
-
throw new Error('DASHBOARD_DISCOVER_REQUIRED: discover the source before preview');
|
|
219
|
+
const contract = await ensureContract(input.binding);
|
|
184
220
|
const binding = (0, agent_schema_1.fromAgentBinding)(input.binding, contract);
|
|
185
221
|
return preview(binding);
|
|
186
|
-
}, { name: 'dashboard_preview', description: 'Run one read-only binding using parameters[].defaultValue. Returns validated Dataset fields, first 20 rows, full query completeness and audit. Required before create; changes to binding/defaults require another preview.',
|
|
222
|
+
}, { name: 'dashboard_preview', description: 'Run one read-only binding using parameters[].defaultValue. Automatically discovers the source/provider query contract when absent in this run; use dashboard_discover to inspect business metadata or repair invalid queries. Returns validated Dataset fields, first 20 rows, full query completeness and audit. Required before create; changes to binding/defaults require another preview.',
|
|
187
223
|
schema: agent_schema_1.previewToolSchema, verboseParsingErrors: true, metadata: { toolName: { en_US: 'Verify dashboard data', zh_Hans: '预览并验证看板数据' } } }),
|
|
188
224
|
(0, tools_1.tool)(async ({ bindingJson }) => preview(plugin_sdk_1.analyticsBindingSchema.parse(JSON.parse(bindingJson))), {
|
|
189
|
-
name: 'dashboard_preview_binding', description: 'Preview a complete canonical AnalyticsBinding returned by another tool. Serialize the complete canonical Binding (for example discovery items[].metadata.binding), including parameters[].controlId. bindingPayload is only the payload, not a Binding. If adding a parameter, include name, controlId, type, required and defaultValue. Do not convert it to the simplified dashboard_preview input.
|
|
225
|
+
name: 'dashboard_preview_binding', description: 'Preview a complete canonical AnalyticsBinding returned by another tool. Serialize the complete canonical Binding (for example discovery items[].metadata.binding), including parameters[].controlId. bindingPayload is only the payload, not a Binding. If adding a parameter, include name, controlId, type, required and defaultValue. Do not convert it to the simplified dashboard_preview input. Automatically discovers the source/provider query contract when absent in this run; use dashboard_discover for business metadata. Returns the same previewId receipt for dashboard_create.',
|
|
190
226
|
schema: v3_1.z.object({ bindingJson: v3_1.z.string().min(2).max(200000) }).strict(), verboseParsingErrors: true,
|
|
191
227
|
metadata: { toolName: { en_US: 'Verify registered dataset', zh_Hans: '验证已注册数据集' } }
|
|
192
228
|
}),
|
package/dist/lib/plugin.js
CHANGED
|
@@ -7,6 +7,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.LiveDashboardPlugin = void 0;
|
|
10
|
+
const content_capability_1 = require("./content-capability");
|
|
11
|
+
const content_provider_1 = require("./content.provider");
|
|
10
12
|
const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
|
|
11
13
|
const dashboard_service_1 = require("./dashboard.service");
|
|
12
14
|
const view_provider_1 = require("./view.provider");
|
|
@@ -18,5 +20,5 @@ let LiveDashboardPlugin = class LiveDashboardPlugin {
|
|
|
18
20
|
};
|
|
19
21
|
exports.LiveDashboardPlugin = LiveDashboardPlugin;
|
|
20
22
|
exports.LiveDashboardPlugin = LiveDashboardPlugin = __decorate([
|
|
21
|
-
(0, plugin_sdk_1.XpertServerPlugin)({ providers: [dashboard_service_1.DashboardService, view_provider_1.DashboardViewProvider, middleware_1.DashboardMiddleware, html_validation_1.HtmlDashboardValidation, presentation_provider_1.DashboardPresentationProvider, sharing_service_1.DashboardSharingService] })
|
|
23
|
+
(0, plugin_sdk_1.XpertServerPlugin)({ providers: [content_capability_1.DashboardCapability, content_provider_1.DashboardContentProvider, content_provider_1.DashboardContentEditor, dashboard_service_1.DashboardService, view_provider_1.DashboardViewProvider, middleware_1.DashboardMiddleware, html_validation_1.HtmlDashboardValidation, presentation_provider_1.DashboardPresentationProvider, sharing_service_1.DashboardSharingService] })
|
|
22
24
|
], LiveDashboardPlugin);
|
|
@@ -17,7 +17,7 @@ export declare class DashboardPresentationProvider implements IArtifactPresentat
|
|
|
17
17
|
title: string;
|
|
18
18
|
isDraft: boolean;
|
|
19
19
|
manifest: {
|
|
20
|
-
schema: "xpert.live-dashboard
|
|
20
|
+
schema: "xpert.live-dashboard";
|
|
21
21
|
id: string;
|
|
22
22
|
title: string;
|
|
23
23
|
bindings: import("@xpert-ai/contracts").AnalyticsBinding[];
|
|
@@ -117,6 +117,11 @@ export declare class DashboardPresentationProvider implements IArtifactPresentat
|
|
|
117
117
|
};
|
|
118
118
|
} | undefined;
|
|
119
119
|
datasets: import("@xpert-ai/contracts").AnalyticalDataset[];
|
|
120
|
+
failures: {
|
|
121
|
+
bindingId: string;
|
|
122
|
+
datasetId: string;
|
|
123
|
+
reason: "unavailable";
|
|
124
|
+
}[];
|
|
120
125
|
}>;
|
|
121
126
|
private open;
|
|
122
127
|
}
|
|
@@ -44,8 +44,8 @@ let DashboardPresentationProvider = class DashboardPresentationProvider {
|
|
|
44
44
|
return (0, dashboard_queries_1.queryDashboardBinding)(this.runtime, context.actor, saved.manifest, input.bindingId, input.controls);
|
|
45
45
|
if (request.operation !== 'query')
|
|
46
46
|
throw new common_1.ForbiddenException('DASHBOARD_ACTION_UNSUPPORTED');
|
|
47
|
-
const datasets = await (0, dashboard_queries_1.
|
|
48
|
-
return { datasets, ...(saved.manifest.presentation ? {} : { payload: (0, renderer_1.toDataAnalyticsPayload)(saved.manifest, datasets) }) };
|
|
47
|
+
const { datasets, failures } = await (0, dashboard_queries_1.queryDashboardPartial)(this.runtime, context.actor, saved.manifest, input.controls);
|
|
48
|
+
return { datasets, failures, ...(saved.manifest.presentation ? {} : { payload: (0, renderer_1.toDataAnalyticsPayload)(saved.manifest, datasets) }) };
|
|
49
49
|
}
|
|
50
50
|
open(context) {
|
|
51
51
|
const { artifact, version, content } = context;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentBuiltInState, ToolCallHandler, ToolCallRequest } from '@xpert-ai/plugin-sdk';
|
|
2
|
+
/** Run-local bounds include tool-schema failures, before any discovery or query executes. */
|
|
3
|
+
export declare function createPreviewRetryGuard(): {
|
|
4
|
+
readonly exhausted: boolean;
|
|
5
|
+
readonly summary: string;
|
|
6
|
+
run(request: ToolCallRequest<AgentBuiltInState>, handler: ToolCallHandler): Promise<import("@langchain/core/messages").ToolMessage | import("@langchain/langgraph").Command<unknown, Record<string, unknown>, string>>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPreviewRetryGuard = createPreviewRetryGuard;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const PREVIEW_TOOLS = new Set(['dashboard_preview', 'dashboard_preview_binding', 'dashboard_test_filter']);
|
|
6
|
+
/** Run-local bounds include tool-schema failures, before any discovery or query executes. */
|
|
7
|
+
function createPreviewRetryGuard() {
|
|
8
|
+
const failures = new Map(), pending = new Set();
|
|
9
|
+
let consecutiveFailures = 0, lastError = '';
|
|
10
|
+
const recordFailure = (key, message) => {
|
|
11
|
+
failures.set(key, { count: (failures.get(key)?.count ?? 0) + 1, message: message.slice(0, 2000) });
|
|
12
|
+
consecutiveFailures++;
|
|
13
|
+
lastError = message.slice(0, 2000);
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
get exhausted() { return consecutiveFailures >= 6; },
|
|
17
|
+
get summary() { return `DASHBOARD_PREVIEW_RETRY_LIMIT: preview validation repeatedly failed. This run has stopped making tool calls. Report the last error and the required repair; do not claim an unconfirmed save. Last error: ${lastError}`; },
|
|
18
|
+
async run(request, handler) {
|
|
19
|
+
if (!PREVIEW_TOOLS.has(request.toolCall.name))
|
|
20
|
+
return handler(request);
|
|
21
|
+
const key = (0, node_crypto_1.createHash)('sha256').update(JSON.stringify({ name: request.toolCall.name, args: request.toolCall.args }, (_key, value) => value && typeof value === 'object' && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b))) : value)).digest('hex');
|
|
22
|
+
if (consecutiveFailures >= 6)
|
|
23
|
+
throw new Error(this.summary);
|
|
24
|
+
if ((failures.get(key)?.count ?? 0) >= 2) {
|
|
25
|
+
consecutiveFailures++;
|
|
26
|
+
throw new Error(`DASHBOARD_PREVIEW_REPEAT_BLOCKED: this exact tool input already failed twice; no query was executed. Correct the input using the previous diagnostic, or stop and report the blocker. Last error: ${failures.get(key).message}`);
|
|
27
|
+
}
|
|
28
|
+
// Concurrent duplicate calls must not multiply queries or bypass the per-input bound.
|
|
29
|
+
if (pending.has(key))
|
|
30
|
+
throw new Error('DASHBOARD_PREVIEW_IN_PROGRESS: wait for the identical preview already in progress; do not submit duplicates.');
|
|
31
|
+
pending.add(key);
|
|
32
|
+
try {
|
|
33
|
+
const result = await handler(request);
|
|
34
|
+
if ('status' in result && result.status === 'error' && 'content' in result) {
|
|
35
|
+
recordFailure(key, typeof result.content === 'string' ? result.content : 'Preview tool returned an error');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
failures.delete(key);
|
|
39
|
+
consecutiveFailures = 0;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
recordFailure(key, error instanceof Error ? error.message : 'Preview tool failed');
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
pending.delete(key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/lib/renderer.js
CHANGED
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toDataAnalyticsPayload = toDataAnalyticsPayload;
|
|
4
4
|
/** The only Data Analytics v1 translation. Providers never see chart encoding syntax. */
|
|
5
5
|
function toDataAnalyticsPayload(manifest, datasets) {
|
|
6
|
+
// Missing datasets are failures, not empty/zero business results. The caller renders
|
|
7
|
+
// their failure state separately; successful empty datasets still retain their views.
|
|
8
|
+
const available = new Set(datasets.map(dataset => dataset.datasetId));
|
|
9
|
+
manifest = { ...manifest, charts: manifest.charts.filter(chart => available.has(chart.datasetId)),
|
|
10
|
+
tables: manifest.tables.filter(table => available.has(table.datasetId)) };
|
|
6
11
|
const snapshot = Object.fromEntries(datasets.flatMap((dataset) => [
|
|
7
12
|
[dataset.datasetId, dataset.rows],
|
|
8
13
|
...(!manifest.charts.some((chart) => chart.datasetId === dataset.datasetId) ? [] : [[`__plot.${dataset.datasetId}`, dataset.rows.map((row) => Object.fromEntries(dataset.fields.map((field) => [field.id, manifest.charts.some((chart) => chart.datasetId === dataset.datasetId && [chart.x, chart.y].includes(field.id)) ? renderValue(row[field.id], field.logicalType) : row[field.id]])))]])
|
|
@@ -13,7 +13,7 @@ function dashboardResourceCard(scope, saved) {
|
|
|
13
13
|
resource: { namespace: 'live_dashboard', type: 'live-dashboard', id: saved.artifactId, artifactId: saved.artifactId },
|
|
14
14
|
title: saved.title,
|
|
15
15
|
description: saved.state === 'draft' ? `Dashboard · Draft r${saved.revision}` : `Dashboard · v${saved.versionNumber}`,
|
|
16
|
-
icon: dashboard_icon_1.dashboardIcon,
|
|
16
|
+
icon: { type: dashboard_icon_1.dashboardIcon.type, value: dashboard_icon_1.dashboardIcon.value },
|
|
17
17
|
open: {
|
|
18
18
|
...(0, dashboard_navigation_1.dashboardNavigationTarget)(scope), selectionId: saved.artifactId,
|
|
19
19
|
...(saved.state === 'published' && saved.versionId ? { parameters: { versionId: saved.versionId } } : {})
|
|
@@ -15,7 +15,7 @@ export declare function dashboardSaveEvidence(files: () => WorkspaceFilesApi): {
|
|
|
15
15
|
token: number;
|
|
16
16
|
generations: Map<string, number>;
|
|
17
17
|
supersedesPaths: string[];
|
|
18
|
-
confirmation: "
|
|
18
|
+
confirmation: "draft" | "source";
|
|
19
19
|
};
|
|
20
20
|
accept(save: SaveAttempt, output: unknown): Promise<void>;
|
|
21
21
|
readonly pending: boolean;
|
|
@@ -41,6 +41,7 @@ let DashboardSharingService = class DashboardSharingService {
|
|
|
41
41
|
versionId: link.artifactVersionId, url: link.presentationUrl, expiresAt: link.expiresAt } : null };
|
|
42
42
|
}
|
|
43
43
|
async share(context, input) {
|
|
44
|
+
await this.dashboards.authorizeProject(context, 'manage');
|
|
44
45
|
const state = await this.inspect(context, input.artifactId, input.versionMode === 'version' ? input.versionId : undefined);
|
|
45
46
|
if (state.issues.length || !state.published?.versionId)
|
|
46
47
|
throw new common_1.BadRequestException({ code: 'DASHBOARD_SHARE_BLOCKED', issues: state.issues });
|
|
@@ -52,6 +53,7 @@ let DashboardSharingService = class DashboardSharingService {
|
|
|
52
53
|
return this.inspect(context, input.artifactId, input.versionMode === 'version' ? input.versionId : undefined);
|
|
53
54
|
}
|
|
54
55
|
async revoke(context, artifactId) {
|
|
56
|
+
await this.dashboards.authorizeProject(context, 'manage');
|
|
55
57
|
await this.dashboards.history(context, artifactId);
|
|
56
58
|
await this.runtime.require(plugin_sdk_1.ArtifactsRuntimeCapability).revokeArtifactShare({ artifactId, shareKey: dashboard_sharing_1.DASHBOARD_SHARE_KEY });
|
|
57
59
|
return this.inspect(context, artifactId);
|
|
@@ -19,7 +19,7 @@ export declare class DashboardViewProvider implements IXpertViewExtensionProvide
|
|
|
19
19
|
meta: {
|
|
20
20
|
saved?: {
|
|
21
21
|
manifest: {
|
|
22
|
-
schema: "xpert.live-dashboard
|
|
22
|
+
schema: "xpert.live-dashboard";
|
|
23
23
|
id: string;
|
|
24
24
|
title: string;
|
|
25
25
|
bindings: import("@xpert-ai/contracts").AnalyticsBinding[];
|
|
@@ -191,8 +191,13 @@ export declare class DashboardViewProvider implements IXpertViewExtensionProvide
|
|
|
191
191
|
};
|
|
192
192
|
} | undefined;
|
|
193
193
|
datasets: import("@xpert-ai/contracts").AnalyticalDataset[];
|
|
194
|
+
failures: {
|
|
195
|
+
bindingId: string;
|
|
196
|
+
datasetId: string;
|
|
197
|
+
reason: "unavailable";
|
|
198
|
+
}[];
|
|
194
199
|
manifest: {
|
|
195
|
-
schema: "xpert.live-dashboard
|
|
200
|
+
schema: "xpert.live-dashboard";
|
|
196
201
|
id: string;
|
|
197
202
|
title: string;
|
|
198
203
|
bindings: import("@xpert-ai/contracts").AnalyticsBinding[];
|
|
@@ -20,6 +20,7 @@ const sharing_service_1 = require("./sharing.service");
|
|
|
20
20
|
const dashboard_schema_1 = require("./dashboard.schema");
|
|
21
21
|
const dashboard_receipt_1 = require("./dashboard-receipt");
|
|
22
22
|
const dashboard_navigation_1 = require("./dashboard-navigation");
|
|
23
|
+
const dashboard_icon_1 = require("./dashboard-icon");
|
|
23
24
|
exports.VIEW_KEY = 'live-dashboard';
|
|
24
25
|
exports.VIEW_PROVIDER = 'live-dashboard';
|
|
25
26
|
exports.FEATURE = 'live_dashboard';
|
|
@@ -31,15 +32,15 @@ let DashboardViewProvider = class DashboardViewProvider {
|
|
|
31
32
|
}
|
|
32
33
|
supports(context) { return context.hostType === 'agent' || context.hostType === 'project'; }
|
|
33
34
|
getViewManifests(context, slot) {
|
|
34
|
-
if (!(context.hostType === 'agent' &&
|
|
35
|
+
if (!(context.hostType === 'agent' && ['agent.workbench', 'agent.workbench.fixed', 'agent.workbench.main'].includes(slot) || context.hostType === 'project' && slot === 'detail.sections'))
|
|
35
36
|
return [];
|
|
36
37
|
return [{ key: exports.VIEW_KEY, title: text('Live dashboards', '实时看板'), hostType: context.hostType, slot, order: 35,
|
|
37
|
-
icon:
|
|
38
|
+
icon: dashboard_icon_1.dashboardIcon, refreshable: true, activation: { projectResource: true, requiredFeatures: [exports.FEATURE] },
|
|
38
39
|
source: { provider: exports.VIEW_PROVIDER, plugin: dashboard_service_1.PLUGIN_NAME },
|
|
39
|
-
workbench: { fixed: true, menu: { enabled: true, label: text('Live dashboards', '实时看板'), order: 35 } },
|
|
40
|
+
workbench: { fixed: true, openMode: 'on-demand', menu: { enabled: true, label: text('Live dashboards', '实时看板'), icon: dashboard_icon_1.dashboardIcon, order: 35 } },
|
|
40
41
|
view: { type: 'remote_component', runtime: 'react', protocolVersion: 1, component: { isolation: 'iframe', entry: exports.VIEW_KEY }, dataSource: { mode: 'platform' } },
|
|
41
42
|
dataSource: { mode: 'platform', querySchema: { supportsSelection: true, supportsParameters: true }, cache: { enabled: false } },
|
|
42
|
-
clientCommands: [{ key: contracts_1.ASSISTANT_CONTEXT_SET_COMMAND, label: text('Select dashboard for Assistant', '设置助理当前看板') },
|
|
43
|
+
clientCommands: [{ key: 'workbench.content.status' }, { key: 'workbench.content.resolve' }, { key: contracts_1.ASSISTANT_CONTEXT_SET_COMMAND, label: text('Select dashboard for Assistant', '设置助理当前看板') },
|
|
43
44
|
{ key: contracts_1.ARTIFACT_PRESENTATION_OPEN_COMMAND, label: text('Open shared page', '打开独立页面') },
|
|
44
45
|
{ key: contracts_1.WORKBENCH_NAVIGATION_OPEN_COMMAND, label: text('Open dashboard', '打开看板') }],
|
|
45
46
|
hostEvents: { subscriptions: [{ key: 'dashboard-created', event: 'assistant.tool.completed',
|