这是indexloc提供的服务,不要输入任何密码
Skip to content

WIP: feat: add record synchronizer plugin #13985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 .github/workflows/deploy-integrations-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: ./.github/actions/deploy-plugins
with:
environment: 'production'
extra_filter: "-F '!analytics' -F '!logger' -F '!personality' -F '!synchronizer' -F '!knowledge'"
extra_filter: "-F '!analytics' -F '!logger' -F '!personality' -F '!synchronizer' -F '!knowledge' -F '!record-synchronizer'"
force: ${{ github.event.inputs.force == 'true' }}
token_cloud_ops_account: ${{ secrets.PRODUCTION_TOKEN_CLOUD_OPS_ACCOUNT }}
cloud_ops_workspace_id: ${{ secrets.PRODUCTION_CLOUD_OPS_WORKSPACE_ID }}
118 changes: 118 additions & 0 deletions interfaces/records-readonly/interface.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* bplint-disable */
import * as sdk from '@botpress/sdk'

const NEXT_TOKEN = sdk.z.string().optional().describe('The token to get the next page of records.')

export default new sdk.InterfaceDefinition({
name: 'records-readonly',
version: '0.1.0',
entities: {
record: {
title: 'Record',
description: 'A structured piece of data that can be enumerated and retrieved.',
schema: sdk.z.object({
id: sdk.z.string().describe('The unique identifier of the record. Could be a UUID or any other unique string.'),
lastModifiedDate: sdk.z
.string()
.datetime()
.optional()
.describe('The last modified date of the record, if available'),
revision: sdk.z.string().optional().describe('The revision number or version of the record, if available'),
}),
},
},
actions: {
enumerateRecords: {
attributes: {
...sdk.WELL_KNOWN_ATTRIBUTES.HIDDEN_IN_STUDIO,
},
title: 'List records',
description: 'List all records',
input: {
schema: () =>
sdk.z.object({
nextToken: NEXT_TOKEN.describe(
'The token to get the next page of records. Leave empty to get the first page.'
),
}),
},
output: {
schema: (entities) =>
sdk.z.object({
results: sdk.z
.array(
sdk.z
.union([
sdk.z.object({
type: sdk.z.literal('record'),
record: entities.record.describe('The actual record'),
}),
sdk.z.object({
type: sdk.z.literal('id'),
id: sdk.z.string().describe('The ID of the record'),
}),
])
.describe(
'Either a full record or just its ID. If an ID is provided, the record will be fetched later.'
)
)
.describe('The records retrieved from the external service'),
meta: sdk.z.object({
nextToken: NEXT_TOKEN,
}),
}),
},
},
fetchRecord: {
attributes: {
...sdk.WELL_KNOWN_ATTRIBUTES.HIDDEN_IN_STUDIO,
},
title: 'Fetch record',
description: 'Fetch a record by its ID',
input: {
schema: () =>
sdk.z.object({
id: sdk.z.string().describe('The ID of the record to fetch.'),
}),
},
output: {
schema: (entities) =>
sdk.z.object({
record: entities.record.describe('The record'),
}),
},
},
},
events: {
recordCreated: {
schema: (entities) =>
sdk.z.object({
record: entities.record.describe('The created record'),
}),
},
recordUpdated: {
schema: (entities) =>
sdk.z.object({
record: entities.record.describe('The updated record'),
}),
},
recordDeleted: {
schema: (entities) =>
sdk.z.object({
record: entities.record.describe('The deleted record'),
}),
},
aggregateRecordChanges: {
schema: (entities) =>
sdk.z.object({
modifiedRecords: sdk.z
.object({
created: sdk.z.array(entities.record).describe('The records created'),
updated: sdk.z.array(entities.record).describe('The records updated'),
deleted: sdk.z.array(entities.record).describe('The records deleted'),
})
.describe('The modified records'),
}),
},
},
})
16 changes: 16 additions & 0 deletions interfaces/records-readonly/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@botpresshub/records-readonly",
"description": "Read-only records interface for Botpress",
"private": true,
"scripts": {
"check:type": "tsc --noEmit",
"check:bplint": "bp lint"
},
"license": "MIT",
"dependencies": {
"@botpress/sdk": "workspace:*"
},
"devDependencies": {
"@botpress/cli": "workspace:*"
}
}
8 changes: 8 additions & 0 deletions interfaces/records-readonly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist"
},
"include": ["interface.definition.ts"]
}
21 changes: 21 additions & 0 deletions plugins/record-synchronizer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@botpresshub/record-synchronizer",
"scripts": {
"check:type": "tsc --noEmit",
"build": "bp add -y && bp build"
},
"private": true,
"dependencies": {
"@botpress/client": "workspace:*",
"@botpress/sdk": "workspace:*",
"picomatch": "^4.0.2"
},
"devDependencies": {
"@botpress/cli": "workspace:*",
"@botpresshub/hitl": "workspace:*",
"@types/picomatch": "^3.0.2"
},
"bpDependencies": {
"records-readonly": "../../interfaces/records-readonly"
}
}
43 changes: 43 additions & 0 deletions plugins/record-synchronizer/plugin.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as sdk from '@botpress/sdk'
import recordsReadonly from './bp_modules/records-readonly'

export default new sdk.PluginDefinition({
name: 'record-synchronizer',
version: '0.1.0',
title: 'Record Synchronizer',
description: 'Synchronize records from an external service to Botpress',
configuration: {
schema: sdk.z.object({}),
},
actions: {
syncRecordsToBotpess: {
title: 'Sync records to Botpress',
description: 'Start synchronization of records from the external service to Botpress',
input: {
schema: sdk.z.object({
filters: sdk.z
.object({
modifiedAfter: sdk.z
.string()
.datetime()
.optional()
.describe(
'Filter the records by modified date. Only records modified at or after the specified date will be synchronized.'
),
})
.title('Filters')
.describe('Optional filters to apply when synchronizing records.'),
}),
},
output: {
schema: sdk.z.object({
status: sdk.z.enum(['queued', 'already-running', 'error']),
}),
},
},
},
workflows: {},
interfaces: {
'records-readonly': recordsReadonly,
},
})
11 changes: 11 additions & 0 deletions plugins/record-synchronizer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as bp from '.botpress'

const plugin = new bp.Plugin({
actions: {
async syncRecordsToBotpess() {
throw new Error('Not implemented')
},
},
})

export default plugin
8 changes: 8 additions & 0 deletions plugins/record-synchronizer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist"
},
"include": [".botpress/**/*", "src/**/*"]
}
Loading