-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathaltimate-core-complete.ts
More file actions
45 lines (43 loc) · 1.95 KB
/
altimate-core-complete.ts
File metadata and controls
45 lines (43 loc) · 1.95 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
39
40
41
42
43
44
45
import z from "zod"
import { Tool } from "../../tool/tool"
import { Dispatcher } from "../native"
export const AltimateCoreCompleteTool = Tool.define("altimate_core_complete", {
description:
"Get cursor-aware SQL completion suggestions. Returns table names, column names, functions, and keywords relevant to the cursor position. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
sql: z.string().describe("Partial SQL query"),
cursor_pos: z.number().describe("Cursor position (0-indexed character offset)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
async execute(args, ctx) {
try {
const result = await Dispatcher.call("altimate_core.complete", {
sql: args.sql,
cursor_pos: args.cursor_pos,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
const data = result.data as Record<string, any>
const count = data.items?.length ?? data.suggestions?.length ?? 0
return {
title: `Complete: ${count} suggestion(s)`,
metadata: { success: result.success, suggestion_count: count, error: result.error ?? (data as any).error },
output: formatComplete(data),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return { title: "Complete: ERROR", metadata: { success: false, suggestion_count: 0, error: msg }, output: `Failed: ${msg}` }
}
},
})
function formatComplete(data: Record<string, any>): string {
if (data.error) return `Error: ${data.error}`
const items = data.items ?? data.suggestions ?? []
if (!items.length) return "No completions available."
const lines = ["Suggestions:\n"]
for (const s of items) {
lines.push(` ${s.label ?? s.text} (${s.kind ?? s.type ?? "unknown"})`)
}
return lines.join("\n")
}