@bytesbrains/pi-telegram-bridge 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/index.test.ts +503 -483
- package/src/index.ts +403 -346
- package/src/templates.ts +789 -0
- package/src/tools/telegram.ts +201 -8
package/src/tools/telegram.ts
CHANGED
|
@@ -6,22 +6,215 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Type } from "typebox";
|
|
8
8
|
|
|
9
|
+
// ── Rich Notification Kind ─────────────────────────────────────────
|
|
10
|
+
// Agent picks a "kind" and fills the matching fields.
|
|
11
|
+
// The telegram_notify tool formats it with templates.ts and sends.
|
|
12
|
+
|
|
13
|
+
export const notifySchema = Type.Object({
|
|
14
|
+
kind: Type.Union([
|
|
15
|
+
Type.Literal("issue"),
|
|
16
|
+
Type.Literal("pr"),
|
|
17
|
+
Type.Literal("task"),
|
|
18
|
+
Type.Literal("pipeline"),
|
|
19
|
+
Type.Literal("session"),
|
|
20
|
+
Type.Literal("alert"),
|
|
21
|
+
Type.Literal("factory-job"),
|
|
22
|
+
Type.Literal("standup"),
|
|
23
|
+
Type.Literal("diff"),
|
|
24
|
+
Type.Literal("decision"),
|
|
25
|
+
Type.Literal("ack"),
|
|
26
|
+
]),
|
|
27
|
+
|
|
28
|
+
// ── Issue fields ─────────────────────────────────────
|
|
29
|
+
issueNumber: Type.Optional(Type.Number()),
|
|
30
|
+
issueTitle: Type.Optional(Type.String()),
|
|
31
|
+
issueState: Type.Optional(
|
|
32
|
+
Type.Union([Type.Literal("open"), Type.Literal("closed")]),
|
|
33
|
+
),
|
|
34
|
+
issueStatus: Type.Optional(Type.String()),
|
|
35
|
+
issueAssignee: Type.Optional(Type.String()),
|
|
36
|
+
issueLabels: Type.Optional(Type.Array(Type.String())),
|
|
37
|
+
issueMilestone: Type.Optional(Type.String()),
|
|
38
|
+
issueRepoOwner: Type.Optional(Type.String()),
|
|
39
|
+
issueRepoName: Type.Optional(Type.String()),
|
|
40
|
+
issueBranch: Type.Optional(Type.String()),
|
|
41
|
+
issuePRNumber: Type.Optional(Type.Number()),
|
|
42
|
+
issuePRStatus: Type.Optional(Type.String()),
|
|
43
|
+
issueUrl: Type.Optional(Type.String()),
|
|
44
|
+
|
|
45
|
+
// ── PR fields ────────────────────────────────────────
|
|
46
|
+
prNumber: Type.Optional(Type.Number()),
|
|
47
|
+
prTitle: Type.Optional(Type.String()),
|
|
48
|
+
prState: Type.Optional(
|
|
49
|
+
Type.Union([
|
|
50
|
+
Type.Literal("open"),
|
|
51
|
+
Type.Literal("closed"),
|
|
52
|
+
Type.Literal("merged"),
|
|
53
|
+
Type.Literal("draft"),
|
|
54
|
+
]),
|
|
55
|
+
),
|
|
56
|
+
prAuthor: Type.Optional(Type.String()),
|
|
57
|
+
prBase: Type.Optional(Type.String()),
|
|
58
|
+
prHead: Type.Optional(Type.String()),
|
|
59
|
+
prRepoOwner: Type.Optional(Type.String()),
|
|
60
|
+
prRepoName: Type.Optional(Type.String()),
|
|
61
|
+
prCIPassed: Type.Optional(Type.Number()),
|
|
62
|
+
prCIFailed: Type.Optional(Type.Number()),
|
|
63
|
+
prCITotal: Type.Optional(Type.Number()),
|
|
64
|
+
prCIStatus: Type.Optional(Type.String()),
|
|
65
|
+
prReviewsApproved: Type.Optional(Type.Number()),
|
|
66
|
+
prReviewsRequested: Type.Optional(Type.Number()),
|
|
67
|
+
prReviewsChanges: Type.Optional(Type.Number()),
|
|
68
|
+
prFilesAdded: Type.Optional(Type.Number()),
|
|
69
|
+
prFilesRemoved: Type.Optional(Type.Number()),
|
|
70
|
+
prFilesChanged: Type.Optional(Type.Number()),
|
|
71
|
+
prBreaking: Type.Optional(Type.Boolean()),
|
|
72
|
+
prDraft: Type.Optional(Type.Boolean()),
|
|
73
|
+
prUrl: Type.Optional(Type.String()),
|
|
74
|
+
|
|
75
|
+
// ── Task fields ──────────────────────────────────────
|
|
76
|
+
taskTitle: Type.Optional(Type.String()),
|
|
77
|
+
taskEmoji: Type.Optional(Type.String()),
|
|
78
|
+
taskStatus: Type.Optional(
|
|
79
|
+
Type.Union([
|
|
80
|
+
Type.Literal("started"),
|
|
81
|
+
Type.Literal("in-progress"),
|
|
82
|
+
Type.Literal("paused"),
|
|
83
|
+
Type.Literal("blocked"),
|
|
84
|
+
Type.Literal("complete"),
|
|
85
|
+
]),
|
|
86
|
+
),
|
|
87
|
+
taskProgress: Type.Optional(Type.Number()),
|
|
88
|
+
taskElapsed: Type.Optional(Type.String()),
|
|
89
|
+
taskEta: Type.Optional(Type.String()),
|
|
90
|
+
taskDetails: Type.Optional(Type.Array(Type.String())),
|
|
91
|
+
taskMetrics: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
92
|
+
|
|
93
|
+
// ── Pipeline fields ──────────────────────────────────
|
|
94
|
+
pipelineWorkflow: Type.Optional(Type.String()),
|
|
95
|
+
pipelineRunNumber: Type.Optional(Type.Number()),
|
|
96
|
+
pipelineBranch: Type.Optional(Type.String()),
|
|
97
|
+
pipelineEvent: Type.Optional(Type.String()),
|
|
98
|
+
pipelineJobs: Type.Optional(
|
|
99
|
+
Type.Array(
|
|
100
|
+
Type.Object({
|
|
101
|
+
name: Type.String(),
|
|
102
|
+
status: Type.String(),
|
|
103
|
+
duration: Type.Optional(Type.String()),
|
|
104
|
+
}),
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
pipelineTriggeredBy: Type.Optional(Type.String()),
|
|
108
|
+
pipelineUrl: Type.Optional(Type.String()),
|
|
109
|
+
|
|
110
|
+
// ── Session fields ───────────────────────────────────
|
|
111
|
+
sessionName: Type.Optional(Type.String()),
|
|
112
|
+
sessionBranch: Type.Optional(Type.String()),
|
|
113
|
+
sessionModel: Type.Optional(Type.String()),
|
|
114
|
+
sessionTurns: Type.Optional(Type.Number()),
|
|
115
|
+
sessionTokensUsed: Type.Optional(Type.Number()),
|
|
116
|
+
sessionTokensTotal: Type.Optional(Type.Number()),
|
|
117
|
+
sessionDuration: Type.Optional(Type.String()),
|
|
118
|
+
sessionStatus: Type.Optional(
|
|
119
|
+
Type.Union([
|
|
120
|
+
Type.Literal("idle"),
|
|
121
|
+
Type.Literal("streaming"),
|
|
122
|
+
Type.Literal("tool-exec"),
|
|
123
|
+
Type.Literal("waiting"),
|
|
124
|
+
]),
|
|
125
|
+
),
|
|
126
|
+
|
|
127
|
+
// ── Alert fields ─────────────────────────────────────
|
|
128
|
+
alertLevel: Type.Optional(
|
|
129
|
+
Type.Union([
|
|
130
|
+
Type.Literal("info"),
|
|
131
|
+
Type.Literal("warning"),
|
|
132
|
+
Type.Literal("error"),
|
|
133
|
+
Type.Literal("critical"),
|
|
134
|
+
]),
|
|
135
|
+
),
|
|
136
|
+
alertTitle: Type.Optional(Type.String()),
|
|
137
|
+
alertSource: Type.Optional(Type.String()),
|
|
138
|
+
alertDetail: Type.Optional(Type.String()),
|
|
139
|
+
alertAction: Type.Optional(Type.String()),
|
|
140
|
+
alertStack: Type.Optional(Type.String()),
|
|
141
|
+
|
|
142
|
+
// ── Factory job fields ───────────────────────────────
|
|
143
|
+
jobId: Type.Optional(Type.String()),
|
|
144
|
+
jobMode: Type.Optional(
|
|
145
|
+
Type.Union([
|
|
146
|
+
Type.Literal("single"),
|
|
147
|
+
Type.Literal("chain"),
|
|
148
|
+
Type.Literal("parallel"),
|
|
149
|
+
]),
|
|
150
|
+
),
|
|
151
|
+
jobStatus: Type.Optional(
|
|
152
|
+
Type.Union([
|
|
153
|
+
Type.Literal("pending"),
|
|
154
|
+
Type.Literal("running"),
|
|
155
|
+
Type.Literal("success"),
|
|
156
|
+
Type.Literal("failure"),
|
|
157
|
+
Type.Literal("cancelled"),
|
|
158
|
+
]),
|
|
159
|
+
),
|
|
160
|
+
jobAgent: Type.Optional(Type.String()),
|
|
161
|
+
jobTask: Type.Optional(Type.String()),
|
|
162
|
+
jobEnvironment: Type.Optional(Type.String()),
|
|
163
|
+
jobDuration: Type.Optional(Type.String()),
|
|
164
|
+
jobWorker: Type.Optional(Type.String()),
|
|
165
|
+
|
|
166
|
+
// ── Standup fields ───────────────────────────────────
|
|
167
|
+
standupDate: Type.Optional(Type.String()),
|
|
168
|
+
standupAgent: Type.Optional(Type.String()),
|
|
169
|
+
standupWorkedOn: Type.Optional(Type.Array(Type.String())),
|
|
170
|
+
standupNextUp: Type.Optional(Type.Array(Type.String())),
|
|
171
|
+
standupBlockers: Type.Optional(Type.Array(Type.String())),
|
|
172
|
+
standupMetrics: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
173
|
+
|
|
174
|
+
// ── Diff fields ──────────────────────────────────────
|
|
175
|
+
diffTitle: Type.Optional(Type.String()),
|
|
176
|
+
diffAdded: Type.Optional(Type.Number()),
|
|
177
|
+
diffRemoved: Type.Optional(Type.Number()),
|
|
178
|
+
diffFiles: Type.Optional(Type.Number()),
|
|
179
|
+
diffHighlights: Type.Optional(Type.Array(Type.String())),
|
|
180
|
+
diffUrl: Type.Optional(Type.String()),
|
|
181
|
+
|
|
182
|
+
// ── Decision fields ──────────────────────────────────
|
|
183
|
+
decisionQuestion: Type.Optional(Type.String()),
|
|
184
|
+
decisionContext: Type.Optional(Type.String()),
|
|
185
|
+
decisionOptions: Type.Optional(Type.Array(Type.String())),
|
|
186
|
+
decisionRisk: Type.Optional(
|
|
187
|
+
Type.Union([
|
|
188
|
+
Type.Literal("low"),
|
|
189
|
+
Type.Literal("medium"),
|
|
190
|
+
Type.Literal("high"),
|
|
191
|
+
Type.Literal("critical"),
|
|
192
|
+
]),
|
|
193
|
+
),
|
|
194
|
+
decisionCommand: Type.Optional(Type.String()),
|
|
195
|
+
decisionReason: Type.Optional(Type.String()),
|
|
196
|
+
|
|
197
|
+
// ── Ack fields ───────────────────────────────────────
|
|
198
|
+
ackText: Type.Optional(Type.String()),
|
|
199
|
+
ackEmoji: Type.Optional(Type.String()),
|
|
200
|
+
});
|
|
201
|
+
|
|
9
202
|
export const listenSchema = Type.Object({});
|
|
10
203
|
|
|
11
204
|
export const sendSchema = Type.Object({ message: Type.String() });
|
|
12
205
|
|
|
13
206
|
export const askSchema = Type.Object({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
207
|
+
question: Type.String(),
|
|
208
|
+
options: Type.Optional(Type.Array(Type.String())),
|
|
209
|
+
timeoutMinutes: Type.Optional(Type.Number()),
|
|
17
210
|
});
|
|
18
211
|
|
|
19
212
|
export const statusSchema = Type.Object({});
|
|
20
213
|
|
|
21
214
|
export const overrideSchema = Type.Object({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
215
|
+
command: Type.String(),
|
|
216
|
+
reason: Type.String(),
|
|
217
|
+
context: Type.Optional(Type.String()),
|
|
218
|
+
options: Type.Optional(Type.Array(Type.String())),
|
|
219
|
+
timeoutMinutes: Type.Optional(Type.Number()),
|
|
27
220
|
});
|