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
6 changes: 1 addition & 5 deletions integrations/browser/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IntegrationDefinition } from '@botpress/sdk'
import { actionDefinitions } from 'src/definitions/actions'

export const INTEGRATION_NAME = 'browser'
export const INTEGRATION_VERSION = '0.8.7'
export const INTEGRATION_VERSION = '0.8.8'

export default new IntegrationDefinition({
name: INTEGRATION_NAME,
Expand All @@ -22,10 +22,6 @@ export default new IntegrationDefinition({
FIRECRAWL_API_KEY: {
description: 'FireCrawl key',
},
FIRECRAWL_CUSTOM_HEADERS: {
description: 'Custom HTTP headers to include in Firecrawl scrape requests (JSON object)',
optional: true,
},
LOGO_API_KEY: {
description: 'Logo key',
},
Expand Down
19 changes: 1 addition & 18 deletions integrations/browser/src/actions/browse-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@ const fixOutput = (val: unknown): string => {
return ''
}

const getCustomHeaders = (): Record<string, string> | undefined => {
const raw = bp.secrets.FIRECRAWL_CUSTOM_HEADERS
if (!raw) {
return undefined
}

try {
const parsed = JSON.parse(raw)
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
return undefined
}
return parsed as Record<string, string>
} catch {
return undefined
}
}

const getPageContent = async (props: {
url: string
logger: IntegrationLogger
Expand All @@ -51,7 +34,7 @@ const getPageContent = async (props: {
waitFor: props.waitFor,
timeout: props.timeout,
formats: ['markdown', 'rawHtml'],
headers: getCustomHeaders(),
headers: { 'X-Botpress-Crawler': 'botpress' },
storeInCache: true,
})

Expand Down
8 changes: 8 additions & 0 deletions integrations/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.564.0",
"@botpress/sdk": "workspace:*",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/core": "1.30.0",
"@opentelemetry/exporter-trace-otlp-http": "0.54.2",
"@opentelemetry/instrumentation": "0.54.2",
"@opentelemetry/instrumentation-http": "0.54.2",
"@opentelemetry/resources": "1.27.0",
"@opentelemetry/sdk-trace-base": "1.27.0",
"@opentelemetry/sdk-trace-node": "1.27.0",
"ajv": "^8.12.0",
"axios": "1.2.5",
"chalk": "^4.1.2",
Expand Down
26 changes: 26 additions & 0 deletions integrations/chat/src/api/operations/conversation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as errors from '../../gen/errors'
import { validateFid } from '../../id-store'
import { setSpanAttributes, SPAN_ATTRS } from '../../tracing'
import * as types from '../types'
import * as fid from './fid'
import * as model from './model'
Expand All @@ -12,6 +13,8 @@ export const createConversation: types.AuthenticatedOperations['createConversati
auth: { userId },
} = req

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: userId })

const { conversation } = await props.client.createConversation({
channel: 'channel',
tags: {
Expand All @@ -20,6 +23,8 @@ export const createConversation: types.AuthenticatedOperations['createConversati
},
})

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversation.id })

await props.client.addParticipant({ id: conversation.id, userId })

return fidHandler.mapResponse({
Expand All @@ -33,6 +38,8 @@ export const getConversation: types.AuthenticatedOperations['getConversation'] =
const fidHandler = fid.handlers.getConversation(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: req.params.id, [SPAN_ATTRS.USER_ID]: req.auth.userId })

const { conversation } = await props.client.getConversation({ id: req.params.id })

const { participant } = await props.apiUtils.findParticipant({
Expand Down Expand Up @@ -62,6 +69,8 @@ export const getOrCreateConversation: types.AuthenticatedOperations['getOrCreate
const existingId = await props.convIdStore.byFid.find(conversationFid)

if (existingId) {
setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: existingId, [SPAN_ATTRS.USER_ID]: userId })

const { conversation } = await props.client.getConversation({ id: existingId })
if (conversation.tags.owner !== userId) {
throw new errors.ForbiddenError('You are not the owner of this conversation')
Expand Down Expand Up @@ -96,6 +105,7 @@ export const getOrCreateConversation: types.AuthenticatedOperations['getOrCreate

const { id: conversationId } = conversation

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: userId })
await props.client.addParticipant({ id: conversationId, userId })
await props.convIdStore.byFid.set(conversationFid, conversationId)

Expand All @@ -118,6 +128,8 @@ export const deleteConversation: types.AuthenticatedOperations['deleteConversati
const fidHandler = fid.handlers.deleteConversation(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: req.params.id, [SPAN_ATTRS.USER_ID]: req.auth.userId })

const { conversation } = await props.client.getConversation({ id: req.params.id })
if (conversation.tags.owner !== req.auth.userId) {
throw new errors.ForbiddenError('You are not the owner of this conversation')
Expand All @@ -132,6 +144,8 @@ export const listConversations: types.AuthenticatedOperations['listConversations
const fidHandler = fid.handlers.listConversations(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId })

const { conversations, meta } = await props.client.listConversations({
nextToken: req.query.nextToken,
tags: { owner: req.auth.userId },
Expand All @@ -156,6 +170,8 @@ export const listMessages: types.AuthenticatedOperations['listMessages'] = async
const { nextToken } = req.query
const { conversationId } = req.params

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: req.auth.userId })

const { participant } = await props.apiUtils.findParticipant({ id: conversationId, userId: req.auth.userId })
if (!participant) {
throw new errors.ForbiddenError('You are not a participant in this conversation')
Expand All @@ -178,6 +194,8 @@ export const listenConversation: types.AuthenticatedOperations['listenConversati
const userId = req.auth.userId
const conversationId = req.params.id

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: userId })

const { participant } = await props.apiUtils.findParticipant({ id: conversationId, userId })
if (!participant) {
throw new errors.ForbiddenError('You are not a participant in this conversation')
Expand Down Expand Up @@ -211,6 +229,8 @@ export const addParticipant: types.AuthenticatedOperations['addParticipant'] = a
const conversationId = req.params.conversationId
const participantId = req.body.userId

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: userId })

const {
conversation: {
tags: { owner },
Expand Down Expand Up @@ -244,6 +264,8 @@ export const getParticipant: types.AuthenticatedOperations['getParticipant'] = a
const fidHandler = fid.handlers.getParticipant(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: req.params.conversationId, [SPAN_ATTRS.USER_ID]: req.auth.userId })

const {
conversation: {
tags: { owner },
Expand Down Expand Up @@ -276,6 +298,8 @@ export const removeParticipant: types.AuthenticatedOperations['removeParticipant
const conversationId = req.params.conversationId
const participantId = req.params.userId

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: userId })

const {
conversation: {
tags: { owner },
Expand Down Expand Up @@ -313,6 +337,8 @@ export const listParticipants: types.AuthenticatedOperations['listParticipants']
const fidHandler = fid.handlers.listParticipants(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: req.params.conversationId, [SPAN_ATTRS.USER_ID]: req.auth.userId })

const { participant } = await props.apiUtils.findParticipant({
id: req.params.conversationId,
userId: req.auth.userId,
Expand Down
6 changes: 6 additions & 0 deletions integrations/chat/src/api/operations/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as errors from '../../gen/errors'
import { setSpanAttributes, SPAN_ATTRS } from '../../tracing'
import * as types from '../types'
import * as fid from './fid'
import * as model from './model'
Expand All @@ -10,6 +11,8 @@ export const createEvent: types.AuthenticatedOperations['createEvent'] = async (
const { conversationId, payload } = req.body
const { userId } = req.auth

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: userId })

const { participant } = await props.apiUtils.findParticipant({ id: conversationId, userId: req.auth.userId })
if (!participant) {
throw new errors.ForbiddenError("You are not a participant in this event's conversation")
Expand Down Expand Up @@ -44,8 +47,11 @@ export const getEvent: types.AuthenticatedOperations['getEvent'] = async (props,
const fidHandler = fid.handlers.getEvent(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId })

const { event } = await props.client.getEvent({ id: req.params.id })
const { conversationId } = event.payload
setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId })
const { participant } = await props.apiUtils.findParticipant({ id: conversationId, userId: req.auth.userId })
if (!participant) {
throw new errors.ForbiddenError("You are not a participant in this event's conversation")
Expand Down
14 changes: 14 additions & 0 deletions integrations/chat/src/api/operations/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as errors from '../../gen/errors'
import { setSpanAttributes, SPAN_ATTRS } from '../../tracing'
import * as msgPayload from '../message-payload'
import * as types from '../types'
import * as fid from './fid'
Expand All @@ -11,7 +12,10 @@ export const createMessage: types.AuthenticatedOperations['createMessage'] = asy
const { conversationId, payload, metadata } = req.body
const { userId } = req.auth

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId, [SPAN_ATTRS.USER_ID]: userId })

const { participant } = await props.apiUtils.findParticipant({ id: conversationId, userId: req.auth.userId })

if (!participant) {
throw new errors.ForbiddenError("You are not a participant in this message's conversation")
}
Expand All @@ -25,6 +29,8 @@ export const createMessage: types.AuthenticatedOperations['createMessage'] = asy
payload: mappedPayload,
})

setSpanAttributes({ [SPAN_ATTRS.MESSAGE_ID]: message.id })

const res = await fidHandler.mapResponse({
body: {
message: model.mapMessage(message),
Expand All @@ -43,8 +49,11 @@ export const getMessage: types.AuthenticatedOperations['getMessage'] = async (pr
const fidHandler = fid.handlers.getMessage(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId, [SPAN_ATTRS.MESSAGE_ID]: req.params.id })

const { message } = await props.client.getMessage({ id: req.params.id })
const { conversationId } = message
setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: conversationId })
const { participant } = await props.apiUtils.findParticipant({ id: conversationId, userId: req.auth.userId })
if (!participant) {
throw new errors.ForbiddenError("You are not a participant in this message's conversation")
Expand All @@ -63,7 +72,12 @@ export const deleteMessage: types.AuthenticatedOperations['deleteMessage'] = asy

const { id } = req.params

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId, [SPAN_ATTRS.MESSAGE_ID]: id })

const { message } = await props.client.getMessage({ id })

setSpanAttributes({ [SPAN_ATTRS.CONVERSATION_ID]: message.conversationId })

if (message.userId !== req.auth.userId) {
throw new errors.ForbiddenError('You are not the sender of this message')
}
Expand Down
7 changes: 7 additions & 0 deletions integrations/chat/src/api/operations/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as errors from '../../gen/errors'
import { validateFid } from '../../id-store'
import { setSpanAttributes, SPAN_ATTRS } from '../../tracing'
import * as types from '../types'
import * as fid from './fid'
import * as model from './model'
Expand Down Expand Up @@ -28,6 +29,7 @@ export const createUser: types.Operations['createUser'] = async (props, foreignR
})

const userFid = foreignReq.body.id ?? user.id
setSpanAttributes({ [SPAN_ATTRS.USER_ID]: user.id })
const userKey = props.auth.generateKey({ id: userFid })
return fidHandler.mapResponse({
body: {
Expand All @@ -41,6 +43,7 @@ export const getUser: types.AuthenticatedOperations['getUser'] = async (props, f
const fidHandler = fid.handlers.getUser(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId })
const { user } = await props.client.getUser({ id: req.auth.userId })
return fidHandler.mapResponse({
body: {
Expand All @@ -60,6 +63,7 @@ export const getOrCreateUser: types.AuthenticatedOperations['getOrCreateUser'] =
(await props.apiUtils.findUser({ id: userFid }).then((res) => res.user?.id))

if (existingId) {
setSpanAttributes({ [SPAN_ATTRS.USER_ID]: existingId })
const { user: updatedUser } = await props.client.updateUser({
id: existingId,
name,
Expand Down Expand Up @@ -103,6 +107,7 @@ export const getOrCreateUser: types.AuthenticatedOperations['getOrCreateUser'] =
},
}

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: newUser.id })
await props.userIdStore.byFid.set(userFid, newUser.id)
return fid.merge(res, {
body: {
Expand All @@ -121,6 +126,7 @@ export const updateUser: types.AuthenticatedOperations['updateUser'] = async (pr
body: { name, pictureUrl, profile },
} = req

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId })
const { user } = await props.client.updateUser({ id: req.auth.userId, name, pictureUrl, tags: { profile } })

return fidHandler.mapResponse({
Expand All @@ -134,6 +140,7 @@ export const deleteUser: types.AuthenticatedOperations['deleteUser'] = async (pr
const fidHandler = fid.handlers.deleteUser(props, foreignReq)
const req = await fidHandler.mapRequest()

setSpanAttributes({ [SPAN_ATTRS.USER_ID]: req.auth.userId })
await props.client.deleteUser({ id: req.auth.userId })
return fidHandler.mapResponse({ body: {} })
}
Loading
Loading