-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
219 lines (186 loc) · 6.22 KB
/
Copy pathtypes.go
File metadata and controls
219 lines (186 loc) · 6.22 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package chat
import (
"context"
"net/http"
)
type BotKind int
const (
BotUnknown BotKind = iota
BotHuman
BotBot
)
type Actor struct {
Adapter string
Tenant string
ID string
Name string
BotKind BotKind
}
type ThreadID string
type ThreadRef struct {
ID ThreadID
Adapter string
Tenant string
Channel string
Root string
Direct bool
Raw any
}
type RetryMetadata struct {
Num string
Reason string
}
type Event struct {
ID string
Adapter string
Tenant string
ThreadID ThreadID
DirectMessage bool
// At most one of Message, Command, or Interaction is set: a Command Event and
// an Interaction Event are Events, never Messages.
Message *Message
Command *Command
Interaction *Interaction
Retry RetryMetadata
Raw any
}
type Message struct {
ID string
Text string
Author Actor
Mentioned bool
Raw any
}
type MessageEvent struct {
Event *Event
Thread *Thread
Message *Message
}
type MessageHandler func(context.Context, *MessageEvent) error
// Command is the normalized payload of a Command Event: a deliberate,
// parameterized platform invocation (a Slack slash command, a Teams
// command/invoke). A Command Event is an Event, never a Message.
type Command struct {
Name string
Text string
Args []string // advisory whitespace split of Text, not a parser
Actor Actor
Raw any // Platform Escape Hatch: response_url, trigger_id, Teams invoke value
}
type CommandEvent struct {
Event *Event
Thread *Thread
Command *Command
}
type CommandHandler func(context.Context, *CommandEvent) error
// InteractionKind classifies an Interaction Event. This slice supports
// block_actions (button clicks and menu selections) only.
type InteractionKind int
const (
InteractionUnknown InteractionKind = iota
// InteractionBlockAction is a Slack block_actions interaction: a button click
// or a menu selection.
InteractionBlockAction
)
// Interaction is the normalized payload of an Interaction Event: a Block Kit /
// card component action. Like a Command Event, an Interaction Event is an Event,
// never a Message.
type Interaction struct {
Kind InteractionKind
ActionID string
Actor Actor
Raw any // Platform Escape Hatch: response_url, trigger_id, action values, view state
}
type InteractionEvent struct {
Event *Event
Thread *Thread
Interaction *Interaction
}
type InteractionHandler func(context.Context, *InteractionEvent) error
type DispatchFunc func(context.Context, *Event) error
type Adapter interface {
Name() string
Init(context.Context) error
Shutdown(context.Context) error
Webhook(DispatchFunc) http.Handler
ValidateThreadID(ThreadID) (ThreadRef, error)
PostMessage(context.Context, ThreadRef, PostableMessage) (*SentMessage, error)
BotActor() Actor
}
type MessageFormat int
const (
MessageFormatText MessageFormat = iota
MessageFormatMarkdown
)
type PostableMessage struct {
Text string
Format MessageFormat
}
func Text(text string) PostableMessage {
return PostableMessage{Text: text, Format: MessageFormatText}
}
func Markdown(text string) PostableMessage {
return PostableMessage{Text: text, Format: MessageFormatMarkdown}
}
type SentMessage struct {
ID string
ThreadID ThreadID
Raw any
}
type EphemeralOptions struct {
FallbackToDM bool
}
type EphemeralPoster interface {
PostEphemeralMessage(context.Context, ThreadRef, Actor, PostableMessage, EphemeralOptions) (*SentMessage, error)
}
// NativeContent carries an explicitly platform-native message body (Slack Block
// Kit blocks, a Teams Adaptive Card) as a Platform Escape Hatch. It is NOT a
// cross-platform card model and does NOT widen Postable Message; Plain Text and
// Portable Markdown remain the portable surface. Native content is reached only
// through the NativeContentPoster Optional Capability via typed Adapter Access.
type NativeContent struct {
// Adapter must match the target adapter; a mismatch is an error, never a
// silent portable downgrade.
Adapter string
Payload any
}
// NativeContentPoster is the Optional Capability for posting NativeContent.
// Adapters that support native rich content implement it; callers reach it via
// chat.AdapterAs. Absence of the capability is an explicit unsupported result,
// not a panic.
type NativeContentPoster interface {
PostNative(context.Context, ThreadRef, NativeContent) (*SentMessage, error)
}
// HistoryQuery parameterizes a HistoryReader read. Pagination and ordering are
// adapter-owned (platform read APIs differ) and documented in each adapter's
// GoDoc; this struct imposes no portable pagination model.
type HistoryQuery struct {
// Limit is the desired page size. The adapter clamps it to the platform's
// maximum and applies its own default when Limit <= 0.
Limit int
// Before is an optional opaque cursor: a Message.ID returned by a prior page.
// It is a plain string (NOT a fabricated MessageID type); the adapter
// interprets it per its platform read API.
Before string
}
// HistoryReader is an Optional Capability: an adapter implements it only when the
// platform exposes a conversation read API. It is reached exclusively through
// typed Adapter Access (chat.AdapterAs); it is NOT a method on the core Adapter
// interface, NOT a Routing Hook input, and is never auto-invoked during Runtime
// Dispatch.
//
// ReadHistory is a live platform read keyed by the opaque Thread ID. It performs
// NO runtime storage: it does not write Runtime State, does not dedupe via Event
// Identity, and does not cache. Returned Messages are normalized with raw platform
// data preserved via the Platform Escape Hatch (Message.Raw). Ordering, pagination,
// and page-size clamping are adapter-owned and documented in the adapter's GoDoc.
//
// Stored/long-term conversation context (transcripts, LLM context windows,
// summaries, RAG corpora) is Thread Application State, owned by the application in
// its own storage keyed by Thread ID; this capability is a thin live read-through
// only. Absence of the capability is the explicit ErrUnsupportedCapability result
// (via AdapterAs returning ok == false), never an empty []Message that masquerades
// as "no history".
type HistoryReader interface {
ReadHistory(context.Context, ThreadID, HistoryQuery) ([]Message, error)
}