-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathaltimate-core-parse-dbt.ts
More file actions
38 lines (36 loc) · 1.46 KB
/
altimate-core-parse-dbt.ts
File metadata and controls
38 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import z from "zod"
import { Tool } from "../../tool/tool"
import { Dispatcher } from "../native"
export const AltimateCoreParseDbtTool = Tool.define("altimate_core_parse_dbt", {
description:
"Parse a dbt project directory. Extracts models, sources, tests, and project structure for analysis.",
parameters: z.object({
project_dir: z.string().describe("Path to the dbt project directory"),
}),
async execute(args, ctx) {
try {
const result = await Dispatcher.call("altimate_core.parse_dbt", {
project_dir: args.project_dir,
})
const data = result.data as Record<string, any>
return {
title: `Parse dbt: ${data.models?.length ?? 0} models`,
metadata: { success: result.success },
output: formatParseDbt(data),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return { title: "Parse dbt: ERROR", metadata: { success: false }, output: `Failed: ${msg}` }
}
},
})
function formatParseDbt(data: Record<string, any>): string {
if (data.error) return `Error: ${data.error}`
const lines: string[] = []
if (data.models?.length) lines.push(`Models: ${data.models.length}`)
if (data.sources?.length) lines.push(`Sources: ${data.sources.length}`)
if (data.tests?.length) lines.push(`Tests: ${data.tests.length}`)
if (data.seeds?.length) lines.push(`Seeds: ${data.seeds.length}`)
if (!lines.length) return JSON.stringify(data, null, 2)
return lines.join("\n")
}