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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "^3.564.0",
"@botpress/api": "1.40.0",
"@botpress/api": "1.42.0",
"@botpress/cli": "workspace:*",
"@botpress/client": "workspace:*",
"@botpress/sdk": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/cli",
"version": "4.17.16",
"version": "4.17.17",
"description": "Botpress CLI",
"scripts": {
"build": "pnpm run build:types && pnpm run bundle && pnpm run template:gen",
Expand All @@ -23,8 +23,8 @@
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.7.0",
"@botpress/chat": "0.5.1",
"@botpress/client": "1.24.2",
"@botpress/sdk": "4.15.8",
"@botpress/client": "1.25.0",
"@botpress/sdk": "4.15.10",
"@bpinternal/const": "^0.1.0",
"@bpinternal/tunnel": "^0.1.1",
"@bpinternal/yargs-extra": "^0.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/empty-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.24.2",
"@botpress/sdk": "4.15.8"
"@botpress/client": "1.25.0",
"@botpress/sdk": "4.15.10"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/empty-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.24.2",
"@botpress/sdk": "4.15.8"
"@botpress/client": "1.25.0",
"@botpress/sdk": "4.15.10"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/empty-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"private": true,
"dependencies": {
"@botpress/sdk": "4.15.8"
"@botpress/sdk": "4.15.10"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.24.2",
"@botpress/sdk": "4.15.8"
"@botpress/client": "1.25.0",
"@botpress/sdk": "4.15.10"
},
"devDependencies": {
"@types/node": "^22.16.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/templates/webhook-message/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"private": true,
"dependencies": {
"@botpress/client": "1.24.2",
"@botpress/sdk": "4.15.8",
"@botpress/client": "1.25.0",
"@botpress/sdk": "4.15.10",
"axios": "^1.6.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/client",
"version": "1.24.2",
"version": "1.25.0",
"description": "Botpress Client",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/cognitive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/cognitive",
"version": "0.1.40",
"version": "0.1.41",
"description": "Wrapper around the Botpress Client to call LLMs",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
6 changes: 3 additions & 3 deletions packages/llmz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "llmz",
"type": "module",
"description": "LLMz – An LLM-native Typescript VM built on top of Zui",
"version": "0.0.23",
"version": "0.0.24",
"types": "./dist/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"@babel/standalone": "^7.26.4",
"@babel/traverse": "^7.26.4",
"@babel/types": "^7.26.3",
"@botpress/client": "1.24.2",
"@botpress/client": "1.25.0",
"bytes": "^3.1.2",
"exponential-backoff": "^3.1.1",
"handlebars": "^4.7.8",
Expand Down Expand Up @@ -67,7 +67,7 @@
"tsx": "^4.19.2"
},
"peerDependencies": {
"@botpress/cognitive": "0.1.40",
"@botpress/cognitive": "0.1.41",
"@bpinternal/thicktoken": "^1.0.5",
"@bpinternal/zui": "^1.0.1"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/sdk",
"version": "4.15.8",
"version": "4.15.10",
"description": "Botpress SDK",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand All @@ -16,7 +16,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@botpress/client": "1.24.2",
"@botpress/client": "1.25.0",
"browser-or-node": "^2.1.1"
},
"devDependencies": {
Expand Down
17 changes: 7 additions & 10 deletions packages/sdk/src/bot/server/workflows/update-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,16 @@ const _handleWorkflowUpdate = async (props: types.ServerProps, event: types.Work
return SUCCESS_RESPONSE
}

await _acknowledgeWorkflowStart(props, event)
await _dispatchToHandlers(props, event)

return SUCCESS_RESPONSE
}

const _acknowledgeWorkflowStart = async (props: types.ServerProps, event: types.WorkflowUpdateEvent): Promise<void> => {
if (event.payload.workflow.status !== 'pending') {
return
if (event.payload.workflow.status === 'pending') {
props.logger.warn(
`Workflow "${event.payload.workflow.name}" is still in pending status after processing "${updateType}" event. ` +
'This may indicate that the workflow was not properly acknowledged or terminated by the handler. '
)
}

// Acknowledge start of workflow processing:
await props.client.updateWorkflow({ id: event.payload.workflow.id, status: 'in_progress', eventId: event.id })
return SUCCESS_RESPONSE
}

const _dispatchToHandlers = async (props: types.ServerProps, event: types.WorkflowUpdateEvent): Promise<void> => {
Expand All @@ -93,7 +90,7 @@ const _dispatchToHandlers = async (props: types.ServerProps, event: types.Workfl
event,
conversation: event.payload.conversation,
user: event.payload.user,
workflow: wrapWorkflowInstance({ ...props, workflow: event.payload.workflow }),
workflow: wrapWorkflowInstance({ ...props, workflow: event.payload.workflow, event }),
workflows: proxyWorkflows(props.client),
})
}
Expand Down
61 changes: 38 additions & 23 deletions packages/sdk/src/bot/workflow-proxy/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type * as client from '@botpress/client'
import type { BotSpecificClient } from '../../bot'
import type * as typeUtils from '../../utils/type-utils'
import type { BaseBot } from '../common'
import * as botServerTypes from '../server/types'
import type { WorkflowProxy, WorkflowWithUtilities } from './types'

export const proxyWorkflows = <TBot extends BaseBot>(
Expand Down Expand Up @@ -67,30 +68,44 @@ export const wrapWorkflowInstance = <
>(props: {
client: BotSpecificClient<TBot> | client.Client
workflow: client.Workflow
}): WorkflowWithUtilities<TBot, TWorkflowName> => ({
...(props.workflow as WorkflowWithUtilities<TBot, TWorkflowName>),
event?: botServerTypes.WorkflowUpdateEvent
}): WorkflowWithUtilities<TBot, TWorkflowName> => {
let isAcknowledged = false

async update(x) {
const { workflow } = await props.client.updateWorkflow({ id: props.workflow.id, ...x })
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},
return {
...(props.workflow as WorkflowWithUtilities<TBot, TWorkflowName>),

async update(x) {
const { workflow } = await props.client.updateWorkflow({ id: props.workflow.id, ...x })
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},

async acknowledgeStartOfProcessing() {
if (!props.event || props.workflow.status !== 'pending' || isAcknowledged) {
return
}

async setFailed({ failureReason }) {
const { workflow } = await props.client.updateWorkflow({
id: props.workflow.id,
status: 'failed',
failureReason,
})
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},
await props.client.updateWorkflow({ id: props.workflow.id, status: 'in_progress', eventId: props.event.id })
isAcknowledged = true
},

async setCompleted({ output } = {}) {
const { workflow } = await props.client.updateWorkflow({ id: props.workflow.id, status: 'completed', output })
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},
async setFailed({ failureReason }) {
const { workflow } = await props.client.updateWorkflow({
id: props.workflow.id,
status: 'failed',
failureReason,
})
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},

async cancel() {
const { workflow } = await props.client.updateWorkflow({ id: props.workflow.id, status: 'cancelled' })
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},
})
async setCompleted({ output } = {}) {
const { workflow } = await props.client.updateWorkflow({ id: props.workflow.id, status: 'completed', output })
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},

async cancel() {
const { workflow } = await props.client.updateWorkflow({ id: props.workflow.id, status: 'cancelled' })
return { workflow: wrapWorkflowInstance<TBot, TWorkflowName>({ client: props.client, workflow }) }
},
}
}
14 changes: 14 additions & 0 deletions packages/sdk/src/bot/workflow-proxy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ export type WorkflowWithUtilities<
>
): Promise<{ workflow: WorkflowWithUtilities<TBot, TWorkflowName> }>

/**
* Acknowledges the start of processing for a pending workflow instance.
* If the workflow is not in pending status or has already been
* acknowledged, this is a no-op.
*
* This method **should be called in every workflow handler** as soon as the
* workflow **starts doing work**. If no work needs to be done, setCompleted
* or setFailed should be called instead.
*
* Should a workflow not be acknowledged **in a timely fashion**, it will be
* retriggered 3 times before being marked as failed.
*/
acknowledgeStartOfProcessing(): Promise<void>

/**
* Marks the current workflow instance as failed and stops execution
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/integration/client/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe.concurrent('ClientOperations', () => {
}
}
)
type _assertion = utils.AssertTrue<utils.IsEqual<Actual, Expected>>
type _assertion = utils.AssertTrue<utils.IsEquivalent<Actual, Expected>>
})

test('getOrCreateConversation with FooBarBazIntegration stricly enforces allowed tags', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tsup": "^8.0.2"
},
"peerDependencies": {
"@botpress/client": "1.24.2",
"@botpress/client": "1.25.0",
"@bpinternal/thicktoken": "^1.0.1",
"@bpinternal/zui": "^1.0.1",
"lodash": "^4.17.21",
Expand Down
4 changes: 2 additions & 2 deletions packages/zai/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@botpress/zai",
"description": "Zui AI (zai) – An LLM utility library written on top of Zui and the Botpress API",
"version": "2.1.10",
"version": "2.1.11",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down Expand Up @@ -29,7 +29,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@botpress/cognitive": "0.1.40",
"@botpress/cognitive": "0.1.41",
"json5": "^2.2.3",
"jsonrepair": "^3.10.0",
"lodash-es": "^4.17.21"
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 @@ -60,7 +60,7 @@ const FILE_FILTER_PROPS = sdk.z.object({

export default new sdk.PluginDefinition({
name: 'file-synchronizer',
version: '1.0.0',
version: '1.0.1',
title: 'File Synchronizer',
description: 'Synchronize files from external services to Botpress',
icon: 'icon.svg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const handleEvent: bp.WorkflowHandlers['buildQueue'] = async (props) => {
const workflowState = await props.states.workflow.buildQueueRuntimeState.get(props.workflow.id)
const { syncQueue, key } = await SyncQueue.jobFileManager.getSyncQueue(props, workflowState.jobFileId)

await props.workflow.acknowledgeStartOfProcessing()

props.logger.info('Enumerating files...')
const enumerationState = await SyncQueue.directoryTraversalWithBatching.enumerateAllFilesRecursive(
_getEnumerateAllFilesRecursiveProps(props, syncQueue, key, workflowState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const handleEvent: bp.WorkflowHandlers['processQueue'] = async (props) =>
const { syncQueue, key } = await SyncQueue.jobFileManager.getSyncQueue(props)
const logger = props.logger.withWorkflowId(props.workflow.id)

await props.workflow.acknowledgeStartOfProcessing()

const { finished } = await SyncQueue.queueProcessor.processQueue({
logger,
syncQueue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as SyncQueue from '../../sync-queue'
import * as bp from '.botpress'

export const handleEvent: bp.WorkflowHandlers['buildQueue'] = async (props) => {
await props.workflow.acknowledgeStartOfProcessing()

props.logger.info('Creating job file...')
const syncFileKey = _generateFileKey(props)
const jobFileId = await SyncQueue.jobFileManager.updateSyncQueue(props, syncFileKey, [], props.workflow.tags)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as bp from '.botpress'

export const handleEvent: bp.WorkflowHandlers['processQueue'] = async (_props) => {}
export const handleEvent: bp.WorkflowHandlers['processQueue'] = async (props) => {
await props.workflow.acknowledgeStartOfProcessing()
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as bp from '.botpress'

export const handleEvent: bp.WorkflowHandlers['buildQueue'] = async (_props) => {}
export const handleEvent: bp.WorkflowHandlers['buildQueue'] = async (props) => {
await props.workflow.setFailed({ failureReason: 'Workflow timed out' })
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as bp from '.botpress'

export const handleEvent: bp.WorkflowHandlers['processQueue'] = async (_props) => {}
export const handleEvent: bp.WorkflowHandlers['processQueue'] = async (props) => {
await props.workflow.setFailed({ failureReason: 'Workflow timed out' })
}
Loading
Loading