forked from dipseth/dataproc-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic-templating.ts
More file actions
261 lines (210 loc) · 5.46 KB
/
dynamic-templating.ts
File metadata and controls
261 lines (210 loc) · 5.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/**
* Type definitions for Dynamic Templating System
* Supports job output references and Qdrant knowledge queries
*/
import { JobTracker } from '../services/job-tracker.js';
import { KnowledgeIndexer } from '../services/knowledge-indexer.js';
import { AsyncQueryPoller } from '../services/async-query-poller.js';
import { TemplateResolutionContext } from './templating.js';
/**
* Supported dynamic function types
*/
export type DynamicFunctionType = 'job_output' | 'qdrant_query';
/**
* Parsed function call from template string
*/
export interface FunctionCall {
/** Function name */
name: DynamicFunctionType;
/** Function arguments */
args: string[];
/** Original function string for debugging */
original: string;
/** Position in the template string */
position: {
start: number;
end: number;
};
}
/**
* Context for dynamic function resolution
*/
export interface DynamicResolutionContext {
/** Job tracking service */
jobTracker: JobTracker;
/** Knowledge indexer for Qdrant queries */
knowledgeIndexer: KnowledgeIndexer;
/** Async query poller for job status */
asyncQueryPoller: AsyncQueryPoller;
/** Template resolution context */
templateContext: TemplateResolutionContext;
}
/**
* Cache entry for resolved dynamic values
*/
export interface DynamicCacheEntry {
/** Resolved value */
value: unknown;
/** Cache timestamp */
timestamp: Date;
/** Time-to-live in milliseconds */
ttl: number;
/** Original function call */
functionCall: FunctionCall;
/** Resolution metadata */
metadata: {
resolutionTimeMs: number;
source: 'cache' | 'fresh';
confidence?: number; // For Qdrant queries
};
}
/**
* Dynamic function execution result
*/
export interface FunctionExecutionResult {
/** Resolved value */
value: unknown;
/** Execution success status */
success: boolean;
/** Error message if execution failed */
error?: string;
/** Execution time in milliseconds */
executionTimeMs: number;
/** Whether result was cached */
cached: boolean;
/** Additional metadata */
metadata?: Record<string, unknown>;
}
/**
* Job output function specific types
*/
export interface JobOutputOptions {
/** Job ID to query */
jobId: string;
/** Field path using dot notation (e.g., 'results.rows[0].column_name') */
fieldPath: string;
/** Timeout for waiting for job completion (ms) */
timeoutMs?: number;
/** Whether to wait for job completion if still running */
waitForCompletion?: boolean;
}
/**
* Qdrant query function specific types
*/
export interface QdrantQueryOptions {
/** Semantic query string */
query: string;
/** Field to extract from results */
field: string;
/** Minimum confidence threshold (0-1) */
minConfidence?: number;
/** Maximum number of results to consider */
maxResults?: number;
/** Filter by project/region/cluster */
filters?: {
projectId?: string;
region?: string;
clusterName?: string;
};
}
/**
* Dynamic resolver configuration
*/
export interface DynamicResolverConfig {
/** Enable caching of resolved values */
enableCaching: boolean;
/** Default TTL for cached values (ms) */
defaultTtlMs: number;
/** Maximum cache size */
maxCacheSize: number;
/** Function execution timeout (ms) */
executionTimeoutMs: number;
/** Enable performance metrics */
enableMetrics: boolean;
/** Job output specific configuration */
jobOutput: {
/** Default timeout for job completion (ms) */
defaultTimeoutMs: number;
/** Whether to wait for running jobs by default */
waitForCompletion: boolean;
/** Cache TTL for job outputs (ms) */
cacheTtlMs: number;
};
/** Qdrant query specific configuration */
qdrantQuery: {
/** Default minimum confidence threshold */
defaultMinConfidence: number;
/** Default maximum results to consider */
defaultMaxResults: number;
/** Cache TTL for Qdrant queries (ms) */
cacheTtlMs: number;
};
}
/**
* Dynamic resolver metrics
*/
export interface DynamicResolverMetrics {
/** Total function calls */
totalCalls: number;
/** Successful resolutions */
successfulResolutions: number;
/** Failed resolutions */
failedResolutions: number;
/** Cache hits */
cacheHits: number;
/** Cache misses */
cacheMisses: number;
/** Average resolution time (ms) */
averageResolutionTimeMs: number;
/** Function-specific metrics */
functionMetrics: {
job_output: {
calls: number;
successes: number;
failures: number;
averageTimeMs: number;
};
qdrant_query: {
calls: number;
successes: number;
failures: number;
averageTimeMs: number;
averageConfidence: number;
};
};
}
/**
* Error types for dynamic function resolution
*/
export class DynamicResolutionError extends Error {
constructor(
message: string,
public functionCall: FunctionCall,
public cause?: Error
) {
super(message);
this.name = 'DynamicResolutionError';
}
}
export class JobOutputError extends DynamicResolutionError {
constructor(
message: string,
functionCall: FunctionCall,
public jobId: string,
cause?: Error
) {
super(message, functionCall, cause);
this.name = 'JobOutputError';
}
}
export class QdrantQueryError extends DynamicResolutionError {
constructor(
message: string,
functionCall: FunctionCall,
public query: string,
cause?: Error
) {
super(message, functionCall, cause);
this.name = 'QdrantQueryError';
}
}