@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.
- package/dist/agentops/extract-yaml-project.d.ts +7 -0
- package/dist/agentops/extract-yaml-project.js +42 -0
- package/dist/agentops/formatters.d.ts +5 -0
- package/dist/agentops/formatters.js +47 -0
- package/dist/agentops/snapshots.d.ts +32 -0
- package/dist/agentops/snapshots.js +34 -0
- package/dist/agentops/types.d.ts +224 -0
- package/dist/agentops/types.js +430 -0
- package/dist/argument-validation.d.ts +25 -0
- package/dist/argument-validation.js +217 -0
- package/dist/argument-validation.test.d.ts +1 -0
- package/dist/argument-validation.test.js +205 -0
- package/dist/audit.d.ts +9 -2
- package/dist/audit.js +17 -2
- package/dist/audit.test.d.ts +1 -0
- package/dist/audit.test.js +73 -0
- package/dist/env.d.ts +8 -0
- package/dist/env.js +9 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +14 -2
- package/dist/input-validation.d.ts +35 -0
- package/dist/input-validation.js +87 -0
- package/dist/input-validation.test.js +93 -0
- package/dist/operations/agent-safe.d.ts +5 -0
- package/dist/operations/agent-safe.js +9 -0
- package/dist/operations/ai-agents.d.ts +6 -0
- package/dist/operations/ai-agents.js +427 -0
- package/dist/operations/cli-content.d.ts +5 -0
- package/dist/operations/cli-content.js +71 -0
- package/dist/operations/client-coverage.d.ts +113 -0
- package/dist/operations/client-coverage.js +130 -0
- package/dist/operations/client-coverage.test.d.ts +1 -0
- package/dist/operations/client-coverage.test.js +22 -0
- package/dist/operations/content-developer.d.ts +2 -0
- package/dist/operations/content-developer.js +457 -0
- package/dist/operations/content-governance.d.ts +7 -0
- package/dist/operations/content-governance.js +98 -0
- package/dist/operations/content-reader.d.ts +2 -0
- package/dist/operations/content-reader.js +183 -0
- package/dist/operations/index.d.ts +12 -0
- package/dist/operations/index.js +34 -0
- package/dist/operations/organization-audit.d.ts +2 -0
- package/dist/operations/organization-audit.js +273 -0
- package/dist/operations/parity.test.d.ts +1 -0
- package/dist/operations/parity.test.js +29 -0
- package/dist/operations/registry.d.ts +18 -0
- package/dist/operations/registry.js +110 -0
- package/dist/operations/registry.test.d.ts +1 -0
- package/dist/operations/registry.test.js +223 -0
- package/dist/operations/semantic-layer.d.ts +6 -0
- package/dist/operations/semantic-layer.js +154 -0
- package/dist/operations/types.d.ts +86 -0
- package/dist/operations/types.js +104 -0
- package/dist/operations/types.test.d.ts +1 -0
- package/dist/operations/types.test.js +92 -0
- package/dist/operations/users.d.ts +6 -0
- package/dist/operations/users.js +58 -0
- package/dist/safety.d.ts +32 -2
- package/dist/safety.js +62 -5
- package/dist/safety.test.js +217 -4
- package/dist/types/generated/openapi-types.d.ts +32623 -11194
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +29 -0
- package/dist/types/lightdash-api.d.ts +1 -1
- package/dist/types/v1/ai-agents.d.ts +112 -3
- package/dist/types/v1/charts.d.ts +5 -3
- package/dist/types/v1/dashboards.d.ts +13 -0
- package/dist/types/v1/index.d.ts +45 -8
- package/dist/types/v1/index.js +1 -1
- package/dist/types/v1/lightdash-api.d.ts +107 -16
- package/dist/types/v1/users.d.ts +4 -0
- package/dist/types/v2/content.d.ts +2 -0
- package/dist/types/v2/content.js +8 -0
- package/dist/types/v2/index.d.ts +11 -9
- package/dist/types/v2/index.js +1 -1
- package/package.json +17 -3
- package/src/agentops/extract-yaml-project.ts +42 -0
- package/src/agentops/formatters.ts +52 -0
- package/src/agentops/snapshots.ts +56 -0
- package/src/agentops/types.ts +599 -0
- package/src/argument-validation.test.ts +301 -0
- package/src/argument-validation.ts +258 -0
- package/src/audit.test.ts +87 -0
- package/src/audit.ts +32 -3
- package/src/env.ts +9 -0
- package/src/index.test.ts +1 -0
- package/src/index.ts +17 -6
- package/src/input-validation.test.ts +157 -1
- package/src/input-validation.ts +95 -0
- package/src/operations/agent-safe.ts +8 -0
- package/src/operations/ai-agents.ts +467 -0
- package/src/operations/cli-content.ts +79 -0
- package/src/operations/client-coverage.test.ts +23 -0
- package/src/operations/client-coverage.ts +147 -0
- package/src/operations/content-developer.ts +485 -0
- package/src/operations/content-governance.ts +110 -0
- package/src/operations/content-reader.ts +197 -0
- package/src/operations/index.ts +42 -0
- package/src/operations/organization-audit.ts +293 -0
- package/src/operations/parity.test.ts +33 -0
- package/src/operations/registry.test.ts +250 -0
- package/src/operations/registry.ts +128 -0
- package/src/operations/semantic-layer.ts +166 -0
- package/src/operations/types.test.ts +110 -0
- package/src/operations/types.ts +231 -0
- package/src/operations/users.ts +65 -0
- package/src/safety.test.ts +276 -4
- package/src/safety.ts +83 -4
- package/src/types/generated/openapi-types.ts +33701 -11813
- package/src/types/index.ts +13 -0
- package/src/types/lightdash-api.ts +39 -0
- package/src/types/v1/ai-agents.ts +133 -3
- package/src/types/v1/charts.ts +5 -3
- package/src/types/v1/dashboards.ts +19 -0
- package/src/types/v1/index.ts +51 -8
- package/src/types/v1/lightdash-api.ts +129 -20
- package/src/types/v1/users.ts +4 -0
- package/src/types/v2/content.ts +8 -0
- package/src/types/v2/index.ts +11 -9
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { AI_AGENT_OPERATIONS } from './ai-agents';
|
|
4
|
+
import { CLI_CONTENT_OPERATIONS } from './cli-content';
|
|
5
|
+
import { CONTENT_DEVELOPER_OPERATIONS } from './content-developer';
|
|
6
|
+
import { CONTENT_GOVERNANCE_OPERATIONS } from './content-governance';
|
|
7
|
+
import { CONTENT_READER_OPERATIONS } from './content-reader';
|
|
8
|
+
import { ORGANIZATION_AUDIT_OPERATIONS } from './organization-audit';
|
|
9
|
+
import { getOperation, getOperationsByProfile, listOperations } from './registry';
|
|
10
|
+
import { SEMANTIC_LAYER_OPERATIONS } from './semantic-layer';
|
|
11
|
+
import { defineOperation } from './types';
|
|
12
|
+
import { USER_OPERATIONS } from './users';
|
|
13
|
+
|
|
14
|
+
import type { CapabilityProfile, OperationDescriptor } from './types';
|
|
15
|
+
|
|
16
|
+
const P0_OPERATION_IDS = [
|
|
17
|
+
'ai-agents.admin.agents.list',
|
|
18
|
+
'ai-agents.admin.settings.get',
|
|
19
|
+
'ai-agents.admin.settings.update',
|
|
20
|
+
'ai-agents.project.agents.list',
|
|
21
|
+
'ai-agents.project.agents.get',
|
|
22
|
+
'ai-agents.project.agents.create',
|
|
23
|
+
'ai-agents.project.agents.update',
|
|
24
|
+
'ai-agents.project.agents.delete',
|
|
25
|
+
'ai-agents.project.threads.start',
|
|
26
|
+
'ai-agents.project.threads.continue',
|
|
27
|
+
'ai-agents.project.evaluations.list',
|
|
28
|
+
'ai-agents.project.evaluations.get',
|
|
29
|
+
'ai-agents.project.evaluations.create',
|
|
30
|
+
'ai-agents.project.evaluations.update',
|
|
31
|
+
'ai-agents.project.evaluations.append',
|
|
32
|
+
'ai-agents.project.evaluations.delete',
|
|
33
|
+
'ai-agents.project.evaluations.run',
|
|
34
|
+
'ai-agents.project.evaluations.runs.list',
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
const ALL_PROFILES: CapabilityProfile[] = [
|
|
38
|
+
'core-lifecycle',
|
|
39
|
+
'evaluations',
|
|
40
|
+
'conversations',
|
|
41
|
+
'discovery-readonly',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
function requiredFields(operation: OperationDescriptor): string[] {
|
|
45
|
+
const agentExposure = operation.agentExposure ?? 'agent';
|
|
46
|
+
const fields = [
|
|
47
|
+
operation.id,
|
|
48
|
+
operation.summary,
|
|
49
|
+
operation.http.method,
|
|
50
|
+
operation.http.path,
|
|
51
|
+
operation.authorization.safetyImpact,
|
|
52
|
+
operation.sensitivity,
|
|
53
|
+
agentExposure,
|
|
54
|
+
];
|
|
55
|
+
if (agentExposure === 'agent') {
|
|
56
|
+
if (operation.mcp !== undefined) {
|
|
57
|
+
fields.push(operation.mcp.toolName);
|
|
58
|
+
}
|
|
59
|
+
if (operation.cli !== undefined) {
|
|
60
|
+
fields.push(operation.cli.commandPath);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return fields;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('operation registry', () => {
|
|
67
|
+
it('registers all P0 operation ids', () => {
|
|
68
|
+
for (const id of P0_OPERATION_IDS) {
|
|
69
|
+
expect(getOperation(id)).toBeDefined();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('has no duplicate operation ids', () => {
|
|
74
|
+
const ids = listOperations().map((operation) => operation.id);
|
|
75
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('matches aggregated domain export count', () => {
|
|
79
|
+
expect(listOperations()).toHaveLength(
|
|
80
|
+
AI_AGENT_OPERATIONS.length +
|
|
81
|
+
USER_OPERATIONS.length +
|
|
82
|
+
SEMANTIC_LAYER_OPERATIONS.length +
|
|
83
|
+
ORGANIZATION_AUDIT_OPERATIONS.length +
|
|
84
|
+
CONTENT_READER_OPERATIONS.length +
|
|
85
|
+
CONTENT_DEVELOPER_OPERATIONS.length +
|
|
86
|
+
CONTENT_GOVERNANCE_OPERATIONS.length +
|
|
87
|
+
CLI_CONTENT_OPERATIONS.length,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('includes required descriptor fields on every operation', () => {
|
|
92
|
+
for (const operation of listOperations()) {
|
|
93
|
+
for (const field of requiredFields(operation)) {
|
|
94
|
+
expect(field).toBeTruthy();
|
|
95
|
+
}
|
|
96
|
+
if (operation.agentExposure === 'agent') {
|
|
97
|
+
expect(operation.mcp !== undefined || operation.cli !== undefined).toBe(true);
|
|
98
|
+
}
|
|
99
|
+
expect(operation.profiles.length).toBeGreaterThan(0);
|
|
100
|
+
expect(
|
|
101
|
+
operation.http.path.startsWith('/api/v1/') || operation.http.path.startsWith('/api/v2/'),
|
|
102
|
+
).toBe(true);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('assigns idempotentHint correctly for read and destructive agent operations', () => {
|
|
107
|
+
for (const operation of listOperations()) {
|
|
108
|
+
if (operation.mcp === undefined) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const { annotations } = operation.mcp;
|
|
112
|
+
if (operation.authorization.safetyImpact === 'read') {
|
|
113
|
+
expect(annotations.readOnlyHint).toBe(true);
|
|
114
|
+
}
|
|
115
|
+
if (operation.authorization.safetyImpact === 'write-destructive') {
|
|
116
|
+
expect(annotations.destructiveHint).toBe(true);
|
|
117
|
+
expect(annotations.idempotentHint).toBe(false);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('exposes profile filters for all capability profiles', () => {
|
|
123
|
+
for (const profile of ALL_PROFILES) {
|
|
124
|
+
const operations = getOperationsByProfile(profile);
|
|
125
|
+
expect(operations.length).toBeGreaterThan(0);
|
|
126
|
+
for (const operation of operations) {
|
|
127
|
+
expect(operation.profiles).toContain(profile);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('maps agent CRUD to core-lifecycle profile', () => {
|
|
133
|
+
const crudIds = [
|
|
134
|
+
'ai-agents.project.agents.list',
|
|
135
|
+
'ai-agents.project.agents.get',
|
|
136
|
+
'ai-agents.project.agents.create',
|
|
137
|
+
'ai-agents.project.agents.update',
|
|
138
|
+
'ai-agents.project.agents.delete',
|
|
139
|
+
];
|
|
140
|
+
for (const id of crudIds) {
|
|
141
|
+
const operation = getOperation(id);
|
|
142
|
+
expect(operation?.profiles).toContain('core-lifecycle');
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('maps thread start and continue to conversations profile', () => {
|
|
147
|
+
expect(getOperation('ai-agents.project.threads.start')?.profiles).toContain('conversations');
|
|
148
|
+
expect(getOperation('ai-agents.project.threads.continue')?.profiles).toContain('conversations');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('documents multi-step workflow for thread start', () => {
|
|
152
|
+
const operation = getOperation('ai-agents.project.threads.start');
|
|
153
|
+
expect(operation?.http.path).toBe(
|
|
154
|
+
'/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads',
|
|
155
|
+
);
|
|
156
|
+
expect(operation?.cli?.commandPath).toBe('agents threads start');
|
|
157
|
+
expect(operation?.workflow).toHaveLength(3);
|
|
158
|
+
const lastStep = operation?.workflow?.[operation.workflow.length - 1];
|
|
159
|
+
expect(lastStep?.path).toContain('/generate');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('documents multi-step workflow for thread continue', () => {
|
|
163
|
+
const operation = getOperation('ai-agents.project.threads.continue');
|
|
164
|
+
expect(operation?.workflow).toHaveLength(2);
|
|
165
|
+
expect(operation?.workflow?.[0]?.path).toContain('/messages');
|
|
166
|
+
expect(operation?.workflow?.[1]?.path).toContain('/generate');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('maps evaluation lifecycle operations to evaluations profile', () => {
|
|
170
|
+
const evalIds = [
|
|
171
|
+
'ai-agents.project.evaluations.create',
|
|
172
|
+
'ai-agents.project.evaluations.append',
|
|
173
|
+
'ai-agents.project.evaluations.run',
|
|
174
|
+
'ai-agents.project.evaluations.runs.list',
|
|
175
|
+
];
|
|
176
|
+
for (const id of evalIds) {
|
|
177
|
+
expect(getOperation(id)?.profiles).toContain('evaluations');
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('returns undefined for unknown operation id', () => {
|
|
182
|
+
expect(getOperation('ai-agents.unknown.operation')).toBeUndefined();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('filters operations by profile with empty result for unknown profile usage', () => {
|
|
186
|
+
const ops = getOperationsByProfile('core-lifecycle');
|
|
187
|
+
expect(ops.every((op) => op.profiles.includes('core-lifecycle'))).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('registers users.members.delete as client-only', () => {
|
|
191
|
+
const operation = getOperation('users.members.delete');
|
|
192
|
+
expect(operation?.agentExposure).toBe('client-only');
|
|
193
|
+
expect(operation?.mcp).toBeUndefined();
|
|
194
|
+
expect(operation?.cli).toBeUndefined();
|
|
195
|
+
expect(operation?.bannedMcpToolName).toBe('delete_member');
|
|
196
|
+
expect(operation?.http.path).toBe('/api/v1/org/user/{userUuid}');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('excludes client-only operations from profile discovery catalogs', () => {
|
|
200
|
+
for (const profile of ALL_PROFILES) {
|
|
201
|
+
for (const operation of getOperationsByProfile(profile)) {
|
|
202
|
+
expect(operation.agentExposure).not.toBe('client-only');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
expect(getOperation('users.members.delete')).toBeDefined();
|
|
206
|
+
expect(
|
|
207
|
+
getOperationsByProfile('discovery-readonly').some((op) => op.id === 'users.members.delete'),
|
|
208
|
+
).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('keeps discovery-readonly profile operations read-only', () => {
|
|
212
|
+
for (const operation of getOperationsByProfile('discovery-readonly')) {
|
|
213
|
+
expect(operation.authorization.safetyImpact).toBe('read');
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('never exposes client-only operations on MCP', () => {
|
|
218
|
+
for (const operation of listOperations()) {
|
|
219
|
+
if (operation.agentExposure === 'client-only') {
|
|
220
|
+
expect(operation.mcp).toBeUndefined();
|
|
221
|
+
expect(operation.cli).toBeUndefined();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('rejects descriptors whose safetyImpact disagrees with MCP annotations', () => {
|
|
227
|
+
expect(() =>
|
|
228
|
+
defineOperation({
|
|
229
|
+
id: 'test.invalid-impact',
|
|
230
|
+
summary: 'Invalid impact pairing',
|
|
231
|
+
http: { method: 'GET', path: '/api/v1/test' },
|
|
232
|
+
authorization: { safetyImpact: 'write-destructive' },
|
|
233
|
+
sensitivity: 'none',
|
|
234
|
+
mcp: {
|
|
235
|
+
toolName: 'test_tool',
|
|
236
|
+
annotations: {
|
|
237
|
+
readOnlyHint: true,
|
|
238
|
+
destructiveHint: false,
|
|
239
|
+
idempotentHint: true,
|
|
240
|
+
openWorldHint: false,
|
|
241
|
+
},
|
|
242
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
243
|
+
},
|
|
244
|
+
cli: { commandPath: 'test' },
|
|
245
|
+
agentExposure: 'agent',
|
|
246
|
+
profiles: ['discovery-readonly'],
|
|
247
|
+
}),
|
|
248
|
+
).toThrow(/authorization\.safetyImpact/);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central operation catalog — aggregates domain modules and exposes lookup helpers.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AI_AGENT_OPERATIONS } from './ai-agents';
|
|
6
|
+
import { CLI_CONTENT_OPERATIONS } from './cli-content';
|
|
7
|
+
import { CONTENT_DEVELOPER_OPERATIONS } from './content-developer';
|
|
8
|
+
import { CONTENT_GOVERNANCE_OPERATIONS } from './content-governance';
|
|
9
|
+
import { CONTENT_READER_OPERATIONS } from './content-reader';
|
|
10
|
+
import { ORGANIZATION_AUDIT_OPERATIONS } from './organization-audit';
|
|
11
|
+
import { SEMANTIC_LAYER_OPERATIONS } from './semantic-layer';
|
|
12
|
+
import { USER_OPERATIONS } from './users';
|
|
13
|
+
|
|
14
|
+
import type { CapabilityProfile, OperationDescriptor } from './types';
|
|
15
|
+
|
|
16
|
+
const AGENT_EXPOSURE_CLIENT_ONLY = 'client-only' as const;
|
|
17
|
+
|
|
18
|
+
const ALL_OPERATIONS: readonly OperationDescriptor[] = [
|
|
19
|
+
...AI_AGENT_OPERATIONS,
|
|
20
|
+
...USER_OPERATIONS,
|
|
21
|
+
...SEMANTIC_LAYER_OPERATIONS,
|
|
22
|
+
...ORGANIZATION_AUDIT_OPERATIONS,
|
|
23
|
+
...CONTENT_READER_OPERATIONS,
|
|
24
|
+
...CONTENT_DEVELOPER_OPERATIONS,
|
|
25
|
+
...CONTENT_GOVERNANCE_OPERATIONS,
|
|
26
|
+
...CLI_CONTENT_OPERATIONS,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const operationsById = new Map<string, OperationDescriptor>(
|
|
30
|
+
ALL_OPERATIONS.map((operation) => [operation.id, operation]),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (operationsById.size !== ALL_OPERATIONS.length) {
|
|
34
|
+
const seen = new Set<string>();
|
|
35
|
+
const duplicates: string[] = [];
|
|
36
|
+
for (const operation of ALL_OPERATIONS) {
|
|
37
|
+
if (seen.has(operation.id)) {
|
|
38
|
+
duplicates.push(operation.id);
|
|
39
|
+
}
|
|
40
|
+
seen.add(operation.id);
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Duplicate operation ids in registry: ${duplicates.join(', ')}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const operationsByMcpToolName = new Map<string, OperationDescriptor>();
|
|
46
|
+
for (const operation of ALL_OPERATIONS) {
|
|
47
|
+
if (operation.agentExposure === AGENT_EXPOSURE_CLIENT_ONLY || operation.mcp === undefined) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// Index only exposed tools so lookups match registerToolsByIds / schema honesty.
|
|
51
|
+
if (!operation.mcp.taskSupport.exposed) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const toolName = operation.mcp.toolName;
|
|
55
|
+
if (operationsByMcpToolName.has(toolName)) {
|
|
56
|
+
throw new Error(`Duplicate MCP toolName in operation catalog: ${toolName}`);
|
|
57
|
+
}
|
|
58
|
+
operationsByMcpToolName.set(toolName, operation);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const EXPOSED_MCP_TOOL_NAMES: readonly string[] = ALL_OPERATIONS.filter(
|
|
62
|
+
(operation) =>
|
|
63
|
+
operation.agentExposure === 'agent' &&
|
|
64
|
+
operation.mcp !== undefined &&
|
|
65
|
+
operation.mcp.taskSupport.exposed,
|
|
66
|
+
).map((operation) => {
|
|
67
|
+
const mcp = operation.mcp;
|
|
68
|
+
if (mcp === undefined) {
|
|
69
|
+
throw new Error(`Invariant: exposed filter retained operation without mcp (${operation.id})`);
|
|
70
|
+
}
|
|
71
|
+
return mcp.toolName;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const BANNED_MCP_TOOL_NAMES: readonly string[] = ALL_OPERATIONS.filter(
|
|
75
|
+
(operation) =>
|
|
76
|
+
operation.agentExposure === AGENT_EXPOSURE_CLIENT_ONLY &&
|
|
77
|
+
typeof operation.bannedMcpToolName === 'string' &&
|
|
78
|
+
operation.bannedMcpToolName.trim().length > 0,
|
|
79
|
+
).map((operation) => {
|
|
80
|
+
const banned = operation.bannedMcpToolName;
|
|
81
|
+
if (banned === undefined) {
|
|
82
|
+
throw new Error(`Invariant: banned filter retained operation without name (${operation.id})`);
|
|
83
|
+
}
|
|
84
|
+
return banned;
|
|
85
|
+
});
|
|
86
|
+
/** Returns a registered operation by id, or undefined when not found. */
|
|
87
|
+
export function getOperation(id: string): OperationDescriptor | undefined {
|
|
88
|
+
return operationsById.get(id);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Returns the agent operation registered for an MCP tool name (sans prefix), if any. */
|
|
92
|
+
export function getOperationByMcpToolName(toolName: string): OperationDescriptor | undefined {
|
|
93
|
+
return operationsByMcpToolName.get(toolName);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Returns every registered operation descriptor. */
|
|
97
|
+
export function listOperations(): readonly OperationDescriptor[] {
|
|
98
|
+
return ALL_OPERATIONS;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Returns agent-surface operations that include the given capability profile. */
|
|
102
|
+
export function getOperationsByProfile(profile: CapabilityProfile): readonly OperationDescriptor[] {
|
|
103
|
+
return ALL_OPERATIONS.filter(
|
|
104
|
+
(operation) =>
|
|
105
|
+
operation.agentExposure !== 'client-only' && operation.profiles.includes(profile),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** MCP tool names (sans prefix) with `mcp.taskSupport.exposed === true`. */
|
|
110
|
+
export function listExposedMcpToolNames(): readonly string[] {
|
|
111
|
+
return EXPOSED_MCP_TOOL_NAMES;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** MCP tool names that must never be registered (client-only denylist). */
|
|
115
|
+
export function listBannedMcpToolNames(): readonly string[] {
|
|
116
|
+
return BANNED_MCP_TOOL_NAMES;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Exposed MCP tool names for a capability profile (persona allowlist source). */
|
|
120
|
+
export function listMcpToolNamesByProfile(profile: CapabilityProfile): readonly string[] {
|
|
121
|
+
return getOperationsByProfile(profile).flatMap((operation) => {
|
|
122
|
+
const mcp = operation.mcp;
|
|
123
|
+
if (mcp === undefined || mcp.taskSupport.exposed !== true) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
return [mcp.toolName];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic-layer MCP/CLI operations in the shared operation catalog (ADR-0013).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { READ_ONLY_DEFAULT } from '../safety';
|
|
6
|
+
|
|
7
|
+
import { defineOperation } from './types';
|
|
8
|
+
|
|
9
|
+
import type { CapabilityProfile, OperationDescriptor } from './types';
|
|
10
|
+
|
|
11
|
+
const PROFILE_SEMANTIC: CapabilityProfile = 'semantic-discovery';
|
|
12
|
+
const API_V1 = '/api/v1';
|
|
13
|
+
|
|
14
|
+
const listProjects = defineOperation({
|
|
15
|
+
id: 'semantic.projects.list',
|
|
16
|
+
summary: 'List organization projects (or pinned project when HTTP pin is set)',
|
|
17
|
+
http: { method: 'GET', path: `${API_V1}/org/projects` },
|
|
18
|
+
authorization: { safetyImpact: 'read' },
|
|
19
|
+
sensitivity: 'secret.connection',
|
|
20
|
+
mcp: {
|
|
21
|
+
toolName: 'list_projects',
|
|
22
|
+
annotations: READ_ONLY_DEFAULT,
|
|
23
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
24
|
+
},
|
|
25
|
+
cli: { commandPath: 'projects list' },
|
|
26
|
+
profiles: [PROFILE_SEMANTIC],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const getProject = defineOperation({
|
|
30
|
+
id: 'semantic.projects.get',
|
|
31
|
+
summary: 'Get a project by UUID (connection secrets omitted on MCP)',
|
|
32
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}` },
|
|
33
|
+
authorization: { safetyImpact: 'read' },
|
|
34
|
+
sensitivity: 'secret.connection',
|
|
35
|
+
mcp: {
|
|
36
|
+
toolName: 'get_project',
|
|
37
|
+
annotations: READ_ONLY_DEFAULT,
|
|
38
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
39
|
+
},
|
|
40
|
+
cli: { commandPath: 'projects get' },
|
|
41
|
+
profiles: [PROFILE_SEMANTIC, 'content-reader', 'content-developer'],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const listExplores = defineOperation({
|
|
45
|
+
id: 'semantic.explores.list',
|
|
46
|
+
summary: 'List explores in a project',
|
|
47
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores` },
|
|
48
|
+
authorization: { safetyImpact: 'read' },
|
|
49
|
+
sensitivity: 'none',
|
|
50
|
+
mcp: {
|
|
51
|
+
toolName: 'list_explores',
|
|
52
|
+
annotations: READ_ONLY_DEFAULT,
|
|
53
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
54
|
+
},
|
|
55
|
+
cli: { commandPath: 'projects explores list' },
|
|
56
|
+
profiles: [PROFILE_SEMANTIC],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const getExplore = defineOperation({
|
|
60
|
+
id: 'semantic.explores.get',
|
|
61
|
+
summary: 'Get a full explore definition',
|
|
62
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
|
|
63
|
+
authorization: { safetyImpact: 'read' },
|
|
64
|
+
sensitivity: 'none',
|
|
65
|
+
mcp: {
|
|
66
|
+
toolName: 'get_explore',
|
|
67
|
+
annotations: READ_ONLY_DEFAULT,
|
|
68
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
69
|
+
},
|
|
70
|
+
cli: { commandPath: 'projects explores get' },
|
|
71
|
+
profiles: [PROFILE_SEMANTIC],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const listDimensions = defineOperation({
|
|
75
|
+
id: 'semantic.explores.list_dimensions',
|
|
76
|
+
summary: 'List dimensions for an explore (derived from get explore)',
|
|
77
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
|
|
78
|
+
authorization: { safetyImpact: 'read' },
|
|
79
|
+
sensitivity: 'none',
|
|
80
|
+
mcp: {
|
|
81
|
+
toolName: 'list_dimensions',
|
|
82
|
+
annotations: READ_ONLY_DEFAULT,
|
|
83
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
84
|
+
},
|
|
85
|
+
cli: { commandPath: 'projects explores dimensions' },
|
|
86
|
+
profiles: [PROFILE_SEMANTIC],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const getFieldLineage = defineOperation({
|
|
90
|
+
id: 'semantic.explores.get_field_lineage',
|
|
91
|
+
summary: 'Get field lineage for an explore field (derived from get explore)',
|
|
92
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
|
|
93
|
+
authorization: { safetyImpact: 'read' },
|
|
94
|
+
sensitivity: 'none',
|
|
95
|
+
mcp: {
|
|
96
|
+
toolName: 'get_field_lineage',
|
|
97
|
+
annotations: READ_ONLY_DEFAULT,
|
|
98
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
99
|
+
},
|
|
100
|
+
cli: { commandPath: 'projects explores lineage' },
|
|
101
|
+
profiles: [PROFILE_SEMANTIC],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const listMetrics = defineOperation({
|
|
105
|
+
id: 'semantic.metrics.list',
|
|
106
|
+
summary: 'List metrics in the project data catalog',
|
|
107
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/dataCatalog/metrics` },
|
|
108
|
+
authorization: { safetyImpact: 'read' },
|
|
109
|
+
sensitivity: 'none',
|
|
110
|
+
mcp: {
|
|
111
|
+
toolName: 'list_metrics',
|
|
112
|
+
annotations: READ_ONLY_DEFAULT,
|
|
113
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
114
|
+
},
|
|
115
|
+
cli: { commandPath: 'metrics list' },
|
|
116
|
+
profiles: [PROFILE_SEMANTIC],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const getMetric = defineOperation({
|
|
120
|
+
id: 'semantic.metrics.get',
|
|
121
|
+
summary: 'Get a metric from the project data catalog',
|
|
122
|
+
http: {
|
|
123
|
+
method: 'GET',
|
|
124
|
+
path: `${API_V1}/projects/{projectUuid}/dataCatalog/metrics/{tableName}/{metricName}`,
|
|
125
|
+
},
|
|
126
|
+
authorization: { safetyImpact: 'read' },
|
|
127
|
+
sensitivity: 'none',
|
|
128
|
+
mcp: {
|
|
129
|
+
toolName: 'get_metric',
|
|
130
|
+
annotations: READ_ONLY_DEFAULT,
|
|
131
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
132
|
+
},
|
|
133
|
+
cli: { commandPath: 'metrics get' },
|
|
134
|
+
profiles: [PROFILE_SEMANTIC],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const compileQuery = defineOperation({
|
|
138
|
+
id: 'semantic.query.compile',
|
|
139
|
+
summary: 'Compile a metric query to SQL without executing warehouse rows',
|
|
140
|
+
http: {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}/compileQuery`,
|
|
143
|
+
},
|
|
144
|
+
authorization: { safetyImpact: 'read' },
|
|
145
|
+
sensitivity: 'none',
|
|
146
|
+
mcp: {
|
|
147
|
+
toolName: 'compile_query',
|
|
148
|
+
annotations: READ_ONLY_DEFAULT,
|
|
149
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
150
|
+
},
|
|
151
|
+
cli: { commandPath: 'query compile' },
|
|
152
|
+
profiles: [PROFILE_SEMANTIC],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/** Semantic-layer operations registered in the shared operation catalog. */
|
|
156
|
+
export const SEMANTIC_LAYER_OPERATIONS: readonly OperationDescriptor[] = [
|
|
157
|
+
listProjects,
|
|
158
|
+
getProject,
|
|
159
|
+
listExplores,
|
|
160
|
+
getExplore,
|
|
161
|
+
listDimensions,
|
|
162
|
+
getFieldLineage,
|
|
163
|
+
listMetrics,
|
|
164
|
+
getMetric,
|
|
165
|
+
compileQuery,
|
|
166
|
+
];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { defineOperation } from './types';
|
|
4
|
+
|
|
5
|
+
const baseDescriptor = {
|
|
6
|
+
id: 'test.operation',
|
|
7
|
+
summary: 'Test operation',
|
|
8
|
+
http: { method: 'GET' as const, path: '/api/v1/test' },
|
|
9
|
+
authorization: { safetyImpact: 'read' as const },
|
|
10
|
+
sensitivity: 'none' as const,
|
|
11
|
+
mcp: {
|
|
12
|
+
toolName: 'test_op',
|
|
13
|
+
annotations: {
|
|
14
|
+
readOnlyHint: true,
|
|
15
|
+
destructiveHint: false,
|
|
16
|
+
idempotentHint: true,
|
|
17
|
+
openWorldHint: false,
|
|
18
|
+
},
|
|
19
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
20
|
+
},
|
|
21
|
+
cli: { commandPath: 'test op' },
|
|
22
|
+
agentExposure: 'agent' as const,
|
|
23
|
+
profiles: ['discovery-readonly' as const],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('defineOperation', () => {
|
|
27
|
+
it('accepts a valid read descriptor', () => {
|
|
28
|
+
expect(defineOperation(baseDescriptor)).toEqual({
|
|
29
|
+
...baseDescriptor,
|
|
30
|
+
agentExposure: 'agent',
|
|
31
|
+
sensitivity: 'none',
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('defaults agentExposure to agent and sensitivity to none', () => {
|
|
36
|
+
const { agentExposure, sensitivity, ...withoutDefaults } = baseDescriptor;
|
|
37
|
+
void agentExposure;
|
|
38
|
+
void sensitivity;
|
|
39
|
+
const op = defineOperation(withoutDefaults);
|
|
40
|
+
expect(op.agentExposure).toBe('agent');
|
|
41
|
+
expect(op.sensitivity).toBe('none');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('allows agent ops with mcp only', () => {
|
|
45
|
+
const { cli: _cli, ...rest } = baseDescriptor;
|
|
46
|
+
void _cli;
|
|
47
|
+
expect(defineOperation(rest).cli).toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('allows agent ops with cli only', () => {
|
|
51
|
+
const { mcp: _mcp, ...rest } = baseDescriptor;
|
|
52
|
+
void _mcp;
|
|
53
|
+
expect(defineOperation(rest).mcp).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('rejects agent ops with neither mcp nor cli', () => {
|
|
57
|
+
const { mcp: _mcp, cli: _cli, ...rest } = baseDescriptor;
|
|
58
|
+
void _mcp;
|
|
59
|
+
void _cli;
|
|
60
|
+
expect(() => defineOperation(rest)).toThrow(/require mcp and\/or cli/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('rejects empty id', () => {
|
|
64
|
+
expect(() => defineOperation({ ...baseDescriptor, id: ' ' })).toThrow(/id/);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('rejects unknown profile', () => {
|
|
68
|
+
expect(() =>
|
|
69
|
+
defineOperation({
|
|
70
|
+
...baseDescriptor,
|
|
71
|
+
profiles: ['unknown-profile' as 'discovery-readonly'],
|
|
72
|
+
}),
|
|
73
|
+
).toThrow(/unknown capability profile/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('allows read operation with idempotentHint false (transient execution)', () => {
|
|
77
|
+
const op = defineOperation({
|
|
78
|
+
...baseDescriptor,
|
|
79
|
+
mcp: {
|
|
80
|
+
...baseDescriptor.mcp,
|
|
81
|
+
annotations: { ...baseDescriptor.mcp.annotations, idempotentHint: false },
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
expect(op.mcp?.annotations.idempotentHint).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('rejects client-only operation that still has mcp', () => {
|
|
88
|
+
expect(() =>
|
|
89
|
+
defineOperation({
|
|
90
|
+
...baseDescriptor,
|
|
91
|
+
agentExposure: 'client-only',
|
|
92
|
+
}),
|
|
93
|
+
).toThrow(/must omit mcp and cli/);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('allows client-only operation with bannedMcpToolName and no mcp/cli', () => {
|
|
97
|
+
const op = defineOperation({
|
|
98
|
+
id: 'test.client-only',
|
|
99
|
+
summary: 'Client only delete',
|
|
100
|
+
http: { method: 'DELETE', path: '/api/v1/test/{id}' },
|
|
101
|
+
authorization: { safetyImpact: 'write-destructive' },
|
|
102
|
+
agentExposure: 'client-only',
|
|
103
|
+
bannedMcpToolName: 'delete_test',
|
|
104
|
+
profiles: ['discovery-readonly'],
|
|
105
|
+
});
|
|
106
|
+
expect(op.agentExposure).toBe('client-only');
|
|
107
|
+
expect(op.bannedMcpToolName).toBe('delete_test');
|
|
108
|
+
expect(op.sensitivity).toBe('none');
|
|
109
|
+
});
|
|
110
|
+
});
|