feat: implement PI core chat timeline
This commit is contained in:
@@ -43,11 +43,19 @@ export function registerHostApiProxyHandlers(hostApiContext?: HostApiContext): v
|
||||
// Inject the per-session auth token so the Host API server accepts this request.
|
||||
headers['Authorization'] = `Bearer ${getHostApiToken()}`;
|
||||
headers[RENDERER_CAPABILITY_HEADER] = getRendererCapability();
|
||||
let body: string | undefined;
|
||||
let body: string | Uint8Array | undefined;
|
||||
|
||||
if (request.body !== undefined && request.body !== null) {
|
||||
if (typeof request.body === 'string') {
|
||||
body = request.body;
|
||||
} else if (request.body instanceof ArrayBuffer) {
|
||||
body = new Uint8Array(request.body);
|
||||
} else if (ArrayBuffer.isView(request.body)) {
|
||||
body = new Uint8Array(
|
||||
request.body.buffer,
|
||||
request.body.byteOffset,
|
||||
request.body.byteLength,
|
||||
);
|
||||
} else {
|
||||
body = JSON.stringify(request.body);
|
||||
}
|
||||
@@ -79,7 +87,14 @@ export function registerHostApiProxyHandlers(hostApiContext?: HostApiContext): v
|
||||
body,
|
||||
});
|
||||
|
||||
const data: { status: number; ok: boolean; json?: unknown; text?: string } = {
|
||||
const data: {
|
||||
status: number;
|
||||
ok: boolean;
|
||||
json?: unknown;
|
||||
text?: string;
|
||||
bytes?: Uint8Array;
|
||||
contentType?: string;
|
||||
} = {
|
||||
status: response.status,
|
||||
ok: response.ok,
|
||||
};
|
||||
@@ -88,6 +103,9 @@ export function registerHostApiProxyHandlers(hostApiContext?: HostApiContext): v
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
if (contentType.includes('application/json')) {
|
||||
data.json = await response.json().catch(() => undefined);
|
||||
} else if (contentType.startsWith('image/') || contentType === 'application/octet-stream') {
|
||||
data.bytes = new Uint8Array(await response.arrayBuffer());
|
||||
data.contentType = contentType.split(';', 1)[0]?.trim() || 'application/octet-stream';
|
||||
} else {
|
||||
data.text = await response.text().catch(() => '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user