@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,196 @@
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 registry_1 = require("./registry");
6
+ const types_1 = require("./types");
7
+ const users_1 = require("./users");
8
+ const P0_OPERATION_IDS = [
9
+ 'ai-agents.admin.agents.list',
10
+ 'ai-agents.admin.settings.get',
11
+ 'ai-agents.admin.settings.update',
12
+ 'ai-agents.project.agents.list',
13
+ 'ai-agents.project.agents.get',
14
+ 'ai-agents.project.agents.create',
15
+ 'ai-agents.project.agents.update',
16
+ 'ai-agents.project.agents.delete',
17
+ 'ai-agents.project.threads.start',
18
+ 'ai-agents.project.threads.continue',
19
+ 'ai-agents.project.evaluations.list',
20
+ 'ai-agents.project.evaluations.get',
21
+ 'ai-agents.project.evaluations.create',
22
+ 'ai-agents.project.evaluations.update',
23
+ 'ai-agents.project.evaluations.append',
24
+ 'ai-agents.project.evaluations.delete',
25
+ 'ai-agents.project.evaluations.run',
26
+ 'ai-agents.project.evaluations.runs.list',
27
+ ];
28
+ const ALL_PROFILES = [
29
+ 'core-lifecycle',
30
+ 'evaluations',
31
+ 'conversations',
32
+ 'discovery-readonly',
33
+ ];
34
+ function requiredFields(operation) {
35
+ var _a;
36
+ const agentExposure = (_a = operation.agentExposure) !== null && _a !== void 0 ? _a : 'agent';
37
+ const fields = [
38
+ operation.id,
39
+ operation.summary,
40
+ operation.http.method,
41
+ operation.http.path,
42
+ operation.authorization.safetyImpact,
43
+ agentExposure,
44
+ ];
45
+ if (agentExposure === 'agent') {
46
+ fields.push(operation.mcp.toolName, operation.cli.commandPath);
47
+ }
48
+ return fields;
49
+ }
50
+ (0, vitest_1.describe)('operation registry', () => {
51
+ (0, vitest_1.it)('registers all P0 operation ids', () => {
52
+ for (const id of P0_OPERATION_IDS) {
53
+ (0, vitest_1.expect)((0, registry_1.getOperation)(id)).toBeDefined();
54
+ }
55
+ });
56
+ (0, vitest_1.it)('has no duplicate operation ids', () => {
57
+ const ids = (0, registry_1.listOperations)().map((operation) => operation.id);
58
+ (0, vitest_1.expect)(new Set(ids).size).toBe(ids.length);
59
+ });
60
+ (0, vitest_1.it)('matches aggregated domain export count', () => {
61
+ (0, vitest_1.expect)((0, registry_1.listOperations)()).toHaveLength(ai_agents_1.AI_AGENT_OPERATIONS.length + users_1.USER_OPERATIONS.length);
62
+ });
63
+ (0, vitest_1.it)('includes required descriptor fields on every operation', () => {
64
+ for (const operation of (0, registry_1.listOperations)()) {
65
+ for (const field of requiredFields(operation)) {
66
+ (0, vitest_1.expect)(field).toBeTruthy();
67
+ }
68
+ (0, vitest_1.expect)(operation.profiles.length).toBeGreaterThan(0);
69
+ (0, vitest_1.expect)(operation.http.path.startsWith('/api/v1/')).toBe(true);
70
+ }
71
+ });
72
+ (0, vitest_1.it)('assigns idempotentHint correctly for read and destructive operations', () => {
73
+ for (const operation of (0, registry_1.listOperations)()) {
74
+ const { annotations } = operation.mcp;
75
+ if (operation.authorization.safetyImpact === 'read') {
76
+ (0, vitest_1.expect)(annotations.idempotentHint).toBe(true);
77
+ (0, vitest_1.expect)(annotations.readOnlyHint).toBe(true);
78
+ }
79
+ if (operation.authorization.safetyImpact === 'write-destructive') {
80
+ (0, vitest_1.expect)(annotations.destructiveHint).toBe(true);
81
+ (0, vitest_1.expect)(annotations.idempotentHint).toBe(false);
82
+ }
83
+ }
84
+ });
85
+ (0, vitest_1.it)('exposes profile filters for all capability profiles', () => {
86
+ for (const profile of ALL_PROFILES) {
87
+ const operations = (0, registry_1.getOperationsByProfile)(profile);
88
+ (0, vitest_1.expect)(operations.length).toBeGreaterThan(0);
89
+ for (const operation of operations) {
90
+ (0, vitest_1.expect)(operation.profiles).toContain(profile);
91
+ }
92
+ }
93
+ });
94
+ (0, vitest_1.it)('maps agent CRUD to core-lifecycle profile', () => {
95
+ const crudIds = [
96
+ 'ai-agents.project.agents.list',
97
+ 'ai-agents.project.agents.get',
98
+ 'ai-agents.project.agents.create',
99
+ 'ai-agents.project.agents.update',
100
+ 'ai-agents.project.agents.delete',
101
+ ];
102
+ for (const id of crudIds) {
103
+ const operation = (0, registry_1.getOperation)(id);
104
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.profiles).toContain('core-lifecycle');
105
+ }
106
+ });
107
+ (0, vitest_1.it)('maps thread start and continue to conversations profile', () => {
108
+ var _a, _b;
109
+ (0, vitest_1.expect)((_a = (0, registry_1.getOperation)('ai-agents.project.threads.start')) === null || _a === void 0 ? void 0 : _a.profiles).toContain('conversations');
110
+ (0, vitest_1.expect)((_b = (0, registry_1.getOperation)('ai-agents.project.threads.continue')) === null || _b === void 0 ? void 0 : _b.profiles).toContain('conversations');
111
+ });
112
+ (0, vitest_1.it)('documents multi-step workflow for thread start', () => {
113
+ var _a;
114
+ const operation = (0, registry_1.getOperation)('ai-agents.project.threads.start');
115
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.http.path).toBe('/api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads');
116
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.cli.commandPath).toBe('agents threads start');
117
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.workflow).toHaveLength(3);
118
+ const lastStep = (_a = operation === null || operation === void 0 ? void 0 : operation.workflow) === null || _a === void 0 ? void 0 : _a[operation.workflow.length - 1];
119
+ (0, vitest_1.expect)(lastStep === null || lastStep === void 0 ? void 0 : lastStep.path).toContain('/generate');
120
+ });
121
+ (0, vitest_1.it)('documents multi-step workflow for thread continue', () => {
122
+ var _a, _b, _c, _d;
123
+ const operation = (0, registry_1.getOperation)('ai-agents.project.threads.continue');
124
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.workflow).toHaveLength(2);
125
+ (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');
126
+ (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');
127
+ });
128
+ (0, vitest_1.it)('maps evaluation lifecycle operations to evaluations profile', () => {
129
+ var _a;
130
+ const evalIds = [
131
+ 'ai-agents.project.evaluations.create',
132
+ 'ai-agents.project.evaluations.append',
133
+ 'ai-agents.project.evaluations.run',
134
+ 'ai-agents.project.evaluations.runs.list',
135
+ ];
136
+ for (const id of evalIds) {
137
+ (0, vitest_1.expect)((_a = (0, registry_1.getOperation)(id)) === null || _a === void 0 ? void 0 : _a.profiles).toContain('evaluations');
138
+ }
139
+ });
140
+ (0, vitest_1.it)('returns undefined for unknown operation id', () => {
141
+ (0, vitest_1.expect)((0, registry_1.getOperation)('ai-agents.unknown.operation')).toBeUndefined();
142
+ });
143
+ (0, vitest_1.it)('filters operations by profile with empty result for unknown profile usage', () => {
144
+ const ops = (0, registry_1.getOperationsByProfile)('core-lifecycle');
145
+ (0, vitest_1.expect)(ops.every((op) => op.profiles.includes('core-lifecycle'))).toBe(true);
146
+ });
147
+ (0, vitest_1.it)('registers users.members.delete as client-only', () => {
148
+ const operation = (0, registry_1.getOperation)('users.members.delete');
149
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.agentExposure).toBe('client-only');
150
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.mcp.taskSupport.exposed).toBe(false);
151
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.mcp.toolName).toBe('delete_member');
152
+ (0, vitest_1.expect)(operation === null || operation === void 0 ? void 0 : operation.http.path).toBe('/api/v1/org/user/{userUuid}');
153
+ });
154
+ (0, vitest_1.it)('excludes client-only operations from profile discovery catalogs', () => {
155
+ for (const profile of ALL_PROFILES) {
156
+ for (const operation of (0, registry_1.getOperationsByProfile)(profile)) {
157
+ (0, vitest_1.expect)(operation.agentExposure).not.toBe('client-only');
158
+ }
159
+ }
160
+ (0, vitest_1.expect)((0, registry_1.getOperation)('users.members.delete')).toBeDefined();
161
+ (0, vitest_1.expect)((0, registry_1.getOperationsByProfile)('discovery-readonly').some((op) => op.id === 'users.members.delete')).toBe(false);
162
+ });
163
+ (0, vitest_1.it)('keeps discovery-readonly profile operations read-only', () => {
164
+ for (const operation of (0, registry_1.getOperationsByProfile)('discovery-readonly')) {
165
+ (0, vitest_1.expect)(operation.authorization.safetyImpact).toBe('read');
166
+ }
167
+ });
168
+ (0, vitest_1.it)('never exposes client-only operations on MCP', () => {
169
+ for (const operation of (0, registry_1.listOperations)()) {
170
+ if (operation.agentExposure === 'client-only') {
171
+ (0, vitest_1.expect)(operation.mcp.taskSupport.exposed).toBe(false);
172
+ }
173
+ }
174
+ });
175
+ (0, vitest_1.it)('rejects descriptors whose safetyImpact disagrees with MCP annotations', () => {
176
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)({
177
+ id: 'test.invalid-impact',
178
+ summary: 'Invalid impact pairing',
179
+ http: { method: 'GET', path: '/api/v1/test' },
180
+ authorization: { safetyImpact: 'write-destructive' },
181
+ mcp: {
182
+ toolName: 'test_tool',
183
+ annotations: {
184
+ readOnlyHint: true,
185
+ destructiveHint: false,
186
+ idempotentHint: true,
187
+ openWorldHint: false,
188
+ },
189
+ taskSupport: { exposed: true, taskEligible: false },
190
+ },
191
+ cli: { commandPath: 'test' },
192
+ agentExposure: 'agent',
193
+ profiles: ['discovery-readonly'],
194
+ })).toThrow(/authorization\.safetyImpact/);
195
+ });
196
+ });
@@ -0,0 +1,69 @@
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
+ 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 = 'conversations' | 'core-lifecycle' | 'discovery-readonly' | 'evaluations';
15
+ /** MCP task semantics for an operation. */
16
+ export type McpTaskSupport = {
17
+ /** When true, the operation is exposed as an MCP tool. */
18
+ exposed: boolean;
19
+ /**
20
+ * When true, the operation may complete asynchronously via MCP Tasks.
21
+ * Long-running evaluation runs and LLM generation are task-eligible.
22
+ */
23
+ taskEligible: boolean;
24
+ };
25
+ export type OperationAuthorization = {
26
+ safetyImpact: SafetyImpact;
27
+ };
28
+ export type OperationHttp = {
29
+ method: HttpMethod;
30
+ /** OpenAPI-style path template (includes `/api/v1` prefix). */
31
+ path: string;
32
+ };
33
+ export type OperationMcp = {
34
+ /** MCP tool name without the `lightdash_` prefix. */
35
+ toolName: string;
36
+ annotations: ToolAnnotations;
37
+ taskSupport: McpTaskSupport;
38
+ };
39
+ export type OperationCli = {
40
+ /** Space-delimited CLI command path from the root program (e.g. `agents list`). */
41
+ commandPath: string;
42
+ };
43
+ /** Optional multi-step HTTP workflow when a single registry entry orchestrates several API calls. */
44
+ export type OperationWorkflowStep = {
45
+ method: HttpMethod;
46
+ path: string;
47
+ summary: string;
48
+ };
49
+ export type OperationDescriptor = {
50
+ /** Stable dot-separated identifier (e.g. `ai-agents.project.agents.list`). */
51
+ id: string;
52
+ summary: string;
53
+ http: OperationHttp;
54
+ authorization: OperationAuthorization;
55
+ mcp: OperationMcp;
56
+ cli: OperationCli;
57
+ /** `agent` (default) = may be exposed on MCP/CLI; `client-only` = typed client only. */
58
+ agentExposure?: AgentExposure;
59
+ profiles: readonly CapabilityProfile[];
60
+ /** When set, documents the ordered client-side HTTP steps behind this operation. */
61
+ workflow?: readonly OperationWorkflowStep[];
62
+ };
63
+ /**
64
+ * Defines a typed operation descriptor with RFC consistency checks.
65
+ * Throws when authorization impact disagrees with MCP annotations or profiles are invalid.
66
+ */
67
+ export declare function defineOperation<T extends OperationDescriptor>(descriptor: T): T & {
68
+ agentExposure: AgentExposure;
69
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Shared typed operation registry (RFC Section 7).
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
+ 'conversations',
10
+ 'core-lifecycle',
11
+ 'discovery-readonly',
12
+ 'evaluations',
13
+ ]);
14
+ function assertNonEmpty(value, field) {
15
+ if (value.trim().length === 0) {
16
+ throw new Error(`Operation ${field} must be a non-empty string`);
17
+ }
18
+ }
19
+ function expectedImpactFromAnnotations(annotations) {
20
+ if (annotations.readOnlyHint) {
21
+ return 'read';
22
+ }
23
+ if (annotations.destructiveHint) {
24
+ return 'write-destructive';
25
+ }
26
+ if (annotations.openWorldHint) {
27
+ return 'external-side-effect';
28
+ }
29
+ return 'write-nondestructive';
30
+ }
31
+ function validateIdempotentHint(annotations, impact, id) {
32
+ if (impact === 'read' && annotations.idempotentHint !== true) {
33
+ throw new Error(`Operation '${id}': read operations must set mcp.annotations.idempotentHint = true`);
34
+ }
35
+ if (impact === 'write-destructive' && annotations.idempotentHint === true) {
36
+ throw new Error(`Operation '${id}': destructive operations must not set mcp.annotations.idempotentHint = true`);
37
+ }
38
+ }
39
+ /**
40
+ * Defines a typed operation descriptor with RFC consistency checks.
41
+ * Throws when authorization impact disagrees with MCP annotations or profiles are invalid.
42
+ */
43
+ function defineOperation(descriptor) {
44
+ var _a;
45
+ assertNonEmpty(descriptor.id, 'id');
46
+ assertNonEmpty(descriptor.summary, 'summary');
47
+ assertNonEmpty(descriptor.http.path, 'http.path');
48
+ const agentExposure = (_a = descriptor.agentExposure) !== null && _a !== void 0 ? _a : 'agent';
49
+ if (agentExposure === 'agent') {
50
+ assertNonEmpty(descriptor.mcp.toolName, 'mcp.toolName');
51
+ assertNonEmpty(descriptor.cli.commandPath, 'cli.commandPath');
52
+ }
53
+ if (agentExposure === 'client-only' && descriptor.mcp.taskSupport.exposed) {
54
+ throw new Error(`Operation '${descriptor.id}': client-only operations must set mcp.taskSupport.exposed to false`);
55
+ }
56
+ if (descriptor.profiles.length === 0) {
57
+ throw new Error(`Operation '${descriptor.id}' must declare at least one capability profile`);
58
+ }
59
+ for (const profile of descriptor.profiles) {
60
+ if (!VALID_PROFILES.has(profile)) {
61
+ throw new Error(`Operation '${descriptor.id}' has unknown capability profile '${profile}'`);
62
+ }
63
+ }
64
+ const expectedImpact = expectedImpactFromAnnotations(descriptor.mcp.annotations);
65
+ if (descriptor.authorization.safetyImpact !== expectedImpact) {
66
+ throw new Error(`Operation '${descriptor.id}': authorization.safetyImpact is '${descriptor.authorization.safetyImpact}' but MCP annotations imply '${expectedImpact}'`);
67
+ }
68
+ validateIdempotentHint(descriptor.mcp.annotations, descriptor.authorization.safetyImpact, descriptor.id);
69
+ return Object.assign(Object.assign({}, descriptor), { agentExposure });
70
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
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
+ mcp: {
22
+ toolName: 'test_op',
23
+ annotations: {
24
+ readOnlyHint: true,
25
+ destructiveHint: false,
26
+ idempotentHint: true,
27
+ openWorldHint: false,
28
+ },
29
+ taskSupport: { exposed: true, taskEligible: false },
30
+ },
31
+ cli: { commandPath: 'test op' },
32
+ agentExposure: 'agent',
33
+ profiles: ['discovery-readonly'],
34
+ };
35
+ (0, vitest_1.describe)('defineOperation', () => {
36
+ (0, vitest_1.it)('accepts a valid read descriptor', () => {
37
+ (0, vitest_1.expect)((0, types_1.defineOperation)(baseDescriptor)).toEqual(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'agent' }));
38
+ });
39
+ (0, vitest_1.it)('defaults agentExposure to agent', () => {
40
+ const { agentExposure } = baseDescriptor, withoutExposure = __rest(baseDescriptor, ["agentExposure"]);
41
+ void agentExposure;
42
+ (0, vitest_1.expect)((0, types_1.defineOperation)(withoutExposure).agentExposure).toBe('agent');
43
+ });
44
+ (0, vitest_1.it)('rejects empty id', () => {
45
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { id: ' ' }))).toThrow(/id/);
46
+ });
47
+ (0, vitest_1.it)('rejects empty summary', () => {
48
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { summary: '' }))).toThrow(/summary/);
49
+ });
50
+ (0, vitest_1.it)('rejects empty http path', () => {
51
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { http: { method: 'GET', path: '' } }))).toThrow(/http.path/);
52
+ });
53
+ (0, vitest_1.it)('rejects empty profiles', () => {
54
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: [] }))).toThrow(/profile/);
55
+ });
56
+ (0, vitest_1.it)('rejects unknown profile', () => {
57
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { profiles: ['unknown-profile'] }))).toThrow(/unknown capability profile/);
58
+ });
59
+ (0, vitest_1.it)('rejects read operation without idempotentHint', () => {
60
+ (0, vitest_1.expect)(() => (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 }) }) }))).toThrow(/idempotentHint/);
61
+ });
62
+ (0, vitest_1.it)('rejects destructive operation with idempotentHint true', () => {
63
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { authorization: { safetyImpact: 'write-destructive' }, mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: {
64
+ readOnlyHint: false,
65
+ destructiveHint: true,
66
+ idempotentHint: true,
67
+ openWorldHint: false,
68
+ } }) }))).toThrow(/destructive operations/);
69
+ });
70
+ (0, vitest_1.it)('rejects client-only operation with mcp exposed', () => {
71
+ (0, vitest_1.expect)(() => (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { agentExposure: 'client-only', mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { taskSupport: { exposed: true, taskEligible: false } }) }))).toThrow(/client-only operations must set mcp.taskSupport.exposed to false/);
72
+ });
73
+ (0, vitest_1.it)('allows client-only operation without mcp tool name or cli path', () => {
74
+ const op = (0, types_1.defineOperation)({
75
+ id: 'test.client-only',
76
+ summary: 'Client only delete',
77
+ http: { method: 'DELETE', path: '/api/v1/test/{id}' },
78
+ authorization: { safetyImpact: 'write-destructive' },
79
+ mcp: {
80
+ toolName: '',
81
+ annotations: {
82
+ readOnlyHint: false,
83
+ destructiveHint: true,
84
+ idempotentHint: false,
85
+ openWorldHint: false,
86
+ },
87
+ taskSupport: { exposed: false, taskEligible: false },
88
+ },
89
+ cli: { commandPath: '' },
90
+ agentExposure: 'client-only',
91
+ profiles: ['discovery-readonly'],
92
+ });
93
+ (0, vitest_1.expect)(op.agentExposure).toBe('client-only');
94
+ });
95
+ (0, vitest_1.it)('maps openWorldHint to external-side-effect impact', () => {
96
+ const op = (0, types_1.defineOperation)(Object.assign(Object.assign({}, baseDescriptor), { authorization: { safetyImpact: 'external-side-effect' }, mcp: Object.assign(Object.assign({}, baseDescriptor.mcp), { annotations: {
97
+ readOnlyHint: false,
98
+ destructiveHint: false,
99
+ idempotentHint: false,
100
+ openWorldHint: true,
101
+ } }) }));
102
+ (0, vitest_1.expect)(op.authorization.safetyImpact).toBe('external-side-effect');
103
+ });
104
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Organization member operations in the shared operation registry.
3
+ */
4
+ import type { OperationDescriptor } from './types';
5
+ /** Organization member operations registered in the shared operation registry. */
6
+ export declare const USER_OPERATIONS: readonly OperationDescriptor[];
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /**
3
+ * Organization member operations in the shared operation registry.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.USER_OPERATIONS = void 0;
7
+ const safety_1 = require("../safety");
8
+ const types_1 = require("./types");
9
+ const PROFILE_DISCOVERY = 'discovery-readonly';
10
+ const PROFILE_CORE_LIFECYCLE = 'core-lifecycle';
11
+ const API_V1 = '/api/v1';
12
+ const MEMBERS_PATH = `${API_V1}/org/users`;
13
+ const MEMBER_PATH = `${MEMBERS_PATH}/{userUuid}`;
14
+ const DELETE_MEMBER_PATH = `${API_V1}/org/user/{userUuid}`;
15
+ const membersList = (0, types_1.defineOperation)({
16
+ id: 'users.members.list',
17
+ summary: 'List organization members (one page)',
18
+ http: { method: 'GET', path: MEMBERS_PATH },
19
+ authorization: { safetyImpact: 'read' },
20
+ mcp: {
21
+ toolName: 'list_organization_members',
22
+ annotations: safety_1.READ_ONLY_DEFAULT,
23
+ taskSupport: { exposed: true, taskEligible: false },
24
+ },
25
+ cli: { commandPath: 'users list' },
26
+ profiles: [PROFILE_DISCOVERY],
27
+ });
28
+ const membersGet = (0, types_1.defineOperation)({
29
+ id: 'users.members.get',
30
+ summary: 'Get an organization member by UUID',
31
+ http: { method: 'GET', path: MEMBER_PATH },
32
+ authorization: { safetyImpact: 'read' },
33
+ mcp: {
34
+ toolName: 'get_member',
35
+ annotations: safety_1.READ_ONLY_DEFAULT,
36
+ taskSupport: { exposed: true, taskEligible: false },
37
+ },
38
+ cli: { commandPath: 'users get' },
39
+ profiles: [PROFILE_DISCOVERY],
40
+ });
41
+ const membersDelete = (0, types_1.defineOperation)({
42
+ id: 'users.members.delete',
43
+ summary: 'Permanently remove a user from the organization (irrecoverable; client-only)',
44
+ http: { method: 'DELETE', path: DELETE_MEMBER_PATH },
45
+ authorization: { safetyImpact: 'write-destructive' },
46
+ mcp: {
47
+ toolName: 'delete_member',
48
+ annotations: safety_1.WRITE_DESTRUCTIVE,
49
+ taskSupport: { exposed: false, taskEligible: false },
50
+ },
51
+ cli: { commandPath: '' },
52
+ agentExposure: 'client-only',
53
+ profiles: [PROFILE_CORE_LIFECYCLE],
54
+ });
55
+ /** Organization member operations registered in the shared operation registry. */
56
+ exports.USER_OPERATIONS = [
57
+ membersList,
58
+ membersGet,
59
+ membersDelete,
60
+ ];
package/dist/safety.d.ts CHANGED
@@ -1,9 +1,16 @@
1
+ /**
2
+ * Semantic impact classification for operations (RFC Phase 0).
3
+ * Used by {@link OperationPolicy} and {@link isOperationAllowed}.
4
+ */
5
+ export type SafetyImpact = 'credential-sensitive' | 'external-side-effect' | 'read' | 'write-destructive' | 'write-nondestructive';
1
6
  /**
2
7
  * Hierarchical safety modes for Lightdash AI tools and CLI.
3
8
  */
4
9
  export declare enum SafetyMode {
5
10
  READ_ONLY = "read-only",
11
+ /** Deprecated alias — prefer {@link SafetyMode.WRITE_NONDESTRUCTIVE}. */
6
12
  WRITE_IDEMPOTENT = "write-idempotent",
13
+ WRITE_NONDESTRUCTIVE = "write-nondestructive",
7
14
  WRITE_DESTRUCTIVE = "write-destructive"
8
15
  }
9
16
  /**
@@ -17,18 +24,36 @@ export type ToolAnnotations = {
17
24
  idempotentHint?: boolean;
18
25
  openWorldHint?: boolean;
19
26
  };
27
+ /** Policy describing the semantic impact of an operation. */
28
+ export type OperationPolicy = {
29
+ impact: SafetyImpact;
30
+ };
20
31
  /** Preset: read-only, non-destructive, idempotent, closed-world. Use for list/get/compile tools. */
21
32
  export declare const READ_ONLY_DEFAULT: ToolAnnotations;
22
- /** Preset: write, non-destructive, idempotent (e.g. upsert by slug). Use for create/update tools. */
33
+ /**
34
+ * Legacy preset: write, non-destructive, idempotent (e.g. upsert by slug).
35
+ * Prefer {@link WRITE_NONDESTRUCTIVE} for new tools; idempotent behavior is not implied by safety mode.
36
+ */
23
37
  export declare const WRITE_IDEMPOTENT: ToolAnnotations;
38
+ /** Preset: write, non-destructive, closed-world. Use for create/update tools without idempotency guarantee. */
39
+ export declare const WRITE_NONDESTRUCTIVE: ToolAnnotations;
40
+ /** Preset: write, non-destructive, open-world. Use for LLM generation and similar external interactions. */
41
+ export declare const WRITE_OPEN_WORLD: ToolAnnotations;
24
42
  /** Preset: write, destructive, non-idempotent. Use for delete/remove tools. */
25
43
  export declare const WRITE_DESTRUCTIVE: ToolAnnotations;
26
44
  /**
27
- * Validates if an operation is allowed in the current safety mode.
45
+ * Validates if an operation is allowed in the current safety mode using MCP tool annotations.
46
+ * Unknown modes default to permissive for backward compatibility.
28
47
  */
29
48
  export declare function isAllowed(mode: SafetyMode | string, annotations: ToolAnnotations): boolean;
49
+ /**
50
+ * Validates if an operation is allowed in the current safety mode using semantic impact policy.
51
+ * Unknown modes fail closed.
52
+ */
53
+ export declare function isOperationAllowed(mode: SafetyMode | string, policy: OperationPolicy): boolean;
30
54
  /**
31
55
  * Resolves safety mode from environment variable.
56
+ * Accepts `write-idempotent` as a deprecated alias for `write-nondestructive`.
32
57
  */
33
58
  export declare function getSafetyModeFromEnv(): SafetyMode;
34
59
  /**