@lightdash-tools/client 0.6.0 → 0.7.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.
Files changed (237) hide show
  1. package/README.md +2 -2
  2. package/dist/agentops/apply-agent-change.d.ts +3 -0
  3. package/dist/agentops/apply-agent-change.js +63 -0
  4. package/dist/agentops/apply-bundle-diff.d.ts +13 -0
  5. package/dist/agentops/apply-bundle-diff.js +44 -0
  6. package/dist/agentops/apply-bundle-diff.test.d.ts +1 -0
  7. package/dist/agentops/apply-bundle-diff.test.js +397 -0
  8. package/dist/agentops/apply-context.d.ts +14 -0
  9. package/dist/agentops/apply-context.js +6 -0
  10. package/dist/agentops/apply-evaluation-change.d.ts +3 -0
  11. package/dist/agentops/apply-evaluation-change.js +78 -0
  12. package/dist/agentops/fetch-bundle-state.d.ts +6 -0
  13. package/dist/agentops/fetch-bundle-state.js +20 -0
  14. package/dist/agentops/fetch-bundle-state.test.d.ts +1 -0
  15. package/dist/agentops/fetch-bundle-state.test.js +44 -0
  16. package/dist/agentops/index.d.ts +3 -0
  17. package/dist/agentops/index.js +9 -0
  18. package/dist/agentops/resolve-evaluation-run.d.ts +15 -0
  19. package/dist/agentops/resolve-evaluation-run.js +48 -0
  20. package/dist/api/v1/ai-agents/admin.d.ts +16 -0
  21. package/dist/api/v1/ai-agents/admin.js +29 -0
  22. package/dist/api/v1/ai-agents/agents.d.ts +18 -0
  23. package/dist/api/v1/ai-agents/agents.js +31 -0
  24. package/dist/api/v1/ai-agents/artifacts.d.ts +26 -0
  25. package/dist/api/v1/ai-agents/artifacts.js +41 -0
  26. package/dist/api/v1/ai-agents/artifacts.test.d.ts +1 -0
  27. package/dist/api/v1/ai-agents/artifacts.test.js +69 -0
  28. package/dist/api/v1/ai-agents/discovery.d.ts +28 -0
  29. package/dist/api/v1/ai-agents/discovery.js +46 -0
  30. package/dist/api/v1/ai-agents/discovery.test.d.ts +1 -0
  31. package/dist/api/v1/ai-agents/discovery.test.js +90 -0
  32. package/dist/api/v1/ai-agents/evaluations.d.ts +39 -0
  33. package/dist/api/v1/ai-agents/evaluations.js +70 -0
  34. package/dist/api/v1/ai-agents/facade.d.ts +79 -0
  35. package/dist/api/v1/ai-agents/facade.js +193 -0
  36. package/dist/api/v1/ai-agents/feedback.d.ts +10 -0
  37. package/dist/api/v1/ai-agents/feedback.js +15 -0
  38. package/dist/api/v1/ai-agents/feedback.test.d.ts +1 -0
  39. package/dist/api/v1/ai-agents/feedback.test.js +23 -0
  40. package/dist/api/v1/ai-agents/index.d.ts +1 -0
  41. package/dist/api/v1/ai-agents/index.js +5 -0
  42. package/dist/api/v1/ai-agents/mcp-servers.d.ts +20 -0
  43. package/dist/api/v1/ai-agents/mcp-servers.js +35 -0
  44. package/dist/api/v1/ai-agents/mcp-servers.test.d.ts +1 -0
  45. package/dist/api/v1/ai-agents/mcp-servers.test.js +66 -0
  46. package/dist/api/v1/ai-agents/request-options.d.ts +12 -0
  47. package/dist/api/v1/ai-agents/request-options.js +20 -0
  48. package/dist/api/v1/ai-agents/sql-approval.d.ts +10 -0
  49. package/dist/api/v1/ai-agents/sql-approval.js +15 -0
  50. package/dist/api/v1/ai-agents/sql-approval.test.d.ts +1 -0
  51. package/dist/api/v1/ai-agents/sql-approval.test.js +25 -0
  52. package/dist/api/v1/ai-agents/threads.d.ts +56 -0
  53. package/dist/api/v1/ai-agents/threads.js +97 -0
  54. package/dist/api/v1/ai-agents/threads.test.d.ts +1 -0
  55. package/dist/api/v1/ai-agents/threads.test.js +39 -0
  56. package/dist/api/v1/ai-agents.test.js +172 -89
  57. package/dist/api/v1/analytics.d.ts +10 -0
  58. package/dist/api/v1/analytics.js +14 -0
  59. package/dist/api/v1/analytics.test.d.ts +4 -0
  60. package/dist/api/v1/analytics.test.js +27 -0
  61. package/dist/api/v1/charts.d.ts +5 -2
  62. package/dist/api/v1/charts.js +18 -30
  63. package/dist/api/v1/charts.test.js +19 -28
  64. package/dist/api/v1/dashboards.d.ts +11 -2
  65. package/dist/api/v1/dashboards.js +19 -14
  66. package/dist/api/v1/dashboards.test.js +54 -12
  67. package/dist/api/v1/explores.d.ts +4 -2
  68. package/dist/api/v1/explores.js +20 -29
  69. package/dist/api/v1/explores.test.js +31 -21
  70. package/dist/api/v1/groups.d.ts +1 -1
  71. package/dist/api/v1/groups.js +25 -51
  72. package/dist/api/v1/groups.test.js +15 -24
  73. package/dist/api/v1/metrics.d.ts +2 -2
  74. package/dist/api/v1/metrics.js +4 -17
  75. package/dist/api/v1/metrics.test.js +6 -15
  76. package/dist/api/v1/organizations.d.ts +1 -1
  77. package/dist/api/v1/organizations.js +2 -13
  78. package/dist/api/v1/organizations.test.js +3 -12
  79. package/dist/api/v1/project-access.d.ts +1 -1
  80. package/dist/api/v1/project-access.js +18 -45
  81. package/dist/api/v1/project-access.test.js +27 -36
  82. package/dist/api/v1/projects.d.ts +1 -1
  83. package/dist/api/v1/projects.js +6 -21
  84. package/dist/api/v1/projects.test.js +9 -18
  85. package/dist/api/v1/query.d.ts +5 -2
  86. package/dist/api/v1/query.js +8 -18
  87. package/dist/api/v1/query.test.js +6 -15
  88. package/dist/api/v1/schedulers.d.ts +2 -2
  89. package/dist/api/v1/schedulers.js +4 -17
  90. package/dist/api/v1/schedulers.test.js +6 -15
  91. package/dist/api/v1/spaces.d.ts +1 -1
  92. package/dist/api/v1/spaces.js +18 -45
  93. package/dist/api/v1/spaces.test.js +27 -36
  94. package/dist/api/v1/tags.d.ts +1 -1
  95. package/dist/api/v1/tags.js +4 -17
  96. package/dist/api/v1/tags.test.js +6 -15
  97. package/dist/api/v1/users.d.ts +3 -1
  98. package/dist/api/v1/users.js +22 -39
  99. package/dist/api/v1/users.test.js +44 -30
  100. package/dist/api/v1/validation.d.ts +5 -2
  101. package/dist/api/v1/validation.js +8 -18
  102. package/dist/api/v1/validation.test.js +6 -15
  103. package/dist/api/v2/content.d.ts +2 -2
  104. package/dist/api/v2/content.js +3 -14
  105. package/dist/api/v2/content.test.js +3 -12
  106. package/dist/api/v2/dashboards.d.ts +10 -0
  107. package/dist/api/v2/dashboards.js +14 -0
  108. package/dist/api/v2/dashboards.test.d.ts +4 -0
  109. package/dist/api/v2/dashboards.test.js +27 -0
  110. package/dist/api/v2/organization-roles.d.ts +1 -1
  111. package/dist/api/v2/organization-roles.js +21 -50
  112. package/dist/api/v2/organization-roles.test.js +33 -42
  113. package/dist/api/v2/project-role-assignments.d.ts +1 -1
  114. package/dist/api/v2/project-role-assignments.js +12 -33
  115. package/dist/api/v2/project-role-assignments.test.js +18 -27
  116. package/dist/api/v2/query.d.ts +1 -1
  117. package/dist/api/v2/query.js +10 -29
  118. package/dist/api/v2/query.test.js +15 -24
  119. package/dist/api/v2/validation.d.ts +28 -0
  120. package/dist/api/v2/validation.js +23 -0
  121. package/dist/client.d.ts +20 -14
  122. package/dist/client.js +22 -16
  123. package/dist/config.d.ts +35 -10
  124. package/dist/http/axios-client.d.ts +4 -4
  125. package/dist/http/http-client.d.ts +3 -3
  126. package/dist/http/http-client.js +19 -40
  127. package/dist/http/interceptors.d.ts +3 -3
  128. package/dist/http/interceptors.js +16 -3
  129. package/dist/http/rate-limiter.js +2 -13
  130. package/dist/http/rate-limiter.test.js +15 -24
  131. package/dist/index.d.ts +7 -2
  132. package/dist/index.js +12 -1
  133. package/dist/index.test.js +13 -5
  134. package/dist/pagination/fetch-all-pages.js +18 -29
  135. package/dist/pagination/fetch-all-pages.test.js +15 -24
  136. package/dist/types/api.d.ts +1 -1
  137. package/dist/utils/env.d.ts +11 -2
  138. package/dist/utils/env.js +41 -8
  139. package/dist/utils/env.test.js +14 -4
  140. package/dist/utils/logger.js +5 -4
  141. package/dist/utils/retry.js +17 -28
  142. package/dist/utils/retry.test.js +9 -18
  143. package/dist/utils/secret-string.test.d.ts +1 -0
  144. package/dist/utils/secret-string.test.js +25 -0
  145. package/package.json +12 -4
  146. package/src/agentops/apply-agent-change.ts +82 -0
  147. package/src/agentops/apply-bundle-diff.test.ts +453 -0
  148. package/src/agentops/apply-bundle-diff.ts +63 -0
  149. package/src/agentops/apply-context.ts +23 -0
  150. package/src/agentops/apply-evaluation-change.ts +125 -0
  151. package/src/agentops/fetch-bundle-state.test.ts +51 -0
  152. package/src/agentops/fetch-bundle-state.ts +33 -0
  153. package/src/agentops/index.ts +11 -0
  154. package/src/agentops/resolve-evaluation-run.ts +94 -0
  155. package/src/api/v1/ai-agents/admin.ts +41 -0
  156. package/src/api/v1/ai-agents/agents.ts +40 -0
  157. package/src/api/v1/ai-agents/artifacts.test.ts +84 -0
  158. package/src/api/v1/ai-agents/artifacts.ts +92 -0
  159. package/src/api/v1/ai-agents/discovery.test.ts +102 -0
  160. package/src/api/v1/ai-agents/discovery.ts +79 -0
  161. package/src/api/v1/ai-agents/evaluations.ts +152 -0
  162. package/src/api/v1/ai-agents/facade.ts +489 -0
  163. package/src/api/v1/ai-agents/feedback.test.ts +30 -0
  164. package/src/api/v1/ai-agents/feedback.ts +24 -0
  165. package/src/api/v1/ai-agents/index.ts +1 -0
  166. package/src/api/v1/ai-agents/mcp-servers.test.ts +81 -0
  167. package/src/api/v1/ai-agents/mcp-servers.ts +67 -0
  168. package/src/api/v1/ai-agents/request-options.ts +32 -0
  169. package/src/api/v1/ai-agents/sql-approval.test.ts +32 -0
  170. package/src/api/v1/ai-agents/sql-approval.ts +24 -0
  171. package/src/api/v1/ai-agents/threads.test.ts +55 -0
  172. package/src/api/v1/ai-agents/threads.ts +216 -0
  173. package/src/api/v1/ai-agents.test.ts +189 -13
  174. package/src/api/v1/analytics.test.ts +32 -0
  175. package/src/api/v1/analytics.ts +16 -0
  176. package/src/api/v1/charts.test.ts +8 -6
  177. package/src/api/v1/charts.ts +8 -4
  178. package/src/api/v1/dashboards.test.ts +57 -0
  179. package/src/api/v1/dashboards.ts +41 -2
  180. package/src/api/v1/explores.test.ts +22 -0
  181. package/src/api/v1/explores.ts +13 -2
  182. package/src/api/v1/groups.test.ts +2 -0
  183. package/src/api/v1/groups.ts +9 -7
  184. package/src/api/v1/metrics.test.ts +2 -0
  185. package/src/api/v1/metrics.ts +3 -2
  186. package/src/api/v1/organizations.test.ts +2 -0
  187. package/src/api/v1/organizations.ts +2 -1
  188. package/src/api/v1/project-access.test.ts +3 -1
  189. package/src/api/v1/project-access.ts +2 -1
  190. package/src/api/v1/projects.test.ts +2 -0
  191. package/src/api/v1/projects.ts +2 -1
  192. package/src/api/v1/query.test.ts +2 -0
  193. package/src/api/v1/query.ts +6 -2
  194. package/src/api/v1/schedulers.test.ts +2 -0
  195. package/src/api/v1/schedulers.ts +3 -2
  196. package/src/api/v1/spaces.test.ts +2 -0
  197. package/src/api/v1/spaces.ts +2 -1
  198. package/src/api/v1/tags.test.ts +2 -0
  199. package/src/api/v1/tags.ts +2 -1
  200. package/src/api/v1/users.test.ts +26 -0
  201. package/src/api/v1/users.ts +8 -2
  202. package/src/api/v1/validation.test.ts +2 -0
  203. package/src/api/v1/validation.ts +6 -2
  204. package/src/api/v2/content.test.ts +2 -0
  205. package/src/api/v2/content.ts +3 -2
  206. package/src/api/v2/dashboards.test.ts +32 -0
  207. package/src/api/v2/dashboards.ts +18 -0
  208. package/src/api/v2/organization-roles.test.ts +2 -0
  209. package/src/api/v2/organization-roles.ts +2 -1
  210. package/src/api/v2/project-role-assignments.test.ts +2 -0
  211. package/src/api/v2/project-role-assignments.ts +2 -1
  212. package/src/api/v2/query.test.ts +2 -0
  213. package/src/api/v2/query.ts +2 -1
  214. package/src/api/v2/validation.ts +48 -0
  215. package/src/client.test.ts +1 -0
  216. package/src/client.ts +27 -17
  217. package/src/config.ts +38 -10
  218. package/src/errors.test.ts +1 -0
  219. package/src/http/axios-client.ts +8 -5
  220. package/src/http/http-client.ts +8 -6
  221. package/src/http/interceptors.ts +23 -10
  222. package/src/http/rate-limiter.test.ts +1 -0
  223. package/src/http/rate-limiter.ts +3 -1
  224. package/src/index.test.ts +16 -7
  225. package/src/index.ts +16 -1
  226. package/src/pagination/fetch-all-pages.test.ts +2 -0
  227. package/src/types/api.ts +1 -1
  228. package/src/utils/env.test.ts +16 -4
  229. package/src/utils/env.ts +61 -10
  230. package/src/utils/logger.ts +6 -4
  231. package/src/utils/retry.test.ts +1 -0
  232. package/src/utils/retry.ts +2 -1
  233. package/src/utils/secret-string.test.ts +27 -0
  234. package/tsconfig.json +4 -2
  235. package/dist/api/v1/ai-agents.d.ts +0 -63
  236. package/dist/api/v1/ai-agents.js +0 -173
  237. package/src/api/v1/ai-agents.ts +0 -252
@@ -0,0 +1,81 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+
3
+ import { AiAgentsMcpServersClient } from './mcp-servers';
4
+
5
+ import type { HttpClient } from '../../../http/http-client';
6
+
7
+ describe('AiAgentsMcpServersClient', () => {
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('listProjectMcpServers should call GET …/mcpServers', async () => {
21
+ const client = new AiAgentsMcpServersClient(mockHttp);
22
+ const servers = [{ uuid: 'mcp1', name: 'GitHub' }];
23
+ vi.mocked(mockHttp.get).mockResolvedValue(servers);
24
+ const result = await client.listProjectMcpServers('proj1');
25
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/mcpServers');
26
+ expect(result).toEqual(servers);
27
+ });
28
+
29
+ it('createProjectMcpServer should call POST …/mcpServers', async () => {
30
+ const client = new AiAgentsMcpServersClient(mockHttp);
31
+ const body = { name: 'Custom', url: 'https://mcp.example.com', authType: 'none' as const };
32
+ const created = { uuid: 'mcp2', ...body };
33
+ vi.mocked(mockHttp.post).mockResolvedValue(created);
34
+ const result = await client.createProjectMcpServer('proj1', body);
35
+ expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/mcpServers', body);
36
+ expect(result).toEqual(created);
37
+ });
38
+
39
+ it('listMcpServerTools should call GET …/mcpServers/{mcpServerUuid}/tools', async () => {
40
+ const client = new AiAgentsMcpServersClient(mockHttp);
41
+ const tools = [{ uuid: 'tool1', toolName: 'search' }];
42
+ vi.mocked(mockHttp.get).mockResolvedValue(tools);
43
+ const result = await client.listMcpServerTools('proj1', 'mcp1');
44
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/mcpServers/mcp1/tools');
45
+ expect(result).toEqual(tools);
46
+ });
47
+
48
+ it('refreshMcpServerTools should call POST …/tools/refresh', async () => {
49
+ const client = new AiAgentsMcpServersClient(mockHttp);
50
+ const tools = [{ uuid: 'tool1', toolName: 'search' }];
51
+ vi.mocked(mockHttp.post).mockResolvedValue(tools);
52
+ const result = await client.refreshMcpServerTools('proj1', 'mcp1');
53
+ expect(mockHttp.post).toHaveBeenCalledWith(
54
+ '/projects/proj1/aiAgents/mcpServers/mcp1/tools/refresh',
55
+ {},
56
+ );
57
+ expect(result).toEqual(tools);
58
+ });
59
+
60
+ it('listAgentMcpServers should call GET …/{agentUuid}/mcpServers', async () => {
61
+ const client = new AiAgentsMcpServersClient(mockHttp);
62
+ const servers = [{ uuid: 'mcp1', name: 'GitHub' }];
63
+ vi.mocked(mockHttp.get).mockResolvedValue(servers);
64
+ const result = await client.listAgentMcpServers('proj1', 'a1');
65
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/mcpServers');
66
+ expect(result).toEqual(servers);
67
+ });
68
+
69
+ it('updateAgentMcpServerTools should call PATCH …/{agentUuid}/mcpServers/{mcpServerUuid}/tools', async () => {
70
+ const client = new AiAgentsMcpServersClient(mockHttp);
71
+ const body = { toolSettings: [{ toolName: 'search', enabled: true }] };
72
+ const tools = [{ uuid: 'tool1', toolName: 'search', enabled: true }];
73
+ vi.mocked(mockHttp.patch).mockResolvedValue(tools);
74
+ const result = await client.updateAgentMcpServerTools('proj1', 'a1', 'mcp1', body);
75
+ expect(mockHttp.patch).toHaveBeenCalledWith(
76
+ '/projects/proj1/aiAgents/a1/mcpServers/mcp1/tools',
77
+ body,
78
+ );
79
+ expect(result).toEqual(tools);
80
+ });
81
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * AI agent MCP server client (EE-guarded upstream).
3
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/mcpServers/...
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import type {
9
+ AiAgentMcpServerTool,
10
+ AiMcpServer,
11
+ AiMcpServerTool,
12
+ CreateProjectMcpServerBody,
13
+ UpdateAgentMcpServerToolsBody,
14
+ } from '@lightdash-tools/common';
15
+
16
+ export class AiAgentsMcpServersClient extends BaseApiClient {
17
+ /** List MCP servers configured for a project (GET …/mcpServers). */
18
+ async listProjectMcpServers(projectUuid: string): Promise<AiMcpServer[]> {
19
+ return this.http.get<AiMcpServer[]>(`/projects/${projectUuid}/aiAgents/mcpServers`);
20
+ }
21
+
22
+ /** Create a project MCP server (POST …/mcpServers). */
23
+ async createProjectMcpServer(
24
+ projectUuid: string,
25
+ body: CreateProjectMcpServerBody,
26
+ ): Promise<AiMcpServer> {
27
+ return this.http.post<AiMcpServer>(`/projects/${projectUuid}/aiAgents/mcpServers`, body);
28
+ }
29
+
30
+ /** List tools exposed by a project MCP server (GET …/mcpServers/{mcpServerUuid}/tools). */
31
+ async listMcpServerTools(projectUuid: string, mcpServerUuid: string): Promise<AiMcpServerTool[]> {
32
+ return this.http.get<AiMcpServerTool[]>(
33
+ `/projects/${projectUuid}/aiAgents/mcpServers/${mcpServerUuid}/tools`,
34
+ );
35
+ }
36
+
37
+ /** Refresh tools from the remote MCP server (POST …/tools/refresh). */
38
+ async refreshMcpServerTools(
39
+ projectUuid: string,
40
+ mcpServerUuid: string,
41
+ ): Promise<AiMcpServerTool[]> {
42
+ return this.http.post<AiMcpServerTool[]>(
43
+ `/projects/${projectUuid}/aiAgents/mcpServers/${mcpServerUuid}/tools/refresh`,
44
+ {},
45
+ );
46
+ }
47
+
48
+ /** List MCP servers linked to an agent (GET …/{agentUuid}/mcpServers). */
49
+ async listAgentMcpServers(projectUuid: string, agentUuid: string): Promise<AiMcpServer[]> {
50
+ return this.http.get<AiMcpServer[]>(
51
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/mcpServers`,
52
+ );
53
+ }
54
+
55
+ /** Update per-agent tool enablement (PATCH …/{agentUuid}/mcpServers/{mcpServerUuid}/tools). */
56
+ async updateAgentMcpServerTools(
57
+ projectUuid: string,
58
+ agentUuid: string,
59
+ mcpServerUuid: string,
60
+ body: UpdateAgentMcpServerToolsBody,
61
+ ): Promise<AiAgentMcpServerTool[]> {
62
+ return this.http.patch<AiAgentMcpServerTool[]>(
63
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/mcpServers/${mcpServerUuid}/tools`,
64
+ body,
65
+ );
66
+ }
67
+ }
@@ -0,0 +1,32 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+
3
+ /** Per-request overrides for AI agent thread operations. */
4
+ export interface RequestOptions {
5
+ /** AbortSignal for request cancellation. */
6
+ signal?: AbortSignal;
7
+ /** Request timeout in milliseconds. */
8
+ timeoutMs?: number;
9
+ /** Optional correlation ID sent as `X-Request-Id`. */
10
+ requestId?: string;
11
+ }
12
+
13
+ /** Maps {@link RequestOptions} to Axios request config. */
14
+ export function toAxiosConfig(options?: RequestOptions): AxiosRequestConfig | undefined {
15
+ if (!options) {
16
+ return undefined;
17
+ }
18
+
19
+ const config: AxiosRequestConfig = {};
20
+
21
+ if (options.signal !== undefined) {
22
+ config.signal = options.signal;
23
+ }
24
+ if (options.timeoutMs !== undefined) {
25
+ config.timeout = options.timeoutMs;
26
+ }
27
+ if (options.requestId !== undefined) {
28
+ config.headers = { 'X-Request-Id': options.requestId };
29
+ }
30
+
31
+ return Object.keys(config).length > 0 ? config : undefined;
32
+ }
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+
3
+ import { AiAgentsSqlApprovalClient } from './sql-approval';
4
+
5
+ import type { HttpClient } from '../../../http/http-client';
6
+
7
+ describe('AiAgentsSqlApprovalClient', () => {
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('submitSqlApproval should call POST …/tool-calls/{toolCallId}/sql-approval', async () => {
21
+ const client = new AiAgentsSqlApprovalClient(mockHttp);
22
+ const body = { decision: 'approved' as const };
23
+ const result = { decision: 'approved' as const };
24
+ vi.mocked(mockHttp.post).mockResolvedValue(result);
25
+ const response = await client.submitSqlApproval('proj1', 'a1', 't1', 'call-1', body);
26
+ expect(mockHttp.post).toHaveBeenCalledWith(
27
+ '/projects/proj1/aiAgents/a1/threads/t1/tool-calls/call-1/sql-approval',
28
+ body,
29
+ );
30
+ expect(response).toEqual(result);
31
+ });
32
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * AI agent SQL approval client.
3
+ * Endpoints: …/threads/{threadUuid}/tool-calls/{toolCallId}/sql-approval
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import type { SubmitSqlApprovalBody, SubmitSqlApprovalResult } from '@lightdash-tools/common';
9
+
10
+ export class AiAgentsSqlApprovalClient extends BaseApiClient {
11
+ /** Submit an approval decision for a pending SQL tool call (POST …/sql-approval). */
12
+ async submitSqlApproval(
13
+ projectUuid: string,
14
+ agentUuid: string,
15
+ threadUuid: string,
16
+ toolCallId: string,
17
+ body: SubmitSqlApprovalBody,
18
+ ): Promise<SubmitSqlApprovalResult> {
19
+ return this.http.post<SubmitSqlApprovalResult>(
20
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads/${threadUuid}/tool-calls/${toolCallId}/sql-approval`,
21
+ body,
22
+ );
23
+ }
24
+ }
@@ -0,0 +1,55 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+
3
+ import { AiAgentsThreadsClient } from './threads';
4
+
5
+ import type { HttpClient } from '../../../http/http-client';
6
+
7
+ describe('AiAgentsThreadsClient extensions', () => {
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('generateThreadTitle should call POST …/generate-title', async () => {
21
+ const client = new AiAgentsThreadsClient(mockHttp);
22
+ const title = { title: 'Revenue analysis' };
23
+ vi.mocked(mockHttp.post).mockResolvedValue(title);
24
+ const result = await client.generateThreadTitle('proj1', 'a1', 't1');
25
+ expect(mockHttp.post).toHaveBeenCalledWith(
26
+ '/projects/proj1/aiAgents/a1/threads/t1/generate-title',
27
+ undefined,
28
+ undefined,
29
+ );
30
+ expect(result).toEqual(title);
31
+ });
32
+
33
+ it('cloneThread should call POST …/clone/{promptUuid}', async () => {
34
+ const client = new AiAgentsThreadsClient(mockHttp);
35
+ const thread = { uuid: 't2', title: 'Clone' };
36
+ vi.mocked(mockHttp.post).mockResolvedValue(thread);
37
+ const result = await client.cloneThread('proj1', 'a1', 't1', {
38
+ promptUuid: 'p1',
39
+ createdFrom: 'web_app',
40
+ });
41
+ expect(mockHttp.post).toHaveBeenCalledWith(
42
+ '/projects/proj1/aiAgents/a1/threads/t1/clone/p1',
43
+ undefined,
44
+ { params: { createdFrom: 'web_app' } },
45
+ );
46
+ expect(result).toEqual(thread);
47
+ });
48
+
49
+ it('cloneThread without body should throw', async () => {
50
+ const client = new AiAgentsThreadsClient(mockHttp);
51
+ await expect(client.cloneThread('proj1', 'a1', 't1')).rejects.toThrow(
52
+ 'cloneThread requires body.promptUuid',
53
+ );
54
+ });
55
+ });
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Project-scoped AI agent thread client.
3
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/threads/...
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import { toAxiosConfig } from './request-options';
9
+
10
+ import type { RequestOptions } from './request-options';
11
+ import type {
12
+ AiAgentThread,
13
+ AiAgentThreadSummary,
14
+ CloneThreadBody,
15
+ CreateAgentThreadBody,
16
+ CreateAgentThreadMessageResult,
17
+ GenerateAgentThreadBody,
18
+ GenerateAgentThreadResult,
19
+ GenerateThreadTitleResult,
20
+ } from '@lightdash-tools/common';
21
+
22
+ /** Thread metadata for {@link startConversation}; the user prompt is sent via the message body. */
23
+ export type StartConversationThreadBody = Omit<CreateAgentThreadBody, 'prompt'>;
24
+
25
+ function toCreateThreadBody(
26
+ threadBody: StartConversationThreadBody | undefined,
27
+ ): CreateAgentThreadBody | undefined {
28
+ if (threadBody === undefined) {
29
+ return undefined;
30
+ }
31
+ const body: CreateAgentThreadBody = { ...threadBody };
32
+ delete body.prompt;
33
+ return body;
34
+ }
35
+
36
+ export class AiAgentsThreadsClient extends BaseApiClient {
37
+ /** List all threads for an agent (GET /projects/{projectUuid}/aiAgents/{agentUuid}/threads). */
38
+ async listAgentThreads(projectUuid: string, agentUuid: string): Promise<AiAgentThreadSummary[]> {
39
+ return this.http.get<AiAgentThreadSummary[]>(
40
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads`,
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Create a new thread (POST /projects/{projectUuid}/aiAgents/{agentUuid}/threads).
46
+ * Does not send a prompt; use {@link createAgentThreadMessage} and
47
+ * {@link generateAgentThreadResponse} for the RFC conversation flow.
48
+ */
49
+ async createAgentThread(
50
+ projectUuid: string,
51
+ agentUuid: string,
52
+ body?: CreateAgentThreadBody,
53
+ options?: RequestOptions,
54
+ ): Promise<AiAgentThreadSummary> {
55
+ return this.http.post<AiAgentThreadSummary>(
56
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads`,
57
+ body ?? {},
58
+ toAxiosConfig(options),
59
+ );
60
+ }
61
+
62
+ /** Get a thread with its messages (GET …/threads/{threadUuid}). */
63
+ async getAgentThread(
64
+ projectUuid: string,
65
+ agentUuid: string,
66
+ threadUuid: string,
67
+ options?: RequestOptions,
68
+ ): Promise<AiAgentThread> {
69
+ return this.http.get<AiAgentThread>(
70
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads/${threadUuid}`,
71
+ toAxiosConfig(options),
72
+ );
73
+ }
74
+
75
+ /**
76
+ * Add a user message to a thread
77
+ * (POST …/threads/{threadUuid}/messages).
78
+ */
79
+ async createAgentThreadMessage(
80
+ projectUuid: string,
81
+ agentUuid: string,
82
+ threadUuid: string,
83
+ body: GenerateAgentThreadBody,
84
+ options?: RequestOptions,
85
+ ): Promise<CreateAgentThreadMessageResult> {
86
+ return this.http.post<CreateAgentThreadMessageResult>(
87
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads/${threadUuid}/messages`,
88
+ body,
89
+ toAxiosConfig(options),
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Trigger agent generation for the latest pending user message
95
+ * (POST …/threads/{threadUuid}/generate). Sends no request body.
96
+ */
97
+ async generateAgentThreadResponse(
98
+ projectUuid: string,
99
+ agentUuid: string,
100
+ threadUuid: string,
101
+ options?: RequestOptions,
102
+ ): Promise<GenerateAgentThreadResult>;
103
+
104
+ /**
105
+ * @deprecated Pass the prompt via {@link createAgentThreadMessage} first. When `body` is
106
+ * provided, creates the message then calls generate for backward compatibility.
107
+ */
108
+ async generateAgentThreadResponse(
109
+ projectUuid: string,
110
+ agentUuid: string,
111
+ threadUuid: string,
112
+ body: GenerateAgentThreadBody,
113
+ options?: RequestOptions,
114
+ ): Promise<GenerateAgentThreadResult>;
115
+
116
+ async generateAgentThreadResponse(
117
+ projectUuid: string,
118
+ agentUuid: string,
119
+ threadUuid: string,
120
+ bodyOrOptions?: GenerateAgentThreadBody | RequestOptions,
121
+ maybeOptions?: RequestOptions,
122
+ ): Promise<GenerateAgentThreadResult> {
123
+ const hasPromptBody =
124
+ bodyOrOptions !== undefined && typeof bodyOrOptions === 'object' && 'prompt' in bodyOrOptions;
125
+
126
+ if (hasPromptBody) {
127
+ const body = bodyOrOptions as GenerateAgentThreadBody;
128
+ const options = maybeOptions;
129
+ await this.createAgentThreadMessage(projectUuid, agentUuid, threadUuid, body, options);
130
+ return this.generateAgentThreadResponse(projectUuid, agentUuid, threadUuid, options);
131
+ }
132
+
133
+ const options = (hasPromptBody ? maybeOptions : bodyOrOptions) as RequestOptions | undefined;
134
+ return this.http.post<GenerateAgentThreadResult>(
135
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads/${threadUuid}/generate`,
136
+ undefined,
137
+ toAxiosConfig(options),
138
+ );
139
+ }
140
+
141
+ /**
142
+ * Start a new conversation: create thread → add user message → generate response.
143
+ */
144
+ async startConversation(
145
+ projectUuid: string,
146
+ agentUuid: string,
147
+ body: GenerateAgentThreadBody,
148
+ options?: RequestOptions & { threadBody?: StartConversationThreadBody },
149
+ ): Promise<{ thread: AiAgentThreadSummary; result: GenerateAgentThreadResult }> {
150
+ const { threadBody, ...requestOptions } = options ?? {};
151
+ const thread = await this.createAgentThread(
152
+ projectUuid,
153
+ agentUuid,
154
+ toCreateThreadBody(threadBody),
155
+ requestOptions,
156
+ );
157
+ await this.createAgentThreadMessage(projectUuid, agentUuid, thread.uuid, body, requestOptions);
158
+ const result = await this.generateAgentThreadResponse(
159
+ projectUuid,
160
+ agentUuid,
161
+ thread.uuid,
162
+ requestOptions,
163
+ );
164
+ return { thread, result };
165
+ }
166
+
167
+ /**
168
+ * Continue an existing conversation: add user message → generate response.
169
+ */
170
+ async continueConversation(
171
+ projectUuid: string,
172
+ agentUuid: string,
173
+ threadUuid: string,
174
+ body: GenerateAgentThreadBody,
175
+ options?: RequestOptions,
176
+ ): Promise<GenerateAgentThreadResult> {
177
+ await this.createAgentThreadMessage(projectUuid, agentUuid, threadUuid, body, options);
178
+ return this.generateAgentThreadResponse(projectUuid, agentUuid, threadUuid, options);
179
+ }
180
+
181
+ /** Generate a title for a thread (POST …/threads/{threadUuid}/generate-title). */
182
+ async generateThreadTitle(
183
+ projectUuid: string,
184
+ agentUuid: string,
185
+ threadUuid: string,
186
+ options?: RequestOptions,
187
+ ): Promise<GenerateThreadTitleResult> {
188
+ return this.http.post<GenerateThreadTitleResult>(
189
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads/${threadUuid}/generate-title`,
190
+ undefined,
191
+ toAxiosConfig(options),
192
+ );
193
+ }
194
+
195
+ /**
196
+ * Clone a thread from an existing prompt
197
+ * (POST …/threads/{threadUuid}/clone/{promptUuid}).
198
+ */
199
+ async cloneThread(
200
+ projectUuid: string,
201
+ agentUuid: string,
202
+ threadUuid: string,
203
+ body?: CloneThreadBody,
204
+ ): Promise<AiAgentThreadSummary> {
205
+ const promptUuid = body?.promptUuid;
206
+ if (!promptUuid) {
207
+ throw new Error('cloneThread requires body.promptUuid');
208
+ }
209
+
210
+ return this.http.post<AiAgentThreadSummary>(
211
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/threads/${threadUuid}/clone/${promptUuid}`,
212
+ undefined,
213
+ body.createdFrom === undefined ? undefined : { params: { createdFrom: body.createdFrom } },
214
+ );
215
+ }
216
+ }