chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:34:48 +08:00
commit 77bb5bf71f
3762 changed files with 353249 additions and 0 deletions
@@ -0,0 +1,54 @@
import * as sdk from '@botpress/sdk'
import { zuiSchemaToTypeScriptType } from '../../generators'
import { Module, ReExportTypeModule } from '../../module'
import * as strings from '../../strings'
type ActionInput = sdk.ActionDefinition['input']
type ActionOutput = sdk.ActionDefinition['output']
export class ActionInputModule extends Module {
public constructor(private _input: ActionInput) {
const name = 'input'
const exportName = strings.typeName(name)
super({ path: `${name}.ts`, exportName })
}
public async getContent() {
return zuiSchemaToTypeScriptType(this._input.schema, this.exportName)
}
}
export class ActionOutputModule extends Module {
public constructor(private _output: ActionOutput) {
const name = 'output'
const exportName = strings.typeName(name)
super({ path: `${name}.ts`, exportName })
}
public async getContent() {
return zuiSchemaToTypeScriptType(this._output.schema, this.exportName)
}
}
export class ActionModule extends ReExportTypeModule {
public constructor(actionName: string, action: sdk.ActionDefinition) {
super({ exportName: strings.typeName(actionName) })
const inputModule = new ActionInputModule(action.input)
const outputModule = new ActionOutputModule(action.output)
this.pushDep(inputModule)
this.pushDep(outputModule)
}
}
export class ActionsModule extends ReExportTypeModule {
public constructor(actions: Record<string, sdk.ActionDefinition>) {
super({ exportName: strings.typeName('actions') })
for (const [actionName, action] of Object.entries(actions)) {
const module = new ActionModule(actionName, action)
module.unshift(actionName)
this.pushDep(module)
}
}
}
@@ -0,0 +1,85 @@
import * as sdk from '@botpress/sdk'
import { GENERATED_HEADER, INDEX_FILE } from '../../consts'
import { zuiSchemaToTypeScriptType, stringifySingleLine } from '../../generators'
import { Module, ReExportTypeModule } from '../../module'
import * as strings from '../../strings'
class MessageModule extends Module {
public constructor(
name: string,
private _message: sdk.MessageDefinition
) {
super({
path: `${name}.ts`,
exportName: strings.typeName(name),
})
}
public async getContent() {
return zuiSchemaToTypeScriptType(this._message.schema, this.exportName)
}
}
class MessagesModule extends ReExportTypeModule {
public constructor(channel: sdk.ChannelDefinition) {
super({ exportName: strings.typeName('messages') })
for (const [messageName, message] of Object.entries(channel.messages ?? {})) {
const module = new MessageModule(messageName, message)
this.pushDep(module)
}
}
}
class ChannelModule extends Module {
private _messagesModule: MessagesModule
public constructor(
channelName: string,
private _channel: sdk.ChannelDefinition
) {
super({
path: INDEX_FILE,
exportName: strings.typeName(channelName),
})
this._messagesModule = new MessagesModule(_channel)
this._messagesModule.unshift('messages')
this.pushDep(this._messagesModule)
}
public async getContent() {
const messageImport = this._messagesModule.import(this)
const conversation = {
tags: this._channel.conversation?.tags ?? {},
creation: this._channel.conversation?.creation ?? { enabled: false, requiredTags: [] },
}
const message = {
tags: this._channel.message?.tags ?? {},
}
return [
GENERATED_HEADER,
`import { ${this._messagesModule.exportName} } from './${messageImport}'`,
`export * from './${messageImport}'`,
'',
`export type ${this.exportName} = {`,
` messages: ${this._messagesModule.exportName}`,
` message: ${stringifySingleLine(message)}`,
` conversation: ${stringifySingleLine(conversation)}`,
'}',
].join('\n')
}
}
export class ChannelsModule extends ReExportTypeModule {
public constructor(channels: Record<string, sdk.ChannelDefinition>) {
super({ exportName: strings.typeName('channels') })
for (const [channelName, channel] of Object.entries(channels)) {
const module = new ChannelModule(channelName, channel)
module.unshift(channelName)
this.pushDep(module)
}
}
}
@@ -0,0 +1,26 @@
import * as sdk from '@botpress/sdk'
import { INDEX_FILE } from '../../consts'
import { zuiSchemaToTypeScriptType } from '../../generators'
import { Module } from '../../module'
import * as strings from '../../strings'
export class DefaultConfigurationModule extends Module {
public constructor(private _configuration: sdk.ConfigurationDefinition | undefined) {
const name = 'configuration'
const exportName = strings.typeName(name)
super({
path: INDEX_FILE,
exportName,
})
}
public async getContent() {
if (!this._configuration) {
return [
'/** Default Configuration of the Integration */',
'export type Configuration = Record<string, never>;',
].join('\n')
}
return zuiSchemaToTypeScriptType(this._configuration.schema, this.exportName)
}
}
@@ -0,0 +1,36 @@
import * as sdk from '@botpress/sdk'
import { zuiSchemaToTypeScriptType } from '../../generators'
import { Module, ReExportTypeModule } from '../../module'
import * as strings from '../../strings'
export class ConfigurationModule extends Module {
public constructor(
name: string,
private _configuration: sdk.ConfigurationDefinition
) {
const configurationName = name
const exportName = strings.typeName(`${configurationName}Config`)
super({
path: `${name}.ts`,
exportName,
})
}
public async getContent() {
const { schema } = this._configuration
if (!schema) {
return `export type ${this.exportName} = Record<string, never>;`
}
return zuiSchemaToTypeScriptType(schema, this.exportName)
}
}
export class ConfigurationsModule extends ReExportTypeModule {
public constructor(configurations: Record<string, sdk.ConfigurationDefinition>) {
super({ exportName: strings.typeName('configurations') })
for (const [configurationName, configuration] of Object.entries(configurations)) {
const module = new ConfigurationModule(configurationName, configuration)
this.pushDep(module)
}
}
}
@@ -0,0 +1,30 @@
import * as sdk from '@botpress/sdk'
import { zuiSchemaToTypeScriptType } from '../../generators'
import { Module, ReExportTypeModule } from '../../module'
import * as strings from '../../strings'
export class EntityModule extends Module {
public constructor(
name: string,
private _entity: sdk.EntityDefinition
) {
const entityName = name
const exportName = strings.typeName(entityName)
super({ path: `${name}.ts`, exportName })
}
public async getContent() {
return zuiSchemaToTypeScriptType(this._entity.schema, this.exportName)
}
}
export class EntitiesModule extends ReExportTypeModule {
public constructor(entities: Record<string, sdk.EntityDefinition>) {
super({ exportName: strings.typeName('entities') })
for (const [entityName, entity] of Object.entries(entities)) {
const module = new EntityModule(entityName, entity)
this.pushDep(module)
}
}
}
@@ -0,0 +1,29 @@
import * as sdk from '@botpress/sdk'
import { zuiSchemaToTypeScriptType } from '../../generators'
import { Module, ReExportTypeModule } from '../../module'
import * as strings from '../../strings'
export class EventModule extends Module {
public constructor(
name: string,
private _event: sdk.EventDefinition
) {
const eventName = name
const exportName = strings.typeName(eventName)
super({ path: `${name}.ts`, exportName })
}
public async getContent() {
return zuiSchemaToTypeScriptType(this._event.schema, this.exportName)
}
}
export class EventsModule extends ReExportTypeModule {
public constructor(events: Record<string, sdk.EventDefinition>) {
super({ exportName: strings.typeName('events') })
for (const [eventName, event] of Object.entries(events)) {
const module = new EventModule(eventName, event)
this.pushDep(module)
}
}
}
@@ -0,0 +1,127 @@
import * as sdk from '@botpress/sdk'
import { GENERATED_HEADER, INDEX_FILE } from '../../consts'
import { stringifySingleLine } from '../../generators'
import { Module } from '../../module'
import { ActionsModule } from './actions-module'
import { ChannelsModule } from './channels-module'
import { DefaultConfigurationModule } from './configuration-module'
import { ConfigurationsModule } from './configurations-module'
import { EntitiesModule } from './entities-module'
import { EventsModule } from './events-module'
import { StatesModule } from './states-module'
type IntegrationTypingsModuleDependencies = {
defaultConfigModule: DefaultConfigurationModule
configurationsModule: ConfigurationsModule
actionsModule: ActionsModule
channelsModule: ChannelsModule
eventsModule: EventsModule
statesModule: StatesModule
entitiesModule: EntitiesModule
}
export class IntegrationTypingsModule extends Module {
private _dependencies: IntegrationTypingsModuleDependencies
public constructor(private _integration: sdk.IntegrationPackage['definition']) {
super({
path: INDEX_FILE,
exportName: 'TIntegration',
})
const defaultConfigModule = new DefaultConfigurationModule(_integration.configuration)
defaultConfigModule.unshift('configuration')
const configurationsModule = new ConfigurationsModule(_integration.configurations ?? {})
configurationsModule.unshift('configurations')
const actionsModule = new ActionsModule(_integration.actions ?? {})
actionsModule.unshift('actions')
const channelsModule = new ChannelsModule(_integration.channels ?? {})
channelsModule.unshift('channels')
const eventsModule = new EventsModule(_integration.events ?? {})
eventsModule.unshift('events')
const statesModule = new StatesModule(_integration.states ?? {})
statesModule.unshift('states')
const entitiesModule = new EntitiesModule(_integration.entities ?? {})
entitiesModule.unshift('entities')
this._dependencies = {
defaultConfigModule,
configurationsModule,
actionsModule,
channelsModule,
eventsModule,
statesModule,
entitiesModule,
}
for (const dep of Object.values(this._dependencies)) {
this.pushDep(dep)
}
}
public async getContent() {
let content = ''
const {
defaultConfigModule,
configurationsModule,
actionsModule,
channelsModule,
eventsModule,
statesModule,
entitiesModule,
} = this._dependencies
const defaultConfigImport = defaultConfigModule.import(this)
const configurationsImport = configurationsModule.import(this)
const actionsImport = actionsModule.import(this)
const channelsImport = channelsModule.import(this)
const eventsImport = eventsModule.import(this)
const statesImport = statesModule.import(this)
const entitiesImport = entitiesModule.import(this)
const user = {
tags: this._integration.user?.tags ?? {},
creation: this._integration.user?.creation ?? { enabled: false, requiredTags: [] },
}
content += [
GENERATED_HEADER,
`import * as ${defaultConfigModule.name} from "./${defaultConfigImport}"`,
`import * as ${configurationsModule.name} from "./${configurationsImport}"`,
`import * as ${actionsModule.name} from "./${actionsImport}"`,
`import * as ${channelsModule.name} from "./${channelsImport}"`,
`import * as ${eventsModule.name} from "./${eventsImport}"`,
`import * as ${statesModule.name} from "./${statesImport}"`,
`import * as ${entitiesModule.name} from "./${entitiesImport}"`,
`export * as ${defaultConfigModule.name} from "./${defaultConfigImport}"`,
`export * as ${configurationsModule.name} from "./${configurationsImport}"`,
`export * as ${actionsModule.name} from "./${actionsImport}"`,
`export * as ${channelsModule.name} from "./${channelsImport}"`,
`export * as ${eventsModule.name} from "./${eventsImport}"`,
`export * as ${statesModule.name} from "./${statesImport}"`,
`export * as ${entitiesModule.name} from "./${entitiesImport}"`,
'',
'export type TIntegration = {',
` name: "${this._integration.name}"`,
` version: "${this._integration.version}"`,
` user: ${stringifySingleLine(user)}`,
` configuration: ${defaultConfigModule.name}.${defaultConfigModule.exportName}`,
` configurations: ${configurationsModule.name}.${configurationsModule.exportName}`,
` actions: ${actionsModule.name}.${actionsModule.exportName}`,
` channels: ${channelsModule.name}.${channelsModule.exportName}`,
` events: ${eventsModule.name}.${eventsModule.exportName}`,
` states: ${statesModule.name}.${statesModule.exportName}`,
` entities: ${entitiesModule.name}.${entitiesModule.exportName}`,
'}',
].join('\n')
return content
}
}
@@ -0,0 +1,62 @@
import * as sdk from '@botpress/sdk'
import * as consts from '../../consts'
import * as gen from '../../generators'
import { Module, ReExportTypeModule } from '../../module'
import * as strings from '../../strings'
export class StatePayloadModule extends Module {
public constructor(private _state: sdk.StateDefinition) {
super({
path: 'payload.ts',
exportName: strings.typeName('Payload'),
})
}
public async getContent() {
return gen.zuiSchemaToTypeScriptType(this._state.schema, 'Payload')
}
}
export class StateModule extends Module {
private _payloadModule: StatePayloadModule
public constructor(
private _name: string,
private _state: sdk.StateDefinition
) {
super({
path: consts.INDEX_FILE,
exportName: strings.typeName(_name),
})
this._payloadModule = new StatePayloadModule(_state)
this.pushDep(this._payloadModule)
}
public async getContent(): Promise<string> {
const { _payloadModule } = this
const payloadImport = _payloadModule.import(this)
const exportName = strings.typeName(this._name)
return [
consts.GENERATED_HEADER,
`import * as ${_payloadModule.name} from './${payloadImport}'`,
`export type ${exportName} = {`,
` type: ${gen.primitiveToTypescriptValue(this._state.type)},`,
` payload: ${_payloadModule.name}.${_payloadModule.exportName}`,
'}',
].join('\n')
}
}
export class StatesModule extends ReExportTypeModule {
public constructor(states: Record<string, sdk.StateDefinition>) {
super({ exportName: strings.typeName('states') })
for (const [stateName, state] of Object.entries(states)) {
const module = new StateModule(stateName, state)
module.unshift(stateName)
this.pushDep(module)
}
}
}