orchid-ai 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -0
- package/dist/components/ChatPanel.d.ts +123 -0
- package/dist/components/Conversation.d.ts +75 -0
- package/dist/components/ErrorBoundary.d.ts +16 -0
- package/dist/components/Icon.d.ts +84 -0
- package/dist/components/ModelSwitcher.d.ts +24 -0
- package/dist/components/SuggestionsPanel.d.ts +27 -0
- package/dist/constants.d.ts +353 -0
- package/dist/hooks/useAiMerge.d.ts +20 -0
- package/dist/hooks/useModelSwitcher.d.ts +65 -0
- package/dist/hooks/useStreamingAI.d.ts +29 -0
- package/dist/hooks/useSuggestions.d.ts +48 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.esm.js +3385 -0
- package/dist/index.js +3400 -0
- package/dist/server/components/ChatPanel.d.ts +123 -0
- package/dist/server/components/Conversation.d.ts +75 -0
- package/dist/server/components/ErrorBoundary.d.ts +16 -0
- package/dist/server/components/Icon.d.ts +84 -0
- package/dist/server/components/ModelSwitcher.d.ts +24 -0
- package/dist/server/components/SuggestionsPanel.d.ts +27 -0
- package/dist/server/constants.d.ts +353 -0
- package/dist/server/contextual-service.d.ts +59 -0
- package/dist/server/document-processor.d.ts +60 -0
- package/dist/server/hooks/useAiMerge.d.ts +20 -0
- package/dist/server/hooks/useModelSwitcher.d.ts +65 -0
- package/dist/server/hooks/useStreamingAI.d.ts +29 -0
- package/dist/server/hooks/useSuggestions.d.ts +48 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.esm.js +14008 -0
- package/dist/server/index.js +14019 -0
- package/dist/server/server/contextual-service.d.ts +59 -0
- package/dist/server/server/document-processor.d.ts +60 -0
- package/dist/server/server/index.d.ts +7 -0
- package/dist/server/server/server.d.ts +32 -0
- package/dist/server/server/service.d.ts +267 -0
- package/dist/server/server/training-schema.d.ts +17 -0
- package/dist/server/server/training.d.ts +231 -0
- package/dist/server/server/utils.d.ts +209 -0
- package/dist/server/server.d.ts +32 -0
- package/dist/server/service.d.ts +267 -0
- package/dist/server/training-schema.d.ts +17 -0
- package/dist/server/training.d.ts +231 -0
- package/dist/server/types/types.d.ts +481 -0
- package/dist/server/utils/fileHandler.d.ts +20 -0
- package/dist/server/utils/mergeWithAi.d.ts +19 -0
- package/dist/server/utils.d.ts +209 -0
- package/dist/types/types.d.ts +481 -0
- package/dist/utils/fileHandler.d.ts +20 -0
- package/dist/utils/mergeWithAi.d.ts +19 -0
- package/dist/utils.d.ts +19 -0
- package/package.json +137 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { ChatTheme, CommandTheme, ModelInfo } from './types/types';
|
|
2
|
+
export declare const DEFAULT_CONFIG: {
|
|
3
|
+
service: "claude";
|
|
4
|
+
model: string;
|
|
5
|
+
temperature: number;
|
|
6
|
+
maxTokens: number;
|
|
7
|
+
chatLevel: "none";
|
|
8
|
+
supportsImages: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const DEFAULT_MODELS: Record<string, ModelInfo[]>;
|
|
11
|
+
export declare const defaultTheme: CommandTheme;
|
|
12
|
+
export declare const defaultDarkTheme: ChatTheme;
|
|
13
|
+
export declare const defaultLightTheme: ChatTheme;
|
|
14
|
+
export declare const commandTrainingRules: {
|
|
15
|
+
components: {
|
|
16
|
+
patterns: {
|
|
17
|
+
componentName: RegExp;
|
|
18
|
+
props: RegExp;
|
|
19
|
+
state: RegExp;
|
|
20
|
+
functions: RegExp;
|
|
21
|
+
routes: RegExp;
|
|
22
|
+
formFields: RegExp;
|
|
23
|
+
imports: RegExp;
|
|
24
|
+
exports: RegExp;
|
|
25
|
+
hooks: RegExp;
|
|
26
|
+
eventHandlers: RegExp;
|
|
27
|
+
};
|
|
28
|
+
importance: string[];
|
|
29
|
+
};
|
|
30
|
+
schemas: {
|
|
31
|
+
patterns: {
|
|
32
|
+
modelName: RegExp;
|
|
33
|
+
fields: RegExp;
|
|
34
|
+
fieldDefinitions: RegExp;
|
|
35
|
+
indexes: RegExp;
|
|
36
|
+
indexDefinitions: RegExp;
|
|
37
|
+
validations: RegExp;
|
|
38
|
+
validationRules: RegExp;
|
|
39
|
+
};
|
|
40
|
+
importance: string[];
|
|
41
|
+
};
|
|
42
|
+
constants: {
|
|
43
|
+
patterns: {
|
|
44
|
+
definitions: RegExp;
|
|
45
|
+
constValues: RegExp;
|
|
46
|
+
enums: RegExp;
|
|
47
|
+
enumValues: RegExp;
|
|
48
|
+
arrayConstants: RegExp;
|
|
49
|
+
objectConstants: RegExp;
|
|
50
|
+
};
|
|
51
|
+
importance: string[];
|
|
52
|
+
};
|
|
53
|
+
types: {
|
|
54
|
+
patterns: {
|
|
55
|
+
types: RegExp;
|
|
56
|
+
typeDefinitions: RegExp;
|
|
57
|
+
interfaces: RegExp;
|
|
58
|
+
interfaceDefinitions: RegExp;
|
|
59
|
+
enums: RegExp;
|
|
60
|
+
enumMembers: RegExp;
|
|
61
|
+
generics: RegExp;
|
|
62
|
+
unionTypes: RegExp;
|
|
63
|
+
optionalFields: RegExp;
|
|
64
|
+
};
|
|
65
|
+
importance: string[];
|
|
66
|
+
};
|
|
67
|
+
dataTypes: {
|
|
68
|
+
date: {
|
|
69
|
+
pattern: RegExp;
|
|
70
|
+
transform: (value: any) => any;
|
|
71
|
+
validation: (value: any) => boolean;
|
|
72
|
+
};
|
|
73
|
+
number: {
|
|
74
|
+
pattern: RegExp;
|
|
75
|
+
transform: (value: any) => number;
|
|
76
|
+
validation: (value: any) => boolean;
|
|
77
|
+
};
|
|
78
|
+
boolean: {
|
|
79
|
+
pattern: RegExp;
|
|
80
|
+
transform: (value: any) => boolean;
|
|
81
|
+
validation: (value: any) => value is boolean;
|
|
82
|
+
};
|
|
83
|
+
string: {
|
|
84
|
+
pattern: RegExp;
|
|
85
|
+
transform: (value: any) => string;
|
|
86
|
+
validation: (value: any) => value is string;
|
|
87
|
+
};
|
|
88
|
+
array: {
|
|
89
|
+
pattern: RegExp;
|
|
90
|
+
transform: (value: any) => any[];
|
|
91
|
+
validation: (value: any) => value is any[];
|
|
92
|
+
};
|
|
93
|
+
object: {
|
|
94
|
+
pattern: RegExp;
|
|
95
|
+
transform: (value: any) => any;
|
|
96
|
+
validation: (value: any) => boolean;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
dataTypeImportance: string[];
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Base training data for the command service.
|
|
103
|
+
*
|
|
104
|
+
* NOTE: You should customize the following for your project:
|
|
105
|
+
* - components: List all relevant React component files.
|
|
106
|
+
* - schemas: List all Monastery schema files.
|
|
107
|
+
* - constants: List all constants files.
|
|
108
|
+
* - types: List all TypeScript type files.
|
|
109
|
+
* - options: Define all field options and refinement logic for your domain.
|
|
110
|
+
* - _paths: Metadata specifying which fields contain file paths (used by collector).
|
|
111
|
+
*
|
|
112
|
+
* The collector will extract structured data including:
|
|
113
|
+
* - Component names, props, state, functions, form fields
|
|
114
|
+
* - Schema field definitions with types and validations
|
|
115
|
+
* - Constant values and enum members
|
|
116
|
+
* - TypeScript interfaces and type definitions
|
|
117
|
+
*/
|
|
118
|
+
export declare const baseTrainingData: {
|
|
119
|
+
/**
|
|
120
|
+
* List of React component file paths used for context.
|
|
121
|
+
* The collector will extract: component names, props, state, functions, form fields, imports, hooks
|
|
122
|
+
* @type {string[]}
|
|
123
|
+
*/
|
|
124
|
+
components: never[];
|
|
125
|
+
/**
|
|
126
|
+
* List of Monastery schema file paths.
|
|
127
|
+
* The collector will extract: model names, field definitions, indexes, validations
|
|
128
|
+
* @type {string[]}
|
|
129
|
+
*/
|
|
130
|
+
schemas: never[];
|
|
131
|
+
/**
|
|
132
|
+
* List of constants file paths.
|
|
133
|
+
* The collector will extract: constant definitions, values, enums
|
|
134
|
+
* @type {string[]}
|
|
135
|
+
*/
|
|
136
|
+
constants: never[];
|
|
137
|
+
/**
|
|
138
|
+
* List of TypeScript type file paths.
|
|
139
|
+
* The collector will extract: type definitions, interfaces, enums
|
|
140
|
+
* @type {string[]}
|
|
141
|
+
*/
|
|
142
|
+
types: never[];
|
|
143
|
+
/**
|
|
144
|
+
* Manual route definitions with descriptions.
|
|
145
|
+
* Define all available routes with clear descriptions for the AI to understand.
|
|
146
|
+
* Format: { path: string, title: string, description?: string }
|
|
147
|
+
* @type {Array<{path: string, title: string, description?: string}>}
|
|
148
|
+
*/
|
|
149
|
+
routes: never[];
|
|
150
|
+
/**
|
|
151
|
+
* Field options and refinement logic. Customize for your domain fields.
|
|
152
|
+
* The AI will use these to understand field values and validation rules.
|
|
153
|
+
* @type {Object}
|
|
154
|
+
*/
|
|
155
|
+
options: {};
|
|
156
|
+
/**
|
|
157
|
+
* Metadata specifying which fields contain file paths for the collector.
|
|
158
|
+
* The collector will automatically read and process these fields.
|
|
159
|
+
* Note: 'routes' is now handled manually - no automatic extraction.
|
|
160
|
+
* @type {string[]}
|
|
161
|
+
*/
|
|
162
|
+
_paths: never[];
|
|
163
|
+
/**
|
|
164
|
+
* Action types.
|
|
165
|
+
* The AI will use these to understand the user's input
|
|
166
|
+
* and return the correct suggestions for icon display
|
|
167
|
+
* @type {Object}
|
|
168
|
+
*/
|
|
169
|
+
actionTypes: {
|
|
170
|
+
type: string;
|
|
171
|
+
description: string;
|
|
172
|
+
}[];
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Instructions for a fully conversational AI assistant.
|
|
176
|
+
* Always provides chatty, helpful responses regardless of context.
|
|
177
|
+
*/
|
|
178
|
+
export declare const fullChatInstructions: string;
|
|
179
|
+
/**
|
|
180
|
+
* Instructions for a basic conversational AI assistant.
|
|
181
|
+
* Balances being helpful with being concise, focusing on essential help and actions.
|
|
182
|
+
*/
|
|
183
|
+
export declare const basicChatInstructions: string;
|
|
184
|
+
/**
|
|
185
|
+
* Instructions for a functional, JSON-only AI assistant.
|
|
186
|
+
* Provides only JSON responses with no explanations or commentary.
|
|
187
|
+
*/
|
|
188
|
+
export declare const noneChatInstructions: string;
|
|
189
|
+
/**
|
|
190
|
+
* Structured training data format optimized for AI models
|
|
191
|
+
* Organizes information hierarchically with clear relationships
|
|
192
|
+
*/
|
|
193
|
+
export declare const structuredTrainingFormat: {
|
|
194
|
+
/**
|
|
195
|
+
* Application Overview - High-level context for the AI
|
|
196
|
+
*/
|
|
197
|
+
overview: {
|
|
198
|
+
domain: string;
|
|
199
|
+
purpose: string;
|
|
200
|
+
architecture: string;
|
|
201
|
+
primaryEntities: string[];
|
|
202
|
+
commonActions: string[];
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Component Hierarchy - Organized by functionality
|
|
206
|
+
*/
|
|
207
|
+
components: {
|
|
208
|
+
pages: Array<{
|
|
209
|
+
name: string;
|
|
210
|
+
path: string;
|
|
211
|
+
purpose: string;
|
|
212
|
+
mainActions: string[];
|
|
213
|
+
relatedEntities: string[];
|
|
214
|
+
}>;
|
|
215
|
+
forms: Array<{
|
|
216
|
+
name: string;
|
|
217
|
+
purpose: string;
|
|
218
|
+
fields: Array<{
|
|
219
|
+
name: string;
|
|
220
|
+
type: string;
|
|
221
|
+
required: boolean;
|
|
222
|
+
validation?: string;
|
|
223
|
+
}>;
|
|
224
|
+
actions: string[];
|
|
225
|
+
relatedEntity: string;
|
|
226
|
+
}>;
|
|
227
|
+
ui: Array<{
|
|
228
|
+
name: string;
|
|
229
|
+
purpose: string;
|
|
230
|
+
props: Array<{
|
|
231
|
+
name: string;
|
|
232
|
+
type: string;
|
|
233
|
+
required: boolean;
|
|
234
|
+
}>;
|
|
235
|
+
}>;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Data Models - Structured with relationships
|
|
239
|
+
*/
|
|
240
|
+
dataModels: {
|
|
241
|
+
entities: Array<{
|
|
242
|
+
name: string;
|
|
243
|
+
purpose: string;
|
|
244
|
+
fields: Array<{
|
|
245
|
+
name: string;
|
|
246
|
+
type: string;
|
|
247
|
+
required: boolean;
|
|
248
|
+
description?: string;
|
|
249
|
+
validation?: string;
|
|
250
|
+
options?: string[];
|
|
251
|
+
}>;
|
|
252
|
+
relationships: Array<{
|
|
253
|
+
type: "hasMany" | "belongsTo" | "hasOne";
|
|
254
|
+
entity: string;
|
|
255
|
+
description: string;
|
|
256
|
+
}>;
|
|
257
|
+
commonActions: string[];
|
|
258
|
+
}>;
|
|
259
|
+
enums: Array<{
|
|
260
|
+
name: string;
|
|
261
|
+
purpose: string;
|
|
262
|
+
values: Array<{
|
|
263
|
+
key: string;
|
|
264
|
+
value: string;
|
|
265
|
+
description?: string;
|
|
266
|
+
}>;
|
|
267
|
+
}>;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Navigation & Routes - Organized by user flow
|
|
271
|
+
*/
|
|
272
|
+
navigation: {
|
|
273
|
+
routes: Array<{
|
|
274
|
+
path: string;
|
|
275
|
+
name: string;
|
|
276
|
+
purpose: string;
|
|
277
|
+
requiredParams?: string[];
|
|
278
|
+
relatedEntity?: string;
|
|
279
|
+
commonActions: string[];
|
|
280
|
+
}>;
|
|
281
|
+
workflows: Array<{
|
|
282
|
+
name: string;
|
|
283
|
+
description: string;
|
|
284
|
+
steps: Array<{
|
|
285
|
+
action: string;
|
|
286
|
+
route: string;
|
|
287
|
+
description: string;
|
|
288
|
+
}>;
|
|
289
|
+
}>;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Business Rules - Context for decision making
|
|
293
|
+
*/
|
|
294
|
+
businessRules: {
|
|
295
|
+
validation: Array<{
|
|
296
|
+
field: string;
|
|
297
|
+
rule: string;
|
|
298
|
+
message: string;
|
|
299
|
+
context: string;
|
|
300
|
+
}>;
|
|
301
|
+
workflows: Array<{
|
|
302
|
+
trigger: string;
|
|
303
|
+
conditions: string[];
|
|
304
|
+
actions: string[];
|
|
305
|
+
description: string;
|
|
306
|
+
}>;
|
|
307
|
+
permissions: Array<{
|
|
308
|
+
action: string;
|
|
309
|
+
entity: string;
|
|
310
|
+
conditions: string[];
|
|
311
|
+
description: string;
|
|
312
|
+
}>;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Examples - Concrete usage patterns
|
|
316
|
+
*/
|
|
317
|
+
examples: {
|
|
318
|
+
commonTasks: Array<{
|
|
319
|
+
userIntent: string;
|
|
320
|
+
expectedAction: string;
|
|
321
|
+
formData?: Record<string, any>;
|
|
322
|
+
route?: string;
|
|
323
|
+
description: string;
|
|
324
|
+
}>;
|
|
325
|
+
fieldMappings: Array<{
|
|
326
|
+
userInput: string;
|
|
327
|
+
fieldName: string;
|
|
328
|
+
processedValue: any;
|
|
329
|
+
validation?: string;
|
|
330
|
+
}>;
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Provider-specific training data formatters
|
|
335
|
+
* These functions format the structured training data in optimal ways for each AI provider
|
|
336
|
+
*/
|
|
337
|
+
export declare const trainingDataFormatters: {
|
|
338
|
+
/**
|
|
339
|
+
* Claude-optimized format: Structured markdown with clear sections
|
|
340
|
+
* Claude performs best with clear hierarchical markdown and explicit structure
|
|
341
|
+
*/
|
|
342
|
+
claude: (data: typeof structuredTrainingFormat) => string;
|
|
343
|
+
/**
|
|
344
|
+
* GPT-4-optimized format: Structured with clear hierarchy and consistent formatting
|
|
345
|
+
* OpenAI models prefer clear structure with consistent patterns
|
|
346
|
+
*/
|
|
347
|
+
openai: (data: typeof structuredTrainingFormat) => string;
|
|
348
|
+
/**
|
|
349
|
+
* Gemini-optimized format: JSON structure with nested relationships
|
|
350
|
+
* Gemini models excel at processing structured JSON data with clear relationships
|
|
351
|
+
*/
|
|
352
|
+
gemini: (data: typeof structuredTrainingFormat) => string;
|
|
353
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ContextualServiceConfig, ContextualRequest } from '../types/types.js';
|
|
2
|
+
export declare class ContextualCommandService {
|
|
3
|
+
private config;
|
|
4
|
+
private verboseLogging;
|
|
5
|
+
private usage;
|
|
6
|
+
constructor(config: ContextualServiceConfig);
|
|
7
|
+
private autoConfigureProviders;
|
|
8
|
+
private log;
|
|
9
|
+
private handleError;
|
|
10
|
+
/**
|
|
11
|
+
* Build a focused system prompt based on schema and chat level
|
|
12
|
+
*/
|
|
13
|
+
private buildContextualSystemPrompt;
|
|
14
|
+
/**
|
|
15
|
+
* Format schema fields into readable descriptions
|
|
16
|
+
*/
|
|
17
|
+
private formatSchemaFields;
|
|
18
|
+
/**
|
|
19
|
+
* Create a model instance for a specific request
|
|
20
|
+
*/
|
|
21
|
+
private createModelForRequest;
|
|
22
|
+
private createModelInstance;
|
|
23
|
+
private getApiKeyForProvider;
|
|
24
|
+
/**
|
|
25
|
+
* Stream suggestions with contextual schema information
|
|
26
|
+
*/
|
|
27
|
+
streamSuggestions(request: ContextualRequest, onData: (data: any) => void, onDone: () => void, onError: (error: Error) => void): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Get non-streaming suggestions
|
|
30
|
+
*/
|
|
31
|
+
getSuggestions(request: ContextualRequest): Promise<any[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Get available models
|
|
34
|
+
*/
|
|
35
|
+
getAvailableModels(): Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
provider: string;
|
|
39
|
+
available: boolean;
|
|
40
|
+
}[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Get usage statistics
|
|
43
|
+
*/
|
|
44
|
+
getUsageStats(): {
|
|
45
|
+
requests: number;
|
|
46
|
+
totalTokens: number;
|
|
47
|
+
totalComputeUnits: number;
|
|
48
|
+
providers: {
|
|
49
|
+
name: string;
|
|
50
|
+
requests: number;
|
|
51
|
+
computeUnits: number;
|
|
52
|
+
models: string[];
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Track request for usage stats
|
|
57
|
+
*/
|
|
58
|
+
private trackRequest;
|
|
59
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface ProcessedFile {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
size: number;
|
|
5
|
+
content: string;
|
|
6
|
+
isImage: boolean;
|
|
7
|
+
originalData?: string;
|
|
8
|
+
fileData?: string;
|
|
9
|
+
metadata?: {
|
|
10
|
+
dimensions?: {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
encoding?: string;
|
|
15
|
+
pages?: number;
|
|
16
|
+
sheets?: string[];
|
|
17
|
+
rows?: number;
|
|
18
|
+
columns?: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class DocumentProcessor {
|
|
22
|
+
/**
|
|
23
|
+
* Process a single file and extract its content
|
|
24
|
+
*/
|
|
25
|
+
static processFile(file: {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
size: number;
|
|
29
|
+
data: string;
|
|
30
|
+
}, aiService?: string): Promise<ProcessedFile>;
|
|
31
|
+
/**
|
|
32
|
+
* Process multiple files and return both processed files and image data for AI
|
|
33
|
+
*/
|
|
34
|
+
static processFiles(files: Array<{
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
size: number;
|
|
38
|
+
data: string;
|
|
39
|
+
}>, aiService?: string): Promise<{
|
|
40
|
+
processedFiles: ProcessedFile[];
|
|
41
|
+
imageData: Array<{
|
|
42
|
+
data: string;
|
|
43
|
+
type: string;
|
|
44
|
+
name: string;
|
|
45
|
+
}>;
|
|
46
|
+
fileData: string[];
|
|
47
|
+
textContent: string;
|
|
48
|
+
}>;
|
|
49
|
+
private static getSupportedFormats;
|
|
50
|
+
private static processImage;
|
|
51
|
+
private static isImageFile;
|
|
52
|
+
private static processPDF;
|
|
53
|
+
private static processTextFile;
|
|
54
|
+
private static processRTF;
|
|
55
|
+
private static processCSV;
|
|
56
|
+
private static formatFileSize;
|
|
57
|
+
private static processJSON;
|
|
58
|
+
private static processXML;
|
|
59
|
+
private static isValidUTF8Text;
|
|
60
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MergeConfig } from '../utils';
|
|
2
|
+
interface Options<T> {
|
|
3
|
+
ai?: Partial<T>;
|
|
4
|
+
draft: T;
|
|
5
|
+
onMerged: (next: T) => void;
|
|
6
|
+
config?: MergeConfig<T>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* React hook that merges an AI-generated payload into local form state.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const { pending, applyPending } = useAiMerge({ ai, draft, onMerged })
|
|
13
|
+
* <WarningModal isOpen={!!pending} onConfirm={applyPending} />
|
|
14
|
+
*/
|
|
15
|
+
export declare function useAiMerge<T>({ ai, draft, onMerged, config }: Options<T>): {
|
|
16
|
+
pending: Partial<T> | null;
|
|
17
|
+
applyPending: () => void;
|
|
18
|
+
clearPending: () => void;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ModelInfo } from '../types/types';
|
|
2
|
+
interface CurrentModel {
|
|
3
|
+
provider: string;
|
|
4
|
+
model: string;
|
|
5
|
+
}
|
|
6
|
+
interface ModelCapabilities {
|
|
7
|
+
supportsImages: boolean;
|
|
8
|
+
computeWeight?: number;
|
|
9
|
+
}
|
|
10
|
+
interface UsageStats {
|
|
11
|
+
requests: number;
|
|
12
|
+
totalTokens: number;
|
|
13
|
+
totalComputeUnits: number;
|
|
14
|
+
modelSwitches: number;
|
|
15
|
+
uptime: number;
|
|
16
|
+
providers: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
requests: number;
|
|
19
|
+
computeUnits: number;
|
|
20
|
+
models: string[];
|
|
21
|
+
}>;
|
|
22
|
+
currentProvider: string;
|
|
23
|
+
currentModel: string;
|
|
24
|
+
}
|
|
25
|
+
interface UseModelSwitcherOptions {
|
|
26
|
+
initialProvider?: string;
|
|
27
|
+
initialModel?: string;
|
|
28
|
+
customModels?: Record<string, ModelInfo[]>;
|
|
29
|
+
}
|
|
30
|
+
export declare function useModelSwitcher({ initialProvider, initialModel, customModels, }?: UseModelSwitcherOptions): {
|
|
31
|
+
models: ModelInfo[];
|
|
32
|
+
modelsByProvider: Record<string, ModelInfo[]>;
|
|
33
|
+
currentModel: CurrentModel;
|
|
34
|
+
currentCapabilities: ModelCapabilities;
|
|
35
|
+
usageStats: UsageStats;
|
|
36
|
+
isLoading: boolean;
|
|
37
|
+
error: null;
|
|
38
|
+
switchModel: (model: string, provider?: string) => {
|
|
39
|
+
success: boolean;
|
|
40
|
+
current: {
|
|
41
|
+
provider: string;
|
|
42
|
+
model: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
trackUsage: (tokens: number, computeUnits: number) => void;
|
|
46
|
+
resetUsageStats: () => void;
|
|
47
|
+
getCurrentModelInfo: () => {
|
|
48
|
+
provider: string;
|
|
49
|
+
model: string;
|
|
50
|
+
capabilities: ModelCapabilities;
|
|
51
|
+
};
|
|
52
|
+
modelState: {
|
|
53
|
+
models: ModelInfo[];
|
|
54
|
+
current: CurrentModel;
|
|
55
|
+
capabilities: ModelCapabilities;
|
|
56
|
+
usage: UsageStats;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
};
|
|
59
|
+
fetchModelState: () => Promise<void>;
|
|
60
|
+
fetchModels: () => Promise<void>;
|
|
61
|
+
fetchUsageStats: () => Promise<void>;
|
|
62
|
+
fetchCurrentCapabilities: () => Promise<void>;
|
|
63
|
+
integrationMode: "local";
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChatMessage, ModelCapabilities, ServerConfig } from '../types/types';
|
|
2
|
+
interface ModelSelection {
|
|
3
|
+
provider: string;
|
|
4
|
+
model: string;
|
|
5
|
+
capabilities: ModelCapabilities;
|
|
6
|
+
}
|
|
7
|
+
export declare function useStreamingAI({ userId, serverConfig, formData, chats: externalChats, setChats: externalSetChats, currentChatId: externalCurrentChatId, setCurrentChatId: externalSetCurrentChatId, modelSelection, onUsageTracked, chatLevel, additionalContext, verbose, }: {
|
|
8
|
+
userId: string;
|
|
9
|
+
serverConfig?: ServerConfig;
|
|
10
|
+
formData?: Record<string, unknown>;
|
|
11
|
+
chats?: Record<string, ChatMessage[]>;
|
|
12
|
+
setChats?: React.Dispatch<React.SetStateAction<Record<string, ChatMessage[]>>>;
|
|
13
|
+
currentChatId?: string;
|
|
14
|
+
setCurrentChatId?: React.Dispatch<React.SetStateAction<string>>;
|
|
15
|
+
modelSelection?: ModelSelection;
|
|
16
|
+
onUsageTracked?: (tokens: number, computeUnits: number) => void;
|
|
17
|
+
chatLevel?: 'full' | 'basic' | 'none';
|
|
18
|
+
additionalContext?: string | Record<string, unknown>;
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
}): {
|
|
21
|
+
chat: ChatMessage[];
|
|
22
|
+
chats: Record<string, ChatMessage[]>;
|
|
23
|
+
currentChatId: string;
|
|
24
|
+
isLoading: boolean;
|
|
25
|
+
sendQuery: (query: string, files?: File[], context?: string) => void;
|
|
26
|
+
newChat: () => void;
|
|
27
|
+
switchChat: (chatId: string) => void;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CommandSuggestion, ServerConfig } from '../types/types';
|
|
2
|
+
interface UseSuggestionsProps {
|
|
3
|
+
userId: string;
|
|
4
|
+
formData?: Record<string, unknown>;
|
|
5
|
+
serverConfig?: ServerConfig;
|
|
6
|
+
debounceMs?: number;
|
|
7
|
+
maxSuggestions?: number;
|
|
8
|
+
chatLevel?: 'none' | 'basic' | 'full';
|
|
9
|
+
modelSelection?: {
|
|
10
|
+
provider: string;
|
|
11
|
+
model: string;
|
|
12
|
+
capabilities: {
|
|
13
|
+
supportsImages: boolean;
|
|
14
|
+
computeWeight: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
onUsageTracked?: (tokens: number, computeUnits: number) => void;
|
|
18
|
+
context?: string;
|
|
19
|
+
}
|
|
20
|
+
interface UseSuggestionsReturn {
|
|
21
|
+
suggestions: CommandSuggestion[];
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
error: string | null;
|
|
24
|
+
getSuggestions: (query: string, additionalContext?: string) => Promise<CommandSuggestion[] | Error>;
|
|
25
|
+
clearSuggestions: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Hook for getting AI suggestions based on a query
|
|
29
|
+
*
|
|
30
|
+
* @param userId - User ID for the suggestion request
|
|
31
|
+
* @param formData - Current form data context
|
|
32
|
+
* @param serverConfig - Server configuration
|
|
33
|
+
* @param debounceMs - Debounce delay in milliseconds (default: 300)
|
|
34
|
+
* @param maxSuggestions - Maximum number of suggestions to return (default: 10)
|
|
35
|
+
* @param chatLevel - Chat level to send to the server (default: 'none')
|
|
36
|
+
* @returns Object containing suggestions, loading state, error state, and control functions
|
|
37
|
+
*/
|
|
38
|
+
export declare function useSuggestions({ userId, formData, serverConfig, debounceMs, maxSuggestions, chatLevel, // <-- default to 'none'
|
|
39
|
+
modelSelection, onUsageTracked, context, }: UseSuggestionsProps): UseSuggestionsReturn;
|
|
40
|
+
/**
|
|
41
|
+
* Hook for getting suggestions with automatic debouncing
|
|
42
|
+
*
|
|
43
|
+
* @param query - The search query
|
|
44
|
+
* @param options - Configuration options
|
|
45
|
+
* @returns Object containing suggestions, loading state, and error state
|
|
46
|
+
*/
|
|
47
|
+
export declare function useDebouncedSuggestions(query: string, options: UseSuggestionsProps): Omit<UseSuggestionsReturn, 'getSuggestions' | 'clearSuggestions'>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TrainingConfig, ServerOptions, AIProvider, CommandServer, ContextualServiceConfig, ContextualRequest, SchemaDefinition, SchemaProperty } from '../types/types.js';
|
|
2
|
+
export type { ServerOptions, CommandServer, TrainingConfig, AIProvider, ContextualServiceConfig, ContextualRequest, SchemaDefinition, SchemaProperty, };
|
|
3
|
+
export { setupCommandServer, createCommandConfig, formatErrorForUser, } from './server';
|
|
4
|
+
export { CommandService, } from './service';
|
|
5
|
+
export { ContextualCommandService, } from './contextual-service';
|
|
6
|
+
export { getTrainingDataConfig, CommandTrainingCollector, } from './training';
|
|
7
|
+
export { createTrainingConfig, validateTrainingConfig, getExpectedFileStructure, } from './training-schema';
|