@lightdash-tools/mcp 0.19.0 → 0.21.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/README.md +5 -5
- package/dist/auth/request-state-key.d.ts +2 -2
- package/dist/auth/request-state-key.js +2 -2
- package/dist/config/enabled-profiles.d.ts +1 -1
- package/dist/config/enabled-profiles.js +3 -2
- package/dist/config/enabled-profiles.test.js +1 -0
- package/dist/policy/create-agent-preview.d.ts +65 -0
- package/dist/policy/create-agent-preview.js +126 -0
- package/dist/policy/create-agent-preview.test.d.ts +4 -0
- package/dist/policy/create-agent-preview.test.js +162 -0
- package/dist/policy/envelope.d.ts +1 -1
- package/dist/profiles/ai-agent-ops/v1/index.js +10 -0
- package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +6 -3
- package/dist/profiles/ai-agent-ops/v1/invariants.js +6 -2
- package/dist/profiles/ai-agent-ops/v1/prompts.js +24 -3
- package/dist/profiles/ai-agent-ops/v1/prompts.test.js +10 -1
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/core.md +34 -2
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +9 -4
- package/dist/profiles/content-reader/v1/invariants.d.ts +1 -1
- package/dist/profiles/content-reader/v1/invariants.js +1 -1
- package/dist/profiles/content-reader/v1/resources/playbooks/core.md +14 -14
- package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +9 -7
- package/dist/profiles/data-analyst/v1/prompts.js +1 -1
- package/dist/profiles/data-analyst/v1/resources/playbooks/core.md +10 -10
- package/dist/profiles/data-analyst/v1/resources/playbooks/explore.md +2 -1
- package/dist/profiles/index.test.js +7 -2
- package/dist/server/server.js +16 -4
- package/dist/tools/ai-agents/agents.d.ts +8 -0
- package/dist/tools/ai-agents/agents.js +283 -1
- package/dist/tools/ai-agents/agents.test.js +25 -0
- package/dist/tools/ai-agents/create-elicitation.d.ts +52 -0
- package/dist/tools/ai-agents/create-elicitation.js +206 -0
- package/dist/tools/ai-agents/create-elicitation.test.d.ts +4 -0
- package/dist/tools/ai-agents/create-elicitation.test.js +363 -0
- package/dist/tools/ai-agents/create-request-state.d.ts +18 -0
- package/dist/tools/ai-agents/create-request-state.js +43 -0
- package/dist/tools/ai-agents/documents.d.ts +15 -0
- package/dist/tools/ai-agents/documents.js +212 -0
- package/dist/tools/ai-agents/documents.test.d.ts +1 -0
- package/dist/tools/ai-agents/documents.test.js +129 -0
- package/dist/tools/ai-agents/gate-create-project-agent.d.ts +28 -0
- package/dist/tools/ai-agents/gate-create-project-agent.js +71 -0
- package/dist/tools/ai-agents/helpers.d.ts +11 -0
- package/dist/tools/ai-agents/helpers.js +29 -1
- package/dist/tools/ai-agents/knowledge-warnings.d.ts +11 -0
- package/dist/tools/ai-agents/knowledge-warnings.js +21 -0
- package/dist/tools/ai-agents/space-warnings.d.ts +36 -0
- package/dist/tools/ai-agents/space-warnings.js +101 -0
- package/dist/tools/ai-agents/space-warnings.test.d.ts +1 -0
- package/dist/tools/ai-agents/space-warnings.test.js +78 -0
- package/dist/tools/ai-agents/tag-warnings.d.ts +31 -0
- package/dist/tools/ai-agents/tag-warnings.js +70 -0
- package/dist/tools/ai-agents/test-support.d.ts +4 -1
- package/dist/tools/ai-agents/test-support.js +7 -2
- package/dist/tools/composition/explain-content.js +56 -6
- package/dist/tools/lib/artifacts.d.ts +41 -0
- package/dist/tools/lib/artifacts.js +90 -0
- package/dist/tools/project/projects.js +1 -0
- package/dist/tools/project/projects.test.js +1 -0
- package/dist/tools/project/reader-content.d.ts +11 -0
- package/dist/tools/project/reader-content.js +63 -5
- package/dist/tools/project/reader-content.sql.test.d.ts +4 -0
- package/dist/tools/project/reader-content.sql.test.js +113 -0
- package/dist/tools/project/reader-execution.js +77 -33
- package/dist/tools/project/reader-execution.test.js +59 -2
- package/dist/tools/query/chart-source.d.ts +29 -1
- package/dist/tools/query/chart-source.js +66 -11
- package/dist/tools/query/lifecycle.js +9 -4
- package/dist/tools/query/query-artifact-result.d.ts +25 -0
- package/dist/tools/query/query-artifact-result.js +64 -0
- package/dist/tools/query/query-artifact-result.test.d.ts +4 -0
- package/dist/tools/query/query-artifact-result.test.js +87 -0
- package/dist/tools/query/resolve-saved-sql-chart.d.ts +10 -0
- package/dist/tools/query/resolve-saved-sql-chart.js +48 -0
- package/dist/tools/query/resolve-saved-sql-chart.test.d.ts +1 -0
- package/dist/tools/query/resolve-saved-sql-chart.test.js +50 -0
- package/dist/tools/query/run-metric-query.js +9 -5
- package/dist/tools/query/run-metric-query.test.js +5 -0
- package/dist/tools/shared.artifacts.test.d.ts +1 -0
- package/dist/tools/shared.artifacts.test.js +93 -0
- package/dist/tools/shared.d.ts +40 -1
- package/dist/tools/shared.js +33 -0
- package/package.json +3 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft warnings when agent spaceAccess UUIDs are not found in the project.
|
|
3
|
+
*/
|
|
4
|
+
export type AgentSpaceWarningCode = 'SPACE_LIST_UNAVAILABLE' | 'SPACES_NOT_IN_PROJECT';
|
|
5
|
+
export type AgentSpaceWarning = {
|
|
6
|
+
code: AgentSpaceWarningCode;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type ResolvedSpaceRef = {
|
|
10
|
+
uuid: string;
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
export type ProjectSpacesClient = {
|
|
14
|
+
listSpacesInProject: (projectUuid: string) => Promise<ResolvedSpaceRef[]>;
|
|
15
|
+
};
|
|
16
|
+
/** Non-empty spaceAccess only; null/empty skip (all project spaces). */
|
|
17
|
+
export declare function effectiveAgentSpaceAccess(spaceAccess: string[] | undefined): string[] | undefined;
|
|
18
|
+
export type SpaceAccessValidationResult = {
|
|
19
|
+
error: Error;
|
|
20
|
+
} | {
|
|
21
|
+
resolved: ResolvedSpaceRef[];
|
|
22
|
+
unknownUuids: string[];
|
|
23
|
+
} | {
|
|
24
|
+
skipped: true;
|
|
25
|
+
};
|
|
26
|
+
/** Validate spaceAccess UUIDs against the project space list. */
|
|
27
|
+
export declare function fetchSpaceAccessValidation(client: ProjectSpacesClient, projectUuid: string, spaceAccess: string[] | undefined): Promise<SpaceAccessValidationResult>;
|
|
28
|
+
/** Human-readable space scope line for create confirmation / preview. */
|
|
29
|
+
export declare function formatSpaceAccessPreviewLine(spaceAccess: string[] | undefined, validation: SpaceAccessValidationResult): string;
|
|
30
|
+
/** Derive soft warnings from a prior validation result (no upstream call). */
|
|
31
|
+
export declare function warningsFromSpaceAccessValidation(result: SpaceAccessValidationResult): AgentSpaceWarning[];
|
|
32
|
+
/**
|
|
33
|
+
* After create/update with non-empty spaceAccess, warn when UUIDs are missing from the project.
|
|
34
|
+
* Never fails the mutation.
|
|
35
|
+
*/
|
|
36
|
+
export declare function warningsForAgentSpaceAccess(client: ProjectSpacesClient, projectUuid: string, spaceAccess: string[] | undefined): Promise<AgentSpaceWarning[]>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Soft warnings when agent spaceAccess UUIDs are not found in the project.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.effectiveAgentSpaceAccess = effectiveAgentSpaceAccess;
|
|
7
|
+
exports.fetchSpaceAccessValidation = fetchSpaceAccessValidation;
|
|
8
|
+
exports.formatSpaceAccessPreviewLine = formatSpaceAccessPreviewLine;
|
|
9
|
+
exports.warningsFromSpaceAccessValidation = warningsFromSpaceAccessValidation;
|
|
10
|
+
exports.warningsForAgentSpaceAccess = warningsForAgentSpaceAccess;
|
|
11
|
+
/** Non-empty spaceAccess only; null/empty skip (all project spaces). */
|
|
12
|
+
function effectiveAgentSpaceAccess(spaceAccess) {
|
|
13
|
+
if (spaceAccess == null || spaceAccess.length === 0) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return spaceAccess;
|
|
17
|
+
}
|
|
18
|
+
/** Validate spaceAccess UUIDs against the project space list. */
|
|
19
|
+
async function fetchSpaceAccessValidation(client, projectUuid, spaceAccess) {
|
|
20
|
+
const effective = effectiveAgentSpaceAccess(spaceAccess);
|
|
21
|
+
if (effective === undefined) {
|
|
22
|
+
return { skipped: true };
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const spaces = await client.listSpacesInProject(projectUuid);
|
|
26
|
+
const byUuid = new Map(spaces.map((space) => [space.uuid, space]));
|
|
27
|
+
const resolved = [];
|
|
28
|
+
const unknownUuids = [];
|
|
29
|
+
for (const uuid of effective) {
|
|
30
|
+
const space = byUuid.get(uuid);
|
|
31
|
+
if (space === undefined) {
|
|
32
|
+
unknownUuids.push(uuid);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
resolved.push({ uuid: space.uuid, name: space.name });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { resolved, unknownUuids };
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return { error: err instanceof Error ? err : new Error(String(err)) };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Human-readable space scope line for create confirmation / preview. */
|
|
45
|
+
function formatSpaceAccessPreviewLine(spaceAccess, validation) {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
if ('skipped' in validation) {
|
|
48
|
+
return 'Space access: (all project spaces)';
|
|
49
|
+
}
|
|
50
|
+
if ('error' in validation) {
|
|
51
|
+
const count = (_b = (_a = effectiveAgentSpaceAccess(spaceAccess)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
52
|
+
return `Space access: ${count} UUID(s) configured (names unavailable — space list call failed)`;
|
|
53
|
+
}
|
|
54
|
+
if (validation.unknownUuids.length > 0) {
|
|
55
|
+
const known = formatResolvedSpaceRefs(validation.resolved);
|
|
56
|
+
const unknown = validation.unknownUuids.join(', ');
|
|
57
|
+
const effective = effectiveAgentSpaceAccess(spaceAccess);
|
|
58
|
+
const count = (_c = effective === null || effective === void 0 ? void 0 : effective.length) !== null && _c !== void 0 ? _c : validation.resolved.length + validation.unknownUuids.length;
|
|
59
|
+
return known.length > 0
|
|
60
|
+
? `Space access: ${count} UUID(s) — known: ${known}; not in project: ${unknown}`
|
|
61
|
+
: `Space access: ${count} UUID(s) not found in project: ${unknown}`;
|
|
62
|
+
}
|
|
63
|
+
return `Space access: ${validation.resolved.length} space(s): ${formatResolvedSpaceRefs(validation.resolved)}`;
|
|
64
|
+
}
|
|
65
|
+
function formatResolvedSpaceRefs(spaces) {
|
|
66
|
+
return spaces.map((s) => `${s.name} (${s.uuid})`).join(', ');
|
|
67
|
+
}
|
|
68
|
+
/** Derive soft warnings from a prior validation result (no upstream call). */
|
|
69
|
+
function warningsFromSpaceAccessValidation(result) {
|
|
70
|
+
if ('skipped' in result) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
if ('error' in result) {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
code: 'SPACE_LIST_UNAVAILABLE',
|
|
77
|
+
message: `Could not verify agent spaceAccess UUIDs: ${result.error.message}`,
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
if (result.unknownUuids.length > 0) {
|
|
82
|
+
const known = formatResolvedSpaceRefs(result.resolved);
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
code: 'SPACES_NOT_IN_PROJECT',
|
|
86
|
+
message: `spaceAccess includes UUID(s) not found in this project: ${result.unknownUuids.join(', ')}.` +
|
|
87
|
+
(known.length > 0 ? ` Known: ${known}.` : '') +
|
|
88
|
+
' Discover valid UUIDs via content-reader list_spaces — do not invent.',
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* After create/update with non-empty spaceAccess, warn when UUIDs are missing from the project.
|
|
96
|
+
* Never fails the mutation.
|
|
97
|
+
*/
|
|
98
|
+
async function warningsForAgentSpaceAccess(client, projectUuid, spaceAccess) {
|
|
99
|
+
const result = await fetchSpaceAccessValidation(client, projectUuid, spaceAccess);
|
|
100
|
+
return warningsFromSpaceAccessValidation(result);
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const space_warnings_js_1 = require("./space-warnings.js");
|
|
5
|
+
const PROJECT = '11111111-1111-1111-1111-111111111111';
|
|
6
|
+
const SPACE_A = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
|
|
7
|
+
const SPACE_B = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
|
|
8
|
+
const UNKNOWN = 'cccccccc-cccc-cccc-cccc-cccccccccccc';
|
|
9
|
+
(0, vitest_1.describe)('warningsForAgentSpaceAccess', () => {
|
|
10
|
+
(0, vitest_1.it)('skips when spaceAccess is undefined or empty', async () => {
|
|
11
|
+
const listSpacesInProject = vitest_1.vi.fn();
|
|
12
|
+
const client = { listSpacesInProject };
|
|
13
|
+
(0, vitest_1.expect)(await (0, space_warnings_js_1.warningsForAgentSpaceAccess)(client, PROJECT, undefined)).toEqual([]);
|
|
14
|
+
(0, vitest_1.expect)(await (0, space_warnings_js_1.warningsForAgentSpaceAccess)(client, PROJECT, [])).toEqual([]);
|
|
15
|
+
(0, vitest_1.expect)(listSpacesInProject).not.toHaveBeenCalled();
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('returns SPACES_NOT_IN_PROJECT when UUIDs are missing', async () => {
|
|
18
|
+
var _a;
|
|
19
|
+
const listSpacesInProject = vitest_1.vi.fn().mockResolvedValue([{ uuid: SPACE_A, name: 'Finance' }]);
|
|
20
|
+
const warnings = await (0, space_warnings_js_1.warningsForAgentSpaceAccess)({ listSpacesInProject }, PROJECT, [
|
|
21
|
+
SPACE_A,
|
|
22
|
+
UNKNOWN,
|
|
23
|
+
]);
|
|
24
|
+
(0, vitest_1.expect)(warnings).toEqual([
|
|
25
|
+
vitest_1.expect.objectContaining({
|
|
26
|
+
code: 'SPACES_NOT_IN_PROJECT',
|
|
27
|
+
message: vitest_1.expect.stringContaining(UNKNOWN),
|
|
28
|
+
}),
|
|
29
|
+
]);
|
|
30
|
+
(0, vitest_1.expect)((_a = warnings[0]) === null || _a === void 0 ? void 0 : _a.message).toContain('Finance');
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('returns no warning when all UUIDs match', async () => {
|
|
33
|
+
const listSpacesInProject = vitest_1.vi.fn().mockResolvedValue([
|
|
34
|
+
{ uuid: SPACE_A, name: 'Finance' },
|
|
35
|
+
{ uuid: SPACE_B, name: 'Leadership' },
|
|
36
|
+
]);
|
|
37
|
+
const warnings = await (0, space_warnings_js_1.warningsForAgentSpaceAccess)({ listSpacesInProject }, PROJECT, [
|
|
38
|
+
SPACE_A,
|
|
39
|
+
SPACE_B,
|
|
40
|
+
]);
|
|
41
|
+
(0, vitest_1.expect)(warnings).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('returns SPACE_LIST_UNAVAILABLE when list throws', async () => {
|
|
44
|
+
const listSpacesInProject = vitest_1.vi.fn().mockRejectedValue(new Error('upstream down'));
|
|
45
|
+
const warnings = await (0, space_warnings_js_1.warningsForAgentSpaceAccess)({ listSpacesInProject }, PROJECT, [SPACE_A]);
|
|
46
|
+
(0, vitest_1.expect)(warnings).toEqual([
|
|
47
|
+
vitest_1.expect.objectContaining({
|
|
48
|
+
code: 'SPACE_LIST_UNAVAILABLE',
|
|
49
|
+
message: vitest_1.expect.stringContaining('upstream down'),
|
|
50
|
+
}),
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
(0, vitest_1.describe)('warningsFromSpaceAccessValidation', () => {
|
|
55
|
+
(0, vitest_1.it)('derives SPACES_NOT_IN_PROJECT without upstream call', () => {
|
|
56
|
+
const warnings = (0, space_warnings_js_1.warningsFromSpaceAccessValidation)({
|
|
57
|
+
resolved: [{ uuid: SPACE_A, name: 'Finance' }],
|
|
58
|
+
unknownUuids: [UNKNOWN],
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.expect)(warnings).toEqual([
|
|
61
|
+
vitest_1.expect.objectContaining({
|
|
62
|
+
code: 'SPACES_NOT_IN_PROJECT',
|
|
63
|
+
message: vitest_1.expect.stringContaining(UNKNOWN),
|
|
64
|
+
}),
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.describe)('formatSpaceAccessPreviewLine', () => {
|
|
69
|
+
(0, vitest_1.it)('shows all spaces when skipped', () => {
|
|
70
|
+
(0, vitest_1.expect)((0, space_warnings_js_1.formatSpaceAccessPreviewLine)(undefined, { skipped: true })).toBe('Space access: (all project spaces)');
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.it)('shows resolved names when all match', async () => {
|
|
73
|
+
const validation = await (0, space_warnings_js_1.fetchSpaceAccessValidation)({
|
|
74
|
+
listSpacesInProject: vitest_1.vi.fn().mockResolvedValue([{ uuid: SPACE_A, name: 'Finance' }]),
|
|
75
|
+
}, PROJECT, [SPACE_A]);
|
|
76
|
+
(0, vitest_1.expect)((0, space_warnings_js_1.formatSpaceAccessPreviewLine)([SPACE_A], validation)).toContain('Finance');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft warnings when agent tags match no explores (Lightdash explore allowlist).
|
|
3
|
+
*/
|
|
4
|
+
export type AgentTagWarningCode = 'EXPLORE_ACCESS_SUMMARY_UNAVAILABLE' | 'TAGS_MATCH_NO_EXPLORES';
|
|
5
|
+
export type AgentTagWarning = {
|
|
6
|
+
code: AgentTagWarningCode;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type ExploreAccessSummaryClient = {
|
|
10
|
+
getExploreAccessSummary: (projectUuid: string, body: {
|
|
11
|
+
tags: string[] | null;
|
|
12
|
+
}) => Promise<unknown[]>;
|
|
13
|
+
};
|
|
14
|
+
/** Non-empty tags only; null/empty skip (all explores). */
|
|
15
|
+
export declare function effectiveAgentTags(tags: string[] | null | undefined): string[] | undefined;
|
|
16
|
+
export type ExploreAccessForTagsResult = {
|
|
17
|
+
count: number;
|
|
18
|
+
} | {
|
|
19
|
+
error: Error;
|
|
20
|
+
} | {
|
|
21
|
+
skipped: true;
|
|
22
|
+
};
|
|
23
|
+
/** Shared explore-access-summary fetch for preview messages and post-mutation warnings. */
|
|
24
|
+
export declare function fetchExploreAccessForAgentTags(client: ExploreAccessSummaryClient, projectUuid: string, tags: string[] | null | undefined): Promise<ExploreAccessForTagsResult>;
|
|
25
|
+
/** Explore count for create confirmation copy; null when all explores or summary unavailable. */
|
|
26
|
+
export declare function previewExploreCountForTags(client: ExploreAccessSummaryClient, projectUuid: string, tags: string[] | null | undefined): Promise<number | null>;
|
|
27
|
+
/**
|
|
28
|
+
* After create/update with non-empty tags, warn when explore-access-summary is empty.
|
|
29
|
+
* Never fails the mutation.
|
|
30
|
+
*/
|
|
31
|
+
export declare function warningsForAgentTags(client: ExploreAccessSummaryClient, projectUuid: string, tags: string[] | null | undefined): Promise<AgentTagWarning[]>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Soft warnings when agent tags match no explores (Lightdash explore allowlist).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.effectiveAgentTags = effectiveAgentTags;
|
|
7
|
+
exports.fetchExploreAccessForAgentTags = fetchExploreAccessForAgentTags;
|
|
8
|
+
exports.previewExploreCountForTags = previewExploreCountForTags;
|
|
9
|
+
exports.warningsForAgentTags = warningsForAgentTags;
|
|
10
|
+
/** Non-empty tags only; null/empty skip (all explores). */
|
|
11
|
+
function effectiveAgentTags(tags) {
|
|
12
|
+
if (tags == null || tags.length === 0) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return tags;
|
|
16
|
+
}
|
|
17
|
+
/** Shared explore-access-summary fetch for preview messages and post-mutation warnings. */
|
|
18
|
+
async function fetchExploreAccessForAgentTags(client, projectUuid, tags) {
|
|
19
|
+
const effective = effectiveAgentTags(tags);
|
|
20
|
+
if (effective === undefined) {
|
|
21
|
+
return { skipped: true };
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const summary = await client.getExploreAccessSummary(projectUuid, { tags: effective });
|
|
25
|
+
return { count: summary.length };
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return { error: err instanceof Error ? err : new Error(String(err)) };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Explore count for create confirmation copy; null when all explores or summary unavailable. */
|
|
32
|
+
async function previewExploreCountForTags(client, projectUuid, tags) {
|
|
33
|
+
const result = await fetchExploreAccessForAgentTags(client, projectUuid, tags);
|
|
34
|
+
if ('skipped' in result) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if ('error' in result) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return result.count;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* After create/update with non-empty tags, warn when explore-access-summary is empty.
|
|
44
|
+
* Never fails the mutation.
|
|
45
|
+
*/
|
|
46
|
+
async function warningsForAgentTags(client, projectUuid, tags) {
|
|
47
|
+
const result = await fetchExploreAccessForAgentTags(client, projectUuid, tags);
|
|
48
|
+
if ('skipped' in result) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
if ('error' in result) {
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
code: 'EXPLORE_ACCESS_SUMMARY_UNAVAILABLE',
|
|
55
|
+
message: `Could not verify explore access for agent tags: ${result.error.message}`,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
if (result.count === 0) {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
code: 'TAGS_MATCH_NO_EXPLORES',
|
|
63
|
+
message: 'Agent tags match no explores (OR match on dbt/Lightdash explore or field tags). ' +
|
|
64
|
+
'The agent will see no data model. Clear tags for all explores, or tag explores first, ' +
|
|
65
|
+
'then re-check with get_explore_access_summary.',
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
@@ -17,8 +17,11 @@ export type RegisteredAiAgentTool = {
|
|
|
17
17
|
inputSchema: Record<string, unknown>;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
export declare function mockAiAgentsContext(aiAgents: Record<string, ReturnType<typeof vi.fn>>): McpContextProvider;
|
|
20
|
+
export declare function mockAiAgentsContext(aiAgents: Record<string, ReturnType<typeof vi.fn>>, spaces?: Record<string, ReturnType<typeof vi.fn>>): McpContextProvider;
|
|
21
21
|
export declare function registeredAiAgentTool(register: (server: never, ctx: McpContextProvider) => void, ctx: McpContextProvider, toolId: string, server?: {
|
|
22
22
|
registerTool: ReturnType<typeof vi.fn>;
|
|
23
|
+
server?: {
|
|
24
|
+
getClientCapabilities: () => unknown;
|
|
25
|
+
};
|
|
23
26
|
}): RegisteredAiAgentTool;
|
|
24
27
|
export declare function parseAiAgentToolBody(result: AiAgentToolResult): Record<string, unknown>;
|
|
@@ -8,17 +8,22 @@ exports.registeredAiAgentTool = registeredAiAgentTool;
|
|
|
8
8
|
exports.parseAiAgentToolBody = parseAiAgentToolBody;
|
|
9
9
|
const vitest_1 = require("vitest");
|
|
10
10
|
const shared_js_1 = require("../shared.js");
|
|
11
|
-
function mockAiAgentsContext(aiAgents
|
|
11
|
+
function mockAiAgentsContext(aiAgents, spaces = {
|
|
12
|
+
listSpacesInProject: vitest_1.vi.fn().mockResolvedValue([]),
|
|
13
|
+
}) {
|
|
12
14
|
return {
|
|
13
15
|
getContext: async () => ({
|
|
14
16
|
lightdashClient: {
|
|
15
|
-
v1: { aiAgents },
|
|
17
|
+
v1: { aiAgents, spaces },
|
|
16
18
|
},
|
|
17
19
|
auth: { mode: 'none' },
|
|
18
20
|
}),
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
function registeredAiAgentTool(register, ctx, toolId, server = { registerTool: vitest_1.vi.fn() }) {
|
|
24
|
+
if (!server.registerTool) {
|
|
25
|
+
server.registerTool = vitest_1.vi.fn();
|
|
26
|
+
}
|
|
22
27
|
register(server, ctx);
|
|
23
28
|
const call = server.registerTool.mock.calls.find((entry) => entry[0] === `${shared_js_1.TOOL_PREFIX}${toolId}`);
|
|
24
29
|
if (call === undefined) {
|
|
@@ -10,35 +10,85 @@ const project_scope_js_1 = require("../../governance/project-scope.js");
|
|
|
10
10
|
const content_reader_js_1 = require("../../policy/content-reader.js");
|
|
11
11
|
const envelope_js_1 = require("../../policy/envelope.js");
|
|
12
12
|
const api_shape_js_1 = require("../lib/api-shape.js");
|
|
13
|
+
const artifacts_js_1 = require("../lib/artifacts.js");
|
|
13
14
|
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
14
15
|
const reader_content_js_1 = require("../project/reader-content.js");
|
|
15
16
|
const chart_source_js_1 = require("../query/chart-source.js");
|
|
16
17
|
const reader_tool_helpers_js_1 = require("../query/reader-tool-helpers.js");
|
|
18
|
+
const resolve_saved_sql_chart_js_1 = require("../query/resolve-saved-sql-chart.js");
|
|
17
19
|
const shared_js_1 = require("../shared.js");
|
|
18
20
|
const types_js_1 = require("../types.js");
|
|
21
|
+
function sqlExplainSummary(args) {
|
|
22
|
+
return {
|
|
23
|
+
identity: {
|
|
24
|
+
uuid: args.savedSqlUuid,
|
|
25
|
+
name: args.name,
|
|
26
|
+
type: 'chart',
|
|
27
|
+
},
|
|
28
|
+
businessDescription: args.description,
|
|
29
|
+
verification: { verified: false },
|
|
30
|
+
measures: [],
|
|
31
|
+
groupings: [],
|
|
32
|
+
filters: [],
|
|
33
|
+
parameters: [],
|
|
34
|
+
timeContext: [],
|
|
35
|
+
knownWarnings: ['SQL chart; standalone execution disabled by default on content-reader'],
|
|
36
|
+
executionRequirements: ['Not executable via run_chart on content-reader v1'],
|
|
37
|
+
summary: (0, reader_content_js_1.toReaderSqlChartSummary)(args),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
19
40
|
function registerExplainContent(server, contextProvider) {
|
|
20
41
|
(0, content_reader_js_1.registerContentReaderTool)(server, 'explain_content', {
|
|
21
42
|
title: 'Explain content',
|
|
22
|
-
description: 'Produce a deterministic metadata-based explanation of a chart or dashboard',
|
|
43
|
+
description: 'Produce a deterministic metadata-based explanation of a chart or dashboard. For saved SQL charts, pass includeArtifacts=["sql"] to attach the authored SQL body as a separate MCP resource.',
|
|
23
44
|
safety: content_reader_js_1.METADATA_SAFETY,
|
|
24
45
|
inputSchema: {
|
|
25
46
|
projectUuid: (0, schema_fields_js_1.projectUuidField)().optional(),
|
|
26
47
|
contentType: zod_1.z.enum(['chart', 'dashboard']),
|
|
27
48
|
contentUuidOrSlug: (0, schema_fields_js_1.uuidOrSlugField)('Content UUID or slug'),
|
|
49
|
+
includeArtifacts: (0, artifacts_js_1.includeArtifactsField)(['sql']),
|
|
28
50
|
},
|
|
29
51
|
},
|
|
30
52
|
/* eslint-disable sonarjs/cognitive-complexity, sonarjs/cyclomatic-complexity -- explain branches */
|
|
31
53
|
(profile) => (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
32
|
-
var _a;
|
|
54
|
+
var _a, _b;
|
|
33
55
|
try {
|
|
34
56
|
const scope = (0, project_scope_js_1.resolveProjectScope)({ projectUuid: args.projectUuid });
|
|
35
57
|
if (args.contentType === 'chart') {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
const include = (0, artifacts_js_1.parseIncludeArtifacts)(args.includeArtifacts, []);
|
|
59
|
+
const preClass = await (0, chart_source_js_1.resolveChartSource)(c, scope.projectUuid, args.contentUuidOrSlug);
|
|
60
|
+
if (preClass.class === 'sql') {
|
|
61
|
+
const savedSqlUuid = (_a = preClass.uuid) !== null && _a !== void 0 ? _a : args.contentUuidOrSlug;
|
|
62
|
+
if (include.has('sql')) {
|
|
63
|
+
const sqlChart = await (0, resolve_saved_sql_chart_js_1.resolveSavedSqlChart)(c, scope.projectUuid, savedSqlUuid);
|
|
64
|
+
return (0, artifacts_js_1.sqlRevealToolResult)({
|
|
65
|
+
profile,
|
|
66
|
+
projectUuid: scope.projectUuid,
|
|
67
|
+
projectPinned: scope.projectPinned,
|
|
68
|
+
include,
|
|
69
|
+
savedSqlUuid: sqlChart.savedSqlUuid,
|
|
70
|
+
sql: sqlChart.sql,
|
|
71
|
+
summaryData: sqlExplainSummary(sqlChart),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return (0, artifacts_js_1.sqlRevealToolResult)({
|
|
75
|
+
profile,
|
|
76
|
+
projectUuid: scope.projectUuid,
|
|
77
|
+
projectPinned: scope.projectPinned,
|
|
78
|
+
include,
|
|
79
|
+
savedSqlUuid,
|
|
80
|
+
summaryData: sqlExplainSummary({
|
|
81
|
+
savedSqlUuid,
|
|
82
|
+
name: preClass.name,
|
|
83
|
+
description: preClass.description,
|
|
84
|
+
slug: preClass.slug,
|
|
85
|
+
space: preClass.space,
|
|
86
|
+
lastUpdatedAt: preClass.lastUpdatedAt,
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
39
89
|
}
|
|
40
90
|
const chart = (0, api_shape_js_1.asRecord)(await c.v2.charts.getSavedChart(scope.projectUuid, args.contentUuidOrSlug));
|
|
41
|
-
const metricQuery = ((
|
|
91
|
+
const metricQuery = ((_b = chart.metricQuery) !== null && _b !== void 0 ? _b : {});
|
|
42
92
|
const verification = chart.verification;
|
|
43
93
|
const chartType = (0, reader_content_js_1.detectChartType)(chart);
|
|
44
94
|
const explanation = {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-reader tool-result artifact helpers (ADR-0032).
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import type { ContentReaderWarning } from '../../policy/envelope.js';
|
|
6
|
+
import type { TextContent, ToolArtifactCatalogEntry, ToolArtifactKind, ToolArtifactSpec } from '../shared.js';
|
|
7
|
+
import type { ProfileId } from '@lightdash-tools/common';
|
|
8
|
+
/** Per-tool allowlist — do not advertise kinds the tool cannot attach. */
|
|
9
|
+
export declare function includeArtifactsField(kinds: readonly [ToolArtifactKind, ...ToolArtifactKind[]]): z.ZodType<ToolArtifactKind[] | undefined>;
|
|
10
|
+
export declare function parseIncludeArtifacts(value: Array<'data' | 'sql'> | undefined, defaults: ToolArtifactKind[]): Set<ToolArtifactKind>;
|
|
11
|
+
export declare function contentReaderArtifactUri(kind: ToolArtifactKind, id: string): string;
|
|
12
|
+
export declare const SQL_ARTIFACT_AVAILABLE_WARNING: ContentReaderWarning;
|
|
13
|
+
/** Opted-in SQL is model-facing (ADR-0032). */
|
|
14
|
+
export declare function buildSqlArtifact(args: {
|
|
15
|
+
savedSqlUuid: string;
|
|
16
|
+
sql: string;
|
|
17
|
+
}): ToolArtifactSpec;
|
|
18
|
+
export declare function buildDataArtifact(args: {
|
|
19
|
+
queryUuid: string;
|
|
20
|
+
rows: unknown;
|
|
21
|
+
}): ToolArtifactSpec;
|
|
22
|
+
export declare function catalogEntry(kind: ToolArtifactKind, uri: string, mimeType: string, included: boolean): ToolArtifactCatalogEntry;
|
|
23
|
+
/** Catalog (+ optional attach) for an authored SQL body. */
|
|
24
|
+
export declare function buildSqlArtifactParts(include: Set<ToolArtifactKind>, sql: {
|
|
25
|
+
savedSqlUuid: string;
|
|
26
|
+
sql?: string;
|
|
27
|
+
}): {
|
|
28
|
+
artifacts: ToolArtifactSpec[];
|
|
29
|
+
catalog: ToolArtifactCatalogEntry[];
|
|
30
|
+
};
|
|
31
|
+
/** Discover/explain SQL chart: envelope summary + optional SQL resource part. */
|
|
32
|
+
export declare function sqlRevealToolResult(args: {
|
|
33
|
+
profile: ProfileId;
|
|
34
|
+
projectUuid: string;
|
|
35
|
+
projectPinned: boolean;
|
|
36
|
+
include: Set<ToolArtifactKind>;
|
|
37
|
+
savedSqlUuid: string;
|
|
38
|
+
/** Present only when `include` has `'sql'` (avoids downloading the body otherwise). */
|
|
39
|
+
sql?: string;
|
|
40
|
+
summaryData: object;
|
|
41
|
+
}): TextContent;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-reader tool-result artifact helpers (ADR-0032).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SQL_ARTIFACT_AVAILABLE_WARNING = void 0;
|
|
7
|
+
exports.includeArtifactsField = includeArtifactsField;
|
|
8
|
+
exports.parseIncludeArtifacts = parseIncludeArtifacts;
|
|
9
|
+
exports.contentReaderArtifactUri = contentReaderArtifactUri;
|
|
10
|
+
exports.buildSqlArtifact = buildSqlArtifact;
|
|
11
|
+
exports.buildDataArtifact = buildDataArtifact;
|
|
12
|
+
exports.catalogEntry = catalogEntry;
|
|
13
|
+
exports.buildSqlArtifactParts = buildSqlArtifactParts;
|
|
14
|
+
exports.sqlRevealToolResult = sqlRevealToolResult;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const envelope_js_1 = require("../../policy/envelope.js");
|
|
17
|
+
const shared_js_1 = require("../shared.js");
|
|
18
|
+
/** Per-tool allowlist — do not advertise kinds the tool cannot attach. */
|
|
19
|
+
function includeArtifactsField(kinds) {
|
|
20
|
+
const kindList = kinds.join(', ');
|
|
21
|
+
const values = [...kinds];
|
|
22
|
+
return zod_1.z
|
|
23
|
+
.array(zod_1.z.enum(values))
|
|
24
|
+
.optional()
|
|
25
|
+
.describe(`Bulky payloads to attach as separate MCP resource parts (allowed: ${kindList}). Omitted kinds use each tool's default.`);
|
|
26
|
+
}
|
|
27
|
+
function parseIncludeArtifacts(value, defaults) {
|
|
28
|
+
return new Set(value !== null && value !== void 0 ? value : defaults);
|
|
29
|
+
}
|
|
30
|
+
function contentReaderArtifactUri(kind, id) {
|
|
31
|
+
return `lightdash://artifacts/content-reader/${kind}/${encodeURIComponent(id)}`;
|
|
32
|
+
}
|
|
33
|
+
exports.SQL_ARTIFACT_AVAILABLE_WARNING = {
|
|
34
|
+
code: 'SQL_ARTIFACT_AVAILABLE',
|
|
35
|
+
message: 'Authored SQL is available; pass includeArtifacts=["sql"] to attach it as a separate resource part',
|
|
36
|
+
};
|
|
37
|
+
/** Opted-in SQL is model-facing (ADR-0032). */
|
|
38
|
+
function buildSqlArtifact(args) {
|
|
39
|
+
return {
|
|
40
|
+
kind: 'sql',
|
|
41
|
+
uri: contentReaderArtifactUri('sql', args.savedSqlUuid),
|
|
42
|
+
mimeType: 'text/sql',
|
|
43
|
+
text: args.sql,
|
|
44
|
+
audience: ['assistant', 'user'],
|
|
45
|
+
priority: 0.6,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function buildDataArtifact(args) {
|
|
49
|
+
return {
|
|
50
|
+
kind: 'data',
|
|
51
|
+
uri: contentReaderArtifactUri('data', args.queryUuid),
|
|
52
|
+
mimeType: 'application/json',
|
|
53
|
+
text: JSON.stringify(args.rows),
|
|
54
|
+
audience: ['assistant', 'user'],
|
|
55
|
+
priority: 0.8,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function catalogEntry(kind, uri, mimeType, included) {
|
|
59
|
+
return { kind, uri, mimeType, included };
|
|
60
|
+
}
|
|
61
|
+
/** Catalog (+ optional attach) for an authored SQL body. */
|
|
62
|
+
function buildSqlArtifactParts(include, sql) {
|
|
63
|
+
const uri = contentReaderArtifactUri('sql', sql.savedSqlUuid);
|
|
64
|
+
const included = include.has('sql') && typeof sql.sql === 'string';
|
|
65
|
+
const catalog = [catalogEntry('sql', uri, 'text/sql', included)];
|
|
66
|
+
const artifacts = included && sql.sql !== undefined
|
|
67
|
+
? [buildSqlArtifact({ savedSqlUuid: sql.savedSqlUuid, sql: sql.sql })]
|
|
68
|
+
: [];
|
|
69
|
+
return { artifacts, catalog };
|
|
70
|
+
}
|
|
71
|
+
/** Discover/explain SQL chart: envelope summary + optional SQL resource part. */
|
|
72
|
+
function sqlRevealToolResult(args) {
|
|
73
|
+
const includeSql = args.include.has('sql');
|
|
74
|
+
const warnings = includeSql ? [] : [exports.SQL_ARTIFACT_AVAILABLE_WARNING];
|
|
75
|
+
const envelope = (0, envelope_js_1.contentReaderEnvelope)(args.summaryData, {
|
|
76
|
+
profile: args.profile,
|
|
77
|
+
projectUuid: args.projectUuid,
|
|
78
|
+
projectPinned: args.projectPinned,
|
|
79
|
+
warnings,
|
|
80
|
+
});
|
|
81
|
+
const { artifacts, catalog } = buildSqlArtifactParts(args.include, {
|
|
82
|
+
savedSqlUuid: args.savedSqlUuid,
|
|
83
|
+
sql: includeSql ? args.sql : undefined,
|
|
84
|
+
});
|
|
85
|
+
return (0, shared_js_1.artifactToolResult)({
|
|
86
|
+
summary: envelope,
|
|
87
|
+
artifacts,
|
|
88
|
+
catalog,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -177,6 +177,7 @@ function mockContext(listProjects, getProject) {
|
|
|
177
177
|
canExecuteSqlCharts: false,
|
|
178
178
|
canExecuteDashboardTiles: true,
|
|
179
179
|
canExecuteDashboardSqlTiles: true,
|
|
180
|
+
canRevealSqlBodies: true,
|
|
180
181
|
});
|
|
181
182
|
(0, vitest_1.expect)(body.context.projectUuid).toBe(PINNED);
|
|
182
183
|
(0, vitest_1.expect)(getProject).toHaveBeenCalledWith(PINNED);
|
|
@@ -18,6 +18,17 @@ export type DashboardTileClass = {
|
|
|
18
18
|
export declare function classifyDashboardTile(type: string, props: Record<string, unknown>): DashboardTileClass;
|
|
19
19
|
/** Pass through OpenAPI TableCalculation fields agents need to clone. */
|
|
20
20
|
export declare function toReaderTableCalculation(tc: unknown): Record<string, unknown>;
|
|
21
|
+
/** Metadata summary for a saved SQL chart — never includes the authored SQL body. */
|
|
22
|
+
export declare function toReaderSqlChartSummary(chart: {
|
|
23
|
+
savedSqlUuid: string;
|
|
24
|
+
slug?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
description?: string | null;
|
|
27
|
+
chartKind?: unknown;
|
|
28
|
+
limit?: unknown;
|
|
29
|
+
space?: unknown;
|
|
30
|
+
lastUpdatedAt?: string | null;
|
|
31
|
+
}): Record<string, unknown>;
|
|
21
32
|
export declare function toReaderDashboard(dashboard: Record<string, unknown>, includeTiles: boolean): {
|
|
22
33
|
description: unknown;
|
|
23
34
|
filters: unknown;
|