8323e6218c
Switch OpenAI-compatible streaming from chat.completions.stream()
to chat.completions.create({ stream: true }) and track finish_reason
from streamed chunks directly.
This avoids the SDK's final chat-completion reconstruction path,
which could throw in preview builds while processing agent streams.
Also keep function/class names and sourcemaps in production builds
to make preview stack traces easier to read.
This issue can randomly happen when using `google/gemma-4-31b-it` model via OpenRouter.
Original error stacktrace:
```
index-Bh7OJFcp.js:807 Error processing stream: kn: Cannot read properties of undefined (reading 'type')
at Bb.qJ (index-Bh7OJFcp.js:780:4436)Caused by: TypeError: Cannot read properties of undefined (reading 'type')
at _J (index-Bh7OJFcp.js:780:1713)
at index-Bh7OJFcp.js:780:416
at Array.map (<anonymous>)
at R6e (index-Bh7OJFcp.js:780:408)
at z6e (index-Bh7OJFcp.js:785:258)
at Bb.By (index-Bh7OJFcp.js:781:4928)
at Bb._createChatCompletion (index-Bh7OJFcp.js:781:1059)
at async Bb._runChatCompletion (index-Bh7OJFcp.js:780:6759)
```
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { fileURLToPath, URL } from 'node:url';
|
|
|
|
// Read version from package.json
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
|
|
const version = packageJson.version;
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
base: '/kgstudio/',
|
|
define: {
|
|
__APP_VERSION__: JSON.stringify(version),
|
|
},
|
|
esbuild: {
|
|
keepNames: true,
|
|
},
|
|
build: {
|
|
sourcemap: true,
|
|
},
|
|
server: {
|
|
host: true,
|
|
headers: {
|
|
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
},
|
|
// IMPORTANT: MAKE SURE TO UPDATE YOUR OS HOSTS FILE TO POINT `testlocal.com` TO YOUR LOCAL IP (e.g. 127.0.0.1).
|
|
allowedHosts: ['testlocal.com', '.testlocal.com', 'localhost', '127.0.0.1'],
|
|
},
|
|
preview: {
|
|
headers: {
|
|
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
},
|
|
},
|
|
});
|