Unified · Split
| @@ -2,7 +2,7 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | import { Suspense, useEffect, useState } from "react"; | 3 | import { Suspense, useEffect, useState } from "react"; |
| 4 | import { Link, useLocation, useNavigate } from "react-router"; | 4 | import { Link, useLocation, useNavigate } from "react-router"; |
| 5 | import { ExternalLink, Github, LayoutDashboard, ShieldCheck, Wrench, Menu, X } from "lucide-react"; | 5 | import { ExternalLink, Github, LayoutDashboard, ListTodo, ShieldCheck, Wrench, Menu, X } from "lucide-react"; |
| 6 | import { Button } from "@/components/ui/button"; | 6 | import { Button } from "@/components/ui/button"; |
| 7 | import { Sheet, SheetContent, SheetTrigger, SheetTitle } from "@/components/ui/sheet"; | 7 | import { Sheet, SheetContent, SheetTrigger, SheetTitle } from "@/components/ui/sheet"; |
| 8 | import { useSession } from "@/lib/session-context"; | 8 | import { useSession } from "@/lib/session-context"; |
| @@ -15,6 +15,7 @@ import { cn } from "@/lib/utils"; · 6 unmodified lines | |||
| 15 | 15 | ||
| 16 | const NAV_ITEMS = [ | 16 | const NAV_ITEMS = [ |
| 17 | { href: "/", label: "Home", icon: LayoutDashboard }, | 17 | { href: "/", label: "Home", icon: LayoutDashboard }, |
| 18 | { href: "/tasks", label: "Tasks", icon: ListTodo }, | ||
| 18 | { href: "/approvals", label: "Approvals", icon: ShieldCheck }, | 19 | { href: "/approvals", label: "Approvals", icon: ShieldCheck }, |
| 19 | { href: "/tools", label: "Tools", icon: Wrench }, | 20 | { href: "/tools", label: "Tools", icon: Wrench }, |
| 20 | ]; | 21 | ]; |
| @@ -7,6 +7,7 @@ import { DashboardView } from "@/components/dashboard/view"; · 6 unmodified lines | |||
| 7 | import { MenubarMvpView } from "@/components/menubar/mvp-view"; | 7 | import { MenubarMvpView } from "@/components/menubar/mvp-view"; |
| 8 | import { OnboardingView } from "@/components/organization/onboarding-view"; | 8 | import { OnboardingView } from "@/components/organization/onboarding-view"; |
| 9 | import { OrganizationSettingsView } from "@/components/organization/organization-settings-view"; | 9 | import { OrganizationSettingsView } from "@/components/organization/organization-settings-view"; |
| 10 | import { TasksView } from "@/components/tasks/tasks-view"; | ||
| 10 | import { ToolsView } from "@/components/tools/view"; | 11 | import { ToolsView } from "@/components/tools/view"; |
| 11 | 12 | ||
| 12 | function ToolsRoute() { | 13 | function ToolsRoute() { |
| @@ -37,7 +38,7 @@ export default function FrontendApp() { · 24 unmodified lines | |||
| 37 | <Route element={<ShellLayout />}> | 38 | <Route element={<ShellLayout />}> |
| 38 | <Route path="/" element={<DashboardView />} /> | 39 | <Route path="/" element={<DashboardView />} /> |
| 39 | <Route path="/static-app-shell" element={<DashboardView />} /> | 40 | <Route path="/static-app-shell" element={<DashboardView />} /> |
| 40 | <Route path="/tasks" element={<Navigate to="/tools?tab=editor" replace />} /> | 41 | <Route path="/tasks" element={<TasksView />} /> |
| 41 | <Route path="/approvals" element={<ApprovalsView />} /> | 42 | <Route path="/approvals" element={<ApprovalsView />} /> |
| 42 | <Route path="/tools" element={<ToolsRoute />} /> | 43 | <Route path="/tools" element={<ToolsRoute />} /> |
| 43 | <Route path="/organization" element={<OrganizationSettingsView />} /> | 44 | <Route path="/organization" element={<OrganizationSettingsView />} /> |
| @@ -30,6 +30,8 @@ test("discover returns aliases and example calls", async () => { · 29 unmodified lines | |||
| 30 | aliases: string[]; | 30 | aliases: string[]; |
| 31 | exampleCall: string; | 31 | exampleCall: string; |
| 32 | signature: string; | 32 | signature: string; |
| 33 | canonicalSignature: string; | ||
| 34 | expandedShape: { input: string; output: string }; | ||
| 33 | }>; | 35 | }>; |
| 34 | total: number; | 36 | total: number; |
| 35 | }; | 37 | }; |
| @@ -41,6 +43,9 @@ test("discover returns aliases and example calls", async () => { · 5 unmodified lines | |||
| 41 | expect(result.results[0]?.aliases).toContain("calc.math.addnumbers"); | 43 | expect(result.results[0]?.aliases).toContain("calc.math.addnumbers"); |
| 42 | expect(result.results[0]?.exampleCall).toBe("await tools.calc.math.add_numbers({ a: ..., b: ... });"); | 44 | expect(result.results[0]?.exampleCall).toBe("await tools.calc.math.add_numbers({ a: ..., b: ... });"); |
| 43 | expect(result.results[0]?.signature).toContain("Promise<{ sum: number }>"); | 45 | expect(result.results[0]?.signature).toContain("Promise<{ sum: number }>"); |
| 46 | expect(result.results[0]?.canonicalSignature).toContain("Promise<{ sum: number }>"); | ||
| 47 | expect(result.results[0]?.expandedShape.input).toContain("a:"); | ||
| 48 | expect(result.results[0]?.expandedShape.output).toContain("sum"); | ||
| 44 | }); | 49 | }); |
| 45 | 50 | ||
| 46 | test("discover example call handles input-shaped args", async () => { | 51 | test("discover example call handles input-shaped args", async () => { |
| @@ -92,7 +97,12 @@ test("discover uses compact signatures by default and allows full mode", async ( · 45 unmodified lines | |||
| 92 | { taskId: "t", workspaceId: TEST_WORKSPACE_ID, isToolAllowed: () => true }, | 97 | { taskId: "t", workspaceId: TEST_WORKSPACE_ID, isToolAllowed: () => true }, |
| 93 | ) as { | 98 | ) as { |
| 94 | bestPath: string | null; | 99 | bestPath: string | null; |
| 95 | results: Array<{ description: string; signature: string }>; | 100 | results: Array<{ |
| 101 | description: string; | ||
| 102 | signature: string; | ||
| 103 | canonicalSignature: string; | ||
| 104 | expandedShape: { input: string; output: string }; | ||
| 105 | }>; | ||
| 96 | }; | 106 | }; |
| 97 | 107 | ||
| 98 | const fullResult = await tool.run( | 108 | const fullResult = await tool.run( |
| @@ -100,12 +110,19 @@ test("discover uses compact signatures by default and allows full mode", async ( · 1 unmodified line | |||
| 100 | { taskId: "t", workspaceId: TEST_WORKSPACE_ID, isToolAllowed: () => true }, | 110 | { taskId: "t", workspaceId: TEST_WORKSPACE_ID, isToolAllowed: () => true }, |
| 101 | ) as { | 111 | ) as { |
| 102 | bestPath: string | null; | 112 | bestPath: string | null; |
| 103 | results: Array<{ description: string; signature: string }>; | 113 | results: Array<{ |
| 114 | description: string; | ||
| 115 | signature: string; | ||
| 116 | canonicalSignature: string; | ||
| 117 | expandedShape: { input: string; output: string }; | ||
| 118 | }>; | ||
| 104 | }; | 119 | }; |
| 105 | 120 | ||
| 106 | expect(compactResult.bestPath).toBe("linear.query.teams"); | 121 | expect(compactResult.bestPath).toBe("linear.query.teams"); |
| 107 | expect(fullResult.bestPath).toBe("linear.query.teams"); | 122 | expect(fullResult.bestPath).toBe("linear.query.teams"); |
| 108 | expect(compactResult.results[0]?.signature).toContain("Promise<{ data: ...; errors: unknown[] }>"); | 123 | expect(compactResult.results[0]?.signature).toContain("Promise<{ data: ...; errors: unknown[] }>"); |
| 124 | expect(compactResult.results[0]?.canonicalSignature).toContain("TeamConnection"); | ||
| 125 | expect(compactResult.results[0]?.expandedShape.input).toContain("filter"); | ||
| 109 | expect(compactResult.results[0]?.description).not.toContain("TRAILING_MARKER_TEXT"); | 126 | expect(compactResult.results[0]?.description).not.toContain("TRAILING_MARKER_TEXT"); |
| 110 | 127 | ||
| 111 | expect(fullResult.results[0]?.signature).toContain("TeamFilter"); | 128 | expect(fullResult.results[0]?.signature).toContain("TeamFilter"); |
| @@ -2,7 +2,12 @@ import type { ToolDefinition } from "./types"; · 1 unmodified line | |||
| 2 | import { | 2 | import { |
| 3 | compactDescriptionLine, | 3 | compactDescriptionLine, |
| 4 | } from "./type-hints"; | 4 | } from "./type-hints"; |
| 5 | import { buildExampleCall, formatSignature } from "./tool-discovery/formatting"; | 5 | import { |
| 6 | buildExampleCall, | ||
| 7 | buildExpandedShape, | ||
| 8 | formatCanonicalSignature, | ||
| 9 | formatSignature, | ||
| 10 | } from "./tool-discovery/formatting"; | ||
| 6 | import { buildIndex, getTopLevelNamespace, listIndexForContext } from "./tool-discovery/indexing"; | 11 | import { buildIndex, getTopLevelNamespace, listIndexForContext } from "./tool-discovery/indexing"; |
| 7 | import { chooseBestPath, deriveIntentPhrase, extractNamespaceHints, scoreEntry } from "./tool-discovery/ranking"; | 12 | import { chooseBestPath, deriveIntentPhrase, extractNamespaceHints, scoreEntry } from "./tool-discovery/ranking"; |
| 8 | 13 | ||
| @@ -119,7 +124,7 @@ export function createDiscoverTool(tools: ToolDefinition[]): ToolDefinition { · 110 unmodified lines | |||
| 119 | metadata: { | 124 | metadata: { |
| 120 | argsType: "{ query: string; depth?: number; limit?: number; compact?: boolean }", | 125 | argsType: "{ query: string; depth?: number; limit?: number; compact?: boolean }", |
| 121 | returnsType: | 126 | returnsType: |
| 122 | "{ bestPath: string | null; results: Array<{ path: string; aliases: string[]; source: string; approval: 'auto' | 'required'; description: string; signature: string; exampleCall: string }>; total: number }", | 127 | "{ bestPath: string | null; results: Array<{ path: string; aliases: string[]; source: string; approval: 'auto' | 'required'; description: string; signature: string; canonicalSignature: string; expandedShape: { input: string; output: string }; exampleCall: string }>; total: number }", |
| 123 | }, | 128 | }, |
| 124 | run: async (input: unknown, context) => { | 129 | run: async (input: unknown, context) => { |
| 125 | const payload = input && typeof input === "object" ? (input as Record<string, unknown>) : {}; | 130 | const payload = input && typeof input === "object" ? (input as Record<string, unknown>) : {}; |
| @@ -151,6 +156,8 @@ export function createDiscoverTool(tools: ToolDefinition[]): ToolDefinition { · 25 unmodified lines | |||
| 151 | approval: entry.approval, | 156 | approval: entry.approval, |
| 152 | description: compact ? compactDescriptionLine(entry.description) : entry.description, | 157 | description: compact ? compactDescriptionLine(entry.description) : entry.description, |
| 153 | signature: formatSignature(entry, depth, compact), | 158 | signature: formatSignature(entry, depth, compact), |
| 159 | canonicalSignature: formatCanonicalSignature(entry), | ||
| 160 | expandedShape: buildExpandedShape(entry), | ||
| 154 | exampleCall: buildExampleCall(entry), | 161 | exampleCall: buildExampleCall(entry), |
| 155 | })); | 162 | })); |
| 156 | 163 | ||
| @@ -52,3 +52,14 @@ export function formatSignature(entry: DiscoverIndexEntry, depth: number, compac · 51 unmodified lines | |||
| 52 | 52 | ||
| 53 | return `(input: ${entry.argsType}): Promise<${entry.returnsType}> [source=${entry.source}]`; | 53 | return `(input: ${entry.argsType}): Promise<${entry.returnsType}> [source=${entry.source}]`; |
| 54 | } | 54 | } |
| 55 | |||
| 56 | export function formatCanonicalSignature(entry: DiscoverIndexEntry): string { | ||
| 57 | return `(input: ${entry.argsType}): Promise<${entry.returnsType}>`; | ||
| 58 | } | ||
| 59 | |||
| 60 | export function buildExpandedShape(entry: DiscoverIndexEntry): { input: string; output: string } { | ||
| 61 | return { | ||
| 62 | input: entry.expandedArgsShape, | ||
| 63 | output: entry.expandedReturnsShape, | ||
| 64 | }; | ||
| 65 | } | ||
| @@ -1,5 +1,10 @@ | |||
| 1 | import type { ToolDefinition } from "../types"; | 1 | import type { ToolDefinition } from "../types"; |
| 2 | import { compactArgDisplayHint, compactReturnTypeHint } from "../type-hints"; | 2 | import { |
| 3 | compactArgDisplayHint, | ||
| 4 | compactReturnTypeHint, | ||
| 5 | llmExpandedArgShapeHint, | ||
| 6 | llmExpandedReturnShapeHint, | ||
| 7 | } from "../type-hints"; | ||
| 3 | import type { DiscoverIndexEntry } from "./types"; | 8 | import type { DiscoverIndexEntry } from "./types"; |
| 4 | 9 | ||
| 5 | const GENERIC_NAMESPACE_SUFFIXES = new Set([ | 10 | const GENERIC_NAMESPACE_SUFFIXES = new Set([ |
| @@ -107,6 +112,12 @@ export function buildIndex(tools: ToolDefinition[]): DiscoverIndexEntry[] { · 101 unmodified lines | |||
| 107 | tool.metadata?.displayReturnsType | 112 | tool.metadata?.displayReturnsType |
| 108 | ?? compactReturnTypeHint(returnsType), | 113 | ?? compactReturnTypeHint(returnsType), |
| 109 | ); | 114 | ); |
| 115 | const expandedArgsShape = normalizeType( | ||
| 116 | llmExpandedArgShapeHint(argsType, argPreviewKeys), | ||
| 117 | ); | ||
| 118 | const expandedReturnsShape = normalizeType( | ||
| 119 | llmExpandedReturnShapeHint(returnsType), | ||
| 120 | ); | ||
| 110 | 121 | ||
| 111 | return { | 122 | return { |
| 112 | path: tool.path, | 123 | path: tool.path, |
| @@ -119,6 +130,8 @@ export function buildIndex(tools: ToolDefinition[]): DiscoverIndexEntry[] { · 6 unmodified lines | |||
| 119 | returnsType, | 130 | returnsType, |
| 120 | displayArgsType, | 131 | displayArgsType, |
| 121 | displayReturnsType, | 132 | displayReturnsType, |
| 133 | expandedArgsShape, | ||
| 134 | expandedReturnsShape, | ||
| 122 | argPreviewKeys, | 135 | argPreviewKeys, |
| 123 | searchText, | 136 | searchText, |
| 124 | normalizedPath: normalizeSearchToken(tool.path), | 137 | normalizedPath: normalizeSearchToken(tool.path), |
| @@ -11,6 +11,8 @@ export interface DiscoverIndexEntry { · 10 unmodified lines | |||
| 11 | returnsType: string; | 11 | returnsType: string; |
| 12 | displayArgsType: string; | 12 | displayArgsType: string; |
| 13 | displayReturnsType: string; | 13 | displayReturnsType: string; |
| 14 | expandedArgsShape: string; | ||
| 15 | expandedReturnsShape: string; | ||
| 14 | argPreviewKeys: string[]; | 16 | argPreviewKeys: string[]; |
| 15 | searchText: string; | 17 | searchText: string; |
| 16 | normalizedPath: string; | 18 | normalizedPath: string; |
| @@ -43,6 +43,16 @@ function splitTopLevelBy(value: string, separator: string): string[] { · 42 unmodified lines | |||
| 43 | return parts; | 43 | return parts; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | function dedupeStrings(values: string[]): string[] { | ||
| 47 | const unique: string[] = []; | ||
| 48 | for (const value of values) { | ||
| 49 | const trimmed = value.trim(); | ||
| 50 | if (!trimmed) continue; | ||
| 51 | if (!unique.includes(trimmed)) unique.push(trimmed); | ||
| 52 | } | ||
| 53 | return unique; | ||
| 54 | } | ||
| 55 | |||
| 46 | function normalizeSimpleUnion(typeExpression: string): string { | 56 | function normalizeSimpleUnion(typeExpression: string): string { |
| 47 | const parts = splitTopLevelBy(typeExpression, "|") | 57 | const parts = splitTopLevelBy(typeExpression, "|") |
| 48 | .map((part) => part.trim()) | 58 | .map((part) => part.trim()) |
| @@ -178,6 +188,21 @@ export function extractTopLevelTypeKeys(typeHint: string): string[] { · 129 unmodified lines | |||
| 178 | return keys; | 188 | return keys; |
| 179 | } | 189 | } |
| 180 | 190 | ||
| 191 | export function extractTopLevelTypeKeysFromExpression(typeHint: string): string[] { | ||
| 192 | const direct = extractTopLevelTypeKeys(typeHint); | ||
| 193 | if (direct.length > 0) return direct; | ||
| 194 | |||
| 195 | const fromIntersections = splitTopLevelBy(typeHint, "&") | ||
| 196 | .flatMap((part) => extractTopLevelTypeKeys(part)); | ||
| 197 | if (fromIntersections.length > 0) { | ||
| 198 | return dedupeStrings(fromIntersections); | ||
| 199 | } | ||
| 200 | |||
| 201 | const fromUnions = splitTopLevelBy(typeHint, "|") | ||
| 202 | .flatMap((part) => extractTopLevelTypeKeys(part)); | ||
| 203 | return dedupeStrings(fromUnions); | ||
| 204 | } | ||
| 205 | |||
| 181 | export function compactArgKeysHint(keys: string[]): string { | 206 | export function compactArgKeysHint(keys: string[]): string { |
| 182 | const normalized = keys | 207 | const normalized = keys |
| 183 | .map((key) => key.trim()) | 208 | .map((key) => key.trim()) |
| @@ -272,6 +297,42 @@ export function compactReturnTypeHint(returnsType: string): string { · 88 unmodified lines | |||
| 272 | return truncateInline(normalized, 130); | 297 | return truncateInline(normalized, 130); |
| 273 | } | 298 | } |
| 274 | 299 | ||
| 300 | export function llmExpandedArgShapeHint(argsType: string, argPreviewKeys: string[] = []): string { | ||
| 301 | const normalized = argsType.replace(/\s+/g, " ").trim(); | ||
| 302 | if (!normalized || normalized === "{}") return "{}"; | ||
| 303 | |||
| 304 | const simpleInline = normalized.length <= 480 && !normalized.includes('components["schemas"]'); | ||
| 305 | if (simpleInline) return normalized; | ||
| 306 | |||
| 307 | const keys = dedupeStrings(argPreviewKeys.length > 0 | ||
| 308 | ? argPreviewKeys | ||
| 309 | : extractTopLevelTypeKeysFromExpression(argsType)); | ||
| 310 | if (keys.length > 0) { | ||
| 311 | const shown = keys.slice(0, 12).map((key) => `${key}: ...`); | ||
| 312 | const suffix = keys.length > 12 ? "; ..." : ""; | ||
| 313 | return `{ ${shown.join("; ")}${suffix} }`; | ||
| 314 | } | ||
| 315 | |||
| 316 | return truncateInline(normalized, 260); | ||
| 317 | } | ||
| 318 | |||
| 319 | export function llmExpandedReturnShapeHint(returnsType: string): string { | ||
| 320 | const normalized = returnsType.replace(/\s+/g, " ").trim(); | ||
| 321 | if (!normalized) return "unknown"; | ||
| 322 | |||
| 323 | const simpleInline = normalized.length <= 560 && !normalized.includes('components["schemas"]'); | ||
| 324 | if (simpleInline) return normalized; | ||
| 325 | |||
| 326 | const keys = extractTopLevelTypeKeysFromExpression(returnsType); | ||
| 327 | if (keys.length > 0) { | ||
| 328 | const shown = keys.slice(0, 12).map((key) => `${key}: ...`); | ||
| 329 | const suffix = keys.length > 12 ? "; ..." : ""; | ||
| 330 | return `{ ${shown.join("; ")}${suffix} }`; | ||
| 331 | } | ||
| 332 | |||
| 333 | return truncateInline(normalized, 280); | ||
| 334 | } | ||
| 335 | |||
| 275 | export function compactDescriptionLine(description: string): string { | 336 | export function compactDescriptionLine(description: string): string { |
| 276 | const firstLine = description.split("\n")[0] ?? description; | 337 | const firstLine = description.split("\n")[0] ?? description; |
| 277 | return truncateInline(firstLine, 180); | 338 | return truncateInline(firstLine, 180); |