@lightdash-tools/common 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 (94) hide show
  1. package/dist/agentops/extract-yaml-project.d.ts +7 -0
  2. package/dist/agentops/extract-yaml-project.js +42 -0
  3. package/dist/agentops/formatters.d.ts +5 -0
  4. package/dist/agentops/formatters.js +47 -0
  5. package/dist/agentops/snapshots.d.ts +32 -0
  6. package/dist/agentops/snapshots.js +34 -0
  7. package/dist/agentops/types.d.ts +224 -0
  8. package/dist/agentops/types.js +430 -0
  9. package/dist/argument-validation.d.ts +25 -0
  10. package/dist/argument-validation.js +199 -0
  11. package/dist/argument-validation.test.d.ts +1 -0
  12. package/dist/argument-validation.test.js +183 -0
  13. package/dist/audit.d.ts +9 -2
  14. package/dist/audit.js +17 -2
  15. package/dist/audit.test.d.ts +1 -0
  16. package/dist/audit.test.js +73 -0
  17. package/dist/env.d.ts +8 -0
  18. package/dist/env.js +9 -1
  19. package/dist/index.d.ts +7 -1
  20. package/dist/index.js +14 -0
  21. package/dist/input-validation.d.ts +35 -0
  22. package/dist/input-validation.js +87 -0
  23. package/dist/input-validation.test.js +93 -0
  24. package/dist/operations/agent-safe.d.ts +7 -0
  25. package/dist/operations/agent-safe.js +16 -0
  26. package/dist/operations/ai-agents.d.ts +6 -0
  27. package/dist/operations/ai-agents.js +411 -0
  28. package/dist/operations/index.d.ts +5 -0
  29. package/dist/operations/index.js +16 -0
  30. package/dist/operations/parity.test.d.ts +1 -0
  31. package/dist/operations/parity.test.js +28 -0
  32. package/dist/operations/registry.d.ts +10 -0
  33. package/dist/operations/registry.js +35 -0
  34. package/dist/operations/registry.test.d.ts +1 -0
  35. package/dist/operations/registry.test.js +196 -0
  36. package/dist/operations/types.d.ts +69 -0
  37. package/dist/operations/types.js +70 -0
  38. package/dist/operations/types.test.d.ts +1 -0
  39. package/dist/operations/types.test.js +104 -0
  40. package/dist/operations/users.d.ts +6 -0
  41. package/dist/operations/users.js +60 -0
  42. package/dist/safety.d.ts +27 -2
  43. package/dist/safety.js +52 -5
  44. package/dist/safety.test.js +217 -4
  45. package/dist/types/generated/openapi-types.d.ts +35895 -10622
  46. package/dist/types/generated/openapi-types.js +0 -1
  47. package/dist/types/lightdash-api.d.ts +1 -1
  48. package/dist/types/v1/ai-agents.d.ts +112 -3
  49. package/dist/types/v1/charts.d.ts +5 -3
  50. package/dist/types/v1/dashboards.d.ts +13 -0
  51. package/dist/types/v1/index.d.ts +45 -8
  52. package/dist/types/v1/index.js +1 -1
  53. package/dist/types/v1/lightdash-api.d.ts +107 -16
  54. package/dist/types/v1/users.d.ts +4 -0
  55. package/dist/types/v2/content.d.ts +2 -0
  56. package/dist/types/v2/content.js +8 -0
  57. package/dist/types/v2/index.d.ts +11 -9
  58. package/dist/types/v2/index.js +1 -1
  59. package/package.json +16 -3
  60. package/src/agentops/extract-yaml-project.ts +42 -0
  61. package/src/agentops/formatters.ts +52 -0
  62. package/src/agentops/snapshots.ts +56 -0
  63. package/src/agentops/types.ts +599 -0
  64. package/src/argument-validation.test.ts +270 -0
  65. package/src/argument-validation.ts +240 -0
  66. package/src/audit.test.ts +87 -0
  67. package/src/audit.ts +21 -3
  68. package/src/env.ts +9 -0
  69. package/src/index.test.ts +1 -0
  70. package/src/index.ts +16 -1
  71. package/src/input-validation.test.ts +157 -1
  72. package/src/input-validation.ts +95 -0
  73. package/src/operations/agent-safe.ts +18 -0
  74. package/src/operations/ai-agents.ts +451 -0
  75. package/src/operations/index.ts +19 -0
  76. package/src/operations/parity.test.ts +35 -0
  77. package/src/operations/registry.test.ts +219 -0
  78. package/src/operations/registry.ts +44 -0
  79. package/src/operations/types.test.ts +148 -0
  80. package/src/operations/types.ts +168 -0
  81. package/src/operations/users.ts +67 -0
  82. package/src/safety.test.ts +276 -4
  83. package/src/safety.ts +72 -4
  84. package/src/types/generated/openapi-types.ts +37017 -11241
  85. package/src/types/lightdash-api.ts +39 -0
  86. package/src/types/v1/ai-agents.ts +133 -3
  87. package/src/types/v1/charts.ts +5 -3
  88. package/src/types/v1/dashboards.ts +19 -0
  89. package/src/types/v1/index.ts +51 -8
  90. package/src/types/v1/lightdash-api.ts +129 -20
  91. package/src/types/v1/users.ts +4 -0
  92. package/src/types/v2/content.ts +8 -0
  93. package/src/types/v2/index.ts +11 -9
  94. package/tsconfig.json +1 -0
@@ -0,0 +1,42 @@
1
+ import { parseLightdashAiAgentBundle, parseLightdashAiEvaluationGate } from './types';
2
+
3
+ /** True when MCP tool args carry AgentOps YAML documents that imply a project scope. */
4
+ export function hasYamlProjectDocumentArgs(args: unknown): boolean {
5
+ if (typeof args !== 'object' || args === null || Array.isArray(args)) {
6
+ return false;
7
+ }
8
+ const record = args as Record<string, unknown>;
9
+ return typeof record.bundleYaml === 'string' || typeof record.gateYaml === 'string';
10
+ }
11
+
12
+ /**
13
+ * Extracts project UUIDs from MCP tool args, including YAML document fields
14
+ * (`bundleYaml`, `gateYaml`) used by AgentOps composite tools.
15
+ */
16
+ export function extractProjectUuidsFromToolArgs(args: unknown): string[] {
17
+ const uuids: string[] = [];
18
+
19
+ if (typeof args === 'object' && args !== null && !Array.isArray(args)) {
20
+ const record = args as Record<string, unknown>;
21
+
22
+ if (typeof record.bundleYaml === 'string') {
23
+ try {
24
+ const bundle = parseLightdashAiAgentBundle(record.bundleYaml);
25
+ uuids.push(bundle.spec.projectUuid);
26
+ } catch {
27
+ // Handler validates YAML; allowlist runs before handler may see invalid YAML.
28
+ }
29
+ }
30
+
31
+ if (typeof record.gateYaml === 'string') {
32
+ try {
33
+ const gate = parseLightdashAiEvaluationGate(record.gateYaml);
34
+ uuids.push(gate.spec.projectUuid);
35
+ } catch {
36
+ // Same as bundleYaml — parse errors surface in the handler.
37
+ }
38
+ }
39
+ }
40
+
41
+ return uuids;
42
+ }
@@ -0,0 +1,52 @@
1
+ import type { GatePolicyEvaluation, LightdashAiEvaluationGate } from './types';
2
+
3
+ function escapeXml(text: string): string {
4
+ return text
5
+ .replace(/&/g, '&amp;')
6
+ .replace(/</g, '&lt;')
7
+ .replace(/>/g, '&gt;')
8
+ .replace(/"/g, '&quot;')
9
+ .replace(/'/g, '&apos;');
10
+ }
11
+
12
+ export function formatGateJUnit(
13
+ gate: LightdashAiEvaluationGate,
14
+ evaluation: GatePolicyEvaluation,
15
+ ): string {
16
+ const name = escapeXml(gate.metadata.name);
17
+ const failures = evaluation.passed
18
+ ? ''
19
+ : ` <failure message="${escapeXml(evaluation.reasons.join('; '))}">Gate policy failed</failure>\n`;
20
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuite name="${name}" tests="1" failures="${evaluation.passed ? 0 : 1}">\n <testcase name="${name}" classname="agentops.evaluate-gate">\n${failures} </testcase>\n</testsuite>\n`;
21
+ }
22
+
23
+ export function formatGateTimeoutJUnit(gate: LightdashAiEvaluationGate): string {
24
+ const name = escapeXml(gate.metadata.name);
25
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuite name="${name}" tests="1" failures="1">\n <testcase name="timeout"><failure>Timed out</failure></testcase>\n</testsuite>\n`;
26
+ }
27
+
28
+ export function formatGateTimeoutMarkdown(gate: LightdashAiEvaluationGate): string {
29
+ return `# Evaluation Gate: ${gate.metadata.name}\n\n**Result:** TIMEOUT\n`;
30
+ }
31
+
32
+ export function formatGateMarkdown(
33
+ gate: LightdashAiEvaluationGate,
34
+ evaluation: GatePolicyEvaluation,
35
+ ): string {
36
+ const lines = [
37
+ `# Evaluation Gate: ${gate.metadata.name}`,
38
+ '',
39
+ `**Result:** ${evaluation.passed ? 'PASSED' : 'FAILED'} (exit ${evaluation.exitCode})`,
40
+ '',
41
+ '## Metrics',
42
+ `- Run status: ${evaluation.metrics.runStatus}`,
43
+ `- Passed assessments: ${evaluation.metrics.passedAssessments}`,
44
+ `- Failed assessments: ${evaluation.metrics.failedAssessments}`,
45
+ `- Pass rate: ${evaluation.metrics.passRate ?? 'n/a'}`,
46
+ '',
47
+ ];
48
+ if (evaluation.reasons.length > 0) {
49
+ lines.push('## Reasons', ...evaluation.reasons.map((r) => `- ${r}`), '');
50
+ }
51
+ return lines.join('\n');
52
+ }
@@ -0,0 +1,56 @@
1
+ import { normalizeEvaluationPrompt } from './types';
2
+
3
+ import type { AgentStateSnapshot, EvaluationStateSnapshot, GateRunSnapshot } from './types';
4
+
5
+ export function toGateRunSnapshot(run: {
6
+ runUuid: string;
7
+ status: GateRunSnapshot['status'];
8
+ passedAssessments: number;
9
+ failedAssessments: number;
10
+ completedAt: string | null;
11
+ }): GateRunSnapshot {
12
+ return {
13
+ runUuid: run.runUuid,
14
+ status: run.status,
15
+ passedAssessments: run.passedAssessments,
16
+ failedAssessments: run.failedAssessments,
17
+ completedAt: run.completedAt,
18
+ };
19
+ }
20
+
21
+ export function toAgentSnapshot(agent: {
22
+ uuid: string;
23
+ name: string;
24
+ description: string | null;
25
+ instruction: string | null;
26
+ tags: string[] | null;
27
+ enableDataAccess?: boolean;
28
+ enableSelfImprovement?: boolean;
29
+ }): AgentStateSnapshot {
30
+ return {
31
+ uuid: agent.uuid,
32
+ name: agent.name,
33
+ description: agent.description,
34
+ instruction: agent.instruction,
35
+ tags: agent.tags,
36
+ enableDataAccess: agent.enableDataAccess,
37
+ enableSelfImprovement: agent.enableSelfImprovement,
38
+ };
39
+ }
40
+
41
+ export function toEvaluationSnapshot(evaluation: {
42
+ evalUuid: string;
43
+ title: string;
44
+ description: string | null;
45
+ prompts: Array<
46
+ | { type?: 'string'; prompt: string; expectedResponse: string | null }
47
+ | { type?: 'thread'; threadUuid: string; promptUuid: string; expectedResponse: string | null }
48
+ >;
49
+ }): EvaluationStateSnapshot {
50
+ return {
51
+ evalUuid: evaluation.evalUuid,
52
+ title: evaluation.title,
53
+ description: evaluation.description,
54
+ prompts: evaluation.prompts.map((p) => normalizeEvaluationPrompt(p)),
55
+ };
56
+ }