@lightdash-tools/common 0.19.0 → 0.21.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.
@@ -12,7 +12,12 @@ export declare function toAgentSnapshot(agent: {
12
12
  description: string | null;
13
13
  instruction: string | null;
14
14
  tags: string[] | null;
15
+ spaceAccess?: string[];
15
16
  enableDataAccess?: boolean;
17
+ enableContentTools?: boolean;
18
+ enableSqlMode?: boolean;
19
+ enableUserContext?: boolean;
20
+ adminOnly?: boolean;
16
21
  enableSelfImprovement?: boolean;
17
22
  }): AgentStateSnapshot;
18
23
  export declare function toEvaluationSnapshot(evaluation: {
@@ -20,7 +20,12 @@ function toAgentSnapshot(agent) {
20
20
  description: agent.description,
21
21
  instruction: agent.instruction,
22
22
  tags: agent.tags,
23
+ spaceAccess: agent.spaceAccess,
23
24
  enableDataAccess: agent.enableDataAccess,
25
+ enableContentTools: agent.enableContentTools,
26
+ enableSqlMode: agent.enableSqlMode,
27
+ enableUserContext: agent.enableUserContext,
28
+ adminOnly: agent.adminOnly,
24
29
  enableSelfImprovement: agent.enableSelfImprovement,
25
30
  };
26
31
  }
@@ -25,7 +25,12 @@ declare const bundleAgentSchema: z.ZodObject<{
25
25
  instruction: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
26
  tags: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
27
27
  enableDataAccess: z.ZodOptional<z.ZodBoolean>;
28
+ enableContentTools: z.ZodOptional<z.ZodBoolean>;
29
+ enableSqlMode: z.ZodOptional<z.ZodBoolean>;
30
+ enableUserContext: z.ZodOptional<z.ZodBoolean>;
31
+ adminOnly: z.ZodOptional<z.ZodBoolean>;
28
32
  enableSelfImprovement: z.ZodOptional<z.ZodBoolean>;
33
+ spaceAccess: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
34
  evaluations: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
30
35
  key: z.ZodString;
31
36
  uuid: z.ZodOptional<z.ZodString>;
@@ -59,7 +64,12 @@ export declare const lightdashAiAgentBundleSchema: z.ZodObject<{
59
64
  instruction: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
65
  tags: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
61
66
  enableDataAccess: z.ZodOptional<z.ZodBoolean>;
67
+ enableContentTools: z.ZodOptional<z.ZodBoolean>;
68
+ enableSqlMode: z.ZodOptional<z.ZodBoolean>;
69
+ enableUserContext: z.ZodOptional<z.ZodBoolean>;
70
+ adminOnly: z.ZodOptional<z.ZodBoolean>;
62
71
  enableSelfImprovement: z.ZodOptional<z.ZodBoolean>;
72
+ spaceAccess: z.ZodOptional<z.ZodArray<z.ZodString>>;
63
73
  evaluations: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
64
74
  key: z.ZodString;
65
75
  uuid: z.ZodOptional<z.ZodString>;
@@ -157,7 +167,12 @@ export interface AgentStateSnapshot {
157
167
  description: string | null;
158
168
  instruction: string | null;
159
169
  tags: string[] | null;
170
+ spaceAccess?: string[];
160
171
  enableDataAccess?: boolean;
172
+ enableContentTools?: boolean;
173
+ enableSqlMode?: boolean;
174
+ enableUserContext?: boolean;
175
+ adminOnly?: boolean;
161
176
  enableSelfImprovement?: boolean;
162
177
  }
163
178
  /** Minimal evaluation shape for diffing. */
@@ -16,6 +16,7 @@ exports.getLightdashAiEvaluationGateJsonSchema = getLightdashAiEvaluationGateJso
16
16
  exports.evaluateGatePolicy = evaluateGatePolicy;
17
17
  const yaml_1 = require("yaml");
18
18
  const zod_1 = require("zod");
19
+ const secure_create_defaults_js_1 = require("../ai-agents/secure-create-defaults.js");
19
20
  // ─── Shared metadata ─────────────────────────────────────────────────────────
20
21
  const metadataSchema = zod_1.z.object({
21
22
  name: zod_1.z.string().min(1),
@@ -49,7 +50,12 @@ const bundleAgentSchema = zod_1.z.object({
49
50
  instruction: zod_1.z.string().nullable().optional(),
50
51
  tags: zod_1.z.array(zod_1.z.string()).nullable().optional(),
51
52
  enableDataAccess: zod_1.z.boolean().optional(),
53
+ enableContentTools: zod_1.z.boolean().optional(),
54
+ enableSqlMode: zod_1.z.boolean().optional(),
55
+ enableUserContext: zod_1.z.boolean().optional(),
56
+ adminOnly: zod_1.z.boolean().optional(),
52
57
  enableSelfImprovement: zod_1.z.boolean().optional(),
58
+ spaceAccess: zod_1.z.array(zod_1.z.string().uuid()).optional(),
53
59
  evaluations: zod_1.z.array(bundleEvaluationSchema).optional().default([]),
54
60
  });
55
61
  exports.lightdashAiAgentBundleSchema = zod_1.z.object({
@@ -138,13 +144,23 @@ function normalizeEvaluationPrompt(prompt) {
138
144
  function promptsEqual(a, b) {
139
145
  return JSON.stringify(a) === JSON.stringify(b);
140
146
  }
147
+ const OPTIONAL_AGENT_BOOLEAN_FIELDS = [
148
+ 'enableDataAccess',
149
+ 'enableContentTools',
150
+ 'enableSqlMode',
151
+ 'enableUserContext',
152
+ 'adminOnly',
153
+ 'enableSelfImprovement',
154
+ ];
141
155
  function agentFieldsToCompare(agent) {
142
156
  const fields = ['name', 'description', 'instruction', 'tags'];
143
- if (agent.enableDataAccess !== undefined) {
144
- fields.push('enableDataAccess');
157
+ if (agent.spaceAccess !== undefined) {
158
+ fields.push('spaceAccess');
145
159
  }
146
- if (agent.enableSelfImprovement !== undefined) {
147
- fields.push('enableSelfImprovement');
160
+ for (const field of OPTIONAL_AGENT_BOOLEAN_FIELDS) {
161
+ if (agent[field] !== undefined) {
162
+ fields.push(field);
163
+ }
148
164
  }
149
165
  return fields;
150
166
  }
@@ -153,24 +169,28 @@ function normalizeAgentBooleanFlag(value) {
153
169
  return value !== null && value !== void 0 ? value : false;
154
170
  }
155
171
  function normalizeTags(tags) {
156
- if (tags == null || tags.length === 0) {
157
- return null;
172
+ return (0, secure_create_defaults_js_1.normalizeAgentTags)(tags);
173
+ }
174
+ function normalizeSpaceAccess(spaceAccess) {
175
+ if (spaceAccess === undefined) {
176
+ return undefined;
158
177
  }
159
- return tags;
178
+ return [...spaceAccess].sort();
160
179
  }
161
180
  function pickAgentFields(agent) {
162
- return {
163
- name: agent.name,
164
- description: agent.description,
165
- instruction: agent.instruction,
166
- tags: normalizeTags(agent.tags),
167
- enableDataAccess: normalizeAgentBooleanFlag(agent.enableDataAccess),
168
- enableSelfImprovement: normalizeAgentBooleanFlag(agent.enableSelfImprovement),
169
- };
181
+ return Object.assign(Object.assign({ name: agent.name, description: agent.description, instruction: agent.instruction, tags: normalizeTags(agent.tags) }, (agent.spaceAccess !== undefined
182
+ ? { spaceAccess: normalizeSpaceAccess(agent.spaceAccess) }
183
+ : {})), { enableDataAccess: normalizeAgentBooleanFlag(agent.enableDataAccess), enableContentTools: normalizeAgentBooleanFlag(agent.enableContentTools), enableSqlMode: normalizeAgentBooleanFlag(agent.enableSqlMode), enableUserContext: normalizeAgentBooleanFlag(agent.enableUserContext), adminOnly: normalizeAgentBooleanFlag(agent.adminOnly), enableSelfImprovement: normalizeAgentBooleanFlag(agent.enableSelfImprovement) });
170
184
  }
171
185
  function desiredAgentToSnapshot(agent, uuid) {
172
186
  var _a, _b, _c;
173
- return Object.assign(Object.assign({ uuid, name: agent.name, description: (_a = agent.description) !== null && _a !== void 0 ? _a : null, instruction: (_b = agent.instruction) !== null && _b !== void 0 ? _b : null, tags: normalizeTags((_c = agent.tags) !== null && _c !== void 0 ? _c : null) }, (agent.enableDataAccess !== undefined ? { enableDataAccess: agent.enableDataAccess } : {})), (agent.enableSelfImprovement !== undefined
187
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ uuid, name: agent.name, description: (_a = agent.description) !== null && _a !== void 0 ? _a : null, instruction: (_b = agent.instruction) !== null && _b !== void 0 ? _b : null, tags: normalizeTags((_c = agent.tags) !== null && _c !== void 0 ? _c : null) }, (agent.spaceAccess !== undefined
188
+ ? { spaceAccess: normalizeSpaceAccess(agent.spaceAccess) }
189
+ : {})), (agent.enableDataAccess !== undefined ? { enableDataAccess: agent.enableDataAccess } : {})), (agent.enableContentTools !== undefined
190
+ ? { enableContentTools: agent.enableContentTools }
191
+ : {})), (agent.enableSqlMode !== undefined ? { enableSqlMode: agent.enableSqlMode } : {})), (agent.enableUserContext !== undefined
192
+ ? { enableUserContext: agent.enableUserContext }
193
+ : {})), (agent.adminOnly !== undefined ? { adminOnly: agent.adminOnly } : {})), (agent.enableSelfImprovement !== undefined
174
194
  ? { enableSelfImprovement: agent.enableSelfImprovement }
175
195
  : {}));
176
196
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Lightdash AI agent knowledge document limits (product docs: 20KB per document).
3
+ */
4
+ export declare const AGENT_DOCUMENT_MAX_BYTES = 20480;
5
+ export declare const AGENT_DOCUMENT_DEFAULT_MIME: "text/markdown";
6
+ export declare const AGENT_DOCUMENT_ALLOWED_MIME_TYPES: readonly ["text/markdown", "text/plain"];
7
+ export type AgentDocumentMimeType = (typeof AGENT_DOCUMENT_ALLOWED_MIME_TYPES)[number];
8
+ export declare function agentDocumentContentByteLength(content: string): number;
9
+ export declare function isAgentDocumentContentWithinLimit(content: string): boolean;
10
+ export declare function isAllowedAgentDocumentMimeType(mimeType: string): mimeType is AgentDocumentMimeType;
11
+ /** Derive a filename hint when the host omits originalFilename. */
12
+ export declare function defaultAgentDocumentFilename(name: string, mimeType: AgentDocumentMimeType): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Lightdash AI agent knowledge document limits (product docs: 20KB per document).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AGENT_DOCUMENT_ALLOWED_MIME_TYPES = exports.AGENT_DOCUMENT_DEFAULT_MIME = exports.AGENT_DOCUMENT_MAX_BYTES = void 0;
7
+ exports.agentDocumentContentByteLength = agentDocumentContentByteLength;
8
+ exports.isAgentDocumentContentWithinLimit = isAgentDocumentContentWithinLimit;
9
+ exports.isAllowedAgentDocumentMimeType = isAllowedAgentDocumentMimeType;
10
+ exports.defaultAgentDocumentFilename = defaultAgentDocumentFilename;
11
+ exports.AGENT_DOCUMENT_MAX_BYTES = 20480;
12
+ exports.AGENT_DOCUMENT_DEFAULT_MIME = 'text/markdown';
13
+ exports.AGENT_DOCUMENT_ALLOWED_MIME_TYPES = ['text/markdown', 'text/plain'];
14
+ function agentDocumentContentByteLength(content) {
15
+ return Buffer.byteLength(content, 'utf8');
16
+ }
17
+ function isAgentDocumentContentWithinLimit(content) {
18
+ return agentDocumentContentByteLength(content) <= exports.AGENT_DOCUMENT_MAX_BYTES;
19
+ }
20
+ function isAllowedAgentDocumentMimeType(mimeType) {
21
+ return exports.AGENT_DOCUMENT_ALLOWED_MIME_TYPES.includes(mimeType);
22
+ }
23
+ /** Derive a filename hint when the host omits originalFilename. */
24
+ function defaultAgentDocumentFilename(name, mimeType) {
25
+ const trimmed = name.trim();
26
+ const base = trimmed.length > 0 ? trimmed : 'document';
27
+ if (mimeType === 'text/plain') {
28
+ return base.endsWith('.txt') ? base : `${base}.txt`;
29
+ }
30
+ return base.endsWith('.md') ? base : `${base}.md`;
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const document_limits_js_1 = require("./document-limits.js");
5
+ (0, vitest_1.describe)('document-limits', () => {
6
+ (0, vitest_1.it)('measures UTF-8 byte length', () => {
7
+ (0, vitest_1.expect)((0, document_limits_js_1.agentDocumentContentByteLength)('hello')).toBe(5);
8
+ (0, vitest_1.expect)((0, document_limits_js_1.agentDocumentContentByteLength)('€')).toBe(3);
9
+ });
10
+ (0, vitest_1.it)('enforces the 20KB ceiling', () => {
11
+ (0, vitest_1.expect)((0, document_limits_js_1.isAgentDocumentContentWithinLimit)('x'.repeat(document_limits_js_1.AGENT_DOCUMENT_MAX_BYTES))).toBe(true);
12
+ (0, vitest_1.expect)((0, document_limits_js_1.isAgentDocumentContentWithinLimit)('x'.repeat(document_limits_js_1.AGENT_DOCUMENT_MAX_BYTES + 1))).toBe(false);
13
+ });
14
+ (0, vitest_1.it)('allows markdown and plain text mime types only', () => {
15
+ (0, vitest_1.expect)((0, document_limits_js_1.isAllowedAgentDocumentMimeType)('text/markdown')).toBe(true);
16
+ (0, vitest_1.expect)((0, document_limits_js_1.isAllowedAgentDocumentMimeType)('text/plain')).toBe(true);
17
+ (0, vitest_1.expect)((0, document_limits_js_1.isAllowedAgentDocumentMimeType)('application/pdf')).toBe(false);
18
+ });
19
+ (0, vitest_1.it)('derives default filenames from name and mime type', () => {
20
+ (0, vitest_1.expect)((0, document_limits_js_1.defaultAgentDocumentFilename)('Glossary', 'text/markdown')).toBe('Glossary.md');
21
+ (0, vitest_1.expect)((0, document_limits_js_1.defaultAgentDocumentFilename)('notes.txt', 'text/plain')).toBe('notes.txt');
22
+ });
23
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Secure-by-default flags for Lightdash AI agent create (MCP, CLI, agentops).
3
+ * More conservative than Lightdash UI defaults — elevation is explicit opt-in.
4
+ */
5
+ import type { CreateAiAgent } from '../types/v1/lightdash-api.js';
6
+ export declare const SECURE_AGENT_CREATE_DEFAULTS: {
7
+ readonly enableDataAccess: false;
8
+ readonly enableContentTools: false;
9
+ readonly enableSqlMode: false;
10
+ readonly enableUserContext: false;
11
+ readonly adminOnly: true;
12
+ readonly enableSelfImprovement: false;
13
+ };
14
+ export type SecureAgentCreateFlags = {
15
+ enableDataAccess?: boolean;
16
+ enableContentTools?: boolean;
17
+ enableSqlMode?: boolean;
18
+ enableUserContext?: boolean;
19
+ adminOnly?: boolean;
20
+ enableSelfImprovement?: boolean;
21
+ };
22
+ export type ResolvedSecureAgentCreateFlags = {
23
+ enableDataAccess: boolean;
24
+ enableContentTools: boolean;
25
+ enableSqlMode: boolean;
26
+ enableUserContext: boolean;
27
+ adminOnly: boolean;
28
+ enableSelfImprovement: boolean;
29
+ };
30
+ export declare const AGENT_PERMISSION_UI_LABELS: {
31
+ readonly enableDataAccess: "Read rows behind chart";
32
+ readonly enableContentTools: "Create/edit content";
33
+ readonly enableSqlMode: "SQL mode";
34
+ readonly enableUserContext: "User context";
35
+ readonly enableSelfImprovement: "Self-improvement";
36
+ readonly adminOnly: "Admins & developers only";
37
+ };
38
+ export type AgentCreatePayloadFields = SecureAgentCreateFlags & {
39
+ name: string;
40
+ description?: string | null;
41
+ instruction?: string | null;
42
+ tags?: string[] | null;
43
+ groupAccess?: string[];
44
+ userAccess?: string[];
45
+ spaceAccess?: string[];
46
+ mcpServerUuids?: string[];
47
+ };
48
+ export type BuildSecureCreateAiAgentInput = AgentCreatePayloadFields & {
49
+ projectUuid: string;
50
+ integrations?: CreateAiAgent['integrations'];
51
+ imageUrl?: CreateAiAgent['imageUrl'];
52
+ modelConfig?: CreateAiAgent['modelConfig'];
53
+ };
54
+ /** Canonical digest of create fields (order-stable). Shared by elicitation and preview tokens. */
55
+ export declare function digestCreateAgentPayload(payload: AgentCreatePayloadFields): string;
56
+ /** Empty tag list means all explores — normalize to null for API/digest consistency. */
57
+ export declare function normalizeAgentTags(tags: string[] | null | undefined): string[] | null;
58
+ export type AgentElevationWarningCode = 'ELEVATED_CONTENT_TOOLS' | 'ELEVATED_CONTENT_WITHOUT_DATA' | 'ELEVATED_DATA_ACCESS' | 'ELEVATED_PUBLIC_VISIBILITY' | 'ELEVATED_SQL_MODE' | 'ELEVATED_USER_CONTEXT';
59
+ export type AgentElevationWarning = {
60
+ code: AgentElevationWarningCode;
61
+ message: string;
62
+ };
63
+ export type AgentCreateVisibilityInput = SecureAgentCreateFlags & {
64
+ groupAccess?: string[];
65
+ userAccess?: string[];
66
+ };
67
+ /** Merge partial create args over secure defaults (explicit false/true honored). */
68
+ export declare function resolveSecureAgentCreateFlags(partial: SecureAgentCreateFlags): ResolvedSecureAgentCreateFlags;
69
+ /** Build a create-agent API body with secure defaults applied (MCP, CLI, agentops). */
70
+ export declare function buildSecureCreateAiAgentBody(input: BuildSecureCreateAiAgentInput): CreateAiAgent;
71
+ /** Human-readable permission lines for create elicitation (UI-aligned labels). */
72
+ export declare function formatAgentPermissionSummary(partial: SecureAgentCreateFlags, visibilityInput?: Pick<AgentCreateVisibilityInput, 'groupAccess' | 'userAccess'>): string[];
73
+ /** Warn when resolved flags deviate from the secure baseline. */
74
+ export declare function collectElevationWarnings(partial: AgentCreateVisibilityInput): AgentElevationWarning[];
75
+ /** Elevation warnings for update patches — only fields explicitly set in the patch. */
76
+ export declare function collectElevationWarningsFromPatch(patch: Pick<AgentCreateVisibilityInput, 'groupAccess' | 'userAccess'> & SecureAgentCreateFlags): AgentElevationWarning[];
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /**
3
+ * Secure-by-default flags for Lightdash AI agent create (MCP, CLI, agentops).
4
+ * More conservative than Lightdash UI defaults — elevation is explicit opt-in.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.AGENT_PERMISSION_UI_LABELS = exports.SECURE_AGENT_CREATE_DEFAULTS = void 0;
8
+ exports.digestCreateAgentPayload = digestCreateAgentPayload;
9
+ exports.normalizeAgentTags = normalizeAgentTags;
10
+ exports.resolveSecureAgentCreateFlags = resolveSecureAgentCreateFlags;
11
+ exports.buildSecureCreateAiAgentBody = buildSecureCreateAiAgentBody;
12
+ exports.formatAgentPermissionSummary = formatAgentPermissionSummary;
13
+ exports.collectElevationWarnings = collectElevationWarnings;
14
+ exports.collectElevationWarningsFromPatch = collectElevationWarningsFromPatch;
15
+ const node_crypto_1 = require("node:crypto");
16
+ exports.SECURE_AGENT_CREATE_DEFAULTS = {
17
+ enableDataAccess: false,
18
+ enableContentTools: false,
19
+ enableSqlMode: false,
20
+ enableUserContext: false,
21
+ adminOnly: true,
22
+ enableSelfImprovement: false,
23
+ };
24
+ exports.AGENT_PERMISSION_UI_LABELS = {
25
+ enableDataAccess: 'Read rows behind chart',
26
+ enableContentTools: 'Create/edit content',
27
+ enableSqlMode: 'SQL mode',
28
+ enableUserContext: 'User context',
29
+ enableSelfImprovement: 'Self-improvement',
30
+ adminOnly: 'Admins & developers only',
31
+ };
32
+ function sortedStrings(values) {
33
+ return values === undefined ? [] : [...values].sort();
34
+ }
35
+ function canonicalTagsForDigest(tags) {
36
+ const normalized = normalizeAgentTags(tags);
37
+ return normalized == null ? null : sortedStrings(normalized);
38
+ }
39
+ function canonicalCreateAgentPayload(payload) {
40
+ var _a, _b;
41
+ const flags = resolveSecureAgentCreateFlags(payload);
42
+ return {
43
+ adminOnly: flags.adminOnly,
44
+ description: (_a = payload.description) !== null && _a !== void 0 ? _a : null,
45
+ enableContentTools: flags.enableContentTools,
46
+ enableDataAccess: flags.enableDataAccess,
47
+ enableSelfImprovement: flags.enableSelfImprovement,
48
+ enableSqlMode: flags.enableSqlMode,
49
+ enableUserContext: flags.enableUserContext,
50
+ groupAccess: sortedStrings(payload.groupAccess),
51
+ instruction: (_b = payload.instruction) !== null && _b !== void 0 ? _b : null,
52
+ mcpServerUuids: sortedStrings(payload.mcpServerUuids),
53
+ name: payload.name,
54
+ spaceAccess: sortedStrings(payload.spaceAccess),
55
+ tags: canonicalTagsForDigest(payload.tags),
56
+ userAccess: sortedStrings(payload.userAccess),
57
+ };
58
+ }
59
+ /** Canonical digest of create fields (order-stable). Shared by elicitation and preview tokens. */
60
+ function digestCreateAgentPayload(payload) {
61
+ return (0, node_crypto_1.createHash)('sha256')
62
+ .update(JSON.stringify(canonicalCreateAgentPayload(payload)))
63
+ .digest('hex');
64
+ }
65
+ /** Empty tag list means all explores — normalize to null for API/digest consistency. */
66
+ function normalizeAgentTags(tags) {
67
+ if (tags == null || tags.length === 0) {
68
+ return null;
69
+ }
70
+ return tags;
71
+ }
72
+ /** Merge partial create args over secure defaults (explicit false/true honored). */
73
+ function resolveSecureAgentCreateFlags(partial) {
74
+ var _a, _b, _c, _d, _e, _f;
75
+ return {
76
+ enableDataAccess: (_a = partial.enableDataAccess) !== null && _a !== void 0 ? _a : exports.SECURE_AGENT_CREATE_DEFAULTS.enableDataAccess,
77
+ enableContentTools: (_b = partial.enableContentTools) !== null && _b !== void 0 ? _b : exports.SECURE_AGENT_CREATE_DEFAULTS.enableContentTools,
78
+ enableSqlMode: (_c = partial.enableSqlMode) !== null && _c !== void 0 ? _c : exports.SECURE_AGENT_CREATE_DEFAULTS.enableSqlMode,
79
+ enableUserContext: (_d = partial.enableUserContext) !== null && _d !== void 0 ? _d : exports.SECURE_AGENT_CREATE_DEFAULTS.enableUserContext,
80
+ adminOnly: (_e = partial.adminOnly) !== null && _e !== void 0 ? _e : exports.SECURE_AGENT_CREATE_DEFAULTS.adminOnly,
81
+ enableSelfImprovement: (_f = partial.enableSelfImprovement) !== null && _f !== void 0 ? _f : exports.SECURE_AGENT_CREATE_DEFAULTS.enableSelfImprovement,
82
+ };
83
+ }
84
+ /** Build a create-agent API body with secure defaults applied (MCP, CLI, agentops). */
85
+ function buildSecureCreateAiAgentBody(input) {
86
+ var _a, _b, _c, _d, _e, _f, _g;
87
+ const flags = resolveSecureAgentCreateFlags(input);
88
+ return Object.assign(Object.assign({ name: input.name, projectUuid: input.projectUuid, description: (_a = input.description) !== null && _a !== void 0 ? _a : null, instruction: (_b = input.instruction) !== null && _b !== void 0 ? _b : null, tags: normalizeAgentTags(input.tags), integrations: (_c = input.integrations) !== null && _c !== void 0 ? _c : [], imageUrl: (_d = input.imageUrl) !== null && _d !== void 0 ? _d : null, groupAccess: (_e = input.groupAccess) !== null && _e !== void 0 ? _e : [], userAccess: (_f = input.userAccess) !== null && _f !== void 0 ? _f : [], spaceAccess: (_g = input.spaceAccess) !== null && _g !== void 0 ? _g : [], enableDataAccess: flags.enableDataAccess, enableContentTools: flags.enableContentTools, enableSqlMode: flags.enableSqlMode, enableUserContext: flags.enableUserContext, adminOnly: flags.adminOnly, enableSelfImprovement: flags.enableSelfImprovement, version: 1 }, (input.mcpServerUuids !== undefined ? { mcpServerUuids: input.mcpServerUuids } : {})), (input.modelConfig !== undefined ? { modelConfig: input.modelConfig } : {}));
89
+ }
90
+ function onOff(value) {
91
+ return value ? 'on' : 'off';
92
+ }
93
+ function formatVisibility(resolved, input) {
94
+ var _a, _b, _c, _d;
95
+ if (resolved.adminOnly) {
96
+ return 'Admins & developers only';
97
+ }
98
+ const groupCount = (_b = (_a = input.groupAccess) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
99
+ const userCount = (_d = (_c = input.userAccess) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
100
+ if (groupCount > 0 || userCount > 0) {
101
+ return `Specific users/groups (${userCount} user(s), ${groupCount} group(s))`;
102
+ }
103
+ return 'Everyone in the project';
104
+ }
105
+ /** Human-readable permission lines for create elicitation (UI-aligned labels). */
106
+ function formatAgentPermissionSummary(partial, visibilityInput = {}) {
107
+ const resolved = resolveSecureAgentCreateFlags(partial);
108
+ return [
109
+ ` ${exports.AGENT_PERMISSION_UI_LABELS.enableDataAccess}: ${onOff(resolved.enableDataAccess)}`,
110
+ ` ${exports.AGENT_PERMISSION_UI_LABELS.enableContentTools}: ${onOff(resolved.enableContentTools)}`,
111
+ ` ${exports.AGENT_PERMISSION_UI_LABELS.enableSqlMode}: ${onOff(resolved.enableSqlMode)}`,
112
+ ` ${exports.AGENT_PERMISSION_UI_LABELS.enableUserContext}: ${onOff(resolved.enableUserContext)}`,
113
+ ` ${exports.AGENT_PERMISSION_UI_LABELS.enableSelfImprovement}: ${onOff(resolved.enableSelfImprovement)}`,
114
+ ` Who can use: ${formatVisibility(resolved, Object.assign(Object.assign({}, partial), visibilityInput))}`,
115
+ ];
116
+ }
117
+ const CONTENT_WITHOUT_DATA_WARNING = {
118
+ code: 'ELEVATED_CONTENT_WITHOUT_DATA',
119
+ message: 'Content editing is enabled without data access. Lightdash locks content tools until data access is on.',
120
+ };
121
+ const CAPABILITY_ELEVATIONS = [
122
+ {
123
+ code: 'ELEVATED_DATA_ACCESS',
124
+ isActive: (resolved) => resolved.enableDataAccess,
125
+ isPatchActive: (patch) => patch.enableDataAccess === true,
126
+ createMessage: 'Agent has data access enabled (Read rows behind chart). Warehouse row values may be sent to the LLM.',
127
+ updateMessage: 'Update enables data access (Read rows behind chart). Warehouse row values may be sent to the LLM.',
128
+ },
129
+ {
130
+ code: 'ELEVATED_CONTENT_TOOLS',
131
+ isActive: (resolved) => resolved.enableContentTools,
132
+ isPatchActive: (patch) => patch.enableContentTools === true,
133
+ createMessage: 'Agent has content editing enabled. It may create or mutate saved charts and dashboards.',
134
+ updateMessage: 'Update enables content editing. The agent may create or mutate saved charts and dashboards.',
135
+ },
136
+ {
137
+ code: 'ELEVATED_SQL_MODE',
138
+ isActive: (resolved) => resolved.enableSqlMode,
139
+ isPatchActive: (patch) => patch.enableSqlMode === true,
140
+ createMessage: 'Agent has SQL mode enabled. It may run raw SQL against the warehouse (subject to user approval per query).',
141
+ updateMessage: 'Update enables SQL mode. The agent may run raw SQL against the warehouse (subject to user approval per query).',
142
+ },
143
+ {
144
+ code: 'ELEVATED_USER_CONTEXT',
145
+ isActive: (resolved) => resolved.enableUserContext,
146
+ isPatchActive: (patch) => patch.enableUserContext === true,
147
+ createMessage: 'Agent has user context enabled. It receives the requesting user name, role, and group memberships.',
148
+ updateMessage: 'Update enables user context. The agent receives the requesting user name, role, and group memberships.',
149
+ },
150
+ ];
151
+ function visibilityElevationMessage(groupCount, userCount, prefix, messages) {
152
+ return {
153
+ code: 'ELEVATED_PUBLIC_VISIBILITY',
154
+ message: groupCount === 0 && userCount === 0
155
+ ? `${prefix} ${messages.everyone}`
156
+ : `${prefix} ${messages.specific}`,
157
+ };
158
+ }
159
+ /** Warn when resolved flags deviate from the secure baseline. */
160
+ function collectElevationWarnings(partial) {
161
+ var _a, _b, _c, _d;
162
+ const resolved = resolveSecureAgentCreateFlags(partial);
163
+ const warnings = [];
164
+ for (const check of CAPABILITY_ELEVATIONS) {
165
+ if (check.isActive(resolved)) {
166
+ warnings.push({ code: check.code, message: check.createMessage });
167
+ }
168
+ }
169
+ if (!resolved.adminOnly) {
170
+ warnings.push(visibilityElevationMessage((_b = (_a = partial.groupAccess) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, (_d = (_c = partial.userAccess) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0, 'Agent visibility is', {
171
+ everyone: 'Everyone in the project (adminOnly: false). All project members can use this agent.',
172
+ specific: 'limited to specific users/groups (adminOnly: false). Verify access lists before release.',
173
+ }));
174
+ }
175
+ if (resolved.enableContentTools && !resolved.enableDataAccess) {
176
+ warnings.push(CONTENT_WITHOUT_DATA_WARNING);
177
+ }
178
+ return warnings;
179
+ }
180
+ function pushCapabilityElevation(warnings, patch) {
181
+ for (const check of CAPABILITY_ELEVATIONS) {
182
+ if (check.isPatchActive(patch)) {
183
+ warnings.push({ code: check.code, message: check.updateMessage });
184
+ }
185
+ }
186
+ if (patch.enableContentTools === true && patch.enableDataAccess === false) {
187
+ warnings.push(Object.assign(Object.assign({}, CONTENT_WITHOUT_DATA_WARNING), { message: 'Content editing enabled without data access in this patch. Lightdash locks content tools until data access is on.' }));
188
+ }
189
+ }
190
+ function pushVisibilityElevation(warnings, patch) {
191
+ var _a, _b, _c, _d, _e, _f, _g, _h;
192
+ if (patch.adminOnly === false) {
193
+ warnings.push(visibilityElevationMessage((_b = (_a = patch.groupAccess) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, (_d = (_c = patch.userAccess) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0, 'Update sets visibility to', {
194
+ everyone: 'Everyone in the project (adminOnly: false).',
195
+ specific: `specific users/groups (adminOnly: false; ${(_f = (_e = patch.userAccess) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0} user(s), ${(_h = (_g = patch.groupAccess) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0} group(s)).`,
196
+ }));
197
+ }
198
+ }
199
+ /** Elevation warnings for update patches — only fields explicitly set in the patch. */
200
+ function collectElevationWarningsFromPatch(patch) {
201
+ const warnings = [];
202
+ pushCapabilityElevation(warnings, patch);
203
+ pushVisibilityElevation(warnings, patch);
204
+ return warnings;
205
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const secure_create_defaults_js_1 = require("./secure-create-defaults.js");
5
+ (0, vitest_1.describe)('resolveSecureAgentCreateFlags', () => {
6
+ (0, vitest_1.it)('returns secure defaults when partial is empty', () => {
7
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.resolveSecureAgentCreateFlags)({})).toEqual(secure_create_defaults_js_1.SECURE_AGENT_CREATE_DEFAULTS);
8
+ });
9
+ (0, vitest_1.it)('honors explicit overrides', () => {
10
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.resolveSecureAgentCreateFlags)({
11
+ enableDataAccess: true,
12
+ adminOnly: false,
13
+ })).toEqual(Object.assign(Object.assign({}, secure_create_defaults_js_1.SECURE_AGENT_CREATE_DEFAULTS), { enableDataAccess: true, adminOnly: false }));
14
+ });
15
+ });
16
+ (0, vitest_1.describe)('normalizeAgentTags', () => {
17
+ (0, vitest_1.it)('maps empty arrays to null', () => {
18
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.normalizeAgentTags)([])).toBeNull();
19
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.normalizeAgentTags)(null)).toBeNull();
20
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.normalizeAgentTags)(['orders'])).toEqual(['orders']);
21
+ });
22
+ });
23
+ (0, vitest_1.describe)('buildSecureCreateAiAgentBody', () => {
24
+ (0, vitest_1.it)('applies secure defaults and standard create scaffolding', () => {
25
+ const body = (0, secure_create_defaults_js_1.buildSecureCreateAiAgentBody)({
26
+ name: 'Smoke',
27
+ projectUuid: '550e8400-e29b-41d4-a716-446655440000',
28
+ });
29
+ (0, vitest_1.expect)(body).toMatchObject(Object.assign(Object.assign({}, secure_create_defaults_js_1.SECURE_AGENT_CREATE_DEFAULTS), { name: 'Smoke', integrations: [], imageUrl: null, groupAccess: [], userAccess: [], spaceAccess: [], version: 1 }));
30
+ });
31
+ (0, vitest_1.it)('preserves integrations, imageUrl, and modelConfig from file input', () => {
32
+ const modelConfig = { modelProvider: 'openai', modelName: 'gpt-4o' };
33
+ const body = (0, secure_create_defaults_js_1.buildSecureCreateAiAgentBody)({
34
+ name: 'Advanced',
35
+ projectUuid: '550e8400-e29b-41d4-a716-446655440000',
36
+ integrations: [{ type: 'slack', channelId: 'C123' }],
37
+ imageUrl: 'https://example.com/agent.png',
38
+ modelConfig,
39
+ });
40
+ (0, vitest_1.expect)(body.integrations).toEqual([{ type: 'slack', channelId: 'C123' }]);
41
+ (0, vitest_1.expect)(body.imageUrl).toBe('https://example.com/agent.png');
42
+ (0, vitest_1.expect)(body.modelConfig).toEqual(modelConfig);
43
+ });
44
+ });
45
+ (0, vitest_1.describe)('collectElevationWarnings', () => {
46
+ (0, vitest_1.it)('returns no warnings for secure baseline', () => {
47
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.collectElevationWarnings)({})).toEqual([]);
48
+ });
49
+ (0, vitest_1.it)('warns on elevated data access and public visibility', () => {
50
+ const warnings = (0, secure_create_defaults_js_1.collectElevationWarnings)({
51
+ enableDataAccess: true,
52
+ adminOnly: false,
53
+ });
54
+ (0, vitest_1.expect)(warnings.map((w) => w.code)).toEqual([
55
+ 'ELEVATED_DATA_ACCESS',
56
+ 'ELEVATED_PUBLIC_VISIBILITY',
57
+ ]);
58
+ });
59
+ (0, vitest_1.it)('warns when content tools enabled without data access', () => {
60
+ const warnings = (0, secure_create_defaults_js_1.collectElevationWarnings)({ enableContentTools: true });
61
+ (0, vitest_1.expect)(warnings.map((w) => w.code)).toContain('ELEVATED_CONTENT_TOOLS');
62
+ (0, vitest_1.expect)(warnings.map((w) => w.code)).toContain('ELEVATED_CONTENT_WITHOUT_DATA');
63
+ });
64
+ (0, vitest_1.it)('warns on specific user/group visibility', () => {
65
+ const warnings = (0, secure_create_defaults_js_1.collectElevationWarnings)({
66
+ adminOnly: false,
67
+ userAccess: ['u1'],
68
+ groupAccess: [],
69
+ });
70
+ (0, vitest_1.expect)(warnings).toEqual([vitest_1.expect.objectContaining({ code: 'ELEVATED_PUBLIC_VISIBILITY' })]);
71
+ });
72
+ });
73
+ (0, vitest_1.describe)('digestCreateAgentPayload', () => {
74
+ (0, vitest_1.it)('is order-stable for tags and omits empty tag lists', () => {
75
+ const a = (0, secure_create_defaults_js_1.digestCreateAgentPayload)({ name: 'A', tags: ['b', 'a'], enableDataAccess: true });
76
+ const b = (0, secure_create_defaults_js_1.digestCreateAgentPayload)({ name: 'A', tags: ['a', 'b'], enableDataAccess: true });
77
+ (0, vitest_1.expect)(a).toBe(b);
78
+ const omitted = (0, secure_create_defaults_js_1.digestCreateAgentPayload)({ name: 'A' });
79
+ const empty = (0, secure_create_defaults_js_1.digestCreateAgentPayload)({ name: 'A', tags: [] });
80
+ (0, vitest_1.expect)(omitted).toBe(empty);
81
+ });
82
+ });
83
+ (0, vitest_1.describe)('collectElevationWarningsFromPatch', () => {
84
+ (0, vitest_1.it)('returns empty when patch has no permission fields', () => {
85
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.collectElevationWarningsFromPatch)({})).toEqual([]);
86
+ });
87
+ (0, vitest_1.it)('warns only when patch explicitly elevates', () => {
88
+ const warnings = (0, secure_create_defaults_js_1.collectElevationWarningsFromPatch)({ enableDataAccess: true });
89
+ (0, vitest_1.expect)(warnings.map((w) => w.code)).toContain('ELEVATED_DATA_ACCESS');
90
+ });
91
+ (0, vitest_1.it)('does not warn content-without-data when patch only enables content tools', () => {
92
+ (0, vitest_1.expect)((0, secure_create_defaults_js_1.collectElevationWarningsFromPatch)({ enableContentTools: true })).toEqual([
93
+ vitest_1.expect.objectContaining({ code: 'ELEVATED_CONTENT_TOOLS' }),
94
+ ]);
95
+ });
96
+ (0, vitest_1.it)('warns content-without-data when patch explicitly disables data access', () => {
97
+ const warnings = (0, secure_create_defaults_js_1.collectElevationWarningsFromPatch)({
98
+ enableContentTools: true,
99
+ enableDataAccess: false,
100
+ });
101
+ (0, vitest_1.expect)(warnings.map((w) => w.code)).toContain('ELEVATED_CONTENT_WITHOUT_DATA');
102
+ });
103
+ });
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export * from './input-validation';
4
4
  export * from './argument-validation';
5
5
  export * from './profile-ids';
6
6
  export * from './agent-safe';
7
+ export * from './ai-agents/secure-create-defaults';
8
+ export * from './ai-agents/document-limits';
7
9
  export * from './agentops/types';
8
10
  export * from './agentops/snapshots';
9
11
  export * from './agentops/formatters';
package/dist/index.js CHANGED
@@ -27,6 +27,10 @@ __exportStar(require("./argument-validation"), exports);
27
27
  __exportStar(require("./profile-ids"), exports);
28
28
  // Irrecoverable MCP tool denylist
29
29
  __exportStar(require("./agent-safe"), exports);
30
+ // Secure AI agent create defaults (MCP, CLI, agentops)
31
+ __exportStar(require("./ai-agents/secure-create-defaults"), exports);
32
+ // AI agent knowledge document limits
33
+ __exportStar(require("./ai-agents/document-limits"), exports);
30
34
  // Export AgentOps bundle and gate types
31
35
  __exportStar(require("./agentops/types"), exports);
32
36
  __exportStar(require("./agentops/snapshots"), exports);