fix(agent): handle non-builtin models in getModelFromDb and upgrade pi-ai

This commit is contained in:
yiling
2026-07-22 16:09:36 +08:00
parent fbf963fe43
commit e9959bcc68
4 changed files with 70 additions and 30 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest'
import { formatSkillsForPrompt, createAgentSession } from './index'
import { formatSkillsForPrompt, createAgentSession, getModelFromDb, type DbProviderInfo } from './index'
import { createSandboxedBashTool } from './tools/sandboxed-bash'
import { SandboxManager, type SandboxAskCallback } from '@anthropic-ai/sandbox-runtime'
import { prisma } from '@shumai/db'
@@ -374,3 +374,35 @@ describe('Sandbox Network isolation integration', () => {
}
})
})
describe('getModelFromDb', () => {
it('should correctly initialize non-built-in model with provider and id', () => {
const providers: DbProviderInfo[] = [
{
name: 'google',
config: { api: 'google-generative-ai', apiKey: 'GOOGLE_API_KEY' },
models: [
{
modelId: 'non-existent-or-future-model',
name: 'Future Model',
config: {
api: 'google-generative-ai',
reasoning: false,
input: ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 8192,
maxTokens: 4096,
},
},
],
},
]
const model = getModelFromDb(providers, 'google', 'non-existent-or-future-model')
expect(model).toBeDefined()
expect(model?.id).toBe('non-existent-or-future-model')
expect(model?.provider).toBe('google')
expect(model?.api).toBe('google-generative-ai')
})
})