@@ -4,6 +4,27 @@ import type { AIToolDefinition, IDataEngine, IMetadataService } from '@objectsta
44import type { ToolHandler } from './tool-registry.js' ;
55import type { ToolRegistry } from './tool-registry.js' ;
66
7+ // ---------------------------------------------------------------------------
8+ // Internal type aliases for metadata payloads (returned as `unknown` from
9+ // IMetadataService — we cast to these lightweight shapes for field access).
10+ // ---------------------------------------------------------------------------
11+
12+ /** Minimal shape of an object definition as returned by IMetadataService. */
13+ interface ObjectDef {
14+ name : string ;
15+ label ?: string ;
16+ fields ?: Record < string , FieldDef > ;
17+ }
18+
19+ /** Minimal shape of a field definition inside an object. */
20+ interface FieldDef {
21+ type ?: string ;
22+ label ?: string ;
23+ required ?: boolean ;
24+ reference ?: string ;
25+ options ?: unknown ;
26+ }
27+
728// ---------------------------------------------------------------------------
829// Data context — injected once at registration time
930// ---------------------------------------------------------------------------
@@ -198,7 +219,7 @@ export const DATA_TOOL_DEFINITIONS: AIToolDefinition[] = [
198219function createListObjectsHandler ( ctx : DataToolContext ) : ToolHandler {
199220 return async ( ) => {
200221 const objects = await ctx . metadataService . listObjects ( ) ;
201- const summary = objects . map ( ( o : any ) => ( {
222+ const summary = ( objects as ObjectDef [ ] ) . map ( o => ( {
202223 name : o . name ,
203224 label : o . label ?? o . name ,
204225 } ) ) ;
@@ -214,11 +235,10 @@ function createDescribeObjectHandler(ctx: DataToolContext): ToolHandler {
214235 return JSON . stringify ( { error : `Object "${ objectName } " not found` } ) ;
215236 }
216237
217- const def = objectDef as any ;
238+ const def = objectDef as ObjectDef ;
218239 const fields = def . fields ?? { } ;
219- const fieldSummary : Record < string , any > = { } ;
220- for ( const [ key , fd ] of Object . entries ( fields ) ) {
221- const f = fd as any ;
240+ const fieldSummary : Record < string , Record < string , unknown > > = { } ;
241+ for ( const [ key , f ] of Object . entries ( fields ) ) {
222242 fieldSummary [ key ] = {
223243 type : f . type ,
224244 label : f . label ?? key ,
@@ -289,6 +309,9 @@ function createGetRecordHandler(ctx: DataToolContext): ToolHandler {
289309 } ;
290310}
291311
312+ /** Aggregation function names supported by the data engine. */
313+ type AggFn = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct' ;
314+
292315function createAggregateDataHandler ( ctx : DataToolContext ) : ToolHandler {
293316 return async ( args ) => {
294317 const { objectName, aggregations, groupBy, where } = args as {
@@ -302,7 +325,7 @@ function createAggregateDataHandler(ctx: DataToolContext): ToolHandler {
302325 where,
303326 groupBy,
304327 aggregations : aggregations . map ( a => ( {
305- function : a . function as any ,
328+ function : a . function as AggFn ,
306329 field : a . field ,
307330 alias : a . alias ,
308331 } ) ) ,
0 commit comments