mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
- Introduce MapStore
to manage map state and controls using MobX-State-Tree.
- Integrate `MapStore` into `ClientChatStore`. - Add support for handling map control tool responses in `StreamStore`. - Update `InputMenu` with loading state while fetching models and UI improvements. - Include `useLayoutEffect` in `LandingComponent` for persistent state management. - Enhance `ChatService` with debug logs, model fallback handling, and better error reporting.
This commit is contained in:
@@ -24,10 +24,68 @@ export class ProviderRepository {
|
||||
};
|
||||
|
||||
static async getModelFamily(model: any, env: GenericEnv) {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Looking up model "${model}"`);
|
||||
|
||||
const allModels = await env.KV_STORAGE.get('supportedModels');
|
||||
const models = JSON.parse(allModels);
|
||||
const modelData = models.filter((m: ModelMeta) => m.id === model);
|
||||
return modelData[0].provider;
|
||||
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Found ${models.length} total models in KV storage`);
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.getModelFamily: Available model IDs:', models.map((m: ModelMeta) => m.id));
|
||||
|
||||
// First try exact match
|
||||
let modelData = models.filter((m: ModelMeta) => m.id === model);
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Exact match attempt for "${model}" found ${modelData.length} results`);
|
||||
|
||||
// If no exact match, try to find by partial match (handle provider prefixes)
|
||||
if (modelData.length === 0) {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Trying partial match for "${model}"`);
|
||||
modelData = models.filter((m: ModelMeta) => {
|
||||
// Check if the model ID ends with the requested model name
|
||||
// This handles cases like "accounts/fireworks/models/mixtral-8x22b-instruct" matching "mixtral-8x22b-instruct"
|
||||
const endsWithMatch = m.id.endsWith(model);
|
||||
const modelEndsWithStoredBase = model.endsWith(m.id.split('/').pop() || '');
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Checking "${m.id}" - endsWith: ${endsWithMatch}, modelEndsWithBase: ${modelEndsWithStoredBase}`);
|
||||
return endsWithMatch || modelEndsWithStoredBase;
|
||||
});
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Partial match found ${modelData.length} results`);
|
||||
}
|
||||
|
||||
// If still no match, try to find by the base model name (last part after /)
|
||||
if (modelData.length === 0) {
|
||||
const baseModelName = model.split('/').pop();
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Trying base name match for "${baseModelName}"`);
|
||||
modelData = models.filter((m: ModelMeta) => {
|
||||
const baseStoredName = m.id.split('/').pop();
|
||||
const matches = baseStoredName === baseModelName;
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Comparing base names "${baseStoredName}" === "${baseModelName}": ${matches}`);
|
||||
return matches;
|
||||
});
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Base name match found ${modelData.length} results`);
|
||||
}
|
||||
|
||||
const selectedProvider = modelData[0]?.provider;
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: Final result for "${model}" -> provider: "${selectedProvider}"`);
|
||||
|
||||
if (modelData.length > 0) {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.getModelFamily: Selected model data:', modelData[0]);
|
||||
} else {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.getModelFamily: No matching model found for "${model}"`);
|
||||
}
|
||||
|
||||
return selectedProvider;
|
||||
}
|
||||
|
||||
static async getModelMeta(meta: any, env: GenericEnv) {
|
||||
@@ -41,12 +99,19 @@ export class ProviderRepository {
|
||||
}
|
||||
|
||||
setProviders(env: GenericEnv) {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.setProviders: Starting provider detection');
|
||||
|
||||
const indicies = {
|
||||
providerName: 0,
|
||||
providerValue: 1,
|
||||
};
|
||||
const valueDelimiter = '_';
|
||||
const envKeys = Object.keys(env);
|
||||
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.setProviders: Environment keys ending with KEY:', envKeys.filter(key => key.endsWith('KEY')));
|
||||
|
||||
for (let i = 0; i < envKeys.length; i++) {
|
||||
if (envKeys.at(i)?.endsWith('KEY')) {
|
||||
const detectedProvider = envKeys
|
||||
@@ -55,9 +120,15 @@ export class ProviderRepository {
|
||||
.at(indicies.providerName)
|
||||
?.toLowerCase();
|
||||
const detectedProviderValue = env[envKeys.at(i) as string];
|
||||
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.setProviders: Processing ${envKeys[i]} -> detected provider: "${detectedProvider}", has value: ${!!detectedProviderValue}`);
|
||||
|
||||
if (detectedProviderValue) {
|
||||
switch (detectedProvider) {
|
||||
case 'anthropic':
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.setProviders: Adding Claude provider (anthropic)');
|
||||
this.#providers.push({
|
||||
name: 'claude',
|
||||
key: env.ANTHROPIC_API_KEY,
|
||||
@@ -65,6 +136,8 @@ export class ProviderRepository {
|
||||
});
|
||||
break;
|
||||
case 'gemini':
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.setProviders: Adding Google provider (gemini)');
|
||||
this.#providers.push({
|
||||
name: 'google',
|
||||
key: env.GEMINI_API_KEY,
|
||||
@@ -72,6 +145,8 @@ export class ProviderRepository {
|
||||
});
|
||||
break;
|
||||
case 'cloudflare':
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log('[DEBUG_LOG] ProviderRepository.setProviders: Adding Cloudflare provider');
|
||||
this.#providers.push({
|
||||
name: 'cloudflare',
|
||||
key: env.CLOUDFLARE_API_KEY,
|
||||
@@ -82,6 +157,8 @@ export class ProviderRepository {
|
||||
});
|
||||
break;
|
||||
default:
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.setProviders: Adding default provider "${detectedProvider}"`);
|
||||
this.#providers.push({
|
||||
name: detectedProvider as SupportedProvider,
|
||||
key: env[envKeys[i] as string],
|
||||
@@ -89,8 +166,14 @@ export class ProviderRepository {
|
||||
ProviderRepository.OPENAI_COMPAT_ENDPOINTS[detectedProvider as SupportedProvider],
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.setProviders: Skipping ${envKeys[i]} - no value provided`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
console.log(`[DEBUG_LOG] ProviderRepository.setProviders: Final configured providers (${this.#providers.length}):`, this.#providers.map(p => ({ name: p.name, endpoint: p.endpoint, hasKey: !!p.key })));
|
||||
}
|
||||
}
|
||||
|
@@ -236,7 +236,7 @@ export abstract class BaseChatProvider implements ChatStreamProvider {
|
||||
|
||||
// Process chunk normally for non-tool-call responses
|
||||
if (!chunk.choices[0]?.delta?.tool_calls) {
|
||||
console.log('after-tool-call-chunk', chunk);
|
||||
// console.log('after-tool-call-chunk', chunk);
|
||||
const shouldBreak = await this.processChunk(chunk, dataCallback);
|
||||
if (shouldBreak) {
|
||||
conversationComplete = true;
|
||||
|
@@ -18,7 +18,7 @@ export class FireworksAiChatProvider extends BaseChatProvider {
|
||||
}
|
||||
|
||||
return {
|
||||
model: `${modelPrefix}${param.model}`,
|
||||
model: `${param.model}`,
|
||||
messages: safeMessages,
|
||||
stream: true,
|
||||
};
|
||||
|
@@ -9,14 +9,14 @@ export interface MapsControlResult {
|
||||
*/
|
||||
export const MapsTools = {
|
||||
type: 'function',
|
||||
description:
|
||||
'Interface for controlling a web-rendered map to explore publicly available geospatial data',
|
||||
|
||||
/**
|
||||
* Mock implementation of a maps control command.
|
||||
*/
|
||||
function: {
|
||||
name: 'maps_control',
|
||||
description:
|
||||
'Interface for controlling a web-rendered map to explore publicly available geospatial data',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
Reference in New Issue
Block a user