Skip to content
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

Enhancements to messages defined in BrowserTypes #1268

Closed
Tracked by #1267
Roaders opened this issue Jul 17, 2024 · 2 comments
Closed
Tracked by #1267

Enhancements to messages defined in BrowserTypes #1268

Roaders opened this issue Jul 17, 2024 · 2 comments
Labels
Milestone

Comments

@Roaders
Copy link
Contributor

Roaders commented Jul 17, 2024

Enhancement Request

Use Case:

I am a developer implementing a Desktop Agent Proxy that will use the proposed messaging protocol to communicate with a Desktop Agent. The types defined in BrowserTypes are very helpful but there are things that can be done to make things easier.

  • Have a union type of all messages called FDC3Message (name is just an example. I am not good at naming things! feel free to suggest a different name)
  • The FDC3Message union type should be composed of 2 other union types RequestMessage and ResponseMessage
  • Have a RequestMessageBase and a ResponseMessageBase. All response messages should have a source: AppIdentifier and request / response uuid in the meta object for example (I am not sure how practical this is but some commanality between messages would be great)
  • Have a type predicate defined for each message type:
export function isAddContextListenerRequest(value: any): value is AddContextListenerRequest{
    return (value as AddContextListenerRequest).type === "addContextListenerRequest"; 
}

This isn't necessarily the desired implementation - we could probably use some of the logic from the Convert class to do a better check that it is in fact a valid message. The important bit is the type predicate return type.

We have already implemeted a lot of type predicates and union types but I am not sure how useful it would be to contribute these as I understand that the BrowserTypes are generated by magic so that magic should probably also generate the predicates and union types.

@Roaders Roaders added the enhancement New feature or request label Jul 17, 2024
@kriswest
Copy link
Contributor

@Roaders There exist AppRequestMessage, AgentResponseMessage and AgentEvent message schemas and types. See:

  • export interface AppRequestMessage {
    /**
    * Metadata for a request message sent by an FDC3-enabled app to a Desktop Agent.
    */
    meta: AppRequestMessageMeta;
    /**
    * The message payload typically contains the arguments to FDC3 API functions.
    */
    payload: { [key: string]: any };
    /**
    * Identifies the type of the message and it is typically set to the FDC3 function name that
    * the message relates to, e.g. 'findIntent', with 'Request' appended.
    */
    type: RequestMessageType;
    }
  • export interface AgentResponseMessage {
    /**
    * Metadata for messages sent by a Desktop Agent to an App in response to an API call
    */
    meta: AgentResponseMessageMeta;
    /**
    * A payload for a response to an API call that will contain any return values or an `error`
    * property containing a standardized error message indicating that the request was
    * unsuccessful.
    */
    payload: AgentResponseMessageResponsePayload;
    /**
    * Identifies the type of the message and it is typically set to the FDC3 function name that
    * the message relates to, e.g. 'findIntent', with 'Response' appended.
    */
    type: ResponseMessageType;
    }
  • export interface AgentEventMessage {
    /**
    * Metadata for messages sent by a Desktop Agent to an App notifying it of an event.
    */
    meta: AgentEventMessageMeta;
    /**
    * The message payload contains details of the event that the app is being notified about.
    */
    payload: { [key: string]: any };
    /**
    * Identifies the type of the message and it is typically set to the FDC3 function name that
    * the message relates to, e.g. 'findIntent', with 'Response' appended.
    */
    type: EventMessageType;
    }

The types are structurally compatible with all messages derived from them so you can use them to write generalized TypeScript code in your implementation. However, as we generate the TypeScript code from the schemas, the type definitions of specific message types don't formally extend these types - but as TypeScript uses structural compatibility rather than than more traditional declarative typing that should not matter (other than it feeling a little odd to those of us that grew up with OO languages).

Given the number of messages, we should try to avoid creating a manual maintenance situation wherever possible (lest we incur the wrath of future generations of FDC3 maintainers). However, I believe it could/should be possible to come up with a way to generate some of your above suggestions by post processing the BrowserTypes file.

Type detection does seem like something the Convert class could be doing...

@kriswest
Copy link
Contributor

kriswest commented Dec 5, 2024

Closed as completed - merged into fdc3-for-web-impl branch

@kriswest kriswest closed this as completed Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants