@lightdash-tools/client 0.5.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,33 @@
1
+ /**
2
+ * Fetches current Lightdash state for AgentOps bundle operations.
3
+ */
4
+
5
+ import { toAgentSnapshot, toEvaluationSnapshot } from '@lightdash-tools/common';
6
+
7
+ import type { LightdashClient } from '../client';
8
+ import type { BundleCurrentState, LightdashAiAgentBundle } from '@lightdash-tools/common';
9
+
10
+ export async function fetchBundleCurrentState(
11
+ client: LightdashClient,
12
+ bundle: LightdashAiAgentBundle,
13
+ ): Promise<BundleCurrentState> {
14
+ const projectUuid = bundle.spec.projectUuid;
15
+ const summaries = await client.v1.aiAgents.listAgents(projectUuid);
16
+
17
+ const agents = await Promise.all(
18
+ summaries.map(async (summary) => {
19
+ const evalSummaries = await client.v1.aiAgents.listEvaluations(projectUuid, summary.uuid);
20
+ const evaluations = await Promise.all(
21
+ evalSummaries.map((e) =>
22
+ client.v1.aiAgents.getEvaluation(projectUuid, summary.uuid, e.evalUuid),
23
+ ),
24
+ );
25
+ return {
26
+ agent: toAgentSnapshot(summary),
27
+ evaluations: evaluations.map(toEvaluationSnapshot),
28
+ };
29
+ }),
30
+ );
31
+
32
+ return { projectUuid, agents };
33
+ }
@@ -0,0 +1,11 @@
1
+ export { fetchBundleCurrentState } from './fetch-bundle-state';
2
+ export {
3
+ applyBundleDiff,
4
+ type ApplyBundleDiffFailure,
5
+ type ApplyBundleDiffResult,
6
+ } from './apply-bundle-diff';
7
+ export {
8
+ resolveEvaluationRun,
9
+ type ResolveEvaluationRunOptions,
10
+ type ResolveEvaluationRunResult,
11
+ } from './resolve-evaluation-run';
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Resolves and optionally polls an evaluation run for AgentOps gate workflows.
3
+ */
4
+
5
+ import { toGateRunSnapshot } from '@lightdash-tools/common';
6
+
7
+ import type { LightdashClient } from '../client';
8
+ import type { GateRunSnapshot, LightdashAiEvaluationGate } from '@lightdash-tools/common';
9
+
10
+ export interface ResolveEvaluationRunOptions {
11
+ wait: boolean;
12
+ timeoutMs: number;
13
+ pollIntervalMs: number;
14
+ }
15
+
16
+ export interface ResolveEvaluationRunResult {
17
+ run: GateRunSnapshot;
18
+ timedOut: boolean;
19
+ }
20
+
21
+ function sleep(ms: number): Promise<void> {
22
+ return new Promise((resolve) => {
23
+ setTimeout(resolve, ms);
24
+ });
25
+ }
26
+
27
+ async function resolveRunUuid(
28
+ client: LightdashClient,
29
+ gate: LightdashAiEvaluationGate,
30
+ ): Promise<string> {
31
+ const { projectUuid, agentUuid, evaluationUuid } = gate.spec;
32
+ let runUuid = gate.spec.runUuid;
33
+
34
+ if (!runUuid && gate.spec.triggerRun) {
35
+ const triggered = await client.v1.aiAgents.runEvaluation(
36
+ projectUuid,
37
+ agentUuid,
38
+ evaluationUuid,
39
+ );
40
+ runUuid = triggered.runUuid;
41
+ }
42
+
43
+ if (!runUuid) {
44
+ const response = await client.v1.aiAgents.listEvaluationRuns(
45
+ projectUuid,
46
+ agentUuid,
47
+ evaluationUuid,
48
+ { page: 1, pageSize: 100 },
49
+ );
50
+ const latest = [...response.data.runs].sort(
51
+ (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
52
+ )[0];
53
+ if (!latest) {
54
+ throw new Error('No evaluation runs found. Set spec.triggerRun: true or spec.runUuid.');
55
+ }
56
+ runUuid = latest.runUuid;
57
+ }
58
+
59
+ return runUuid;
60
+ }
61
+
62
+ export async function resolveEvaluationRun(
63
+ client: LightdashClient,
64
+ gate: LightdashAiEvaluationGate,
65
+ options: ResolveEvaluationRunOptions,
66
+ ): Promise<ResolveEvaluationRunResult> {
67
+ const { projectUuid, agentUuid, evaluationUuid } = gate.spec;
68
+ const runUuid = await resolveRunUuid(client, gate);
69
+ const deadline = Date.now() + options.timeoutMs;
70
+
71
+ while (true) {
72
+ const run = await client.v1.aiAgents.getEvaluationRunResults(
73
+ projectUuid,
74
+ agentUuid,
75
+ evaluationUuid,
76
+ runUuid,
77
+ );
78
+ const snapshot = toGateRunSnapshot(run);
79
+
80
+ if (snapshot.status === 'completed' || snapshot.status === 'failed') {
81
+ return { run: snapshot, timedOut: false };
82
+ }
83
+
84
+ if (!options.wait) {
85
+ return { run: snapshot, timedOut: false };
86
+ }
87
+
88
+ if (Date.now() >= deadline) {
89
+ return { run: snapshot, timedOut: true };
90
+ }
91
+
92
+ await sleep(options.pollIntervalMs);
93
+ }
94
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * AI agents admin API client.
3
+ * Endpoints: /api/v1/aiAgents/admin/...
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import type {
9
+ AiAgentSummary,
10
+ AiAgentsAdminThreadsResult,
11
+ GetAdminThreadsParams,
12
+ GetAiOrganizationSettingsResult,
13
+ UpdateAiOrganizationSettings,
14
+ UpdateAiOrganizationSettingsResult,
15
+ } from '@lightdash-tools/common';
16
+
17
+ export class AiAgentsAdminClient extends BaseApiClient {
18
+ /** List all AI agent threads across the org (admin). Supports pagination and filters. */
19
+ async getAdminThreads(params?: GetAdminThreadsParams): Promise<AiAgentsAdminThreadsResult> {
20
+ return this.http.get<AiAgentsAdminThreadsResult>('/aiAgents/admin/threads', {
21
+ params,
22
+ });
23
+ }
24
+
25
+ /** List all AI agents across the org (admin). */
26
+ async listAdminAgents(): Promise<AiAgentSummary[]> {
27
+ return this.http.get<AiAgentSummary[]>('/aiAgents/admin/agents');
28
+ }
29
+
30
+ /** Get AI organization settings. */
31
+ async getAiOrganizationSettings(): Promise<GetAiOrganizationSettingsResult> {
32
+ return this.http.get<GetAiOrganizationSettingsResult>('/aiAgents/admin/settings');
33
+ }
34
+
35
+ /** Update AI organization settings. */
36
+ async updateAiOrganizationSettings(
37
+ body: UpdateAiOrganizationSettings,
38
+ ): Promise<UpdateAiOrganizationSettingsResult> {
39
+ return this.http.patch<UpdateAiOrganizationSettingsResult>('/aiAgents/admin/settings', body);
40
+ }
41
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Project-scoped AI agent CRUD client.
3
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/...
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import type {
9
+ AiAgent,
10
+ AiAgentSummary,
11
+ CreateAiAgent,
12
+ UpdateAiAgent,
13
+ } from '@lightdash-tools/common';
14
+
15
+ export class AiAgentsProjectClient extends BaseApiClient {
16
+ /** List all agents in a project (GET /projects/{projectUuid}/aiAgents). */
17
+ async listAgents(projectUuid: string): Promise<AiAgentSummary[]> {
18
+ return this.http.get<AiAgentSummary[]>(`/projects/${projectUuid}/aiAgents`);
19
+ }
20
+
21
+ /** Get a single agent by UUID (GET /projects/{projectUuid}/aiAgents/{agentUuid}). */
22
+ async getAgent(projectUuid: string, agentUuid: string): Promise<AiAgent> {
23
+ return this.http.get<AiAgent>(`/projects/${projectUuid}/aiAgents/${agentUuid}`);
24
+ }
25
+
26
+ /** Create a new agent in a project (POST /projects/{projectUuid}/aiAgents). */
27
+ async createAgent(projectUuid: string, body: CreateAiAgent): Promise<AiAgent> {
28
+ return this.http.post<AiAgent>(`/projects/${projectUuid}/aiAgents`, body);
29
+ }
30
+
31
+ /** Update an existing agent (PATCH /projects/{projectUuid}/aiAgents/{agentUuid}). */
32
+ async updateAgent(projectUuid: string, agentUuid: string, body: UpdateAiAgent): Promise<AiAgent> {
33
+ return this.http.patch<AiAgent>(`/projects/${projectUuid}/aiAgents/${agentUuid}`, body);
34
+ }
35
+
36
+ /** Delete an agent (DELETE /projects/{projectUuid}/aiAgents/{agentUuid}). */
37
+ async deleteAgent(projectUuid: string, agentUuid: string): Promise<void> {
38
+ await this.http.delete(`/projects/${projectUuid}/aiAgents/${agentUuid}`);
39
+ }
40
+ }
@@ -0,0 +1,84 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+
3
+ import { AiAgentsArtifactsClient } from './artifacts';
4
+
5
+ import type { HttpClient } from '../../../http/http-client';
6
+
7
+ describe('AiAgentsArtifactsClient', () => {
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('listVerifiedArtifacts should call GET …/verified-artifacts with pagination params', async () => {
21
+ const client = new AiAgentsArtifactsClient(mockHttp);
22
+ const paged = {
23
+ data: [],
24
+ pagination: { page: 1, pageSize: 10, totalResults: 0, totalPageCount: 0 },
25
+ };
26
+ vi.mocked(mockHttp.get).mockResolvedValue(paged);
27
+ const result = await client.listVerifiedArtifacts('proj1', 'a1', { page: 1, pageSize: 10 });
28
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/verified-artifacts', {
29
+ params: { page: 1, pageSize: 10 },
30
+ });
31
+ expect(result).toEqual(paged);
32
+ });
33
+
34
+ it('listVerifiedQuestions should call GET …/verified-questions', async () => {
35
+ const client = new AiAgentsArtifactsClient(mockHttp);
36
+ const questions = [{ uuid: 'q1', question: 'What is revenue?' }];
37
+ vi.mocked(mockHttp.get).mockResolvedValue(questions);
38
+ const result = await client.listVerifiedQuestions('proj1', 'a1');
39
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/verified-questions');
40
+ expect(result).toEqual(questions);
41
+ });
42
+
43
+ it('getArtifact should call GET …/artifacts/{artifactUuid}', async () => {
44
+ const client = new AiAgentsArtifactsClient(mockHttp);
45
+ const artifact = { artifactUuid: 'art1', versionUuid: 'v1' };
46
+ vi.mocked(mockHttp.get).mockResolvedValue(artifact);
47
+ const result = await client.getArtifact('proj1', 'a1', 'art1');
48
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/artifacts/art1');
49
+ expect(result).toEqual(artifact);
50
+ });
51
+
52
+ it('getArtifactVersion should call GET …/artifacts/{artifactUuid}/versions/{versionUuid}', async () => {
53
+ const client = new AiAgentsArtifactsClient(mockHttp);
54
+ const artifact = { artifactUuid: 'art1', versionUuid: 'v2' };
55
+ vi.mocked(mockHttp.get).mockResolvedValue(artifact);
56
+ const result = await client.getArtifactVersion('proj1', 'a1', 'art1', 'v2');
57
+ expect(mockHttp.get).toHaveBeenCalledWith(
58
+ '/projects/proj1/aiAgents/a1/artifacts/art1/versions/v2',
59
+ );
60
+ expect(result).toEqual(artifact);
61
+ });
62
+
63
+ it('getArtifactVersionVizQuery should call GET …/versions/{versionUuid}/viz-query', async () => {
64
+ const client = new AiAgentsArtifactsClient(mockHttp);
65
+ const vizQuery = { type: 'table', metadata: { title: null, description: null } };
66
+ vi.mocked(mockHttp.get).mockResolvedValue(vizQuery);
67
+ const result = await client.getArtifactVersionVizQuery('proj1', 'a1', 'art1', 'v1');
68
+ expect(mockHttp.get).toHaveBeenCalledWith(
69
+ '/projects/proj1/aiAgents/a1/artifacts/art1/versions/v1/viz-query',
70
+ );
71
+ expect(result).toEqual(vizQuery);
72
+ });
73
+
74
+ it('getDashboardArtifactChartVizQuery should call GET …/charts/{chartIndex}/viz-query', async () => {
75
+ const client = new AiAgentsArtifactsClient(mockHttp);
76
+ const vizQuery = { type: 'table', metadata: { title: null, description: null } };
77
+ vi.mocked(mockHttp.get).mockResolvedValue(vizQuery);
78
+ const result = await client.getDashboardArtifactChartVizQuery('proj1', 'a1', 'art1', 'v1', 2);
79
+ expect(mockHttp.get).toHaveBeenCalledWith(
80
+ '/projects/proj1/aiAgents/a1/artifacts/art1/versions/v1/charts/2/viz-query',
81
+ );
82
+ expect(result).toEqual(vizQuery);
83
+ });
84
+ });
@@ -0,0 +1,92 @@
1
+ /**
2
+ * AI agent artifacts client.
3
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/{agentUuid}/artifacts/...
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import type {
9
+ AiAgentThreadMessageVizQuery,
10
+ AiAgentVerifiedArtifactsListResult,
11
+ AiAgentVerifiedQuestion,
12
+ AiArtifact,
13
+ ListVerifiedArtifactsParams,
14
+ } from '@lightdash-tools/common';
15
+
16
+ export class AiAgentsArtifactsClient extends BaseApiClient {
17
+ /** List verified artifacts with pagination (GET …/verified-artifacts). */
18
+ async listVerifiedArtifacts(
19
+ projectUuid: string,
20
+ agentUuid: string,
21
+ params?: ListVerifiedArtifactsParams,
22
+ ): Promise<AiAgentVerifiedArtifactsListResult> {
23
+ return this.http.get<AiAgentVerifiedArtifactsListResult>(
24
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/verified-artifacts`,
25
+ { params },
26
+ );
27
+ }
28
+
29
+ /** List verified questions (GET …/verified-questions). */
30
+ async listVerifiedQuestions(
31
+ projectUuid: string,
32
+ agentUuid: string,
33
+ ): Promise<AiAgentVerifiedQuestion[]> {
34
+ return this.http.get<AiAgentVerifiedQuestion[]>(
35
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/verified-questions`,
36
+ );
37
+ }
38
+
39
+ /** Get the latest artifact version (GET …/artifacts/{artifactUuid}). */
40
+ async getArtifact(
41
+ projectUuid: string,
42
+ agentUuid: string,
43
+ artifactUuid: string,
44
+ ): Promise<AiArtifact> {
45
+ return this.http.get<AiArtifact>(
46
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/artifacts/${artifactUuid}`,
47
+ );
48
+ }
49
+
50
+ /** Get a specific artifact version (GET …/artifacts/{artifactUuid}/versions/{versionUuid}). */
51
+ async getArtifactVersion(
52
+ projectUuid: string,
53
+ agentUuid: string,
54
+ artifactUuid: string,
55
+ versionUuid: string,
56
+ ): Promise<AiArtifact> {
57
+ return this.http.get<AiArtifact>(
58
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/artifacts/${artifactUuid}/versions/${versionUuid}`,
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Get the viz query for an artifact version
64
+ * (GET …/artifacts/{artifactUuid}/versions/{versionUuid}/viz-query).
65
+ */
66
+ async getArtifactVersionVizQuery(
67
+ projectUuid: string,
68
+ agentUuid: string,
69
+ artifactUuid: string,
70
+ versionUuid: string,
71
+ ): Promise<AiAgentThreadMessageVizQuery> {
72
+ return this.http.get<AiAgentThreadMessageVizQuery>(
73
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/artifacts/${artifactUuid}/versions/${versionUuid}/viz-query`,
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Get the viz query for a dashboard chart within an artifact version
79
+ * (GET …/artifacts/{artifactUuid}/versions/{versionUuid}/charts/{chartIndex}/viz-query).
80
+ */
81
+ async getDashboardArtifactChartVizQuery(
82
+ projectUuid: string,
83
+ agentUuid: string,
84
+ artifactUuid: string,
85
+ versionUuid: string,
86
+ chartIndex: number,
87
+ ): Promise<AiAgentThreadMessageVizQuery> {
88
+ return this.http.get<AiAgentThreadMessageVizQuery>(
89
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/artifacts/${artifactUuid}/versions/${versionUuid}/charts/${chartIndex}/viz-query`,
90
+ );
91
+ }
92
+ }
@@ -0,0 +1,102 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+
3
+ import { AiAgentsDiscoveryClient } from './discovery';
4
+
5
+ import type { HttpClient } from '../../../http/http-client';
6
+
7
+ describe('AiAgentsDiscoveryClient', () => {
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('getAgentModelOptions should call GET …/{agentUuid}/models', async () => {
21
+ const client = new AiAgentsDiscoveryClient(mockHttp);
22
+ const models = [{ name: 'gpt-4', provider: 'openai', default: true }];
23
+ vi.mocked(mockHttp.get).mockResolvedValue(models);
24
+ const result = await client.getAgentModelOptions('proj1', 'a1');
25
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/models');
26
+ expect(result).toEqual(models);
27
+ });
28
+
29
+ it('getAgentSuggestions should call GET …/suggestions with optional params', async () => {
30
+ const client = new AiAgentsDiscoveryClient(mockHttp);
31
+ const suggestions = { chips: [{ label: 'Revenue trend' }] };
32
+ vi.mocked(mockHttp.get).mockResolvedValue(suggestions);
33
+ const result = await client.getAgentSuggestions('proj1', 'a1', {
34
+ threadUuid: 't1',
35
+ enableSqlMode: true,
36
+ });
37
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/suggestions', {
38
+ params: { threadUuid: 't1', enableSqlMode: true },
39
+ });
40
+ expect(result).toEqual(suggestions);
41
+ });
42
+
43
+ it('evaluateAgentReadiness should call POST …/evaluateReadiness', async () => {
44
+ const client = new AiAgentsDiscoveryClient(mockHttp);
45
+ const score = { overallScore: 0.8 };
46
+ vi.mocked(mockHttp.post).mockResolvedValue(score);
47
+ const result = await client.evaluateAgentReadiness('proj1', 'a1');
48
+ expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/evaluateReadiness', {});
49
+ expect(result).toEqual(score);
50
+ });
51
+
52
+ it('getExploreAccessSummary should call POST …/explore-access-summary', async () => {
53
+ const client = new AiAgentsDiscoveryClient(mockHttp);
54
+ const summary = [{ exploreName: 'orders', metrics: [], dimensions: [], joinedTables: [] }];
55
+ vi.mocked(mockHttp.post).mockResolvedValue(summary);
56
+ const result = await client.getExploreAccessSummary('proj1', 'a1', { tags: ['ai'] });
57
+ expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
58
+ tags: ['ai'],
59
+ });
60
+ expect(result).toEqual(summary);
61
+ });
62
+
63
+ it('getExploreAccessSummary without body should default tags to null', async () => {
64
+ const client = new AiAgentsDiscoveryClient(mockHttp);
65
+ vi.mocked(mockHttp.post).mockResolvedValue([]);
66
+ await client.getExploreAccessSummary('proj1', 'a1');
67
+ expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
68
+ tags: null,
69
+ });
70
+ });
71
+
72
+ it('getUserAgentPreferences should call GET …/preferences', async () => {
73
+ const client = new AiAgentsDiscoveryClient(mockHttp);
74
+ const prefs = { defaultAgentUuid: 'a1' };
75
+ vi.mocked(mockHttp.get).mockResolvedValue(prefs);
76
+ const result = await client.getUserAgentPreferences('proj1');
77
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/preferences');
78
+ expect(result).toEqual(prefs);
79
+ });
80
+
81
+ it('getUserAgentPreferences should return null when API returns empty success', async () => {
82
+ const client = new AiAgentsDiscoveryClient(mockHttp);
83
+ vi.mocked(mockHttp.get).mockResolvedValue(undefined);
84
+ const result = await client.getUserAgentPreferences('proj1');
85
+ expect(result).toBeNull();
86
+ });
87
+
88
+ it('setUserAgentPreferences should call POST …/preferences', async () => {
89
+ const client = new AiAgentsDiscoveryClient(mockHttp);
90
+ const body = { defaultAgentUuid: 'a2' };
91
+ vi.mocked(mockHttp.post).mockResolvedValue(undefined);
92
+ await client.setUserAgentPreferences('proj1', body);
93
+ expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/preferences', body);
94
+ });
95
+
96
+ it('deleteUserAgentPreferences should call DELETE …/preferences', async () => {
97
+ const client = new AiAgentsDiscoveryClient(mockHttp);
98
+ vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
99
+ await client.deleteUserAgentPreferences('proj1');
100
+ expect(mockHttp.delete).toHaveBeenCalledWith('/projects/proj1/aiAgents/preferences');
101
+ });
102
+ });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * AI agent discovery and preferences client.
3
+ * Endpoints: /api/v1/projects/{projectUuid}/aiAgents/...
4
+ */
5
+
6
+ import { BaseApiClient } from '../../base-client';
7
+
8
+ import type {
9
+ AgentSuggestions,
10
+ AiAgentExploreAccessSummary,
11
+ AiAgentUserPreferences,
12
+ AiModelOption,
13
+ ExploreAccessSummaryBody,
14
+ GetAgentSuggestionsParams,
15
+ ReadinessScore,
16
+ } from '@lightdash-tools/common';
17
+
18
+ export class AiAgentsDiscoveryClient extends BaseApiClient {
19
+ /** Available model options for an agent (GET …/{agentUuid}/models). */
20
+ async getAgentModelOptions(projectUuid: string, agentUuid: string): Promise<AiModelOption[]> {
21
+ return this.http.get<AiModelOption[]>(`/projects/${projectUuid}/aiAgents/${agentUuid}/models`);
22
+ }
23
+
24
+ /** Suggestion chips for an agent (GET …/{agentUuid}/suggestions). */
25
+ async getAgentSuggestions(
26
+ projectUuid: string,
27
+ agentUuid: string,
28
+ params?: GetAgentSuggestionsParams,
29
+ ): Promise<AgentSuggestions> {
30
+ return this.http.get<AgentSuggestions>(
31
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/suggestions`,
32
+ { params },
33
+ );
34
+ }
35
+
36
+ /** Evaluate agent readiness (POST …/{agentUuid}/evaluateReadiness). */
37
+ async evaluateAgentReadiness(projectUuid: string, agentUuid: string): Promise<ReadinessScore> {
38
+ return this.http.post<ReadinessScore>(
39
+ `/projects/${projectUuid}/aiAgents/${agentUuid}/evaluateReadiness`,
40
+ {},
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Summarize explore access for tag-filtered explores
46
+ * (POST …/explore-access-summary).
47
+ */
48
+ async getExploreAccessSummary(
49
+ projectUuid: string,
50
+ _agentUuid: string,
51
+ body?: ExploreAccessSummaryBody,
52
+ ): Promise<AiAgentExploreAccessSummary[]> {
53
+ return this.http.post<AiAgentExploreAccessSummary[]>(
54
+ `/projects/${projectUuid}/aiAgents/explore-access-summary`,
55
+ body ?? { tags: null },
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Get user default agent preferences (GET …/preferences).
61
+ * Returns null when the user has not set preferences (`ApiSuccessEmpty`).
62
+ */
63
+ async getUserAgentPreferences(projectUuid: string): Promise<AiAgentUserPreferences | null> {
64
+ const results = await this.http.get<AiAgentUserPreferences | undefined>(
65
+ `/projects/${projectUuid}/aiAgents/preferences`,
66
+ );
67
+ return results ?? null;
68
+ }
69
+
70
+ /** Set user default agent preferences (POST …/preferences). */
71
+ async setUserAgentPreferences(projectUuid: string, body: AiAgentUserPreferences): Promise<void> {
72
+ await this.http.post<void>(`/projects/${projectUuid}/aiAgents/preferences`, body);
73
+ }
74
+
75
+ /** Clear user default agent preferences (DELETE …/preferences). */
76
+ async deleteUserAgentPreferences(projectUuid: string): Promise<void> {
77
+ await this.http.delete(`/projects/${projectUuid}/aiAgents/preferences`);
78
+ }
79
+ }