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
12 changes: 9 additions & 3 deletions packages/client/src/common/debug-interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ export const addDebugInterceptors = (axiosInstance: axios.AxiosInstance) => {

const _formatRequestLog = (config: AxiosRequestConfigWithMetadata): string => {
const { method, url, headers, data } = config

const fullUrl = config.baseURL ? new URL(url!, config.baseURL).toString() : url

return (
'REQUEST: ' +
JSON.stringify({
method: method?.toUpperCase(),
url,
url: fullUrl,
timestamp: new Date().toISOString(),
requestId: config.metadata?.id,
headers,
Expand All @@ -64,13 +67,14 @@ const _formatRequestLog = (config: AxiosRequestConfigWithMetadata): string => {
const _formatResponseLog = (response: AxiosResponseWithMetadata): string => {
const { config, status, headers, data } = response
const duration = _formatDuration(response)
const fullUrl = config.baseURL ? new URL(response.config.url!, config.baseURL).toString() : response.config.url

return (
'RESPONSE: ' +
JSON.stringify({
method: config.method?.toUpperCase(),
status,
url: config.url,
url: fullUrl,
timestamp: new Date().toISOString(),
requestId: config.metadata?.id,
duration,
Expand All @@ -83,13 +87,15 @@ const _formatResponseLog = (response: AxiosResponseWithMetadata): string => {

const _formatErrorLog = (error: AxiosErrorWithMetadata): string => {
const duration = error ? _formatDuration(error) : 'N/A'
const fullUrl = error.config.baseURL ? new URL(error.config.url!, error.config.baseURL).toString() : error.config.url

return (
'ERROR: ' +
JSON.stringify({
status: error.code,
url: error.config.url ?? 'N/A',
url: fullUrl,
timestamp: new Date().toISOString(),
requestId: error.config.metadata?.id ?? 'N/A',
duration,
})
)
Expand Down
15 changes: 12 additions & 3 deletions packages/common/src/conversation-transcript/message-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import * as sdk from '@botpress/sdk'

type AllMessageTypes = typeof sdk.messages.defaults & { markdown: typeof sdk.messages.markdown }
type ValueOf<T> = T[keyof T]
type Merge<A, B> = Omit<A, keyof B> & B

export type Message = {
type AllMessageTypes = Merge<
typeof sdk.messages.defaults,
{
markdown: typeof sdk.messages.markdown
bloc: typeof sdk.messages.markdownBloc
}
>

export type Message = ValueOf<{
[K in keyof AllMessageTypes]: {
type: K
source:
Expand All @@ -15,7 +24,7 @@ export type Message = {
}
payload: sdk.z.infer<AllMessageTypes[K]['schema']>
}
}[keyof AllMessageTypes]
}>

export type MessageSource = Message['source']

Expand Down
Loading