@lightdash-tools/common 0.6.0 → 0.8.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.
Files changed (120) hide show
  1. package/dist/agentops/extract-yaml-project.d.ts +7 -0
  2. package/dist/agentops/extract-yaml-project.js +42 -0
  3. package/dist/agentops/formatters.d.ts +5 -0
  4. package/dist/agentops/formatters.js +47 -0
  5. package/dist/agentops/snapshots.d.ts +32 -0
  6. package/dist/agentops/snapshots.js +34 -0
  7. package/dist/agentops/types.d.ts +224 -0
  8. package/dist/agentops/types.js +430 -0
  9. package/dist/argument-validation.d.ts +25 -0
  10. package/dist/argument-validation.js +217 -0
  11. package/dist/argument-validation.test.d.ts +1 -0
  12. package/dist/argument-validation.test.js +205 -0
  13. package/dist/audit.d.ts +9 -2
  14. package/dist/audit.js +17 -2
  15. package/dist/audit.test.d.ts +1 -0
  16. package/dist/audit.test.js +73 -0
  17. package/dist/env.d.ts +8 -0
  18. package/dist/env.js +9 -1
  19. package/dist/index.d.ts +7 -3
  20. package/dist/index.js +14 -2
  21. package/dist/input-validation.d.ts +35 -0
  22. package/dist/input-validation.js +87 -0
  23. package/dist/input-validation.test.js +93 -0
  24. package/dist/operations/agent-safe.d.ts +5 -0
  25. package/dist/operations/agent-safe.js +9 -0
  26. package/dist/operations/ai-agents.d.ts +6 -0
  27. package/dist/operations/ai-agents.js +427 -0
  28. package/dist/operations/cli-content.d.ts +5 -0
  29. package/dist/operations/cli-content.js +71 -0
  30. package/dist/operations/client-coverage.d.ts +113 -0
  31. package/dist/operations/client-coverage.js +130 -0
  32. package/dist/operations/client-coverage.test.d.ts +1 -0
  33. package/dist/operations/client-coverage.test.js +22 -0
  34. package/dist/operations/content-developer.d.ts +2 -0
  35. package/dist/operations/content-developer.js +457 -0
  36. package/dist/operations/content-governance.d.ts +7 -0
  37. package/dist/operations/content-governance.js +98 -0
  38. package/dist/operations/content-reader.d.ts +2 -0
  39. package/dist/operations/content-reader.js +183 -0
  40. package/dist/operations/index.d.ts +12 -0
  41. package/dist/operations/index.js +34 -0
  42. package/dist/operations/organization-audit.d.ts +2 -0
  43. package/dist/operations/organization-audit.js +273 -0
  44. package/dist/operations/parity.test.d.ts +1 -0
  45. package/dist/operations/parity.test.js +29 -0
  46. package/dist/operations/registry.d.ts +18 -0
  47. package/dist/operations/registry.js +110 -0
  48. package/dist/operations/registry.test.d.ts +1 -0
  49. package/dist/operations/registry.test.js +223 -0
  50. package/dist/operations/semantic-layer.d.ts +6 -0
  51. package/dist/operations/semantic-layer.js +154 -0
  52. package/dist/operations/types.d.ts +86 -0
  53. package/dist/operations/types.js +104 -0
  54. package/dist/operations/types.test.d.ts +1 -0
  55. package/dist/operations/types.test.js +92 -0
  56. package/dist/operations/users.d.ts +6 -0
  57. package/dist/operations/users.js +58 -0
  58. package/dist/safety.d.ts +32 -2
  59. package/dist/safety.js +62 -5
  60. package/dist/safety.test.js +217 -4
  61. package/dist/types/generated/openapi-types.d.ts +32623 -11194
  62. package/dist/types/index.d.ts +12 -0
  63. package/dist/types/index.js +29 -0
  64. package/dist/types/lightdash-api.d.ts +1 -1
  65. package/dist/types/v1/ai-agents.d.ts +112 -3
  66. package/dist/types/v1/charts.d.ts +5 -3
  67. package/dist/types/v1/dashboards.d.ts +13 -0
  68. package/dist/types/v1/index.d.ts +45 -8
  69. package/dist/types/v1/index.js +1 -1
  70. package/dist/types/v1/lightdash-api.d.ts +107 -16
  71. package/dist/types/v1/users.d.ts +4 -0
  72. package/dist/types/v2/content.d.ts +2 -0
  73. package/dist/types/v2/content.js +8 -0
  74. package/dist/types/v2/index.d.ts +11 -9
  75. package/dist/types/v2/index.js +1 -1
  76. package/package.json +17 -3
  77. package/src/agentops/extract-yaml-project.ts +42 -0
  78. package/src/agentops/formatters.ts +52 -0
  79. package/src/agentops/snapshots.ts +56 -0
  80. package/src/agentops/types.ts +599 -0
  81. package/src/argument-validation.test.ts +301 -0
  82. package/src/argument-validation.ts +258 -0
  83. package/src/audit.test.ts +87 -0
  84. package/src/audit.ts +32 -3
  85. package/src/env.ts +9 -0
  86. package/src/index.test.ts +1 -0
  87. package/src/index.ts +17 -6
  88. package/src/input-validation.test.ts +157 -1
  89. package/src/input-validation.ts +95 -0
  90. package/src/operations/agent-safe.ts +8 -0
  91. package/src/operations/ai-agents.ts +467 -0
  92. package/src/operations/cli-content.ts +79 -0
  93. package/src/operations/client-coverage.test.ts +23 -0
  94. package/src/operations/client-coverage.ts +147 -0
  95. package/src/operations/content-developer.ts +485 -0
  96. package/src/operations/content-governance.ts +110 -0
  97. package/src/operations/content-reader.ts +197 -0
  98. package/src/operations/index.ts +42 -0
  99. package/src/operations/organization-audit.ts +293 -0
  100. package/src/operations/parity.test.ts +33 -0
  101. package/src/operations/registry.test.ts +250 -0
  102. package/src/operations/registry.ts +128 -0
  103. package/src/operations/semantic-layer.ts +166 -0
  104. package/src/operations/types.test.ts +110 -0
  105. package/src/operations/types.ts +231 -0
  106. package/src/operations/users.ts +65 -0
  107. package/src/safety.test.ts +276 -4
  108. package/src/safety.ts +83 -4
  109. package/src/types/generated/openapi-types.ts +33701 -11813
  110. package/src/types/index.ts +13 -0
  111. package/src/types/lightdash-api.ts +39 -0
  112. package/src/types/v1/ai-agents.ts +133 -3
  113. package/src/types/v1/charts.ts +5 -3
  114. package/src/types/v1/dashboards.ts +19 -0
  115. package/src/types/v1/index.ts +51 -8
  116. package/src/types/v1/lightdash-api.ts +129 -20
  117. package/src/types/v1/users.ts +4 -0
  118. package/src/types/v2/content.ts +8 -0
  119. package/src/types/v2/index.ts +11 -9
  120. package/tsconfig.json +1 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const ai_agents_1 = require("./ai-agents");
5
+ const cli_content_1 = require("./cli-content");
6
+ const content_developer_1 = require("./content-developer");
7
+ const content_governance_1 = require("./content-governance");
8
+ const content_reader_1 = require("./content-reader");
9
+ const organization_audit_1 = require("./organization-audit");
10
+ const registry_1 = require("./registry");
11
+ const semantic_layer_1 = require("./semantic-layer");
12
+ const types_1 = require("./types");
13
+ const users_1 = require("./users");
14
+ const P0_OPERATION_IDS = [
15
+ 'ai-agents.admin.agents.list',
16
+ 'ai-agents.admin.settings.get',
17
+ 'ai-agents.admin.settings.update',
18
+ 'ai-agents.project.agents.list',
19
+ 'ai-agents.project.agents.get',
20
+ 'ai-agents.project.agents.create',
21
+ 'ai-agents.project.agents.update',
22
+ 'ai-agents.project.agents.delete',
23
+ 'ai-agents.project.threads.start',
24
+ 'ai-agents.project.threads.continue',
25
+ 'ai-agents.project.evaluations.list',
26
+ 'ai-agents.project.evaluations.get',
27
+ 'ai-agents.project.evaluations.create',
28
+ 'ai-agents.project.evaluations.update',
29
+ 'ai-agents.project.evaluations.append',
30
+ 'ai-agents.project.evaluations.delete',
31
+ 'ai-agents.project.evaluations.run',
32
+ 'ai-agents.project.evaluations.runs.list',
33
+ ];
34
+ const ALL_PROFILES = [
35
+ 'core-lifecycle',
36
+ 'evaluations',
37
+ 'conversations',
38
+ 'discovery-readonly',
39
+ ];
40
+ function requiredFields(operation) {
41
+ var _a;
42
+ const agentExposure = (_a = operation.agentExposure) !== null && _a !== void 0 ? _a : 'agent';
43
+ const fields = [
44
+ operation.id,
45
+ operation.summary,
46
+ operation.http.method,
47
+ operation.http.path,
48
+ operation.authorization.safetyImpact,
49
+ operation.sensitivity,
50
+ agentExposure,
51
+ ];
52
+ if (agentExposure === 'agent') {
53
+ if (operation.mcp !== undefined) {
54
+ fields.push(operation.mcp.toolName);
55
+ }
56
+ if (operation.cli !== undefined) {
57
+ fields.push(operation.cli.commandPath);
58
+ }
59
+ }
60
+ return fields;
61
+ }
62
+ (0, vitest_1.describe)('operation registry', () => {
63
+ (0, vitest_1.it)('registers all P0 operation ids', () => {
64
+ for (const id of P0_OPERATION_IDS) {
65
+ (0, vitest_1.expect)((0, registry_1.getOperation)(id)).toBeDefined();
66
+ }
67
+ });
68
+ (0, vitest_1.it)('has no duplicate operation ids', () => {
69
+ const ids = (0, registry_1.listOperations)().map((operation) => operation.id);
70
+ (0, vitest_1.expect)(new Set(ids).size).toBe(ids.length);
71
+ });
72
+ (0, vitest_1.it)('matches aggregated domain export count', () => {
73
+ (0, vitest_1.expect)((0, registry_1.listOperations)()).toHaveLength(ai_agents_1.AI_AGENT_OPERATIONS.length +
74
+ users_1.USER_OPERATIONS.length +
75
+ semantic_layer_1.SEMANTIC_LAYER_OPERATIONS.length +
76
+ organization_audit_1.ORGANIZATION_AUDIT_OPERATIONS.length +
77
+ content_reader_1.CONTENT_READER_OPERATIONS.length +
78
+ content_developer_1.CONTENT_DEVELOPER_OPERATIONS.length +
79
+ content_governance_1.CONTENT_GOVERNANCE_OPERATIONS.length +
80
+ cli_content_1.CLI_CONTENT_OPERATIONS.length);
81
+ });
82
+ (0, vitest_1.it)('includes required descriptor fields on every operation', () => {
83
+ for (const operation of (0, registry_1.listOperations)()) {
84
+ for (const field of requiredFields(operation)) {
85
+ (0, vitest_1.expect)(field).toBeTruthy();
86
+ }
87
+ if (operation.agentExposure === 'agent') {
88
+ (0, vitest_1.expect)(operation.mcp !== undefined || operation.cli !== undefined).toBe(true);
89
+ }
90
+ (0, vitest_1.expect)(operation.profiles.length).toBeGreaterThan(0);
91
+ (0, vitest_1.expect)(operation.http.path.startsWith('/api/v1/') || operation.http.path.startsWith('/api/v2/')).toBe(true);
92
+ }
93
+ });
94
+ (0, vitest_1.it)('assigns idempotentHint correctly for read and destructive agent operations', () => {
95
+ for (const operation of (0, registry_1.listOperations)()) {
96
+ if (operation.mcp === undefined) {
97
+ continue;
98
+ }
99
+ const { annotations } = operation.mcp;
100
+ if (operation.authorization.safetyImpact === 'read') {
101
+ (0, vitest_1.expect)(annotations.readOnlyHint).toBe(true);
102
+ }
103
+ if (operation.authorization.safetyImpact === 'write-destructive') {
104
+ (0, vitest_1.expect)(annotations.destructiveHint).toBe(true);
105
+ (0, vitest_1.expect)(annotations.idempotentHint).toBe(false);
106
+ }
107
+ }
108
+ });
109
+ (0, vitest_1.it)('exposes profile filters for all capability profiles', () => {
110
+ for (const profile of ALL_PROFILES) {
111
+ const operations = (0, registry_1.getOperationsByProfile)(profile);
112
+ (0, vitest_1.expect)(operations.length).toBeGreaterThan(0);
113
+ for (const operation of operations) {
114
+ (0, vitest_1.expect)(operation.profiles).toContain(profile);
115
+ }
116
+ }
117
+ });
118
+ (0, vitest_1.it)('maps agent CRUD to core-lifecycle profile', () => {
119
+ const crudIds = [
120
+ 'ai-agents.project.agents.list',
121
+ 'ai-agents.project.agents.get',
122
+ 'ai-agents.project.agents.create',
123
+ 'ai-agents.project.agents.update',
124
+ 'ai-agents.project.agents.delete',
125
+ ];
126
+ for (const id of crudIds) {
127
+ const operation = (0, registry_1.getOperation)(id);
128
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.profiles).toContain('core-lifecycle');
129
+ }
130
+ });
131
+ (0, vitest_1.it)('maps thread start and continue to conversations profile', () => {
132
+ var _a, _b;
133
+ (0, vitest_1.expect)((_a = (0, registry_1.getOperation)('ai-agents.project.threads.start')) === null || _a === void 0 ? void 0 : _a.profiles).toContain('conversations');
134
+ (0, vitest_1.expect)((_b = (0, registry_1.getOperation)('ai-agents.project.threads.continue')) === null || _b === void 0 ? void 0 : _b.profiles).toContain('conversations');
135
+ });
136
+ (0, vitest_1.it)('documents multi-step workflow for thread start', () => {
137
+ var _a, _b;
138
+ const operation = (0, registry_1.getOperation)('ai-agents.project.threads.start');
139
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.http.path).toBe('/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads');
140
+ (0, vitest_1.expect)((_a = operation === null || operation === void 0 ? void 0 : operation.cli) === null || _a === void 0 ? void 0 : _a.commandPath).toBe('agents threads start');
141
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.workflow).toHaveLength(3);
142
+ const lastStep = (_b = operation === null || operation === void 0 ? void 0 : operation.workflow) === null || _b === void 0 ? void 0 : _b[operation.workflow.length - 1];
143
+ (0, vitest_1.expect)(lastStep === null || lastStep === void 0 ? void 0 : lastStep.path).toContain('/generate');
144
+ });
145
+ (0, vitest_1.it)('documents multi-step workflow for thread continue', () => {
146
+ var _a, _b, _c, _d;
147
+ const operation = (0, registry_1.getOperation)('ai-agents.project.threads.continue');
148
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.workflow).toHaveLength(2);
149
+ (0, vitest_1.expect)((_b = (_a = operation === null || operation === void 0 ? void 0 : operation.workflow) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.path).toContain('/messages');
150
+ (0, vitest_1.expect)((_d = (_c = operation === null || operation === void 0 ? void 0 : operation.workflow) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.path).toContain('/generate');
151
+ });
152
+ (0, vitest_1.it)('maps evaluation lifecycle operations to evaluations profile', () => {
153
+ var _a;
154
+ const evalIds = [
155
+ 'ai-agents.project.evaluations.create',
156
+ 'ai-agents.project.evaluations.append',
157
+ 'ai-agents.project.evaluations.run',
158
+ 'ai-agents.project.evaluations.runs.list',
159
+ ];
160
+ for (const id of evalIds) {
161
+ (0, vitest_1.expect)((_a = (0, registry_1.getOperation)(id)) === null || _a === void 0 ? void 0 : _a.profiles).toContain('evaluations');
162
+ }
163
+ });
164
+ (0, vitest_1.it)('returns undefined for unknown operation id', () => {
165
+ (0, vitest_1.expect)((0, registry_1.getOperation)('ai-agents.unknown.operation')).toBeUndefined();
166
+ });
167
+ (0, vitest_1.it)('filters operations by profile with empty result for unknown profile usage', () => {
168
+ const ops = (0, registry_1.getOperationsByProfile)('core-lifecycle');
169
+ (0, vitest_1.expect)(ops.every((op) => op.profiles.includes('core-lifecycle'))).toBe(true);
170
+ });
171
+ (0, vitest_1.it)('registers users.members.delete as client-only', () => {
172
+ const operation = (0, registry_1.getOperation)('users.members.delete');
173
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.agentExposure).toBe('client-only');
174
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.mcp).toBeUndefined();
175
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.cli).toBeUndefined();
176
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.bannedMcpToolName).toBe('delete_member');
177
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.http.path).toBe('/api/v1/org/user/{userUuid}');
178
+ });
179
+ (0, vitest_1.it)('excludes client-only operations from profile discovery catalogs', () => {
180
+ for (const profile of ALL_PROFILES) {
181
+ for (const operation of (0, registry_1.getOperationsByProfile)(profile)) {
182
+ (0, vitest_1.expect)(operation.agentExposure).not.toBe('client-only');
183
+ }
184
+ }
185
+ (0, vitest_1.expect)((0, registry_1.getOperation)('users.members.delete')).toBeDefined();
186
+ (0, vitest_1.expect)((0, registry_1.getOperationsByProfile)('discovery-readonly').some((op) => op.id === 'users.members.delete')).toBe(false);
187
+ });
188
+ (0, vitest_1.it)('keeps discovery-readonly profile operations read-only', () => {
189
+ for (const operation of (0, registry_1.getOperationsByProfile)('discovery-readonly')) {
190
+ (0, vitest_1.expect)(operation.authorization.safetyImpact).toBe('read');
191
+ }
192
+ });
193
+ (0, vitest_1.it)('never exposes client-only operations on MCP', () => {
194
+ for (const operation of (0, registry_1.listOperations)()) {
195
+ if (operation.agentExposure === 'client-only') {
196
+ (0, vitest_1.expect)(operation.mcp).toBeUndefined();
197
+ (0, vitest_1.expect)(operation.cli).toBeUndefined();
198
+ }
199
+ }
200
+ });
201
+ (0, vitest_1.it)('rejects descriptors whose safetyImpact disagrees with MCP annotations', () => {
202
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)({
203
+ id: 'test.invalid-impact',
204
+ summary: 'Invalid impact pairing',
205
+ http: { method: 'GET', path: '/api/v1/test' },
206
+ authorization: { safetyImpact: 'write-destructive' },
207
+ sensitivity: 'none',
208
+ mcp: {
209
+ toolName: 'test_tool',
210
+ annotations: {
211
+ readOnlyHint: true,
212
+ destructiveHint: false,
213
+ idempotentHint: true,
214
+ openWorldHint: false,
215
+ },
216
+ taskSupport: { exposed: true, taskEligible: false },
217
+ },
218
+ cli: { commandPath: 'test' },
219
+ agentExposure: 'agent',
220
+ profiles: ['discovery-readonly'],
221
+ })).toThrow(/authorization\.safetyImpact/);
222
+ });
223
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Semantic-layer MCP/CLI operations in the shared operation catalog (ADR-0013).
3
+ */
4
+ import type { OperationDescriptor } from './types';
5
+ /** Semantic-layer operations registered in the shared operation catalog. */
6
+ export declare const SEMANTIC_LAYER_OPERATIONS: readonly OperationDescriptor[];
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /**
3
+ * Semantic-layer MCP/CLI operations in the shared operation catalog (ADR-0013).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SEMANTIC_LAYER_OPERATIONS = void 0;
7
+ const safety_1 = require("../safety");
8
+ const types_1 = require("./types");
9
+ const PROFILE_SEMANTIC = 'semantic-discovery';
10
+ const API_V1 = '/api/v1';
11
+ const listProjects = (0, types_1.defineOperation)({
12
+ id: 'semantic.projects.list',
13
+ summary: 'List organization projects (or pinned project when HTTP pin is set)',
14
+ http: { method: 'GET', path: `${API_V1}/org/projects` },
15
+ authorization: { safetyImpact: 'read' },
16
+ sensitivity: 'secret.connection',
17
+ mcp: {
18
+ toolName: 'list_projects',
19
+ annotations: safety_1.READ_ONLY_DEFAULT,
20
+ taskSupport: { exposed: true, taskEligible: false },
21
+ },
22
+ cli: { commandPath: 'projects list' },
23
+ profiles: [PROFILE_SEMANTIC],
24
+ });
25
+ const getProject = (0, types_1.defineOperation)({
26
+ id: 'semantic.projects.get',
27
+ summary: 'Get a project by UUID (connection secrets omitted on MCP)',
28
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}` },
29
+ authorization: { safetyImpact: 'read' },
30
+ sensitivity: 'secret.connection',
31
+ mcp: {
32
+ toolName: 'get_project',
33
+ annotations: safety_1.READ_ONLY_DEFAULT,
34
+ taskSupport: { exposed: true, taskEligible: false },
35
+ },
36
+ cli: { commandPath: 'projects get' },
37
+ profiles: [PROFILE_SEMANTIC, 'content-reader', 'content-developer'],
38
+ });
39
+ const listExplores = (0, types_1.defineOperation)({
40
+ id: 'semantic.explores.list',
41
+ summary: 'List explores in a project',
42
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores` },
43
+ authorization: { safetyImpact: 'read' },
44
+ sensitivity: 'none',
45
+ mcp: {
46
+ toolName: 'list_explores',
47
+ annotations: safety_1.READ_ONLY_DEFAULT,
48
+ taskSupport: { exposed: true, taskEligible: false },
49
+ },
50
+ cli: { commandPath: 'projects explores list' },
51
+ profiles: [PROFILE_SEMANTIC],
52
+ });
53
+ const getExplore = (0, types_1.defineOperation)({
54
+ id: 'semantic.explores.get',
55
+ summary: 'Get a full explore definition',
56
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
57
+ authorization: { safetyImpact: 'read' },
58
+ sensitivity: 'none',
59
+ mcp: {
60
+ toolName: 'get_explore',
61
+ annotations: safety_1.READ_ONLY_DEFAULT,
62
+ taskSupport: { exposed: true, taskEligible: false },
63
+ },
64
+ cli: { commandPath: 'projects explores get' },
65
+ profiles: [PROFILE_SEMANTIC],
66
+ });
67
+ const listDimensions = (0, types_1.defineOperation)({
68
+ id: 'semantic.explores.list_dimensions',
69
+ summary: 'List dimensions for an explore (derived from get explore)',
70
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
71
+ authorization: { safetyImpact: 'read' },
72
+ sensitivity: 'none',
73
+ mcp: {
74
+ toolName: 'list_dimensions',
75
+ annotations: safety_1.READ_ONLY_DEFAULT,
76
+ taskSupport: { exposed: true, taskEligible: false },
77
+ },
78
+ cli: { commandPath: 'projects explores dimensions' },
79
+ profiles: [PROFILE_SEMANTIC],
80
+ });
81
+ const getFieldLineage = (0, types_1.defineOperation)({
82
+ id: 'semantic.explores.get_field_lineage',
83
+ summary: 'Get field lineage for an explore field (derived from get explore)',
84
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
85
+ authorization: { safetyImpact: 'read' },
86
+ sensitivity: 'none',
87
+ mcp: {
88
+ toolName: 'get_field_lineage',
89
+ annotations: safety_1.READ_ONLY_DEFAULT,
90
+ taskSupport: { exposed: true, taskEligible: false },
91
+ },
92
+ cli: { commandPath: 'projects explores lineage' },
93
+ profiles: [PROFILE_SEMANTIC],
94
+ });
95
+ const listMetrics = (0, types_1.defineOperation)({
96
+ id: 'semantic.metrics.list',
97
+ summary: 'List metrics in the project data catalog',
98
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/dataCatalog/metrics` },
99
+ authorization: { safetyImpact: 'read' },
100
+ sensitivity: 'none',
101
+ mcp: {
102
+ toolName: 'list_metrics',
103
+ annotations: safety_1.READ_ONLY_DEFAULT,
104
+ taskSupport: { exposed: true, taskEligible: false },
105
+ },
106
+ cli: { commandPath: 'metrics list' },
107
+ profiles: [PROFILE_SEMANTIC],
108
+ });
109
+ const getMetric = (0, types_1.defineOperation)({
110
+ id: 'semantic.metrics.get',
111
+ summary: 'Get a metric from the project data catalog',
112
+ http: {
113
+ method: 'GET',
114
+ path: `${API_V1}/projects/{projectUuid}/dataCatalog/metrics/{tableName}/{metricName}`,
115
+ },
116
+ authorization: { safetyImpact: 'read' },
117
+ sensitivity: 'none',
118
+ mcp: {
119
+ toolName: 'get_metric',
120
+ annotations: safety_1.READ_ONLY_DEFAULT,
121
+ taskSupport: { exposed: true, taskEligible: false },
122
+ },
123
+ cli: { commandPath: 'metrics get' },
124
+ profiles: [PROFILE_SEMANTIC],
125
+ });
126
+ const compileQuery = (0, types_1.defineOperation)({
127
+ id: 'semantic.query.compile',
128
+ summary: 'Compile a metric query to SQL without executing warehouse rows',
129
+ http: {
130
+ method: 'POST',
131
+ path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}/compileQuery`,
132
+ },
133
+ authorization: { safetyImpact: 'read' },
134
+ sensitivity: 'none',
135
+ mcp: {
136
+ toolName: 'compile_query',
137
+ annotations: safety_1.READ_ONLY_DEFAULT,
138
+ taskSupport: { exposed: true, taskEligible: false },
139
+ },
140
+ cli: { commandPath: 'query compile' },
141
+ profiles: [PROFILE_SEMANTIC],
142
+ });
143
+ /** Semantic-layer operations registered in the shared operation catalog. */
144
+ exports.SEMANTIC_LAYER_OPERATIONS = [
145
+ listProjects,
146
+ getProject,
147
+ listExplores,
148
+ getExplore,
149
+ listDimensions,
150
+ getFieldLineage,
151
+ listMetrics,
152
+ getMetric,
153
+ compileQuery,
154
+ ];
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Shared typed operation catalog (ADR-0013).
3
+ * Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
4
+ */
5
+ import type { SafetyImpact, ToolAnnotations } from '../safety';
6
+ export type { SafetyImpact };
7
+ /** Whether an operation may appear on MCP/CLI agent surfaces. */
8
+ export type AgentExposure = 'agent' | 'client-only';
9
+ /** HTTP verbs supported by registered operations. */
10
+ export type HttpMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
11
+ /**
12
+ * Capability profiles group operations for selective exposure (CLI profiles, MCP subsets).
13
+ */
14
+ export type CapabilityProfile = 'content-developer' | 'content-governance' | 'content-reader' | 'conversations' | 'core-lifecycle' | 'discovery-readonly' | 'evaluations' | 'org-audit-readonly' | 'semantic-discovery';
15
+ /**
16
+ * MCP response sensitivity class (ADR-0011).
17
+ * Documents which redaction class handlers must apply; does not auto-redact.
18
+ */
19
+ export type SensitivityClass = 'none' | 'pii.email' | 'secret.connection' | 'secret.destination';
20
+ /** MCP task semantics for an operation. */
21
+ export type McpTaskSupport = {
22
+ /** When true, the operation is exposed as an MCP tool. */
23
+ exposed: boolean;
24
+ /**
25
+ * When true, the operation may complete asynchronously via MCP Tasks.
26
+ * Long-running evaluation runs and LLM generation are task-eligible.
27
+ */
28
+ taskEligible: boolean;
29
+ };
30
+ export type OperationAuthorization = {
31
+ safetyImpact: SafetyImpact;
32
+ };
33
+ export type OperationHttp = {
34
+ method: HttpMethod;
35
+ /** OpenAPI-style path template (includes `/api/v1` or `/api/v2` prefix). */
36
+ path: string;
37
+ };
38
+ export type OperationMcp = {
39
+ /** MCP tool name without the `lightdash_` prefix. */
40
+ toolName: string;
41
+ annotations: ToolAnnotations;
42
+ taskSupport: McpTaskSupport;
43
+ };
44
+ export type OperationCli = {
45
+ /** Space-delimited CLI command path from the root program (e.g. `agents list`). */
46
+ commandPath: string;
47
+ };
48
+ /** Optional multi-step HTTP workflow when a single registry entry orchestrates several API calls. */
49
+ export type OperationWorkflowStep = {
50
+ method: HttpMethod;
51
+ path: string;
52
+ summary: string;
53
+ };
54
+ export type OperationDescriptor = {
55
+ /** Stable dot-separated identifier (e.g. `ai-agents.project.agents.list`). */
56
+ id: string;
57
+ summary: string;
58
+ http: OperationHttp;
59
+ authorization: OperationAuthorization;
60
+ /**
61
+ * Response sensitivity class for agent surfaces (ADR-0011).
62
+ * Defaults to `none` when omitted from `defineOperation` input.
63
+ */
64
+ sensitivity: SensitivityClass;
65
+ profiles: readonly CapabilityProfile[];
66
+ /** `agent` (default) = may appear on MCP and/or CLI; `client-only` = typed client only. */
67
+ agentExposure: AgentExposure;
68
+ /** Present when the operation is registered (or reserved) as an MCP tool. */
69
+ mcp?: OperationMcp;
70
+ /** Present when a real CLI command exists (`commandPath` must match Commander). */
71
+ cli?: OperationCli;
72
+ /** Irrecoverable denylist name for client-only ops (sans `lightdash_` prefix). */
73
+ bannedMcpToolName?: string;
74
+ /** When set, documents the ordered client-side HTTP steps behind this operation. */
75
+ workflow?: readonly OperationWorkflowStep[];
76
+ };
77
+ /** Input to `defineOperation` before defaults are applied. */
78
+ export type OperationDefinitionInput = Omit<OperationDescriptor, 'agentExposure' | 'sensitivity'> & {
79
+ agentExposure?: AgentExposure;
80
+ sensitivity?: SensitivityClass;
81
+ };
82
+ /**
83
+ * Defines a typed operation descriptor with catalog consistency checks (ADR-0013).
84
+ * Agent ops require at least one of `mcp` or `cli`. Client-only ops omit both.
85
+ */
86
+ export declare function defineOperation(input: OperationDefinitionInput): OperationDescriptor;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Shared typed operation catalog (ADR-0013).
4
+ * Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.defineOperation = defineOperation;
8
+ const VALID_PROFILES = new Set([
9
+ 'content-developer',
10
+ 'content-governance',
11
+ 'content-reader',
12
+ 'conversations',
13
+ 'core-lifecycle',
14
+ 'discovery-readonly',
15
+ 'evaluations',
16
+ 'org-audit-readonly',
17
+ 'semantic-discovery',
18
+ ]);
19
+ const VALID_SENSITIVITY = new Set([
20
+ 'none',
21
+ 'pii.email',
22
+ 'secret.connection',
23
+ 'secret.destination',
24
+ ]);
25
+ function assertNonEmpty(value, field) {
26
+ if (value.trim().length === 0) {
27
+ throw new Error(`Operation ${field} must be a non-empty string`);
28
+ }
29
+ }
30
+ function expectedImpactFromAnnotations(annotations) {
31
+ if (annotations.readOnlyHint) {
32
+ return 'read';
33
+ }
34
+ if (annotations.destructiveHint) {
35
+ return 'write-destructive';
36
+ }
37
+ if (annotations.openWorldHint) {
38
+ return 'external-side-effect';
39
+ }
40
+ return 'write-nondestructive';
41
+ }
42
+ function validateIdempotentHint(annotations, impact, id) {
43
+ if (impact === 'write-destructive' && annotations.idempotentHint === true) {
44
+ throw new Error(`Operation '${id}': destructive operations must not set mcp.annotations.idempotentHint = true`);
45
+ }
46
+ }
47
+ function validateProfiles(id, profiles) {
48
+ if (profiles.length === 0) {
49
+ throw new Error(`Operation '${id}' must declare at least one capability profile`);
50
+ }
51
+ for (const profile of profiles) {
52
+ if (!VALID_PROFILES.has(profile)) {
53
+ throw new Error(`Operation '${id}' has unknown capability profile '${profile}'`);
54
+ }
55
+ }
56
+ }
57
+ function validateClientOnlyOperation(input) {
58
+ var _a;
59
+ if (input.mcp !== undefined || input.cli !== undefined) {
60
+ throw new Error(`Operation '${input.id}': client-only operations must omit mcp and cli metadata`);
61
+ }
62
+ if (input.bannedMcpToolName !== undefined && input.bannedMcpToolName.trim().length === 0) {
63
+ throw new Error(`Operation '${input.id}': bannedMcpToolName must be non-empty when set`);
64
+ }
65
+ return Object.assign(Object.assign({}, input), { agentExposure: 'client-only', sensitivity: (_a = input.sensitivity) !== null && _a !== void 0 ? _a : 'none' });
66
+ }
67
+ function validateAgentMcp(input) {
68
+ if (input.mcp === undefined) {
69
+ return;
70
+ }
71
+ assertNonEmpty(input.mcp.toolName, 'mcp.toolName');
72
+ const expectedImpact = expectedImpactFromAnnotations(input.mcp.annotations);
73
+ if (input.authorization.safetyImpact !== expectedImpact) {
74
+ throw new Error(`Operation '${input.id}': authorization.safetyImpact is '${input.authorization.safetyImpact}' but MCP annotations imply '${expectedImpact}'`);
75
+ }
76
+ validateIdempotentHint(input.mcp.annotations, input.authorization.safetyImpact, input.id);
77
+ }
78
+ /**
79
+ * Defines a typed operation descriptor with catalog consistency checks (ADR-0013).
80
+ * Agent ops require at least one of `mcp` or `cli`. Client-only ops omit both.
81
+ */
82
+ function defineOperation(input) {
83
+ var _a, _b;
84
+ assertNonEmpty(input.id, 'id');
85
+ assertNonEmpty(input.summary, 'summary');
86
+ assertNonEmpty(input.http.path, 'http.path');
87
+ const sensitivity = (_a = input.sensitivity) !== null && _a !== void 0 ? _a : 'none';
88
+ if (!VALID_SENSITIVITY.has(sensitivity)) {
89
+ throw new Error(`Operation '${input.id}' has unknown sensitivity '${String(sensitivity)}'`);
90
+ }
91
+ validateProfiles(input.id, input.profiles);
92
+ const agentExposure = (_b = input.agentExposure) !== null && _b !== void 0 ? _b : 'agent';
93
+ if (agentExposure === 'client-only') {
94
+ return validateClientOnlyOperation(Object.assign(Object.assign({}, input), { sensitivity }));
95
+ }
96
+ if (input.mcp === undefined && input.cli === undefined) {
97
+ throw new Error(`Operation '${input.id}': agent operations require mcp and/or cli metadata`);
98
+ }
99
+ validateAgentMcp(input);
100
+ if (input.cli !== undefined) {
101
+ assertNonEmpty(input.cli.commandPath, 'cli.commandPath');
102
+ }
103
+ return Object.assign(Object.assign({}, input), { agentExposure: 'agent', sensitivity });
104
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const vitest_1 = require("vitest");
15
+ const types_1 = require("./types");
16
+ const baseDescriptor = {
17
+ id: 'test.operation',
18
+ summary: 'Test operation',
19
+ http: { method: 'GET', path: '/api/v1/test' },
20
+ authorization: { safetyImpact: 'read' },
21
+ sensitivity: 'none',
22
+ mcp: {
23
+ toolName: 'test_op',
24
+ annotations: {
25
+ readOnlyHint: true,
26
+ destructiveHint: false,
27
+ idempotentHint: true,
28
+ openWorldHint: false,
29
+ },
30
+ taskSupport: { exposed: true, taskEligible: false },
31
+ },
32
+ cli: { commandPath: 'test op' },
33
+ agentExposure: 'agent',
34
+ profiles: ['discovery-readonly'],
35
+ };
36
+ (0, vitest_1.describe)('defineOperation', () => {
37
+ (0, vitest_1.it)('accepts a valid read descriptor', () => {
38
+ (0, vitest_1.expect)((0, types_1.defineOperation)(baseDescriptor)).toEqual(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'agent', sensitivity: 'none' }));
39
+ });
40
+ (0, vitest_1.it)('defaults agentExposure to agent and sensitivity to none', () => {
41
+ const { agentExposure, sensitivity } = baseDescriptor, withoutDefaults = __rest(baseDescriptor, ["agentExposure", "sensitivity"]);
42
+ void agentExposure;
43
+ void sensitivity;
44
+ const op = (0, types_1.defineOperation)(withoutDefaults);
45
+ (0, vitest_1.expect)(op.agentExposure).toBe('agent');
46
+ (0, vitest_1.expect)(op.sensitivity).toBe('none');
47
+ });
48
+ (0, vitest_1.it)('allows agent ops with mcp only', () => {
49
+ const { cli: _cli } = baseDescriptor, rest = __rest(baseDescriptor, ["cli"]);
50
+ void _cli;
51
+ (0, vitest_1.expect)((0, types_1.defineOperation)(rest).cli).toBeUndefined();
52
+ });
53
+ (0, vitest_1.it)('allows agent ops with cli only', () => {
54
+ const { mcp: _mcp } = baseDescriptor, rest = __rest(baseDescriptor, ["mcp"]);
55
+ void _mcp;
56
+ (0, vitest_1.expect)((0, types_1.defineOperation)(rest).mcp).toBeUndefined();
57
+ });
58
+ (0, vitest_1.it)('rejects agent ops with neither mcp nor cli', () => {
59
+ const { mcp: _mcp, cli: _cli } = baseDescriptor, rest = __rest(baseDescriptor, ["mcp", "cli"]);
60
+ void _mcp;
61
+ void _cli;
62
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(rest)).toThrow(/require mcp and\/or cli/);
63
+ });
64
+ (0, vitest_1.it)('rejects empty id', () => {
65
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { id: ' ' }))).toThrow(/id/);
66
+ });
67
+ (0, vitest_1.it)('rejects unknown profile', () => {
68
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: ['unknown-profile'] }))).toThrow(/unknown capability profile/);
69
+ });
70
+ (0, vitest_1.it)('allows read operation with idempotentHint false (transient execution)', () => {
71
+ var _a;
72
+ const op = (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: Object.assign(Object.assign({}, baseDescriptor.mcp.annotations), { idempotentHint: false }) }) }));
73
+ (0, vitest_1.expect)((_a = op.mcp) === null || _a === void 0 ? void 0 : _a.annotations.idempotentHint).toBe(false);
74
+ });
75
+ (0, vitest_1.it)('rejects client-only operation that still has mcp', () => {
76
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'client-only' }))).toThrow(/must omit mcp and cli/);
77
+ });
78
+ (0, vitest_1.it)('allows client-only operation with bannedMcpToolName and no mcp/cli', () => {
79
+ const op = (0, types_1.defineOperation)({
80
+ id: 'test.client-only',
81
+ summary: 'Client only delete',
82
+ http: { method: 'DELETE', path: '/api/v1/test/{id}' },
83
+ authorization: { safetyImpact: 'write-destructive' },
84
+ agentExposure: 'client-only',
85
+ bannedMcpToolName: 'delete_test',
86
+ profiles: ['discovery-readonly'],
87
+ });
88
+ (0, vitest_1.expect)(op.agentExposure).toBe('client-only');
89
+ (0, vitest_1.expect)(op.bannedMcpToolName).toBe('delete_test');
90
+ (0, vitest_1.expect)(op.sensitivity).toBe('none');
91
+ });
92
+ });