create-runtime-plugin.ts 944 B

1234567891011121314151617181920212223
  1. import { definePluginCreator, PluginContext } from '@flowgram.ai/free-layout-editor';
  2. import { RuntimePluginOptions } from './type';
  3. import { WorkflowRuntimeServerClient } from './server-client';
  4. import { WorkflowRuntimeService } from './runtime-service';
  5. import { WorkflowRuntimeClient } from './browser-client';
  6. export const createRuntimePlugin = definePluginCreator<RuntimePluginOptions, PluginContext>({
  7. onBind({ bind, rebind }, options) {
  8. bind(WorkflowRuntimeClient).toSelf().inSingletonScope();
  9. bind(WorkflowRuntimeServerClient).toSelf().inSingletonScope();
  10. if (options.mode === 'server') {
  11. rebind(WorkflowRuntimeClient).to(WorkflowRuntimeServerClient);
  12. }
  13. bind(WorkflowRuntimeService).toSelf().inSingletonScope();
  14. },
  15. onInit(ctx, options) {
  16. if (options.mode === 'server') {
  17. const serverClient = ctx.get(WorkflowRuntimeServerClient);
  18. serverClient.init(options.serverConfig);
  19. }
  20. },
  21. });