项目文件夹

文件
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

64 行
1.8 KiB
TypeScript

import {
VoiceConversationResponseSchema,
VoiceUsageResponseSchema,
type VoiceConversationResponse,
type VoiceUsageResponse,
} from '@slopus/happy-wire';
import { AuthCredentials } from '@/auth/tokenStorage';
import { getServerUrl } from './serverConfig';
import { getHappyClientId } from './apiSocket';
import { config } from '@/config';
export type { VoiceConversationResponse, VoiceUsageResponse };
export async function fetchVoiceCredentials(
credentials: AuthCredentials,
sessionId: string
): Promise<VoiceConversationResponse> {
const serverUrl = getServerUrl();
const agentId = config.elevenLabsAgentId;
if (!agentId) {
throw new Error('Agent ID not configured');
}
const response = await fetch(`${serverUrl}/v1/voice/conversations`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${credentials.token}`,
'Content-Type': 'application/json',
'X-Happy-Client': getHappyClientId(),
},
body: JSON.stringify({
agentId
})
});
if (!response.ok) {
throw new Error(`Voice token request failed: ${response.status}`);
}
return VoiceConversationResponseSchema.parse(await response.json());
}
export async function fetchVoiceUsage(
credentials: AuthCredentials
): Promise<VoiceUsageResponse> {
const serverUrl = getServerUrl();
const response = await fetch(`${serverUrl}/v1/voice/usage`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${credentials.token}`,
'X-Happy-Client': getHappyClientId(),
},
});
if (!response.ok) {
throw new Error(`Voice usage request failed: ${response.status}`);
}
return VoiceUsageResponseSchema.parse(await response.json());
}