@lightdash-tools/common 0.5.0 → 0.7.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 (94) 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 +199 -0
  11. package/dist/argument-validation.test.d.ts +1 -0
  12. package/dist/argument-validation.test.js +183 -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 -1
  20. package/dist/index.js +14 -0
  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 +7 -0
  25. package/dist/operations/agent-safe.js +16 -0
  26. package/dist/operations/ai-agents.d.ts +6 -0
  27. package/dist/operations/ai-agents.js +411 -0
  28. package/dist/operations/index.d.ts +5 -0
  29. package/dist/operations/index.js +16 -0
  30. package/dist/operations/parity.test.d.ts +1 -0
  31. package/dist/operations/parity.test.js +28 -0
  32. package/dist/operations/registry.d.ts +10 -0
  33. package/dist/operations/registry.js +35 -0
  34. package/dist/operations/registry.test.d.ts +1 -0
  35. package/dist/operations/registry.test.js +196 -0
  36. package/dist/operations/types.d.ts +69 -0
  37. package/dist/operations/types.js +70 -0
  38. package/dist/operations/types.test.d.ts +1 -0
  39. package/dist/operations/types.test.js +104 -0
  40. package/dist/operations/users.d.ts +6 -0
  41. package/dist/operations/users.js +60 -0
  42. package/dist/safety.d.ts +27 -2
  43. package/dist/safety.js +52 -5
  44. package/dist/safety.test.js +217 -4
  45. package/dist/types/generated/openapi-types.d.ts +35895 -10622
  46. package/dist/types/generated/openapi-types.js +0 -1
  47. package/dist/types/lightdash-api.d.ts +1 -1
  48. package/dist/types/v1/ai-agents.d.ts +112 -3
  49. package/dist/types/v1/charts.d.ts +5 -3
  50. package/dist/types/v1/dashboards.d.ts +13 -0
  51. package/dist/types/v1/index.d.ts +45 -8
  52. package/dist/types/v1/index.js +1 -1
  53. package/dist/types/v1/lightdash-api.d.ts +107 -16
  54. package/dist/types/v1/users.d.ts +4 -0
  55. package/dist/types/v2/content.d.ts +2 -0
  56. package/dist/types/v2/content.js +8 -0
  57. package/dist/types/v2/index.d.ts +11 -9
  58. package/dist/types/v2/index.js +1 -1
  59. package/package.json +16 -3
  60. package/src/agentops/extract-yaml-project.ts +42 -0
  61. package/src/agentops/formatters.ts +52 -0
  62. package/src/agentops/snapshots.ts +56 -0
  63. package/src/agentops/types.ts +599 -0
  64. package/src/argument-validation.test.ts +270 -0
  65. package/src/argument-validation.ts +240 -0
  66. package/src/audit.test.ts +87 -0
  67. package/src/audit.ts +21 -3
  68. package/src/env.ts +9 -0
  69. package/src/index.test.ts +1 -0
  70. package/src/index.ts +16 -1
  71. package/src/input-validation.test.ts +157 -1
  72. package/src/input-validation.ts +95 -0
  73. package/src/operations/agent-safe.ts +18 -0
  74. package/src/operations/ai-agents.ts +451 -0
  75. package/src/operations/index.ts +19 -0
  76. package/src/operations/parity.test.ts +35 -0
  77. package/src/operations/registry.test.ts +219 -0
  78. package/src/operations/registry.ts +44 -0
  79. package/src/operations/types.test.ts +148 -0
  80. package/src/operations/types.ts +168 -0
  81. package/src/operations/users.ts +67 -0
  82. package/src/safety.test.ts +276 -4
  83. package/src/safety.ts +72 -4
  84. package/src/types/generated/openapi-types.ts +37017 -11241
  85. package/src/types/lightdash-api.ts +39 -0
  86. package/src/types/v1/ai-agents.ts +133 -3
  87. package/src/types/v1/charts.ts +5 -3
  88. package/src/types/v1/dashboards.ts +19 -0
  89. package/src/types/v1/index.ts +51 -8
  90. package/src/types/v1/lightdash-api.ts +129 -20
  91. package/src/types/v1/users.ts +4 -0
  92. package/src/types/v2/content.ts +8 -0
  93. package/src/types/v2/index.ts +11 -9
  94. package/tsconfig.json +1 -0
@@ -0,0 +1,219 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { AI_AGENT_OPERATIONS } from './ai-agents';
4
+ import { getOperation, getOperationsByProfile, listOperations } from './registry';
5
+ import { defineOperation } from './types';
6
+ import { USER_OPERATIONS } from './users';
7
+
8
+ import type { CapabilityProfile, OperationDescriptor } from './types';
9
+
10
+ const P0_OPERATION_IDS = [
11
+ 'ai-agents.admin.agents.list',
12
+ 'ai-agents.admin.settings.get',
13
+ 'ai-agents.admin.settings.update',
14
+ 'ai-agents.project.agents.list',
15
+ 'ai-agents.project.agents.get',
16
+ 'ai-agents.project.agents.create',
17
+ 'ai-agents.project.agents.update',
18
+ 'ai-agents.project.agents.delete',
19
+ 'ai-agents.project.threads.start',
20
+ 'ai-agents.project.threads.continue',
21
+ 'ai-agents.project.evaluations.list',
22
+ 'ai-agents.project.evaluations.get',
23
+ 'ai-agents.project.evaluations.create',
24
+ 'ai-agents.project.evaluations.update',
25
+ 'ai-agents.project.evaluations.append',
26
+ 'ai-agents.project.evaluations.delete',
27
+ 'ai-agents.project.evaluations.run',
28
+ 'ai-agents.project.evaluations.runs.list',
29
+ ] as const;
30
+
31
+ const ALL_PROFILES: CapabilityProfile[] = [
32
+ 'core-lifecycle',
33
+ 'evaluations',
34
+ 'conversations',
35
+ 'discovery-readonly',
36
+ ];
37
+
38
+ function requiredFields(operation: OperationDescriptor): string[] {
39
+ const agentExposure = operation.agentExposure ?? 'agent';
40
+ const fields = [
41
+ operation.id,
42
+ operation.summary,
43
+ operation.http.method,
44
+ operation.http.path,
45
+ operation.authorization.safetyImpact,
46
+ agentExposure,
47
+ ];
48
+ if (agentExposure === 'agent') {
49
+ fields.push(operation.mcp.toolName, operation.cli.commandPath);
50
+ }
51
+ return fields;
52
+ }
53
+
54
+ describe('operation registry', () => {
55
+ it('registers all P0 operation ids', () => {
56
+ for (const id of P0_OPERATION_IDS) {
57
+ expect(getOperation(id)).toBeDefined();
58
+ }
59
+ });
60
+
61
+ it('has no duplicate operation ids', () => {
62
+ const ids = listOperations().map((operation) => operation.id);
63
+ expect(new Set(ids).size).toBe(ids.length);
64
+ });
65
+
66
+ it('matches aggregated domain export count', () => {
67
+ expect(listOperations()).toHaveLength(AI_AGENT_OPERATIONS.length + USER_OPERATIONS.length);
68
+ });
69
+
70
+ it('includes required descriptor fields on every operation', () => {
71
+ for (const operation of listOperations()) {
72
+ for (const field of requiredFields(operation)) {
73
+ expect(field).toBeTruthy();
74
+ }
75
+ expect(operation.profiles.length).toBeGreaterThan(0);
76
+ expect(operation.http.path.startsWith('/api/v1/')).toBe(true);
77
+ }
78
+ });
79
+
80
+ it('assigns idempotentHint correctly for read and destructive operations', () => {
81
+ for (const operation of listOperations()) {
82
+ const { annotations } = operation.mcp;
83
+ if (operation.authorization.safetyImpact === 'read') {
84
+ expect(annotations.idempotentHint).toBe(true);
85
+ expect(annotations.readOnlyHint).toBe(true);
86
+ }
87
+ if (operation.authorization.safetyImpact === 'write-destructive') {
88
+ expect(annotations.destructiveHint).toBe(true);
89
+ expect(annotations.idempotentHint).toBe(false);
90
+ }
91
+ }
92
+ });
93
+
94
+ it('exposes profile filters for all capability profiles', () => {
95
+ for (const profile of ALL_PROFILES) {
96
+ const operations = getOperationsByProfile(profile);
97
+ expect(operations.length).toBeGreaterThan(0);
98
+ for (const operation of operations) {
99
+ expect(operation.profiles).toContain(profile);
100
+ }
101
+ }
102
+ });
103
+
104
+ it('maps agent CRUD to core-lifecycle profile', () => {
105
+ const crudIds = [
106
+ 'ai-agents.project.agents.list',
107
+ 'ai-agents.project.agents.get',
108
+ 'ai-agents.project.agents.create',
109
+ 'ai-agents.project.agents.update',
110
+ 'ai-agents.project.agents.delete',
111
+ ];
112
+ for (const id of crudIds) {
113
+ const operation = getOperation(id);
114
+ expect(operation?.profiles).toContain('core-lifecycle');
115
+ }
116
+ });
117
+
118
+ it('maps thread start and continue to conversations profile', () => {
119
+ expect(getOperation('ai-agents.project.threads.start')?.profiles).toContain('conversations');
120
+ expect(getOperation('ai-agents.project.threads.continue')?.profiles).toContain('conversations');
121
+ });
122
+
123
+ it('documents multi-step workflow for thread start', () => {
124
+ const operation = getOperation('ai-agents.project.threads.start');
125
+ expect(operation?.http.path).toBe(
126
+ '/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads',
127
+ );
128
+ expect(operation?.cli.commandPath).toBe('agents threads start');
129
+ expect(operation?.workflow).toHaveLength(3);
130
+ const lastStep = operation?.workflow?.[operation.workflow.length - 1];
131
+ expect(lastStep?.path).toContain('/generate');
132
+ });
133
+
134
+ it('documents multi-step workflow for thread continue', () => {
135
+ const operation = getOperation('ai-agents.project.threads.continue');
136
+ expect(operation?.workflow).toHaveLength(2);
137
+ expect(operation?.workflow?.[0]?.path).toContain('/messages');
138
+ expect(operation?.workflow?.[1]?.path).toContain('/generate');
139
+ });
140
+
141
+ it('maps evaluation lifecycle operations to evaluations profile', () => {
142
+ const evalIds = [
143
+ 'ai-agents.project.evaluations.create',
144
+ 'ai-agents.project.evaluations.append',
145
+ 'ai-agents.project.evaluations.run',
146
+ 'ai-agents.project.evaluations.runs.list',
147
+ ];
148
+ for (const id of evalIds) {
149
+ expect(getOperation(id)?.profiles).toContain('evaluations');
150
+ }
151
+ });
152
+
153
+ it('returns undefined for unknown operation id', () => {
154
+ expect(getOperation('ai-agents.unknown.operation')).toBeUndefined();
155
+ });
156
+
157
+ it('filters operations by profile with empty result for unknown profile usage', () => {
158
+ const ops = getOperationsByProfile('core-lifecycle');
159
+ expect(ops.every((op) => op.profiles.includes('core-lifecycle'))).toBe(true);
160
+ });
161
+
162
+ it('registers users.members.delete as client-only', () => {
163
+ const operation = getOperation('users.members.delete');
164
+ expect(operation?.agentExposure).toBe('client-only');
165
+ expect(operation?.mcp.taskSupport.exposed).toBe(false);
166
+ expect(operation?.mcp.toolName).toBe('delete_member');
167
+ expect(operation?.http.path).toBe('/api/v1/org/user/{userUuid}');
168
+ });
169
+
170
+ it('excludes client-only operations from profile discovery catalogs', () => {
171
+ for (const profile of ALL_PROFILES) {
172
+ for (const operation of getOperationsByProfile(profile)) {
173
+ expect(operation.agentExposure).not.toBe('client-only');
174
+ }
175
+ }
176
+ expect(getOperation('users.members.delete')).toBeDefined();
177
+ expect(
178
+ getOperationsByProfile('discovery-readonly').some((op) => op.id === 'users.members.delete'),
179
+ ).toBe(false);
180
+ });
181
+
182
+ it('keeps discovery-readonly profile operations read-only', () => {
183
+ for (const operation of getOperationsByProfile('discovery-readonly')) {
184
+ expect(operation.authorization.safetyImpact).toBe('read');
185
+ }
186
+ });
187
+
188
+ it('never exposes client-only operations on MCP', () => {
189
+ for (const operation of listOperations()) {
190
+ if (operation.agentExposure === 'client-only') {
191
+ expect(operation.mcp.taskSupport.exposed).toBe(false);
192
+ }
193
+ }
194
+ });
195
+
196
+ it('rejects descriptors whose safetyImpact disagrees with MCP annotations', () => {
197
+ expect(() =>
198
+ defineOperation({
199
+ id: 'test.invalid-impact',
200
+ summary: 'Invalid impact pairing',
201
+ http: { method: 'GET', path: '/api/v1/test' },
202
+ authorization: { safetyImpact: 'write-destructive' },
203
+ mcp: {
204
+ toolName: 'test_tool',
205
+ annotations: {
206
+ readOnlyHint: true,
207
+ destructiveHint: false,
208
+ idempotentHint: true,
209
+ openWorldHint: false,
210
+ },
211
+ taskSupport: { exposed: true, taskEligible: false },
212
+ },
213
+ cli: { commandPath: 'test' },
214
+ agentExposure: 'agent',
215
+ profiles: ['discovery-readonly'],
216
+ }),
217
+ ).toThrow(/authorization\.safetyImpact/);
218
+ });
219
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Central operation registry — aggregates domain modules and exposes lookup helpers.
3
+ */
4
+
5
+ import { AI_AGENT_OPERATIONS } from './ai-agents';
6
+ import { USER_OPERATIONS } from './users';
7
+
8
+ import type { CapabilityProfile, OperationDescriptor } from './types';
9
+
10
+ const ALL_OPERATIONS: readonly OperationDescriptor[] = [...AI_AGENT_OPERATIONS, ...USER_OPERATIONS];
11
+
12
+ const operationsById = new Map<string, OperationDescriptor>(
13
+ ALL_OPERATIONS.map((operation) => [operation.id, operation]),
14
+ );
15
+
16
+ if (operationsById.size !== ALL_OPERATIONS.length) {
17
+ const seen = new Set<string>();
18
+ const duplicates: string[] = [];
19
+ for (const operation of ALL_OPERATIONS) {
20
+ if (seen.has(operation.id)) {
21
+ duplicates.push(operation.id);
22
+ }
23
+ seen.add(operation.id);
24
+ }
25
+ throw new Error(`Duplicate operation ids in registry: ${duplicates.join(', ')}`);
26
+ }
27
+
28
+ /** Returns a registered operation by id, or undefined when not found. */
29
+ export function getOperation(id: string): OperationDescriptor | undefined {
30
+ return operationsById.get(id);
31
+ }
32
+
33
+ /** Returns every registered operation descriptor. */
34
+ export function listOperations(): readonly OperationDescriptor[] {
35
+ return ALL_OPERATIONS;
36
+ }
37
+
38
+ /** Returns agent-surface operations that include the given capability profile. */
39
+ export function getOperationsByProfile(profile: CapabilityProfile): readonly OperationDescriptor[] {
40
+ return ALL_OPERATIONS.filter(
41
+ (operation) =>
42
+ operation.agentExposure !== 'client-only' && operation.profiles.includes(profile),
43
+ );
44
+ }
@@ -0,0 +1,148 @@
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
+ mcp: {
11
+ toolName: 'test_op',
12
+ annotations: {
13
+ readOnlyHint: true,
14
+ destructiveHint: false,
15
+ idempotentHint: true,
16
+ openWorldHint: false,
17
+ },
18
+ taskSupport: { exposed: true, taskEligible: false },
19
+ },
20
+ cli: { commandPath: 'test op' },
21
+ agentExposure: 'agent' as const,
22
+ profiles: ['discovery-readonly' as const],
23
+ };
24
+
25
+ describe('defineOperation', () => {
26
+ it('accepts a valid read descriptor', () => {
27
+ expect(defineOperation(baseDescriptor)).toEqual({
28
+ ...baseDescriptor,
29
+ agentExposure: 'agent',
30
+ });
31
+ });
32
+
33
+ it('defaults agentExposure to agent', () => {
34
+ const { agentExposure, ...withoutExposure } = baseDescriptor;
35
+ void agentExposure;
36
+ expect(defineOperation(withoutExposure).agentExposure).toBe('agent');
37
+ });
38
+
39
+ it('rejects empty id', () => {
40
+ expect(() => defineOperation({ ...baseDescriptor, id: ' ' })).toThrow(/id/);
41
+ });
42
+
43
+ it('rejects empty summary', () => {
44
+ expect(() => defineOperation({ ...baseDescriptor, summary: '' })).toThrow(/summary/);
45
+ });
46
+
47
+ it('rejects empty http path', () => {
48
+ expect(() => defineOperation({ ...baseDescriptor, http: { method: 'GET', path: '' } })).toThrow(
49
+ /http.path/,
50
+ );
51
+ });
52
+
53
+ it('rejects empty profiles', () => {
54
+ expect(() => defineOperation({ ...baseDescriptor, profiles: [] })).toThrow(/profile/);
55
+ });
56
+
57
+ it('rejects unknown profile', () => {
58
+ expect(() =>
59
+ defineOperation({
60
+ ...baseDescriptor,
61
+ profiles: ['unknown-profile' as 'discovery-readonly'],
62
+ }),
63
+ ).toThrow(/unknown capability profile/);
64
+ });
65
+
66
+ it('rejects read operation without idempotentHint', () => {
67
+ expect(() =>
68
+ defineOperation({
69
+ ...baseDescriptor,
70
+ mcp: {
71
+ ...baseDescriptor.mcp,
72
+ annotations: { ...baseDescriptor.mcp.annotations, idempotentHint: false },
73
+ },
74
+ }),
75
+ ).toThrow(/idempotentHint/);
76
+ });
77
+
78
+ it('rejects destructive operation with idempotentHint true', () => {
79
+ expect(() =>
80
+ defineOperation({
81
+ ...baseDescriptor,
82
+ authorization: { safetyImpact: 'write-destructive' },
83
+ mcp: {
84
+ ...baseDescriptor.mcp,
85
+ annotations: {
86
+ readOnlyHint: false,
87
+ destructiveHint: true,
88
+ idempotentHint: true,
89
+ openWorldHint: false,
90
+ },
91
+ },
92
+ }),
93
+ ).toThrow(/destructive operations/);
94
+ });
95
+
96
+ it('rejects client-only operation with mcp exposed', () => {
97
+ expect(() =>
98
+ defineOperation({
99
+ ...baseDescriptor,
100
+ agentExposure: 'client-only',
101
+ mcp: {
102
+ ...baseDescriptor.mcp,
103
+ taskSupport: { exposed: true, taskEligible: false },
104
+ },
105
+ }),
106
+ ).toThrow(/client-only operations must set mcp.taskSupport.exposed to false/);
107
+ });
108
+
109
+ it('allows client-only operation without mcp tool name or cli path', () => {
110
+ const op = defineOperation({
111
+ id: 'test.client-only',
112
+ summary: 'Client only delete',
113
+ http: { method: 'DELETE', path: '/api/v1/test/{id}' },
114
+ authorization: { safetyImpact: 'write-destructive' },
115
+ mcp: {
116
+ toolName: '',
117
+ annotations: {
118
+ readOnlyHint: false,
119
+ destructiveHint: true,
120
+ idempotentHint: false,
121
+ openWorldHint: false,
122
+ },
123
+ taskSupport: { exposed: false, taskEligible: false },
124
+ },
125
+ cli: { commandPath: '' },
126
+ agentExposure: 'client-only',
127
+ profiles: ['discovery-readonly'],
128
+ });
129
+ expect(op.agentExposure).toBe('client-only');
130
+ });
131
+
132
+ it('maps openWorldHint to external-side-effect impact', () => {
133
+ const op = defineOperation({
134
+ ...baseDescriptor,
135
+ authorization: { safetyImpact: 'external-side-effect' },
136
+ mcp: {
137
+ ...baseDescriptor.mcp,
138
+ annotations: {
139
+ readOnlyHint: false,
140
+ destructiveHint: false,
141
+ idempotentHint: false,
142
+ openWorldHint: true,
143
+ },
144
+ },
145
+ });
146
+ expect(op.authorization.safetyImpact).toBe('external-side-effect');
147
+ });
148
+ });
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Shared typed operation registry (RFC Section 7).
3
+ * Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
4
+ */
5
+
6
+ import type { SafetyImpact, ToolAnnotations } from '../safety';
7
+
8
+ export type { SafetyImpact };
9
+
10
+ /** Whether an operation may appear on MCP/CLI agent surfaces. */
11
+ export type AgentExposure = 'agent' | 'client-only';
12
+
13
+ /** HTTP verbs supported by registered operations. */
14
+ export type HttpMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
15
+
16
+ /**
17
+ * Capability profiles group operations for selective exposure (CLI profiles, MCP subsets).
18
+ */
19
+ export type CapabilityProfile =
20
+ 'conversations' | 'core-lifecycle' | 'discovery-readonly' | 'evaluations';
21
+
22
+ /** MCP task semantics for an operation. */
23
+ export type McpTaskSupport = {
24
+ /** When true, the operation is exposed as an MCP tool. */
25
+ exposed: boolean;
26
+ /**
27
+ * When true, the operation may complete asynchronously via MCP Tasks.
28
+ * Long-running evaluation runs and LLM generation are task-eligible.
29
+ */
30
+ taskEligible: boolean;
31
+ };
32
+
33
+ export type OperationAuthorization = {
34
+ safetyImpact: SafetyImpact;
35
+ };
36
+
37
+ export type OperationHttp = {
38
+ method: HttpMethod;
39
+ /** OpenAPI-style path template (includes `/api/v1` prefix). */
40
+ path: string;
41
+ };
42
+
43
+ export type OperationMcp = {
44
+ /** MCP tool name without the `lightdash_` prefix. */
45
+ toolName: string;
46
+ annotations: ToolAnnotations;
47
+ taskSupport: McpTaskSupport;
48
+ };
49
+
50
+ export type OperationCli = {
51
+ /** Space-delimited CLI command path from the root program (e.g. `agents list`). */
52
+ commandPath: string;
53
+ };
54
+
55
+ /** Optional multi-step HTTP workflow when a single registry entry orchestrates several API calls. */
56
+ export type OperationWorkflowStep = {
57
+ method: HttpMethod;
58
+ path: string;
59
+ summary: string;
60
+ };
61
+
62
+ export type OperationDescriptor = {
63
+ /** Stable dot-separated identifier (e.g. `ai-agents.project.agents.list`). */
64
+ id: string;
65
+ summary: string;
66
+ http: OperationHttp;
67
+ authorization: OperationAuthorization;
68
+ mcp: OperationMcp;
69
+ cli: OperationCli;
70
+ /** `agent` (default) = may be exposed on MCP/CLI; `client-only` = typed client only. */
71
+ agentExposure?: AgentExposure;
72
+ profiles: readonly CapabilityProfile[];
73
+ /** When set, documents the ordered client-side HTTP steps behind this operation. */
74
+ workflow?: readonly OperationWorkflowStep[];
75
+ };
76
+
77
+ const VALID_PROFILES = new Set<CapabilityProfile>([
78
+ 'conversations',
79
+ 'core-lifecycle',
80
+ 'discovery-readonly',
81
+ 'evaluations',
82
+ ]);
83
+
84
+ function assertNonEmpty(value: string, field: string): void {
85
+ if (value.trim().length === 0) {
86
+ throw new Error(`Operation ${field} must be a non-empty string`);
87
+ }
88
+ }
89
+
90
+ function expectedImpactFromAnnotations(annotations: ToolAnnotations): SafetyImpact {
91
+ if (annotations.readOnlyHint) {
92
+ return 'read';
93
+ }
94
+ if (annotations.destructiveHint) {
95
+ return 'write-destructive';
96
+ }
97
+ if (annotations.openWorldHint) {
98
+ return 'external-side-effect';
99
+ }
100
+ return 'write-nondestructive';
101
+ }
102
+
103
+ function validateIdempotentHint(
104
+ annotations: ToolAnnotations,
105
+ impact: SafetyImpact,
106
+ id: string,
107
+ ): void {
108
+ if (impact === 'read' && annotations.idempotentHint !== true) {
109
+ throw new Error(
110
+ `Operation '${id}': read operations must set mcp.annotations.idempotentHint = true`,
111
+ );
112
+ }
113
+ if (impact === 'write-destructive' && annotations.idempotentHint === true) {
114
+ throw new Error(
115
+ `Operation '${id}': destructive operations must not set mcp.annotations.idempotentHint = true`,
116
+ );
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Defines a typed operation descriptor with RFC consistency checks.
122
+ * Throws when authorization impact disagrees with MCP annotations or profiles are invalid.
123
+ */
124
+ export function defineOperation<T extends OperationDescriptor>(
125
+ descriptor: T,
126
+ ): T & { agentExposure: AgentExposure } {
127
+ assertNonEmpty(descriptor.id, 'id');
128
+ assertNonEmpty(descriptor.summary, 'summary');
129
+ assertNonEmpty(descriptor.http.path, 'http.path');
130
+
131
+ const agentExposure = descriptor.agentExposure ?? 'agent';
132
+
133
+ if (agentExposure === 'agent') {
134
+ assertNonEmpty(descriptor.mcp.toolName, 'mcp.toolName');
135
+ assertNonEmpty(descriptor.cli.commandPath, 'cli.commandPath');
136
+ }
137
+
138
+ if (agentExposure === 'client-only' && descriptor.mcp.taskSupport.exposed) {
139
+ throw new Error(
140
+ `Operation '${descriptor.id}': client-only operations must set mcp.taskSupport.exposed to false`,
141
+ );
142
+ }
143
+
144
+ if (descriptor.profiles.length === 0) {
145
+ throw new Error(`Operation '${descriptor.id}' must declare at least one capability profile`);
146
+ }
147
+
148
+ for (const profile of descriptor.profiles) {
149
+ if (!VALID_PROFILES.has(profile)) {
150
+ throw new Error(`Operation '${descriptor.id}' has unknown capability profile '${profile}'`);
151
+ }
152
+ }
153
+
154
+ const expectedImpact = expectedImpactFromAnnotations(descriptor.mcp.annotations);
155
+ if (descriptor.authorization.safetyImpact !== expectedImpact) {
156
+ throw new Error(
157
+ `Operation '${descriptor.id}': authorization.safetyImpact is '${descriptor.authorization.safetyImpact}' but MCP annotations imply '${expectedImpact}'`,
158
+ );
159
+ }
160
+
161
+ validateIdempotentHint(
162
+ descriptor.mcp.annotations,
163
+ descriptor.authorization.safetyImpact,
164
+ descriptor.id,
165
+ );
166
+
167
+ return { ...descriptor, agentExposure };
168
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Organization member operations in the shared operation registry.
3
+ */
4
+
5
+ import { READ_ONLY_DEFAULT, WRITE_DESTRUCTIVE } from '../safety';
6
+
7
+ import { defineOperation } from './types';
8
+
9
+ import type { CapabilityProfile, OperationDescriptor } from './types';
10
+
11
+ const PROFILE_DISCOVERY: CapabilityProfile = 'discovery-readonly';
12
+ const PROFILE_CORE_LIFECYCLE: CapabilityProfile = 'core-lifecycle';
13
+
14
+ const API_V1 = '/api/v1';
15
+ const MEMBERS_PATH = `${API_V1}/org/users`;
16
+ const MEMBER_PATH = `${MEMBERS_PATH}/{userUuid}`;
17
+ const DELETE_MEMBER_PATH = `${API_V1}/org/user/{userUuid}`;
18
+
19
+ const membersList = defineOperation({
20
+ id: 'users.members.list',
21
+ summary: 'List organization members (one page)',
22
+ http: { method: 'GET', path: MEMBERS_PATH },
23
+ authorization: { safetyImpact: 'read' },
24
+ mcp: {
25
+ toolName: 'list_organization_members',
26
+ annotations: READ_ONLY_DEFAULT,
27
+ taskSupport: { exposed: true, taskEligible: false },
28
+ },
29
+ cli: { commandPath: 'users list' },
30
+ profiles: [PROFILE_DISCOVERY],
31
+ });
32
+
33
+ const membersGet = defineOperation({
34
+ id: 'users.members.get',
35
+ summary: 'Get an organization member by UUID',
36
+ http: { method: 'GET', path: MEMBER_PATH },
37
+ authorization: { safetyImpact: 'read' },
38
+ mcp: {
39
+ toolName: 'get_member',
40
+ annotations: READ_ONLY_DEFAULT,
41
+ taskSupport: { exposed: true, taskEligible: false },
42
+ },
43
+ cli: { commandPath: 'users get' },
44
+ profiles: [PROFILE_DISCOVERY],
45
+ });
46
+
47
+ const membersDelete = defineOperation({
48
+ id: 'users.members.delete',
49
+ summary: 'Permanently remove a user from the organization (irrecoverable; client-only)',
50
+ http: { method: 'DELETE', path: DELETE_MEMBER_PATH },
51
+ authorization: { safetyImpact: 'write-destructive' },
52
+ mcp: {
53
+ toolName: 'delete_member',
54
+ annotations: WRITE_DESTRUCTIVE,
55
+ taskSupport: { exposed: false, taskEligible: false },
56
+ },
57
+ cli: { commandPath: '' },
58
+ agentExposure: 'client-only',
59
+ profiles: [PROFILE_CORE_LIFECYCLE],
60
+ });
61
+
62
+ /** Organization member operations registered in the shared operation registry. */
63
+ export const USER_OPERATIONS: readonly OperationDescriptor[] = [
64
+ membersList,
65
+ membersGet,
66
+ membersDelete,
67
+ ];