@lightdash-tools/client 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/apply-agent-change.js +15 -24
- package/dist/agentops/apply-agent-change.test.d.ts +1 -0
- package/dist/agentops/apply-agent-change.test.js +160 -0
- package/dist/api/v1/ai-agents/agents.js +3 -1
- package/dist/api/v1/ai-agents/documents.d.ts +20 -0
- package/dist/api/v1/ai-agents/documents.js +35 -0
- package/dist/api/v1/ai-agents/documents.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/documents.test.js +69 -0
- package/dist/api/v1/ai-agents/facade.d.ts +8 -1
- package/dist/api/v1/ai-agents/facade.js +21 -0
- package/dist/api/v1/ai-agents.test.js +3 -1
- package/dist/api/v1/sql-runner.d.ts +13 -0
- package/dist/api/v1/sql-runner.js +18 -0
- package/dist/api/v1/sql-runner.test.d.ts +1 -0
- package/dist/api/v1/sql-runner.test.js +53 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +2 -2
- package/src/agentops/apply-agent-change.test.ts +206 -0
- package/src/agentops/apply-agent-change.ts +26 -25
- package/src/api/v1/ai-agents/agents.ts +3 -1
- package/src/api/v1/ai-agents/documents.test.ts +86 -0
- package/src/api/v1/ai-agents/documents.ts +86 -0
- package/src/api/v1/ai-agents/facade.ts +53 -0
- package/src/api/v1/ai-agents.test.ts +3 -1
- package/src/api/v1/sql-runner.test.ts +61 -0
- package/src/api/v1/sql-runner.ts +26 -0
- package/src/client.ts +3 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveSecureAgentCreateFlags,
|
|
3
|
+
SECURE_AGENT_CREATE_DEFAULTS,
|
|
4
|
+
} from '@lightdash-tools/common';
|
|
5
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { applyAgentChange } from './apply-agent-change.js';
|
|
8
|
+
|
|
9
|
+
import type { ApplyBundleContext } from './apply-context';
|
|
10
|
+
import type { LightdashAiAgentBundle } from '@lightdash-tools/common';
|
|
11
|
+
|
|
12
|
+
const PROJECT_UUID = '550e8400-e29b-41d4-a716-446655440000';
|
|
13
|
+
|
|
14
|
+
const bundle: LightdashAiAgentBundle = {
|
|
15
|
+
apiVersion: 'lightdash.ai/v1alpha1',
|
|
16
|
+
kind: 'LightdashAiAgentBundle',
|
|
17
|
+
metadata: { name: 'test-bundle' },
|
|
18
|
+
spec: {
|
|
19
|
+
projectUuid: PROJECT_UUID,
|
|
20
|
+
agents: [
|
|
21
|
+
{
|
|
22
|
+
key: 'a1',
|
|
23
|
+
name: 'Governed Agent',
|
|
24
|
+
evaluations: [],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function makeCreateContext(createAgent: ReturnType<typeof vi.fn>): ApplyBundleContext {
|
|
31
|
+
return {
|
|
32
|
+
bundle,
|
|
33
|
+
projectUuid: PROJECT_UUID,
|
|
34
|
+
client: {
|
|
35
|
+
v1: {
|
|
36
|
+
aiAgents: {
|
|
37
|
+
createAgent,
|
|
38
|
+
updateAgent: vi.fn(),
|
|
39
|
+
deleteAgent: vi.fn(),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} as unknown as ApplyBundleContext['client'],
|
|
43
|
+
agentUuidByKey: new Map(),
|
|
44
|
+
failed: [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('applyAgentChange create', () => {
|
|
49
|
+
it('applies secure defaults when bundle omits permission flags', async () => {
|
|
50
|
+
const createAgent = vi.fn().mockResolvedValue({ uuid: 'agent-1', name: 'Governed Agent' });
|
|
51
|
+
const ctx = makeCreateContext(createAgent);
|
|
52
|
+
|
|
53
|
+
const ok = await applyAgentChange(ctx, {
|
|
54
|
+
resourceType: 'agent',
|
|
55
|
+
operation: 'create',
|
|
56
|
+
key: 'a1',
|
|
57
|
+
path: 'agents[a1]',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(ok).toBe(true);
|
|
61
|
+
expect(createAgent).toHaveBeenCalledWith(
|
|
62
|
+
PROJECT_UUID,
|
|
63
|
+
expect.objectContaining(resolveSecureAgentCreateFlags({})),
|
|
64
|
+
);
|
|
65
|
+
expect(createAgent.mock.calls[0]?.[1]).toMatchObject(SECURE_AGENT_CREATE_DEFAULTS);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('forwards spaceAccess from bundle spec on create', async () => {
|
|
69
|
+
const spaceUuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
|
|
70
|
+
const createAgent = vi.fn().mockResolvedValue({ uuid: 'agent-1', name: 'Scoped Agent' });
|
|
71
|
+
const bundleWithSpaces: LightdashAiAgentBundle = {
|
|
72
|
+
...bundle,
|
|
73
|
+
spec: {
|
|
74
|
+
...bundle.spec,
|
|
75
|
+
agents: [
|
|
76
|
+
{
|
|
77
|
+
key: 'a1',
|
|
78
|
+
name: 'Scoped Agent',
|
|
79
|
+
spaceAccess: [spaceUuid],
|
|
80
|
+
evaluations: [],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const ctx: ApplyBundleContext = {
|
|
86
|
+
...makeCreateContext(createAgent),
|
|
87
|
+
bundle: bundleWithSpaces,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const ok = await applyAgentChange(ctx, {
|
|
91
|
+
resourceType: 'agent',
|
|
92
|
+
operation: 'create',
|
|
93
|
+
key: 'a1',
|
|
94
|
+
path: 'agents[a1]',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(ok).toBe(true);
|
|
98
|
+
expect(createAgent.mock.calls[0]?.[1]).toMatchObject({ spaceAccess: [spaceUuid] });
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('applyAgentChange update', () => {
|
|
103
|
+
it('forwards optional permission fields from bundle spec', async () => {
|
|
104
|
+
const updateAgent = vi.fn().mockResolvedValue({});
|
|
105
|
+
const bundleWithPerms: LightdashAiAgentBundle = {
|
|
106
|
+
...bundle,
|
|
107
|
+
spec: {
|
|
108
|
+
...bundle.spec,
|
|
109
|
+
agents: [
|
|
110
|
+
{
|
|
111
|
+
key: 'a1',
|
|
112
|
+
uuid: 'agent-1',
|
|
113
|
+
name: 'Governed Agent',
|
|
114
|
+
enableContentTools: true,
|
|
115
|
+
adminOnly: false,
|
|
116
|
+
evaluations: [],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
const ctx: ApplyBundleContext = {
|
|
122
|
+
bundle: bundleWithPerms,
|
|
123
|
+
projectUuid: PROJECT_UUID,
|
|
124
|
+
client: {
|
|
125
|
+
v1: {
|
|
126
|
+
aiAgents: {
|
|
127
|
+
createAgent: vi.fn(),
|
|
128
|
+
updateAgent,
|
|
129
|
+
deleteAgent: vi.fn(),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
} as unknown as ApplyBundleContext['client'],
|
|
133
|
+
agentUuidByKey: new Map(),
|
|
134
|
+
failed: [],
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const ok = await applyAgentChange(ctx, {
|
|
138
|
+
resourceType: 'agent',
|
|
139
|
+
operation: 'update',
|
|
140
|
+
key: 'a1',
|
|
141
|
+
agentUuid: 'agent-1',
|
|
142
|
+
path: 'agents[a1]',
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
expect(ok).toBe(true);
|
|
146
|
+
expect(updateAgent).toHaveBeenCalledWith(PROJECT_UUID, 'agent-1', {
|
|
147
|
+
uuid: 'agent-1',
|
|
148
|
+
name: 'Governed Agent',
|
|
149
|
+
description: null,
|
|
150
|
+
instruction: null,
|
|
151
|
+
tags: null,
|
|
152
|
+
enableContentTools: true,
|
|
153
|
+
adminOnly: false,
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('forwards spaceAccess from bundle spec on update', async () => {
|
|
158
|
+
const spaceUuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
|
|
159
|
+
const updateAgent = vi.fn().mockResolvedValue({});
|
|
160
|
+
const bundleWithSpaces: LightdashAiAgentBundle = {
|
|
161
|
+
...bundle,
|
|
162
|
+
spec: {
|
|
163
|
+
...bundle.spec,
|
|
164
|
+
agents: [
|
|
165
|
+
{
|
|
166
|
+
key: 'a1',
|
|
167
|
+
uuid: 'agent-1',
|
|
168
|
+
name: 'Governed Agent',
|
|
169
|
+
spaceAccess: [spaceUuid],
|
|
170
|
+
evaluations: [],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
const ctx: ApplyBundleContext = {
|
|
176
|
+
bundle: bundleWithSpaces,
|
|
177
|
+
projectUuid: PROJECT_UUID,
|
|
178
|
+
client: {
|
|
179
|
+
v1: {
|
|
180
|
+
aiAgents: {
|
|
181
|
+
createAgent: vi.fn(),
|
|
182
|
+
updateAgent,
|
|
183
|
+
deleteAgent: vi.fn(),
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
} as unknown as ApplyBundleContext['client'],
|
|
187
|
+
agentUuidByKey: new Map(),
|
|
188
|
+
failed: [],
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const ok = await applyAgentChange(ctx, {
|
|
192
|
+
resourceType: 'agent',
|
|
193
|
+
operation: 'update',
|
|
194
|
+
key: 'a1',
|
|
195
|
+
agentUuid: 'agent-1',
|
|
196
|
+
path: 'agents[a1]',
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(ok).toBe(true);
|
|
200
|
+
expect(updateAgent).toHaveBeenCalledWith(
|
|
201
|
+
PROJECT_UUID,
|
|
202
|
+
'agent-1',
|
|
203
|
+
expect.objectContaining({ spaceAccess: [spaceUuid] }),
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -1,27 +1,36 @@
|
|
|
1
|
+
import { buildSecureCreateAiAgentBody } from '@lightdash-tools/common';
|
|
2
|
+
|
|
1
3
|
import { recordApplyFailure } from './apply-context';
|
|
2
4
|
|
|
3
5
|
import type { ApplyBundleContext } from './apply-context';
|
|
4
|
-
import type { BundleAgentSpec, BundleDiffChange
|
|
6
|
+
import type { BundleAgentSpec, BundleDiffChange } from '@lightdash-tools/common';
|
|
5
7
|
|
|
6
8
|
function findDesiredAgent(ctx: ApplyBundleContext, key: string): BundleAgentSpec | undefined {
|
|
7
9
|
return ctx.bundle.spec.agents.find((a) => a.key === key);
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
function
|
|
12
|
+
function buildAgentUpdatePatch(desired: BundleAgentSpec, agentUuid: string) {
|
|
11
13
|
return {
|
|
14
|
+
uuid: agentUuid,
|
|
12
15
|
name: desired.name,
|
|
13
|
-
projectUuid,
|
|
14
16
|
description: desired.description ?? null,
|
|
15
17
|
instruction: desired.instruction ?? null,
|
|
16
18
|
tags: desired.tags ?? null,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
...(desired.enableDataAccess !== undefined
|
|
20
|
+
? { enableDataAccess: desired.enableDataAccess }
|
|
21
|
+
: {}),
|
|
22
|
+
...(desired.enableContentTools !== undefined
|
|
23
|
+
? { enableContentTools: desired.enableContentTools }
|
|
24
|
+
: {}),
|
|
25
|
+
...(desired.enableSqlMode !== undefined ? { enableSqlMode: desired.enableSqlMode } : {}),
|
|
26
|
+
...(desired.enableUserContext !== undefined
|
|
27
|
+
? { enableUserContext: desired.enableUserContext }
|
|
28
|
+
: {}),
|
|
29
|
+
...(desired.adminOnly !== undefined ? { adminOnly: desired.adminOnly } : {}),
|
|
30
|
+
...(desired.enableSelfImprovement !== undefined
|
|
31
|
+
? { enableSelfImprovement: desired.enableSelfImprovement }
|
|
32
|
+
: {}),
|
|
33
|
+
...(desired.spaceAccess !== undefined ? { spaceAccess: desired.spaceAccess } : {}),
|
|
25
34
|
};
|
|
26
35
|
}
|
|
27
36
|
|
|
@@ -39,7 +48,7 @@ export async function applyAgentChange(
|
|
|
39
48
|
}
|
|
40
49
|
const created = await client.v1.aiAgents.createAgent(
|
|
41
50
|
projectUuid,
|
|
42
|
-
|
|
51
|
+
buildSecureCreateAiAgentBody({ ...desired, projectUuid }),
|
|
43
52
|
);
|
|
44
53
|
agentUuidByKey.set(desired.key, created.uuid);
|
|
45
54
|
return true;
|
|
@@ -56,19 +65,11 @@ export async function applyAgentChange(
|
|
|
56
65
|
recordApplyFailure(ctx, change, `Could not resolve agent UUID for key '${change.key}'`);
|
|
57
66
|
return false;
|
|
58
67
|
}
|
|
59
|
-
await client.v1.aiAgents.updateAgent(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
tags: desired.tags ?? null,
|
|
65
|
-
...(desired.enableDataAccess !== undefined
|
|
66
|
-
? { enableDataAccess: desired.enableDataAccess }
|
|
67
|
-
: {}),
|
|
68
|
-
...(desired.enableSelfImprovement !== undefined
|
|
69
|
-
? { enableSelfImprovement: desired.enableSelfImprovement }
|
|
70
|
-
: {}),
|
|
71
|
-
});
|
|
68
|
+
await client.v1.aiAgents.updateAgent(
|
|
69
|
+
projectUuid,
|
|
70
|
+
agentUuid,
|
|
71
|
+
buildAgentUpdatePatch(desired, agentUuid),
|
|
72
|
+
);
|
|
72
73
|
agentUuidByKey.set(desired.key, agentUuid);
|
|
73
74
|
return true;
|
|
74
75
|
}
|
|
@@ -25,7 +25,9 @@ export class AiAgentsProjectClient extends BaseApiClient {
|
|
|
25
25
|
|
|
26
26
|
/** Create a new agent in a project (POST /projects/{projectUuid}/aiAgents). */
|
|
27
27
|
async createAgent(projectUuid: string, body: CreateAiAgent): Promise<AiAgent> {
|
|
28
|
-
return this.http.post<AiAgent>(`/projects/${projectUuid}/aiAgents`, body
|
|
28
|
+
return this.http.post<AiAgent>(`/projects/${projectUuid}/aiAgents`, body, undefined, {
|
|
29
|
+
maxRetries: 0,
|
|
30
|
+
});
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/** Update an existing agent (PATCH /projects/{projectUuid}/aiAgents/{agentUuid}). */
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { AiAgentsDocumentsClient } from './documents';
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../../../http/http-client';
|
|
6
|
+
|
|
7
|
+
describe('AiAgentsDocumentsClient', () => {
|
|
8
|
+
let mockHttp: HttpClient;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockHttp = {
|
|
12
|
+
get: vi.fn(),
|
|
13
|
+
post: vi.fn(),
|
|
14
|
+
put: vi.fn(),
|
|
15
|
+
patch: vi.fn(),
|
|
16
|
+
delete: vi.fn(),
|
|
17
|
+
} as unknown as HttpClient;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('listDocuments should call GET …/documents', async () => {
|
|
21
|
+
const client = new AiAgentsDocumentsClient(mockHttp);
|
|
22
|
+
const summaries = [{ uuid: 'd1', name: 'Glossary' }];
|
|
23
|
+
vi.mocked(mockHttp.get).mockResolvedValue(summaries);
|
|
24
|
+
const result = await client.listDocuments('proj1', 'a1');
|
|
25
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents');
|
|
26
|
+
expect(result).toEqual(summaries);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('getDocumentContent should call GET …/documents/{uuid}/content', async () => {
|
|
30
|
+
const client = new AiAgentsDocumentsClient(mockHttp);
|
|
31
|
+
const content = { uuid: 'd1', name: 'Glossary', mimeType: 'text/markdown', content: '# Hi' };
|
|
32
|
+
vi.mocked(mockHttp.get).mockResolvedValue(content);
|
|
33
|
+
const result = await client.getDocumentContent('proj1', 'a1', 'd1');
|
|
34
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1/content');
|
|
35
|
+
expect(result).toEqual(content);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('createDocument should call POST …/documents', async () => {
|
|
39
|
+
const client = new AiAgentsDocumentsClient(mockHttp);
|
|
40
|
+
const body = {
|
|
41
|
+
name: 'Glossary',
|
|
42
|
+
content: '# Terms',
|
|
43
|
+
mimeType: 'text/markdown',
|
|
44
|
+
originalFilename: 'Glossary.md',
|
|
45
|
+
};
|
|
46
|
+
const created = { uuid: 'd1', ...body };
|
|
47
|
+
vi.mocked(mockHttp.post).mockResolvedValue(created);
|
|
48
|
+
const result = await client.createDocument('proj1', 'a1', body);
|
|
49
|
+
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
50
|
+
'/projects/proj1/aiAgents/a1/documents',
|
|
51
|
+
body,
|
|
52
|
+
undefined,
|
|
53
|
+
{ maxRetries: 0 },
|
|
54
|
+
);
|
|
55
|
+
expect(result).toEqual(created);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('updateDocumentContent should call PATCH …/content', async () => {
|
|
59
|
+
const client = new AiAgentsDocumentsClient(mockHttp);
|
|
60
|
+
const body = { name: 'Glossary v2', content: '# Updated' };
|
|
61
|
+
const updated = { uuid: 'd1', ...body };
|
|
62
|
+
vi.mocked(mockHttp.patch).mockResolvedValue(updated);
|
|
63
|
+
const result = await client.updateDocumentContent('proj1', 'a1', 'd1', body);
|
|
64
|
+
expect(mockHttp.patch).toHaveBeenCalledWith(
|
|
65
|
+
'/projects/proj1/aiAgents/a1/documents/d1/content',
|
|
66
|
+
body,
|
|
67
|
+
);
|
|
68
|
+
expect(result).toEqual(updated);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('updateDocumentSettings should call PATCH …/documents/{uuid}', async () => {
|
|
72
|
+
const client = new AiAgentsDocumentsClient(mockHttp);
|
|
73
|
+
vi.mocked(mockHttp.patch).mockResolvedValue(undefined);
|
|
74
|
+
await client.updateDocumentSettings('proj1', 'a1', 'd1', { alwaysIncludeInContext: true });
|
|
75
|
+
expect(mockHttp.patch).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1', {
|
|
76
|
+
alwaysIncludeInContext: true,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('deleteDocument should call DELETE …/documents/{uuid}', async () => {
|
|
81
|
+
const client = new AiAgentsDocumentsClient(mockHttp);
|
|
82
|
+
vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
|
|
83
|
+
await client.deleteDocument('proj1', 'a1', 'd1');
|
|
84
|
+
expect(mockHttp.delete).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-scoped AI agent knowledge document client.
|
|
3
|
+
* Endpoints: /api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/documents/...
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BaseApiClient } from '../../base-client';
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
AiAgentDocument,
|
|
10
|
+
AiAgentDocumentContent,
|
|
11
|
+
AiAgentDocumentSummary,
|
|
12
|
+
CreateAgentDocumentBody,
|
|
13
|
+
UpdateAgentDocumentContentBody,
|
|
14
|
+
UpdateAgentDocumentSettingsBody,
|
|
15
|
+
} from '@lightdash-tools/common';
|
|
16
|
+
|
|
17
|
+
export class AiAgentsDocumentsClient extends BaseApiClient {
|
|
18
|
+
/** List knowledge documents for an agent (GET …/documents). */
|
|
19
|
+
async listDocuments(projectUuid: string, agentUuid: string): Promise<AiAgentDocumentSummary[]> {
|
|
20
|
+
return this.http.get<AiAgentDocumentSummary[]>(
|
|
21
|
+
`/projects/${projectUuid}/aiAgents/${agentUuid}/documents`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Read full document content (GET …/documents/{documentUuid}/content). */
|
|
26
|
+
async getDocumentContent(
|
|
27
|
+
projectUuid: string,
|
|
28
|
+
agentUuid: string,
|
|
29
|
+
documentUuid: string,
|
|
30
|
+
): Promise<AiAgentDocumentContent> {
|
|
31
|
+
return this.http.get<AiAgentDocumentContent>(
|
|
32
|
+
`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}/content`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Create a knowledge document scoped to this agent (POST …/documents). */
|
|
37
|
+
async createDocument(
|
|
38
|
+
projectUuid: string,
|
|
39
|
+
agentUuid: string,
|
|
40
|
+
body: CreateAgentDocumentBody,
|
|
41
|
+
): Promise<AiAgentDocument> {
|
|
42
|
+
return this.http.post<AiAgentDocument>(
|
|
43
|
+
`/projects/${projectUuid}/aiAgents/${agentUuid}/documents`,
|
|
44
|
+
body,
|
|
45
|
+
undefined,
|
|
46
|
+
{ maxRetries: 0 },
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Replace document name and content (PATCH …/documents/{documentUuid}/content). */
|
|
51
|
+
async updateDocumentContent(
|
|
52
|
+
projectUuid: string,
|
|
53
|
+
agentUuid: string,
|
|
54
|
+
documentUuid: string,
|
|
55
|
+
body: UpdateAgentDocumentContentBody,
|
|
56
|
+
): Promise<AiAgentDocument> {
|
|
57
|
+
return this.http.patch<AiAgentDocument>(
|
|
58
|
+
`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}/content`,
|
|
59
|
+
body,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Update document settings such as alwaysIncludeInContext (PATCH …/documents/{documentUuid}). */
|
|
64
|
+
async updateDocumentSettings(
|
|
65
|
+
projectUuid: string,
|
|
66
|
+
agentUuid: string,
|
|
67
|
+
documentUuid: string,
|
|
68
|
+
body: UpdateAgentDocumentSettingsBody,
|
|
69
|
+
): Promise<void> {
|
|
70
|
+
await this.http.patch(
|
|
71
|
+
`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}`,
|
|
72
|
+
body,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Delete a knowledge document (DELETE …/documents/{documentUuid}). */
|
|
77
|
+
async deleteDocument(
|
|
78
|
+
projectUuid: string,
|
|
79
|
+
agentUuid: string,
|
|
80
|
+
documentUuid: string,
|
|
81
|
+
): Promise<void> {
|
|
82
|
+
await this.http.delete(
|
|
83
|
+
`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -9,6 +9,7 @@ import { AiAgentsAdminClient } from './admin';
|
|
|
9
9
|
import { AiAgentsProjectClient } from './agents';
|
|
10
10
|
import { AiAgentsArtifactsClient } from './artifacts';
|
|
11
11
|
import { AiAgentsDiscoveryClient } from './discovery';
|
|
12
|
+
import { AiAgentsDocumentsClient } from './documents';
|
|
12
13
|
import { AiAgentsEvaluationsClient } from './evaluations';
|
|
13
14
|
import { AiAgentsFeedbackClient } from './feedback';
|
|
14
15
|
import { AiAgentsMcpServersClient } from './mcp-servers';
|
|
@@ -21,6 +22,9 @@ import type { HttpClient } from '../../../http/http-client';
|
|
|
21
22
|
import type {
|
|
22
23
|
AgentSuggestions,
|
|
23
24
|
AiAgent,
|
|
25
|
+
AiAgentDocument,
|
|
26
|
+
AiAgentDocumentContent,
|
|
27
|
+
AiAgentDocumentSummary,
|
|
24
28
|
AiAgentEvaluation,
|
|
25
29
|
AiAgentEvaluationRun,
|
|
26
30
|
AiAgentEvaluationRunSummary,
|
|
@@ -46,6 +50,7 @@ import type {
|
|
|
46
50
|
CloneThreadBody,
|
|
47
51
|
CreateAgentThreadBody,
|
|
48
52
|
CreateAgentThreadMessageResult,
|
|
53
|
+
CreateAgentDocumentBody,
|
|
49
54
|
CreateAiAgent,
|
|
50
55
|
CreateEvaluationBody,
|
|
51
56
|
CreateEvaluationResult,
|
|
@@ -63,6 +68,8 @@ import type {
|
|
|
63
68
|
SubmitSqlApprovalResult,
|
|
64
69
|
UpdateAiAgent,
|
|
65
70
|
UpdateAiOrganizationSettings,
|
|
71
|
+
UpdateAgentDocumentContentBody,
|
|
72
|
+
UpdateAgentDocumentSettingsBody,
|
|
66
73
|
UpdateAiOrganizationSettingsResult,
|
|
67
74
|
UpdateAgentMcpServerToolsBody,
|
|
68
75
|
UpdateEvaluationBody,
|
|
@@ -74,6 +81,7 @@ export class AiAgentsClient extends BaseApiClient {
|
|
|
74
81
|
private readonly agents: AiAgentsProjectClient;
|
|
75
82
|
private readonly artifacts: AiAgentsArtifactsClient;
|
|
76
83
|
private readonly discovery: AiAgentsDiscoveryClient;
|
|
84
|
+
private readonly documents: AiAgentsDocumentsClient;
|
|
77
85
|
private readonly threads: AiAgentsThreadsClient;
|
|
78
86
|
private readonly evaluations: AiAgentsEvaluationsClient;
|
|
79
87
|
private readonly feedback: AiAgentsFeedbackClient;
|
|
@@ -87,6 +95,7 @@ export class AiAgentsClient extends BaseApiClient {
|
|
|
87
95
|
this.agents = new AiAgentsProjectClient(http);
|
|
88
96
|
this.artifacts = new AiAgentsArtifactsClient(http);
|
|
89
97
|
this.discovery = new AiAgentsDiscoveryClient(http);
|
|
98
|
+
this.documents = new AiAgentsDocumentsClient(http);
|
|
90
99
|
this.threads = new AiAgentsThreadsClient(http);
|
|
91
100
|
this.evaluations = new AiAgentsEvaluationsClient(http);
|
|
92
101
|
this.feedback = new AiAgentsFeedbackClient(http);
|
|
@@ -513,4 +522,48 @@ export class AiAgentsClient extends BaseApiClient {
|
|
|
513
522
|
): Promise<AiAgentEvaluationRun> {
|
|
514
523
|
return this.evaluations.getEvaluationRunResults(projectUuid, agentUuid, evalUuid, runUuid);
|
|
515
524
|
}
|
|
525
|
+
|
|
526
|
+
// ─── Project-scoped: knowledge documents ─────────────────────────────────────
|
|
527
|
+
|
|
528
|
+
listDocuments(projectUuid: string, agentUuid: string): Promise<AiAgentDocumentSummary[]> {
|
|
529
|
+
return this.documents.listDocuments(projectUuid, agentUuid);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
getDocumentContent(
|
|
533
|
+
projectUuid: string,
|
|
534
|
+
agentUuid: string,
|
|
535
|
+
documentUuid: string,
|
|
536
|
+
): Promise<AiAgentDocumentContent> {
|
|
537
|
+
return this.documents.getDocumentContent(projectUuid, agentUuid, documentUuid);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
createDocument(
|
|
541
|
+
projectUuid: string,
|
|
542
|
+
agentUuid: string,
|
|
543
|
+
body: CreateAgentDocumentBody,
|
|
544
|
+
): Promise<AiAgentDocument> {
|
|
545
|
+
return this.documents.createDocument(projectUuid, agentUuid, body);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
updateDocumentContent(
|
|
549
|
+
projectUuid: string,
|
|
550
|
+
agentUuid: string,
|
|
551
|
+
documentUuid: string,
|
|
552
|
+
body: UpdateAgentDocumentContentBody,
|
|
553
|
+
): Promise<AiAgentDocument> {
|
|
554
|
+
return this.documents.updateDocumentContent(projectUuid, agentUuid, documentUuid, body);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
updateDocumentSettings(
|
|
558
|
+
projectUuid: string,
|
|
559
|
+
agentUuid: string,
|
|
560
|
+
documentUuid: string,
|
|
561
|
+
body: UpdateAgentDocumentSettingsBody,
|
|
562
|
+
): Promise<void> {
|
|
563
|
+
return this.documents.updateDocumentSettings(projectUuid, agentUuid, documentUuid, body);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
deleteDocument(projectUuid: string, agentUuid: string, documentUuid: string): Promise<void> {
|
|
567
|
+
return this.documents.deleteDocument(projectUuid, agentUuid, documentUuid);
|
|
568
|
+
}
|
|
516
569
|
}
|
|
@@ -102,7 +102,9 @@ describe('AiAgentsClient', () => {
|
|
|
102
102
|
const created = { uuid: 'a2', name: 'New Agent', projectUuid: 'proj1' };
|
|
103
103
|
vi.mocked(mockHttp.post).mockResolvedValue(created);
|
|
104
104
|
const result = await client.createAgent('proj1', body);
|
|
105
|
-
expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents', body
|
|
105
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents', body, undefined, {
|
|
106
|
+
maxRetries: 0,
|
|
107
|
+
});
|
|
106
108
|
expect(result).toEqual(created);
|
|
107
109
|
});
|
|
108
110
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { SqlRunnerClient } from './sql-runner.js';
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../../http/http-client';
|
|
6
|
+
|
|
7
|
+
describe('SqlRunnerClient', () => {
|
|
8
|
+
let mockHttp: HttpClient;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockHttp = {
|
|
12
|
+
get: vi.fn(),
|
|
13
|
+
post: vi.fn(),
|
|
14
|
+
put: vi.fn(),
|
|
15
|
+
patch: vi.fn(),
|
|
16
|
+
delete: vi.fn(),
|
|
17
|
+
getBytes: vi.fn(),
|
|
18
|
+
} as unknown as HttpClient;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('getSavedSqlChart should call GET /projects/{projectUuid}/sqlRunner/saved/{uuid}', async () => {
|
|
22
|
+
const client = new SqlRunnerClient(mockHttp);
|
|
23
|
+
const chart = {
|
|
24
|
+
savedSqlUuid: 'sql-1',
|
|
25
|
+
name: 'Orders SQL',
|
|
26
|
+
slug: 'orders-sql',
|
|
27
|
+
sql: 'SELECT 1',
|
|
28
|
+
limit: 500,
|
|
29
|
+
};
|
|
30
|
+
vi.mocked(mockHttp.get).mockResolvedValue(chart);
|
|
31
|
+
const result = await client.getSavedSqlChart('p1', 'sql-1');
|
|
32
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/sql-1');
|
|
33
|
+
expect(result).toEqual(chart);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('getSavedSqlChartBySlug should call GET …/sqlRunner/saved/slug/{slug}', async () => {
|
|
37
|
+
const client = new SqlRunnerClient(mockHttp);
|
|
38
|
+
const chart = {
|
|
39
|
+
savedSqlUuid: 'sql-1',
|
|
40
|
+
name: 'Orders SQL',
|
|
41
|
+
slug: 'orders-sql',
|
|
42
|
+
sql: 'SELECT 1',
|
|
43
|
+
limit: 500,
|
|
44
|
+
};
|
|
45
|
+
vi.mocked(mockHttp.get).mockResolvedValue(chart);
|
|
46
|
+
const result = await client.getSavedSqlChartBySlug('p1', 'orders-sql');
|
|
47
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/slug/orders-sql');
|
|
48
|
+
expect(result).toEqual(chart);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('encodes uuid and slug path segments', async () => {
|
|
52
|
+
const client = new SqlRunnerClient(mockHttp);
|
|
53
|
+
vi.mocked(mockHttp.get).mockResolvedValue({});
|
|
54
|
+
await client.getSavedSqlChart('p1', 'a/b');
|
|
55
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/a%2Fb');
|
|
56
|
+
await client.getSavedSqlChartBySlug('p1', 'slug/with spaces');
|
|
57
|
+
expect(mockHttp.get).toHaveBeenCalledWith(
|
|
58
|
+
'/projects/p1/sqlRunner/saved/slug/slug%2Fwith%20spaces',
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Runner API client. Endpoints for saved SQL charts (metadata + authored SQL body).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { BaseApiClient } from '../base-client';
|
|
6
|
+
|
|
7
|
+
import type { components } from '@lightdash-tools/common';
|
|
8
|
+
|
|
9
|
+
/** Saved SQL chart including authored `sql` body. */
|
|
10
|
+
export type SqlChart = components['schemas']['SqlChart'];
|
|
11
|
+
|
|
12
|
+
export class SqlRunnerClient extends BaseApiClient {
|
|
13
|
+
/** Get a saved SQL chart by UUID within a project (includes authored SQL). */
|
|
14
|
+
async getSavedSqlChart(projectUuid: string, uuid: string): Promise<SqlChart> {
|
|
15
|
+
return this.http.get<SqlChart>(
|
|
16
|
+
`/projects/${projectUuid}/sqlRunner/saved/${encodeURIComponent(uuid)}`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Get a saved SQL chart by slug within a project (includes authored SQL). */
|
|
21
|
+
async getSavedSqlChartBySlug(projectUuid: string, slug: string): Promise<SqlChart> {
|
|
22
|
+
return this.http.get<SqlChart>(
|
|
23
|
+
`/projects/${projectUuid}/sqlRunner/saved/slug/${encodeURIComponent(slug)}`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|