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
40 changes: 30 additions & 10 deletions packages/sdk/src/bot/workflow-proxy/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ import type { BaseBot } from '../common'
import * as botServerTypes from '../server/types'
import type { WorkflowProxy, ActionableWorkflow } from './types'

// FIXME: Plugin (and bot) workflow definitions are currently being created on
// the fly at run time. However, they should be part of the bot/plugin
// definition. The SDK currently gives the illusion that they are defined
// at deploy time, but in reality they are not. Nothing about the
// workflows is sent to the backend at deploy time.
//
// This is being tracked as https://linear.app/botpress/issue/KKN-292
//
// Since currently each workflow definition is unique to a workflow run,
// the tags are not prefixed by the plugin instance's alias. This is
// because the backend's input validation prevents us from having a `#`
// character in the workflow definition's tag definition. The plugin
// prefix separator should only be present when we merge a plugin's
// definitions into a bot (ie when installing a plugin in a bot). It
// should not be allowed when calling the createWorkflow endpoint
// directly, which is what the CLI currently does.
//
// Once we have proper deploy-time workflow definitions, we should
// prefix/unprefix the tags like we do in the other plugin proxies.
//
// This means removing `undefined /* props.pluginAlias */` and replacing
// it with `props.pluginAlias` in the calls to `prefixTagsIfNeeded()` and
// `unprefixTagsOwnedByPlugin()`.

export const proxyWorkflows = <TBot extends BaseBot>(props: {
client: BotSpecificClient<TBot> | client.Client
pluginAlias?: string
Expand All @@ -31,11 +55,7 @@ export const proxyWorkflows = <TBot extends BaseBot>(props: {
const { workflow } = await props.client.createWorkflow({
name: workflowName as typeUtils.Cast<TWorkflowName, string>,
status: 'pending',
...input,
tags:
input.tags && props.pluginAlias
? prefixTagsIfNeeded(input.tags, { alias: props.pluginAlias })
: undefined,
...prefixTagsIfNeeded(input, { alias: undefined /* props.pluginAlias */ }),
})
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ ...props, workflow }) }
},
Expand All @@ -55,15 +75,15 @@ export const wrapWorkflowInstance = <
let isAcknowledged = false

return {
...((props.pluginAlias
? unprefixTagsOwnedByPlugin(props.workflow, { alias: props.pluginAlias })
: props.workflow) as ActionableWorkflow<TBot, TWorkflowName>),
...(unprefixTagsOwnedByPlugin(props.workflow, { alias: undefined /* props.pluginAlias */ }) as ActionableWorkflow<
TBot,
TWorkflowName
>),

async update(x) {
const { workflow } = await props.client.updateWorkflow({
id: props.workflow.id,
...x,
tags: x.tags && props.pluginAlias ? prefixTagsIfNeeded(x.tags, { alias: props.pluginAlias }) : undefined,
...prefixTagsIfNeeded(x, { alias: undefined /* props.pluginAlias */ }),
})
await props.onWorkflowUpdate?.(workflow)

Expand Down
16 changes: 9 additions & 7 deletions packages/sdk/src/plugin/action-proxy/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export const proxyActions = <TPlugin extends BasePlugin>(
const actualActionName =
props.interfaces[integrationOrInterfaceAlias]?.actions?.[actionName]?.name ?? actionName

return client.callAction({
type: `${integrationAlias}:${actualActionName}` as typeUtils.Cast<
keyof EnumerateActions<TPlugin>,
string
>,
input,
})
return client
.callAction({
type: `${integrationAlias}:${actualActionName}` as typeUtils.Cast<
keyof EnumerateActions<TPlugin>,
string
>,
input,
})
.then((res) => res.output)
},
}
),
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/plugin/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class PluginImplementation<TPlugin extends BasePlugin = BasePlugin> imple
const { configuration, interfaces, integrations, alias } = this._runtime
const actions = proxyActions(client, this._runtime) as ActionProxy<BasePlugin>
const states = proxyStates(client, this._runtime) as StateProxy<BasePlugin>
const workflows = proxyWorkflows({ client }) as WorkflowProxy<BasePlugin>
const workflows = proxyWorkflows({ client, pluginAlias: this._runtime.alias }) as WorkflowProxy<BasePlugin>
const events = proxyEvents(client, this._runtime) as EventProxy<BasePlugin>
const users = proxyUsers({ client, pluginAlias: this._runtime.alias }) as UserFinder<BasePlugin>
const conversations = proxyConversations({ client, plugin: this._runtime }) as ConversationFinder<BasePlugin>
Expand Down
2 changes: 1 addition & 1 deletion plugins/conversation-insights/plugin.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PluginDefinition, z } from '@botpress/sdk'

export default new PluginDefinition({
name: 'conversation-insights',
version: '0.4.5',
version: '0.4.6',
configuration: {
schema: z.object({
aiEnabled: z.boolean().default(true).describe('Set to true to enable title, summary and sentiment ai generation'),
Expand Down
2 changes: 1 addition & 1 deletion plugins/file-synchronizer/plugin.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const FILE_FILTER_PROPS = sdk.z.object({

export default new sdk.PluginDefinition({
name: 'file-synchronizer',
version: '1.1.0',
version: '1.1.1',
title: 'File Synchronizer',
description: 'Synchronize files from external services to Botpress',
icon: 'icon.svg',
Expand Down
2 changes: 1 addition & 1 deletion plugins/hitl/plugin.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const PLUGIN_CONFIG_SCHEMA = sdk.z.object({

export default new sdk.PluginDefinition({
name: 'hitl',
version: '1.1.0',
version: '1.1.1',
title: 'Human In The Loop',
description: 'Seamlessly transfer conversations to human agents',
icon: 'icon.svg',
Expand Down
Loading