fix(playground): inject X-Organization-Id on non-umi fetch paths
Playground completions (chat streaming via ``fetchChunkedData``) and the raw ``fetch()`` calls for image / audio generation skip umi's ``request`` pipeline and so miss the request interceptor in ``request.extensions.ts`` that pins tenant context. Higress receives those calls without ``X-Organization-Id`` and the auth callback falls back to the user's USER-principal id rather than their active Org, which makes Playground usage invisible from Org-scoped Usage views even after the backend learned to backfill ``consumer_principal_id``. Centralise the lookup in ``tenantHeaders()`` next to ``fetchChunkedData`` so both streaming helpers and the four ``fetch()``-direct entry points in ``playground/apis/index.ts`` (image / TTS) attach the header with the same precedence as the umi interceptor (``createScopeOrgOverride`` first, ``currentOrganizationId`` second). Returns an empty object when no active org context is set, leaving requests unchanged.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { GPUSTACK_API_BASE_URL, OPENAI_COMPATIBLE } from '@/config/settings';
|
||||
import { createFormData, errorHandler } from '@/utils/fetch-chunk-data';
|
||||
import {
|
||||
createFormData,
|
||||
errorHandler,
|
||||
tenantHeaders
|
||||
} from '@/utils/fetch-chunk-data';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export { GPUSTACK_API_BASE_URL, OPENAI_COMPATIBLE };
|
||||
@@ -92,7 +96,8 @@ export const createImages = async (
|
||||
body: JSON.stringify(params),
|
||||
signal: options.signal,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
...tenantHeaders()
|
||||
}
|
||||
});
|
||||
if (!res.ok) {
|
||||
@@ -112,7 +117,10 @@ export const editImage = async (params: {
|
||||
const response = await fetch(EDIT_IMAGE_API, {
|
||||
method: 'POST',
|
||||
body: createFormData(params.data),
|
||||
signal: params.signal
|
||||
signal: params.signal,
|
||||
headers: {
|
||||
...tenantHeaders()
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
return await errorHandler(response);
|
||||
@@ -129,7 +137,8 @@ export const createImage = async (params: {
|
||||
body: JSON.stringify(params.data),
|
||||
signal: params.signal,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
...tenantHeaders()
|
||||
}
|
||||
});
|
||||
|
||||
@@ -156,7 +165,8 @@ export const textToSpeech = async (params: any, options?: any) => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(params.data),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
...tenantHeaders()
|
||||
},
|
||||
signal: params.signal
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user