Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"remark-gfm": "^4.0.1",
"tailwind-merge": "^3.3.1",
"tailwindcss-animate": "^1.0.7",
"tinfoil": "^1.1.4",
"uuid": "^13.0.0",
"web-haptics": "^0.0.6",
"zod": "^4.0.17",
Expand Down
25 changes: 25 additions & 0 deletions src/ai/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createAnthropic } from '@ai-sdk/anthropic'
import { createOpenAI } from '@ai-sdk/openai'
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import type { HttpClient } from '@/lib/http'
import { SecureClient } from 'tinfoil'
import { v7 as uuidv7 } from 'uuid'

// Currently @openrouter/ai-sdk-provider is NOT compatible with Vercel AI SDK v5. If you enable this, you will get the following error:
Expand Down Expand Up @@ -49,6 +50,17 @@ export const ollama = createOpenAI({
fetch,
})

// Reuse one SecureClient across requests so attestation runs once per page load.
let tinfoilClient: SecureClient | null = null

export const getTinfoilClient = async (): Promise<SecureClient> => {
if (!tinfoilClient) {
tinfoilClient = new SecureClient()
}
await tinfoilClient.ready()
return tinfoilClient
}

type AiFetchStreamingResponseOptions = {
init: RequestInit
saveMessages: SaveMessagesFunction
Expand Down Expand Up @@ -124,6 +136,19 @@ export const createModel = async (modelConfig: Model) => {
})
return openrouter(modelConfig.model)
}
case 'tinfoil': {
if (!modelConfig.apiKey) {
throw new Error('No API key provided')
}
const client = await getTinfoilClient()
const tinfoil = createOpenAICompatible({
name: 'tinfoil',
baseURL: client.getBaseURL()!,
apiKey: modelConfig.apiKey,
fetch: client.fetch,
})
return tinfoil(modelConfig.model)
}
default:
throw new Error(`Unsupported provider: ${modelConfig.provider}`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/db/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const modelsTable = sqliteTable(
{
id: text('id').primaryKey(),
provider: text('provider', {
enum: ['openai', 'custom', 'openrouter', 'thunderbolt', 'anthropic'],
enum: ['openai', 'custom', 'openrouter', 'thunderbolt', 'anthropic', 'tinfoil'],
}),
name: text('name'),
model: text('model'),
Expand Down
2 changes: 1 addition & 1 deletion src/settings/models/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Trash2 } from 'lucide-react'

const formSchema = z
.object({
provider: z.enum(['thunderbolt', 'anthropic', 'openai', 'custom', 'openrouter']),
provider: z.enum(['thunderbolt', 'anthropic', 'openai', 'custom', 'openrouter', 'tinfoil']),
name: z.string().min(1, { message: 'Name is required.' }),
model: z.string().min(1, { message: 'Model name is required.' }),
url: z.string().optional(),
Expand Down
33 changes: 27 additions & 6 deletions src/settings/models/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createModel } from '@/ai/fetch'
import { createModel, getTinfoilClient } from '@/ai/fetch'
import { ModificationIndicator } from '@/components/modification-indicator'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
Expand Down Expand Up @@ -147,7 +147,7 @@ const modelReducer = (state: ModelState, action: ModelAction): ModelState => {

const formSchema = z
.object({
provider: z.enum(['thunderbolt', 'anthropic', 'openai', 'custom', 'openrouter']),
provider: z.enum(['thunderbolt', 'anthropic', 'openai', 'custom', 'openrouter', 'tinfoil']),
name: z.string().min(1, { message: 'Name is required.' }),
model: z.string().min(1, { message: 'Model name is required.' }),
customModel: z.string().optional(),
Expand Down Expand Up @@ -403,6 +403,24 @@ export default function ModelsPage() {
endpoint = 'https://openrouter.ai/api/v1/models'
headers = { Authorization: `Bearer ${apiKey}` }
break
case 'tinfoil': {
// /v1/models is unauthenticated, but route through SecureClient so
// attestation is warmed up before the user's first chat.
const client = await getTinfoilClient()
const response = await http.get(`${client.getBaseURL()}models`, { fetch: client.fetch }).json<{
Comment thread
cjroth marked this conversation as resolved.
data: Array<AvailableModel & { endpoints?: string[]; tool_calling?: boolean }>
}>()

// The catalog also includes embedding, audio, document, and tts
// models; filter to ones that expose chat completions.
const tinfoilModels = (response.data || [])
.filter((m) => Array.isArray(m.endpoints) && m.endpoints.includes('/v1/chat/completions'))
.map((m) => ({ ...m, supports_tools: m.tool_calling === true }))
.sort((a, b) => a.id.localeCompare(b.id))

dispatch({ type: 'FETCH_MODELS_SUCCESS', models: tinfoilModels })
return
}
case 'thunderbolt': {
const thunderboltModels = [
{ id: 'kimi-k2-instruct', name: 'Kimi K2', supports_tools: true },
Expand Down Expand Up @@ -603,7 +621,7 @@ export default function ModelsPage() {
form.setValue('toolUsage', true, { shouldValidate: false, shouldDirty: false })

// Fetch models if we have the necessary credentials
if (['thunderbolt', 'anthropic'].includes(currentProvider)) {
if (['thunderbolt', 'tinfoil', 'anthropic'].includes(currentProvider)) {
fetchAvailableModels(currentProvider)
}

Expand Down Expand Up @@ -633,6 +651,8 @@ export default function ModelsPage() {
switch (provider) {
case 'thunderbolt':
return 'Thunderbolt'
case 'tinfoil':
return 'Tinfoil'
case 'anthropic':
return 'Anthropic'
case 'openai':
Expand Down Expand Up @@ -678,7 +698,7 @@ export default function ModelsPage() {
const watchedModel = form.watch('model')

const canTestConnection = useMemo(() => {
if (watchedProvider === 'anthropic') {
if (['anthropic', 'tinfoil'].includes(watchedProvider)) {
return !!watchedModel && watchedApiKey
}

Expand Down Expand Up @@ -714,6 +734,7 @@ export default function ModelsPage() {
</SelectTrigger>
<SelectContent>
<SelectItem value="thunderbolt">Thunderbolt</SelectItem>
<SelectItem value="tinfoil">Tinfoil</SelectItem>
<SelectItem value="openai">OpenAI</SelectItem>
<SelectItem value="openrouter">OpenRouter</SelectItem>
<SelectItem value="anthropic">Anthropic</SelectItem>
Expand Down Expand Up @@ -778,13 +799,13 @@ export default function ModelsPage() {
const url = form.watch('url')

// Show model selection if:
// 1. Thunderbolt (no API key needed)
// 1. Thunderbolt / Tinfoil (no API key needed)
// 1. Anthropic (API key required for testing - model list is hardwired)
// 2. Other providers with API key
// 3. OpenAI Compatible with URL (API key optional)
const showModelSelection =
!modelLoadError &&
(['thunderbolt', 'anthropic'].includes(provider) ||
(['thunderbolt', 'tinfoil', 'anthropic'].includes(provider) ||
(provider && apiKey) ||
(provider === 'custom' && url))

Expand Down
1 change: 1 addition & 0 deletions src/settings/models/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function ModelsLayout() {
<SelectItem key={model.id} value={model.id}>
<p className="text-left">
{model.provider === 'thunderbolt' && 'Thunderbolt'}
{model.provider === 'tinfoil' && 'Tinfoil'}
{model.provider === 'openai' && 'OpenAI'}
{model.provider === 'openrouter' && 'OpenRouter'}
{model.provider === 'custom' && 'Custom'} - {model.model}
Expand Down
3 changes: 2 additions & 1 deletion src/settings/models/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { Model } from '@/types'

const formSchema = z
.object({
provider: z.enum(['thunderbolt', 'openai', 'custom', 'openrouter']),
provider: z.enum(['thunderbolt', 'openai', 'custom', 'openrouter', 'tinfoil']),
name: z.string().min(1, { message: 'Name is required.' }),
model: z.string().min(1, { message: 'Model name is required.' }),
url: z.string().optional(),
Expand Down Expand Up @@ -117,6 +117,7 @@ export default function NewModelPage() {
</SelectTrigger>
<SelectContent>
<SelectItem value="thunderbolt">Thunderbolt</SelectItem>
<SelectItem value="tinfoil">Tinfoil</SelectItem>
<SelectItem value="openai">OpenAI</SelectItem>
<SelectItem value="openrouter">OpenRouter</SelectItem>
<SelectItem value="custom">Custom</SelectItem>
Expand Down