-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotocol.go
More file actions
64 lines (57 loc) · 1.78 KB
/
Copy pathprotocol.go
File metadata and controls
64 lines (57 loc) · 1.78 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
package main
import "time"
type Request struct {
Op string `json:"op"`
Args map[string]any `json:"args,omitempty"`
}
type Response struct {
OK bool `json:"ok"`
Data any `json:"data,omitempty"`
Error string `json:"error,omitempty"`
Code int `json:"code,omitempty"`
}
type ErrorDetail struct {
Code int `json:"code,omitempty"`
Reason string `json:"reason,omitempty"`
RetryHint string `json:"retry_hint,omitempty"`
Context map[string]any `json:"context,omitempty"`
}
type Message struct {
Seq int `json:"seq"`
From string `json:"from"`
TS time.Time `json:"ts"`
Body string `json:"body"`
}
const (
CodeOK = 0
CodeError = 1
CodeTimeout = 2
CodePeerClosed = 3
// CodeNotYourTurn is reserved; no longer produced now that channels have
// no turn FSM. Keep the slot so external tooling that still parses 4
// doesn't silently reuse the code for a new meaning.
CodeNotYourTurn = 4
CodeNotFound = 5
CodeUnauthorized = 6 // signature rejected or caller not registered
CodeSupervisorBusy = 7 // supervisor still owns a non-empty task list; handoff first
CodeProjectIdentityMismatch = 8 // publish payload project does not match caller's registered project
CodePIDConflict = 9 // PID already registered as a different live agent
CodeSessionConflict = 10 // re-registration conflicts with a live session's harness or CWD
)
func errorResponse(code int, reason, retryHint, message string, context map[string]any) Response {
if code == 0 {
code = CodeError
}
return Response{
Error: message,
Code: code,
Data: map[string]any{
"error": ErrorDetail{
Code: code,
Reason: reason,
RetryHint: retryHint,
Context: context,
},
},
}
}