-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchannels.mnm
More file actions
161 lines (134 loc) · 3.59 KB
/
Copy pathchannels.mnm
File metadata and controls
161 lines (134 loc) · 3.59 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
# channels.mnm
# Multi-channel ingestion with update support
# Demonstrates ingesting data from multiple messaging platforms
config {
storage: sqlite("./data/channels.db")
vector: auto("qdrant")
graph: auto("neo4j")
embedding: openai("text-embedding-3-small")
extractor: openai("gpt-4o-mini")
}
namespace team_memory {
memory Message {
content: string
author: string
source: string
channel: string
message_id: string?
subject: string
predicate: string
object: string
confidence: float[0,1]
created_at: timestamp
@index source
@index author
@index subject
@index predicate
}
# ─── Slack Channel ─────────────────────────────────────────
channel slack_feed {
source: slack
config {
token: env("SLACK_TOKEN")
}
poll_interval: 5m
on message -> ingest(content: string, author: string) {
content
|> extract()
|> store()
}
on edit -> update(content: string, message_id: string) {
content
|> extract()
|> store()
}
on delete(message_id: string) {
let msg = from Message
where message_id == message_id
limit 1
}
}
# ─── Discord Channel ───────────────────────────────────────
channel discord_feed {
source: discord
config {
token: env("DISCORD_TOKEN")
}
poll_interval: 5m
on message -> ingest(content: string, author: string) {
content
|> extract()
|> store()
}
on edit -> update(content: string) {
content
|> extract()
|> store()
}
}
# ─── Telegram Channel ──────────────────────────────────────
channel telegram_feed {
source: telegram
config {
token: env("TELEGRAM_BOT_TOKEN")
}
poll_interval: 1m
on message -> ingest(content: string, author: string) {
content
|> extract()
|> store()
}
on edit -> update(content: string) {
content
|> extract()
|> store()
}
}
# ─── Webhook (generic) ─────────────────────────────────────
channel webhook_feed {
source: webhook
config {
endpoint: env("WEBHOOK_URL")
}
poll_interval: 30s
on message -> ingest(content: string) {
content
|> extract()
|> store()
}
}
# ─── Queries ────────────────────────────────────────────────
on ingest(content: string) {
content
|> extract()
|> store()
}
query Search(input: string): Message[] {
from Message
where semantic_match(input, threshold: 0.5)
order by created_at desc
limit 20
}
query BySource(source: string): Message[] {
from Message
where source == source
order by created_at desc
limit 50
}
query ByAuthor(author: string): Message[] {
from Message
where author == author
order by created_at desc
limit 50
}
# ─── Update Rules ──────────────────────────────────────────
update Message {
on_conflict(old, new) {
if new.confidence > old.confidence {
supersede(old, new)
} else {
discard(new)
}
}
}
}