@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.
- package/dist/agentops/snapshots.d.ts +5 -0
- package/dist/agentops/snapshots.js +5 -0
- package/dist/agentops/types.d.ts +15 -0
- package/dist/agentops/types.js +36 -16
- package/dist/ai-agents/document-limits.d.ts +12 -0
- package/dist/ai-agents/document-limits.js +31 -0
- package/dist/ai-agents/document-limits.test.d.ts +1 -0
- package/dist/ai-agents/document-limits.test.js +23 -0
- package/dist/ai-agents/secure-create-defaults.d.ts +76 -0
- package/dist/ai-agents/secure-create-defaults.js +205 -0
- package/dist/ai-agents/secure-create-defaults.test.d.ts +1 -0
- package/dist/ai-agents/secure-create-defaults.test.js +103 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/types/lightdash-api.d.ts +1 -1
- package/dist/types/v1/ai-agents.d.ts +12 -0
- package/dist/types/v1/index.d.ts +6 -0
- package/dist/types/v1/lightdash-api.d.ts +12 -0
- package/package.json +1 -1
- package/src/agentops/snapshots.ts +10 -0
- package/src/agentops/types.ts +52 -7
- package/src/ai-agents/document-limits.test.ts +32 -0
- package/src/ai-agents/document-limits.ts +38 -0
- package/src/ai-agents/secure-create-defaults.test.ts +140 -0
- package/src/ai-agents/secure-create-defaults.ts +352 -0
- package/src/index.ts +6 -0
- package/src/types/lightdash-api.ts +6 -0
- package/src/types/v1/ai-agents.ts +16 -0
- package/src/types/v1/index.ts +7 -0
- package/src/types/v1/lightdash-api.ts +14 -0
|
@@ -25,4 +25,4 @@ export declare namespace LightdashApi {
|
|
|
25
25
|
export import V1 = V1Api.V1;
|
|
26
26
|
export import V2 = V2Api;
|
|
27
27
|
}
|
|
28
|
-
export type { Project, OrganizationProject, Organization, SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody, DashboardBasicDetailsWithTileTypes, DashboardAsCodeListResults, DashboardAsCodeUpsertResults, UpsertDashboardAsCodeBody, SpaceSummary, Space, CreateSpace, UpdateSpace, AddSpaceUserAccess, AddSpaceGroupAccess, SpaceMemberRole, ProjectMemberProfile, ProjectMemberRole, CreateProjectMember, UpdateProjectMember, ProjectGroupAccess, CreateProjectGroupAccessBody, UpdateProjectGroupAccess, AuthenticatedUser, MetricQueryRequest, CompileQueryRequest, ExecuteAsyncMetricQueryRequestParams, ExecuteAsyncSqlQueryRequestParams, ExecuteAsyncSavedChartRequestParams, ExecuteAsyncDashboardChartRequestParams, ExecuteAsyncUnderlyingDataRequestParams, RunQueryResults, CompiledQueryResults, ExecuteAsyncMetricQueryResults, ExecuteAsyncDashboardChartResults, ExecuteAsyncSqlQueryResults, AiAgentSummary, AiAgentAdminSortField, AiAgentsAdminThreadsResult, GetAiOrganizationSettingsResult, UpdateAiOrganizationSettings, UpdateAiOrganizationSettingsResult, GetAdminThreadsParams, AiAgent, CreateAiAgent, UpdateAiAgent, AiAgentThreadSummary, AiAgentThread, CreateAgentThreadBody, CreateAgentThreadMessageBody, CreateAgentThreadMessageResult, GenerateAgentThreadBody, GenerateAgentThreadResult, CreateEvaluationPrompt, CreateEvaluationBody, CreateEvaluationResult, UpdateEvaluationBody, AppendEvaluationBody, AiAgentEvaluationSummary, AiAgentEvaluation, AiAgentEvaluationRunSummary, AiAgentEvaluationRunsListResponse, AiAgentEvaluationRun, AiAgentEvaluationRunResult, AiModelOption, ReadinessScore, AiAgentExploreAccessSummary, ExploreAccessSummaryBody, AiAgentUserPreferences, GetAgentSuggestionsParams, AgentSuggestion, AgentSuggestionPromptChip, AgentSuggestionNavigateChip, AgentSuggestionTool, AgentSuggestionChip, AgentSuggestions, GenerateThreadTitleResult, CloneThreadBody, AiAgentVerifiedArtifact, AiAgentVerifiedArtifactsListResult, ListVerifiedArtifactsParams, AiAgentVerifiedQuestion, AiArtifact, AiAgentThreadMessageVizQuery, UpdateMessageFeedbackBody, AiMcpServerAuthType, AiMcpCredentialScope, AiMcpServerConnectionStatus, AiMcpServer, AiMcpServerTool, AiAgentMcpServerTool, CreateProjectMcpServerBody, AiAgentMcpServerToolUpdate, UpdateAgentMcpServerToolsBody, SqlApprovalDecision, SubmitSqlApprovalBody, SubmitSqlApprovalResult, AiRouterRouteRequest, AiRouterRouteResponseResult, ApiExploresResults, ApiExploreResults, } from './v1/lightdash-api';
|
|
28
|
+
export type { Project, OrganizationProject, Organization, SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody, DashboardBasicDetailsWithTileTypes, DashboardAsCodeListResults, DashboardAsCodeUpsertResults, UpsertDashboardAsCodeBody, SpaceSummary, Space, CreateSpace, UpdateSpace, AddSpaceUserAccess, AddSpaceGroupAccess, SpaceMemberRole, ProjectMemberProfile, ProjectMemberRole, CreateProjectMember, UpdateProjectMember, ProjectGroupAccess, CreateProjectGroupAccessBody, UpdateProjectGroupAccess, AuthenticatedUser, MetricQueryRequest, CompileQueryRequest, ExecuteAsyncMetricQueryRequestParams, ExecuteAsyncSqlQueryRequestParams, ExecuteAsyncSavedChartRequestParams, ExecuteAsyncDashboardChartRequestParams, ExecuteAsyncUnderlyingDataRequestParams, RunQueryResults, CompiledQueryResults, ExecuteAsyncMetricQueryResults, ExecuteAsyncDashboardChartResults, ExecuteAsyncSqlQueryResults, AiAgentSummary, AiAgentAdminSortField, AiAgentsAdminThreadsResult, GetAiOrganizationSettingsResult, UpdateAiOrganizationSettings, UpdateAiOrganizationSettingsResult, GetAdminThreadsParams, AiAgent, CreateAiAgent, UpdateAiAgent, AiAgentThreadSummary, AiAgentThread, CreateAgentThreadBody, CreateAgentThreadMessageBody, CreateAgentThreadMessageResult, GenerateAgentThreadBody, GenerateAgentThreadResult, CreateEvaluationPrompt, CreateEvaluationBody, CreateEvaluationResult, UpdateEvaluationBody, AppendEvaluationBody, AiAgentEvaluationSummary, AiAgentEvaluation, AiAgentEvaluationRunSummary, AiAgentEvaluationRunsListResponse, AiAgentEvaluationRun, AiAgentEvaluationRunResult, AiModelOption, ReadinessScore, AiAgentExploreAccessSummary, ExploreAccessSummaryBody, AiAgentUserPreferences, GetAgentSuggestionsParams, AgentSuggestion, AgentSuggestionPromptChip, AgentSuggestionNavigateChip, AgentSuggestionTool, AgentSuggestionChip, AgentSuggestions, GenerateThreadTitleResult, CloneThreadBody, AiAgentDocument, AiAgentDocumentSummary, AiAgentDocumentContent, CreateAgentDocumentBody, UpdateAgentDocumentContentBody, UpdateAgentDocumentSettingsBody, AiAgentVerifiedArtifact, AiAgentVerifiedArtifactsListResult, ListVerifiedArtifactsParams, AiAgentVerifiedQuestion, AiArtifact, AiAgentThreadMessageVizQuery, UpdateMessageFeedbackBody, AiMcpServerAuthType, AiMcpCredentialScope, AiMcpServerConnectionStatus, AiMcpServer, AiMcpServerTool, AiAgentMcpServerTool, CreateProjectMcpServerBody, AiAgentMcpServerToolUpdate, UpdateAgentMcpServerToolsBody, SqlApprovalDecision, SubmitSqlApprovalBody, SubmitSqlApprovalResult, AiRouterRouteRequest, AiRouterRouteResponseResult, ApiExploresResults, ApiExploreResults, } from './v1/lightdash-api';
|
|
@@ -135,6 +135,18 @@ export declare namespace AiAgents {
|
|
|
135
135
|
promptUuid: string;
|
|
136
136
|
createdFrom?: 'evals' | 'web_app';
|
|
137
137
|
}
|
|
138
|
+
/** Full knowledge document (POST create response). */
|
|
139
|
+
type AiAgentDocument = components['schemas']['AiAgentDocument'];
|
|
140
|
+
/** Document summary in list responses (no full content). */
|
|
141
|
+
type AiAgentDocumentSummary = components['schemas']['AiAgentDocumentSummary'];
|
|
142
|
+
/** Document content payload (GET …/content). */
|
|
143
|
+
type AiAgentDocumentContent = components['schemas']['AiAgentDocumentContent'];
|
|
144
|
+
/** Request body for POST …/documents. */
|
|
145
|
+
type CreateAgentDocumentBody = components['schemas']['ApiCreateAgentDocument'];
|
|
146
|
+
/** Request body for PATCH …/documents/{uuid}/content. */
|
|
147
|
+
type UpdateAgentDocumentContentBody = components['schemas']['ApiUpdateAgentDocumentContent'];
|
|
148
|
+
/** Request body for PATCH …/documents/{uuid} settings. */
|
|
149
|
+
type UpdateAgentDocumentSettingsBody = components['schemas']['ApiUpdateAgentDocument'];
|
|
138
150
|
/** Verified artifact summary (GET …/verified-artifacts). */
|
|
139
151
|
type AiAgentVerifiedArtifact = components['schemas']['AiAgentVerifiedArtifact'];
|
|
140
152
|
/** Paginated verified artifacts list (`results` of verified-artifacts response). */
|
package/dist/types/v1/index.d.ts
CHANGED
|
@@ -125,6 +125,12 @@ export declare namespace V1 {
|
|
|
125
125
|
type AgentSuggestions = A.AgentSuggestions;
|
|
126
126
|
type GenerateThreadTitleResult = A.GenerateThreadTitleResult;
|
|
127
127
|
type CloneThreadBody = A.CloneThreadBody;
|
|
128
|
+
type AiAgentDocument = A.AiAgentDocument;
|
|
129
|
+
type AiAgentDocumentSummary = A.AiAgentDocumentSummary;
|
|
130
|
+
type AiAgentDocumentContent = A.AiAgentDocumentContent;
|
|
131
|
+
type CreateAgentDocumentBody = A.CreateAgentDocumentBody;
|
|
132
|
+
type UpdateAgentDocumentContentBody = A.UpdateAgentDocumentContentBody;
|
|
133
|
+
type UpdateAgentDocumentSettingsBody = A.UpdateAgentDocumentSettingsBody;
|
|
128
134
|
type AiAgentVerifiedArtifact = A.AiAgentVerifiedArtifact;
|
|
129
135
|
type AiAgentVerifiedArtifactsListResult = A.AiAgentVerifiedArtifactsListResult;
|
|
130
136
|
type ListVerifiedArtifactsParams = A.ListVerifiedArtifactsParams;
|
|
@@ -177,6 +177,12 @@ export declare namespace LightdashApi {
|
|
|
177
177
|
type AgentSuggestions = AiAgentsTypes.AgentSuggestions;
|
|
178
178
|
type GenerateThreadTitleResult = AiAgentsTypes.GenerateThreadTitleResult;
|
|
179
179
|
type CloneThreadBody = AiAgentsTypes.CloneThreadBody;
|
|
180
|
+
type AiAgentDocument = AiAgentsTypes.AiAgentDocument;
|
|
181
|
+
type AiAgentDocumentSummary = AiAgentsTypes.AiAgentDocumentSummary;
|
|
182
|
+
type AiAgentDocumentContent = AiAgentsTypes.AiAgentDocumentContent;
|
|
183
|
+
type CreateAgentDocumentBody = AiAgentsTypes.CreateAgentDocumentBody;
|
|
184
|
+
type UpdateAgentDocumentContentBody = AiAgentsTypes.UpdateAgentDocumentContentBody;
|
|
185
|
+
type UpdateAgentDocumentSettingsBody = AiAgentsTypes.UpdateAgentDocumentSettingsBody;
|
|
180
186
|
type AiAgentVerifiedArtifact = AiAgentsTypes.AiAgentVerifiedArtifact;
|
|
181
187
|
type AiAgentVerifiedArtifactsListResult = AiAgentsTypes.AiAgentVerifiedArtifactsListResult;
|
|
182
188
|
type ListVerifiedArtifactsParams = AiAgentsTypes.ListVerifiedArtifactsParams;
|
|
@@ -321,6 +327,12 @@ export type AgentSuggestionChip = AiAgents.AgentSuggestionChip;
|
|
|
321
327
|
export type AgentSuggestions = AiAgents.AgentSuggestions;
|
|
322
328
|
export type GenerateThreadTitleResult = AiAgents.GenerateThreadTitleResult;
|
|
323
329
|
export type CloneThreadBody = AiAgents.CloneThreadBody;
|
|
330
|
+
export type AiAgentDocument = AiAgents.AiAgentDocument;
|
|
331
|
+
export type AiAgentDocumentSummary = AiAgents.AiAgentDocumentSummary;
|
|
332
|
+
export type AiAgentDocumentContent = AiAgents.AiAgentDocumentContent;
|
|
333
|
+
export type CreateAgentDocumentBody = AiAgents.CreateAgentDocumentBody;
|
|
334
|
+
export type UpdateAgentDocumentContentBody = AiAgents.UpdateAgentDocumentContentBody;
|
|
335
|
+
export type UpdateAgentDocumentSettingsBody = AiAgents.UpdateAgentDocumentSettingsBody;
|
|
324
336
|
export type AiAgentVerifiedArtifact = AiAgents.AiAgentVerifiedArtifact;
|
|
325
337
|
export type AiAgentVerifiedArtifactsListResult = AiAgents.AiAgentVerifiedArtifactsListResult;
|
|
326
338
|
export type ListVerifiedArtifactsParams = AiAgents.ListVerifiedArtifactsParams;
|
package/package.json
CHANGED
|
@@ -24,7 +24,12 @@ export function toAgentSnapshot(agent: {
|
|
|
24
24
|
description: string | null;
|
|
25
25
|
instruction: string | null;
|
|
26
26
|
tags: string[] | null;
|
|
27
|
+
spaceAccess?: string[];
|
|
27
28
|
enableDataAccess?: boolean;
|
|
29
|
+
enableContentTools?: boolean;
|
|
30
|
+
enableSqlMode?: boolean;
|
|
31
|
+
enableUserContext?: boolean;
|
|
32
|
+
adminOnly?: boolean;
|
|
28
33
|
enableSelfImprovement?: boolean;
|
|
29
34
|
}): AgentStateSnapshot {
|
|
30
35
|
return {
|
|
@@ -33,7 +38,12 @@ export function toAgentSnapshot(agent: {
|
|
|
33
38
|
description: agent.description,
|
|
34
39
|
instruction: agent.instruction,
|
|
35
40
|
tags: agent.tags,
|
|
41
|
+
spaceAccess: agent.spaceAccess,
|
|
36
42
|
enableDataAccess: agent.enableDataAccess,
|
|
43
|
+
enableContentTools: agent.enableContentTools,
|
|
44
|
+
enableSqlMode: agent.enableSqlMode,
|
|
45
|
+
enableUserContext: agent.enableUserContext,
|
|
46
|
+
adminOnly: agent.adminOnly,
|
|
37
47
|
enableSelfImprovement: agent.enableSelfImprovement,
|
|
38
48
|
};
|
|
39
49
|
}
|
package/src/agentops/types.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { parse as parseYaml } from 'yaml';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
+
import { normalizeAgentTags } from '../ai-agents/secure-create-defaults.js';
|
|
10
|
+
|
|
9
11
|
// ─── Shared metadata ─────────────────────────────────────────────────────────
|
|
10
12
|
|
|
11
13
|
const metadataSchema = z.object({
|
|
@@ -44,7 +46,12 @@ const bundleAgentSchema = z.object({
|
|
|
44
46
|
instruction: z.string().nullable().optional(),
|
|
45
47
|
tags: z.array(z.string()).nullable().optional(),
|
|
46
48
|
enableDataAccess: z.boolean().optional(),
|
|
49
|
+
enableContentTools: z.boolean().optional(),
|
|
50
|
+
enableSqlMode: z.boolean().optional(),
|
|
51
|
+
enableUserContext: z.boolean().optional(),
|
|
52
|
+
adminOnly: z.boolean().optional(),
|
|
47
53
|
enableSelfImprovement: z.boolean().optional(),
|
|
54
|
+
spaceAccess: z.array(z.string().uuid()).optional(),
|
|
48
55
|
evaluations: z.array(bundleEvaluationSchema).optional().default([]),
|
|
49
56
|
});
|
|
50
57
|
|
|
@@ -142,7 +149,12 @@ export interface AgentStateSnapshot {
|
|
|
142
149
|
description: string | null;
|
|
143
150
|
instruction: string | null;
|
|
144
151
|
tags: string[] | null;
|
|
152
|
+
spaceAccess?: string[];
|
|
145
153
|
enableDataAccess?: boolean;
|
|
154
|
+
enableContentTools?: boolean;
|
|
155
|
+
enableSqlMode?: boolean;
|
|
156
|
+
enableUserContext?: boolean;
|
|
157
|
+
adminOnly?: boolean;
|
|
146
158
|
enableSelfImprovement?: boolean;
|
|
147
159
|
}
|
|
148
160
|
|
|
@@ -247,13 +259,24 @@ function promptsEqual(
|
|
|
247
259
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
248
260
|
}
|
|
249
261
|
|
|
262
|
+
const OPTIONAL_AGENT_BOOLEAN_FIELDS = [
|
|
263
|
+
'enableDataAccess',
|
|
264
|
+
'enableContentTools',
|
|
265
|
+
'enableSqlMode',
|
|
266
|
+
'enableUserContext',
|
|
267
|
+
'adminOnly',
|
|
268
|
+
'enableSelfImprovement',
|
|
269
|
+
] as const satisfies ReadonlyArray<keyof AgentStateSnapshot & keyof BundleAgentSpec>;
|
|
270
|
+
|
|
250
271
|
function agentFieldsToCompare(agent: BundleAgentSpec): Array<keyof AgentStateSnapshot> {
|
|
251
272
|
const fields: Array<keyof AgentStateSnapshot> = ['name', 'description', 'instruction', 'tags'];
|
|
252
|
-
if (agent.
|
|
253
|
-
fields.push('
|
|
273
|
+
if (agent.spaceAccess !== undefined) {
|
|
274
|
+
fields.push('spaceAccess');
|
|
254
275
|
}
|
|
255
|
-
|
|
256
|
-
|
|
276
|
+
for (const field of OPTIONAL_AGENT_BOOLEAN_FIELDS) {
|
|
277
|
+
if (agent[field] !== undefined) {
|
|
278
|
+
fields.push(field);
|
|
279
|
+
}
|
|
257
280
|
}
|
|
258
281
|
return fields;
|
|
259
282
|
}
|
|
@@ -264,10 +287,14 @@ function normalizeAgentBooleanFlag(value: boolean | undefined): boolean {
|
|
|
264
287
|
}
|
|
265
288
|
|
|
266
289
|
function normalizeTags(tags: string[] | null | undefined): string[] | null {
|
|
267
|
-
|
|
268
|
-
|
|
290
|
+
return normalizeAgentTags(tags);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function normalizeSpaceAccess(spaceAccess: string[] | undefined): string[] | undefined {
|
|
294
|
+
if (spaceAccess === undefined) {
|
|
295
|
+
return undefined;
|
|
269
296
|
}
|
|
270
|
-
return
|
|
297
|
+
return [...spaceAccess].sort();
|
|
271
298
|
}
|
|
272
299
|
|
|
273
300
|
function pickAgentFields(agent: AgentStateSnapshot): Partial<AgentStateSnapshot> {
|
|
@@ -276,7 +303,14 @@ function pickAgentFields(agent: AgentStateSnapshot): Partial<AgentStateSnapshot>
|
|
|
276
303
|
description: agent.description,
|
|
277
304
|
instruction: agent.instruction,
|
|
278
305
|
tags: normalizeTags(agent.tags),
|
|
306
|
+
...(agent.spaceAccess !== undefined
|
|
307
|
+
? { spaceAccess: normalizeSpaceAccess(agent.spaceAccess) }
|
|
308
|
+
: {}),
|
|
279
309
|
enableDataAccess: normalizeAgentBooleanFlag(agent.enableDataAccess),
|
|
310
|
+
enableContentTools: normalizeAgentBooleanFlag(agent.enableContentTools),
|
|
311
|
+
enableSqlMode: normalizeAgentBooleanFlag(agent.enableSqlMode),
|
|
312
|
+
enableUserContext: normalizeAgentBooleanFlag(agent.enableUserContext),
|
|
313
|
+
adminOnly: normalizeAgentBooleanFlag(agent.adminOnly),
|
|
280
314
|
enableSelfImprovement: normalizeAgentBooleanFlag(agent.enableSelfImprovement),
|
|
281
315
|
};
|
|
282
316
|
}
|
|
@@ -288,7 +322,18 @@ function desiredAgentToSnapshot(agent: BundleAgentSpec, uuid: string): AgentStat
|
|
|
288
322
|
description: agent.description ?? null,
|
|
289
323
|
instruction: agent.instruction ?? null,
|
|
290
324
|
tags: normalizeTags(agent.tags ?? null),
|
|
325
|
+
...(agent.spaceAccess !== undefined
|
|
326
|
+
? { spaceAccess: normalizeSpaceAccess(agent.spaceAccess) }
|
|
327
|
+
: {}),
|
|
291
328
|
...(agent.enableDataAccess !== undefined ? { enableDataAccess: agent.enableDataAccess } : {}),
|
|
329
|
+
...(agent.enableContentTools !== undefined
|
|
330
|
+
? { enableContentTools: agent.enableContentTools }
|
|
331
|
+
: {}),
|
|
332
|
+
...(agent.enableSqlMode !== undefined ? { enableSqlMode: agent.enableSqlMode } : {}),
|
|
333
|
+
...(agent.enableUserContext !== undefined
|
|
334
|
+
? { enableUserContext: agent.enableUserContext }
|
|
335
|
+
: {}),
|
|
336
|
+
...(agent.adminOnly !== undefined ? { adminOnly: agent.adminOnly } : {}),
|
|
292
337
|
...(agent.enableSelfImprovement !== undefined
|
|
293
338
|
? { enableSelfImprovement: agent.enableSelfImprovement }
|
|
294
339
|
: {}),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AGENT_DOCUMENT_MAX_BYTES,
|
|
5
|
+
agentDocumentContentByteLength,
|
|
6
|
+
defaultAgentDocumentFilename,
|
|
7
|
+
isAgentDocumentContentWithinLimit,
|
|
8
|
+
isAllowedAgentDocumentMimeType,
|
|
9
|
+
} from './document-limits.js';
|
|
10
|
+
|
|
11
|
+
describe('document-limits', () => {
|
|
12
|
+
it('measures UTF-8 byte length', () => {
|
|
13
|
+
expect(agentDocumentContentByteLength('hello')).toBe(5);
|
|
14
|
+
expect(agentDocumentContentByteLength('€')).toBe(3);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('enforces the 20KB ceiling', () => {
|
|
18
|
+
expect(isAgentDocumentContentWithinLimit('x'.repeat(AGENT_DOCUMENT_MAX_BYTES))).toBe(true);
|
|
19
|
+
expect(isAgentDocumentContentWithinLimit('x'.repeat(AGENT_DOCUMENT_MAX_BYTES + 1))).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('allows markdown and plain text mime types only', () => {
|
|
23
|
+
expect(isAllowedAgentDocumentMimeType('text/markdown')).toBe(true);
|
|
24
|
+
expect(isAllowedAgentDocumentMimeType('text/plain')).toBe(true);
|
|
25
|
+
expect(isAllowedAgentDocumentMimeType('application/pdf')).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('derives default filenames from name and mime type', () => {
|
|
29
|
+
expect(defaultAgentDocumentFilename('Glossary', 'text/markdown')).toBe('Glossary.md');
|
|
30
|
+
expect(defaultAgentDocumentFilename('notes.txt', 'text/plain')).toBe('notes.txt');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightdash AI agent knowledge document limits (product docs: 20KB per document).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const AGENT_DOCUMENT_MAX_BYTES = 20_480;
|
|
6
|
+
|
|
7
|
+
export const AGENT_DOCUMENT_DEFAULT_MIME = 'text/markdown' as const;
|
|
8
|
+
|
|
9
|
+
export const AGENT_DOCUMENT_ALLOWED_MIME_TYPES = ['text/markdown', 'text/plain'] as const;
|
|
10
|
+
|
|
11
|
+
export type AgentDocumentMimeType = (typeof AGENT_DOCUMENT_ALLOWED_MIME_TYPES)[number];
|
|
12
|
+
|
|
13
|
+
export function agentDocumentContentByteLength(content: string): number {
|
|
14
|
+
return Buffer.byteLength(content, 'utf8');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isAgentDocumentContentWithinLimit(content: string): boolean {
|
|
18
|
+
return agentDocumentContentByteLength(content) <= AGENT_DOCUMENT_MAX_BYTES;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isAllowedAgentDocumentMimeType(
|
|
22
|
+
mimeType: string,
|
|
23
|
+
): mimeType is AgentDocumentMimeType {
|
|
24
|
+
return (AGENT_DOCUMENT_ALLOWED_MIME_TYPES as readonly string[]).includes(mimeType);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Derive a filename hint when the host omits originalFilename. */
|
|
28
|
+
export function defaultAgentDocumentFilename(
|
|
29
|
+
name: string,
|
|
30
|
+
mimeType: AgentDocumentMimeType,
|
|
31
|
+
): string {
|
|
32
|
+
const trimmed = name.trim();
|
|
33
|
+
const base = trimmed.length > 0 ? trimmed : 'document';
|
|
34
|
+
if (mimeType === 'text/plain') {
|
|
35
|
+
return base.endsWith('.txt') ? base : `${base}.txt`;
|
|
36
|
+
}
|
|
37
|
+
return base.endsWith('.md') ? base : `${base}.md`;
|
|
38
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildSecureCreateAiAgentBody,
|
|
5
|
+
collectElevationWarnings,
|
|
6
|
+
collectElevationWarningsFromPatch,
|
|
7
|
+
digestCreateAgentPayload,
|
|
8
|
+
normalizeAgentTags,
|
|
9
|
+
resolveSecureAgentCreateFlags,
|
|
10
|
+
SECURE_AGENT_CREATE_DEFAULTS,
|
|
11
|
+
} from './secure-create-defaults.js';
|
|
12
|
+
|
|
13
|
+
describe('resolveSecureAgentCreateFlags', () => {
|
|
14
|
+
it('returns secure defaults when partial is empty', () => {
|
|
15
|
+
expect(resolveSecureAgentCreateFlags({})).toEqual(SECURE_AGENT_CREATE_DEFAULTS);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('honors explicit overrides', () => {
|
|
19
|
+
expect(
|
|
20
|
+
resolveSecureAgentCreateFlags({
|
|
21
|
+
enableDataAccess: true,
|
|
22
|
+
adminOnly: false,
|
|
23
|
+
}),
|
|
24
|
+
).toEqual({
|
|
25
|
+
...SECURE_AGENT_CREATE_DEFAULTS,
|
|
26
|
+
enableDataAccess: true,
|
|
27
|
+
adminOnly: false,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('normalizeAgentTags', () => {
|
|
33
|
+
it('maps empty arrays to null', () => {
|
|
34
|
+
expect(normalizeAgentTags([])).toBeNull();
|
|
35
|
+
expect(normalizeAgentTags(null)).toBeNull();
|
|
36
|
+
expect(normalizeAgentTags(['orders'])).toEqual(['orders']);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('buildSecureCreateAiAgentBody', () => {
|
|
41
|
+
it('applies secure defaults and standard create scaffolding', () => {
|
|
42
|
+
const body = buildSecureCreateAiAgentBody({
|
|
43
|
+
name: 'Smoke',
|
|
44
|
+
projectUuid: '550e8400-e29b-41d4-a716-446655440000',
|
|
45
|
+
});
|
|
46
|
+
expect(body).toMatchObject({
|
|
47
|
+
...SECURE_AGENT_CREATE_DEFAULTS,
|
|
48
|
+
name: 'Smoke',
|
|
49
|
+
integrations: [],
|
|
50
|
+
imageUrl: null,
|
|
51
|
+
groupAccess: [],
|
|
52
|
+
userAccess: [],
|
|
53
|
+
spaceAccess: [],
|
|
54
|
+
version: 1,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('preserves integrations, imageUrl, and modelConfig from file input', () => {
|
|
59
|
+
const modelConfig = { modelProvider: 'openai', modelName: 'gpt-4o' };
|
|
60
|
+
const body = buildSecureCreateAiAgentBody({
|
|
61
|
+
name: 'Advanced',
|
|
62
|
+
projectUuid: '550e8400-e29b-41d4-a716-446655440000',
|
|
63
|
+
integrations: [{ type: 'slack', channelId: 'C123' }],
|
|
64
|
+
imageUrl: 'https://example.com/agent.png',
|
|
65
|
+
modelConfig,
|
|
66
|
+
});
|
|
67
|
+
expect(body.integrations).toEqual([{ type: 'slack', channelId: 'C123' }]);
|
|
68
|
+
expect(body.imageUrl).toBe('https://example.com/agent.png');
|
|
69
|
+
expect(body.modelConfig).toEqual(modelConfig);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('collectElevationWarnings', () => {
|
|
74
|
+
it('returns no warnings for secure baseline', () => {
|
|
75
|
+
expect(collectElevationWarnings({})).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('warns on elevated data access and public visibility', () => {
|
|
79
|
+
const warnings = collectElevationWarnings({
|
|
80
|
+
enableDataAccess: true,
|
|
81
|
+
adminOnly: false,
|
|
82
|
+
});
|
|
83
|
+
expect(warnings.map((w) => w.code)).toEqual([
|
|
84
|
+
'ELEVATED_DATA_ACCESS',
|
|
85
|
+
'ELEVATED_PUBLIC_VISIBILITY',
|
|
86
|
+
]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('warns when content tools enabled without data access', () => {
|
|
90
|
+
const warnings = collectElevationWarnings({ enableContentTools: true });
|
|
91
|
+
expect(warnings.map((w) => w.code)).toContain('ELEVATED_CONTENT_TOOLS');
|
|
92
|
+
expect(warnings.map((w) => w.code)).toContain('ELEVATED_CONTENT_WITHOUT_DATA');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('warns on specific user/group visibility', () => {
|
|
96
|
+
const warnings = collectElevationWarnings({
|
|
97
|
+
adminOnly: false,
|
|
98
|
+
userAccess: ['u1'],
|
|
99
|
+
groupAccess: [],
|
|
100
|
+
});
|
|
101
|
+
expect(warnings).toEqual([expect.objectContaining({ code: 'ELEVATED_PUBLIC_VISIBILITY' })]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('digestCreateAgentPayload', () => {
|
|
106
|
+
it('is order-stable for tags and omits empty tag lists', () => {
|
|
107
|
+
const a = digestCreateAgentPayload({ name: 'A', tags: ['b', 'a'], enableDataAccess: true });
|
|
108
|
+
const b = digestCreateAgentPayload({ name: 'A', tags: ['a', 'b'], enableDataAccess: true });
|
|
109
|
+
expect(a).toBe(b);
|
|
110
|
+
|
|
111
|
+
const omitted = digestCreateAgentPayload({ name: 'A' });
|
|
112
|
+
const empty = digestCreateAgentPayload({ name: 'A', tags: [] });
|
|
113
|
+
expect(omitted).toBe(empty);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('collectElevationWarningsFromPatch', () => {
|
|
118
|
+
it('returns empty when patch has no permission fields', () => {
|
|
119
|
+
expect(collectElevationWarningsFromPatch({})).toEqual([]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('warns only when patch explicitly elevates', () => {
|
|
123
|
+
const warnings = collectElevationWarningsFromPatch({ enableDataAccess: true });
|
|
124
|
+
expect(warnings.map((w) => w.code)).toContain('ELEVATED_DATA_ACCESS');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('does not warn content-without-data when patch only enables content tools', () => {
|
|
128
|
+
expect(collectElevationWarningsFromPatch({ enableContentTools: true })).toEqual([
|
|
129
|
+
expect.objectContaining({ code: 'ELEVATED_CONTENT_TOOLS' }),
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('warns content-without-data when patch explicitly disables data access', () => {
|
|
134
|
+
const warnings = collectElevationWarningsFromPatch({
|
|
135
|
+
enableContentTools: true,
|
|
136
|
+
enableDataAccess: false,
|
|
137
|
+
});
|
|
138
|
+
expect(warnings.map((w) => w.code)).toContain('ELEVATED_CONTENT_WITHOUT_DATA');
|
|
139
|
+
});
|
|
140
|
+
});
|