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: 5 additions & 1 deletion integrations/n8n/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default new IntegrationDefinition({
name: 'n8n',
title: 'n8n',
description: 'This integration allows you to interact with n8n workflows.',
version: '0.1.0',
version: '0.1.1',
readme: 'hub.md',
icon: 'icon.svg',
configuration: {
Expand Down Expand Up @@ -126,4 +126,8 @@ export default new IntegrationDefinition({
}),
},
},
attributes: {
category: 'Developer Tools',
repo: 'botpress',
},
})
4 changes: 2 additions & 2 deletions integrations/sharepoint/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { actions, configuration, states } from './definitions'

export default new sdk.IntegrationDefinition({
name: 'sharepoint',
version: '1.0.0',
version: '1.0.1',
title: 'SharePoint',
description: 'Sync SharePoint document libraries with Botpress knowledge bases.',
readme: 'hub.md',
Expand All @@ -13,7 +13,7 @@ export default new sdk.IntegrationDefinition({
states,
actions,
attributes: {
category: 'Knowledge Base',
category: 'File Management',
repo: 'botpress',
},
}).extend(filesReadonly, ({}) => ({
Expand Down
79 changes: 56 additions & 23 deletions packages/cli/src/api/bot-body.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as client from '@botpress/client'
import * as sdk from '@botpress/sdk'
import * as errors from '../errors'
import * as utils from '../utils'
import * as types from './types'

Expand All @@ -9,50 +10,82 @@ export const prepareCreateBotBody = async (bot: sdk.BotDefinition): Promise<type
message: bot.message,
recurringEvents: bot.recurringEvents,
actions: bot.actions
? await utils.records.mapValuesAsync(bot.actions, async (action) => ({
? await utils.records.mapValuesAsync(bot.actions, async (action, actionName) => ({
...action,
input: {
...action.input,
schema: await utils.schema.mapZodToJsonSchema(action.input, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
}),
schema: await utils.schema
.mapZodToJsonSchema(action.input, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(
thrown,
`Failed to convert ZUI to JSON schema for bot action ${actionName} input`
)
}),
},
output: {
...action.output,
schema: await utils.schema.mapZodToJsonSchema(action.output, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
}),
schema: await utils.schema
.mapZodToJsonSchema(action.output, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(
thrown,
`Failed to convert ZUI to JSON schema for bot action ${actionName} output`
)
}),
},
}))
: undefined,
configuration: bot.configuration
? {
...bot.configuration,
schema: await utils.schema.mapZodToJsonSchema(bot.configuration, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
}),
schema: await utils.schema
.mapZodToJsonSchema(bot.configuration, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, 'Failed to convert ZUI to JSON schema for bot configuration')
}),
}
: undefined,
events: bot.events
? await utils.records.mapValuesAsync(bot.events, async (event) => ({
? await utils.records.mapValuesAsync(bot.events, async (event, eventName) => ({
...event,
schema: await utils.schema.mapZodToJsonSchema(event, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
}),
schema: await utils.schema
.mapZodToJsonSchema(event, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(
thrown,
`Failed to convert ZUI to JSON schema for bot event ${eventName}`
)
}),
}))
: undefined,
states: bot.states
? (utils.records.filterValues(
await utils.records.mapValuesAsync(bot.states, async (state) => ({
await utils.records.mapValuesAsync(bot.states, async (state, stateName) => ({
...state,
schema: await utils.schema.mapZodToJsonSchema(state, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
}),
schema: await utils.schema
.mapZodToJsonSchema(state, {
useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: bot.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(
thrown,
`Failed to convert ZUI to JSON schema for bot state ${stateName}`
)
}),
})),
({ type }) => type !== 'workflow'
) as types.CreateBotRequestBody['states'])
Expand Down
165 changes: 98 additions & 67 deletions packages/cli/src/api/integration-body.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,108 @@
import * as client from '@botpress/client'
import * as sdk from '@botpress/sdk'
import * as errors from '../errors'
import * as utils from '../utils'
import * as types from './types'

export const prepareCreateIntegrationBody = async (
integration: sdk.IntegrationDefinition
): Promise<types.CreateIntegrationRequestBody> => ({
name: integration.name,
version: integration.version,
title: 'title' in integration ? integration.title : undefined,
description: 'description' in integration ? integration.description : undefined,
user: integration.user,
events: integration.events
? await utils.records.mapValuesAsync(integration.events, async (event) => ({
...event,
schema: await utils.schema.mapZodToJsonSchema(event, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
}),
}))
: undefined,
actions: integration.actions
? await utils.records.mapValuesAsync(integration.actions, async (action) => ({
...action,
input: {
...action.input,
schema: await utils.schema.mapZodToJsonSchema(action.input, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
}),
},
output: {
...action.output,
schema: await utils.schema.mapZodToJsonSchema(action.output, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
}),
},
}))
: undefined,
channels: integration.channels
? await utils.records.mapValuesAsync(integration.channels, async (channel) => ({
...channel,
messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({
...message,
schema: await utils.schema.mapZodToJsonSchema(message, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
}),
})),
}))
: undefined,
states: integration.states
? await utils.records.mapValuesAsync(integration.states, async (state) => ({
...state,
schema: await utils.schema.mapZodToJsonSchema(state, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
}),
}))
: undefined,
entities: integration.entities
? await utils.records.mapValuesAsync(integration.entities, async (entity) => ({
...entity,
schema: await utils.schema.mapZodToJsonSchema(entity, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
}),
}))
: undefined,
attributes: integration.attributes,
extraOperations: '__advanced' in integration ? integration.__advanced?.extraOperations : undefined,
})
): Promise<types.CreateIntegrationRequestBody> => {
const base = `Failed to convert ZUI to JSON schema for integration ${integration.name}`
return {
name: integration.name,
version: integration.version,
title: 'title' in integration ? integration.title : undefined,
description: 'description' in integration ? integration.description : undefined,
user: integration.user,
events: integration.events
? await utils.records.mapValuesAsync(integration.events, async (event, eventName) => ({
...event,
schema: await utils.schema
.mapZodToJsonSchema(event, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, `${base} for event ${eventName}`)
}),
}))
: undefined,
actions: integration.actions
? await utils.records.mapValuesAsync(integration.actions, async (action, actionName) => ({
...action,
input: {
...action.input,
schema: await utils.schema
.mapZodToJsonSchema(action.input, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, `${base} for action ${actionName} input`)
}),
},
output: {
...action.output,
schema: await utils.schema
.mapZodToJsonSchema(action.output, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, `${base} for action ${actionName} output`)
}),
},
}))
: undefined,
channels: integration.channels
? await utils.records.mapValuesAsync(integration.channels, async (channel, channelName) => ({
...channel,
messages: await utils.records.mapValuesAsync(channel.messages, async (message, messageName) => ({
...message,
schema: await utils.schema
.mapZodToJsonSchema(message, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(
thrown,
`${base} for channel ${channelName} for message ${messageName}`
)
}),
})),
}))
: undefined,
states: integration.states
? await utils.records.mapValuesAsync(integration.states, async (state, stateName) => ({
...state,
schema: await utils.schema
.mapZodToJsonSchema(state, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, `${base} for state ${stateName}`)
}),
}))
: undefined,
entities: integration.entities
? await utils.records.mapValuesAsync(integration.entities, async (entity, entityName) => ({
...entity,
schema: await utils.schema
.mapZodToJsonSchema(entity, {
useLegacyZuiTransformer: integration.__advanced?.useLegacyZuiTransformer,
toJSONSchemaOptions: integration.__advanced?.toJSONSchemaOptions,
})
.catch((thrown) => {
throw errors.BotpressCLIError.wrap(thrown, `${base} for entity ${entityName}`)
}),
}))
: undefined,
attributes: integration.attributes,
extraOperations: '__advanced' in integration ? integration.__advanced?.extraOperations : undefined,
}
}

type UpdateIntegrationChannelsBody = NonNullable<types.UpdateIntegrationRequestBody['channels']>
type UpdateIntegrationChannelBody = UpdateIntegrationChannelsBody[string]
Expand Down
Loading
Loading