Files
veridian/server/utils/providers/closedrouter.ts
T
zoeissleeping 8ccaa824dd feat: file upload retry, secure file tokens, UI polish
- Add HMAC-based file token auth for secure AI model file access
- Add file upload retry with exponential backoff (max 3 retries)
- File endpoint now requires session auth or signed token
- Support assistant role messages in chat input
- Optimistic UI for attachments on message send
- Verify topic ownership before allowing messages
- Switch web scraping to Firecrawl API
- Agent profile page layout fixes (proper flex overflow)
- Add quick switcher (Ctrl+K) to sidenav
- Clean up longcat.ts and stale comments
2026-06-06 00:16:39 -05:00

68 lines
2.0 KiB
TypeScript

import { createOpenAI } from '@ai-sdk/openai';
import { GatewayFetchError } from '~~/server/utils/ai-provider';
import { Err, Ok } from '~~/types/result';
import type { ProviderModule } from '.';
export default {
id: 'closedrouter',
baseUrl: 'https://router.queef.in/v1',
modelsEndpoint: '/models',
createGateway({ apiKey, baseURL }) {
if (apiKey === undefined) {
return Err(GatewayFetchError.NoProviderApiKey);
}
return Ok({
gateway: createOpenAI({
name: 'ClosedRouter',
apiKey,
baseURL
}),
streamTransformer: undefined,
textTransformer: undefined,
});
},
getAuthHeaders(apiKey) {
return apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
},
async fetchModels({ baseURL, apiKey }) {
const res = await fetch(`${baseURL}/models`, {
method: 'GET',
headers: { Authorization: `Bearer ${apiKey}` },
});
const data = await res.json();
if (!res.ok) {
throw createError({ statusCode: res.status, message: JSON.stringify(data) });
}
return data.data.map((model: any) => {
const capabilities = new Array<string>();
if (model.capabilities) {
if (model.capabilities.reasoning) {
capabilities.push('reasoning');
}
if (model.capabilities.tool_call) {
capabilities.push('tools');
}
}
return {
id: model.id,
name: model.name,
attributes: {
inputModalities: model.modalities?.input || ['text'],
outputModalities: model.modalities?.output || ['text'],
capabilities: capabilities,
contextWindow: model.context_window,
supported_parameters: [],
},
};
});
},
} satisfies ProviderModule;