orchid-ai 1.2.3 → 1.2.5

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.
Files changed (38) hide show
  1. package/README.md +3 -3
  2. package/dist/cli/components/ChatPanel.d.ts +2 -1
  3. package/dist/cli/components/Conversation.d.ts +2 -1
  4. package/dist/cli/components/ModelSwitcher.d.ts +2 -1
  5. package/dist/cli/hooks/useModelSwitcher.d.ts +7 -4
  6. package/dist/cli/hooks/useResolvedDefaultModel.d.ts +21 -0
  7. package/dist/cli/hooks/useStreamingAI.d.ts +3 -2
  8. package/dist/cli/index.d.ts +1 -0
  9. package/dist/cli/server/contextual-service.d.ts +49 -1
  10. package/dist/cli/server/intent-detection.d.ts +2 -0
  11. package/dist/cli/server/utils.d.ts +0 -12
  12. package/dist/cli/types/types.d.ts +2 -1
  13. package/dist/components/ChatPanel.d.ts +2 -1
  14. package/dist/components/Conversation.d.ts +2 -1
  15. package/dist/components/ModelSwitcher.d.ts +2 -1
  16. package/dist/hooks/useModelSwitcher.d.ts +7 -4
  17. package/dist/hooks/useResolvedDefaultModel.d.ts +21 -0
  18. package/dist/hooks/useStreamingAI.d.ts +3 -2
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.esm.js +425 -39
  21. package/dist/index.js +425 -38
  22. package/dist/server/components/ChatPanel.d.ts +2 -1
  23. package/dist/server/components/Conversation.d.ts +2 -1
  24. package/dist/server/components/ModelSwitcher.d.ts +2 -1
  25. package/dist/server/contextual-service.d.ts +49 -1
  26. package/dist/server/hooks/useModelSwitcher.d.ts +7 -4
  27. package/dist/server/hooks/useResolvedDefaultModel.d.ts +21 -0
  28. package/dist/server/hooks/useStreamingAI.d.ts +3 -2
  29. package/dist/server/index.esm.js +507 -151
  30. package/dist/server/index.js +473 -99
  31. package/dist/server/intent-detection.d.ts +2 -0
  32. package/dist/server/server/contextual-service.d.ts +49 -1
  33. package/dist/server/server/intent-detection.d.ts +2 -0
  34. package/dist/server/server/utils.d.ts +0 -12
  35. package/dist/server/types/types.d.ts +2 -1
  36. package/dist/server/utils.d.ts +0 -12
  37. package/dist/types/types.d.ts +2 -1
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@ A powerful AI-powered command interface for web applications that provides conte
6
6
 
7
7
  ### **Latest AI Model Support**
8
8
  - **OpenAI**: GPT-4 Turbo, GPT-4o, GPT-4o Mini (all with image support)
9
- - **Claude**: Opus 4, Sonnet 4, Haiku 3.5 (latest 2025 models)
9
+ - **Claude**: Opus 4, Sonnet 4.5, Haiku 4.5 (latest 2025 models)
10
10
  - **Gemini**: 2.5 Pro, 2.5 Flash, 2.5 Flash Lite (newest generation)
11
11
 
12
12
  ### **Provider-Specific Training Data Optimization**
@@ -154,8 +154,8 @@ export const clientConfig = {
154
154
  { id: 'gpt-4o-mini', name: 'GPT-4o Mini', supportsImages: true, computeWeight: 0.3 },
155
155
  ],
156
156
  claude: [
157
- { id: 'claude-sonnet-4-20250514', name: 'Claude Sonnet 4', supportsImages: true, computeWeight: 0.6 },
158
- { id: 'claude-3-5-haiku-20241022', name: 'Claude Haiku 3.5', supportsImages: true, computeWeight: 0.2 },
157
+ { id: 'claude-sonnet-4-5-20250929', name: 'Claude Sonnet 4.5', supportsImages: true, computeWeight: 0.6 },
158
+ { id: 'claude-haiku-4-5-20251001', name: 'Claude Haiku 4.5', supportsImages: true, computeWeight: 0.2 },
159
159
  ],
160
160
  gemini: [
161
161
  { id: 'gemini-2.5-flash', name: 'Gemini 2.5 Flash', supportsImages: true, computeWeight: 0.5 },
@@ -20,7 +20,8 @@ interface ChatPanelProps {
20
20
  models?: Record<string, ModelInfo[]>;
21
21
  defaultModel?: {
22
22
  provider: string;
23
- model: string;
23
+ model?: string;
24
+ tier?: 'fast' | 'balanced' | 'powerful';
24
25
  };
25
26
  showUsageStats?: boolean;
26
27
  maxFileSize?: string;
@@ -27,7 +27,8 @@ interface ConversationProps {
27
27
  models?: Record<string, ModelInfo[]>;
28
28
  defaultModel?: {
29
29
  provider: string;
30
- model: string;
30
+ model?: string;
31
+ tier?: 'fast' | 'balanced' | 'powerful';
31
32
  };
32
33
  showUsageStats?: boolean;
33
34
  maxFileSize?: string;
@@ -4,7 +4,8 @@ interface ModelSwitcherProps {
4
4
  models?: Record<string, ModelInfo[]>;
5
5
  defaultModel?: {
6
6
  provider: string;
7
- model: string;
7
+ model?: string;
8
+ tier?: 'fast' | 'balanced' | 'powerful';
8
9
  };
9
10
  showUsageStats?: boolean;
10
11
  theme?: ChatTheme;
@@ -1,4 +1,4 @@
1
- import { ModelInfo } from '../types/types';
1
+ import { ModelInfo, ServerConfig } from '../types/types';
2
2
  interface CurrentModel {
3
3
  provider: string;
4
4
  model: string;
@@ -25,16 +25,19 @@ interface UsageStats {
25
25
  interface UseModelSwitcherOptions {
26
26
  initialProvider?: string;
27
27
  initialModel?: string;
28
+ initialTier?: 'fast' | 'balanced' | 'powerful';
28
29
  customModels?: Record<string, ModelInfo[]>;
30
+ serverConfig?: ServerConfig;
29
31
  }
30
- export declare function useModelSwitcher({ initialProvider, initialModel, customModels, }?: UseModelSwitcherOptions): {
32
+ export declare function useModelSwitcher({ initialProvider, initialModel, initialTier, // Can be undefined - don't default here, let Conversation handle it
33
+ customModels, serverConfig, }?: UseModelSwitcherOptions): {
31
34
  models: ModelInfo[];
32
35
  modelsByProvider: Record<string, ModelInfo[]>;
33
36
  currentModel: CurrentModel;
34
37
  currentCapabilities: ModelCapabilities;
35
38
  usageStats: UsageStats;
36
39
  isLoading: boolean;
37
- error: null;
40
+ error: string | null;
38
41
  switchModel: (model: string, provider?: string) => {
39
42
  success: boolean;
40
43
  current: {
@@ -48,7 +51,7 @@ export declare function useModelSwitcher({ initialProvider, initialModel, custom
48
51
  provider: string;
49
52
  model: string;
50
53
  capabilities: ModelCapabilities;
51
- };
54
+ } | null;
52
55
  modelState: {
53
56
  models: ModelInfo[];
54
57
  current: CurrentModel;
@@ -0,0 +1,21 @@
1
+ import type { ModelCapabilities } from '../types/types';
2
+ /**
3
+ * Hook to resolve tier-based default model config to actual model
4
+ *
5
+ * This hook takes a default model configuration that may include a tier
6
+ * (like 'fast', 'balanced', 'powerful') and resolves it to an actual model
7
+ * by fetching the available models from the server and selecting the best
8
+ * match for the provider and tier combination.
9
+ *
10
+ * @param defaultModel - The model configuration to resolve
11
+ * @returns The resolved model with provider, model name, and capabilities
12
+ */
13
+ export declare function useResolvedDefaultModel(defaultModel?: {
14
+ provider: string;
15
+ model?: string;
16
+ tier?: 'fast' | 'balanced' | 'powerful';
17
+ }): {
18
+ provider: string;
19
+ model: string;
20
+ capabilities: ModelCapabilities;
21
+ } | undefined;
@@ -1,8 +1,9 @@
1
1
  import { ChatMessage, ModelCapabilities, ServerConfig } from '../types/types';
2
2
  interface ModelSelection {
3
3
  provider: string;
4
- model: string;
5
- capabilities: ModelCapabilities;
4
+ model?: string;
5
+ tier?: 'fast' | 'balanced' | 'powerful';
6
+ capabilities?: ModelCapabilities;
6
7
  }
7
8
  export declare function useStreamingAI({ userId, serverConfig, formData, chats: externalChats, setChats: externalSetChats, currentChatId: externalCurrentChatId, setCurrentChatId: externalSetCurrentChatId, modelSelection, onUsageTracked, chatLevel, additionalContext, verbose, }: {
8
9
  userId: string;
@@ -1,5 +1,6 @@
1
1
  export { useStreamingAI } from './hooks/useStreamingAI';
2
2
  export { useSuggestions, useDebouncedSuggestions, } from './hooks/useSuggestions';
3
+ export { useResolvedDefaultModel } from './hooks/useResolvedDefaultModel';
3
4
  export { ChatPanel } from './components/ChatPanel';
4
5
  export { Conversation } from './components/Conversation';
5
6
  export { SuggestionsPanel, SuggestionCard, } from './components/SuggestionsPanel';
@@ -1,9 +1,20 @@
1
1
  import type { ContextualServiceConfig, ContextualRequest } from '../types/types.js';
2
2
  export declare class ContextualCommandService {
3
3
  private config;
4
+ private modelsCache;
5
+ private cacheFilePath;
6
+ private readonly CACHE_TTL_MS;
4
7
  private verboseLogging;
5
8
  private usage;
6
9
  constructor(config: ContextualServiceConfig);
10
+ /**
11
+ * Load models cache from file if it exists and is fresh
12
+ */
13
+ private loadModelsCache;
14
+ /**
15
+ * Save models cache to file
16
+ */
17
+ private saveModelsCache;
7
18
  private autoConfigureProviders;
8
19
  private log;
9
20
  private handleError;
@@ -30,14 +41,51 @@ export declare class ContextualCommandService {
30
41
  */
31
42
  getSuggestions(request: ContextualRequest): Promise<any[]>;
32
43
  /**
33
- * Get available models
44
+ * Static utility to read cached models from file (for use in other services)
45
+ */
46
+ static getCachedModelsSync(): Array<{
47
+ id: string;
48
+ name: string;
49
+ provider: string;
50
+ available: boolean;
51
+ computeWeight?: number;
52
+ supportsImages?: boolean;
53
+ }>;
54
+ /**
55
+ * Static utility to get the fastest model for a provider from cache
56
+ */
57
+ static getFastestModelSync(provider: string): string | null;
58
+ /**
59
+ * Get available models from API or use cached/defaults
60
+ * Uses file-based cache that refreshes every 24 hours
34
61
  */
35
62
  getAvailableModels(): Promise<{
36
63
  id: string;
37
64
  name: string;
38
65
  provider: string;
39
66
  available: boolean;
67
+ computeWeight?: number;
68
+ supportsImages?: boolean;
40
69
  }[]>;
70
+ /**
71
+ * Get the latest default model for a provider (balanced tier, or fallback to hardcoded)
72
+ * This should be used instead of DEFAULT_CONFIG.model when possible
73
+ */
74
+ getLatestDefaultModel(provider?: string): Promise<string>;
75
+ /**
76
+ * Get default models by tier for a provider
77
+ * @param provider - Provider name
78
+ * @param tier - 'fast' (lowest computeWeight = cheapest), 'balanced' (medium), or 'powerful' (highest = most expensive)
79
+ */
80
+ getDefaultModelByTier(provider: string, tier?: 'fast' | 'balanced' | 'powerful'): Promise<string | null>;
81
+ /**
82
+ * Get latest models from each tier for all configured providers
83
+ */
84
+ getLatestModelsByTier(): Promise<Record<string, {
85
+ fast: string;
86
+ balanced: string;
87
+ powerful: string;
88
+ }>>;
41
89
  /**
42
90
  * Get usage statistics
43
91
  */
@@ -90,10 +90,12 @@ export declare class IntentDetectionPlugin {
90
90
  constructor(config: IntentDetectionConfig);
91
91
  /**
92
92
  * Resolve model name with dynamic discovery support
93
+ * Uses cached models when available, falls back to defaults
93
94
  */
94
95
  private resolveModelName;
95
96
  /**
96
97
  * Dynamically discover and select the best model for the provider
98
+ * Uses cached models when available
97
99
  */
98
100
  private discoverBestModel;
99
101
  private createModelInstance;
@@ -14,18 +14,6 @@ export declare function getDefaultModelsForProvider(provider: string): {
14
14
  provider: string;
15
15
  available: boolean;
16
16
  supportsImages: boolean;
17
- }[] | {
18
- id: string;
19
- name: string;
20
- provider: string;
21
- available: boolean;
22
- supportsImages: boolean;
23
- }[] | {
24
- id: string;
25
- name: string;
26
- provider: string;
27
- available: boolean;
28
- supportsImages: boolean;
29
17
  }[];
30
18
  /**
31
19
  * Enhanced context analysis for better AI suggestions
@@ -494,7 +494,8 @@ export interface ContextualRequest {
494
494
  }>;
495
495
  modelSelection?: {
496
496
  provider: string;
497
- model: string;
497
+ model?: string;
498
+ tier?: 'fast' | 'balanced' | 'powerful';
498
499
  };
499
500
  chatLevel?: 'full' | 'basic' | 'none';
500
501
  additionalContext?: string;
@@ -20,7 +20,8 @@ interface ChatPanelProps {
20
20
  models?: Record<string, ModelInfo[]>;
21
21
  defaultModel?: {
22
22
  provider: string;
23
- model: string;
23
+ model?: string;
24
+ tier?: 'fast' | 'balanced' | 'powerful';
24
25
  };
25
26
  showUsageStats?: boolean;
26
27
  maxFileSize?: string;
@@ -27,7 +27,8 @@ interface ConversationProps {
27
27
  models?: Record<string, ModelInfo[]>;
28
28
  defaultModel?: {
29
29
  provider: string;
30
- model: string;
30
+ model?: string;
31
+ tier?: 'fast' | 'balanced' | 'powerful';
31
32
  };
32
33
  showUsageStats?: boolean;
33
34
  maxFileSize?: string;
@@ -4,7 +4,8 @@ interface ModelSwitcherProps {
4
4
  models?: Record<string, ModelInfo[]>;
5
5
  defaultModel?: {
6
6
  provider: string;
7
- model: string;
7
+ model?: string;
8
+ tier?: 'fast' | 'balanced' | 'powerful';
8
9
  };
9
10
  showUsageStats?: boolean;
10
11
  theme?: ChatTheme;
@@ -1,4 +1,4 @@
1
- import { ModelInfo } from '../types/types';
1
+ import { ModelInfo, ServerConfig } from '../types/types';
2
2
  interface CurrentModel {
3
3
  provider: string;
4
4
  model: string;
@@ -25,16 +25,19 @@ interface UsageStats {
25
25
  interface UseModelSwitcherOptions {
26
26
  initialProvider?: string;
27
27
  initialModel?: string;
28
+ initialTier?: 'fast' | 'balanced' | 'powerful';
28
29
  customModels?: Record<string, ModelInfo[]>;
30
+ serverConfig?: ServerConfig;
29
31
  }
30
- export declare function useModelSwitcher({ initialProvider, initialModel, customModels, }?: UseModelSwitcherOptions): {
32
+ export declare function useModelSwitcher({ initialProvider, initialModel, initialTier, // Can be undefined - don't default here, let Conversation handle it
33
+ customModels, serverConfig, }?: UseModelSwitcherOptions): {
31
34
  models: ModelInfo[];
32
35
  modelsByProvider: Record<string, ModelInfo[]>;
33
36
  currentModel: CurrentModel;
34
37
  currentCapabilities: ModelCapabilities;
35
38
  usageStats: UsageStats;
36
39
  isLoading: boolean;
37
- error: null;
40
+ error: string | null;
38
41
  switchModel: (model: string, provider?: string) => {
39
42
  success: boolean;
40
43
  current: {
@@ -48,7 +51,7 @@ export declare function useModelSwitcher({ initialProvider, initialModel, custom
48
51
  provider: string;
49
52
  model: string;
50
53
  capabilities: ModelCapabilities;
51
- };
54
+ } | null;
52
55
  modelState: {
53
56
  models: ModelInfo[];
54
57
  current: CurrentModel;
@@ -0,0 +1,21 @@
1
+ import type { ModelCapabilities } from '../types/types';
2
+ /**
3
+ * Hook to resolve tier-based default model config to actual model
4
+ *
5
+ * This hook takes a default model configuration that may include a tier
6
+ * (like 'fast', 'balanced', 'powerful') and resolves it to an actual model
7
+ * by fetching the available models from the server and selecting the best
8
+ * match for the provider and tier combination.
9
+ *
10
+ * @param defaultModel - The model configuration to resolve
11
+ * @returns The resolved model with provider, model name, and capabilities
12
+ */
13
+ export declare function useResolvedDefaultModel(defaultModel?: {
14
+ provider: string;
15
+ model?: string;
16
+ tier?: 'fast' | 'balanced' | 'powerful';
17
+ }): {
18
+ provider: string;
19
+ model: string;
20
+ capabilities: ModelCapabilities;
21
+ } | undefined;
@@ -1,8 +1,9 @@
1
1
  import { ChatMessage, ModelCapabilities, ServerConfig } from '../types/types';
2
2
  interface ModelSelection {
3
3
  provider: string;
4
- model: string;
5
- capabilities: ModelCapabilities;
4
+ model?: string;
5
+ tier?: 'fast' | 'balanced' | 'powerful';
6
+ capabilities?: ModelCapabilities;
6
7
  }
7
8
  export declare function useStreamingAI({ userId, serverConfig, formData, chats: externalChats, setChats: externalSetChats, currentChatId: externalCurrentChatId, setCurrentChatId: externalSetCurrentChatId, modelSelection, onUsageTracked, chatLevel, additionalContext, verbose, }: {
8
9
  userId: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { useStreamingAI } from './hooks/useStreamingAI';
2
2
  export { useSuggestions, useDebouncedSuggestions, } from './hooks/useSuggestions';
3
+ export { useResolvedDefaultModel } from './hooks/useResolvedDefaultModel';
3
4
  export { ChatPanel } from './components/ChatPanel';
4
5
  export { Conversation } from './components/Conversation';
5
6
  export { SuggestionsPanel, SuggestionCard, } from './components/SuggestionsPanel';