@xpert-ai/plugin-live-dashboard 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.xpertai-plugin/plugin.json +1 -1
  2. package/README.md +2 -2
  3. package/dist/lib/analysis-scene-tool.d.ts +8 -8
  4. package/dist/lib/analysis-scene.schema.d.ts +6 -6
  5. package/dist/lib/artifact-type.provider.js +38 -1
  6. package/dist/lib/bundled-example-source.d.ts +11 -0
  7. package/dist/lib/bundled-example-source.js +60 -0
  8. package/dist/lib/certification.schema.d.ts +4 -0
  9. package/dist/lib/certification.schema.js +14 -0
  10. package/dist/lib/content-capability.js +1 -0
  11. package/dist/lib/dashboard-delivery.d.ts +11 -0
  12. package/dist/lib/dashboard-delivery.js +55 -0
  13. package/dist/lib/dashboard-download-policy.d.ts +4 -0
  14. package/dist/lib/dashboard-download-policy.js +7 -0
  15. package/dist/lib/dashboard-navigation.d.ts +5 -5
  16. package/dist/lib/dashboard-queries.d.ts +2 -2
  17. package/dist/lib/dashboard-queries.js +2 -2
  18. package/dist/lib/dashboard-view.schema.d.ts +10 -10
  19. package/dist/lib/dashboard.schema.d.ts +18 -0
  20. package/dist/lib/dashboard.schema.js +2 -1
  21. package/dist/lib/dashboard.service.d.ts +11 -2
  22. package/dist/lib/dashboard.service.js +17 -4
  23. package/dist/lib/definition-tools.d.ts +14 -54
  24. package/dist/lib/definition-tools.js +29 -9
  25. package/dist/lib/document-host.d.ts +1 -1
  26. package/dist/lib/document-host.js +2 -1
  27. package/dist/lib/editing-session.d.ts +4 -4
  28. package/dist/lib/evidence/evidence-diff.d.ts +17 -0
  29. package/dist/lib/evidence/evidence-diff.js +30 -0
  30. package/dist/lib/evidence/evidence-transfers.d.ts +14 -0
  31. package/dist/lib/evidence/evidence-transfers.js +41 -0
  32. package/dist/lib/evidence/evidence-view.provider.d.ts +91 -0
  33. package/dist/lib/evidence/evidence-view.provider.js +92 -0
  34. package/dist/lib/evidence/evidence.entity.d.ts +14 -0
  35. package/dist/lib/evidence/evidence.entity.js +62 -0
  36. package/dist/lib/evidence/evidence.provider.d.ts +43 -0
  37. package/dist/lib/evidence/evidence.provider.js +91 -0
  38. package/dist/lib/evidence/evidence.service.d.ts +67 -0
  39. package/dist/lib/evidence/evidence.service.js +218 -0
  40. package/dist/lib/middleware.d.ts +6 -2
  41. package/dist/lib/middleware.js +95 -11
  42. package/dist/lib/monitor.js +2 -2
  43. package/dist/lib/plugin.js +6 -1
  44. package/dist/lib/query-session.d.ts +1 -1
  45. package/dist/lib/query-session.js +13 -8
  46. package/dist/lib/remote-entry.d.ts +1 -1
  47. package/dist/lib/runtime-context.d.ts +2 -0
  48. package/dist/lib/runtime-context.js +21 -0
  49. package/dist/lib/source-executions.d.ts +36 -18
  50. package/dist/lib/source-executions.js +2 -1
  51. package/dist/lib/templates.js +5 -5
  52. package/dist/lib/view.provider.js +7 -1
  53. package/dist/remote/app.css +1 -1
  54. package/dist/remote/app.js +23 -23
  55. package/dist/remote/build-manifest.json +48 -37
  56. package/dist/sandbox-actions/action.json +1 -1
  57. package/dist/sandbox-actions/bundle/host.js +2 -2
  58. package/docs/editing.mdx +6 -0
  59. package/docs/html-mode.md +1 -1
  60. package/package.json +5 -5
  61. package/skills/live-dashboard/SKILL.md +1 -1
  62. package/skills/live-dashboard/examples/README.md +2 -2
  63. package/skills/live-dashboard/examples/production-quality/README.md +2 -2
  64. package/skills/live-dashboard/examples/regional-sales/README.md +3 -3
  65. package/skills/live-dashboard/examples/regional-sales/query.json +49 -1
  66. package/skills/live-dashboard/examples/sales-overview/README.md +2 -2
@@ -131,7 +131,7 @@ export declare class DashboardService {
131
131
  status: "draft";
132
132
  title: string;
133
133
  } | null>;
134
- save(context: XpertResolvedViewHostContext, manifest: DashboardManifest, expectedVersionId: string | null, expectedRevision?: number, importedDependencies?: ArtifactDocumentDependencyAsset[], task?: SaveOptions): Promise<{
134
+ save(context: XpertResolvedViewHostContext, manifest: DashboardManifest, expectedVersionId: string | null, expectedRevision?: number, importedDependencies?: ArtifactDocumentDependencyAsset[], task?: SaveOptions, restoreVersionId?: string): Promise<{
135
135
  artifactId: string;
136
136
  draftId: string;
137
137
  draftRevision: number;
@@ -347,6 +347,15 @@ export declare class DashboardService {
347
347
  status: "draft";
348
348
  title: string;
349
349
  }>;
350
+ /** Historical bytes become a freshly validated draft; published versions and shares stay unchanged. */
351
+ restore(context: XpertResolvedViewHostContext, artifactId: string, versionId: string, expectedRevision: number, expectedCurrentVersionId: string | null): Promise<{
352
+ artifactId: string;
353
+ draftId: string;
354
+ draftRevision: number;
355
+ baseVersionId: string | null;
356
+ status: "draft";
357
+ title: string;
358
+ }>;
350
359
  publish(context: XpertResolvedViewHostContext, artifactId: string, expectedRevision: number, expectedCurrentVersionId: string | null): Promise<{
351
360
  artifactId: string;
352
361
  versionId: string;
@@ -511,7 +520,7 @@ export declare class DashboardService {
511
520
  versionId: string | null | undefined;
512
521
  versionNumber: number | undefined;
513
522
  }>;
514
- queryBinding(context: XpertResolvedViewHostContext, artifactId: string, versionId: string | undefined, bindingId: string, input: Record<string, AnalyticsValue>, draftRevision?: number): Promise<import("@xpert-ai/contracts").AnalyticalDataset>;
523
+ queryBinding(context: XpertResolvedViewHostContext, artifactId: string, versionId: string | undefined, bindingId: string, input: Record<string, AnalyticsValue>, draftRevision?: number, cache?: AnalyticsQueryRequest['cache']): Promise<import("@xpert-ai/contracts").AnalyticalDataset>;
515
524
  /** Every operation uses the current human's Project role; data queries still use actor(context). */
516
525
  authorizeProject(context: XpertResolvedViewHostContext, operation?: 'read' | 'write' | 'manage'): Promise<import("@xpert-ai/plugin-sdk").ProjectHumanAccess | undefined>;
517
526
  private execute;
@@ -158,7 +158,7 @@ let DashboardService = class DashboardService {
158
158
  return null;
159
159
  return { artifactId: artifact.id, draftId: draft.id, draftRevision: draft.revision, baseVersionId: draft.baseVersionId, status: 'draft', title: draft.title ?? artifact.title ?? '' };
160
160
  }
161
- async save(context, manifest, expectedVersionId, expectedRevision = 0, importedDependencies, task) {
161
+ async save(context, manifest, expectedVersionId, expectedRevision = 0, importedDependencies, task, restoreVersionId) {
162
162
  await task?.progress('authorization', 0, manifest.bindings.length);
163
163
  await this.authorizeProject(context, 'write');
164
164
  const scopedActor = actor(context);
@@ -177,8 +177,10 @@ let DashboardService = class DashboardService {
177
177
  this.assertCapacity(parsed.bindings.length, previous?.manifest.bindings.length ?? 0);
178
178
  if (importedDependencies && existing)
179
179
  throw new common_1.BadRequestException('DASHBOARD_IMPORT_NEW_ID_REQUIRED');
180
+ const restored = restoreVersionId && existing ? await this.openDocument(context, existing.id, restoreVersionId) : undefined;
180
181
  const dependencies = importedDependencies ? (0, artifact_document_1.verifyArtifactDocumentDependencies)(importedDependencies, parsed.presentation?.dependencies ?? [])
181
- : await (0, document_libraries_1.resolveLibraryAssets)(parsed.presentation?.dependencies ?? [], previous?.dependencies);
182
+ : restored ? (0, artifact_document_1.verifyArtifactDocumentDependencies)(restored.dependencies, parsed.presentation?.dependencies ?? [])
183
+ : await (0, document_libraries_1.resolveLibraryAssets)(parsed.presentation?.dependencies ?? [], previous?.dependencies);
182
184
  const buffer = (0, document_package_1.encodeDashboardPackage)(parsed, dependencies);
183
185
  if (buffer.byteLength > document_package_1.MAX_DASHBOARD_PACKAGE_BYTES)
184
186
  throw new common_1.BadRequestException('DASHBOARD_MANIFEST_TOO_LARGE');
@@ -260,6 +262,15 @@ let DashboardService = class DashboardService {
260
262
  throw new common_1.ConflictException('DASHBOARD_DRAFT_CONFLICT');
261
263
  return this.save(context, dashboard_schema_1.dashboardSchema.parse({ ...saved.manifest, ...dashboard_schema_1.dashboardChangesSchema.parse(changes) }), saved.baseVersionId ?? saved.versionId ?? null, expectedRevision);
262
264
  }
265
+ /** Historical bytes become a freshly validated draft; published versions and shares stay unchanged. */
266
+ async restore(context, artifactId, versionId, expectedRevision, expectedCurrentVersionId) {
267
+ await this.authorizeProject(context, 'write');
268
+ const current = await this.open(context, artifactId);
269
+ if ((current.draftRevision ?? 0) !== expectedRevision || (current.baseVersionId ?? current.versionId ?? null) !== expectedCurrentVersionId)
270
+ throw new common_1.ConflictException('DASHBOARD_DRAFT_CONFLICT');
271
+ const historical = await this.openDocument(context, artifactId, versionId);
272
+ return this.save(context, historical.manifest, expectedCurrentVersionId, expectedRevision, undefined, undefined, versionId);
273
+ }
263
274
  async publish(context, artifactId, expectedRevision, expectedCurrentVersionId) {
264
275
  await this.authorizeProject(context, 'manage');
265
276
  return this.publishDraft(context, artifactId, expectedRevision, expectedCurrentVersionId);
@@ -287,9 +298,11 @@ let DashboardService = class DashboardService {
287
298
  const { datasets, failures } = await (0, dashboard_queries_1.queryDashboardPartial)(this.runtime, actor(context), saved.manifest, controls);
288
299
  return { ...saved, datasets, failures, ...(saved.manifest.presentation ? {} : { payload: (0, renderer_1.toDataAnalyticsPayload)(saved.manifest, datasets) }) };
289
300
  }
290
- async queryBinding(context, artifactId, versionId, bindingId, input, draftRevision) {
301
+ async queryBinding(context, artifactId, versionId, bindingId, input, draftRevision, cache) {
291
302
  const saved = await this.open(context, artifactId, versionId, draftRevision);
292
- return (0, dashboard_queries_1.queryDashboardBinding)(this.runtime, actor(context), saved.manifest, bindingId, input);
303
+ const result = await (0, dashboard_queries_1.queryDashboardBinding)(this.runtime, actor(context), saved.manifest, bindingId, input, cache);
304
+ await this.authorizeProject(context);
305
+ return result;
293
306
  }
294
307
  /** Every operation uses the current human's Project role; data queries still use actor(context). */
295
308
  async authorizeProject(context, operation = 'read') {
@@ -1,56 +1,16 @@
1
+ import { exampleIdSchema } from './bundled-example-source';
2
+ import type { AnalyticsBinding } from '@xpert-ai/contracts';
3
+ import type { AnalyticsDefinitionReceipt } from '@xpert-ai/plugin-sdk';
4
+ import { type DynamicStructuredTool } from '@langchain/core/tools';
1
5
  import { z } from 'zod/v3';
2
6
  import { type IAgentMiddlewareContext } from '@xpert-ai/plugin-sdk';
3
- export declare const DEFINITION_GUIDANCE = "If dashboard_list_sources lacks the requested source, call analytics_definition_connections, then analytics_definition_inspect with an exact returned selection and inputJson=\"{}\". Follow its instructions, inspect real source data and generate the business definition yourself. Never ask users to fill internal IDs/configuration. Register using analytics_definition_register and a stable requestId, refresh dashboard_list_sources, discover the returned source and preview before saving. Settings \u2192 Analytics is for viewing, correction and version management. Do not create redundant definitions for already governed sources.";
4
- export declare function createDefinitionTools(context: IAgentMiddlewareContext, registered: () => void): (import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>, {}, {}, string> | import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
5
- providerId: z.ZodString;
6
- connectionKey: z.ZodString;
7
- } & {
8
- inputJson: z.ZodString;
9
- }, "strict", z.ZodTypeAny, {
10
- providerId: string;
11
- connectionKey: string;
12
- inputJson: string;
13
- }, {
14
- providerId: string;
15
- connectionKey: string;
16
- inputJson: string;
17
- }>, {
18
- providerId: string;
19
- connectionKey: string;
20
- inputJson: string;
21
- }, {
22
- providerId: string;
23
- connectionKey: string;
24
- inputJson: string;
25
- }, string> | import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
26
- providerId: z.ZodString;
27
- connectionKey: z.ZodString;
28
- } & {
29
- requestId: z.ZodString;
30
- name: z.ZodString;
31
- definitionJson: z.ZodString;
32
- }, "strict", z.ZodTypeAny, {
33
- name: string;
34
- requestId: string;
35
- providerId: string;
36
- connectionKey: string;
37
- definitionJson: string;
38
- }, {
39
- name: string;
40
- requestId: string;
41
- providerId: string;
42
- connectionKey: string;
43
- definitionJson: string;
44
- }>, {
45
- name: string;
46
- requestId: string;
47
- providerId: string;
48
- connectionKey: string;
49
- definitionJson: string;
50
- }, {
51
- name: string;
52
- requestId: string;
53
- providerId: string;
54
- connectionKey: string;
55
- definitionJson: string;
56
- }, string>)[];
7
+ export declare const DEFINITION_GUIDANCE = "If dashboard_list_sources lacks the requested source, call analytics_definition_connections, then analytics_definition_inspect with an exact returned selection and inputJson=\"{}\". Follow its instructions, inspect real source data and generate the business definition yourself. Never ask users to fill internal IDs/configuration. For a custom definition, register the inspected providerId, connectionKey, name, definitionJson and a stable requestId. For a bundled sample, register with only its exampleId. Refresh sources and preview before saving. Settings \u2192 Analytics is for viewing, correction and version management. Do not create redundant definitions for already governed sources.";
8
+ export declare function createDefinitionTools(context: IAgentMiddlewareContext, registered: () => void, selectExample?: (id: z.infer<typeof exampleIdSchema>, receipt?: AnalyticsDefinitionReceipt) => Promise<{
9
+ binding: AnalyticsBinding;
10
+ preparedQuery?: {
11
+ description: string;
12
+ previewRequest: {
13
+ exampleQuery: string;
14
+ };
15
+ };
16
+ } | undefined> | void): DynamicStructuredTool[];
@@ -2,19 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFINITION_GUIDANCE = void 0;
4
4
  exports.createDefinitionTools = createDefinitionTools;
5
+ const bundled_example_source_1 = require("./bundled-example-source");
5
6
  const tools_1 = require("@langchain/core/tools");
7
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
6
8
  const v3_1 = require("zod/v3");
7
9
  const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
8
10
  const selection = v3_1.z.object({ providerId: v3_1.z.string().min(1).max(160), connectionKey: v3_1.z.string().min(1).max(400) }).strict();
9
- exports.DEFINITION_GUIDANCE = 'If dashboard_list_sources lacks the requested source, call analytics_definition_connections, then analytics_definition_inspect with an exact returned selection and inputJson="{}". Follow its instructions, inspect real source data and generate the business definition yourself. Never ask users to fill internal IDs/configuration. Register using analytics_definition_register and a stable requestId, refresh dashboard_list_sources, discover the returned source and preview before saving. Settings → Analytics is for viewing, correction and version management. Do not create redundant definitions for already governed sources.';
10
- function createDefinitionTools(context, registered) {
11
+ exports.DEFINITION_GUIDANCE = 'If dashboard_list_sources lacks the requested source, call analytics_definition_connections, then analytics_definition_inspect with an exact returned selection and inputJson="{}". Follow its instructions, inspect real source data and generate the business definition yourself. Never ask users to fill internal IDs/configuration. For a custom definition, register the inspected providerId, connectionKey, name, definitionJson and a stable requestId. For a bundled sample, register with only its exampleId. Refresh sources and preview before saving. Settings → Analytics is for viewing, correction and version management. Do not create redundant definitions for already governed sources.';
12
+ const authoredSourceSchema = selection.extend({
13
+ requestId: v3_1.z.string().min(1).max(128).describe('Idempotency key for a custom definition.'), name: v3_1.z.string().min(1).max(200), definitionJson: v3_1.z.string().min(2).max(100000)
14
+ }).strict();
15
+ const sampleSchema = v3_1.z.object({ exampleId: bundled_example_source_1.exampleIdSchema }).strict().describe('Packaged sample. Supply only exampleId; the server derives its idempotency key.');
16
+ const registrationInput = v3_1.z.union([sampleSchema, authoredSourceSchema]);
17
+ // Keep an object root for model providers and expose the same exclusive input shapes the server validates.
18
+ const registrationSchema = { ...(0, json_schema_1.toJsonSchema)(registrationInput), type: 'object' };
19
+ function createDefinitionTools(context, registered, selectExample) {
11
20
  const api = () => {
12
21
  if (!context.workspaceId || !context.xpertId || !context.organizationId || !context.runtime?.capabilities)
13
22
  throw new Error('ANALYTICS_ASSISTANT_SCOPE_REQUIRED');
14
- return { runtime: context.runtime.capabilities.require(plugin_sdk_1.AnalyticsDefinitionAuthoringCapability), scope: {
23
+ const files = context.runtime.capabilities.require(plugin_sdk_1.WorkspaceFilesRuntimeCapability);
24
+ return { files, runtime: context.runtime.capabilities.require(plugin_sdk_1.AnalyticsDefinitionAuthoringCapability), scope: {
15
25
  actor: { tenantId: context.tenantId, organizationId: context.organizationId, userId: context.userId },
16
26
  workspaceId: context.workspaceId, xpertId: context.xpertId,
17
- files: context.runtime.capabilities.require(plugin_sdk_1.WorkspaceFilesRuntimeCapability)
27
+ files
18
28
  } };
19
29
  };
20
30
  return [
@@ -29,13 +39,23 @@ function createDefinitionTools(context, registered) {
29
39
  schema: selection.extend({ inputJson: v3_1.z.string().min(2).max(100000) }).strict(), verboseParsingErrors: true,
30
40
  metadata: { toolName: { en_US: 'Inspect analytics input', zh_Hans: '检查分析输入' } }
31
41
  }),
32
- (0, tools_1.tool)(async ({ definitionJson, ...input }) => {
33
- const { runtime, scope } = api();
34
- const receipt = await runtime.register(scope, { ...input, definition: plugin_sdk_1.analyticsOptionsSchema.parse(JSON.parse(definitionJson)) });
42
+ (0, tools_1.tool)(async (input) => {
43
+ const args = registrationInput.parse(input);
44
+ const { runtime, scope, files } = api();
45
+ if ('exampleId' in args) {
46
+ const { exampleId } = args;
47
+ await selectExample?.(exampleId);
48
+ const receipt = await (0, bundled_example_source_1.registerExampleSource)(exampleId, context.projectId, runtime, scope, files);
49
+ registered();
50
+ const discovery = await selectExample?.(exampleId, receipt);
51
+ return JSON.stringify({ ...receipt, exampleId, ...discovery });
52
+ }
53
+ const { definitionJson, ...selection } = args;
54
+ const receipt = await runtime.register(scope, { ...selection, definition: plugin_sdk_1.analyticsOptionsSchema.parse(JSON.parse(definitionJson)) });
35
55
  registered();
36
56
  return JSON.stringify(receipt);
37
- }, { name: 'analytics_definition_register', description: 'Register an Agent-generated definition matching definitionSchema. System supplies identities and validates real input. Keep requestId stable on retries; changed intent needs another key. Returns an immutable source and discoveryRequest. Refresh sources, discover and preview it before saving a dashboard.',
38
- schema: selection.extend({ requestId: v3_1.z.string().min(1).max(128), name: v3_1.z.string().min(1).max(200), definitionJson: v3_1.z.string().min(2).max(100000) }).strict(), verboseParsingErrors: true,
57
+ }, { name: 'analytics_definition_register', description: bundled_example_source_1.EXAMPLE_SOURCE_GUIDANCE + ' For a custom, Agent-authored definition use the separate providerId/connectionKey/requestId/name/definitionJson form. Only that form takes requestId. Returns an immutable source and discoveryRequest. Refresh sources, discover and preview it before saving a dashboard.',
58
+ schema: registrationSchema, verboseParsingErrors: true,
39
59
  metadata: { toolName: { en_US: 'Register analytics definition', zh_Hans: '生成分析定义' } }
40
60
  })
41
61
  ];
@@ -1,4 +1,4 @@
1
1
  import { type ArtifactDocumentHostOptions } from '@xpert-ai/plugin-sdk/artifact-document';
2
2
  /** The HTML never supplies or overrides its network permissions. */
3
- export declare function mountDashboardDocument<T>(frame: HTMLIFrameElement, options: ArtifactDocumentHostOptions<T>): import("@xpert-ai/plugin-sdk/artifact-document").ArtifactDocumentHost;
3
+ export declare function mountDashboardDocument<T>(frame: HTMLIFrameElement, options: Omit<ArtifactDocumentHostOptions<T>, 'allowDownloads'>): import("@xpert-ai/plugin-sdk/artifact-document").ArtifactDocumentHost;
4
4
  export declare function isDashboardResourceAllowed(resourceType: string, url: string): boolean;
@@ -4,9 +4,10 @@ exports.mountDashboardDocument = mountDashboardDocument;
4
4
  exports.isDashboardResourceAllowed = isDashboardResourceAllowed;
5
5
  const artifact_document_1 = require("@xpert-ai/plugin-sdk/artifact-document");
6
6
  const document_network_1 = require("./document-network");
7
+ const dashboard_download_policy_1 = require("./dashboard-download-policy");
7
8
  /** The HTML never supplies or overrides its network permissions. */
8
9
  function mountDashboardDocument(frame, options) {
9
- return (0, artifact_document_1.mountArtifactDocument)(frame, { ...options, dispatchesPerMinute: 60, networkPolicy: document_network_1.DASHBOARD_NETWORK_POLICY });
10
+ return (0, artifact_document_1.mountArtifactDocument)(frame, { ...options, ...dashboard_download_policy_1.DASHBOARD_DOWNLOAD_POLICY, dispatchesPerMinute: 60, networkPolicy: document_network_1.DASHBOARD_NETWORK_POLICY });
10
11
  }
11
12
  function isDashboardResourceAllowed(resourceType, url) {
12
13
  return (0, artifact_document_1.isArtifactDocumentResourceAllowed)(document_network_1.DASHBOARD_NETWORK_POLICY, resourceType, url);
@@ -84,41 +84,41 @@ export declare const dashboardStateSchema: z.ZodObject<{
84
84
  draftRevision?: number | undefined;
85
85
  }>>;
86
86
  }, "strip", z.ZodTypeAny, {
87
+ scope: string;
87
88
  target: {
88
89
  artifactId: string;
89
90
  schemaVersion: 1;
90
91
  versionId?: string | undefined;
91
92
  draftRevision?: number | undefined;
92
93
  } | null;
93
- scope: string;
94
94
  }, {
95
+ scope: string;
95
96
  target: {
96
97
  artifactId: string;
97
98
  schemaVersion: 1;
98
99
  versionId?: string | undefined;
99
100
  draftRevision?: number | undefined;
100
101
  } | null;
101
- scope: string;
102
102
  }>>>;
103
103
  }, "strip", z.ZodTypeAny, {
104
104
  dashboardEditing?: {
105
+ scope: string;
105
106
  target: {
106
107
  artifactId: string;
107
108
  schemaVersion: 1;
108
109
  versionId?: string | undefined;
109
110
  draftRevision?: number | undefined;
110
111
  } | null;
111
- scope: string;
112
112
  } | null | undefined;
113
113
  }, {
114
114
  dashboardEditing?: {
115
+ scope: string;
115
116
  target: {
116
117
  artifactId: string;
117
118
  schemaVersion: 1;
118
119
  versionId?: string | undefined;
119
120
  draftRevision?: number | undefined;
120
121
  } | null;
121
- scope: string;
122
122
  } | null | undefined;
123
123
  }>;
124
124
  /** Checkpoints belong to an actor and conversation. Copied state must never choose another user's target. */
@@ -0,0 +1,17 @@
1
+ import type { AnalysisEvidenceSnapshot } from '@xpert-ai/contracts';
2
+ /** Positional comparison, not entity matching. Only compare snapshots already
3
+ * authorized and held by the caller; this does not authorize historical rows. */
4
+ export declare function compareEvidence(before: AnalysisEvidenceSnapshot, after: AnalysisEvidenceSnapshot): {
5
+ previousId: string;
6
+ currentId: string;
7
+ changedCells: number;
8
+ changedDatasets: number;
9
+ changes: {
10
+ datasetId: string;
11
+ row: number;
12
+ field: string;
13
+ before: string;
14
+ after: string;
15
+ }[];
16
+ truncated: boolean;
17
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareEvidence = compareEvidence;
4
+ const analytics_1 = require("@xpert-ai/plugin-sdk/analytics");
5
+ /** Positional comparison, not entity matching. Only compare snapshots already
6
+ * authorized and held by the caller; this does not authorize historical rows. */
7
+ function compareEvidence(before, after) {
8
+ const left = new Map(before.datasets.map(value => [value.datasetId, value]));
9
+ const right = new Map(after.datasets.map(value => [value.datasetId, value]));
10
+ const changes = [];
11
+ let changedCells = 0, changedDatasets = 0;
12
+ const display = (value) => value === undefined ? '—' : String(value).slice(0, 300);
13
+ for (const datasetId of new Set([...left.keys(), ...right.keys()])) {
14
+ const a = left.get(datasetId), b = right.get(datasetId);
15
+ if (!a || !b || (0, analytics_1.canonicalEvidenceJson)(a.fields) !== (0, analytics_1.canonicalEvidenceJson)(b.fields) ||
16
+ (0, analytics_1.canonicalEvidenceJson)(a.completeness) !== (0, analytics_1.canonicalEvidenceJson)(b.completeness))
17
+ changedDatasets++;
18
+ for (let row = 0; row < Math.max(a?.rows.length ?? 0, b?.rows.length ?? 0); row++) {
19
+ const av = a?.rows[row] ?? {}, bv = b?.rows[row] ?? {};
20
+ for (const field of new Set([...Object.keys(av), ...Object.keys(bv)])) {
21
+ if (Object.is(av[field], bv[field]))
22
+ continue;
23
+ changedCells++;
24
+ if (changes.length < 50)
25
+ changes.push({ datasetId, row, field, before: display(av[field]), after: display(bv[field]) });
26
+ }
27
+ }
28
+ }
29
+ return { previousId: before.id, currentId: after.id, changedCells, changedDatasets, changes, truncated: changedCells > changes.length };
30
+ }
@@ -0,0 +1,14 @@
1
+ import { type RuntimeCapabilityRegistry } from '@xpert-ai/plugin-sdk';
2
+ import type { XpertResolvedViewHostContext } from '@xpert-ai/contracts';
3
+ import { AnalysisEvidenceService } from './evidence.service';
4
+ export declare class AnalysisEvidenceTransfers {
5
+ private readonly evidence;
6
+ private readonly runtime;
7
+ constructor(evidence: AnalysisEvidenceService, runtime: RuntimeCapabilityRegistry);
8
+ convert(context: XpertResolvedViewHostContext, input: {
9
+ id: string;
10
+ requestId: string;
11
+ title: string;
12
+ target: 'document' | 'presentation' | 'motion';
13
+ }): Promise<import("@xpert-ai/contracts").ContentCatalogItem>;
14
+ }
@@ -0,0 +1,41 @@
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.AnalysisEvidenceTransfers = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
18
+ const evidence_service_1 = require("./evidence.service");
19
+ const dashboard_service_1 = require("../dashboard.service");
20
+ let AnalysisEvidenceTransfers = class AnalysisEvidenceTransfers {
21
+ constructor(evidence, runtime) {
22
+ this.evidence = evidence;
23
+ this.runtime = runtime;
24
+ }
25
+ async convert(context, input) {
26
+ const snapshot = await this.evidence.read(context, input.id);
27
+ const scope = { actor: { tenantId: context.tenantId, organizationId: context.organizationId, userId: context.userId }, projectId: (0, dashboard_service_1.projectId)(context) };
28
+ const catalog = this.runtime.require(plugin_sdk_1.ContentResourcesRuntimeCapability).catalog;
29
+ const source = await catalog.register({ ...scope, source: { providerKey: evidence_service_1.EVIDENCE_PROVIDER, resourceId: snapshot.id } });
30
+ const target = input.target !== 'motion' ? { providerKey: 'office.documents', implementationKey: input.target === 'presentation' ? 'office-presentation' : 'office-document' }
31
+ : { providerKey: 'motion.evidence-video', implementationKey: 'motion-evidence-video' };
32
+ return catalog.create({ ...scope, ...target, requestId: input.requestId, title: input.title,
33
+ transferFrom: { contentId: source.contentId, expectedRevision: snapshot.sha256 } });
34
+ }
35
+ };
36
+ exports.AnalysisEvidenceTransfers = AnalysisEvidenceTransfers;
37
+ exports.AnalysisEvidenceTransfers = AnalysisEvidenceTransfers = __decorate([
38
+ (0, common_1.Injectable)(),
39
+ __param(1, (0, common_1.Inject)(plugin_sdk_1.XPERT_RUNTIME_CAPABILITIES_TOKEN)),
40
+ __metadata("design:paramtypes", [evidence_service_1.AnalysisEvidenceService, Object])
41
+ ], AnalysisEvidenceTransfers);
@@ -0,0 +1,91 @@
1
+ import { AnalysisEvidenceTransfers } from './evidence-transfers';
2
+ import { z } from 'zod/v3';
3
+ import { type IXpertViewExtensionProvider } from '@xpert-ai/plugin-sdk';
4
+ import type { ResourceContentEditorRegistration, XpertExtensionViewManifest, XpertResolvedViewHostContext, XpertViewActionRequest, XpertViewQuery } from '@xpert-ai/contracts';
5
+ import { AnalysisEvidenceService } from './evidence.service';
6
+ export declare const EVIDENCE_EDITOR = "live-dashboard.evidence-editor";
7
+ export declare const evidenceModel: {
8
+ typeId: string;
9
+ modelId: string;
10
+ schemaVersion: string;
11
+ editProtocol: {
12
+ id: string;
13
+ version: string;
14
+ };
15
+ };
16
+ export declare const evidenceConvertSchema: z.ZodObject<{
17
+ id: z.ZodString;
18
+ } & {
19
+ requestId: z.ZodString;
20
+ title: z.ZodString;
21
+ target: z.ZodEnum<["document", "presentation", "motion"]>;
22
+ }, "strict", z.ZodTypeAny, {
23
+ title: string;
24
+ id: string;
25
+ requestId: string;
26
+ target: "presentation" | "document" | "motion";
27
+ }, {
28
+ title: string;
29
+ id: string;
30
+ requestId: string;
31
+ target: "presentation" | "document" | "motion";
32
+ }>;
33
+ export declare class AnalysisEvidenceEditor {
34
+ readonly descriptor: ResourceContentEditorRegistration;
35
+ }
36
+ export declare class AnalysisEvidenceView implements IXpertViewExtensionProvider {
37
+ private readonly evidence;
38
+ private readonly transfers;
39
+ constructor(evidence: AnalysisEvidenceService, transfers: AnalysisEvidenceTransfers);
40
+ supports(context: XpertResolvedViewHostContext): boolean;
41
+ getViewManifests(context: XpertResolvedViewHostContext, slot: string): XpertExtensionViewManifest[];
42
+ getRemoteComponentEntry(_context: XpertResolvedViewHostContext, entry: string): Promise<{
43
+ html: string;
44
+ contentType: "text/html; charset=utf-8";
45
+ }>;
46
+ private assertView;
47
+ getViewData(context: XpertResolvedViewHostContext, key: string, query: XpertViewQuery): Promise<{
48
+ meta: {
49
+ canCapture: boolean;
50
+ snapshot: import("@xpert-ai/contracts").AnalysisEvidenceSnapshot;
51
+ refreshId?: undefined;
52
+ sourceChanged?: undefined;
53
+ };
54
+ } | {
55
+ meta: {
56
+ canCapture: boolean;
57
+ refreshId: string;
58
+ sourceChanged: boolean;
59
+ snapshot?: undefined;
60
+ };
61
+ } | {
62
+ meta: {
63
+ nextCursor?: number | undefined;
64
+ items: {
65
+ id: string;
66
+ title: string;
67
+ sha256: string;
68
+ capturedAt: string;
69
+ artifactId: string | null;
70
+ }[];
71
+ canCapture: boolean;
72
+ snapshot?: undefined;
73
+ refreshId?: undefined;
74
+ sourceChanged?: undefined;
75
+ };
76
+ }>;
77
+ executeViewAction(context: XpertResolvedViewHostContext, key: string, action: string, request: XpertViewActionRequest): Promise<{
78
+ success: boolean;
79
+ data: {
80
+ id: string;
81
+ artifactId: string;
82
+ sha256: string;
83
+ capturedAt: string;
84
+ };
85
+ refresh: boolean;
86
+ } | {
87
+ success: boolean;
88
+ data: import("@xpert-ai/contracts").ContentCatalogItem;
89
+ refresh: boolean;
90
+ }>;
91
+ }
@@ -0,0 +1,92 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AnalysisEvidenceView = exports.AnalysisEvidenceEditor = exports.evidenceConvertSchema = exports.evidenceModel = exports.EVIDENCE_EDITOR = void 0;
13
+ const evidence_transfers_1 = require("./evidence-transfers");
14
+ const common_1 = require("@nestjs/common");
15
+ const v3_1 = require("zod/v3");
16
+ const plugin_sdk_1 = require("@xpert-ai/plugin-sdk");
17
+ const evidence_service_1 = require("./evidence.service");
18
+ const dashboard_service_1 = require("../dashboard.service");
19
+ const remote_entry_1 = require("../remote-entry");
20
+ const dashboard_icon_1 = require("../dashboard-icon");
21
+ const view_provider_1 = require("../view.provider");
22
+ exports.EVIDENCE_EDITOR = 'live-dashboard.evidence-editor';
23
+ exports.evidenceModel = { typeId: 'analysis-evidence', modelId: 'xpert.analysis-evidence', schemaVersion: '1', editProtocol: { id: 'immutable.snapshot', version: '1' } };
24
+ const provider = 'live-dashboard-evidence', view = 'analysis-evidence';
25
+ const idSchema = v3_1.z.object({ id: v3_1.z.string().uuid() }).strict();
26
+ const refreshSchema = idSchema.extend({ requestId: v3_1.z.string().uuid(), title: v3_1.z.string().min(1).max(200) });
27
+ exports.evidenceConvertSchema = idSchema.extend({ requestId: v3_1.z.string().uuid(), title: v3_1.z.string().min(1).max(200), target: v3_1.z.enum(['document', 'presentation', 'motion']) });
28
+ let AnalysisEvidenceEditor = class AnalysisEvidenceEditor {
29
+ constructor() {
30
+ this.descriptor = { kind: 'resource', key: exports.EVIDENCE_EDITOR, protocolVersion: 2,
31
+ title: 'Analysis evidence', view: { providerKey: provider, viewKey: view, entry: view }, supports: [{ ...exports.evidenceModel, access: ['view'] }] };
32
+ }
33
+ };
34
+ exports.AnalysisEvidenceEditor = AnalysisEvidenceEditor;
35
+ exports.AnalysisEvidenceEditor = AnalysisEvidenceEditor = __decorate([
36
+ (0, plugin_sdk_1.ContentEditorProvider)(exports.EVIDENCE_EDITOR)
37
+ ], AnalysisEvidenceEditor);
38
+ let AnalysisEvidenceView = class AnalysisEvidenceView {
39
+ constructor(evidence, transfers) {
40
+ this.evidence = evidence;
41
+ this.transfers = transfers;
42
+ }
43
+ supports(context) { return context.hostType === 'agent'; }
44
+ getViewManifests(context, slot) {
45
+ if (!this.supports(context) || !['agent.workbench', 'agent.workbench.fixed', 'agent.workbench.main'].includes(slot))
46
+ return [];
47
+ return [{ key: view, title: { en_US: 'Analysis evidence', zh_Hans: '分析证据', zh_Hant: '分析證據' }, hostType: 'agent', slot,
48
+ icon: dashboard_icon_1.dashboardIcon, activation: { projectResource: true, requiredFeatures: [view_provider_1.FEATURE] }, source: { provider, plugin: dashboard_service_1.PLUGIN_NAME }, refreshable: true,
49
+ workbench: { fixed: true, openMode: 'on-demand', menu: { enabled: true, order: 39 } },
50
+ view: { type: 'remote_component', runtime: 'react', protocolVersion: 1, component: { isolation: 'iframe', entry: view }, dataSource: { mode: 'platform' } },
51
+ dataSource: { mode: 'platform', querySchema: { supportsSelection: true, supportsParameters: true }, cache: { enabled: false } },
52
+ clientCommands: [{ key: 'workbench.content.resolve' }, { key: 'workbench.navigation.open' }],
53
+ actions: ['capture', 'refresh', 'convert'].map(key => ({ key, label: { en_US: key, zh_Hans: key }, actionType: 'invoke' })) }];
54
+ }
55
+ getRemoteComponentEntry(_context, entry) { this.assertView(entry); return (0, remote_entry_1.dashboardRemoteEntry)(false, 'evidence'); }
56
+ assertView(key) { if (key !== view)
57
+ throw new common_1.BadRequestException('EVIDENCE_VIEW_UNSUPPORTED'); }
58
+ async getViewData(context, key, query) {
59
+ this.assertView(key);
60
+ const canCapture = await this.evidence.canCapture(context);
61
+ if (query.selectionId) {
62
+ const id = v3_1.z.string().uuid().parse(query.selectionId);
63
+ try {
64
+ return { meta: { canCapture, snapshot: await this.evidence.read(context, id) } };
65
+ }
66
+ catch (error) {
67
+ if (!(error instanceof common_1.ConflictException) || error.message !== 'EVIDENCE_SOURCE_CHANGED_CAPTURE_NEW_SNAPSHOT')
68
+ throw error;
69
+ return { meta: { canCapture, refreshId: id, sourceChanged: true } };
70
+ }
71
+ }
72
+ return { meta: { canCapture, ...await this.evidence.list(context, Math.max(0, (query.page ?? 1) - 1) * 50) } };
73
+ }
74
+ async executeViewAction(context, key, action, request) {
75
+ this.assertView(key);
76
+ if (action === 'capture')
77
+ return { success: true, data: await this.evidence.capture(context, evidence_service_1.captureEvidenceSchema.parse(request.input)), refresh: true };
78
+ if (action === 'refresh') {
79
+ const input = refreshSchema.parse(request.input);
80
+ return { success: true, data: await this.evidence.refresh(context, input.id, input.requestId, input.title), refresh: false };
81
+ }
82
+ if (action === 'convert')
83
+ return { success: true, data: await this.transfers.convert(context, exports.evidenceConvertSchema.parse(request.input)), refresh: false };
84
+ throw new common_1.BadRequestException('EVIDENCE_ACTION_UNSUPPORTED');
85
+ }
86
+ };
87
+ exports.AnalysisEvidenceView = AnalysisEvidenceView;
88
+ exports.AnalysisEvidenceView = AnalysisEvidenceView = __decorate([
89
+ (0, plugin_sdk_1.ViewExtensionProvider)(provider),
90
+ __metadata("design:paramtypes", [evidence_service_1.AnalysisEvidenceService,
91
+ evidence_transfers_1.AnalysisEvidenceTransfers])
92
+ ], AnalysisEvidenceView);
@@ -0,0 +1,14 @@
1
+ import type { AnalysisEvidenceSnapshot } from '@xpert-ai/contracts';
2
+ /** Immutable snapshot; only the derived Artifact pointer may be completed after a retry. */
3
+ export declare class AnalysisEvidenceRecord {
4
+ id: string;
5
+ tenantId: string;
6
+ organizationId: string;
7
+ projectId: string;
8
+ createdById: string;
9
+ requestId: string;
10
+ requestHash: string;
11
+ snapshot: AnalysisEvidenceSnapshot;
12
+ artifactId: string | null;
13
+ createdAt: Date;
14
+ }