openworkflow_dart 0.1.0 copy "openworkflow_dart: ^0.1.0" to clipboard
openworkflow_dart: ^0.1.0 copied to clipboard

A workflow JSON Spec Parser for dart with service.

example/openworkflow_dart_example.dart

import 'dart:convert';
import 'dart:io';
import 'package:opentool_dart/opentool_dart.dart';
import 'package:openworkflow_dart/openworkflow_dart.dart';
import 'custom_driver/mock_driver.dart';

Future<void> main() async {
  ToolDriver mockDriver = await _buildToolDriver();
  OpenWorkflow openWorkflow = await _buildWorkflow();
  Session session = _buildSession();

  WorkflowService workflow = WorkflowService([mockDriver], openWorkflow, session);

  workflow.run();
}

Future<ToolDriver> _buildToolDriver() async {
  String folder = "${Directory.current.path}${Platform.pathSeparator}example";
  String jsonFileName = "mock_tool.json";
  String jsonPath = "$folder${Platform.pathSeparator}custom_driver${Platform.pathSeparator}$jsonFileName";
  OpenTool openTool = await OpenToolLoader().loadFromFile(jsonPath);
  MockDriver mockDriver = MockDriver(openTool);
  return mockDriver;
}

Future<OpenWorkflow> _buildWorkflow() async {
  String folder = "${Directory.current.path}${Platform.pathSeparator}example";
  String workflowJson = "openworkflow-crud-example.json";
  OpenWorkflow openWorkflow = await OpenWorkflowLoader().loadFromFile("$folder${Platform.pathSeparator}json${Platform.pathSeparator}$workflowJson");
  return openWorkflow;
}

Session _buildSession() {
  Session session = Session();
  session.addMessageListener(listen);
  return session;
}

void listen(OperationMessage operationMessage) {
  print(jsonEncode(operationMessage.toJson())
      .replaceAll(OperationType.FUNCTION_CALL, "👉${OperationType.FUNCTION_CALL}")
      .replaceAll(OperationType.TOOL_RETURN, "⬅️${OperationType.TOOL_RETURN}")
      .replaceAll(OperationType.FINISH, "✅${OperationType.FINISH}")
  );
}
0
likes
90
points
20
downloads

Publisher

unverified uploader

Weekly Downloads

A workflow JSON Spec Parser for dart with service.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

json_annotation, opentool_dart

More

Packages that depend on openworkflow_dart