@lightdash-tools/client 0.20.0 → 0.22.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.
@@ -1,30 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyAgentChange = applyAgentChange;
4
+ const common_1 = require("@lightdash-tools/common");
4
5
  const apply_context_1 = require("./apply-context");
5
6
  function findDesiredAgent(ctx, key) {
6
7
  return ctx.bundle.spec.agents.find((a) => a.key === key);
7
8
  }
8
- function buildCreateAgentBody(desired, projectUuid) {
9
- var _a, _b, _c, _d, _e;
10
- return {
11
- name: desired.name,
12
- projectUuid,
13
- description: (_a = desired.description) !== null && _a !== void 0 ? _a : null,
14
- instruction: (_b = desired.instruction) !== null && _b !== void 0 ? _b : null,
15
- tags: (_c = desired.tags) !== null && _c !== void 0 ? _c : null,
16
- integrations: [],
17
- imageUrl: null,
18
- groupAccess: [],
19
- userAccess: [],
20
- spaceAccess: [],
21
- enableDataAccess: (_d = desired.enableDataAccess) !== null && _d !== void 0 ? _d : false,
22
- enableSelfImprovement: (_e = desired.enableSelfImprovement) !== null && _e !== void 0 ? _e : false,
23
- version: 1,
24
- };
9
+ function buildAgentUpdatePatch(desired, agentUuid) {
10
+ var _a, _b, _c;
11
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ uuid: agentUuid, name: desired.name, description: (_a = desired.description) !== null && _a !== void 0 ? _a : null, instruction: (_b = desired.instruction) !== null && _b !== void 0 ? _b : null, tags: (_c = desired.tags) !== null && _c !== void 0 ? _c : null }, (desired.enableDataAccess !== undefined
12
+ ? { enableDataAccess: desired.enableDataAccess }
13
+ : {})), (desired.enableContentTools !== undefined
14
+ ? { enableContentTools: desired.enableContentTools }
15
+ : {})), (desired.enableSqlMode !== undefined ? { enableSqlMode: desired.enableSqlMode } : {})), (desired.enableUserContext !== undefined
16
+ ? { enableUserContext: desired.enableUserContext }
17
+ : {})), (desired.adminOnly !== undefined ? { adminOnly: desired.adminOnly } : {})), (desired.enableSelfImprovement !== undefined
18
+ ? { enableSelfImprovement: desired.enableSelfImprovement }
19
+ : {})), (desired.spaceAccess !== undefined ? { spaceAccess: desired.spaceAccess } : {}));
25
20
  }
26
21
  async function applyAgentChange(ctx, change) {
27
- var _a, _b, _c, _d, _e;
22
+ var _a, _b;
28
23
  const { client, projectUuid, agentUuidByKey } = ctx;
29
24
  if (change.operation === 'create') {
30
25
  const desired = findDesiredAgent(ctx, change.key);
@@ -32,7 +27,7 @@ async function applyAgentChange(ctx, change) {
32
27
  (0, apply_context_1.recordApplyFailure)(ctx, change, `Agent spec not found for key '${change.key}'`);
33
28
  return false;
34
29
  }
35
- const created = await client.v1.aiAgents.createAgent(projectUuid, buildCreateAgentBody(desired, projectUuid));
30
+ const created = await client.v1.aiAgents.createAgent(projectUuid, (0, common_1.buildSecureCreateAiAgentBody)(Object.assign(Object.assign({}, desired), { projectUuid })));
36
31
  agentUuidByKey.set(desired.key, created.uuid);
37
32
  return true;
38
33
  }
@@ -47,11 +42,7 @@ async function applyAgentChange(ctx, change) {
47
42
  (0, apply_context_1.recordApplyFailure)(ctx, change, `Could not resolve agent UUID for key '${change.key}'`);
48
43
  return false;
49
44
  }
50
- await client.v1.aiAgents.updateAgent(projectUuid, agentUuid, Object.assign(Object.assign({ uuid: agentUuid, name: desired.name, description: (_c = desired.description) !== null && _c !== void 0 ? _c : null, instruction: (_d = desired.instruction) !== null && _d !== void 0 ? _d : null, tags: (_e = desired.tags) !== null && _e !== void 0 ? _e : null }, (desired.enableDataAccess !== undefined
51
- ? { enableDataAccess: desired.enableDataAccess }
52
- : {})), (desired.enableSelfImprovement !== undefined
53
- ? { enableSelfImprovement: desired.enableSelfImprovement }
54
- : {})));
45
+ await client.v1.aiAgents.updateAgent(projectUuid, agentUuid, buildAgentUpdatePatch(desired, agentUuid));
55
46
  agentUuidByKey.set(desired.key, agentUuid);
56
47
  return true;
57
48
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const common_1 = require("@lightdash-tools/common");
4
+ const vitest_1 = require("vitest");
5
+ const apply_agent_change_js_1 = require("./apply-agent-change.js");
6
+ const PROJECT_UUID = '550e8400-e29b-41d4-a716-446655440000';
7
+ const bundle = {
8
+ apiVersion: 'lightdash.ai/v1alpha1',
9
+ kind: 'LightdashAiAgentBundle',
10
+ metadata: { name: 'test-bundle' },
11
+ spec: {
12
+ projectUuid: PROJECT_UUID,
13
+ agents: [
14
+ {
15
+ key: 'a1',
16
+ name: 'Governed Agent',
17
+ evaluations: [],
18
+ },
19
+ ],
20
+ },
21
+ };
22
+ function makeCreateContext(createAgent) {
23
+ return {
24
+ bundle,
25
+ projectUuid: PROJECT_UUID,
26
+ client: {
27
+ v1: {
28
+ aiAgents: {
29
+ createAgent,
30
+ updateAgent: vitest_1.vi.fn(),
31
+ deleteAgent: vitest_1.vi.fn(),
32
+ },
33
+ },
34
+ },
35
+ agentUuidByKey: new Map(),
36
+ failed: [],
37
+ };
38
+ }
39
+ (0, vitest_1.describe)('applyAgentChange create', () => {
40
+ (0, vitest_1.it)('applies secure defaults when bundle omits permission flags', async () => {
41
+ var _a;
42
+ const createAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: 'agent-1', name: 'Governed Agent' });
43
+ const ctx = makeCreateContext(createAgent);
44
+ const ok = await (0, apply_agent_change_js_1.applyAgentChange)(ctx, {
45
+ resourceType: 'agent',
46
+ operation: 'create',
47
+ key: 'a1',
48
+ path: 'agents[a1]',
49
+ });
50
+ (0, vitest_1.expect)(ok).toBe(true);
51
+ (0, vitest_1.expect)(createAgent).toHaveBeenCalledWith(PROJECT_UUID, vitest_1.expect.objectContaining((0, common_1.resolveSecureAgentCreateFlags)({})));
52
+ (0, vitest_1.expect)((_a = createAgent.mock.calls[0]) === null || _a === void 0 ? void 0 : _a[1]).toMatchObject(common_1.SECURE_AGENT_CREATE_DEFAULTS);
53
+ });
54
+ (0, vitest_1.it)('forwards spaceAccess from bundle spec on create', async () => {
55
+ var _a;
56
+ const spaceUuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
57
+ const createAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: 'agent-1', name: 'Scoped Agent' });
58
+ const bundleWithSpaces = Object.assign(Object.assign({}, bundle), { spec: Object.assign(Object.assign({}, bundle.spec), { agents: [
59
+ {
60
+ key: 'a1',
61
+ name: 'Scoped Agent',
62
+ spaceAccess: [spaceUuid],
63
+ evaluations: [],
64
+ },
65
+ ] }) });
66
+ const ctx = Object.assign(Object.assign({}, makeCreateContext(createAgent)), { bundle: bundleWithSpaces });
67
+ const ok = await (0, apply_agent_change_js_1.applyAgentChange)(ctx, {
68
+ resourceType: 'agent',
69
+ operation: 'create',
70
+ key: 'a1',
71
+ path: 'agents[a1]',
72
+ });
73
+ (0, vitest_1.expect)(ok).toBe(true);
74
+ (0, vitest_1.expect)((_a = createAgent.mock.calls[0]) === null || _a === void 0 ? void 0 : _a[1]).toMatchObject({ spaceAccess: [spaceUuid] });
75
+ });
76
+ });
77
+ (0, vitest_1.describe)('applyAgentChange update', () => {
78
+ (0, vitest_1.it)('forwards optional permission fields from bundle spec', async () => {
79
+ const updateAgent = vitest_1.vi.fn().mockResolvedValue({});
80
+ const bundleWithPerms = Object.assign(Object.assign({}, bundle), { spec: Object.assign(Object.assign({}, bundle.spec), { agents: [
81
+ {
82
+ key: 'a1',
83
+ uuid: 'agent-1',
84
+ name: 'Governed Agent',
85
+ enableContentTools: true,
86
+ adminOnly: false,
87
+ evaluations: [],
88
+ },
89
+ ] }) });
90
+ const ctx = {
91
+ bundle: bundleWithPerms,
92
+ projectUuid: PROJECT_UUID,
93
+ client: {
94
+ v1: {
95
+ aiAgents: {
96
+ createAgent: vitest_1.vi.fn(),
97
+ updateAgent,
98
+ deleteAgent: vitest_1.vi.fn(),
99
+ },
100
+ },
101
+ },
102
+ agentUuidByKey: new Map(),
103
+ failed: [],
104
+ };
105
+ const ok = await (0, apply_agent_change_js_1.applyAgentChange)(ctx, {
106
+ resourceType: 'agent',
107
+ operation: 'update',
108
+ key: 'a1',
109
+ agentUuid: 'agent-1',
110
+ path: 'agents[a1]',
111
+ });
112
+ (0, vitest_1.expect)(ok).toBe(true);
113
+ (0, vitest_1.expect)(updateAgent).toHaveBeenCalledWith(PROJECT_UUID, 'agent-1', {
114
+ uuid: 'agent-1',
115
+ name: 'Governed Agent',
116
+ description: null,
117
+ instruction: null,
118
+ tags: null,
119
+ enableContentTools: true,
120
+ adminOnly: false,
121
+ });
122
+ });
123
+ (0, vitest_1.it)('forwards spaceAccess from bundle spec on update', async () => {
124
+ const spaceUuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
125
+ const updateAgent = vitest_1.vi.fn().mockResolvedValue({});
126
+ const bundleWithSpaces = Object.assign(Object.assign({}, bundle), { spec: Object.assign(Object.assign({}, bundle.spec), { agents: [
127
+ {
128
+ key: 'a1',
129
+ uuid: 'agent-1',
130
+ name: 'Governed Agent',
131
+ spaceAccess: [spaceUuid],
132
+ evaluations: [],
133
+ },
134
+ ] }) });
135
+ const ctx = {
136
+ bundle: bundleWithSpaces,
137
+ projectUuid: PROJECT_UUID,
138
+ client: {
139
+ v1: {
140
+ aiAgents: {
141
+ createAgent: vitest_1.vi.fn(),
142
+ updateAgent,
143
+ deleteAgent: vitest_1.vi.fn(),
144
+ },
145
+ },
146
+ },
147
+ agentUuidByKey: new Map(),
148
+ failed: [],
149
+ };
150
+ const ok = await (0, apply_agent_change_js_1.applyAgentChange)(ctx, {
151
+ resourceType: 'agent',
152
+ operation: 'update',
153
+ key: 'a1',
154
+ agentUuid: 'agent-1',
155
+ path: 'agents[a1]',
156
+ });
157
+ (0, vitest_1.expect)(ok).toBe(true);
158
+ (0, vitest_1.expect)(updateAgent).toHaveBeenCalledWith(PROJECT_UUID, 'agent-1', vitest_1.expect.objectContaining({ spaceAccess: [spaceUuid] }));
159
+ });
160
+ });
@@ -17,7 +17,9 @@ class AiAgentsProjectClient extends base_client_1.BaseApiClient {
17
17
  }
18
18
  /** Create a new agent in a project (POST /projects/{projectUuid}/aiAgents). */
19
19
  async createAgent(projectUuid, body) {
20
- return this.http.post(`/projects/${projectUuid}/aiAgents`, body);
20
+ return this.http.post(`/projects/${projectUuid}/aiAgents`, body, undefined, {
21
+ maxRetries: 0,
22
+ });
21
23
  }
22
24
  /** Update an existing agent (PATCH /projects/{projectUuid}/aiAgents/{agentUuid}). */
23
25
  async updateAgent(projectUuid, agentUuid, body) {
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Project-scoped AI agent knowledge document client.
3
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/documents/...
4
+ */
5
+ import { BaseApiClient } from '../../base-client';
6
+ import type { AiAgentDocument, AiAgentDocumentContent, AiAgentDocumentSummary, CreateAgentDocumentBody, UpdateAgentDocumentContentBody, UpdateAgentDocumentSettingsBody } from '@lightdash-tools/common';
7
+ export declare class AiAgentsDocumentsClient extends BaseApiClient {
8
+ /** List knowledge documents for an agent (GET …/documents). */
9
+ listDocuments(projectUuid: string, agentUuid: string): Promise<AiAgentDocumentSummary[]>;
10
+ /** Read full document content (GET …/documents/{documentUuid}/content). */
11
+ getDocumentContent(projectUuid: string, agentUuid: string, documentUuid: string): Promise<AiAgentDocumentContent>;
12
+ /** Create a knowledge document scoped to this agent (POST …/documents). */
13
+ createDocument(projectUuid: string, agentUuid: string, body: CreateAgentDocumentBody): Promise<AiAgentDocument>;
14
+ /** Replace document name and content (PATCH …/documents/{documentUuid}/content). */
15
+ updateDocumentContent(projectUuid: string, agentUuid: string, documentUuid: string, body: UpdateAgentDocumentContentBody): Promise<AiAgentDocument>;
16
+ /** Update document settings such as alwaysIncludeInContext (PATCH …/documents/{documentUuid}). */
17
+ updateDocumentSettings(projectUuid: string, agentUuid: string, documentUuid: string, body: UpdateAgentDocumentSettingsBody): Promise<void>;
18
+ /** Delete a knowledge document (DELETE …/documents/{documentUuid}). */
19
+ deleteDocument(projectUuid: string, agentUuid: string, documentUuid: string): Promise<void>;
20
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * Project-scoped AI agent knowledge document client.
4
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/documents/...
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.AiAgentsDocumentsClient = void 0;
8
+ const base_client_1 = require("../../base-client");
9
+ class AiAgentsDocumentsClient extends base_client_1.BaseApiClient {
10
+ /** List knowledge documents for an agent (GET …/documents). */
11
+ async listDocuments(projectUuid, agentUuid) {
12
+ return this.http.get(`/projects/${projectUuid}/aiAgents/${agentUuid}/documents`);
13
+ }
14
+ /** Read full document content (GET …/documents/{documentUuid}/content). */
15
+ async getDocumentContent(projectUuid, agentUuid, documentUuid) {
16
+ return this.http.get(`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}/content`);
17
+ }
18
+ /** Create a knowledge document scoped to this agent (POST …/documents). */
19
+ async createDocument(projectUuid, agentUuid, body) {
20
+ return this.http.post(`/projects/${projectUuid}/aiAgents/${agentUuid}/documents`, body, undefined, { maxRetries: 0 });
21
+ }
22
+ /** Replace document name and content (PATCH …/documents/{documentUuid}/content). */
23
+ async updateDocumentContent(projectUuid, agentUuid, documentUuid, body) {
24
+ return this.http.patch(`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}/content`, body);
25
+ }
26
+ /** Update document settings such as alwaysIncludeInContext (PATCH …/documents/{documentUuid}). */
27
+ async updateDocumentSettings(projectUuid, agentUuid, documentUuid, body) {
28
+ await this.http.patch(`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}`, body);
29
+ }
30
+ /** Delete a knowledge document (DELETE …/documents/{documentUuid}). */
31
+ async deleteDocument(projectUuid, agentUuid, documentUuid) {
32
+ await this.http.delete(`/projects/${projectUuid}/aiAgents/${agentUuid}/documents/${documentUuid}`);
33
+ }
34
+ }
35
+ exports.AiAgentsDocumentsClient = AiAgentsDocumentsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const documents_1 = require("./documents");
5
+ (0, vitest_1.describe)('AiAgentsDocumentsClient', () => {
6
+ let mockHttp;
7
+ (0, vitest_1.beforeEach)(() => {
8
+ mockHttp = {
9
+ get: vitest_1.vi.fn(),
10
+ post: vitest_1.vi.fn(),
11
+ put: vitest_1.vi.fn(),
12
+ patch: vitest_1.vi.fn(),
13
+ delete: vitest_1.vi.fn(),
14
+ };
15
+ });
16
+ (0, vitest_1.it)('listDocuments should call GET …/documents', async () => {
17
+ const client = new documents_1.AiAgentsDocumentsClient(mockHttp);
18
+ const summaries = [{ uuid: 'd1', name: 'Glossary' }];
19
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(summaries);
20
+ const result = await client.listDocuments('proj1', 'a1');
21
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents');
22
+ (0, vitest_1.expect)(result).toEqual(summaries);
23
+ });
24
+ (0, vitest_1.it)('getDocumentContent should call GET …/documents/{uuid}/content', async () => {
25
+ const client = new documents_1.AiAgentsDocumentsClient(mockHttp);
26
+ const content = { uuid: 'd1', name: 'Glossary', mimeType: 'text/markdown', content: '# Hi' };
27
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(content);
28
+ const result = await client.getDocumentContent('proj1', 'a1', 'd1');
29
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1/content');
30
+ (0, vitest_1.expect)(result).toEqual(content);
31
+ });
32
+ (0, vitest_1.it)('createDocument should call POST …/documents', async () => {
33
+ const client = new documents_1.AiAgentsDocumentsClient(mockHttp);
34
+ const body = {
35
+ name: 'Glossary',
36
+ content: '# Terms',
37
+ mimeType: 'text/markdown',
38
+ originalFilename: 'Glossary.md',
39
+ };
40
+ const created = Object.assign({ uuid: 'd1' }, body);
41
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(created);
42
+ const result = await client.createDocument('proj1', 'a1', body);
43
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents', body, undefined, { maxRetries: 0 });
44
+ (0, vitest_1.expect)(result).toEqual(created);
45
+ });
46
+ (0, vitest_1.it)('updateDocumentContent should call PATCH …/content', async () => {
47
+ const client = new documents_1.AiAgentsDocumentsClient(mockHttp);
48
+ const body = { name: 'Glossary v2', content: '# Updated' };
49
+ const updated = Object.assign({ uuid: 'd1' }, body);
50
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(updated);
51
+ const result = await client.updateDocumentContent('proj1', 'a1', 'd1', body);
52
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1/content', body);
53
+ (0, vitest_1.expect)(result).toEqual(updated);
54
+ });
55
+ (0, vitest_1.it)('updateDocumentSettings should call PATCH …/documents/{uuid}', async () => {
56
+ const client = new documents_1.AiAgentsDocumentsClient(mockHttp);
57
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(undefined);
58
+ await client.updateDocumentSettings('proj1', 'a1', 'd1', { alwaysIncludeInContext: true });
59
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1', {
60
+ alwaysIncludeInContext: true,
61
+ });
62
+ });
63
+ (0, vitest_1.it)('deleteDocument should call DELETE …/documents/{uuid}', async () => {
64
+ const client = new documents_1.AiAgentsDocumentsClient(mockHttp);
65
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
66
+ await client.deleteDocument('proj1', 'a1', 'd1');
67
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/documents/d1');
68
+ });
69
+ });
@@ -6,12 +6,13 @@ import { BaseApiClient } from '../../base-client';
6
6
  import { type StartConversationThreadBody } from './threads';
7
7
  import type { RequestOptions } from './request-options';
8
8
  import type { HttpClient } from '../../../http/http-client';
9
- import type { AgentSuggestions, AiAgent, AiAgentEvaluation, AiAgentEvaluationRun, AiAgentEvaluationRunSummary, AiAgentEvaluationRunsListResponse, AiAgentEvaluationSummary, AiAgentExploreAccessSummary, AiAgentMcpServerTool, AiAgentsAdminThreadsResult, AiAgentSummary, AiAgentThread, AiAgentThreadMessageVizQuery, AiAgentThreadSummary, AiAgentUserPreferences, AiAgentVerifiedArtifactsListResult, AiAgentVerifiedQuestion, AiArtifact, AiMcpServer, AiMcpServerTool, AiModelOption, AiRouterRouteRequest, AiRouterRouteResponseResult, AppendEvaluationBody, CloneThreadBody, CreateAgentThreadBody, CreateAgentThreadMessageResult, CreateAiAgent, CreateEvaluationBody, CreateEvaluationResult, CreateProjectMcpServerBody, ExploreAccessSummaryBody, GenerateAgentThreadBody, GenerateAgentThreadResult, GenerateThreadTitleResult, GetAdminThreadsParams, GetAgentSuggestionsParams, GetAiOrganizationSettingsResult, ListVerifiedArtifactsParams, ReadinessScore, SubmitSqlApprovalBody, SubmitSqlApprovalResult, UpdateAiAgent, UpdateAiOrganizationSettings, UpdateAiOrganizationSettingsResult, UpdateAgentMcpServerToolsBody, UpdateEvaluationBody, UpdateMessageFeedbackBody } from '@lightdash-tools/common';
9
+ import type { AgentSuggestions, AiAgent, AiAgentDocument, AiAgentDocumentContent, AiAgentDocumentSummary, AiAgentEvaluation, AiAgentEvaluationRun, AiAgentEvaluationRunSummary, AiAgentEvaluationRunsListResponse, AiAgentEvaluationSummary, AiAgentExploreAccessSummary, AiAgentMcpServerTool, AiAgentsAdminThreadsResult, AiAgentSummary, AiAgentThread, AiAgentThreadMessageVizQuery, AiAgentThreadSummary, AiAgentUserPreferences, AiAgentVerifiedArtifactsListResult, AiAgentVerifiedQuestion, AiArtifact, AiMcpServer, AiMcpServerTool, AiModelOption, AiRouterRouteRequest, AiRouterRouteResponseResult, AppendEvaluationBody, CloneThreadBody, CreateAgentThreadBody, CreateAgentThreadMessageResult, CreateAgentDocumentBody, CreateAiAgent, CreateEvaluationBody, CreateEvaluationResult, CreateProjectMcpServerBody, ExploreAccessSummaryBody, GenerateAgentThreadBody, GenerateAgentThreadResult, GenerateThreadTitleResult, GetAdminThreadsParams, GetAgentSuggestionsParams, GetAiOrganizationSettingsResult, ListVerifiedArtifactsParams, ReadinessScore, SubmitSqlApprovalBody, SubmitSqlApprovalResult, UpdateAiAgent, UpdateAiOrganizationSettings, UpdateAgentDocumentContentBody, UpdateAgentDocumentSettingsBody, UpdateAiOrganizationSettingsResult, UpdateAgentMcpServerToolsBody, UpdateEvaluationBody, UpdateMessageFeedbackBody } from '@lightdash-tools/common';
10
10
  export declare class AiAgentsClient extends BaseApiClient {
11
11
  private readonly admin;
12
12
  private readonly agents;
13
13
  private readonly artifacts;
14
14
  private readonly discovery;
15
+ private readonly documents;
15
16
  private readonly threads;
16
17
  private readonly evaluations;
17
18
  private readonly feedback;
@@ -83,4 +84,10 @@ export declare class AiAgentsClient extends BaseApiClient {
83
84
  }): Promise<AiAgentEvaluationRunsListResponse>;
84
85
  listAllEvaluationRuns(projectUuid: string, agentUuid: string, evalUuid: string): Promise<AiAgentEvaluationRunSummary[]>;
85
86
  getEvaluationRunResults(projectUuid: string, agentUuid: string, evalUuid: string, runUuid: string): Promise<AiAgentEvaluationRun>;
87
+ listDocuments(projectUuid: string, agentUuid: string): Promise<AiAgentDocumentSummary[]>;
88
+ getDocumentContent(projectUuid: string, agentUuid: string, documentUuid: string): Promise<AiAgentDocumentContent>;
89
+ createDocument(projectUuid: string, agentUuid: string, body: CreateAgentDocumentBody): Promise<AiAgentDocument>;
90
+ updateDocumentContent(projectUuid: string, agentUuid: string, documentUuid: string, body: UpdateAgentDocumentContentBody): Promise<AiAgentDocument>;
91
+ updateDocumentSettings(projectUuid: string, agentUuid: string, documentUuid: string, body: UpdateAgentDocumentSettingsBody): Promise<void>;
92
+ deleteDocument(projectUuid: string, agentUuid: string, documentUuid: string): Promise<void>;
86
93
  }
@@ -10,6 +10,7 @@ const admin_1 = require("./admin");
10
10
  const agents_1 = require("./agents");
11
11
  const artifacts_1 = require("./artifacts");
12
12
  const discovery_1 = require("./discovery");
13
+ const documents_1 = require("./documents");
13
14
  const evaluations_1 = require("./evaluations");
14
15
  const feedback_1 = require("./feedback");
15
16
  const mcp_servers_1 = require("./mcp-servers");
@@ -23,6 +24,7 @@ class AiAgentsClient extends base_client_1.BaseApiClient {
23
24
  this.agents = new agents_1.AiAgentsProjectClient(http);
24
25
  this.artifacts = new artifacts_1.AiAgentsArtifactsClient(http);
25
26
  this.discovery = new discovery_1.AiAgentsDiscoveryClient(http);
27
+ this.documents = new documents_1.AiAgentsDocumentsClient(http);
26
28
  this.threads = new threads_1.AiAgentsThreadsClient(http);
27
29
  this.evaluations = new evaluations_1.AiAgentsEvaluationsClient(http);
28
30
  this.feedback = new feedback_1.AiAgentsFeedbackClient(http);
@@ -198,5 +200,24 @@ class AiAgentsClient extends base_client_1.BaseApiClient {
198
200
  getEvaluationRunResults(projectUuid, agentUuid, evalUuid, runUuid) {
199
201
  return this.evaluations.getEvaluationRunResults(projectUuid, agentUuid, evalUuid, runUuid);
200
202
  }
203
+ // ─── Project-scoped: knowledge documents ─────────────────────────────────────
204
+ listDocuments(projectUuid, agentUuid) {
205
+ return this.documents.listDocuments(projectUuid, agentUuid);
206
+ }
207
+ getDocumentContent(projectUuid, agentUuid, documentUuid) {
208
+ return this.documents.getDocumentContent(projectUuid, agentUuid, documentUuid);
209
+ }
210
+ createDocument(projectUuid, agentUuid, body) {
211
+ return this.documents.createDocument(projectUuid, agentUuid, body);
212
+ }
213
+ updateDocumentContent(projectUuid, agentUuid, documentUuid, body) {
214
+ return this.documents.updateDocumentContent(projectUuid, agentUuid, documentUuid, body);
215
+ }
216
+ updateDocumentSettings(projectUuid, agentUuid, documentUuid, body) {
217
+ return this.documents.updateDocumentSettings(projectUuid, agentUuid, documentUuid, body);
218
+ }
219
+ deleteDocument(projectUuid, agentUuid, documentUuid) {
220
+ return this.documents.deleteDocument(projectUuid, agentUuid, documentUuid);
221
+ }
201
222
  }
202
223
  exports.AiAgentsClient = AiAgentsClient;
@@ -89,7 +89,9 @@ const ai_agents_1 = require("./ai-agents");
89
89
  const created = { uuid: 'a2', name: 'New Agent', projectUuid: 'proj1' };
90
90
  vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(created);
91
91
  const result = await client.createAgent('proj1', body);
92
- (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents', body);
92
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents', body, undefined, {
93
+ maxRetries: 0,
94
+ });
93
95
  (0, vitest_1.expect)(result).toEqual(created);
94
96
  });
95
97
  (0, vitest_1.it)('updateAgent should call PATCH /projects/{projectUuid}/aiAgents/{agentUuid} with body', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/client",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Client library for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "axios": "^1.19.0",
17
17
  "bottleneck": "^2.19.5",
18
- "@lightdash-tools/common": "0.20.0"
18
+ "@lightdash-tools/common": "0.22.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^25.9.3"
@@ -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, CreateAiAgent } from '@lightdash-tools/common';
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 buildCreateAgentBody(desired: BundleAgentSpec, projectUuid: string): CreateAiAgent {
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
- integrations: [],
18
- imageUrl: null,
19
- groupAccess: [],
20
- userAccess: [],
21
- spaceAccess: [],
22
- enableDataAccess: desired.enableDataAccess ?? false,
23
- enableSelfImprovement: desired.enableSelfImprovement ?? false,
24
- version: 1,
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
- buildCreateAgentBody(desired, projectUuid),
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(projectUuid, agentUuid, {
60
- uuid: agentUuid,
61
- name: desired.name,
62
- description: desired.description ?? null,
63
- instruction: desired.instruction ?? null,
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