Skip to content
Merged
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
2 changes: 2 additions & 0 deletions examples/coze-js-web/src/pages/chat-x/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const config = {
getBaseUrl: () =>
localStorage.getItem('chat-x_base_url') || 'https://api.coze.cn',
getBaseWsUrl: () =>
localStorage.getItem('chat-x_base_ws_url') || 'wss://ws.coze.cn',
getPat: () => localStorage.getItem('chat-x_pat') || '',
getBotId: () => localStorage.getItem('chat-x_bot_id') || '',
};
9 changes: 9 additions & 0 deletions examples/coze-js-web/src/pages/chat-x/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const Settings = ({ onSettingsChange }: { onSettingsChange: () => void }) => {
const baseUrl = config.getBaseUrl();
const pat = config.getPat();
const botId = config.getBotId();
const baseWsUrl = config.getBaseWsUrl();

form.setFieldsValue({
base_url: baseUrl,
base_ws_url: baseWsUrl,
pat,
bot_id: botId,
});
Expand Down Expand Up @@ -54,6 +56,13 @@ const Settings = ({ onSettingsChange }: { onSettingsChange: () => void }) => {
>
<Input />
</Form.Item>
<Form.Item
name="base_ws_url"
label="Base WS URL"
rules={[{ required: true, message: 'Please input Base WS URL!' }]}
>
<Input />
</Form.Item>
<Form.Item
name="pat"
label="PAT"
Expand Down
3 changes: 1 addition & 2 deletions examples/coze-js-web/src/pages/chat-x/use-coze-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useCallback, useRef, useState } from 'react';
import {
type BotInfo,
ChatEventType,
COZE_CN_BASE_WS_URL,
CozeAPI,
type CreateChatData,
type EnterMessage,
Expand All @@ -27,7 +26,7 @@ const useCozeAPI = () => {
token: pat,
baseURL: baseUrl,
allowPersonalAccessTokenInBrowser: true,
baseWsURL: COZE_CN_BASE_WS_URL,
baseWsURL: config.getBaseWsUrl(),
debug: false,
});
};
Expand Down
5 changes: 2 additions & 3 deletions examples/coze-js-web/src/pages/chat-x/use-ws-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { type MutableRefObject, useCallback, useEffect, useRef } from 'react';

import { WsSpeechClient, WsTranscriptionClient } from '@coze/api/ws-tools';
import {
COZE_CN_BASE_WS_URL,
type CozeAPI,
type CreateChatData,
type CreateChatWsReq,
Expand Down Expand Up @@ -211,7 +210,7 @@ const useWsAPI = (
const startTranscriptions = useCallback(async () => {
const transcriptionClient = new WsTranscriptionClient({
token: config.getPat(),
baseWsURL: COZE_CN_BASE_WS_URL,
baseWsURL: config.getBaseWsUrl(),
allowPersonalAccessTokenInBrowser: true,
});

Expand Down Expand Up @@ -309,7 +308,7 @@ const useWsAPI = (

const client = new WsSpeechClient({
token: config.getPat(),
baseWsURL: COZE_CN_BASE_WS_URL,
baseWsURL: config.getBaseWsUrl(),
allowPersonalAccessTokenInBrowser: true,
});

Expand Down