superagent icon indicating copy to clipboard operation
superagent copied to clipboard

Suggestion for Enhancing Event Structure Standardization

Open jasgeo75 opened this issue 11 months ago • 1 comments

⚠️ Please check that this feature request hasn't been suggested before.

  • [X] I searched previous Ideas in Discussions didn't find any similar feature requests.
  • [X] I searched previous Issues didn't find any similar feature requests.

🔖 Feature description

I've noticed an opportunity to enhance the scalability and maintainability of server-client communication through the standardization of the event structure used in server-sent events. I believe this enhancement could make the system more robust and easier to work with, both for current and future contributors.

General Event Structure

Each event sent from the server follows this basic structure:

event: <event_type>
data: <json_formatted_data>

<event_type> is a string that specifies the type of the event (e.g., message, function_call, end-of-stream). <json_formatted_data> is a JSON string that contains the event's data. The structure of this data varies depending on the event type.

Specific Event Formats

1. Message Event

Used for sending generic messages or data.

event: message
data: {
  "content": "<message_content>"
}
  • <message_content>: The actual content of the message. It can be any string, including structured data serialized as a string.

2. Function Call Event

Used for indicating a function call, including the function name and arguments.

event: function_call
data: {
  "function": "<function_name>",
  "args": {
    "<arg_name>": "<arg_value>",
    ...
  }
}
  • <function_name>: The name of the function being called.
  • <arg_name>: The name of an argument to the function.
  • <arg_value>: The value of the argument. There can be multiple arg_name: arg_value pairs depending on the function's signature.

3. End-of-Stream Event

Indicates that the stream of events has concluded.

event: end-of-stream
data: {
  "status": "completed"
}
  • "status": "completed": A fixed message indicating the stream has ended successfully.

Rationale

Implementing a uniform structure for server-sent events can simplify event handling logic on the client side, reducing development overhead and potential errors. It also lays a foundation for easier expansion and incorporation of new event types in the future, enhancing the project's adaptability and growth potential.

Acknowledgements

  • [X] My issue title is concise and descriptive.
  • [X] I have searched the existing issues to make sure this feature has not been requested yet.
  • [X] I have provided enough information for the maintainers to understand and evaluate this request.

jasgeo75 avatar Mar 09 '24 22:03 jasgeo75

⚠️ Please check that this feature request hasn't been suggested before.

  • [X] I searched previous Ideas in Discussions didn't find any similar feature requests.
  • [X] I searched previous Issues didn't find any similar feature requests.

🔖 Feature description

I've noticed an opportunity to enhance the scalability and maintainability of server-client communication through the standardization of the event structure used in server-sent events. I believe this enhancement could make the system more robust and easier to work with, both for current and future contributors.

General Event Structure

Each event sent from the server follows this basic structure:


event: <event_type>

data: <json_formatted_data>

<event_type> is a string that specifies the type of the event (e.g., message, function_call, end-of-stream).

<json_formatted_data> is a JSON string that contains the event's data. The structure of this data varies depending on the event type.

Specific Event Formats

1. Message Event

Used for sending generic messages or data.


event: message

data: {

  "content": "<message_content>"

}

  • <message_content>: The actual content of the message. It can be any string, including structured data serialized as a string.

2. Function Call Event

Used for indicating a function call, including the function name and arguments.


event: function_call

data: {

  "function": "<function_name>",

  "args": {

    "<arg_name>": "<arg_value>",

    ...

  }

}

  • <function_name>: The name of the function being called.

  • <arg_name>: The name of an argument to the function.

  • <arg_value>: The value of the argument. There can be multiple arg_name: arg_value pairs depending on the function's signature.

3. End-of-Stream Event

Indicates that the stream of events has concluded.


event: end-of-stream

data: {

  "status": "completed"

}

  • "status": "completed": A fixed message indicating the stream has ended successfully.

Rationale

Implementing a uniform structure for server-sent events can simplify event handling logic on the client side, reducing development overhead and potential errors. It also lays a foundation for easier expansion and incorporation of new event types in the future, enhancing the project's adaptability and growth potential.

Acknowledgements

  • [X] My issue title is concise and descriptive.
  • [X] I have searched the existing issues to make sure this feature has not been requested yet.
  • [X] I have provided enough information for the maintainers to understand and evaluate this request.

I agree with this 100%. Would you be up for contributing?

homanp avatar Mar 09 '24 22:03 homanp