Repository navigation
Expand file tree
/
Copy pathconversation.go
More file actions
66 lines (56 loc) · 2.55 KB
/
Copy pathconversation.go
File metadata and controls
66 lines (56 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package verb
import (
"context"
"github.com/compforge/loopd/pkg/contract"
"github.com/compforge/loopd/runtime/model"
"github.com/compforge/loopd/runtime/service"
)
// Conv exposes persistent collaboration without Server transport details.
type Conv struct{ service service.Conv }
func NewConv(s service.Conv) Conv { return Conv{service: s} }
// Poll records receipt without committing consumption. While working, pass the last
// successful Position as After; on recovery omit After to replay uncommitted inputs.
// +spec=`Poll returns messages in every status, including streaming. Processing partial content and deciding when to Commit belong to the Operator.`
// Position tracks IDs, not revisions. Retain the Message ID and use Read (or a
// Harness Call) to follow later content after advancing past a streaming message.
func (c Conv) Poll(ctx context.Context, id string, request contract.PollRequest) (contract.PollResult, error) {
return c.service.Poll(ctx, id, request)
}
// Commit acknowledges a contiguous safely handled prefix, not business completion.
func (c Conv) Commit(ctx context.Context, id string, request contract.CommitRequest) error {
return c.service.Commit(ctx, id, request)
}
// Read creates a lazy reference. Only an explicit data read performs I/O.
func (c Conv) Read(conversationID, messageID string) model.Message {
return c.service.Read(conversationID, messageID)
}
// List reads bounded metadata and returns lazy handles, not message bodies.
func (c Conv) List(ctx context.Context, id string, query model.MessageQuery) (model.MessagePage, error) {
return c.service.List(ctx, id, query)
}
// Speak publishes complete content. Status may mark failure; use Tell for incremental output.
func (c Conv) Speak(ctx context.Context, id string, request contract.SpeakRequest) (model.Message, error) {
if request.Status == "" {
request.Status = contract.MessageStatusCompleted
}
if !request.Status.Terminal() {
return nil, model.ErrSpeakStatusInvalid
}
info, err := c.service.Create(ctx, id, request)
if err != nil {
return nil, err
}
return c.service.Read(id, info.ID), nil
}
// Tell starts or restores a streaming message. Its writer owns Emit/End.
func (c Conv) Tell(ctx context.Context, id string, request contract.SpeakRequest) (model.Stream, error) {
if request.Status != "" && request.Status != contract.MessageStatusStreaming {
return nil, model.ErrTellStatusInvalid
}
request.Status = contract.MessageStatusStreaming
info, err := c.service.Create(ctx, id, request)
if err != nil {
return nil, err
}
return c.service.Stream(info), nil
}