Skip to content

Commit 5cd1734

Browse files
author
huzijie.sea
committed
feat(cli): add native openai provider support
1 parent 2612626 commit 5cd1734

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@ai-sdk/azure": "^3.0.5",
6363
"@ai-sdk/deepseek": "^2.0.4",
6464
"@ai-sdk/google": "^3.0.4",
65+
"@ai-sdk/openai": "^3.0.26",
6566
"@ai-sdk/openai-compatible": "^2.0.4",
6667
"@inkjs/ui": "^2.0.0",
6768
"@modelcontextprotocol/sdk": "^1.17.4",

packages/cli/src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
export type ProviderType =
7+
| 'openai'
78
| 'openai-compatible'
89
| 'anthropic'
910
| 'gemini'

packages/cli/src/services/VercelAIChatService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createAnthropic } from '@ai-sdk/anthropic';
22
import { createAzure } from '@ai-sdk/azure';
33
import { createDeepSeek } from '@ai-sdk/deepseek';
44
import { createGoogleGenerativeAI } from '@ai-sdk/google';
5+
import { createOpenAI } from '@ai-sdk/openai';
56
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
67
import { generateText, jsonSchema, type LanguageModel, streamText } from 'ai';
78
import type { ChatCompletionMessageToolCall } from 'openai/resources/chat';
@@ -90,6 +91,15 @@ export class VercelAIChatService implements IChatService {
9091
const { provider, apiKey, baseUrl, model, customHeaders, providerId, apiVersion } = config;
9192

9293
switch (provider) {
94+
case 'openai': {
95+
const openai = createOpenAI({
96+
apiKey,
97+
baseURL: baseUrl || undefined,
98+
headers: customHeaders,
99+
});
100+
return openai(model);
101+
}
102+
93103
case 'anthropic': {
94104
const anthropic = createAnthropic({
95105
apiKey,

packages/cli/tests/unit/context/ContextAssembler.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import type { SessionEvent } from '../../../src/context/types.js';
88

99
// Helper: 创建基础事件字段
1010
const base = (
11-
type: string,
12-
sessionId = 'sess-1',
13-
timestamp = '2026-02-21T10:00:00.000Z'
11+
type: string,
12+
sessionId = 'sess-1',
13+
timestamp = '2026-02-21T10:00:00.000Z'
1414
): Omit<SessionEvent, 'type' | 'data'> => ({
15-
id: `evt-${Math.random().toString(36).slice(2, 8)}`,
16-
sessionId,
17-
timestamp,
18-
type: type as any,
19-
cwd: '/tmp/test',
20-
version: '1.0.0',
15+
id: `evt-${Math.random().toString(36).slice(2, 8)}`,
16+
sessionId,
17+
timestamp,
18+
cwd: '/tmp/test',
19+
version: '1.0.0',
2120
});
2221

2322
function sessionCreatedEvent(sessionId = 'sess-1', ts = '2026-02-21T10:00:00.000Z'): SessionEvent {

pnpm-lock.yaml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)