fix: pass dynamic provider_id from initData instead of hardcoding

- Add _providerId field to SessionHandle, extracted from initData.account.apiProvider
- Include provider_id in user message emit, assistant message fallback, and session.ready
- Revert getProviderId normalization (keep raw value from subprocess)
This commit is contained in:
DoSun 2026-05-08 18:59:00 +08:00
parent e258f58fd7
commit 02161dd2a6
2 changed files with 10 additions and 3 deletions

View File

@ -20,9 +20,7 @@ function getModels(initData: InitData | null): ModelInfo[] {
} }
function getProviderId(initData: InitData | null): string { function getProviderId(initData: InitData | null): string {
const p = initData?.account?.apiProvider return initData?.account?.apiProvider ?? 'anthropic'
if (!p || p === 'firstParty') return 'anthropic'
return p
} }
function getProviderName(initData: InitData | null): string { function getProviderName(initData: InitData | null): string {

View File

@ -117,6 +117,7 @@ export class SessionHandle {
private child: ChildProcess | null = null private child: ChildProcess | null = null
private _status: SessionState = 'starting' private _status: SessionState = 'starting'
private _model?: string private _model?: string
private _providerId?: string
private _permissionMode?: string private _permissionMode?: string
private _title?: string private _title?: string
private _costUsd = 0 private _costUsd = 0
@ -411,6 +412,9 @@ export class SessionHandle {
const first = (initData.models as Array<Record<string, string>>)[0] const first = (initData.models as Array<Record<string, string>>)[0]
this._model = first?.value ?? first?.name this._model = first?.value ?? first?.name
} }
if (initData.account?.apiProvider) {
this._providerId = initData.account.apiProvider
}
this._status = 'running' this._status = 'running'
this.lastActiveAt = Date.now() this.lastActiveAt = Date.now()
const resolve = this.initResolve const resolve = this.initResolve
@ -420,6 +424,7 @@ export class SessionHandle {
this.emitEvent('ready', { this.emitEvent('ready', {
status: 'running', status: 'running',
model: this._model, model: this._model,
provider_id: this._providerId,
}) })
this.opts.onInit?.(initData) this.opts.onInit?.(initData)
return return
@ -454,6 +459,9 @@ export class SessionHandle {
if (!msg.model && this._model) { if (!msg.model && this._model) {
msg = { ...msg, model: this._model } msg = { ...msg, model: this._model }
} }
if (!msg.provider_id && this._providerId) {
msg = { ...msg, provider_id: this._providerId }
}
this.emitEvent('message', msg) this.emitEvent('message', msg)
break break
} }
@ -606,6 +614,7 @@ export class SessionHandle {
content, content,
session_id: this.sessionId, session_id: this.sessionId,
model: this._model ?? '', model: this._model ?? '',
provider_id: this._providerId ?? '',
}) })
this.writeStdin(userMsg) this.writeStdin(userMsg)