@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
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
|
-
/**
|
|
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;
|
|
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
|
}
|