-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
309 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
internal/core/plugin_daemon/backwards_invocation/entities.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package backwards_invocation | ||
|
||
type RequestEvent string | ||
|
||
const ( | ||
REQUEST_EVENT_RESPONSE RequestEvent = "response" | ||
REQUEST_EVENT_ERROR RequestEvent = "error" | ||
REQUEST_EVENT_END RequestEvent = "end" | ||
) | ||
|
||
type BaseRequestEvent struct { | ||
BackwardsRequestId string `json:"backwards_request_id"` | ||
Event RequestEvent `json:"event"` | ||
Message string `json:"message"` | ||
Data map[string]any `json:"data"` | ||
} | ||
|
||
func NewResponseEvent(request_id string, message string, data map[string]any) *BaseRequestEvent { | ||
return &BaseRequestEvent{ | ||
BackwardsRequestId: request_id, | ||
Event: REQUEST_EVENT_RESPONSE, | ||
Message: message, | ||
Data: data, | ||
} | ||
} | ||
|
||
func NewErrorEvent(request_id string, message string) *BaseRequestEvent { | ||
return &BaseRequestEvent{ | ||
BackwardsRequestId: request_id, | ||
Event: REQUEST_EVENT_ERROR, | ||
Message: message, | ||
Data: nil, | ||
} | ||
} | ||
|
||
func NewEndEvent(request_id string) *BaseRequestEvent { | ||
return &BaseRequestEvent{ | ||
BackwardsRequestId: request_id, | ||
Event: REQUEST_EVENT_END, | ||
Message: "", | ||
Data: nil, | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
internal/core/plugin_daemon/backwards_invocation/request.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package backwards_invocation | ||
|
||
import ( | ||
"github.com/langgenius/dify-plugin-daemon/internal/core/dify_invocation" | ||
"github.com/langgenius/dify-plugin-daemon/internal/core/session_manager" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/parser" | ||
) | ||
|
||
type BackwardsInvocationType = dify_invocation.InvokeType | ||
|
||
type BackwardsInvocation struct { | ||
typ BackwardsInvocationType | ||
id string | ||
detailed_request map[string]any | ||
session *session_manager.Session | ||
} | ||
|
||
func NewBackwardsInvocation( | ||
typ BackwardsInvocationType, | ||
id string, session *session_manager.Session, detailed_request map[string]any, | ||
) *BackwardsInvocation { | ||
return &BackwardsInvocation{ | ||
typ: typ, | ||
id: id, | ||
detailed_request: detailed_request, | ||
session: session, | ||
} | ||
} | ||
|
||
func (bi *BackwardsInvocation) GetID() string { | ||
return bi.id | ||
} | ||
|
||
func (bi *BackwardsInvocation) WriteError(err error) { | ||
bi.session.Write(parser.MarshalJsonBytes(NewErrorEvent(bi.id, err.Error()))) | ||
} | ||
|
||
func (bi *BackwardsInvocation) Write(message string, data map[string]any) { | ||
bi.session.Write(parser.MarshalJsonBytes(NewResponseEvent(bi.id, message, data))) | ||
} | ||
|
||
func (bi *BackwardsInvocation) End() { | ||
bi.session.Write(parser.MarshalJsonBytes(NewEndEvent(bi.id))) | ||
} | ||
|
||
func (bi *BackwardsInvocation) Type() BackwardsInvocationType { | ||
return bi.typ | ||
} | ||
|
||
func (bi *BackwardsInvocation) RequestData() map[string]any { | ||
return bi.detailed_request | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.