@lightdash-tools/common 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/agentops/extract-yaml-project.d.ts +7 -0
  2. package/dist/agentops/extract-yaml-project.js +42 -0
  3. package/dist/agentops/formatters.d.ts +5 -0
  4. package/dist/agentops/formatters.js +47 -0
  5. package/dist/agentops/snapshots.d.ts +32 -0
  6. package/dist/agentops/snapshots.js +34 -0
  7. package/dist/agentops/types.d.ts +224 -0
  8. package/dist/agentops/types.js +430 -0
  9. package/dist/argument-validation.d.ts +25 -0
  10. package/dist/argument-validation.js +217 -0
  11. package/dist/argument-validation.test.d.ts +1 -0
  12. package/dist/argument-validation.test.js +205 -0
  13. package/dist/audit.d.ts +9 -2
  14. package/dist/audit.js +17 -2
  15. package/dist/audit.test.d.ts +1 -0
  16. package/dist/audit.test.js +73 -0
  17. package/dist/env.d.ts +8 -0
  18. package/dist/env.js +9 -1
  19. package/dist/index.d.ts +7 -3
  20. package/dist/index.js +14 -2
  21. package/dist/input-validation.d.ts +35 -0
  22. package/dist/input-validation.js +87 -0
  23. package/dist/input-validation.test.js +93 -0
  24. package/dist/operations/agent-safe.d.ts +5 -0
  25. package/dist/operations/agent-safe.js +9 -0
  26. package/dist/operations/ai-agents.d.ts +6 -0
  27. package/dist/operations/ai-agents.js +427 -0
  28. package/dist/operations/cli-content.d.ts +5 -0
  29. package/dist/operations/cli-content.js +71 -0
  30. package/dist/operations/client-coverage.d.ts +113 -0
  31. package/dist/operations/client-coverage.js +130 -0
  32. package/dist/operations/client-coverage.test.d.ts +1 -0
  33. package/dist/operations/client-coverage.test.js +22 -0
  34. package/dist/operations/content-developer.d.ts +2 -0
  35. package/dist/operations/content-developer.js +457 -0
  36. package/dist/operations/content-governance.d.ts +7 -0
  37. package/dist/operations/content-governance.js +98 -0
  38. package/dist/operations/content-reader.d.ts +2 -0
  39. package/dist/operations/content-reader.js +183 -0
  40. package/dist/operations/index.d.ts +12 -0
  41. package/dist/operations/index.js +34 -0
  42. package/dist/operations/organization-audit.d.ts +2 -0
  43. package/dist/operations/organization-audit.js +273 -0
  44. package/dist/operations/parity.test.d.ts +1 -0
  45. package/dist/operations/parity.test.js +29 -0
  46. package/dist/operations/registry.d.ts +18 -0
  47. package/dist/operations/registry.js +110 -0
  48. package/dist/operations/registry.test.d.ts +1 -0
  49. package/dist/operations/registry.test.js +223 -0
  50. package/dist/operations/semantic-layer.d.ts +6 -0
  51. package/dist/operations/semantic-layer.js +154 -0
  52. package/dist/operations/types.d.ts +86 -0
  53. package/dist/operations/types.js +104 -0
  54. package/dist/operations/types.test.d.ts +1 -0
  55. package/dist/operations/types.test.js +92 -0
  56. package/dist/operations/users.d.ts +6 -0
  57. package/dist/operations/users.js +58 -0
  58. package/dist/safety.d.ts +32 -2
  59. package/dist/safety.js +62 -5
  60. package/dist/safety.test.js +217 -4
  61. package/dist/types/generated/openapi-types.d.ts +32623 -11194
  62. package/dist/types/index.d.ts +12 -0
  63. package/dist/types/index.js +29 -0
  64. package/dist/types/lightdash-api.d.ts +1 -1
  65. package/dist/types/v1/ai-agents.d.ts +112 -3
  66. package/dist/types/v1/charts.d.ts +5 -3
  67. package/dist/types/v1/dashboards.d.ts +13 -0
  68. package/dist/types/v1/index.d.ts +45 -8
  69. package/dist/types/v1/index.js +1 -1
  70. package/dist/types/v1/lightdash-api.d.ts +107 -16
  71. package/dist/types/v1/users.d.ts +4 -0
  72. package/dist/types/v2/content.d.ts +2 -0
  73. package/dist/types/v2/content.js +8 -0
  74. package/dist/types/v2/index.d.ts +11 -9
  75. package/dist/types/v2/index.js +1 -1
  76. package/package.json +17 -3
  77. package/src/agentops/extract-yaml-project.ts +42 -0
  78. package/src/agentops/formatters.ts +52 -0
  79. package/src/agentops/snapshots.ts +56 -0
  80. package/src/agentops/types.ts +599 -0
  81. package/src/argument-validation.test.ts +301 -0
  82. package/src/argument-validation.ts +258 -0
  83. package/src/audit.test.ts +87 -0
  84. package/src/audit.ts +32 -3
  85. package/src/env.ts +9 -0
  86. package/src/index.test.ts +1 -0
  87. package/src/index.ts +17 -6
  88. package/src/input-validation.test.ts +157 -1
  89. package/src/input-validation.ts +95 -0
  90. package/src/operations/agent-safe.ts +8 -0
  91. package/src/operations/ai-agents.ts +467 -0
  92. package/src/operations/cli-content.ts +79 -0
  93. package/src/operations/client-coverage.test.ts +23 -0
  94. package/src/operations/client-coverage.ts +147 -0
  95. package/src/operations/content-developer.ts +485 -0
  96. package/src/operations/content-governance.ts +110 -0
  97. package/src/operations/content-reader.ts +197 -0
  98. package/src/operations/index.ts +42 -0
  99. package/src/operations/organization-audit.ts +293 -0
  100. package/src/operations/parity.test.ts +33 -0
  101. package/src/operations/registry.test.ts +250 -0
  102. package/src/operations/registry.ts +128 -0
  103. package/src/operations/semantic-layer.ts +166 -0
  104. package/src/operations/types.test.ts +110 -0
  105. package/src/operations/types.ts +231 -0
  106. package/src/operations/users.ts +65 -0
  107. package/src/safety.test.ts +276 -4
  108. package/src/safety.ts +83 -4
  109. package/src/types/generated/openapi-types.ts +33701 -11813
  110. package/src/types/index.ts +13 -0
  111. package/src/types/lightdash-api.ts +39 -0
  112. package/src/types/v1/ai-agents.ts +133 -3
  113. package/src/types/v1/charts.ts +5 -3
  114. package/src/types/v1/dashboards.ts +19 -0
  115. package/src/types/v1/index.ts +51 -8
  116. package/src/types/v1/lightdash-api.ts +129 -20
  117. package/src/types/v1/users.ts +4 -0
  118. package/src/types/v2/content.ts +8 -0
  119. package/src/types/v2/index.ts +11 -9
  120. package/tsconfig.json +1 -0
package/src/safety.ts CHANGED
@@ -1,11 +1,25 @@
1
+ import { extractProjectUuidsFromToolArgs } from './agentops/extract-yaml-project';
1
2
  import { ENV_LIGHTDASH_TOOLS_SAFETY_MODE, ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS } from './env';
2
3
 
4
+ /**
5
+ * Semantic impact classification for operations (RFC Phase 0).
6
+ * Used by {@link OperationPolicy} and {@link isOperationAllowed}.
7
+ */
8
+ export type SafetyImpact =
9
+ | 'credential-sensitive'
10
+ | 'external-side-effect'
11
+ | 'read'
12
+ | 'write-destructive'
13
+ | 'write-nondestructive';
14
+
3
15
  /**
4
16
  * Hierarchical safety modes for Lightdash AI tools and CLI.
5
17
  */
6
18
  export enum SafetyMode {
7
19
  READ_ONLY = 'read-only',
20
+ /** Deprecated alias — prefer {@link SafetyMode.WRITE_NONDESTRUCTIVE}. */
8
21
  WRITE_IDEMPOTENT = 'write-idempotent',
22
+ WRITE_NONDESTRUCTIVE = 'write-nondestructive',
9
23
  WRITE_DESTRUCTIVE = 'write-destructive',
10
24
  }
11
25
 
@@ -21,6 +35,11 @@ export type ToolAnnotations = {
21
35
  openWorldHint?: boolean;
22
36
  };
23
37
 
38
+ /** Policy describing the semantic impact of an operation. */
39
+ export type OperationPolicy = {
40
+ impact: SafetyImpact;
41
+ };
42
+
24
43
  /** Preset: read-only, non-destructive, idempotent, closed-world. Use for list/get/compile tools. */
25
44
  export const READ_ONLY_DEFAULT: ToolAnnotations = {
26
45
  readOnlyHint: true,
@@ -29,7 +48,21 @@ export const READ_ONLY_DEFAULT: ToolAnnotations = {
29
48
  idempotentHint: true,
30
49
  };
31
50
 
32
- /** Preset: write, non-destructive, idempotent (e.g. upsert by slug). Use for create/update tools. */
51
+ /**
52
+ * Preset: read-only but non-idempotent (transient warehouse execution).
53
+ * Used by content-reader saved-chart/tile runs (ADR-0012).
54
+ */
55
+ export const READ_ONLY_TRANSIENT: ToolAnnotations = {
56
+ readOnlyHint: true,
57
+ openWorldHint: false,
58
+ destructiveHint: false,
59
+ idempotentHint: false,
60
+ };
61
+
62
+ /**
63
+ * Legacy preset: write, non-destructive, idempotent (e.g. upsert by slug).
64
+ * Prefer {@link WRITE_NONDESTRUCTIVE} for new tools; idempotent behavior is not implied by safety mode.
65
+ */
33
66
  export const WRITE_IDEMPOTENT: ToolAnnotations = {
34
67
  readOnlyHint: false,
35
68
  openWorldHint: false,
@@ -37,6 +70,22 @@ export const WRITE_IDEMPOTENT: ToolAnnotations = {
37
70
  idempotentHint: true,
38
71
  };
39
72
 
73
+ /** Preset: write, non-destructive, closed-world. Use for create/update tools without idempotency guarantee. */
74
+ export const WRITE_NONDESTRUCTIVE: ToolAnnotations = {
75
+ readOnlyHint: false,
76
+ openWorldHint: false,
77
+ destructiveHint: false,
78
+ idempotentHint: false,
79
+ };
80
+
81
+ /** Preset: write, non-destructive, open-world. Use for LLM generation and similar external interactions. */
82
+ export const WRITE_OPEN_WORLD: ToolAnnotations = {
83
+ readOnlyHint: false,
84
+ openWorldHint: true,
85
+ destructiveHint: false,
86
+ idempotentHint: false,
87
+ };
88
+
40
89
  /** Preset: write, destructive, non-idempotent. Use for delete/remove tools. */
41
90
  export const WRITE_DESTRUCTIVE: ToolAnnotations = {
42
91
  readOnlyHint: false,
@@ -46,26 +95,54 @@ export const WRITE_DESTRUCTIVE: ToolAnnotations = {
46
95
  };
47
96
 
48
97
  /**
49
- * Validates if an operation is allowed in the current safety mode.
98
+ * Validates if an operation is allowed in the current safety mode using MCP tool annotations.
99
+ * Unknown modes default to permissive for backward compatibility.
50
100
  */
51
101
  export function isAllowed(mode: SafetyMode | string, annotations: ToolAnnotations): boolean {
52
102
  switch (mode) {
53
103
  case SafetyMode.READ_ONLY:
54
104
  return !!annotations.readOnlyHint;
105
+ case SafetyMode.WRITE_NONDESTRUCTIVE:
55
106
  case SafetyMode.WRITE_IDEMPOTENT:
56
107
  return !!annotations.readOnlyHint || !annotations.destructiveHint;
57
108
  case SafetyMode.WRITE_DESTRUCTIVE:
58
109
  return true;
59
110
  default:
60
- return true; // Default to most permissive if mode is unknown
111
+ return true;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Validates if an operation is allowed in the current safety mode using semantic impact policy.
117
+ * Unknown modes fail closed.
118
+ */
119
+ export function isOperationAllowed(mode: SafetyMode | string, policy: OperationPolicy): boolean {
120
+ switch (mode) {
121
+ case SafetyMode.READ_ONLY:
122
+ return policy.impact === 'read';
123
+ case SafetyMode.WRITE_NONDESTRUCTIVE:
124
+ case SafetyMode.WRITE_IDEMPOTENT:
125
+ return (
126
+ policy.impact === 'read' ||
127
+ policy.impact === 'write-nondestructive' ||
128
+ policy.impact === 'external-side-effect'
129
+ );
130
+ case SafetyMode.WRITE_DESTRUCTIVE:
131
+ return true;
132
+ default:
133
+ return false;
61
134
  }
62
135
  }
63
136
 
64
137
  /**
65
138
  * Resolves safety mode from environment variable.
139
+ * Accepts `write-idempotent` as a deprecated alias for `write-nondestructive`.
66
140
  */
67
141
  export function getSafetyModeFromEnv(): SafetyMode {
68
142
  const mode = process.env[ENV_LIGHTDASH_TOOLS_SAFETY_MODE];
143
+ if (mode === SafetyMode.WRITE_IDEMPOTENT) {
144
+ return SafetyMode.WRITE_NONDESTRUCTIVE;
145
+ }
69
146
  if (Object.values(SafetyMode).includes(mode as SafetyMode)) {
70
147
  return mode as SafetyMode;
71
148
  }
@@ -143,7 +220,7 @@ export function extractProjectUuids(args: unknown): string[] {
143
220
  } else if (typeof args === 'object') {
144
221
  // MCP or single options object
145
222
  const a = args as Record<string, unknown>;
146
- const keys = ['project', 'projectUuid', 'projectUuids'];
223
+ const keys = ['projects', 'project', 'projectUuid', 'projectUuids'];
147
224
  for (const key of keys) {
148
225
  const val = a[key];
149
226
  if (typeof val === 'string') {
@@ -156,5 +233,7 @@ export function extractProjectUuids(args: unknown): string[] {
156
233
  }
157
234
  }
158
235
 
236
+ uuids.push(...extractProjectUuidsFromToolArgs(args));
237
+
159
238
  return [...new Set(uuids)].filter((u) => u.length > 0);
160
239
  }