Show tool execution messages in AI agent chat (#13117)
https://github.com/user-attachments/assets/c0a42726-50ac-496e-a993-9d6076a84a6a --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { ApolloLink, Observable, Operation } from '@apollo/client/core';
|
||||
import {
|
||||
ApolloLink,
|
||||
Observable,
|
||||
Operation,
|
||||
ServerError,
|
||||
} from '@apollo/client/core';
|
||||
import { FetchResult } from '@apollo/client/link/core';
|
||||
import { ArgumentNode, DirectiveNode } from 'graphql';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
@@ -57,7 +62,13 @@ export class StreamingRestLink extends ApolloLink {
|
||||
fetch(url, requestConfig)
|
||||
.then(async (response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
const networkError = new Error(
|
||||
`HTTP error! status: ${response.status}`,
|
||||
) as ServerError;
|
||||
|
||||
networkError.statusCode = response.status;
|
||||
|
||||
throw networkError;
|
||||
}
|
||||
|
||||
if (!response.body) {
|
||||
@@ -66,7 +77,6 @@ export class StreamingRestLink extends ApolloLink {
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let accumulatedData = '';
|
||||
|
||||
let isStreaming = true;
|
||||
while (isStreaming) {
|
||||
@@ -79,19 +89,9 @@ export class StreamingRestLink extends ApolloLink {
|
||||
}
|
||||
|
||||
const decodedChunk = decoder.decode(value, { stream: true });
|
||||
accumulatedData += decodedChunk;
|
||||
|
||||
if (isDefined(onChunk) && typeof onChunk === 'function') {
|
||||
onChunk(accumulatedData);
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedData = JSON.parse(decodedChunk);
|
||||
observer.next({ data: parsedData });
|
||||
} catch {
|
||||
observer.next({
|
||||
data: { streamingData: decodedChunk },
|
||||
});
|
||||
onChunk(decodedChunk);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user