@lightdash-tools/mcp 0.20.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/README.md +5 -5
- package/dist/auth/request-state-key.d.ts +2 -2
- package/dist/auth/request-state-key.js +2 -2
- package/dist/config/enabled-profiles.d.ts +1 -1
- package/dist/config/enabled-profiles.js +3 -2
- package/dist/config/enabled-profiles.test.js +1 -0
- package/dist/policy/create-agent-preview.d.ts +65 -0
- package/dist/policy/create-agent-preview.js +126 -0
- package/dist/policy/create-agent-preview.test.d.ts +4 -0
- package/dist/policy/create-agent-preview.test.js +162 -0
- package/dist/profiles/ai-agent-ops/v1/index.js +10 -0
- package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +6 -3
- package/dist/profiles/ai-agent-ops/v1/invariants.js +6 -2
- package/dist/profiles/ai-agent-ops/v1/prompts.js +24 -3
- package/dist/profiles/ai-agent-ops/v1/prompts.test.js +10 -1
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/core.md +34 -2
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +9 -4
- package/dist/profiles/index.test.js +7 -2
- package/dist/server/server.js +16 -4
- package/dist/tools/ai-agents/agents.d.ts +8 -0
- package/dist/tools/ai-agents/agents.js +283 -1
- package/dist/tools/ai-agents/agents.test.js +25 -0
- package/dist/tools/ai-agents/create-elicitation.d.ts +52 -0
- package/dist/tools/ai-agents/create-elicitation.js +206 -0
- package/dist/tools/ai-agents/create-elicitation.test.d.ts +4 -0
- package/dist/tools/ai-agents/create-elicitation.test.js +363 -0
- package/dist/tools/ai-agents/create-request-state.d.ts +18 -0
- package/dist/tools/ai-agents/create-request-state.js +43 -0
- package/dist/tools/ai-agents/documents.d.ts +15 -0
- package/dist/tools/ai-agents/documents.js +212 -0
- package/dist/tools/ai-agents/documents.test.d.ts +1 -0
- package/dist/tools/ai-agents/documents.test.js +129 -0
- package/dist/tools/ai-agents/gate-create-project-agent.d.ts +28 -0
- package/dist/tools/ai-agents/gate-create-project-agent.js +71 -0
- package/dist/tools/ai-agents/helpers.d.ts +11 -0
- package/dist/tools/ai-agents/helpers.js +29 -1
- package/dist/tools/ai-agents/knowledge-warnings.d.ts +11 -0
- package/dist/tools/ai-agents/knowledge-warnings.js +21 -0
- package/dist/tools/ai-agents/space-warnings.d.ts +36 -0
- package/dist/tools/ai-agents/space-warnings.js +101 -0
- package/dist/tools/ai-agents/space-warnings.test.d.ts +1 -0
- package/dist/tools/ai-agents/space-warnings.test.js +78 -0
- package/dist/tools/ai-agents/tag-warnings.d.ts +31 -0
- package/dist/tools/ai-agents/tag-warnings.js +70 -0
- package/dist/tools/ai-agents/test-support.d.ts +4 -1
- package/dist/tools/ai-agents/test-support.js +7 -2
- package/package.json +3 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI agent knowledge document tools (ai-agent-ops profile).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deleteAgentDocumentTool = exports.updateAgentDocumentTool = exports.createAgentDocumentTool = exports.getAgentDocumentTool = exports.listAgentDocumentsTool = void 0;
|
|
7
|
+
exports.registerListAgentDocuments = registerListAgentDocuments;
|
|
8
|
+
exports.registerGetAgentDocument = registerGetAgentDocument;
|
|
9
|
+
exports.registerCreateAgentDocument = registerCreateAgentDocument;
|
|
10
|
+
exports.registerUpdateAgentDocument = registerUpdateAgentDocument;
|
|
11
|
+
exports.registerDeleteAgentDocument = registerDeleteAgentDocument;
|
|
12
|
+
const common_1 = require("@lightdash-tools/common");
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const shared_js_1 = require("../shared.js");
|
|
15
|
+
const types_js_1 = require("../types.js");
|
|
16
|
+
const helpers_js_1 = require("./helpers.js");
|
|
17
|
+
const knowledge_warnings_js_1 = require("./knowledge-warnings.js");
|
|
18
|
+
const documentNameField = () => zod_1.z.string().trim().min(1).describe('Knowledge document display name');
|
|
19
|
+
const documentContentField = () => zod_1.z
|
|
20
|
+
.string()
|
|
21
|
+
.describe('Inline document body (Markdown or plain text). Host reads local files and passes the string — no server filePath.');
|
|
22
|
+
const mimeTypeField = () => zod_1.z.string().optional().describe('MIME type: text/markdown (default) or text/plain');
|
|
23
|
+
const originalFilenameField = () => zod_1.z
|
|
24
|
+
.string()
|
|
25
|
+
.trim()
|
|
26
|
+
.min(1)
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Original filename hint (default derived from name)');
|
|
29
|
+
const alwaysIncludeInContextField = () => zod_1.z
|
|
30
|
+
.boolean()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('When true, embed full document in every agent prompt (token cost). Default is on-demand retrieval.');
|
|
33
|
+
function assertAgentDocumentContentWithinLimit(content) {
|
|
34
|
+
if (!(0, common_1.isAgentDocumentContentWithinLimit)(content)) {
|
|
35
|
+
const bytes = (0, common_1.agentDocumentContentByteLength)(content);
|
|
36
|
+
throw new Error(`Knowledge document content exceeds ${common_1.AGENT_DOCUMENT_MAX_BYTES} bytes (${bytes} bytes). Split into focused documents per Lightdash guidance.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function resolveDocumentMimeType(mimeType) {
|
|
40
|
+
const resolved = mimeType !== null && mimeType !== void 0 ? mimeType : common_1.AGENT_DOCUMENT_DEFAULT_MIME;
|
|
41
|
+
if (!(0, common_1.isAllowedAgentDocumentMimeType)(resolved)) {
|
|
42
|
+
throw new Error(`Unsupported mimeType "${resolved}". Allowed: text/markdown, text/plain.`);
|
|
43
|
+
}
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
46
|
+
function buildCreateDocumentBody(args) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
assertAgentDocumentContentWithinLimit(args.content);
|
|
49
|
+
const mimeType = resolveDocumentMimeType(args.mimeType);
|
|
50
|
+
return {
|
|
51
|
+
name: args.name.trim(),
|
|
52
|
+
content: args.content,
|
|
53
|
+
mimeType,
|
|
54
|
+
originalFilename: (_b = (_a = args.originalFilename) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : (0, common_1.defaultAgentDocumentFilename)(args.name, mimeType),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function maybeApplyAlwaysIncludeInContext(client, projectUuid, agentUuid, document, alwaysIncludeInContext) {
|
|
58
|
+
if (alwaysIncludeInContext !== true) {
|
|
59
|
+
return document;
|
|
60
|
+
}
|
|
61
|
+
await client.updateDocumentSettings(projectUuid, agentUuid, document.uuid, {
|
|
62
|
+
alwaysIncludeInContext: true,
|
|
63
|
+
});
|
|
64
|
+
return Object.assign(Object.assign({}, document), { alwaysIncludeInContext: true });
|
|
65
|
+
}
|
|
66
|
+
async function updateAgentDocumentContentFields(scope, name, content) {
|
|
67
|
+
var _a;
|
|
68
|
+
const { client, projectUuid, agentUuid, documentUuid } = scope;
|
|
69
|
+
let nextName;
|
|
70
|
+
let nextContent;
|
|
71
|
+
if (name !== undefined && content !== undefined) {
|
|
72
|
+
nextName = name.trim();
|
|
73
|
+
nextContent = content;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const current = await client.getDocumentContent(projectUuid, agentUuid, documentUuid);
|
|
77
|
+
nextName = (_a = name === null || name === void 0 ? void 0 : name.trim()) !== null && _a !== void 0 ? _a : current.name;
|
|
78
|
+
nextContent = content !== null && content !== void 0 ? content : current.content;
|
|
79
|
+
}
|
|
80
|
+
assertAgentDocumentContentWithinLimit(nextContent);
|
|
81
|
+
return client.updateDocumentContent(projectUuid, agentUuid, documentUuid, {
|
|
82
|
+
name: nextName,
|
|
83
|
+
content: nextContent,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async function applyAlwaysIncludeInContextUpdate(scope, document, alwaysIncludeInContext) {
|
|
87
|
+
const { client, projectUuid, agentUuid, documentUuid } = scope;
|
|
88
|
+
await client.updateDocumentSettings(projectUuid, agentUuid, documentUuid, {
|
|
89
|
+
alwaysIncludeInContext,
|
|
90
|
+
});
|
|
91
|
+
const base = document !== null && document !== void 0 ? document : (await client.getDocumentContent(projectUuid, agentUuid, documentUuid));
|
|
92
|
+
return Object.assign(Object.assign({}, base), { alwaysIncludeInContext });
|
|
93
|
+
}
|
|
94
|
+
function registerListAgentDocuments(server, contextProvider) {
|
|
95
|
+
(0, shared_js_1.registerToolSafe)(server, 'list_agent_documents', {
|
|
96
|
+
title: 'List agent documents',
|
|
97
|
+
description: 'List knowledge document summaries for an agent (org-level plus agent-scoped). Summaries only — no full content.',
|
|
98
|
+
inputSchema: {
|
|
99
|
+
projectUuid: (0, helpers_js_1.optionalProjectUuidField)(),
|
|
100
|
+
agentUuid: (0, helpers_js_1.agentUuidField)(),
|
|
101
|
+
},
|
|
102
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
103
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async ({ projectUuid, agentUuid }) => (0, helpers_js_1.withAiAgentProjectScope)(projectUuid, async (scope) => ({
|
|
104
|
+
data: await c.v1.aiAgents.listDocuments(scope.projectUuid, agentUuid),
|
|
105
|
+
}))));
|
|
106
|
+
}
|
|
107
|
+
function registerGetAgentDocument(server, contextProvider) {
|
|
108
|
+
(0, shared_js_1.registerToolSafe)(server, 'get_agent_document', {
|
|
109
|
+
title: 'Get agent document',
|
|
110
|
+
description: 'Read a knowledge document. Content is redacted unless includeDocumentContent=true.',
|
|
111
|
+
inputSchema: {
|
|
112
|
+
projectUuid: (0, helpers_js_1.optionalProjectUuidField)(),
|
|
113
|
+
agentUuid: (0, helpers_js_1.agentUuidField)(),
|
|
114
|
+
documentUuid: (0, helpers_js_1.documentUuidField)(),
|
|
115
|
+
includeDocumentContent: (0, helpers_js_1.includeDocumentContentField)(),
|
|
116
|
+
},
|
|
117
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
118
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async ({ projectUuid, agentUuid, documentUuid, includeDocumentContent, }) => (0, helpers_js_1.withAiAgentProjectScope)(projectUuid, async (scope) => {
|
|
119
|
+
const document = await c.v1.aiAgents.getDocumentContent(scope.projectUuid, agentUuid, documentUuid);
|
|
120
|
+
return (0, helpers_js_1.redactDocumentContent)(document, includeDocumentContent === true);
|
|
121
|
+
})));
|
|
122
|
+
}
|
|
123
|
+
function registerCreateAgentDocument(server, contextProvider) {
|
|
124
|
+
(0, shared_js_1.registerToolSafe)(server, 'create_agent_document', {
|
|
125
|
+
title: 'Create agent document',
|
|
126
|
+
description: 'Upload inline knowledge (glossary, SOP, metric definitions) scoped to this agent. JSON body — not multipart. Max 20KB.',
|
|
127
|
+
inputSchema: {
|
|
128
|
+
projectUuid: (0, helpers_js_1.optionalProjectUuidField)(),
|
|
129
|
+
agentUuid: (0, helpers_js_1.agentUuidField)(),
|
|
130
|
+
name: documentNameField(),
|
|
131
|
+
content: documentContentField(),
|
|
132
|
+
mimeType: mimeTypeField(),
|
|
133
|
+
originalFilename: originalFilenameField(),
|
|
134
|
+
alwaysIncludeInContext: alwaysIncludeInContextField(),
|
|
135
|
+
},
|
|
136
|
+
annotations: common_1.WRITE_NONDESTRUCTIVE,
|
|
137
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async ({ projectUuid, agentUuid, name, content, mimeType, originalFilename, alwaysIncludeInContext, }) => (0, helpers_js_1.withAiAgentProjectScope)(projectUuid, async (scope) => {
|
|
138
|
+
const body = buildCreateDocumentBody({
|
|
139
|
+
name,
|
|
140
|
+
content,
|
|
141
|
+
mimeType,
|
|
142
|
+
originalFilename,
|
|
143
|
+
});
|
|
144
|
+
let document = await c.v1.aiAgents.createDocument(scope.projectUuid, agentUuid, body);
|
|
145
|
+
document = await maybeApplyAlwaysIncludeInContext(c.v1.aiAgents, scope.projectUuid, agentUuid, document, alwaysIncludeInContext);
|
|
146
|
+
return {
|
|
147
|
+
data: document,
|
|
148
|
+
warnings: (0, knowledge_warnings_js_1.knowledgeDocumentWarnings)({ alwaysIncludeInContext }),
|
|
149
|
+
};
|
|
150
|
+
})));
|
|
151
|
+
}
|
|
152
|
+
function registerUpdateAgentDocument(server, contextProvider) {
|
|
153
|
+
(0, shared_js_1.registerToolSafe)(server, 'update_agent_document', {
|
|
154
|
+
title: 'Update agent document',
|
|
155
|
+
description: 'Update knowledge document content and/or alwaysIncludeInContext. Provide at least one field. Content max 20KB.',
|
|
156
|
+
inputSchema: {
|
|
157
|
+
projectUuid: (0, helpers_js_1.optionalProjectUuidField)(),
|
|
158
|
+
agentUuid: (0, helpers_js_1.agentUuidField)(),
|
|
159
|
+
documentUuid: (0, helpers_js_1.documentUuidField)(),
|
|
160
|
+
name: documentNameField().optional(),
|
|
161
|
+
content: documentContentField().optional(),
|
|
162
|
+
alwaysIncludeInContext: alwaysIncludeInContextField(),
|
|
163
|
+
},
|
|
164
|
+
annotations: common_1.WRITE_NONDESTRUCTIVE,
|
|
165
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async ({ projectUuid, agentUuid, documentUuid, name, content, alwaysIncludeInContext, }) => (0, helpers_js_1.withAiAgentProjectScope)(projectUuid, async (scope) => {
|
|
166
|
+
if (name === undefined &&
|
|
167
|
+
content === undefined &&
|
|
168
|
+
alwaysIncludeInContext === undefined) {
|
|
169
|
+
throw new Error('Provide at least one of name, content, or alwaysIncludeInContext to update.');
|
|
170
|
+
}
|
|
171
|
+
let document;
|
|
172
|
+
const updateScope = {
|
|
173
|
+
client: c.v1.aiAgents,
|
|
174
|
+
projectUuid: scope.projectUuid,
|
|
175
|
+
agentUuid,
|
|
176
|
+
documentUuid,
|
|
177
|
+
};
|
|
178
|
+
if (name !== undefined || content !== undefined) {
|
|
179
|
+
document = await updateAgentDocumentContentFields(updateScope, name, content);
|
|
180
|
+
}
|
|
181
|
+
if (alwaysIncludeInContext !== undefined) {
|
|
182
|
+
document = await applyAlwaysIncludeInContextUpdate(updateScope, document, alwaysIncludeInContext);
|
|
183
|
+
}
|
|
184
|
+
if (document === undefined) {
|
|
185
|
+
throw new Error('Document update did not produce a result.');
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
data: document,
|
|
189
|
+
warnings: (0, knowledge_warnings_js_1.knowledgeDocumentWarnings)({ alwaysIncludeInContext }),
|
|
190
|
+
};
|
|
191
|
+
})));
|
|
192
|
+
}
|
|
193
|
+
function registerDeleteAgentDocument(server, contextProvider) {
|
|
194
|
+
(0, shared_js_1.registerToolSafe)(server, 'delete_agent_document', {
|
|
195
|
+
title: 'Delete agent document',
|
|
196
|
+
description: 'Delete a knowledge document from this agent.',
|
|
197
|
+
inputSchema: {
|
|
198
|
+
projectUuid: (0, helpers_js_1.optionalProjectUuidField)(),
|
|
199
|
+
agentUuid: (0, helpers_js_1.agentUuidField)(),
|
|
200
|
+
documentUuid: (0, helpers_js_1.documentUuidField)(),
|
|
201
|
+
},
|
|
202
|
+
annotations: common_1.WRITE_DESTRUCTIVE,
|
|
203
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async ({ projectUuid, agentUuid, documentUuid, }) => (0, helpers_js_1.withAiAgentProjectScope)(projectUuid, async (scope) => {
|
|
204
|
+
await c.v1.aiAgents.deleteDocument(scope.projectUuid, agentUuid, documentUuid);
|
|
205
|
+
return { data: { deleted: true, documentUuid } };
|
|
206
|
+
})));
|
|
207
|
+
}
|
|
208
|
+
exports.listAgentDocumentsTool = (0, types_js_1.defineTool)('list_agent_documents', registerListAgentDocuments);
|
|
209
|
+
exports.getAgentDocumentTool = (0, types_js_1.defineTool)('get_agent_document', registerGetAgentDocument);
|
|
210
|
+
exports.createAgentDocumentTool = (0, types_js_1.defineTool)('create_agent_document', registerCreateAgentDocument);
|
|
211
|
+
exports.updateAgentDocumentTool = (0, types_js_1.defineTool)('update_agent_document', registerUpdateAgentDocument);
|
|
212
|
+
exports.deleteAgentDocumentTool = (0, types_js_1.defineTool)('delete_agent_document', registerDeleteAgentDocument);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const documents_js_1 = require("./documents.js");
|
|
5
|
+
const helpers_js_1 = require("./helpers.js");
|
|
6
|
+
const test_support_js_1 = require("./test-support.js");
|
|
7
|
+
const PROJECT = '11111111-1111-1111-1111-111111111111';
|
|
8
|
+
const AGENT = '22222222-2222-2222-2222-222222222222';
|
|
9
|
+
const DOCUMENT = '33333333-3333-3333-3333-333333333333';
|
|
10
|
+
(0, vitest_1.describe)('ai-agents document helpers', () => {
|
|
11
|
+
(0, vitest_1.it)('redacts document content by default', () => {
|
|
12
|
+
const { data, warnings } = (0, helpers_js_1.redactDocumentContent)({ uuid: DOCUMENT, name: 'Glossary', content: 'secret terms' }, false);
|
|
13
|
+
(0, vitest_1.expect)(data.content).toBe('[REDACTED]');
|
|
14
|
+
(0, vitest_1.expect)(warnings).toHaveLength(1);
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.it)('reveals document content when includeDocumentContent is true', () => {
|
|
17
|
+
const { data, warnings } = (0, helpers_js_1.redactDocumentContent)({ uuid: DOCUMENT, name: 'Glossary', content: 'secret terms' }, true);
|
|
18
|
+
(0, vitest_1.expect)(data.content).toBe('secret terms');
|
|
19
|
+
(0, vitest_1.expect)(warnings).toHaveLength(0);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.describe)('create_agent_document', () => {
|
|
23
|
+
(0, vitest_1.it)('creates a document and patches alwaysIncludeInContext when requested', async () => {
|
|
24
|
+
const createDocument = vitest_1.vi.fn().mockResolvedValue({
|
|
25
|
+
uuid: DOCUMENT,
|
|
26
|
+
name: 'Glossary',
|
|
27
|
+
alwaysIncludeInContext: false,
|
|
28
|
+
});
|
|
29
|
+
const updateDocumentSettings = vitest_1.vi.fn().mockResolvedValue(undefined);
|
|
30
|
+
const ctx = (0, test_support_js_1.mockAiAgentsContext)({ createDocument, updateDocumentSettings });
|
|
31
|
+
const tool = (0, test_support_js_1.registeredAiAgentTool)(documents_js_1.registerCreateAgentDocument, ctx, 'create_agent_document');
|
|
32
|
+
const result = await tool.handler({
|
|
33
|
+
projectUuid: PROJECT,
|
|
34
|
+
agentUuid: AGENT,
|
|
35
|
+
name: 'Glossary',
|
|
36
|
+
content: '# Terms',
|
|
37
|
+
alwaysIncludeInContext: true,
|
|
38
|
+
});
|
|
39
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(result);
|
|
40
|
+
(0, vitest_1.expect)(createDocument).toHaveBeenCalledWith(PROJECT, AGENT, {
|
|
41
|
+
name: 'Glossary',
|
|
42
|
+
content: '# Terms',
|
|
43
|
+
mimeType: 'text/markdown',
|
|
44
|
+
originalFilename: 'Glossary.md',
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.expect)(updateDocumentSettings).toHaveBeenCalledWith(PROJECT, AGENT, DOCUMENT, {
|
|
47
|
+
alwaysIncludeInContext: true,
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.expect)(body.data).toMatchObject({ uuid: DOCUMENT, alwaysIncludeInContext: true });
|
|
50
|
+
(0, vitest_1.expect)(body.warnings).toEqual(vitest_1.expect.arrayContaining([
|
|
51
|
+
vitest_1.expect.objectContaining({ code: 'KNOWLEDGE_VISIBLE_TO_AGENT_USERS' }),
|
|
52
|
+
vitest_1.expect.objectContaining({ code: 'DOCUMENT_ALWAYS_IN_CONTEXT' }),
|
|
53
|
+
]));
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)('rejects content over 20KB before upstream create', async () => {
|
|
56
|
+
var _a;
|
|
57
|
+
const createDocument = vitest_1.vi.fn();
|
|
58
|
+
const ctx = (0, test_support_js_1.mockAiAgentsContext)({ createDocument });
|
|
59
|
+
const tool = (0, test_support_js_1.registeredAiAgentTool)(documents_js_1.registerCreateAgentDocument, ctx, 'create_agent_document');
|
|
60
|
+
const result = await tool.handler({
|
|
61
|
+
projectUuid: PROJECT,
|
|
62
|
+
agentUuid: AGENT,
|
|
63
|
+
name: 'Huge',
|
|
64
|
+
content: 'x'.repeat(20481),
|
|
65
|
+
});
|
|
66
|
+
(0, vitest_1.expect)(result.isError).toBe(true);
|
|
67
|
+
(0, vitest_1.expect)(createDocument).not.toHaveBeenCalled();
|
|
68
|
+
(0, vitest_1.expect)((_a = result.content[0]) === null || _a === void 0 ? void 0 : _a.text).toContain('20480');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
(0, vitest_1.describe)('get_agent_document', () => {
|
|
72
|
+
(0, vitest_1.it)('redacts content unless includeDocumentContent is true', async () => {
|
|
73
|
+
const getDocumentContent = vitest_1.vi.fn().mockResolvedValue({
|
|
74
|
+
uuid: DOCUMENT,
|
|
75
|
+
name: 'Glossary',
|
|
76
|
+
mimeType: 'text/markdown',
|
|
77
|
+
content: 'secret',
|
|
78
|
+
});
|
|
79
|
+
const ctx = (0, test_support_js_1.mockAiAgentsContext)({ getDocumentContent });
|
|
80
|
+
const tool = (0, test_support_js_1.registeredAiAgentTool)(documents_js_1.registerGetAgentDocument, ctx, 'get_agent_document');
|
|
81
|
+
const redacted = (0, test_support_js_1.parseAiAgentToolBody)(await tool.handler({ projectUuid: PROJECT, agentUuid: AGENT, documentUuid: DOCUMENT }));
|
|
82
|
+
(0, vitest_1.expect)(redacted.data.content).toBe('[REDACTED]');
|
|
83
|
+
const revealed = (0, test_support_js_1.parseAiAgentToolBody)(await tool.handler({
|
|
84
|
+
projectUuid: PROJECT,
|
|
85
|
+
agentUuid: AGENT,
|
|
86
|
+
documentUuid: DOCUMENT,
|
|
87
|
+
includeDocumentContent: true,
|
|
88
|
+
}));
|
|
89
|
+
(0, vitest_1.expect)(revealed.data.content).toBe('secret');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.describe)('update_agent_document', () => {
|
|
93
|
+
(0, vitest_1.it)('merges partial content updates with the current document', async () => {
|
|
94
|
+
const getDocumentContent = vitest_1.vi
|
|
95
|
+
.fn()
|
|
96
|
+
.mockResolvedValueOnce({
|
|
97
|
+
uuid: DOCUMENT,
|
|
98
|
+
name: 'Glossary',
|
|
99
|
+
mimeType: 'text/markdown',
|
|
100
|
+
content: 'old body',
|
|
101
|
+
})
|
|
102
|
+
.mockResolvedValueOnce({
|
|
103
|
+
uuid: DOCUMENT,
|
|
104
|
+
name: 'Glossary',
|
|
105
|
+
mimeType: 'text/markdown',
|
|
106
|
+
content: 'new body',
|
|
107
|
+
});
|
|
108
|
+
const updateDocumentContent = vitest_1.vi.fn().mockResolvedValue({
|
|
109
|
+
uuid: DOCUMENT,
|
|
110
|
+
name: 'Glossary',
|
|
111
|
+
content: 'new body',
|
|
112
|
+
});
|
|
113
|
+
const ctx = (0, test_support_js_1.mockAiAgentsContext)({ getDocumentContent, updateDocumentContent });
|
|
114
|
+
const tool = (0, test_support_js_1.registeredAiAgentTool)(documents_js_1.registerUpdateAgentDocument, ctx, 'update_agent_document');
|
|
115
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(await tool.handler({
|
|
116
|
+
projectUuid: PROJECT,
|
|
117
|
+
agentUuid: AGENT,
|
|
118
|
+
documentUuid: DOCUMENT,
|
|
119
|
+
content: 'new body',
|
|
120
|
+
}));
|
|
121
|
+
(0, vitest_1.expect)(updateDocumentContent).toHaveBeenCalledWith(PROJECT, AGENT, DOCUMENT, {
|
|
122
|
+
name: 'Glossary',
|
|
123
|
+
content: 'new body',
|
|
124
|
+
});
|
|
125
|
+
(0, vitest_1.expect)(body.warnings).toEqual(vitest_1.expect.arrayContaining([
|
|
126
|
+
vitest_1.expect.objectContaining({ code: 'KNOWLEDGE_VISIBLE_TO_AGENT_USERS' }),
|
|
127
|
+
]));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dual-gate orchestrator for create_project_agent (ADR-0033 form + ADR-0034 preview-token).
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolExecutionContext, ToolResult } from '../shared.js';
|
|
5
|
+
import type { ProjectSpacesClient } from './space-warnings.js';
|
|
6
|
+
import type { ExploreAccessSummaryClient } from './tag-warnings.js';
|
|
7
|
+
import type { AgentCreatePayloadFields } from '@lightdash-tools/common';
|
|
8
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
9
|
+
/**
|
|
10
|
+
* Run create confirmation gate. Order:
|
|
11
|
+
* 1. Form elicitation when the client supports it (ADR-0033).
|
|
12
|
+
* 2. Preview-token apply when createConfirmToken is supplied (ADR-0034).
|
|
13
|
+
* 3. PREVIEW_REQUIRED when neither applies.
|
|
14
|
+
*/
|
|
15
|
+
export declare function gateCreateProjectAgent(input: {
|
|
16
|
+
server: McpServer;
|
|
17
|
+
ctx: ToolExecutionContext;
|
|
18
|
+
projectUuid: string;
|
|
19
|
+
payload: AgentCreatePayloadFields;
|
|
20
|
+
exploreAccessClient: ExploreAccessSummaryClient;
|
|
21
|
+
spacesClient: ProjectSpacesClient;
|
|
22
|
+
createConfirmToken?: string;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
proceed: false;
|
|
25
|
+
result: ToolResult;
|
|
26
|
+
} | {
|
|
27
|
+
proceed: true;
|
|
28
|
+
}>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Dual-gate orchestrator for create_project_agent (ADR-0033 form + ADR-0034 preview-token).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.gateCreateProjectAgent = gateCreateProjectAgent;
|
|
7
|
+
const capability_js_1 = require("../../destructive/capability.js");
|
|
8
|
+
const create_agent_preview_js_1 = require("../../policy/create-agent-preview.js");
|
|
9
|
+
const shared_js_1 = require("../shared.js");
|
|
10
|
+
const create_elicitation_js_1 = require("./create-elicitation.js");
|
|
11
|
+
const PREVIEW_REQUIRED_MESSAGE = 'create_project_agent requires confirmation. When the client lacks MCP form elicitation, ' +
|
|
12
|
+
'call preview_create_agent, obtain human approval for the permission summary, then ' +
|
|
13
|
+
'confirm_create_agent, and retry create_project_agent with the same payload and createConfirmToken.';
|
|
14
|
+
function previewRequiredResult(message = PREVIEW_REQUIRED_MESSAGE) {
|
|
15
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
16
|
+
status: 'blocked',
|
|
17
|
+
code: 'PREVIEW_REQUIRED',
|
|
18
|
+
message,
|
|
19
|
+
created: false,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
function previewBlockedResult(code, message) {
|
|
23
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
24
|
+
status: 'blocked',
|
|
25
|
+
code,
|
|
26
|
+
message,
|
|
27
|
+
created: false,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Run create confirmation gate. Order:
|
|
32
|
+
* 1. Form elicitation when the client supports it (ADR-0033).
|
|
33
|
+
* 2. Preview-token apply when createConfirmToken is supplied (ADR-0034).
|
|
34
|
+
* 3. PREVIEW_REQUIRED when neither applies.
|
|
35
|
+
*/
|
|
36
|
+
async function gateCreateProjectAgent(input) {
|
|
37
|
+
const { server, ctx, projectUuid, payload, exploreAccessClient, spacesClient, createConfirmToken, } = input;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- 2025-era fallback
|
|
39
|
+
const initializeCaps = server.server.getClientCapabilities();
|
|
40
|
+
if ((0, capability_js_1.supportsFormElicitation)(ctx.serverContext, initializeCaps)) {
|
|
41
|
+
return (0, create_elicitation_js_1.gateCreateProjectAgentElicitation)({
|
|
42
|
+
server,
|
|
43
|
+
ctx,
|
|
44
|
+
projectUuid,
|
|
45
|
+
payload,
|
|
46
|
+
exploreAccessClient,
|
|
47
|
+
spacesClient,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (createConfirmToken === undefined || createConfirmToken.length === 0) {
|
|
51
|
+
return { proceed: false, result: previewRequiredResult() };
|
|
52
|
+
}
|
|
53
|
+
const payloadDigest = (0, create_elicitation_js_1.digestCreateAgentPayload)(payload);
|
|
54
|
+
try {
|
|
55
|
+
await (0, create_agent_preview_js_1.verifyValidatedCreateConfirmToken)({
|
|
56
|
+
createConfirmToken,
|
|
57
|
+
subject: ctx.subject,
|
|
58
|
+
projectUuid,
|
|
59
|
+
agentName: payload.name,
|
|
60
|
+
payloadDigest,
|
|
61
|
+
serverContext: ctx.serverContext,
|
|
62
|
+
});
|
|
63
|
+
return { proceed: true };
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (err instanceof create_agent_preview_js_1.CreateAgentPreviewError) {
|
|
67
|
+
return { proceed: false, result: previewBlockedResult(err.code, err.message) };
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -9,6 +9,7 @@ export { optionalProjectUuidField };
|
|
|
9
9
|
export declare const agentUuidField: () => z.ZodString;
|
|
10
10
|
export declare const evalUuidField: () => z.ZodString;
|
|
11
11
|
export declare const runUuidField: () => z.ZodString;
|
|
12
|
+
export declare const documentUuidField: () => z.ZodString;
|
|
12
13
|
export declare const threadUuidField: () => z.ZodString;
|
|
13
14
|
/** Project + agent identity shared by inventory, thread, discovery, and eval tools. */
|
|
14
15
|
export type AiAgentScopeArgs = {
|
|
@@ -32,6 +33,7 @@ declare const evaluationPromptSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
32
33
|
export declare const evaluationPromptsField: () => z.ZodArray<typeof evaluationPromptSchema>;
|
|
33
34
|
export declare const includeMessageTextField: () => z.ZodOptional<z.ZodBoolean>;
|
|
34
35
|
export declare const includePromptTextField: () => z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
export declare const includeDocumentContentField: () => z.ZodOptional<z.ZodBoolean>;
|
|
35
37
|
export declare const CONVERSATION_REDACTED_WARNING: {
|
|
36
38
|
code: "REDACTED";
|
|
37
39
|
message: string;
|
|
@@ -40,6 +42,10 @@ export declare const PROMPT_REDACTED_WARNING: {
|
|
|
40
42
|
code: "REDACTED";
|
|
41
43
|
message: string;
|
|
42
44
|
};
|
|
45
|
+
export declare const DOCUMENT_CONTENT_REDACTED_WARNING: {
|
|
46
|
+
code: "REDACTED";
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
43
49
|
type RedactionWarning = {
|
|
44
50
|
code: 'REDACTED';
|
|
45
51
|
message: string;
|
|
@@ -72,3 +78,8 @@ export declare function redactEvalRunResults(run: unknown, includePromptText: bo
|
|
|
72
78
|
data: unknown;
|
|
73
79
|
warnings: RedactionWarning[];
|
|
74
80
|
};
|
|
81
|
+
/** Redact knowledge document content unless explicitly requested. */
|
|
82
|
+
export declare function redactDocumentContent(document: unknown, includeDocumentContent: boolean): {
|
|
83
|
+
data: unknown;
|
|
84
|
+
warnings: RedactionWarning[];
|
|
85
|
+
};
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* Shared helpers for AI-agent MCP tools (ai-agent-ops and ai-agent-chat).
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PROMPT_REDACTED_WARNING = exports.CONVERSATION_REDACTED_WARNING = exports.includePromptTextField = exports.includeMessageTextField = exports.evaluationPromptsField = exports.threadPromptField = exports.THREAD_PROMPT_MAX_CHARS = exports.threadUuidField = exports.runUuidField = exports.evalUuidField = exports.agentUuidField = exports.optionalProjectUuidField = void 0;
|
|
6
|
+
exports.DOCUMENT_CONTENT_REDACTED_WARNING = exports.PROMPT_REDACTED_WARNING = exports.CONVERSATION_REDACTED_WARNING = exports.includeDocumentContentField = exports.includePromptTextField = exports.includeMessageTextField = exports.evaluationPromptsField = exports.threadPromptField = exports.THREAD_PROMPT_MAX_CHARS = exports.threadUuidField = exports.documentUuidField = exports.runUuidField = exports.evalUuidField = exports.agentUuidField = exports.optionalProjectUuidField = void 0;
|
|
7
7
|
exports.withAiAgentProjectScope = withAiAgentProjectScope;
|
|
8
8
|
exports.redactThreadMessages = redactThreadMessages;
|
|
9
9
|
exports.redactThreadSummaries = redactThreadSummaries;
|
|
10
10
|
exports.redactEvaluationPayload = redactEvaluationPayload;
|
|
11
11
|
exports.redactEvalRunResults = redactEvalRunResults;
|
|
12
|
+
exports.redactDocumentContent = redactDocumentContent;
|
|
12
13
|
const zod_1 = require("zod");
|
|
13
14
|
const project_scope_js_1 = require("../../governance/project-scope.js");
|
|
14
15
|
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
@@ -21,6 +22,8 @@ const evalUuidField = () => zod_1.z.string().describe('Evaluation suite UUID');
|
|
|
21
22
|
exports.evalUuidField = evalUuidField;
|
|
22
23
|
const runUuidField = () => zod_1.z.string().describe('Evaluation run UUID');
|
|
23
24
|
exports.runUuidField = runUuidField;
|
|
25
|
+
const documentUuidField = () => zod_1.z.string().describe('Knowledge document UUID');
|
|
26
|
+
exports.documentUuidField = documentUuidField;
|
|
24
27
|
const threadUuidField = () => zod_1.z.string().describe('Thread UUID');
|
|
25
28
|
exports.threadUuidField = threadUuidField;
|
|
26
29
|
/** Conservative local prompt ceiling; not env-configurable in v1 (ADR-0029). */
|
|
@@ -47,6 +50,11 @@ const includePromptTextField = () => zod_1.z
|
|
|
47
50
|
.optional()
|
|
48
51
|
.describe('Return evaluation prompt / expected-response text when true (default false)');
|
|
49
52
|
exports.includePromptTextField = includePromptTextField;
|
|
53
|
+
const includeDocumentContentField = () => zod_1.z
|
|
54
|
+
.boolean()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('Return full knowledge document content when true (default false)');
|
|
57
|
+
exports.includeDocumentContentField = includeDocumentContentField;
|
|
50
58
|
exports.CONVERSATION_REDACTED_WARNING = {
|
|
51
59
|
code: 'REDACTED',
|
|
52
60
|
message: 'Conversation text redacted (messages, firstMessage, title, context, reasoning, steers, tool I/O); pass includeMessageText=true to reveal',
|
|
@@ -55,6 +63,10 @@ exports.PROMPT_REDACTED_WARNING = {
|
|
|
55
63
|
code: 'REDACTED',
|
|
56
64
|
message: 'Evaluation prompt text redacted; pass includePromptText=true to reveal',
|
|
57
65
|
};
|
|
66
|
+
exports.DOCUMENT_CONTENT_REDACTED_WARNING = {
|
|
67
|
+
code: 'REDACTED',
|
|
68
|
+
message: 'Document content redacted; pass includeDocumentContent=true to reveal',
|
|
69
|
+
};
|
|
58
70
|
const MESSAGE_TEXT_KEYS = [
|
|
59
71
|
'message',
|
|
60
72
|
'prompt',
|
|
@@ -323,3 +335,19 @@ function redactEvaluationPayload(evaluation, includePromptText) {
|
|
|
323
335
|
function redactEvalRunResults(run, includePromptText) {
|
|
324
336
|
return redactPromptTextCollection(run, 'results', includePromptText);
|
|
325
337
|
}
|
|
338
|
+
/** Redact knowledge document content unless explicitly requested. */
|
|
339
|
+
function redactDocumentContent(document, includeDocumentContent) {
|
|
340
|
+
if (includeDocumentContent) {
|
|
341
|
+
return { data: document, warnings: [] };
|
|
342
|
+
}
|
|
343
|
+
const base = asRecord(document);
|
|
344
|
+
if (!base) {
|
|
345
|
+
return { data: document, warnings: [] };
|
|
346
|
+
}
|
|
347
|
+
const data = Object.assign({}, base);
|
|
348
|
+
const changed = redactStringKeys(data, ['content']);
|
|
349
|
+
return {
|
|
350
|
+
data,
|
|
351
|
+
warnings: changed ? [exports.DOCUMENT_CONTENT_REDACTED_WARNING] : [],
|
|
352
|
+
};
|
|
353
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft warnings when curating agent knowledge documents.
|
|
3
|
+
*/
|
|
4
|
+
export type KnowledgeDocumentWarningCode = 'DOCUMENT_ALWAYS_IN_CONTEXT' | 'KNOWLEDGE_VISIBLE_TO_AGENT_USERS';
|
|
5
|
+
export type KnowledgeDocumentWarning = {
|
|
6
|
+
code: KnowledgeDocumentWarningCode;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function knowledgeDocumentWarnings(options: {
|
|
10
|
+
alwaysIncludeInContext?: boolean;
|
|
11
|
+
}): KnowledgeDocumentWarning[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Soft warnings when curating agent knowledge documents.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.knowledgeDocumentWarnings = knowledgeDocumentWarnings;
|
|
7
|
+
function knowledgeDocumentWarnings(options) {
|
|
8
|
+
const warnings = [
|
|
9
|
+
{
|
|
10
|
+
code: 'KNOWLEDGE_VISIBLE_TO_AGENT_USERS',
|
|
11
|
+
message: 'Knowledge documents are visible to everyone who can use this agent. Do not upload secrets, customer PII, or material the agent audience should not see.',
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
if (options.alwaysIncludeInContext === true) {
|
|
15
|
+
warnings.push({
|
|
16
|
+
code: 'DOCUMENT_ALWAYS_IN_CONTEXT',
|
|
17
|
+
message: 'alwaysIncludeInContext embeds the full document in every agent prompt, increasing token use and latency. Prefer on-demand retrieval unless the context must apply to every turn.',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return warnings;
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft warnings when agent spaceAccess UUIDs are not found in the project.
|
|
3
|
+
*/
|
|
4
|
+
export type AgentSpaceWarningCode = 'SPACE_LIST_UNAVAILABLE' | 'SPACES_NOT_IN_PROJECT';
|
|
5
|
+
export type AgentSpaceWarning = {
|
|
6
|
+
code: AgentSpaceWarningCode;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type ResolvedSpaceRef = {
|
|
10
|
+
uuid: string;
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
export type ProjectSpacesClient = {
|
|
14
|
+
listSpacesInProject: (projectUuid: string) => Promise<ResolvedSpaceRef[]>;
|
|
15
|
+
};
|
|
16
|
+
/** Non-empty spaceAccess only; null/empty skip (all project spaces). */
|
|
17
|
+
export declare function effectiveAgentSpaceAccess(spaceAccess: string[] | undefined): string[] | undefined;
|
|
18
|
+
export type SpaceAccessValidationResult = {
|
|
19
|
+
error: Error;
|
|
20
|
+
} | {
|
|
21
|
+
resolved: ResolvedSpaceRef[];
|
|
22
|
+
unknownUuids: string[];
|
|
23
|
+
} | {
|
|
24
|
+
skipped: true;
|
|
25
|
+
};
|
|
26
|
+
/** Validate spaceAccess UUIDs against the project space list. */
|
|
27
|
+
export declare function fetchSpaceAccessValidation(client: ProjectSpacesClient, projectUuid: string, spaceAccess: string[] | undefined): Promise<SpaceAccessValidationResult>;
|
|
28
|
+
/** Human-readable space scope line for create confirmation / preview. */
|
|
29
|
+
export declare function formatSpaceAccessPreviewLine(spaceAccess: string[] | undefined, validation: SpaceAccessValidationResult): string;
|
|
30
|
+
/** Derive soft warnings from a prior validation result (no upstream call). */
|
|
31
|
+
export declare function warningsFromSpaceAccessValidation(result: SpaceAccessValidationResult): AgentSpaceWarning[];
|
|
32
|
+
/**
|
|
33
|
+
* After create/update with non-empty spaceAccess, warn when UUIDs are missing from the project.
|
|
34
|
+
* Never fails the mutation.
|
|
35
|
+
*/
|
|
36
|
+
export declare function warningsForAgentSpaceAccess(client: ProjectSpacesClient, projectUuid: string, spaceAccess: string[] | undefined): Promise<AgentSpaceWarning[]>;
|