@elizaos/plugin-linear 2.0.0-alpha.7 → 2.0.11-beta.7
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/LICENSE +21 -0
- package/README.md +91 -51
- package/package.json +27 -10
- package/dist/index.js +0 -3467
- package/dist/index.js.map +0 -27
package/dist/index.js
DELETED
|
@@ -1,3467 +0,0 @@
|
|
|
1
|
-
// src/actions/clearActivity.ts
|
|
2
|
-
import {
|
|
3
|
-
logger
|
|
4
|
-
} from "@elizaos/core";
|
|
5
|
-
var clearActivityAction = {
|
|
6
|
-
name: "CLEAR_LINEAR_ACTIVITY",
|
|
7
|
-
description: "Clear the Linear activity log",
|
|
8
|
-
similes: ["clear-linear-activity", "reset-linear-activity", "delete-linear-activity"],
|
|
9
|
-
examples: [
|
|
10
|
-
[
|
|
11
|
-
{
|
|
12
|
-
name: "User",
|
|
13
|
-
content: {
|
|
14
|
-
text: "Clear the Linear activity log"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: "Assistant",
|
|
19
|
-
content: {
|
|
20
|
-
text: "I'll clear the Linear activity log for you.",
|
|
21
|
-
actions: ["CLEAR_LINEAR_ACTIVITY"]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
[
|
|
26
|
-
{
|
|
27
|
-
name: "User",
|
|
28
|
-
content: {
|
|
29
|
-
text: "Reset Linear activity"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "Assistant",
|
|
34
|
-
content: {
|
|
35
|
-
text: "I'll reset the Linear activity log now.",
|
|
36
|
-
actions: ["CLEAR_LINEAR_ACTIVITY"]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
],
|
|
41
|
-
validate: async (runtime, message, state, options) => {
|
|
42
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
43
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
44
|
-
const __avKeywords = ["clear", "linear", "activity"];
|
|
45
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
46
|
-
const __avRegex = /\b(?:clear|linear|activity)\b/i;
|
|
47
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
48
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
49
|
-
const __avExpectedSource = "";
|
|
50
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
51
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
52
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
53
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
57
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
58
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
59
|
-
const __avKeywords2 = ["clear", "linear", "activity"];
|
|
60
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
61
|
-
const __avRegex2 = /\b(?:clear|linear|activity)\b/i;
|
|
62
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
63
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
64
|
-
const __avExpectedSource2 = "";
|
|
65
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
66
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
67
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
68
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
72
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
73
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
74
|
-
const __avKeywords3 = ["clear", "linear", "activity"];
|
|
75
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
76
|
-
const __avRegex3 = /\b(?:clear|linear|activity)\b/i;
|
|
77
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
78
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
79
|
-
const __avExpectedSource3 = "";
|
|
80
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
81
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
82
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
83
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
87
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
88
|
-
return !!apiKey;
|
|
89
|
-
};
|
|
90
|
-
try {
|
|
91
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
92
|
-
} catch {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
98
|
-
} catch {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
try {
|
|
103
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
104
|
-
} catch {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
109
|
-
try {
|
|
110
|
-
const linearService = runtime.getService("linear");
|
|
111
|
-
if (!linearService) {
|
|
112
|
-
throw new Error("Linear service not available");
|
|
113
|
-
}
|
|
114
|
-
await linearService.clearActivityLog();
|
|
115
|
-
const successMessage = "✅ Linear activity log has been cleared.";
|
|
116
|
-
await callback?.({
|
|
117
|
-
text: successMessage,
|
|
118
|
-
source: message.content.source
|
|
119
|
-
});
|
|
120
|
-
return {
|
|
121
|
-
text: successMessage,
|
|
122
|
-
success: true
|
|
123
|
-
};
|
|
124
|
-
} catch (error) {
|
|
125
|
-
logger.error("Failed to clear Linear activity:", error);
|
|
126
|
-
const errorMessage = `❌ Failed to clear Linear activity: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
127
|
-
await callback?.({
|
|
128
|
-
text: errorMessage,
|
|
129
|
-
source: message.content.source
|
|
130
|
-
});
|
|
131
|
-
return {
|
|
132
|
-
text: errorMessage,
|
|
133
|
-
success: false
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// src/actions/createComment.ts
|
|
140
|
-
import {
|
|
141
|
-
logger as logger2,
|
|
142
|
-
ModelType
|
|
143
|
-
} from "@elizaos/core";
|
|
144
|
-
|
|
145
|
-
// src/generated/prompts/typescript/prompts.ts
|
|
146
|
-
var createCommentTemplate = `Extract comment details from the user's request to add a comment to a Linear issue.
|
|
147
|
-
|
|
148
|
-
User request: "{{userMessage}}"
|
|
149
|
-
|
|
150
|
-
The user might express this in various ways:
|
|
151
|
-
- "Comment on ENG-123: This looks good"
|
|
152
|
-
- "Tell ENG-123 that the fix is ready for testing"
|
|
153
|
-
- "Add a note to the login bug saying we need more info"
|
|
154
|
-
- "Reply to COM2-7: Thanks for the update"
|
|
155
|
-
- "Let the payment issue know that it's blocked by API changes"
|
|
156
|
-
|
|
157
|
-
Return ONLY a JSON object:
|
|
158
|
-
{
|
|
159
|
-
"issueId": "Direct issue ID if explicitly mentioned (e.g., ENG-123)",
|
|
160
|
-
"issueDescription": "Description/keywords of the issue if no ID provided",
|
|
161
|
-
"commentBody": "The actual comment content to add",
|
|
162
|
-
"commentType": "note/reply/update/question/feedback (inferred from context)"
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
Extract the core message the user wants to convey as the comment body.`;
|
|
166
|
-
var createIssueTemplate = `Given the user's request, extract the information needed to create a Linear issue.
|
|
167
|
-
|
|
168
|
-
User request: "{{userMessage}}"
|
|
169
|
-
|
|
170
|
-
Extract and return ONLY a JSON object (no markdown formatting, no code blocks) with the following structure:
|
|
171
|
-
{
|
|
172
|
-
"title": "Brief, clear issue title",
|
|
173
|
-
"description": "Detailed description of the issue (optional, omit or use null if not provided)",
|
|
174
|
-
"teamKey": "Team key if mentioned (e.g., ENG, PROD) - omit or use null if not mentioned",
|
|
175
|
-
"priority": "Priority level if mentioned (1=urgent, 2=high, 3=normal, 4=low) - omit or use null if not mentioned",
|
|
176
|
-
"labels": ["label1", "label2"] (if any labels are mentioned, empty array if none),
|
|
177
|
-
"assignee": "Assignee username or email if mentioned - omit or use null if not mentioned"
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
Return only the JSON object, no other text.`;
|
|
181
|
-
var deleteIssueTemplate = `Given the user's request to delete/archive a Linear issue, extract the issue identifier.
|
|
182
|
-
|
|
183
|
-
User request: "{{userMessage}}"
|
|
184
|
-
|
|
185
|
-
Extract and return ONLY a JSON object (no markdown formatting, no code blocks) with:
|
|
186
|
-
{
|
|
187
|
-
"issueId": "The issue identifier (e.g., ENG-123, COM2-7)"
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
Return only the JSON object, no other text.`;
|
|
191
|
-
var getActivityTemplate = `Extract activity filter criteria from the user's request.
|
|
192
|
-
|
|
193
|
-
User request: "{{userMessage}}"
|
|
194
|
-
|
|
195
|
-
The user might ask for activity in various ways:
|
|
196
|
-
- "Show me today's activity" → time range filter
|
|
197
|
-
- "What issues were created?" → action type filter
|
|
198
|
-
- "What did John do yesterday?" → user filter + time range
|
|
199
|
-
- "Activity on ENG-123" → resource filter
|
|
200
|
-
- "Recent comment activity" → action type + recency
|
|
201
|
-
- "Failed operations this week" → success filter + time range
|
|
202
|
-
|
|
203
|
-
Return ONLY a JSON object:
|
|
204
|
-
{
|
|
205
|
-
"timeRange": {
|
|
206
|
-
"period": "today/yesterday/this-week/last-week/this-month",
|
|
207
|
-
"from": "ISO datetime if specific",
|
|
208
|
-
"to": "ISO datetime if specific"
|
|
209
|
-
},
|
|
210
|
-
"actionTypes": ["create_issue/update_issue/delete_issue/create_comment/search_issues/etc"],
|
|
211
|
-
"resourceTypes": ["issue/project/comment/team"],
|
|
212
|
-
"resourceId": "Specific resource ID if mentioned (e.g., ENG-123)",
|
|
213
|
-
"user": "User name or 'me' for current user",
|
|
214
|
-
"successFilter": "success/failed/all",
|
|
215
|
-
"limit": number (default 10)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
Only include fields that are clearly mentioned.`;
|
|
219
|
-
var getIssueTemplate = `Extract issue identification from the user's request.
|
|
220
|
-
|
|
221
|
-
User request: "{{userMessage}}"
|
|
222
|
-
|
|
223
|
-
The user might reference an issue by:
|
|
224
|
-
- Direct ID (e.g., "ENG-123", "COM2-7")
|
|
225
|
-
- Title keywords (e.g., "the login bug", "that payment issue")
|
|
226
|
-
- Assignee (e.g., "John's high priority task")
|
|
227
|
-
- Recency (e.g., "the latest bug", "most recent issue")
|
|
228
|
-
- Team context (e.g., "newest issue in ELIZA team")
|
|
229
|
-
|
|
230
|
-
Return ONLY a JSON object:
|
|
231
|
-
{
|
|
232
|
-
"directId": "Issue ID if explicitly mentioned (e.g., ENG-123)",
|
|
233
|
-
"searchBy": {
|
|
234
|
-
"title": "Keywords from issue title if mentioned",
|
|
235
|
-
"assignee": "Name/email of assignee if mentioned",
|
|
236
|
-
"priority": "Priority level if mentioned (urgent/high/normal/low or 1-4)",
|
|
237
|
-
"team": "Team name or key if mentioned",
|
|
238
|
-
"state": "Issue state if mentioned (todo/in-progress/done)",
|
|
239
|
-
"recency": "latest/newest/recent/last if mentioned",
|
|
240
|
-
"type": "bug/feature/task if mentioned"
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
Only include fields that are clearly mentioned or implied.`;
|
|
245
|
-
var listProjectsTemplate = `Extract project filter criteria from the user's request.
|
|
246
|
-
|
|
247
|
-
User request: "{{userMessage}}"
|
|
248
|
-
|
|
249
|
-
The user might ask for projects in various ways:
|
|
250
|
-
- "Show me all projects" → list all projects
|
|
251
|
-
- "Active projects" → filter by state (active/planned/completed)
|
|
252
|
-
- "Projects due this quarter" → filter by target date
|
|
253
|
-
- "Which projects is Sarah managing?" → filter by lead/owner
|
|
254
|
-
- "Projects with high priority issues" → filter by contained issue priority
|
|
255
|
-
- "Projects for the engineering team" → filter by team
|
|
256
|
-
- "Completed projects" → filter by state
|
|
257
|
-
- "Projects starting next month" → filter by start date
|
|
258
|
-
|
|
259
|
-
Return ONLY a JSON object:
|
|
260
|
-
{
|
|
261
|
-
"teamFilter": "Team name or key if mentioned",
|
|
262
|
-
"stateFilter": "active/planned/completed/all",
|
|
263
|
-
"dateFilter": {
|
|
264
|
-
"type": "due/starting",
|
|
265
|
-
"period": "this-week/this-month/this-quarter/next-month/next-quarter",
|
|
266
|
-
"from": "ISO date if specific",
|
|
267
|
-
"to": "ISO date if specific"
|
|
268
|
-
},
|
|
269
|
-
"leadFilter": "Project lead name if mentioned",
|
|
270
|
-
"showAll": true/false (true if user explicitly asks for "all")
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
Only include fields that are clearly mentioned.`;
|
|
274
|
-
var listTeamsTemplate = `Extract team filter criteria from the user's request.
|
|
275
|
-
|
|
276
|
-
User request: "{{userMessage}}"
|
|
277
|
-
|
|
278
|
-
The user might ask for teams in various ways:
|
|
279
|
-
- "Show me all teams" → list all teams
|
|
280
|
-
- "Engineering teams" → filter by teams with engineering in name/description
|
|
281
|
-
- "List teams I'm part of" → filter by membership
|
|
282
|
-
- "Which teams work on the mobile app?" → filter by description/focus
|
|
283
|
-
- "Show me the ELIZA team details" → specific team lookup
|
|
284
|
-
- "Active teams" → teams with recent activity
|
|
285
|
-
- "Frontend and backend teams" → multiple team types
|
|
286
|
-
|
|
287
|
-
Return ONLY a JSON object:
|
|
288
|
-
{
|
|
289
|
-
"nameFilter": "Keywords to search in team names",
|
|
290
|
-
"specificTeam": "Specific team name or key if looking for one team",
|
|
291
|
-
"myTeams": true/false (true if user wants their teams),
|
|
292
|
-
"showAll": true/false (true if user explicitly asks for "all"),
|
|
293
|
-
"includeDetails": true/false (true if user wants detailed info)
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
Only include fields that are clearly mentioned.`;
|
|
297
|
-
var searchIssuesTemplate = `Extract search criteria from the user's request for Linear issues.
|
|
298
|
-
|
|
299
|
-
User request: "{{userMessage}}"
|
|
300
|
-
|
|
301
|
-
The user might express searches in various ways:
|
|
302
|
-
- "Show me what John is working on" → assignee filter
|
|
303
|
-
- "Any blockers for the next release?" → priority/label filters
|
|
304
|
-
- "Issues created this week" → date range filter
|
|
305
|
-
- "My high priority bugs" → assignee (current user) + priority + label
|
|
306
|
-
- "Unassigned tasks in the backend team" → no assignee + team filter
|
|
307
|
-
- "What did Sarah close yesterday?" → assignee + state + date
|
|
308
|
-
- "Bugs that are almost done" → label + state filter
|
|
309
|
-
- "Show me the oldest open issues" → state + sort order
|
|
310
|
-
|
|
311
|
-
Extract and return ONLY a JSON object:
|
|
312
|
-
{
|
|
313
|
-
"query": "General search text for title/description",
|
|
314
|
-
"states": ["state names like In Progress, Done, Todo, Backlog"],
|
|
315
|
-
"assignees": ["assignee names or emails, or 'me' for current user"],
|
|
316
|
-
"priorities": ["urgent/high/normal/low or 1/2/3/4"],
|
|
317
|
-
"teams": ["team names or keys"],
|
|
318
|
-
"labels": ["label names"],
|
|
319
|
-
"hasAssignee": true/false (true = has assignee, false = unassigned),
|
|
320
|
-
"dateRange": {
|
|
321
|
-
"field": "created/updated/completed",
|
|
322
|
-
"period": "today/yesterday/this-week/last-week/this-month/last-month",
|
|
323
|
-
"from": "ISO date if specific date",
|
|
324
|
-
"to": "ISO date if specific date"
|
|
325
|
-
},
|
|
326
|
-
"sort": {
|
|
327
|
-
"field": "created/updated/priority",
|
|
328
|
-
"order": "asc/desc"
|
|
329
|
-
},
|
|
330
|
-
"limit": number (default 10)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
Only include fields that are clearly mentioned or implied. For "my" issues, set assignees to ["me"].`;
|
|
334
|
-
var updateIssueTemplate = `Given the user's request to update a Linear issue, extract the information needed.
|
|
335
|
-
|
|
336
|
-
User request: "{{userMessage}}"
|
|
337
|
-
|
|
338
|
-
Extract and return ONLY a JSON object (no markdown formatting, no code blocks) with the following structure:
|
|
339
|
-
{
|
|
340
|
-
"issueId": "The issue identifier (e.g., ENG-123, COM2-7)",
|
|
341
|
-
"updates": {
|
|
342
|
-
"title": "New title if changing the title",
|
|
343
|
-
"description": "New description if changing the description",
|
|
344
|
-
"priority": "Priority level if changing (1=urgent, 2=high, 3=normal, 4=low)",
|
|
345
|
-
"teamKey": "New team key if moving to another team (e.g., ENG, ELIZA, COM2)",
|
|
346
|
-
"assignee": "New assignee username or email if changing",
|
|
347
|
-
"status": "New status if changing (e.g., todo, in-progress, done, canceled)",
|
|
348
|
-
"labels": ["label1", "label2"] (if changing labels, empty array to clear)
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
Only include fields that are being updated. Return only the JSON object, no other text.`;
|
|
353
|
-
|
|
354
|
-
// src/actions/createComment.ts
|
|
355
|
-
var createCommentAction = {
|
|
356
|
-
name: "CREATE_LINEAR_COMMENT",
|
|
357
|
-
description: "Add a comment to a Linear issue",
|
|
358
|
-
similes: [
|
|
359
|
-
"create-linear-comment",
|
|
360
|
-
"add-linear-comment",
|
|
361
|
-
"comment-on-linear-issue",
|
|
362
|
-
"reply-to-linear-issue"
|
|
363
|
-
],
|
|
364
|
-
examples: [
|
|
365
|
-
[
|
|
366
|
-
{
|
|
367
|
-
name: "User",
|
|
368
|
-
content: {
|
|
369
|
-
text: "Comment on ENG-123: This looks good to me"
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
name: "Assistant",
|
|
374
|
-
content: {
|
|
375
|
-
text: "I'll add your comment to issue ENG-123.",
|
|
376
|
-
actions: ["CREATE_LINEAR_COMMENT"]
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
],
|
|
380
|
-
[
|
|
381
|
-
{
|
|
382
|
-
name: "User",
|
|
383
|
-
content: {
|
|
384
|
-
text: "Tell the login bug that we need more information from QA"
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
name: "Assistant",
|
|
389
|
-
content: {
|
|
390
|
-
text: "I'll add that comment to the login bug issue.",
|
|
391
|
-
actions: ["CREATE_LINEAR_COMMENT"]
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
],
|
|
395
|
-
[
|
|
396
|
-
{
|
|
397
|
-
name: "User",
|
|
398
|
-
content: {
|
|
399
|
-
text: "Reply to COM2-7: Thanks for the update, I'll look into it"
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
name: "Assistant",
|
|
404
|
-
content: {
|
|
405
|
-
text: "I'll add your reply to issue COM2-7.",
|
|
406
|
-
actions: ["CREATE_LINEAR_COMMENT"]
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
]
|
|
410
|
-
],
|
|
411
|
-
validate: async (runtime, message, state, options) => {
|
|
412
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
413
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
414
|
-
const __avKeywords = ["create", "linear", "comment"];
|
|
415
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
416
|
-
const __avRegex = /\b(?:create|linear|comment)\b/i;
|
|
417
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
418
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
419
|
-
const __avExpectedSource = "";
|
|
420
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
421
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
422
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
423
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
424
|
-
return false;
|
|
425
|
-
}
|
|
426
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
427
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
428
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
429
|
-
const __avKeywords2 = ["create", "linear", "comment"];
|
|
430
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
431
|
-
const __avRegex2 = /\b(?:create|linear|comment)\b/i;
|
|
432
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
433
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
434
|
-
const __avExpectedSource2 = "";
|
|
435
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
436
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
437
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
438
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
439
|
-
return false;
|
|
440
|
-
}
|
|
441
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
442
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
443
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
444
|
-
const __avKeywords3 = ["create", "linear", "comment"];
|
|
445
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
446
|
-
const __avRegex3 = /\b(?:create|linear|comment)\b/i;
|
|
447
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
448
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
449
|
-
const __avExpectedSource3 = "";
|
|
450
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
451
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
452
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
453
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
454
|
-
return false;
|
|
455
|
-
}
|
|
456
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
457
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
458
|
-
return !!apiKey;
|
|
459
|
-
};
|
|
460
|
-
try {
|
|
461
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
462
|
-
} catch {
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
try {
|
|
467
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
468
|
-
} catch {
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
try {
|
|
473
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
474
|
-
} catch {
|
|
475
|
-
return false;
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
479
|
-
try {
|
|
480
|
-
const linearService = runtime.getService("linear");
|
|
481
|
-
if (!linearService) {
|
|
482
|
-
throw new Error("Linear service not available");
|
|
483
|
-
}
|
|
484
|
-
const content = message.content.text;
|
|
485
|
-
if (!content) {
|
|
486
|
-
const errorMessage = "Please provide a message with the issue and comment content.";
|
|
487
|
-
await callback?.({
|
|
488
|
-
text: errorMessage,
|
|
489
|
-
source: message.content.source
|
|
490
|
-
});
|
|
491
|
-
return {
|
|
492
|
-
text: errorMessage,
|
|
493
|
-
success: false
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
let issueId;
|
|
497
|
-
let commentBody;
|
|
498
|
-
const params = _options?.parameters;
|
|
499
|
-
if (params?.issueId && params?.body) {
|
|
500
|
-
issueId = params.issueId;
|
|
501
|
-
commentBody = params.body;
|
|
502
|
-
} else {
|
|
503
|
-
const prompt = createCommentTemplate.replace("{{userMessage}}", content);
|
|
504
|
-
const response = await runtime.useModel(ModelType.TEXT_LARGE, {
|
|
505
|
-
prompt
|
|
506
|
-
});
|
|
507
|
-
if (!response) {
|
|
508
|
-
const issueMatch = content.match(/(?:comment on|add.*comment.*to|reply to|tell)\s+(\w+-\d+):?\s*(.*)/i);
|
|
509
|
-
if (issueMatch) {
|
|
510
|
-
issueId = issueMatch[1];
|
|
511
|
-
commentBody = issueMatch[2].trim();
|
|
512
|
-
} else {
|
|
513
|
-
throw new Error("Could not understand comment request");
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
try {
|
|
517
|
-
const parsed = JSON.parse(response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim());
|
|
518
|
-
if (parsed.issueId) {
|
|
519
|
-
issueId = parsed.issueId;
|
|
520
|
-
commentBody = parsed.commentBody;
|
|
521
|
-
} else if (parsed.issueDescription) {
|
|
522
|
-
const filters = {
|
|
523
|
-
query: parsed.issueDescription,
|
|
524
|
-
limit: 5
|
|
525
|
-
};
|
|
526
|
-
const defaultTeamKey = runtime.getSetting("LINEAR_DEFAULT_TEAM_KEY");
|
|
527
|
-
if (defaultTeamKey) {
|
|
528
|
-
filters.team = defaultTeamKey;
|
|
529
|
-
}
|
|
530
|
-
const issues = await linearService.searchIssues(filters);
|
|
531
|
-
if (issues.length === 0) {
|
|
532
|
-
const errorMessage = `No issues found matching "${parsed.issueDescription}". Please provide a specific issue ID.`;
|
|
533
|
-
await callback?.({
|
|
534
|
-
text: errorMessage,
|
|
535
|
-
source: message.content.source
|
|
536
|
-
});
|
|
537
|
-
return {
|
|
538
|
-
text: errorMessage,
|
|
539
|
-
success: false
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
if (issues.length === 1) {
|
|
543
|
-
issueId = issues[0].identifier;
|
|
544
|
-
commentBody = parsed.commentBody;
|
|
545
|
-
} else {
|
|
546
|
-
const issueList = await Promise.all(issues.map(async (issue2, index) => {
|
|
547
|
-
const state = await issue2.state;
|
|
548
|
-
return `${index + 1}. ${issue2.identifier}: ${issue2.title} (${state?.name || "No state"})`;
|
|
549
|
-
}));
|
|
550
|
-
const clarifyMessage = `Found multiple issues matching "${parsed.issueDescription}":
|
|
551
|
-
${issueList.join(`
|
|
552
|
-
`)}
|
|
553
|
-
|
|
554
|
-
Please specify which issue to comment on by its ID.`;
|
|
555
|
-
await callback?.({
|
|
556
|
-
text: clarifyMessage,
|
|
557
|
-
source: message.content.source
|
|
558
|
-
});
|
|
559
|
-
return {
|
|
560
|
-
text: clarifyMessage,
|
|
561
|
-
success: false,
|
|
562
|
-
data: {
|
|
563
|
-
multipleMatches: true,
|
|
564
|
-
issues: issues.map((i) => ({
|
|
565
|
-
id: i.id,
|
|
566
|
-
identifier: i.identifier,
|
|
567
|
-
title: i.title
|
|
568
|
-
})),
|
|
569
|
-
pendingComment: parsed.commentBody
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
} else {
|
|
574
|
-
throw new Error("No issue identifier or description found");
|
|
575
|
-
}
|
|
576
|
-
if (parsed.commentType && parsed.commentType !== "note") {
|
|
577
|
-
commentBody = `[${parsed.commentType.toUpperCase()}] ${commentBody}`;
|
|
578
|
-
}
|
|
579
|
-
} catch (parseError) {
|
|
580
|
-
logger2.warn("Failed to parse LLM response, falling back to regex:", parseError);
|
|
581
|
-
const issueMatch = content.match(/(?:comment on|add.*comment.*to|reply to|tell)\s+(\w+-\d+):?\s*(.*)/i);
|
|
582
|
-
if (!issueMatch) {
|
|
583
|
-
const errorMessage = 'Please specify the issue ID and comment content. Example: "Comment on ENG-123: This looks good"';
|
|
584
|
-
await callback?.({
|
|
585
|
-
text: errorMessage,
|
|
586
|
-
source: message.content.source
|
|
587
|
-
});
|
|
588
|
-
return {
|
|
589
|
-
text: errorMessage,
|
|
590
|
-
success: false
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
issueId = issueMatch[1];
|
|
594
|
-
commentBody = issueMatch[2].trim();
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
if (!commentBody || commentBody.length === 0) {
|
|
599
|
-
const errorMessage = "Please provide the comment content.";
|
|
600
|
-
await callback?.({
|
|
601
|
-
text: errorMessage,
|
|
602
|
-
source: message.content.source
|
|
603
|
-
});
|
|
604
|
-
return {
|
|
605
|
-
text: errorMessage,
|
|
606
|
-
success: false
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
const issue = await linearService.getIssue(issueId);
|
|
610
|
-
const comment = await linearService.createComment({
|
|
611
|
-
issueId: issue.id,
|
|
612
|
-
body: commentBody
|
|
613
|
-
});
|
|
614
|
-
const successMessage = `✅ Comment added to issue ${issue.identifier}: "${commentBody}"`;
|
|
615
|
-
await callback?.({
|
|
616
|
-
text: successMessage,
|
|
617
|
-
source: message.content.source
|
|
618
|
-
});
|
|
619
|
-
return {
|
|
620
|
-
text: `Added comment to issue ${issue.identifier}`,
|
|
621
|
-
success: true,
|
|
622
|
-
data: {
|
|
623
|
-
commentId: comment.id,
|
|
624
|
-
issueId: issue.id,
|
|
625
|
-
issueIdentifier: issue.identifier,
|
|
626
|
-
commentBody,
|
|
627
|
-
createdAt: comment.createdAt instanceof Date ? comment.createdAt.toISOString() : comment.createdAt
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
} catch (error) {
|
|
631
|
-
logger2.error("Failed to create comment:", error);
|
|
632
|
-
const errorMessage = `❌ Failed to create comment: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
633
|
-
await callback?.({
|
|
634
|
-
text: errorMessage,
|
|
635
|
-
source: message.content.source
|
|
636
|
-
});
|
|
637
|
-
return {
|
|
638
|
-
text: errorMessage,
|
|
639
|
-
success: false
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
// src/actions/createIssue.ts
|
|
646
|
-
import {
|
|
647
|
-
logger as logger3,
|
|
648
|
-
ModelType as ModelType2
|
|
649
|
-
} from "@elizaos/core";
|
|
650
|
-
var createIssueAction = {
|
|
651
|
-
name: "CREATE_LINEAR_ISSUE",
|
|
652
|
-
description: "Create a new issue in Linear",
|
|
653
|
-
similes: ["create-linear-issue", "new-linear-issue", "add-linear-issue"],
|
|
654
|
-
examples: [
|
|
655
|
-
[
|
|
656
|
-
{
|
|
657
|
-
name: "User",
|
|
658
|
-
content: {
|
|
659
|
-
text: "Create a new issue: Fix login button not working on mobile devices"
|
|
660
|
-
}
|
|
661
|
-
},
|
|
662
|
-
{
|
|
663
|
-
name: "Assistant",
|
|
664
|
-
content: {
|
|
665
|
-
text: "I'll create that issue for you in Linear.",
|
|
666
|
-
actions: ["CREATE_LINEAR_ISSUE"]
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
],
|
|
670
|
-
[
|
|
671
|
-
{
|
|
672
|
-
name: "User",
|
|
673
|
-
content: {
|
|
674
|
-
text: "Create a bug report for the ENG team: API returns 500 error when updating user profile"
|
|
675
|
-
}
|
|
676
|
-
},
|
|
677
|
-
{
|
|
678
|
-
name: "Assistant",
|
|
679
|
-
content: {
|
|
680
|
-
text: "I'll create a bug report for the engineering team right away.",
|
|
681
|
-
actions: ["CREATE_LINEAR_ISSUE"]
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
]
|
|
685
|
-
],
|
|
686
|
-
validate: async (runtime, message, state, options) => {
|
|
687
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
688
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
689
|
-
const __avKeywords = ["create", "linear", "issue"];
|
|
690
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
691
|
-
const __avRegex = /\b(?:create|linear|issue)\b/i;
|
|
692
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
693
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
694
|
-
const __avExpectedSource = "";
|
|
695
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
696
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
697
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
698
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
702
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
703
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
704
|
-
const __avKeywords2 = ["create", "linear", "issue"];
|
|
705
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
706
|
-
const __avRegex2 = /\b(?:create|linear|issue)\b/i;
|
|
707
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
708
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
709
|
-
const __avExpectedSource2 = "";
|
|
710
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
711
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
712
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
713
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
714
|
-
return false;
|
|
715
|
-
}
|
|
716
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
717
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
718
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
719
|
-
const __avKeywords3 = ["create", "linear", "issue"];
|
|
720
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
721
|
-
const __avRegex3 = /\b(?:create|linear|issue)\b/i;
|
|
722
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
723
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
724
|
-
const __avExpectedSource3 = "";
|
|
725
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
726
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
727
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
728
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
729
|
-
return false;
|
|
730
|
-
}
|
|
731
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
732
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
733
|
-
return !!apiKey;
|
|
734
|
-
};
|
|
735
|
-
try {
|
|
736
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
737
|
-
} catch {
|
|
738
|
-
return false;
|
|
739
|
-
}
|
|
740
|
-
};
|
|
741
|
-
try {
|
|
742
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
743
|
-
} catch {
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
try {
|
|
748
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
749
|
-
} catch {
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
},
|
|
753
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
754
|
-
try {
|
|
755
|
-
const linearService = runtime.getService("linear");
|
|
756
|
-
if (!linearService) {
|
|
757
|
-
throw new Error("Linear service not available");
|
|
758
|
-
}
|
|
759
|
-
const content = message.content.text;
|
|
760
|
-
if (!content) {
|
|
761
|
-
const errorMessage = "Please provide a description for the issue.";
|
|
762
|
-
await callback?.({
|
|
763
|
-
text: errorMessage,
|
|
764
|
-
source: message.content.source
|
|
765
|
-
});
|
|
766
|
-
return {
|
|
767
|
-
text: errorMessage,
|
|
768
|
-
success: false
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
const params = _options?.parameters;
|
|
772
|
-
const structuredData = params?.issueData;
|
|
773
|
-
let issueData;
|
|
774
|
-
if (structuredData) {
|
|
775
|
-
issueData = structuredData;
|
|
776
|
-
} else {
|
|
777
|
-
const prompt = createIssueTemplate.replace("{{userMessage}}", content);
|
|
778
|
-
const response = await runtime.useModel(ModelType2.TEXT_LARGE, {
|
|
779
|
-
prompt
|
|
780
|
-
});
|
|
781
|
-
if (!response) {
|
|
782
|
-
throw new Error("Failed to extract issue information");
|
|
783
|
-
}
|
|
784
|
-
try {
|
|
785
|
-
const cleanedResponse = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
786
|
-
const parsed = JSON.parse(cleanedResponse);
|
|
787
|
-
issueData = {
|
|
788
|
-
title: parsed.title || undefined,
|
|
789
|
-
description: parsed.description || undefined,
|
|
790
|
-
priority: parsed.priority ? Number(parsed.priority) : undefined
|
|
791
|
-
};
|
|
792
|
-
if (parsed.teamKey) {
|
|
793
|
-
const teams = await linearService.getTeams();
|
|
794
|
-
const team = teams.find((t) => t.key.toLowerCase() === parsed.teamKey.toLowerCase());
|
|
795
|
-
if (team) {
|
|
796
|
-
issueData.teamId = team.id;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
if (parsed.assignee && parsed.assignee !== "") {
|
|
800
|
-
const cleanAssignee = parsed.assignee.replace(/^@/, "");
|
|
801
|
-
const users = await linearService.getUsers();
|
|
802
|
-
const user = users.find((u) => u.email === cleanAssignee || u.name.toLowerCase().includes(cleanAssignee.toLowerCase()));
|
|
803
|
-
if (user) {
|
|
804
|
-
issueData.assigneeId = user.id;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
if (parsed.labels && Array.isArray(parsed.labels) && parsed.labels.length > 0) {
|
|
808
|
-
const labels = await linearService.getLabels(issueData.teamId);
|
|
809
|
-
const labelIds = [];
|
|
810
|
-
for (const labelName of parsed.labels) {
|
|
811
|
-
if (labelName && labelName !== "") {
|
|
812
|
-
const label = labels.find((l) => l.name.toLowerCase() === labelName.toLowerCase());
|
|
813
|
-
if (label) {
|
|
814
|
-
labelIds.push(label.id);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
if (labelIds.length > 0) {
|
|
819
|
-
issueData.labelIds = labelIds;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
if (!issueData.teamId) {
|
|
823
|
-
const defaultTeamKey = runtime.getSetting("LINEAR_DEFAULT_TEAM_KEY");
|
|
824
|
-
if (defaultTeamKey) {
|
|
825
|
-
const teams = await linearService.getTeams();
|
|
826
|
-
const defaultTeam = teams.find((t) => t.key.toLowerCase() === defaultTeamKey.toLowerCase());
|
|
827
|
-
if (defaultTeam) {
|
|
828
|
-
issueData.teamId = defaultTeam.id;
|
|
829
|
-
logger3.info(`Using configured default team: ${defaultTeam.name} (${defaultTeam.key})`);
|
|
830
|
-
} else {
|
|
831
|
-
logger3.warn(`Default team key ${defaultTeamKey} not found`);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
if (!issueData.teamId) {
|
|
835
|
-
const teams = await linearService.getTeams();
|
|
836
|
-
if (teams.length > 0) {
|
|
837
|
-
issueData.teamId = teams[0].id;
|
|
838
|
-
logger3.warn(`No team specified, using first available team: ${teams[0].name}`);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
} catch (parseError) {
|
|
843
|
-
logger3.error("Failed to parse LLM response:", parseError);
|
|
844
|
-
issueData = {
|
|
845
|
-
title: content.length > 100 ? `${content.substring(0, 100)}...` : content,
|
|
846
|
-
description: content
|
|
847
|
-
};
|
|
848
|
-
const defaultTeamKey = runtime.getSetting("LINEAR_DEFAULT_TEAM_KEY");
|
|
849
|
-
const teams = await linearService.getTeams();
|
|
850
|
-
if (defaultTeamKey) {
|
|
851
|
-
const defaultTeam = teams.find((t) => t.key.toLowerCase() === defaultTeamKey.toLowerCase());
|
|
852
|
-
if (defaultTeam) {
|
|
853
|
-
issueData.teamId = defaultTeam.id;
|
|
854
|
-
logger3.info(`Using configured default team for fallback: ${defaultTeam.name} (${defaultTeam.key})`);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
if (!issueData.teamId && teams.length > 0) {
|
|
858
|
-
issueData.teamId = teams[0].id;
|
|
859
|
-
logger3.warn(`Using first available team for fallback: ${teams[0].name}`);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
if (!issueData.title) {
|
|
864
|
-
const errorMessage = "Could not determine issue title. Please provide more details.";
|
|
865
|
-
await callback?.({
|
|
866
|
-
text: errorMessage,
|
|
867
|
-
source: message.content.source
|
|
868
|
-
});
|
|
869
|
-
return {
|
|
870
|
-
text: errorMessage,
|
|
871
|
-
success: false
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
if (!issueData.teamId) {
|
|
875
|
-
const errorMessage = "No Linear teams found. Please ensure at least one team exists in your Linear workspace.";
|
|
876
|
-
await callback?.({
|
|
877
|
-
text: errorMessage,
|
|
878
|
-
source: message.content.source
|
|
879
|
-
});
|
|
880
|
-
return {
|
|
881
|
-
text: errorMessage,
|
|
882
|
-
success: false
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
const issue = await linearService.createIssue(issueData);
|
|
886
|
-
const successMessage = `✅ Created Linear issue: ${issue.title} (${issue.identifier})
|
|
887
|
-
|
|
888
|
-
View it at: ${issue.url}`;
|
|
889
|
-
await callback?.({
|
|
890
|
-
text: successMessage,
|
|
891
|
-
source: message.content.source
|
|
892
|
-
});
|
|
893
|
-
return {
|
|
894
|
-
text: `Created issue: ${issue.title} (${issue.identifier})`,
|
|
895
|
-
success: true,
|
|
896
|
-
data: {
|
|
897
|
-
issueId: issue.id,
|
|
898
|
-
identifier: issue.identifier,
|
|
899
|
-
url: issue.url
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
} catch (error) {
|
|
903
|
-
logger3.error("Failed to create issue:", error);
|
|
904
|
-
const errorMessage = `❌ Failed to create issue: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
905
|
-
await callback?.({
|
|
906
|
-
text: errorMessage,
|
|
907
|
-
source: message.content.source
|
|
908
|
-
});
|
|
909
|
-
return {
|
|
910
|
-
text: errorMessage,
|
|
911
|
-
success: false
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
};
|
|
916
|
-
|
|
917
|
-
// src/actions/deleteIssue.ts
|
|
918
|
-
import {
|
|
919
|
-
logger as logger4,
|
|
920
|
-
ModelType as ModelType3
|
|
921
|
-
} from "@elizaos/core";
|
|
922
|
-
var deleteIssueAction = {
|
|
923
|
-
name: "DELETE_LINEAR_ISSUE",
|
|
924
|
-
description: "Delete (archive) an issue in Linear",
|
|
925
|
-
similes: [
|
|
926
|
-
"delete-linear-issue",
|
|
927
|
-
"archive-linear-issue",
|
|
928
|
-
"remove-linear-issue",
|
|
929
|
-
"close-linear-issue"
|
|
930
|
-
],
|
|
931
|
-
examples: [
|
|
932
|
-
[
|
|
933
|
-
{
|
|
934
|
-
name: "User",
|
|
935
|
-
content: {
|
|
936
|
-
text: "Delete issue ENG-123"
|
|
937
|
-
}
|
|
938
|
-
},
|
|
939
|
-
{
|
|
940
|
-
name: "Assistant",
|
|
941
|
-
content: {
|
|
942
|
-
text: "I'll archive issue ENG-123 for you.",
|
|
943
|
-
actions: ["DELETE_LINEAR_ISSUE"]
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
],
|
|
947
|
-
[
|
|
948
|
-
{
|
|
949
|
-
name: "User",
|
|
950
|
-
content: {
|
|
951
|
-
text: "Remove COM2-7 from Linear"
|
|
952
|
-
}
|
|
953
|
-
},
|
|
954
|
-
{
|
|
955
|
-
name: "Assistant",
|
|
956
|
-
content: {
|
|
957
|
-
text: "I'll archive issue COM2-7 in Linear.",
|
|
958
|
-
actions: ["DELETE_LINEAR_ISSUE"]
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
],
|
|
962
|
-
[
|
|
963
|
-
{
|
|
964
|
-
name: "User",
|
|
965
|
-
content: {
|
|
966
|
-
text: "Archive the bug report BUG-456"
|
|
967
|
-
}
|
|
968
|
-
},
|
|
969
|
-
{
|
|
970
|
-
name: "Assistant",
|
|
971
|
-
content: {
|
|
972
|
-
text: "I'll archive issue BUG-456 for you.",
|
|
973
|
-
actions: ["DELETE_LINEAR_ISSUE"]
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
]
|
|
977
|
-
],
|
|
978
|
-
validate: async (runtime, message, state, options) => {
|
|
979
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
980
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
981
|
-
const __avKeywords = ["delete", "linear", "issue"];
|
|
982
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
983
|
-
const __avRegex = /\b(?:delete|linear|issue)\b/i;
|
|
984
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
985
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
986
|
-
const __avExpectedSource = "";
|
|
987
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
988
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
989
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
990
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
991
|
-
return false;
|
|
992
|
-
}
|
|
993
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
994
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
995
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
996
|
-
const __avKeywords2 = ["delete", "linear", "issue"];
|
|
997
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
998
|
-
const __avRegex2 = /\b(?:delete|linear|issue)\b/i;
|
|
999
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
1000
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
1001
|
-
const __avExpectedSource2 = "";
|
|
1002
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
1003
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
1004
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
1005
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
1006
|
-
return false;
|
|
1007
|
-
}
|
|
1008
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
1009
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
1010
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
1011
|
-
const __avKeywords3 = ["delete", "linear", "issue"];
|
|
1012
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
1013
|
-
const __avRegex3 = /\b(?:delete|linear|issue)\b/i;
|
|
1014
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
1015
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
1016
|
-
const __avExpectedSource3 = "";
|
|
1017
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
1018
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
1019
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
1020
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
1021
|
-
return false;
|
|
1022
|
-
}
|
|
1023
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
1024
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
1025
|
-
return !!apiKey;
|
|
1026
|
-
};
|
|
1027
|
-
try {
|
|
1028
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
1029
|
-
} catch {
|
|
1030
|
-
return false;
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
try {
|
|
1034
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
1035
|
-
} catch {
|
|
1036
|
-
return false;
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
1039
|
-
try {
|
|
1040
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1041
|
-
} catch {
|
|
1042
|
-
return false;
|
|
1043
|
-
}
|
|
1044
|
-
},
|
|
1045
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
1046
|
-
try {
|
|
1047
|
-
const linearService = runtime.getService("linear");
|
|
1048
|
-
if (!linearService) {
|
|
1049
|
-
throw new Error("Linear service not available");
|
|
1050
|
-
}
|
|
1051
|
-
const content = message.content.text;
|
|
1052
|
-
if (!content) {
|
|
1053
|
-
const errorMessage = "Please specify which issue to delete.";
|
|
1054
|
-
await callback?.({
|
|
1055
|
-
text: errorMessage,
|
|
1056
|
-
source: message.content.source
|
|
1057
|
-
});
|
|
1058
|
-
return {
|
|
1059
|
-
text: errorMessage,
|
|
1060
|
-
success: false
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
let issueId;
|
|
1064
|
-
const params = _options?.parameters;
|
|
1065
|
-
if (params?.issueId) {
|
|
1066
|
-
issueId = params.issueId;
|
|
1067
|
-
} else {
|
|
1068
|
-
const prompt = deleteIssueTemplate.replace("{{userMessage}}", content);
|
|
1069
|
-
const response = await runtime.useModel(ModelType3.TEXT_LARGE, {
|
|
1070
|
-
prompt
|
|
1071
|
-
});
|
|
1072
|
-
if (!response) {
|
|
1073
|
-
throw new Error("Failed to extract issue identifier");
|
|
1074
|
-
}
|
|
1075
|
-
try {
|
|
1076
|
-
const cleanedResponse = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
1077
|
-
const parsed = JSON.parse(cleanedResponse);
|
|
1078
|
-
issueId = parsed.issueId;
|
|
1079
|
-
if (!issueId) {
|
|
1080
|
-
throw new Error("Issue ID not found in parsed response");
|
|
1081
|
-
}
|
|
1082
|
-
} catch (parseError) {
|
|
1083
|
-
logger4.warn("Failed to parse LLM response, falling back to regex parsing:", parseError);
|
|
1084
|
-
const issueMatch = content.match(/(\w+-\d+)/);
|
|
1085
|
-
if (!issueMatch) {
|
|
1086
|
-
const errorMessage = "Please specify an issue ID (e.g., ENG-123) to delete.";
|
|
1087
|
-
await callback?.({
|
|
1088
|
-
text: errorMessage,
|
|
1089
|
-
source: message.content.source
|
|
1090
|
-
});
|
|
1091
|
-
return {
|
|
1092
|
-
text: errorMessage,
|
|
1093
|
-
success: false
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
issueId = issueMatch[1];
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
const issue = await linearService.getIssue(issueId);
|
|
1100
|
-
const issueTitle = issue.title;
|
|
1101
|
-
const issueIdentifier = issue.identifier;
|
|
1102
|
-
logger4.info(`Archiving issue ${issueIdentifier}: ${issueTitle}`);
|
|
1103
|
-
await linearService.deleteIssue(issueId);
|
|
1104
|
-
const successMessage = `✅ Successfully archived issue ${issueIdentifier}: "${issueTitle}"
|
|
1105
|
-
|
|
1106
|
-
The issue has been moved to the archived state and will no longer appear in active views.`;
|
|
1107
|
-
await callback?.({
|
|
1108
|
-
text: successMessage,
|
|
1109
|
-
source: message.content.source
|
|
1110
|
-
});
|
|
1111
|
-
return {
|
|
1112
|
-
text: `Archived issue ${issueIdentifier}: "${issueTitle}"`,
|
|
1113
|
-
success: true,
|
|
1114
|
-
data: {
|
|
1115
|
-
issueId: issue.id,
|
|
1116
|
-
identifier: issueIdentifier,
|
|
1117
|
-
title: issueTitle,
|
|
1118
|
-
archived: true
|
|
1119
|
-
}
|
|
1120
|
-
};
|
|
1121
|
-
} catch (error) {
|
|
1122
|
-
logger4.error("Failed to delete issue:", error);
|
|
1123
|
-
const errorMessage = `❌ Failed to delete issue: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
1124
|
-
await callback?.({
|
|
1125
|
-
text: errorMessage,
|
|
1126
|
-
source: message.content.source
|
|
1127
|
-
});
|
|
1128
|
-
return {
|
|
1129
|
-
text: errorMessage,
|
|
1130
|
-
success: false
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
// src/actions/getActivity.ts
|
|
1137
|
-
import {
|
|
1138
|
-
logger as logger5,
|
|
1139
|
-
ModelType as ModelType4
|
|
1140
|
-
} from "@elizaos/core";
|
|
1141
|
-
var getActivityAction = {
|
|
1142
|
-
name: "GET_LINEAR_ACTIVITY",
|
|
1143
|
-
description: "Get recent Linear activity log with optional filters",
|
|
1144
|
-
similes: [
|
|
1145
|
-
"get-linear-activity",
|
|
1146
|
-
"show-linear-activity",
|
|
1147
|
-
"view-linear-activity",
|
|
1148
|
-
"check-linear-activity"
|
|
1149
|
-
],
|
|
1150
|
-
examples: [
|
|
1151
|
-
[
|
|
1152
|
-
{
|
|
1153
|
-
name: "User",
|
|
1154
|
-
content: {
|
|
1155
|
-
text: "Show me recent Linear activity"
|
|
1156
|
-
}
|
|
1157
|
-
},
|
|
1158
|
-
{
|
|
1159
|
-
name: "Assistant",
|
|
1160
|
-
content: {
|
|
1161
|
-
text: "I'll show you the recent Linear activity.",
|
|
1162
|
-
actions: ["GET_LINEAR_ACTIVITY"]
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
],
|
|
1166
|
-
[
|
|
1167
|
-
{
|
|
1168
|
-
name: "User",
|
|
1169
|
-
content: {
|
|
1170
|
-
text: "What happened in Linear today?"
|
|
1171
|
-
}
|
|
1172
|
-
},
|
|
1173
|
-
{
|
|
1174
|
-
name: "Assistant",
|
|
1175
|
-
content: {
|
|
1176
|
-
text: "Let me check today's Linear activity for you.",
|
|
1177
|
-
actions: ["GET_LINEAR_ACTIVITY"]
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
],
|
|
1181
|
-
[
|
|
1182
|
-
{
|
|
1183
|
-
name: "User",
|
|
1184
|
-
content: {
|
|
1185
|
-
text: "Show me what issues John created this week"
|
|
1186
|
-
}
|
|
1187
|
-
},
|
|
1188
|
-
{
|
|
1189
|
-
name: "Assistant",
|
|
1190
|
-
content: {
|
|
1191
|
-
text: "I'll find the issues John created this week.",
|
|
1192
|
-
actions: ["GET_LINEAR_ACTIVITY"]
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
]
|
|
1196
|
-
],
|
|
1197
|
-
validate: async (runtime, message, state, options) => {
|
|
1198
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1199
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1200
|
-
const __avKeywords = ["get", "linear", "activity"];
|
|
1201
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
1202
|
-
const __avRegex = /\b(?:get|linear|activity)\b/i;
|
|
1203
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
1204
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1205
|
-
const __avExpectedSource = "";
|
|
1206
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
1207
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1208
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1209
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1210
|
-
return false;
|
|
1211
|
-
}
|
|
1212
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
1213
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
1214
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
1215
|
-
const __avKeywords2 = ["get", "linear", "activity"];
|
|
1216
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
1217
|
-
const __avRegex2 = /\b(?:get|linear|activity)\b/i;
|
|
1218
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
1219
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
1220
|
-
const __avExpectedSource2 = "";
|
|
1221
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
1222
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
1223
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
1224
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
1225
|
-
return false;
|
|
1226
|
-
}
|
|
1227
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
1228
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
1229
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
1230
|
-
const __avKeywords3 = ["get", "linear", "activity"];
|
|
1231
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
1232
|
-
const __avRegex3 = /\b(?:get|linear|activity)\b/i;
|
|
1233
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
1234
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
1235
|
-
const __avExpectedSource3 = "";
|
|
1236
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
1237
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
1238
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
1239
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
1240
|
-
return false;
|
|
1241
|
-
}
|
|
1242
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
1243
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
1244
|
-
return !!apiKey;
|
|
1245
|
-
};
|
|
1246
|
-
try {
|
|
1247
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
1248
|
-
} catch {
|
|
1249
|
-
return false;
|
|
1250
|
-
}
|
|
1251
|
-
};
|
|
1252
|
-
try {
|
|
1253
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
1254
|
-
} catch {
|
|
1255
|
-
return false;
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
try {
|
|
1259
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1260
|
-
} catch {
|
|
1261
|
-
return false;
|
|
1262
|
-
}
|
|
1263
|
-
},
|
|
1264
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
1265
|
-
try {
|
|
1266
|
-
const linearService = runtime.getService("linear");
|
|
1267
|
-
if (!linearService) {
|
|
1268
|
-
throw new Error("Linear service not available");
|
|
1269
|
-
}
|
|
1270
|
-
const content = message.content.text || "";
|
|
1271
|
-
const filters = {};
|
|
1272
|
-
let limit = 10;
|
|
1273
|
-
if (content) {
|
|
1274
|
-
const prompt = getActivityTemplate.replace("{{userMessage}}", content);
|
|
1275
|
-
const response = await runtime.useModel(ModelType4.TEXT_LARGE, {
|
|
1276
|
-
prompt
|
|
1277
|
-
});
|
|
1278
|
-
if (response) {
|
|
1279
|
-
try {
|
|
1280
|
-
const parsed = JSON.parse(response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim());
|
|
1281
|
-
if (parsed.timeRange) {
|
|
1282
|
-
const now = new Date;
|
|
1283
|
-
let fromDate;
|
|
1284
|
-
if (parsed.timeRange.from) {
|
|
1285
|
-
fromDate = new Date(parsed.timeRange.from);
|
|
1286
|
-
} else if (parsed.timeRange.period) {
|
|
1287
|
-
switch (parsed.timeRange.period) {
|
|
1288
|
-
case "today":
|
|
1289
|
-
fromDate = new Date(now.setHours(0, 0, 0, 0));
|
|
1290
|
-
break;
|
|
1291
|
-
case "yesterday":
|
|
1292
|
-
fromDate = new Date(now.setDate(now.getDate() - 1));
|
|
1293
|
-
fromDate.setHours(0, 0, 0, 0);
|
|
1294
|
-
break;
|
|
1295
|
-
case "this-week":
|
|
1296
|
-
fromDate = new Date(now.setDate(now.getDate() - now.getDay()));
|
|
1297
|
-
fromDate.setHours(0, 0, 0, 0);
|
|
1298
|
-
break;
|
|
1299
|
-
case "last-week":
|
|
1300
|
-
fromDate = new Date(now.setDate(now.getDate() - now.getDay() - 7));
|
|
1301
|
-
fromDate.setHours(0, 0, 0, 0);
|
|
1302
|
-
break;
|
|
1303
|
-
case "this-month":
|
|
1304
|
-
fromDate = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
1305
|
-
break;
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
if (fromDate) {
|
|
1309
|
-
filters.fromDate = fromDate.toISOString();
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
if (parsed.actionTypes && parsed.actionTypes.length > 0) {
|
|
1313
|
-
filters.action = parsed.actionTypes[0];
|
|
1314
|
-
}
|
|
1315
|
-
if (parsed.resourceTypes && parsed.resourceTypes.length > 0) {
|
|
1316
|
-
filters.resource_type = parsed.resourceTypes[0];
|
|
1317
|
-
}
|
|
1318
|
-
if (parsed.resourceId) {
|
|
1319
|
-
filters.resource_id = parsed.resourceId;
|
|
1320
|
-
}
|
|
1321
|
-
if (parsed.successFilter && parsed.successFilter !== "all") {
|
|
1322
|
-
filters.success = parsed.successFilter === "success";
|
|
1323
|
-
}
|
|
1324
|
-
limit = parsed.limit || 10;
|
|
1325
|
-
} catch (parseError) {
|
|
1326
|
-
logger5.warn("Failed to parse activity filters:", parseError);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
let activity = linearService.getActivityLog(limit * 2, filters);
|
|
1331
|
-
if (filters.fromDate) {
|
|
1332
|
-
const fromDateValue = filters.fromDate;
|
|
1333
|
-
const fromDate = typeof fromDateValue === "string" ? fromDateValue : fromDateValue instanceof Date ? fromDateValue.toISOString() : String(fromDateValue);
|
|
1334
|
-
const fromTime = new Date(fromDate).getTime();
|
|
1335
|
-
if (!Number.isNaN(fromTime)) {
|
|
1336
|
-
activity = activity.filter((item) => new Date(item.timestamp).getTime() >= fromTime);
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
activity = activity.slice(0, limit);
|
|
1340
|
-
if (activity.length === 0) {
|
|
1341
|
-
const noActivityMessage = filters.fromDate ? `No Linear activity found for the specified filters.` : "No recent Linear activity found.";
|
|
1342
|
-
await callback?.({
|
|
1343
|
-
text: noActivityMessage,
|
|
1344
|
-
source: message.content.source
|
|
1345
|
-
});
|
|
1346
|
-
return {
|
|
1347
|
-
text: noActivityMessage,
|
|
1348
|
-
success: true,
|
|
1349
|
-
data: {
|
|
1350
|
-
activity: []
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
}
|
|
1354
|
-
const activityText = activity.map((item, index) => {
|
|
1355
|
-
const time = new Date(item.timestamp).toLocaleString();
|
|
1356
|
-
const status = item.success ? "✅" : "❌";
|
|
1357
|
-
const details = Object.entries(item.details).filter(([key]) => key !== "filters").map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(", ");
|
|
1358
|
-
return `${index + 1}. ${status} ${item.action} on ${item.resource_type} ${item.resource_id}
|
|
1359
|
-
Time: ${time}
|
|
1360
|
-
${details ? `Details: ${details}` : ""}${item.error ? `
|
|
1361
|
-
Error: ${item.error}` : ""}`;
|
|
1362
|
-
}).join(`
|
|
1363
|
-
|
|
1364
|
-
`);
|
|
1365
|
-
const headerText = filters.fromDate ? `\uD83D\uDCCA Linear activity ${content}:` : "\uD83D\uDCCA Recent Linear activity:";
|
|
1366
|
-
const resultMessage = `${headerText}
|
|
1367
|
-
|
|
1368
|
-
${activityText}`;
|
|
1369
|
-
await callback?.({
|
|
1370
|
-
text: resultMessage,
|
|
1371
|
-
source: message.content.source
|
|
1372
|
-
});
|
|
1373
|
-
return {
|
|
1374
|
-
text: `Found ${activity.length} activity item${activity.length === 1 ? "" : "s"}`,
|
|
1375
|
-
success: true,
|
|
1376
|
-
data: {
|
|
1377
|
-
activity: activity.map((item) => ({
|
|
1378
|
-
id: item.id,
|
|
1379
|
-
action: item.action,
|
|
1380
|
-
resource_type: item.resource_type,
|
|
1381
|
-
resource_id: item.resource_id,
|
|
1382
|
-
success: item.success,
|
|
1383
|
-
error: item.error,
|
|
1384
|
-
details: JSON.stringify(item.details),
|
|
1385
|
-
timestamp: typeof item.timestamp === "string" ? item.timestamp : new Date(item.timestamp).toISOString()
|
|
1386
|
-
})),
|
|
1387
|
-
filters: filters ? {
|
|
1388
|
-
...filters,
|
|
1389
|
-
fromDate: filters.fromDate ? typeof filters.fromDate === "string" ? filters.fromDate : String(filters.fromDate) : undefined
|
|
1390
|
-
} : undefined,
|
|
1391
|
-
count: activity.length
|
|
1392
|
-
}
|
|
1393
|
-
};
|
|
1394
|
-
} catch (error) {
|
|
1395
|
-
logger5.error("Failed to get activity:", error);
|
|
1396
|
-
const errorMessage = `❌ Failed to get activity: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
1397
|
-
await callback?.({
|
|
1398
|
-
text: errorMessage,
|
|
1399
|
-
source: message.content.source
|
|
1400
|
-
});
|
|
1401
|
-
return {
|
|
1402
|
-
text: errorMessage,
|
|
1403
|
-
success: false
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
};
|
|
1408
|
-
|
|
1409
|
-
// src/actions/getIssue.ts
|
|
1410
|
-
import {
|
|
1411
|
-
logger as logger6,
|
|
1412
|
-
ModelType as ModelType5
|
|
1413
|
-
} from "@elizaos/core";
|
|
1414
|
-
var getIssueAction = {
|
|
1415
|
-
name: "GET_LINEAR_ISSUE",
|
|
1416
|
-
description: "Get details of a specific Linear issue",
|
|
1417
|
-
similes: [
|
|
1418
|
-
"get-linear-issue",
|
|
1419
|
-
"show-linear-issue",
|
|
1420
|
-
"view-linear-issue",
|
|
1421
|
-
"check-linear-issue",
|
|
1422
|
-
"find-linear-issue"
|
|
1423
|
-
],
|
|
1424
|
-
examples: [
|
|
1425
|
-
[
|
|
1426
|
-
{
|
|
1427
|
-
name: "User",
|
|
1428
|
-
content: {
|
|
1429
|
-
text: "Show me issue ENG-123"
|
|
1430
|
-
}
|
|
1431
|
-
},
|
|
1432
|
-
{
|
|
1433
|
-
name: "Assistant",
|
|
1434
|
-
content: {
|
|
1435
|
-
text: "I'll get the details for issue ENG-123.",
|
|
1436
|
-
actions: ["GET_LINEAR_ISSUE"]
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
],
|
|
1440
|
-
[
|
|
1441
|
-
{
|
|
1442
|
-
name: "User",
|
|
1443
|
-
content: {
|
|
1444
|
-
text: "What's the status of the login bug?"
|
|
1445
|
-
}
|
|
1446
|
-
},
|
|
1447
|
-
{
|
|
1448
|
-
name: "Assistant",
|
|
1449
|
-
content: {
|
|
1450
|
-
text: "Let me find the login bug issue for you.",
|
|
1451
|
-
actions: ["GET_LINEAR_ISSUE"]
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
],
|
|
1455
|
-
[
|
|
1456
|
-
{
|
|
1457
|
-
name: "User",
|
|
1458
|
-
content: {
|
|
1459
|
-
text: "Show me the latest high priority issue assigned to Sarah"
|
|
1460
|
-
}
|
|
1461
|
-
},
|
|
1462
|
-
{
|
|
1463
|
-
name: "Assistant",
|
|
1464
|
-
content: {
|
|
1465
|
-
text: "I'll find the latest high priority issue assigned to Sarah.",
|
|
1466
|
-
actions: ["GET_LINEAR_ISSUE"]
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
]
|
|
1470
|
-
],
|
|
1471
|
-
validate: async (runtime, message, state, options) => {
|
|
1472
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1473
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1474
|
-
const __avKeywords = ["get", "linear", "issue"];
|
|
1475
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
1476
|
-
const __avRegex = /\b(?:get|linear|issue)\b/i;
|
|
1477
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
1478
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1479
|
-
const __avExpectedSource = "";
|
|
1480
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
1481
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1482
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1483
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1484
|
-
return false;
|
|
1485
|
-
}
|
|
1486
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
1487
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
1488
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
1489
|
-
const __avKeywords2 = ["get", "linear", "issue"];
|
|
1490
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
1491
|
-
const __avRegex2 = /\b(?:get|linear|issue)\b/i;
|
|
1492
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
1493
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
1494
|
-
const __avExpectedSource2 = "";
|
|
1495
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
1496
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
1497
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
1498
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
1499
|
-
return false;
|
|
1500
|
-
}
|
|
1501
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
1502
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
1503
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
1504
|
-
const __avKeywords3 = ["get", "linear", "issue"];
|
|
1505
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
1506
|
-
const __avRegex3 = /\b(?:get|linear|issue)\b/i;
|
|
1507
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
1508
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
1509
|
-
const __avExpectedSource3 = "";
|
|
1510
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
1511
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
1512
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
1513
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
1514
|
-
return false;
|
|
1515
|
-
}
|
|
1516
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
1517
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
1518
|
-
return !!apiKey;
|
|
1519
|
-
};
|
|
1520
|
-
try {
|
|
1521
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
1522
|
-
} catch {
|
|
1523
|
-
return false;
|
|
1524
|
-
}
|
|
1525
|
-
};
|
|
1526
|
-
try {
|
|
1527
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
1528
|
-
} catch {
|
|
1529
|
-
return false;
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
try {
|
|
1533
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1534
|
-
} catch {
|
|
1535
|
-
return false;
|
|
1536
|
-
}
|
|
1537
|
-
},
|
|
1538
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
1539
|
-
try {
|
|
1540
|
-
const linearService = runtime.getService("linear");
|
|
1541
|
-
if (!linearService) {
|
|
1542
|
-
throw new Error("Linear service not available");
|
|
1543
|
-
}
|
|
1544
|
-
const content = message.content.text;
|
|
1545
|
-
if (!content) {
|
|
1546
|
-
const errorMessage2 = "Please specify which issue you want to see.";
|
|
1547
|
-
await callback?.({
|
|
1548
|
-
text: errorMessage2,
|
|
1549
|
-
source: message.content.source
|
|
1550
|
-
});
|
|
1551
|
-
return {
|
|
1552
|
-
text: errorMessage2,
|
|
1553
|
-
success: false
|
|
1554
|
-
};
|
|
1555
|
-
}
|
|
1556
|
-
const prompt = getIssueTemplate.replace("{{userMessage}}", content);
|
|
1557
|
-
const response = await runtime.useModel(ModelType5.TEXT_LARGE, {
|
|
1558
|
-
prompt
|
|
1559
|
-
});
|
|
1560
|
-
if (!response) {
|
|
1561
|
-
const issueMatch = content.match(/(\w+-\d+)/);
|
|
1562
|
-
if (issueMatch) {
|
|
1563
|
-
const issue = await linearService.getIssue(issueMatch[1]);
|
|
1564
|
-
return await formatIssueResponse(issue, callback, message);
|
|
1565
|
-
}
|
|
1566
|
-
throw new Error("Could not understand issue reference");
|
|
1567
|
-
}
|
|
1568
|
-
try {
|
|
1569
|
-
const parsed = JSON.parse(response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim());
|
|
1570
|
-
if (parsed.directId) {
|
|
1571
|
-
const issue = await linearService.getIssue(parsed.directId);
|
|
1572
|
-
return await formatIssueResponse(issue, callback, message);
|
|
1573
|
-
}
|
|
1574
|
-
if (parsed.searchBy && Object.keys(parsed.searchBy).length > 0) {
|
|
1575
|
-
const filters = {};
|
|
1576
|
-
if (parsed.searchBy.title) {
|
|
1577
|
-
filters.query = parsed.searchBy.title;
|
|
1578
|
-
}
|
|
1579
|
-
if (parsed.searchBy.assignee) {
|
|
1580
|
-
filters.assignee = [parsed.searchBy.assignee];
|
|
1581
|
-
}
|
|
1582
|
-
if (parsed.searchBy.priority) {
|
|
1583
|
-
const priorityMap = {
|
|
1584
|
-
urgent: 1,
|
|
1585
|
-
high: 2,
|
|
1586
|
-
normal: 3,
|
|
1587
|
-
low: 4,
|
|
1588
|
-
"1": 1,
|
|
1589
|
-
"2": 2,
|
|
1590
|
-
"3": 3,
|
|
1591
|
-
"4": 4
|
|
1592
|
-
};
|
|
1593
|
-
const priority = priorityMap[parsed.searchBy.priority.toLowerCase()];
|
|
1594
|
-
if (priority) {
|
|
1595
|
-
filters.priority = [priority];
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
if (parsed.searchBy.team) {
|
|
1599
|
-
filters.team = parsed.searchBy.team;
|
|
1600
|
-
}
|
|
1601
|
-
if (parsed.searchBy.state) {
|
|
1602
|
-
filters.state = [parsed.searchBy.state];
|
|
1603
|
-
}
|
|
1604
|
-
const defaultTeamKey = runtime.getSetting("LINEAR_DEFAULT_TEAM_KEY");
|
|
1605
|
-
if (defaultTeamKey && !filters.team) {
|
|
1606
|
-
filters.team = defaultTeamKey;
|
|
1607
|
-
}
|
|
1608
|
-
const issues = await linearService.searchIssues({
|
|
1609
|
-
...filters,
|
|
1610
|
-
limit: parsed.searchBy.recency ? 10 : 5
|
|
1611
|
-
});
|
|
1612
|
-
if (issues.length === 0) {
|
|
1613
|
-
const noResultsMessage = "No issues found matching your criteria.";
|
|
1614
|
-
await callback?.({
|
|
1615
|
-
text: noResultsMessage,
|
|
1616
|
-
source: message.content.source
|
|
1617
|
-
});
|
|
1618
|
-
return {
|
|
1619
|
-
text: noResultsMessage,
|
|
1620
|
-
success: false
|
|
1621
|
-
};
|
|
1622
|
-
}
|
|
1623
|
-
if (parsed.searchBy.recency) {
|
|
1624
|
-
issues.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
1625
|
-
}
|
|
1626
|
-
if (parsed.searchBy.recency && issues.length > 0) {
|
|
1627
|
-
return await formatIssueResponse(issues[0], callback, message);
|
|
1628
|
-
}
|
|
1629
|
-
if (issues.length === 1) {
|
|
1630
|
-
return await formatIssueResponse(issues[0], callback, message);
|
|
1631
|
-
}
|
|
1632
|
-
const issueList = await Promise.all(issues.slice(0, 5).map(async (issue, index) => {
|
|
1633
|
-
const state = await issue.state;
|
|
1634
|
-
return `${index + 1}. ${issue.identifier}: ${issue.title} (${state?.name || "No state"})`;
|
|
1635
|
-
}));
|
|
1636
|
-
const clarifyMessage = `Found ${issues.length} issues matching your criteria:
|
|
1637
|
-
${issueList.join(`
|
|
1638
|
-
`)}
|
|
1639
|
-
|
|
1640
|
-
Please specify which one you want to see by its ID.`;
|
|
1641
|
-
await callback?.({
|
|
1642
|
-
text: clarifyMessage,
|
|
1643
|
-
source: message.content.source
|
|
1644
|
-
});
|
|
1645
|
-
return {
|
|
1646
|
-
text: clarifyMessage,
|
|
1647
|
-
success: true,
|
|
1648
|
-
data: {
|
|
1649
|
-
multipleResults: true,
|
|
1650
|
-
issues: issues.slice(0, 5).map((i) => ({
|
|
1651
|
-
id: i.id,
|
|
1652
|
-
identifier: i.identifier,
|
|
1653
|
-
title: i.title
|
|
1654
|
-
}))
|
|
1655
|
-
}
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
} catch (parseError) {
|
|
1659
|
-
logger6.warn("Failed to parse LLM response, falling back to regex:", parseError);
|
|
1660
|
-
const issueMatch = content.match(/(\w+-\d+)/);
|
|
1661
|
-
if (issueMatch) {
|
|
1662
|
-
const issue = await linearService.getIssue(issueMatch[1]);
|
|
1663
|
-
return await formatIssueResponse(issue, callback, message);
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
const errorMessage = "Could not understand which issue you want to see. Please provide an issue ID (e.g., ENG-123) or describe it more specifically.";
|
|
1667
|
-
await callback?.({
|
|
1668
|
-
text: errorMessage,
|
|
1669
|
-
source: message.content.source
|
|
1670
|
-
});
|
|
1671
|
-
return {
|
|
1672
|
-
text: errorMessage,
|
|
1673
|
-
success: false
|
|
1674
|
-
};
|
|
1675
|
-
} catch (error) {
|
|
1676
|
-
logger6.error("Failed to get issue:", error);
|
|
1677
|
-
const errorMessage = `❌ Failed to get issue: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
1678
|
-
await callback?.({
|
|
1679
|
-
text: errorMessage,
|
|
1680
|
-
source: message.content.source
|
|
1681
|
-
});
|
|
1682
|
-
return {
|
|
1683
|
-
text: errorMessage,
|
|
1684
|
-
success: false
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
};
|
|
1689
|
-
async function formatIssueResponse(issue, callback, message) {
|
|
1690
|
-
const assignee = await issue.assignee;
|
|
1691
|
-
const state = await issue.state;
|
|
1692
|
-
const team = await issue.team;
|
|
1693
|
-
const labels = await issue.labels();
|
|
1694
|
-
const project = await issue.project;
|
|
1695
|
-
const issueDetails = {
|
|
1696
|
-
id: issue.id,
|
|
1697
|
-
identifier: issue.identifier,
|
|
1698
|
-
title: issue.title,
|
|
1699
|
-
description: issue.description,
|
|
1700
|
-
priority: issue.priority,
|
|
1701
|
-
priorityLabel: issue.priorityLabel,
|
|
1702
|
-
url: issue.url,
|
|
1703
|
-
createdAt: issue.createdAt,
|
|
1704
|
-
updatedAt: issue.updatedAt,
|
|
1705
|
-
dueDate: issue.dueDate,
|
|
1706
|
-
estimate: issue.estimate,
|
|
1707
|
-
assignee: assignee ? {
|
|
1708
|
-
id: assignee.id,
|
|
1709
|
-
name: assignee.name,
|
|
1710
|
-
email: assignee.email
|
|
1711
|
-
} : null,
|
|
1712
|
-
state: state ? {
|
|
1713
|
-
id: state.id,
|
|
1714
|
-
name: state.name,
|
|
1715
|
-
type: state.type,
|
|
1716
|
-
color: state.color
|
|
1717
|
-
} : null,
|
|
1718
|
-
team: team ? {
|
|
1719
|
-
id: team.id,
|
|
1720
|
-
name: team.name,
|
|
1721
|
-
key: team.key
|
|
1722
|
-
} : null,
|
|
1723
|
-
labels: labels.nodes.map((label) => ({
|
|
1724
|
-
id: label.id,
|
|
1725
|
-
name: label.name,
|
|
1726
|
-
color: label.color
|
|
1727
|
-
})),
|
|
1728
|
-
project: project ? {
|
|
1729
|
-
id: project.id,
|
|
1730
|
-
name: project.name,
|
|
1731
|
-
description: project.description
|
|
1732
|
-
} : null
|
|
1733
|
-
};
|
|
1734
|
-
const priorityLabels = ["", "Urgent", "High", "Normal", "Low"];
|
|
1735
|
-
const priority = priorityLabels[issue.priority || 0] || "No priority";
|
|
1736
|
-
const labelText = issueDetails.labels.length > 0 ? `Labels: ${issueDetails.labels.map((l) => l.name).join(", ")}` : "";
|
|
1737
|
-
const issueMessage = `\uD83D\uDCCB **${issue.identifier}: ${issue.title}**
|
|
1738
|
-
|
|
1739
|
-
Status: ${state?.name || "No status"}
|
|
1740
|
-
Priority: ${priority}
|
|
1741
|
-
Team: ${team?.name || "No team"}
|
|
1742
|
-
Assignee: ${assignee?.name || "Unassigned"}
|
|
1743
|
-
${issue.dueDate ? `Due: ${new Date(issue.dueDate).toLocaleDateString()}` : ""}
|
|
1744
|
-
${labelText}
|
|
1745
|
-
${project ? `Project: ${project.name}` : ""}
|
|
1746
|
-
|
|
1747
|
-
${issue.description || "No description"}
|
|
1748
|
-
|
|
1749
|
-
View in Linear: ${issue.url}`;
|
|
1750
|
-
await callback?.({
|
|
1751
|
-
text: issueMessage,
|
|
1752
|
-
source: message.content.source
|
|
1753
|
-
});
|
|
1754
|
-
const serializedIssue = {
|
|
1755
|
-
...issueDetails,
|
|
1756
|
-
createdAt: issueDetails.createdAt instanceof Date ? issueDetails.createdAt.toISOString() : issueDetails.createdAt,
|
|
1757
|
-
updatedAt: issueDetails.updatedAt instanceof Date ? issueDetails.updatedAt.toISOString() : issueDetails.updatedAt,
|
|
1758
|
-
dueDate: issueDetails.dueDate ? issueDetails.dueDate instanceof Date ? issueDetails.dueDate.toISOString() : issueDetails.dueDate : null
|
|
1759
|
-
};
|
|
1760
|
-
return {
|
|
1761
|
-
text: `Retrieved issue ${issue.identifier}: ${issue.title}`,
|
|
1762
|
-
success: true,
|
|
1763
|
-
data: { issue: serializedIssue }
|
|
1764
|
-
};
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
// src/actions/listProjects.ts
|
|
1768
|
-
import {
|
|
1769
|
-
logger as logger7,
|
|
1770
|
-
ModelType as ModelType6
|
|
1771
|
-
} from "@elizaos/core";
|
|
1772
|
-
var listProjectsAction = {
|
|
1773
|
-
name: "LIST_LINEAR_PROJECTS",
|
|
1774
|
-
description: "List projects in Linear with optional filters",
|
|
1775
|
-
similes: [
|
|
1776
|
-
"list-linear-projects",
|
|
1777
|
-
"show-linear-projects",
|
|
1778
|
-
"get-linear-projects",
|
|
1779
|
-
"view-linear-projects"
|
|
1780
|
-
],
|
|
1781
|
-
examples: [
|
|
1782
|
-
[
|
|
1783
|
-
{
|
|
1784
|
-
name: "User",
|
|
1785
|
-
content: {
|
|
1786
|
-
text: "Show me all projects"
|
|
1787
|
-
}
|
|
1788
|
-
},
|
|
1789
|
-
{
|
|
1790
|
-
name: "Assistant",
|
|
1791
|
-
content: {
|
|
1792
|
-
text: "I'll list all the projects in Linear for you.",
|
|
1793
|
-
actions: ["LIST_LINEAR_PROJECTS"]
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
],
|
|
1797
|
-
[
|
|
1798
|
-
{
|
|
1799
|
-
name: "User",
|
|
1800
|
-
content: {
|
|
1801
|
-
text: "What active projects do we have?"
|
|
1802
|
-
}
|
|
1803
|
-
},
|
|
1804
|
-
{
|
|
1805
|
-
name: "Assistant",
|
|
1806
|
-
content: {
|
|
1807
|
-
text: "Let me show you all the active projects.",
|
|
1808
|
-
actions: ["LIST_LINEAR_PROJECTS"]
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
],
|
|
1812
|
-
[
|
|
1813
|
-
{
|
|
1814
|
-
name: "User",
|
|
1815
|
-
content: {
|
|
1816
|
-
text: "Show me projects for the engineering team"
|
|
1817
|
-
}
|
|
1818
|
-
},
|
|
1819
|
-
{
|
|
1820
|
-
name: "Assistant",
|
|
1821
|
-
content: {
|
|
1822
|
-
text: "I'll find the projects for the engineering team.",
|
|
1823
|
-
actions: ["LIST_LINEAR_PROJECTS"]
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
]
|
|
1827
|
-
],
|
|
1828
|
-
validate: async (runtime, message, state, options) => {
|
|
1829
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
1830
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
1831
|
-
const __avKeywords = ["list", "linear", "projects"];
|
|
1832
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
1833
|
-
const __avRegex = /\b(?:list|linear|projects)\b/i;
|
|
1834
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
1835
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
1836
|
-
const __avExpectedSource = "";
|
|
1837
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
1838
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
1839
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
1840
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
1841
|
-
return false;
|
|
1842
|
-
}
|
|
1843
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
1844
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
1845
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
1846
|
-
const __avKeywords2 = ["list", "linear", "projects"];
|
|
1847
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
1848
|
-
const __avRegex2 = /\b(?:list|linear|projects)\b/i;
|
|
1849
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
1850
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
1851
|
-
const __avExpectedSource2 = "";
|
|
1852
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
1853
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
1854
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
1855
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
1856
|
-
return false;
|
|
1857
|
-
}
|
|
1858
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
1859
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
1860
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
1861
|
-
const __avKeywords3 = ["list", "linear", "projects"];
|
|
1862
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
1863
|
-
const __avRegex3 = /\b(?:list|linear|projects)\b/i;
|
|
1864
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
1865
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
1866
|
-
const __avExpectedSource3 = "";
|
|
1867
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
1868
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
1869
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
1870
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
1871
|
-
return false;
|
|
1872
|
-
}
|
|
1873
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
1874
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
1875
|
-
return !!apiKey;
|
|
1876
|
-
};
|
|
1877
|
-
try {
|
|
1878
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
1879
|
-
} catch {
|
|
1880
|
-
return false;
|
|
1881
|
-
}
|
|
1882
|
-
};
|
|
1883
|
-
try {
|
|
1884
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
1885
|
-
} catch {
|
|
1886
|
-
return false;
|
|
1887
|
-
}
|
|
1888
|
-
};
|
|
1889
|
-
try {
|
|
1890
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
1891
|
-
} catch {
|
|
1892
|
-
return false;
|
|
1893
|
-
}
|
|
1894
|
-
},
|
|
1895
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
1896
|
-
try {
|
|
1897
|
-
const linearService = runtime.getService("linear");
|
|
1898
|
-
if (!linearService) {
|
|
1899
|
-
throw new Error("Linear service not available");
|
|
1900
|
-
}
|
|
1901
|
-
const content = message.content.text || "";
|
|
1902
|
-
let teamId;
|
|
1903
|
-
let showAll = false;
|
|
1904
|
-
let stateFilter;
|
|
1905
|
-
if (content) {
|
|
1906
|
-
const prompt = listProjectsTemplate.replace("{{userMessage}}", content);
|
|
1907
|
-
const response = await runtime.useModel(ModelType6.TEXT_LARGE, {
|
|
1908
|
-
prompt
|
|
1909
|
-
});
|
|
1910
|
-
if (response) {
|
|
1911
|
-
try {
|
|
1912
|
-
const parsed = JSON.parse(response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim());
|
|
1913
|
-
if (parsed.teamFilter) {
|
|
1914
|
-
const teams = await linearService.getTeams();
|
|
1915
|
-
const team = teams.find((t) => t.key.toLowerCase() === parsed.teamFilter.toLowerCase() || t.name.toLowerCase() === parsed.teamFilter.toLowerCase());
|
|
1916
|
-
if (team) {
|
|
1917
|
-
teamId = team.id;
|
|
1918
|
-
logger7.info(`Filtering projects by team: ${team.name} (${team.key})`);
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
showAll = parsed.showAll === true;
|
|
1922
|
-
stateFilter = parsed.stateFilter;
|
|
1923
|
-
} catch (parseError) {
|
|
1924
|
-
logger7.warn("Failed to parse project filters, using basic parsing:", parseError);
|
|
1925
|
-
const teamMatch = content.match(/(?:for|in|of)\s+(?:the\s+)?(\w+)\s+team/i);
|
|
1926
|
-
if (teamMatch) {
|
|
1927
|
-
const teams = await linearService.getTeams();
|
|
1928
|
-
const team = teams.find((t) => t.key.toLowerCase() === teamMatch[1].toLowerCase() || t.name.toLowerCase() === teamMatch[1].toLowerCase());
|
|
1929
|
-
if (team) {
|
|
1930
|
-
teamId = team.id;
|
|
1931
|
-
logger7.info(`Filtering projects by team: ${team.name} (${team.key})`);
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
showAll = content.toLowerCase().includes("all") && content.toLowerCase().includes("project");
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
if (!teamId && !showAll) {
|
|
1939
|
-
const defaultTeamKey = runtime.getSetting("LINEAR_DEFAULT_TEAM_KEY");
|
|
1940
|
-
if (defaultTeamKey) {
|
|
1941
|
-
const teams = await linearService.getTeams();
|
|
1942
|
-
const defaultTeam = teams.find((t) => t.key.toLowerCase() === defaultTeamKey.toLowerCase());
|
|
1943
|
-
if (defaultTeam) {
|
|
1944
|
-
teamId = defaultTeam.id;
|
|
1945
|
-
logger7.info(`Applying default team filter for projects: ${defaultTeam.name} (${defaultTeam.key})`);
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
let projects = await linearService.getProjects(teamId);
|
|
1950
|
-
if (stateFilter && stateFilter !== "all") {
|
|
1951
|
-
projects = projects.filter((project) => {
|
|
1952
|
-
const state = project.state?.toLowerCase() || "";
|
|
1953
|
-
if (stateFilter === "active") {
|
|
1954
|
-
return state === "started" || state === "in progress" || !state;
|
|
1955
|
-
} else if (stateFilter === "planned") {
|
|
1956
|
-
return state === "planned" || state === "backlog";
|
|
1957
|
-
} else if (stateFilter === "completed") {
|
|
1958
|
-
return state === "completed" || state === "done" || state === "canceled";
|
|
1959
|
-
}
|
|
1960
|
-
return true;
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
if (projects.length === 0) {
|
|
1964
|
-
const noProjectsMessage = teamId ? "No projects found for the specified team." : "No projects found in Linear.";
|
|
1965
|
-
await callback?.({
|
|
1966
|
-
text: noProjectsMessage,
|
|
1967
|
-
source: message.content.source
|
|
1968
|
-
});
|
|
1969
|
-
return {
|
|
1970
|
-
text: noProjectsMessage,
|
|
1971
|
-
success: true,
|
|
1972
|
-
data: {
|
|
1973
|
-
projects: []
|
|
1974
|
-
}
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
const projectsWithDetails = await Promise.all(projects.map(async (project) => {
|
|
1978
|
-
const teamsQuery = await project.teams();
|
|
1979
|
-
const teams = await teamsQuery.nodes;
|
|
1980
|
-
const lead = await project.lead;
|
|
1981
|
-
return {
|
|
1982
|
-
...project,
|
|
1983
|
-
teamsList: teams,
|
|
1984
|
-
leadUser: lead
|
|
1985
|
-
};
|
|
1986
|
-
}));
|
|
1987
|
-
const projectList = projectsWithDetails.map((project, index) => {
|
|
1988
|
-
const teamNames = project.teamsList.map((t) => t.name).join(", ") || "No teams";
|
|
1989
|
-
const status = project.state || "Active";
|
|
1990
|
-
const progress = project.progress ? ` (${Math.round(project.progress * 100)}% complete)` : "";
|
|
1991
|
-
const lead = project.leadUser ? ` | Lead: ${project.leadUser.name}` : "";
|
|
1992
|
-
const dates = [];
|
|
1993
|
-
if (project.startDate)
|
|
1994
|
-
dates.push(`Start: ${new Date(project.startDate).toLocaleDateString()}`);
|
|
1995
|
-
if (project.targetDate)
|
|
1996
|
-
dates.push(`Due: ${new Date(project.targetDate).toLocaleDateString()}`);
|
|
1997
|
-
const dateInfo = dates.length > 0 ? `
|
|
1998
|
-
${dates.join(" | ")}` : "";
|
|
1999
|
-
return `${index + 1}. ${project.name}${project.description ? ` - ${project.description}` : ""}
|
|
2000
|
-
Status: ${status}${progress} | Teams: ${teamNames}${lead}${dateInfo}`;
|
|
2001
|
-
}).join(`
|
|
2002
|
-
|
|
2003
|
-
`);
|
|
2004
|
-
const headerText = stateFilter && stateFilter !== "all" ? `\uD83D\uDCC1 Found ${projects.length} ${stateFilter} project${projects.length === 1 ? "" : "s"}:` : `\uD83D\uDCC1 Found ${projects.length} project${projects.length === 1 ? "" : "s"}:`;
|
|
2005
|
-
const resultMessage = `${headerText}
|
|
2006
|
-
|
|
2007
|
-
${projectList}`;
|
|
2008
|
-
await callback?.({
|
|
2009
|
-
text: resultMessage,
|
|
2010
|
-
source: message.content.source
|
|
2011
|
-
});
|
|
2012
|
-
return {
|
|
2013
|
-
text: `Found ${projects.length} project${projects.length === 1 ? "" : "s"}`,
|
|
2014
|
-
success: true,
|
|
2015
|
-
data: {
|
|
2016
|
-
projects: projectsWithDetails.map((p) => ({
|
|
2017
|
-
id: p.id,
|
|
2018
|
-
name: p.name,
|
|
2019
|
-
description: p.description,
|
|
2020
|
-
url: p.url,
|
|
2021
|
-
teams: p.teamsList.map((t) => ({
|
|
2022
|
-
id: t.id,
|
|
2023
|
-
name: t.name,
|
|
2024
|
-
key: t.key
|
|
2025
|
-
})),
|
|
2026
|
-
lead: p.leadUser ? {
|
|
2027
|
-
id: p.leadUser.id,
|
|
2028
|
-
name: p.leadUser.name,
|
|
2029
|
-
email: p.leadUser.email
|
|
2030
|
-
} : null,
|
|
2031
|
-
state: p.state,
|
|
2032
|
-
progress: p.progress,
|
|
2033
|
-
startDate: p.startDate,
|
|
2034
|
-
targetDate: p.targetDate
|
|
2035
|
-
})),
|
|
2036
|
-
count: projects.length,
|
|
2037
|
-
filters: {
|
|
2038
|
-
team: teamId,
|
|
2039
|
-
state: stateFilter
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
};
|
|
2043
|
-
} catch (error) {
|
|
2044
|
-
logger7.error("Failed to list projects:", error);
|
|
2045
|
-
const errorMessage = `❌ Failed to list projects: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
2046
|
-
await callback?.({
|
|
2047
|
-
text: errorMessage,
|
|
2048
|
-
source: message.content.source
|
|
2049
|
-
});
|
|
2050
|
-
return {
|
|
2051
|
-
text: errorMessage,
|
|
2052
|
-
success: false
|
|
2053
|
-
};
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
};
|
|
2057
|
-
|
|
2058
|
-
// src/actions/listTeams.ts
|
|
2059
|
-
import {
|
|
2060
|
-
logger as logger8,
|
|
2061
|
-
ModelType as ModelType7
|
|
2062
|
-
} from "@elizaos/core";
|
|
2063
|
-
var listTeamsAction = {
|
|
2064
|
-
name: "LIST_LINEAR_TEAMS",
|
|
2065
|
-
description: "List teams in Linear with optional filters",
|
|
2066
|
-
similes: ["list-linear-teams", "show-linear-teams", "get-linear-teams", "view-linear-teams"],
|
|
2067
|
-
examples: [
|
|
2068
|
-
[
|
|
2069
|
-
{
|
|
2070
|
-
name: "User",
|
|
2071
|
-
content: {
|
|
2072
|
-
text: "Show me all teams"
|
|
2073
|
-
}
|
|
2074
|
-
},
|
|
2075
|
-
{
|
|
2076
|
-
name: "Assistant",
|
|
2077
|
-
content: {
|
|
2078
|
-
text: "I'll list all the teams in Linear for you.",
|
|
2079
|
-
actions: ["LIST_LINEAR_TEAMS"]
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
],
|
|
2083
|
-
[
|
|
2084
|
-
{
|
|
2085
|
-
name: "User",
|
|
2086
|
-
content: {
|
|
2087
|
-
text: "Which engineering teams do we have?"
|
|
2088
|
-
}
|
|
2089
|
-
},
|
|
2090
|
-
{
|
|
2091
|
-
name: "Assistant",
|
|
2092
|
-
content: {
|
|
2093
|
-
text: "Let me find the engineering teams for you.",
|
|
2094
|
-
actions: ["LIST_LINEAR_TEAMS"]
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
],
|
|
2098
|
-
[
|
|
2099
|
-
{
|
|
2100
|
-
name: "User",
|
|
2101
|
-
content: {
|
|
2102
|
-
text: "Show me the teams I'm part of"
|
|
2103
|
-
}
|
|
2104
|
-
},
|
|
2105
|
-
{
|
|
2106
|
-
name: "Assistant",
|
|
2107
|
-
content: {
|
|
2108
|
-
text: "I'll show you the teams you're a member of.",
|
|
2109
|
-
actions: ["LIST_LINEAR_TEAMS"]
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
]
|
|
2113
|
-
],
|
|
2114
|
-
validate: async (runtime, message, state, options) => {
|
|
2115
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
2116
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
2117
|
-
const __avKeywords = ["list", "linear", "teams"];
|
|
2118
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
2119
|
-
const __avRegex = /\b(?:list|linear|teams)\b/i;
|
|
2120
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
2121
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
2122
|
-
const __avExpectedSource = "";
|
|
2123
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
2124
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
2125
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
2126
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
2127
|
-
return false;
|
|
2128
|
-
}
|
|
2129
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
2130
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
2131
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
2132
|
-
const __avKeywords2 = ["list", "linear", "teams"];
|
|
2133
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
2134
|
-
const __avRegex2 = /\b(?:list|linear|teams)\b/i;
|
|
2135
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
2136
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
2137
|
-
const __avExpectedSource2 = "";
|
|
2138
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
2139
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
2140
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
2141
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
2142
|
-
return false;
|
|
2143
|
-
}
|
|
2144
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
2145
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
2146
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
2147
|
-
const __avKeywords3 = ["list", "linear", "teams"];
|
|
2148
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
2149
|
-
const __avRegex3 = /\b(?:list|linear|teams)\b/i;
|
|
2150
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
2151
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
2152
|
-
const __avExpectedSource3 = "";
|
|
2153
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
2154
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
2155
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
2156
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
2157
|
-
return false;
|
|
2158
|
-
}
|
|
2159
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
2160
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
2161
|
-
return !!apiKey;
|
|
2162
|
-
};
|
|
2163
|
-
try {
|
|
2164
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
2165
|
-
} catch {
|
|
2166
|
-
return false;
|
|
2167
|
-
}
|
|
2168
|
-
};
|
|
2169
|
-
try {
|
|
2170
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
2171
|
-
} catch {
|
|
2172
|
-
return false;
|
|
2173
|
-
}
|
|
2174
|
-
};
|
|
2175
|
-
try {
|
|
2176
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
2177
|
-
} catch {
|
|
2178
|
-
return false;
|
|
2179
|
-
}
|
|
2180
|
-
},
|
|
2181
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
2182
|
-
try {
|
|
2183
|
-
const linearService = runtime.getService("linear");
|
|
2184
|
-
if (!linearService) {
|
|
2185
|
-
throw new Error("Linear service not available");
|
|
2186
|
-
}
|
|
2187
|
-
const content = message.content.text || "";
|
|
2188
|
-
let nameFilter;
|
|
2189
|
-
let specificTeam;
|
|
2190
|
-
let myTeams = false;
|
|
2191
|
-
let includeDetails = false;
|
|
2192
|
-
if (content) {
|
|
2193
|
-
const prompt = listTeamsTemplate.replace("{{userMessage}}", content);
|
|
2194
|
-
const response = await runtime.useModel(ModelType7.TEXT_LARGE, {
|
|
2195
|
-
prompt
|
|
2196
|
-
});
|
|
2197
|
-
if (response) {
|
|
2198
|
-
try {
|
|
2199
|
-
const parsed = JSON.parse(response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim());
|
|
2200
|
-
nameFilter = parsed.nameFilter;
|
|
2201
|
-
specificTeam = parsed.specificTeam;
|
|
2202
|
-
myTeams = parsed.myTeams === true;
|
|
2203
|
-
includeDetails = parsed.includeDetails === true;
|
|
2204
|
-
} catch (parseError) {
|
|
2205
|
-
logger8.warn("Failed to parse team filters:", parseError);
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
let teams = await linearService.getTeams();
|
|
2210
|
-
if (specificTeam) {
|
|
2211
|
-
teams = teams.filter((team) => team.key.toLowerCase() === specificTeam.toLowerCase() || team.name.toLowerCase() === specificTeam.toLowerCase());
|
|
2212
|
-
}
|
|
2213
|
-
if (nameFilter && !specificTeam) {
|
|
2214
|
-
const keywords = nameFilter.toLowerCase().split(/\s+/);
|
|
2215
|
-
teams = teams.filter((team) => {
|
|
2216
|
-
const teamText = `${team.name} ${team.description || ""}`.toLowerCase();
|
|
2217
|
-
return keywords.some((keyword) => teamText.includes(keyword));
|
|
2218
|
-
});
|
|
2219
|
-
}
|
|
2220
|
-
if (myTeams) {
|
|
2221
|
-
try {
|
|
2222
|
-
const userTeams = await linearService.getUserTeams();
|
|
2223
|
-
const userTeamIds = new Set(userTeams.map((t) => t.id));
|
|
2224
|
-
teams = teams.filter((team) => userTeamIds.has(team.id));
|
|
2225
|
-
} catch (error) {
|
|
2226
|
-
logger8.warn("Could not filter for user's teams:", error);
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
if (teams.length === 0) {
|
|
2230
|
-
const noTeamsMessage = specificTeam ? `No team found matching "${specificTeam}".` : nameFilter ? `No teams found matching "${nameFilter}".` : "No teams found in Linear.";
|
|
2231
|
-
await callback?.({
|
|
2232
|
-
text: noTeamsMessage,
|
|
2233
|
-
source: message.content.source
|
|
2234
|
-
});
|
|
2235
|
-
return {
|
|
2236
|
-
text: noTeamsMessage,
|
|
2237
|
-
success: true,
|
|
2238
|
-
data: {
|
|
2239
|
-
teams: []
|
|
2240
|
-
}
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
let teamsWithDetails = teams;
|
|
2244
|
-
if (includeDetails || specificTeam) {
|
|
2245
|
-
teamsWithDetails = await Promise.all(teams.map(async (team) => {
|
|
2246
|
-
const membersQuery = await team.members();
|
|
2247
|
-
const members = await membersQuery.nodes;
|
|
2248
|
-
const projectsQuery = await team.projects();
|
|
2249
|
-
const projects = await projectsQuery.nodes;
|
|
2250
|
-
return Object.assign(team, {
|
|
2251
|
-
memberCount: members.length,
|
|
2252
|
-
projectCount: projects.length,
|
|
2253
|
-
membersList: specificTeam ? members.slice(0, 5) : []
|
|
2254
|
-
});
|
|
2255
|
-
}));
|
|
2256
|
-
}
|
|
2257
|
-
const teamList = teamsWithDetails.map((team, index) => {
|
|
2258
|
-
let info = `${index + 1}. ${team.name} (${team.key})`;
|
|
2259
|
-
if (team.description) {
|
|
2260
|
-
info += `
|
|
2261
|
-
${team.description}`;
|
|
2262
|
-
}
|
|
2263
|
-
if (includeDetails || specificTeam) {
|
|
2264
|
-
info += `
|
|
2265
|
-
Members: ${team.memberCount ?? 0} | Projects: ${team.projectCount ?? 0}`;
|
|
2266
|
-
const membersList = team.membersList ?? [];
|
|
2267
|
-
if (specificTeam && membersList.length > 0) {
|
|
2268
|
-
const memberNames = membersList.map((m) => m.name).join(", ");
|
|
2269
|
-
info += `
|
|
2270
|
-
Team members: ${memberNames}${(team.memberCount ?? 0) > 5 ? " ..." : ""}`;
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
return info;
|
|
2274
|
-
}).join(`
|
|
2275
|
-
|
|
2276
|
-
`);
|
|
2277
|
-
const headerText = specificTeam && teams.length === 1 ? `\uD83D\uDCCB Team Details:` : nameFilter ? `\uD83D\uDCCB Found ${teams.length} team${teams.length === 1 ? "" : "s"} matching "${nameFilter}":` : `\uD83D\uDCCB Found ${teams.length} team${teams.length === 1 ? "" : "s"}:`;
|
|
2278
|
-
const resultMessage = `${headerText}
|
|
2279
|
-
|
|
2280
|
-
${teamList}`;
|
|
2281
|
-
await callback?.({
|
|
2282
|
-
text: resultMessage,
|
|
2283
|
-
source: message.content.source
|
|
2284
|
-
});
|
|
2285
|
-
return {
|
|
2286
|
-
text: `Found ${teams.length} team${teams.length === 1 ? "" : "s"}`,
|
|
2287
|
-
success: true,
|
|
2288
|
-
data: {
|
|
2289
|
-
teams: teamsWithDetails.map((t) => ({
|
|
2290
|
-
id: t.id,
|
|
2291
|
-
name: t.name,
|
|
2292
|
-
key: t.key,
|
|
2293
|
-
description: t.description,
|
|
2294
|
-
memberCount: t.memberCount,
|
|
2295
|
-
projectCount: t.projectCount
|
|
2296
|
-
})),
|
|
2297
|
-
count: teams.length,
|
|
2298
|
-
filters: {
|
|
2299
|
-
name: nameFilter,
|
|
2300
|
-
specific: specificTeam
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
};
|
|
2304
|
-
} catch (error) {
|
|
2305
|
-
logger8.error("Failed to list teams:", error);
|
|
2306
|
-
const errorMessage = `❌ Failed to list teams: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
2307
|
-
await callback?.({
|
|
2308
|
-
text: errorMessage,
|
|
2309
|
-
source: message.content.source
|
|
2310
|
-
});
|
|
2311
|
-
return {
|
|
2312
|
-
text: errorMessage,
|
|
2313
|
-
success: false
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
};
|
|
2318
|
-
|
|
2319
|
-
// src/actions/searchIssues.ts
|
|
2320
|
-
import {
|
|
2321
|
-
logger as logger9,
|
|
2322
|
-
ModelType as ModelType8
|
|
2323
|
-
} from "@elizaos/core";
|
|
2324
|
-
var searchTemplate = searchIssuesTemplate;
|
|
2325
|
-
var searchIssuesAction = {
|
|
2326
|
-
name: "SEARCH_LINEAR_ISSUES",
|
|
2327
|
-
description: "Search for issues in Linear with various filters",
|
|
2328
|
-
similes: [
|
|
2329
|
-
"search-linear-issues",
|
|
2330
|
-
"find-linear-issues",
|
|
2331
|
-
"query-linear-issues",
|
|
2332
|
-
"list-linear-issues"
|
|
2333
|
-
],
|
|
2334
|
-
examples: [
|
|
2335
|
-
[
|
|
2336
|
-
{
|
|
2337
|
-
name: "User",
|
|
2338
|
-
content: {
|
|
2339
|
-
text: "Show me all open bugs"
|
|
2340
|
-
}
|
|
2341
|
-
},
|
|
2342
|
-
{
|
|
2343
|
-
name: "Assistant",
|
|
2344
|
-
content: {
|
|
2345
|
-
text: "I'll search for all open bug issues in Linear.",
|
|
2346
|
-
actions: ["SEARCH_LINEAR_ISSUES"]
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
],
|
|
2350
|
-
[
|
|
2351
|
-
{
|
|
2352
|
-
name: "User",
|
|
2353
|
-
content: {
|
|
2354
|
-
text: "What is John working on?"
|
|
2355
|
-
}
|
|
2356
|
-
},
|
|
2357
|
-
{
|
|
2358
|
-
name: "Assistant",
|
|
2359
|
-
content: {
|
|
2360
|
-
text: "I'll find the issues assigned to John.",
|
|
2361
|
-
actions: ["SEARCH_LINEAR_ISSUES"]
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
],
|
|
2365
|
-
[
|
|
2366
|
-
{
|
|
2367
|
-
name: "User",
|
|
2368
|
-
content: {
|
|
2369
|
-
text: "Show me high priority issues created this week"
|
|
2370
|
-
}
|
|
2371
|
-
},
|
|
2372
|
-
{
|
|
2373
|
-
name: "Assistant",
|
|
2374
|
-
content: {
|
|
2375
|
-
text: "I'll search for high priority issues created this week.",
|
|
2376
|
-
actions: ["SEARCH_LINEAR_ISSUES"]
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
]
|
|
2380
|
-
],
|
|
2381
|
-
validate: async (runtime, message, state, options) => {
|
|
2382
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
2383
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
2384
|
-
const __avKeywords = ["search", "linear", "issues"];
|
|
2385
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
2386
|
-
const __avRegex = /\b(?:search|linear|issues)\b/i;
|
|
2387
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
2388
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
2389
|
-
const __avExpectedSource = "";
|
|
2390
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
2391
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
2392
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
2393
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
2394
|
-
return false;
|
|
2395
|
-
}
|
|
2396
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
2397
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
2398
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
2399
|
-
const __avKeywords2 = ["search", "linear", "issues"];
|
|
2400
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
2401
|
-
const __avRegex2 = /\b(?:search|linear|issues)\b/i;
|
|
2402
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
2403
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
2404
|
-
const __avExpectedSource2 = "";
|
|
2405
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
2406
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
2407
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
2408
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
2409
|
-
return false;
|
|
2410
|
-
}
|
|
2411
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
2412
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
2413
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
2414
|
-
const __avKeywords3 = ["search", "linear", "issues"];
|
|
2415
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
2416
|
-
const __avRegex3 = /\b(?:search|linear|issues)\b/i;
|
|
2417
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
2418
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
2419
|
-
const __avExpectedSource3 = "";
|
|
2420
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
2421
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
2422
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
2423
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
2424
|
-
return false;
|
|
2425
|
-
}
|
|
2426
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
2427
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
2428
|
-
return !!apiKey;
|
|
2429
|
-
};
|
|
2430
|
-
try {
|
|
2431
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
2432
|
-
} catch {
|
|
2433
|
-
return false;
|
|
2434
|
-
}
|
|
2435
|
-
};
|
|
2436
|
-
try {
|
|
2437
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
2438
|
-
} catch {
|
|
2439
|
-
return false;
|
|
2440
|
-
}
|
|
2441
|
-
};
|
|
2442
|
-
try {
|
|
2443
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
2444
|
-
} catch {
|
|
2445
|
-
return false;
|
|
2446
|
-
}
|
|
2447
|
-
},
|
|
2448
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
2449
|
-
try {
|
|
2450
|
-
const linearService = runtime.getService("linear");
|
|
2451
|
-
if (!linearService) {
|
|
2452
|
-
throw new Error("Linear service not available");
|
|
2453
|
-
}
|
|
2454
|
-
const content = message.content.text;
|
|
2455
|
-
if (!content) {
|
|
2456
|
-
const errorMessage = "Please provide search criteria for issues.";
|
|
2457
|
-
await callback?.({
|
|
2458
|
-
text: errorMessage,
|
|
2459
|
-
source: message.content.source
|
|
2460
|
-
});
|
|
2461
|
-
return {
|
|
2462
|
-
text: errorMessage,
|
|
2463
|
-
success: false
|
|
2464
|
-
};
|
|
2465
|
-
}
|
|
2466
|
-
let filters = {};
|
|
2467
|
-
const params = _options?.parameters;
|
|
2468
|
-
if (params?.filters) {
|
|
2469
|
-
filters = params.filters;
|
|
2470
|
-
} else {
|
|
2471
|
-
const prompt = searchTemplate.replace("{{userMessage}}", content);
|
|
2472
|
-
const response = await runtime.useModel(ModelType8.TEXT_LARGE, {
|
|
2473
|
-
prompt
|
|
2474
|
-
});
|
|
2475
|
-
if (!response) {
|
|
2476
|
-
filters = { query: content };
|
|
2477
|
-
} else {
|
|
2478
|
-
try {
|
|
2479
|
-
const cleanedResponse = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
2480
|
-
const parsed = JSON.parse(cleanedResponse);
|
|
2481
|
-
filters = {
|
|
2482
|
-
query: parsed.query,
|
|
2483
|
-
limit: parsed.limit || 10
|
|
2484
|
-
};
|
|
2485
|
-
if (parsed.states && parsed.states.length > 0) {
|
|
2486
|
-
filters.state = parsed.states;
|
|
2487
|
-
}
|
|
2488
|
-
if (parsed.assignees && parsed.assignees.length > 0) {
|
|
2489
|
-
const processedAssignees = [];
|
|
2490
|
-
for (const assignee of parsed.assignees) {
|
|
2491
|
-
if (assignee.toLowerCase() === "me") {
|
|
2492
|
-
try {
|
|
2493
|
-
const currentUser = await linearService.getCurrentUser();
|
|
2494
|
-
processedAssignees.push(currentUser.email);
|
|
2495
|
-
} catch {
|
|
2496
|
-
logger9.warn('Could not resolve "me" to current user');
|
|
2497
|
-
}
|
|
2498
|
-
} else {
|
|
2499
|
-
processedAssignees.push(assignee);
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
if (processedAssignees.length > 0) {
|
|
2503
|
-
filters.assignee = processedAssignees;
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
if (parsed.hasAssignee === false) {
|
|
2507
|
-
filters.query = filters.query ? `${filters.query} unassigned` : "unassigned";
|
|
2508
|
-
}
|
|
2509
|
-
if (parsed.priorities && parsed.priorities.length > 0) {
|
|
2510
|
-
const priorityMap = {
|
|
2511
|
-
urgent: 1,
|
|
2512
|
-
high: 2,
|
|
2513
|
-
normal: 3,
|
|
2514
|
-
low: 4,
|
|
2515
|
-
"1": 1,
|
|
2516
|
-
"2": 2,
|
|
2517
|
-
"3": 3,
|
|
2518
|
-
"4": 4
|
|
2519
|
-
};
|
|
2520
|
-
const priorities = parsed.priorities.map((p) => priorityMap[p.toLowerCase()]).filter(Boolean);
|
|
2521
|
-
if (priorities.length > 0) {
|
|
2522
|
-
filters.priority = priorities;
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
if (parsed.teams && parsed.teams.length > 0) {
|
|
2526
|
-
filters.team = parsed.teams[0];
|
|
2527
|
-
}
|
|
2528
|
-
if (parsed.labels && parsed.labels.length > 0) {
|
|
2529
|
-
filters.label = parsed.labels;
|
|
2530
|
-
}
|
|
2531
|
-
Object.keys(filters).forEach((key) => {
|
|
2532
|
-
if (filters[key] === undefined) {
|
|
2533
|
-
delete filters[key];
|
|
2534
|
-
}
|
|
2535
|
-
});
|
|
2536
|
-
} catch (parseError) {
|
|
2537
|
-
logger9.error("Failed to parse search filters:", parseError);
|
|
2538
|
-
filters = { query: content };
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
if (!filters.team) {
|
|
2543
|
-
const defaultTeamKey = runtime.getSetting("LINEAR_DEFAULT_TEAM_KEY");
|
|
2544
|
-
if (defaultTeamKey) {
|
|
2545
|
-
const searchingAllIssues = content.toLowerCase().includes("all") && (content.toLowerCase().includes("issue") || content.toLowerCase().includes("bug") || content.toLowerCase().includes("task"));
|
|
2546
|
-
if (!searchingAllIssues) {
|
|
2547
|
-
filters.team = defaultTeamKey;
|
|
2548
|
-
logger9.info(`Applying default team filter: ${defaultTeamKey}`);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
filters.limit = params?.limit ?? filters.limit ?? 10;
|
|
2553
|
-
const issues = await linearService.searchIssues(filters);
|
|
2554
|
-
if (issues.length === 0) {
|
|
2555
|
-
const noResultsMessage = "No issues found matching your search criteria.";
|
|
2556
|
-
await callback?.({
|
|
2557
|
-
text: noResultsMessage,
|
|
2558
|
-
source: message.content.source
|
|
2559
|
-
});
|
|
2560
|
-
return {
|
|
2561
|
-
text: noResultsMessage,
|
|
2562
|
-
success: true,
|
|
2563
|
-
data: {
|
|
2564
|
-
issues: [],
|
|
2565
|
-
filters: filters ? { ...filters } : undefined,
|
|
2566
|
-
count: 0
|
|
2567
|
-
}
|
|
2568
|
-
};
|
|
2569
|
-
}
|
|
2570
|
-
const issueList = await Promise.all(issues.map(async (issue, index) => {
|
|
2571
|
-
const state = await issue.state;
|
|
2572
|
-
const assignee = await issue.assignee;
|
|
2573
|
-
const priorityLabels = ["", "Urgent", "High", "Normal", "Low"];
|
|
2574
|
-
const priority = priorityLabels[issue.priority || 0] || "No priority";
|
|
2575
|
-
return `${index + 1}. ${issue.identifier}: ${issue.title}
|
|
2576
|
-
Status: ${state?.name || "No state"} | Priority: ${priority} | Assignee: ${assignee?.name || "Unassigned"}`;
|
|
2577
|
-
}));
|
|
2578
|
-
const issueText = issueList.join(`
|
|
2579
|
-
|
|
2580
|
-
`);
|
|
2581
|
-
const resultMessage = `\uD83D\uDCCB Found ${issues.length} issue${issues.length === 1 ? "" : "s"}:
|
|
2582
|
-
|
|
2583
|
-
${issueText}`;
|
|
2584
|
-
await callback?.({
|
|
2585
|
-
text: resultMessage,
|
|
2586
|
-
source: message.content.source
|
|
2587
|
-
});
|
|
2588
|
-
return {
|
|
2589
|
-
text: `Found ${issues.length} issue${issues.length === 1 ? "" : "s"}`,
|
|
2590
|
-
success: true,
|
|
2591
|
-
data: {
|
|
2592
|
-
issues: await Promise.all(issues.map(async (issue) => {
|
|
2593
|
-
const state = await issue.state;
|
|
2594
|
-
const assignee = await issue.assignee;
|
|
2595
|
-
const team = await issue.team;
|
|
2596
|
-
return {
|
|
2597
|
-
id: issue.id,
|
|
2598
|
-
identifier: issue.identifier,
|
|
2599
|
-
title: issue.title,
|
|
2600
|
-
url: issue.url,
|
|
2601
|
-
priority: issue.priority,
|
|
2602
|
-
state: state ? { name: state.name, type: state.type } : null,
|
|
2603
|
-
assignee: assignee ? { name: assignee.name, email: assignee.email } : null,
|
|
2604
|
-
team: team ? { name: team.name, key: team.key } : null,
|
|
2605
|
-
createdAt: issue.createdAt instanceof Date ? issue.createdAt.toISOString() : issue.createdAt,
|
|
2606
|
-
updatedAt: issue.updatedAt instanceof Date ? issue.updatedAt.toISOString() : issue.updatedAt
|
|
2607
|
-
};
|
|
2608
|
-
})),
|
|
2609
|
-
filters: filters ? { ...filters } : undefined,
|
|
2610
|
-
count: issues.length
|
|
2611
|
-
}
|
|
2612
|
-
};
|
|
2613
|
-
} catch (error) {
|
|
2614
|
-
logger9.error("Failed to search issues:", error);
|
|
2615
|
-
const errorMessage = `❌ Failed to search issues: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
2616
|
-
await callback?.({
|
|
2617
|
-
text: errorMessage,
|
|
2618
|
-
source: message.content.source
|
|
2619
|
-
});
|
|
2620
|
-
return {
|
|
2621
|
-
text: errorMessage,
|
|
2622
|
-
success: false
|
|
2623
|
-
};
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
};
|
|
2627
|
-
|
|
2628
|
-
// src/actions/updateIssue.ts
|
|
2629
|
-
import {
|
|
2630
|
-
logger as logger10,
|
|
2631
|
-
ModelType as ModelType9
|
|
2632
|
-
} from "@elizaos/core";
|
|
2633
|
-
var updateIssueAction = {
|
|
2634
|
-
name: "UPDATE_LINEAR_ISSUE",
|
|
2635
|
-
description: "Update an existing Linear issue",
|
|
2636
|
-
similes: [
|
|
2637
|
-
"update-linear-issue",
|
|
2638
|
-
"edit-linear-issue",
|
|
2639
|
-
"modify-linear-issue",
|
|
2640
|
-
"move-linear-issue",
|
|
2641
|
-
"change-linear-issue"
|
|
2642
|
-
],
|
|
2643
|
-
examples: [
|
|
2644
|
-
[
|
|
2645
|
-
{
|
|
2646
|
-
name: "User",
|
|
2647
|
-
content: {
|
|
2648
|
-
text: 'Update issue ENG-123 title to "Fix login button on all devices"'
|
|
2649
|
-
}
|
|
2650
|
-
},
|
|
2651
|
-
{
|
|
2652
|
-
name: "Assistant",
|
|
2653
|
-
content: {
|
|
2654
|
-
text: "I'll update the title of issue ENG-123 for you.",
|
|
2655
|
-
actions: ["UPDATE_LINEAR_ISSUE"]
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
],
|
|
2659
|
-
[
|
|
2660
|
-
{
|
|
2661
|
-
name: "User",
|
|
2662
|
-
content: {
|
|
2663
|
-
text: "Move issue COM2-7 to the ELIZA team"
|
|
2664
|
-
}
|
|
2665
|
-
},
|
|
2666
|
-
{
|
|
2667
|
-
name: "Assistant",
|
|
2668
|
-
content: {
|
|
2669
|
-
text: "I'll move issue COM2-7 to the ELIZA team.",
|
|
2670
|
-
actions: ["UPDATE_LINEAR_ISSUE"]
|
|
2671
|
-
}
|
|
2672
|
-
}
|
|
2673
|
-
],
|
|
2674
|
-
[
|
|
2675
|
-
{
|
|
2676
|
-
name: "User",
|
|
2677
|
-
content: {
|
|
2678
|
-
text: "Change the priority of BUG-456 to high and assign to john@example.com"
|
|
2679
|
-
}
|
|
2680
|
-
},
|
|
2681
|
-
{
|
|
2682
|
-
name: "Assistant",
|
|
2683
|
-
content: {
|
|
2684
|
-
text: "I'll change the priority of BUG-456 to high and assign it to john@example.com.",
|
|
2685
|
-
actions: ["UPDATE_LINEAR_ISSUE"]
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
]
|
|
2689
|
-
],
|
|
2690
|
-
validate: async (runtime, message, state, options) => {
|
|
2691
|
-
const __avTextRaw = typeof message?.content?.text === "string" ? message.content.text : "";
|
|
2692
|
-
const __avText = __avTextRaw.toLowerCase();
|
|
2693
|
-
const __avKeywords = ["update", "linear", "issue"];
|
|
2694
|
-
const __avKeywordOk = __avKeywords.length > 0 && __avKeywords.some((word) => word.length > 0 && __avText.includes(word));
|
|
2695
|
-
const __avRegex = /\b(?:update|linear|issue)\b/i;
|
|
2696
|
-
const __avRegexOk = __avRegex.test(__avText);
|
|
2697
|
-
const __avSource = String(message?.content?.source ?? message?.source ?? "");
|
|
2698
|
-
const __avExpectedSource = "";
|
|
2699
|
-
const __avSourceOk = __avExpectedSource ? __avSource === __avExpectedSource : Boolean(__avSource || state || runtime?.agentId || runtime?.getService || runtime?.getSetting);
|
|
2700
|
-
const __avOptions = options && typeof options === "object" ? options : {};
|
|
2701
|
-
const __avInputOk = __avText.trim().length > 0 || Object.keys(__avOptions).length > 0 || Boolean(message?.content && typeof message.content === "object");
|
|
2702
|
-
if (!(__avKeywordOk && __avRegexOk && __avSourceOk && __avInputOk)) {
|
|
2703
|
-
return false;
|
|
2704
|
-
}
|
|
2705
|
-
const __avLegacyValidate = async (runtime2, message2, state2, options2) => {
|
|
2706
|
-
const __avTextRaw2 = typeof message2?.content?.text === "string" ? message2.content.text : "";
|
|
2707
|
-
const __avText2 = __avTextRaw2.toLowerCase();
|
|
2708
|
-
const __avKeywords2 = ["update", "linear", "issue"];
|
|
2709
|
-
const __avKeywordOk2 = __avKeywords2.length > 0 && __avKeywords2.some((word) => word.length > 0 && __avText2.includes(word));
|
|
2710
|
-
const __avRegex2 = /\b(?:update|linear|issue)\b/i;
|
|
2711
|
-
const __avRegexOk2 = __avRegex2.test(__avText2);
|
|
2712
|
-
const __avSource2 = String(message2?.content?.source ?? message2?.source ?? "");
|
|
2713
|
-
const __avExpectedSource2 = "";
|
|
2714
|
-
const __avSourceOk2 = __avExpectedSource2 ? __avSource2 === __avExpectedSource2 : Boolean(__avSource2 || state2 || runtime2?.agentId || runtime2?.getService || runtime2?.getSetting);
|
|
2715
|
-
const __avOptions2 = options2 && typeof options2 === "object" ? options2 : {};
|
|
2716
|
-
const __avInputOk2 = __avText2.trim().length > 0 || Object.keys(__avOptions2).length > 0 || Boolean(message2?.content && typeof message2.content === "object");
|
|
2717
|
-
if (!(__avKeywordOk2 && __avRegexOk2 && __avSourceOk2 && __avInputOk2)) {
|
|
2718
|
-
return false;
|
|
2719
|
-
}
|
|
2720
|
-
const __avLegacyValidate2 = async (runtime3, message3, state3, options3) => {
|
|
2721
|
-
const __avTextRaw3 = typeof message3?.content?.text === "string" ? message3.content.text : "";
|
|
2722
|
-
const __avText3 = __avTextRaw3.toLowerCase();
|
|
2723
|
-
const __avKeywords3 = ["update", "linear", "issue"];
|
|
2724
|
-
const __avKeywordOk3 = __avKeywords3.length > 0 && __avKeywords3.some((kw) => kw.length > 0 && __avText3.includes(kw));
|
|
2725
|
-
const __avRegex3 = /\b(?:update|linear|issue)\b/i;
|
|
2726
|
-
const __avRegexOk3 = __avRegex3.test(__avText3);
|
|
2727
|
-
const __avSource3 = String(message3?.content?.source ?? message3?.source ?? "");
|
|
2728
|
-
const __avExpectedSource3 = "";
|
|
2729
|
-
const __avSourceOk3 = __avExpectedSource3 ? __avSource3 === __avExpectedSource3 : Boolean(__avSource3 || state3 || runtime3?.agentId || runtime3?.getService);
|
|
2730
|
-
const __avOptions3 = options3 && typeof options3 === "object" ? options3 : {};
|
|
2731
|
-
const __avInputOk3 = __avText3.trim().length > 0 || Object.keys(__avOptions3).length > 0 || Boolean(message3?.content && typeof message3.content === "object");
|
|
2732
|
-
if (!(__avKeywordOk3 && __avRegexOk3 && __avSourceOk3 && __avInputOk3)) {
|
|
2733
|
-
return false;
|
|
2734
|
-
}
|
|
2735
|
-
const __avLegacyValidate3 = async (runtime4, _message, _state) => {
|
|
2736
|
-
const apiKey = runtime4.getSetting("LINEAR_API_KEY");
|
|
2737
|
-
return !!apiKey;
|
|
2738
|
-
};
|
|
2739
|
-
try {
|
|
2740
|
-
return Boolean(await __avLegacyValidate3(runtime3, message3, state3, options3));
|
|
2741
|
-
} catch {
|
|
2742
|
-
return false;
|
|
2743
|
-
}
|
|
2744
|
-
};
|
|
2745
|
-
try {
|
|
2746
|
-
return Boolean(await __avLegacyValidate2(runtime2, message2, state2, options2));
|
|
2747
|
-
} catch {
|
|
2748
|
-
return false;
|
|
2749
|
-
}
|
|
2750
|
-
};
|
|
2751
|
-
try {
|
|
2752
|
-
return Boolean(await __avLegacyValidate(runtime, message, state, options));
|
|
2753
|
-
} catch {
|
|
2754
|
-
return false;
|
|
2755
|
-
}
|
|
2756
|
-
},
|
|
2757
|
-
async handler(runtime, message, _state, _options, callback) {
|
|
2758
|
-
try {
|
|
2759
|
-
const linearService = runtime.getService("linear");
|
|
2760
|
-
if (!linearService) {
|
|
2761
|
-
throw new Error("Linear service not available");
|
|
2762
|
-
}
|
|
2763
|
-
const content = message.content.text;
|
|
2764
|
-
if (!content) {
|
|
2765
|
-
const errorMessage = "Please provide update instructions for the issue.";
|
|
2766
|
-
await callback?.({
|
|
2767
|
-
text: errorMessage,
|
|
2768
|
-
source: message.content.source
|
|
2769
|
-
});
|
|
2770
|
-
return {
|
|
2771
|
-
text: errorMessage,
|
|
2772
|
-
success: false
|
|
2773
|
-
};
|
|
2774
|
-
}
|
|
2775
|
-
const prompt = updateIssueTemplate.replace("{{userMessage}}", content);
|
|
2776
|
-
const response = await runtime.useModel(ModelType9.TEXT_LARGE, {
|
|
2777
|
-
prompt
|
|
2778
|
-
});
|
|
2779
|
-
if (!response) {
|
|
2780
|
-
throw new Error("Failed to extract update information");
|
|
2781
|
-
}
|
|
2782
|
-
let issueId;
|
|
2783
|
-
const updates = {};
|
|
2784
|
-
try {
|
|
2785
|
-
const cleanedResponse = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
2786
|
-
const parsed = JSON.parse(cleanedResponse);
|
|
2787
|
-
issueId = parsed.issueId;
|
|
2788
|
-
if (!issueId) {
|
|
2789
|
-
throw new Error("Issue ID not found in parsed response");
|
|
2790
|
-
}
|
|
2791
|
-
if (parsed.updates?.title) {
|
|
2792
|
-
updates.title = parsed.updates.title;
|
|
2793
|
-
}
|
|
2794
|
-
if (parsed.updates?.description) {
|
|
2795
|
-
updates.description = parsed.updates.description;
|
|
2796
|
-
}
|
|
2797
|
-
if (parsed.updates?.priority) {
|
|
2798
|
-
updates.priority = Number(parsed.updates.priority);
|
|
2799
|
-
}
|
|
2800
|
-
if (parsed.updates?.teamKey) {
|
|
2801
|
-
const teams = await linearService.getTeams();
|
|
2802
|
-
const team = teams.find((t) => t.key.toLowerCase() === parsed.updates.teamKey.toLowerCase());
|
|
2803
|
-
if (team) {
|
|
2804
|
-
updates.teamId = team.id;
|
|
2805
|
-
logger10.info(`Moving issue to team: ${team.name} (${team.key})`);
|
|
2806
|
-
} else {
|
|
2807
|
-
logger10.warn(`Team with key ${parsed.updates.teamKey} not found`);
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
if (parsed.updates?.assignee) {
|
|
2811
|
-
const cleanAssignee = parsed.updates.assignee.replace(/^@/, "");
|
|
2812
|
-
const users = await linearService.getUsers();
|
|
2813
|
-
const user = users.find((u) => u.email === cleanAssignee || u.name.toLowerCase().includes(cleanAssignee.toLowerCase()));
|
|
2814
|
-
if (user) {
|
|
2815
|
-
updates.assigneeId = user.id;
|
|
2816
|
-
} else {
|
|
2817
|
-
logger10.warn(`User ${cleanAssignee} not found`);
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
if (parsed.updates?.status) {
|
|
2821
|
-
const issue = await linearService.getIssue(issueId);
|
|
2822
|
-
const issueTeam = await issue.team;
|
|
2823
|
-
const teamId = updates.teamId || issueTeam?.id;
|
|
2824
|
-
if (!teamId) {
|
|
2825
|
-
logger10.warn("Could not determine team for status update");
|
|
2826
|
-
} else {
|
|
2827
|
-
const states = await linearService.getWorkflowStates(teamId);
|
|
2828
|
-
const state = states.find((s) => s.name.toLowerCase() === parsed.updates.status.toLowerCase() || s.type.toLowerCase() === parsed.updates.status.toLowerCase());
|
|
2829
|
-
if (state) {
|
|
2830
|
-
updates.stateId = state.id;
|
|
2831
|
-
logger10.info(`Changing status to: ${state.name}`);
|
|
2832
|
-
} else {
|
|
2833
|
-
logger10.warn(`Status ${parsed.updates.status} not found for team`);
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
}
|
|
2837
|
-
if (parsed.updates?.labels && Array.isArray(parsed.updates.labels)) {
|
|
2838
|
-
const teamId = updates.teamId;
|
|
2839
|
-
const labels = await linearService.getLabels(teamId);
|
|
2840
|
-
const labelIds = [];
|
|
2841
|
-
for (const labelName of parsed.updates.labels) {
|
|
2842
|
-
if (labelName) {
|
|
2843
|
-
const label = labels.find((l) => l.name.toLowerCase() === labelName.toLowerCase());
|
|
2844
|
-
if (label) {
|
|
2845
|
-
labelIds.push(label.id);
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
updates.labelIds = labelIds;
|
|
2850
|
-
}
|
|
2851
|
-
} catch (parseError) {
|
|
2852
|
-
logger10.warn("Failed to parse LLM response, falling back to regex parsing:", parseError);
|
|
2853
|
-
const issueMatch = content.match(/(\w+-\d+)/);
|
|
2854
|
-
if (!issueMatch) {
|
|
2855
|
-
const errorMessage = "Please specify an issue ID (e.g., ENG-123) to update.";
|
|
2856
|
-
await callback?.({
|
|
2857
|
-
text: errorMessage,
|
|
2858
|
-
source: message.content.source
|
|
2859
|
-
});
|
|
2860
|
-
return {
|
|
2861
|
-
text: errorMessage,
|
|
2862
|
-
success: false
|
|
2863
|
-
};
|
|
2864
|
-
}
|
|
2865
|
-
issueId = issueMatch[1];
|
|
2866
|
-
const titleMatch = content.match(/title to ["'](.+?)["']/i);
|
|
2867
|
-
if (titleMatch) {
|
|
2868
|
-
updates.title = titleMatch[1];
|
|
2869
|
-
}
|
|
2870
|
-
const priorityMatch = content.match(/priority (?:to |as )?(\w+)/i);
|
|
2871
|
-
if (priorityMatch) {
|
|
2872
|
-
const priorityMap = {
|
|
2873
|
-
urgent: 1,
|
|
2874
|
-
high: 2,
|
|
2875
|
-
normal: 3,
|
|
2876
|
-
medium: 3,
|
|
2877
|
-
low: 4
|
|
2878
|
-
};
|
|
2879
|
-
const priority = priorityMap[priorityMatch[1].toLowerCase()];
|
|
2880
|
-
if (priority) {
|
|
2881
|
-
updates.priority = priority;
|
|
2882
|
-
}
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
if (Object.keys(updates).length === 0) {
|
|
2886
|
-
const errorMessage = `No valid updates found. Please specify what to update (e.g., "Update issue ENG-123 title to 'New Title'")`;
|
|
2887
|
-
await callback?.({
|
|
2888
|
-
text: errorMessage,
|
|
2889
|
-
source: message.content.source
|
|
2890
|
-
});
|
|
2891
|
-
return {
|
|
2892
|
-
text: errorMessage,
|
|
2893
|
-
success: false
|
|
2894
|
-
};
|
|
2895
|
-
}
|
|
2896
|
-
const updatedIssue = await linearService.updateIssue(issueId, updates);
|
|
2897
|
-
const updateSummary = [];
|
|
2898
|
-
if (updates.title)
|
|
2899
|
-
updateSummary.push(`title: "${updates.title}"`);
|
|
2900
|
-
if (updates.priority)
|
|
2901
|
-
updateSummary.push(`priority: ${["", "urgent", "high", "normal", "low"][updates.priority]}`);
|
|
2902
|
-
if (updates.teamId)
|
|
2903
|
-
updateSummary.push(`moved to team`);
|
|
2904
|
-
if (updates.assigneeId)
|
|
2905
|
-
updateSummary.push(`assigned to user`);
|
|
2906
|
-
if (updates.stateId)
|
|
2907
|
-
updateSummary.push(`status changed`);
|
|
2908
|
-
if (updates.labelIds)
|
|
2909
|
-
updateSummary.push(`labels updated`);
|
|
2910
|
-
const successMessage = `✅ Updated issue ${updatedIssue.identifier}: ${updateSummary.join(", ")}
|
|
2911
|
-
|
|
2912
|
-
View it at: ${updatedIssue.url}`;
|
|
2913
|
-
await callback?.({
|
|
2914
|
-
text: successMessage,
|
|
2915
|
-
source: message.content.source
|
|
2916
|
-
});
|
|
2917
|
-
return {
|
|
2918
|
-
text: `Updated issue ${updatedIssue.identifier}: ${updateSummary.join(", ")}`,
|
|
2919
|
-
success: true,
|
|
2920
|
-
data: {
|
|
2921
|
-
issueId: updatedIssue.id,
|
|
2922
|
-
identifier: updatedIssue.identifier,
|
|
2923
|
-
updates: updates ? Object.fromEntries(Object.entries(updates).map(([key, value]) => [
|
|
2924
|
-
key,
|
|
2925
|
-
value instanceof Date ? value.toISOString() : value
|
|
2926
|
-
])) : undefined,
|
|
2927
|
-
url: updatedIssue.url
|
|
2928
|
-
}
|
|
2929
|
-
};
|
|
2930
|
-
} catch (error) {
|
|
2931
|
-
logger10.error("Failed to update issue:", error);
|
|
2932
|
-
const errorMessage = `❌ Failed to update issue: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
2933
|
-
await callback?.({
|
|
2934
|
-
text: errorMessage,
|
|
2935
|
-
source: message.content.source
|
|
2936
|
-
});
|
|
2937
|
-
return {
|
|
2938
|
-
text: errorMessage,
|
|
2939
|
-
success: false
|
|
2940
|
-
};
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
};
|
|
2944
|
-
|
|
2945
|
-
// src/providers/activity.ts
|
|
2946
|
-
var linearActivityProvider = {
|
|
2947
|
-
name: "LINEAR_ACTIVITY",
|
|
2948
|
-
description: "Provides context about recent Linear activity",
|
|
2949
|
-
dynamic: true,
|
|
2950
|
-
get: async (runtime, _message, _state) => {
|
|
2951
|
-
try {
|
|
2952
|
-
const linearService = runtime.getService("linear");
|
|
2953
|
-
if (!linearService) {
|
|
2954
|
-
return {
|
|
2955
|
-
text: "Linear service is not available"
|
|
2956
|
-
};
|
|
2957
|
-
}
|
|
2958
|
-
const activity = linearService.getActivityLog(10);
|
|
2959
|
-
if (activity.length === 0) {
|
|
2960
|
-
return {
|
|
2961
|
-
text: "No recent Linear activity"
|
|
2962
|
-
};
|
|
2963
|
-
}
|
|
2964
|
-
const activityList = activity.map((item) => {
|
|
2965
|
-
const status = item.success ? "✓" : "✗";
|
|
2966
|
-
const time = new Date(item.timestamp).toLocaleTimeString();
|
|
2967
|
-
return `${status} ${time}: ${item.action} ${item.resource_type} ${item.resource_id}`;
|
|
2968
|
-
});
|
|
2969
|
-
const text = `Recent Linear Activity:
|
|
2970
|
-
${activityList.join(`
|
|
2971
|
-
`)}`;
|
|
2972
|
-
return {
|
|
2973
|
-
text,
|
|
2974
|
-
data: {
|
|
2975
|
-
activity: activity.slice(0, 10).map((item) => ({
|
|
2976
|
-
id: item.id,
|
|
2977
|
-
action: item.action,
|
|
2978
|
-
resource_type: item.resource_type,
|
|
2979
|
-
resource_id: item.resource_id,
|
|
2980
|
-
success: item.success,
|
|
2981
|
-
error: item.error,
|
|
2982
|
-
details: JSON.stringify(item.details),
|
|
2983
|
-
timestamp: typeof item.timestamp === "string" ? item.timestamp : new Date(item.timestamp).toISOString()
|
|
2984
|
-
}))
|
|
2985
|
-
}
|
|
2986
|
-
};
|
|
2987
|
-
} catch (_error) {
|
|
2988
|
-
return {
|
|
2989
|
-
text: "Error retrieving Linear activity"
|
|
2990
|
-
};
|
|
2991
|
-
}
|
|
2992
|
-
}
|
|
2993
|
-
};
|
|
2994
|
-
|
|
2995
|
-
// src/providers/issues.ts
|
|
2996
|
-
var linearIssuesProvider = {
|
|
2997
|
-
name: "LINEAR_ISSUES",
|
|
2998
|
-
description: "Provides context about recent Linear issues",
|
|
2999
|
-
dynamic: true,
|
|
3000
|
-
get: async (runtime, _message, _state) => {
|
|
3001
|
-
try {
|
|
3002
|
-
const linearService = runtime.getService("linear");
|
|
3003
|
-
if (!linearService) {
|
|
3004
|
-
return {
|
|
3005
|
-
text: "Linear service is not available"
|
|
3006
|
-
};
|
|
3007
|
-
}
|
|
3008
|
-
const issues = await linearService.searchIssues({ limit: 10 });
|
|
3009
|
-
if (issues.length === 0) {
|
|
3010
|
-
return {
|
|
3011
|
-
text: "No recent Linear issues found"
|
|
3012
|
-
};
|
|
3013
|
-
}
|
|
3014
|
-
const issuesList = await Promise.all(issues.map(async (issue) => {
|
|
3015
|
-
const [assignee, state] = await Promise.all([issue.assignee, issue.state]);
|
|
3016
|
-
return `- ${issue.identifier}: ${issue.title} (${state?.name || "Unknown"}, ${assignee?.name || "Unassigned"})`;
|
|
3017
|
-
}));
|
|
3018
|
-
const text = `Recent Linear Issues:
|
|
3019
|
-
${issuesList.join(`
|
|
3020
|
-
`)}`;
|
|
3021
|
-
return {
|
|
3022
|
-
text,
|
|
3023
|
-
data: {
|
|
3024
|
-
issues: issues.map((issue) => ({
|
|
3025
|
-
id: issue.id,
|
|
3026
|
-
identifier: issue.identifier,
|
|
3027
|
-
title: issue.title
|
|
3028
|
-
}))
|
|
3029
|
-
}
|
|
3030
|
-
};
|
|
3031
|
-
} catch (_error) {
|
|
3032
|
-
return {
|
|
3033
|
-
text: "Error retrieving Linear issues"
|
|
3034
|
-
};
|
|
3035
|
-
}
|
|
3036
|
-
}
|
|
3037
|
-
};
|
|
3038
|
-
|
|
3039
|
-
// src/providers/projects.ts
|
|
3040
|
-
var linearProjectsProvider = {
|
|
3041
|
-
name: "LINEAR_PROJECTS",
|
|
3042
|
-
description: "Provides context about active Linear projects",
|
|
3043
|
-
dynamic: true,
|
|
3044
|
-
get: async (runtime, _message, _state) => {
|
|
3045
|
-
try {
|
|
3046
|
-
const linearService = runtime.getService("linear");
|
|
3047
|
-
if (!linearService) {
|
|
3048
|
-
return {
|
|
3049
|
-
text: "Linear service is not available"
|
|
3050
|
-
};
|
|
3051
|
-
}
|
|
3052
|
-
const projects = await linearService.getProjects();
|
|
3053
|
-
if (projects.length === 0) {
|
|
3054
|
-
return {
|
|
3055
|
-
text: "No Linear projects found"
|
|
3056
|
-
};
|
|
3057
|
-
}
|
|
3058
|
-
const activeProjects = projects.filter((project) => project.state === "started" || project.state === "planned");
|
|
3059
|
-
const projectsList = activeProjects.slice(0, 10).map((project) => `- ${project.name}: ${project.state} (${project.startDate || "No start date"} - ${project.targetDate || "No target date"})`);
|
|
3060
|
-
const text = `Active Linear Projects:
|
|
3061
|
-
${projectsList.join(`
|
|
3062
|
-
`)}`;
|
|
3063
|
-
return {
|
|
3064
|
-
text,
|
|
3065
|
-
data: {
|
|
3066
|
-
projects: activeProjects.slice(0, 10).map((project) => ({
|
|
3067
|
-
id: project.id,
|
|
3068
|
-
name: project.name,
|
|
3069
|
-
state: project.state
|
|
3070
|
-
}))
|
|
3071
|
-
}
|
|
3072
|
-
};
|
|
3073
|
-
} catch (_error) {
|
|
3074
|
-
return {
|
|
3075
|
-
text: "Error retrieving Linear projects"
|
|
3076
|
-
};
|
|
3077
|
-
}
|
|
3078
|
-
}
|
|
3079
|
-
};
|
|
3080
|
-
|
|
3081
|
-
// src/providers/teams.ts
|
|
3082
|
-
var linearTeamsProvider = {
|
|
3083
|
-
name: "LINEAR_TEAMS",
|
|
3084
|
-
description: "Provides context about Linear teams",
|
|
3085
|
-
dynamic: true,
|
|
3086
|
-
get: async (runtime, _message, _state) => {
|
|
3087
|
-
try {
|
|
3088
|
-
const linearService = runtime.getService("linear");
|
|
3089
|
-
if (!linearService) {
|
|
3090
|
-
return {
|
|
3091
|
-
text: "Linear service is not available"
|
|
3092
|
-
};
|
|
3093
|
-
}
|
|
3094
|
-
const teams = await linearService.getTeams();
|
|
3095
|
-
if (teams.length === 0) {
|
|
3096
|
-
return {
|
|
3097
|
-
text: "No Linear teams found"
|
|
3098
|
-
};
|
|
3099
|
-
}
|
|
3100
|
-
const teamsList = teams.map((team) => `- ${team.name} (${team.key}): ${team.description || "No description"}`);
|
|
3101
|
-
const text = `Linear Teams:
|
|
3102
|
-
${teamsList.join(`
|
|
3103
|
-
`)}`;
|
|
3104
|
-
return {
|
|
3105
|
-
text,
|
|
3106
|
-
data: {
|
|
3107
|
-
teams: teams.map((team) => ({
|
|
3108
|
-
id: team.id,
|
|
3109
|
-
name: team.name,
|
|
3110
|
-
key: team.key
|
|
3111
|
-
}))
|
|
3112
|
-
}
|
|
3113
|
-
};
|
|
3114
|
-
} catch (_error) {
|
|
3115
|
-
return {
|
|
3116
|
-
text: "Error retrieving Linear teams"
|
|
3117
|
-
};
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
};
|
|
3121
|
-
|
|
3122
|
-
// src/services/linear.ts
|
|
3123
|
-
import { logger as logger11, Service } from "@elizaos/core";
|
|
3124
|
-
import {
|
|
3125
|
-
LinearClient
|
|
3126
|
-
} from "@linear/sdk";
|
|
3127
|
-
|
|
3128
|
-
// src/types/index.ts
|
|
3129
|
-
class LinearAPIError extends Error {
|
|
3130
|
-
status;
|
|
3131
|
-
response;
|
|
3132
|
-
constructor(message, status, response) {
|
|
3133
|
-
super(message);
|
|
3134
|
-
this.status = status;
|
|
3135
|
-
this.response = response;
|
|
3136
|
-
this.name = "LinearAPIError";
|
|
3137
|
-
}
|
|
3138
|
-
}
|
|
3139
|
-
|
|
3140
|
-
class LinearAuthenticationError extends LinearAPIError {
|
|
3141
|
-
constructor(message) {
|
|
3142
|
-
super(message, 401);
|
|
3143
|
-
this.name = "LinearAuthenticationError";
|
|
3144
|
-
}
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
// src/services/linear.ts
|
|
3148
|
-
class LinearService extends Service {
|
|
3149
|
-
static serviceType = "linear";
|
|
3150
|
-
capabilityDescription = "Linear API integration for issue tracking, project management, and team collaboration";
|
|
3151
|
-
client;
|
|
3152
|
-
activityLog = [];
|
|
3153
|
-
linearConfig;
|
|
3154
|
-
workspaceId;
|
|
3155
|
-
constructor(runtime) {
|
|
3156
|
-
super(runtime);
|
|
3157
|
-
const apiKey = runtime?.getSetting("LINEAR_API_KEY");
|
|
3158
|
-
const workspaceId = runtime?.getSetting("LINEAR_WORKSPACE_ID");
|
|
3159
|
-
if (!apiKey) {
|
|
3160
|
-
throw new LinearAuthenticationError("Linear API key is required");
|
|
3161
|
-
}
|
|
3162
|
-
this.linearConfig = {
|
|
3163
|
-
LINEAR_API_KEY: apiKey,
|
|
3164
|
-
LINEAR_WORKSPACE_ID: workspaceId
|
|
3165
|
-
};
|
|
3166
|
-
this.workspaceId = workspaceId;
|
|
3167
|
-
this.client = new LinearClient({
|
|
3168
|
-
apiKey: this.linearConfig.LINEAR_API_KEY
|
|
3169
|
-
});
|
|
3170
|
-
}
|
|
3171
|
-
static async start(runtime) {
|
|
3172
|
-
const service = new LinearService(runtime);
|
|
3173
|
-
await service.validateConnection();
|
|
3174
|
-
logger11.info("Linear service started successfully");
|
|
3175
|
-
return service;
|
|
3176
|
-
}
|
|
3177
|
-
async stop() {
|
|
3178
|
-
this.activityLog = [];
|
|
3179
|
-
logger11.info("Linear service stopped");
|
|
3180
|
-
}
|
|
3181
|
-
async validateConnection() {
|
|
3182
|
-
try {
|
|
3183
|
-
const viewer = await this.client.viewer;
|
|
3184
|
-
logger11.info(`Linear connected as user: ${viewer.email}`);
|
|
3185
|
-
} catch (_error) {
|
|
3186
|
-
throw new LinearAuthenticationError("Failed to authenticate with Linear API");
|
|
3187
|
-
}
|
|
3188
|
-
}
|
|
3189
|
-
logActivity(action, resourceType, resourceId, details, success, error) {
|
|
3190
|
-
const activity = {
|
|
3191
|
-
id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
3192
|
-
timestamp: new Date().toISOString(),
|
|
3193
|
-
action,
|
|
3194
|
-
resource_type: resourceType,
|
|
3195
|
-
resource_id: resourceId,
|
|
3196
|
-
details,
|
|
3197
|
-
success,
|
|
3198
|
-
error
|
|
3199
|
-
};
|
|
3200
|
-
this.activityLog.push(activity);
|
|
3201
|
-
if (this.activityLog.length > 1000) {
|
|
3202
|
-
this.activityLog = this.activityLog.slice(-1000);
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
getActivityLog(limit, filter) {
|
|
3206
|
-
let filtered = [...this.activityLog];
|
|
3207
|
-
if (filter) {
|
|
3208
|
-
filtered = filtered.filter((item) => {
|
|
3209
|
-
return Object.entries(filter).every(([key, value]) => {
|
|
3210
|
-
return item[key] === value;
|
|
3211
|
-
});
|
|
3212
|
-
});
|
|
3213
|
-
}
|
|
3214
|
-
return filtered.slice(-(limit || 100));
|
|
3215
|
-
}
|
|
3216
|
-
clearActivityLog() {
|
|
3217
|
-
this.activityLog = [];
|
|
3218
|
-
logger11.info("Linear activity log cleared");
|
|
3219
|
-
}
|
|
3220
|
-
async getTeams() {
|
|
3221
|
-
const teams = await this.client.teams();
|
|
3222
|
-
const teamList = await teams.nodes;
|
|
3223
|
-
this.logActivity("list_teams", "team", "all", { count: teamList.length }, true);
|
|
3224
|
-
return teamList;
|
|
3225
|
-
}
|
|
3226
|
-
async getTeam(teamId) {
|
|
3227
|
-
const team = await this.client.team(teamId);
|
|
3228
|
-
this.logActivity("get_team", "team", teamId, { name: team.name }, true);
|
|
3229
|
-
return team;
|
|
3230
|
-
}
|
|
3231
|
-
async createIssue(input) {
|
|
3232
|
-
const issuePayload = await this.client.createIssue({
|
|
3233
|
-
title: input.title,
|
|
3234
|
-
description: input.description,
|
|
3235
|
-
teamId: input.teamId,
|
|
3236
|
-
priority: input.priority,
|
|
3237
|
-
assigneeId: input.assigneeId,
|
|
3238
|
-
labelIds: input.labelIds,
|
|
3239
|
-
projectId: input.projectId,
|
|
3240
|
-
stateId: input.stateId,
|
|
3241
|
-
estimate: input.estimate,
|
|
3242
|
-
dueDate: input.dueDate
|
|
3243
|
-
});
|
|
3244
|
-
const issue = await issuePayload.issue;
|
|
3245
|
-
if (!issue) {
|
|
3246
|
-
throw new Error("Failed to create issue");
|
|
3247
|
-
}
|
|
3248
|
-
this.logActivity("create_issue", "issue", issue.id, {
|
|
3249
|
-
title: input.title,
|
|
3250
|
-
teamId: input.teamId
|
|
3251
|
-
}, true);
|
|
3252
|
-
return issue;
|
|
3253
|
-
}
|
|
3254
|
-
async getIssue(issueId) {
|
|
3255
|
-
const issue = await this.client.issue(issueId);
|
|
3256
|
-
this.logActivity("get_issue", "issue", issueId, {
|
|
3257
|
-
title: issue.title,
|
|
3258
|
-
identifier: issue.identifier
|
|
3259
|
-
}, true);
|
|
3260
|
-
return issue;
|
|
3261
|
-
}
|
|
3262
|
-
async updateIssue(issueId, updates) {
|
|
3263
|
-
const updatePayload = await this.client.updateIssue(issueId, {
|
|
3264
|
-
title: updates.title,
|
|
3265
|
-
description: updates.description,
|
|
3266
|
-
priority: updates.priority,
|
|
3267
|
-
assigneeId: updates.assigneeId,
|
|
3268
|
-
labelIds: updates.labelIds,
|
|
3269
|
-
projectId: updates.projectId,
|
|
3270
|
-
stateId: updates.stateId,
|
|
3271
|
-
estimate: updates.estimate,
|
|
3272
|
-
dueDate: updates.dueDate
|
|
3273
|
-
});
|
|
3274
|
-
const issue = await updatePayload.issue;
|
|
3275
|
-
if (!issue) {
|
|
3276
|
-
throw new Error("Failed to update issue");
|
|
3277
|
-
}
|
|
3278
|
-
this.logActivity("update_issue", "issue", issueId, updates, true);
|
|
3279
|
-
return issue;
|
|
3280
|
-
}
|
|
3281
|
-
async deleteIssue(issueId) {
|
|
3282
|
-
const archivePayload = await this.client.archiveIssue(issueId);
|
|
3283
|
-
const success = await archivePayload.success;
|
|
3284
|
-
if (!success) {
|
|
3285
|
-
throw new Error("Failed to archive issue");
|
|
3286
|
-
}
|
|
3287
|
-
this.logActivity("delete_issue", "issue", issueId, { action: "archived" }, true);
|
|
3288
|
-
}
|
|
3289
|
-
async searchIssues(filters) {
|
|
3290
|
-
const filterObject = {};
|
|
3291
|
-
if (filters.query) {
|
|
3292
|
-
filterObject.or = [
|
|
3293
|
-
{ title: { containsIgnoreCase: filters.query } },
|
|
3294
|
-
{ description: { containsIgnoreCase: filters.query } }
|
|
3295
|
-
];
|
|
3296
|
-
}
|
|
3297
|
-
if (filters.team) {
|
|
3298
|
-
const teams = await this.getTeams();
|
|
3299
|
-
const team = teams.find((t) => t.key.toLowerCase() === filters.team?.toLowerCase() || t.name.toLowerCase() === filters.team?.toLowerCase());
|
|
3300
|
-
if (team) {
|
|
3301
|
-
filterObject.team = { id: { eq: team.id } };
|
|
3302
|
-
}
|
|
3303
|
-
}
|
|
3304
|
-
if (filters.assignee && filters.assignee.length > 0) {
|
|
3305
|
-
const users = await this.getUsers();
|
|
3306
|
-
const assigneeIds = filters.assignee.map((assigneeName) => {
|
|
3307
|
-
const user = users.find((u) => u.email === assigneeName || u.name.toLowerCase().includes(assigneeName.toLowerCase()));
|
|
3308
|
-
return user?.id;
|
|
3309
|
-
}).filter(Boolean);
|
|
3310
|
-
if (assigneeIds.length > 0) {
|
|
3311
|
-
filterObject.assignee = { id: { in: assigneeIds } };
|
|
3312
|
-
}
|
|
3313
|
-
}
|
|
3314
|
-
if (filters.priority && filters.priority.length > 0) {
|
|
3315
|
-
filterObject.priority = { number: { in: filters.priority } };
|
|
3316
|
-
}
|
|
3317
|
-
if (filters.state && filters.state.length > 0) {
|
|
3318
|
-
filterObject.state = {
|
|
3319
|
-
name: { in: filters.state }
|
|
3320
|
-
};
|
|
3321
|
-
}
|
|
3322
|
-
if (filters.label && filters.label.length > 0) {
|
|
3323
|
-
filterObject.labels = {
|
|
3324
|
-
some: {
|
|
3325
|
-
name: { in: filters.label }
|
|
3326
|
-
}
|
|
3327
|
-
};
|
|
3328
|
-
}
|
|
3329
|
-
const query = this.client.issues({
|
|
3330
|
-
first: filters.limit || 50,
|
|
3331
|
-
filter: Object.keys(filterObject).length > 0 ? filterObject : undefined
|
|
3332
|
-
});
|
|
3333
|
-
const issues = await query;
|
|
3334
|
-
const issueList = await issues.nodes;
|
|
3335
|
-
this.logActivity("search_issues", "issue", "search", {
|
|
3336
|
-
filters: { ...filters },
|
|
3337
|
-
count: issueList.length
|
|
3338
|
-
}, true);
|
|
3339
|
-
return issueList;
|
|
3340
|
-
}
|
|
3341
|
-
async createComment(input) {
|
|
3342
|
-
const commentPayload = await this.client.createComment({
|
|
3343
|
-
body: input.body,
|
|
3344
|
-
issueId: input.issueId
|
|
3345
|
-
});
|
|
3346
|
-
const comment = await commentPayload.comment;
|
|
3347
|
-
if (!comment) {
|
|
3348
|
-
throw new Error("Failed to create comment");
|
|
3349
|
-
}
|
|
3350
|
-
this.logActivity("create_comment", "comment", comment.id, {
|
|
3351
|
-
issueId: input.issueId,
|
|
3352
|
-
bodyLength: input.body.length
|
|
3353
|
-
}, true);
|
|
3354
|
-
return comment;
|
|
3355
|
-
}
|
|
3356
|
-
async getProjects(teamId) {
|
|
3357
|
-
const query = this.client.projects({
|
|
3358
|
-
first: 100
|
|
3359
|
-
});
|
|
3360
|
-
const projects = await query;
|
|
3361
|
-
let projectList = await projects.nodes;
|
|
3362
|
-
if (teamId) {
|
|
3363
|
-
const filteredProjects = await Promise.all(projectList.map(async (project) => {
|
|
3364
|
-
const projectTeams = await project.teams();
|
|
3365
|
-
const teamsList = await projectTeams.nodes;
|
|
3366
|
-
const hasTeam = teamsList.some((team) => team.id === teamId);
|
|
3367
|
-
return hasTeam ? project : null;
|
|
3368
|
-
}));
|
|
3369
|
-
projectList = filteredProjects.filter(Boolean);
|
|
3370
|
-
}
|
|
3371
|
-
this.logActivity("list_projects", "project", "all", {
|
|
3372
|
-
count: projectList.length,
|
|
3373
|
-
teamId
|
|
3374
|
-
}, true);
|
|
3375
|
-
return projectList;
|
|
3376
|
-
}
|
|
3377
|
-
async getProject(projectId) {
|
|
3378
|
-
const project = await this.client.project(projectId);
|
|
3379
|
-
this.logActivity("get_project", "project", projectId, {
|
|
3380
|
-
name: project.name
|
|
3381
|
-
}, true);
|
|
3382
|
-
return project;
|
|
3383
|
-
}
|
|
3384
|
-
async getUsers() {
|
|
3385
|
-
const users = await this.client.users();
|
|
3386
|
-
const userList = await users.nodes;
|
|
3387
|
-
this.logActivity("list_users", "user", "all", {
|
|
3388
|
-
count: userList.length
|
|
3389
|
-
}, true);
|
|
3390
|
-
return userList;
|
|
3391
|
-
}
|
|
3392
|
-
async getCurrentUser() {
|
|
3393
|
-
const user = await this.client.viewer;
|
|
3394
|
-
this.logActivity("get_current_user", "user", user.id, {
|
|
3395
|
-
email: user.email,
|
|
3396
|
-
name: user.name
|
|
3397
|
-
}, true);
|
|
3398
|
-
return user;
|
|
3399
|
-
}
|
|
3400
|
-
async getUserTeams() {
|
|
3401
|
-
const viewer = await this.client.viewer;
|
|
3402
|
-
const teams = await viewer.teams();
|
|
3403
|
-
const teamList = await teams.nodes;
|
|
3404
|
-
this.logActivity("list_user_teams", "team", viewer.id, {
|
|
3405
|
-
count: teamList.length
|
|
3406
|
-
}, true);
|
|
3407
|
-
return teamList;
|
|
3408
|
-
}
|
|
3409
|
-
async getLabels(teamId) {
|
|
3410
|
-
const query = this.client.issueLabels({
|
|
3411
|
-
first: 100,
|
|
3412
|
-
filter: teamId ? {
|
|
3413
|
-
team: { id: { eq: teamId } }
|
|
3414
|
-
} : undefined
|
|
3415
|
-
});
|
|
3416
|
-
const labels = await query;
|
|
3417
|
-
const labelList = await labels.nodes;
|
|
3418
|
-
this.logActivity("list_labels", "label", "all", {
|
|
3419
|
-
count: labelList.length,
|
|
3420
|
-
teamId
|
|
3421
|
-
}, true);
|
|
3422
|
-
return labelList;
|
|
3423
|
-
}
|
|
3424
|
-
async getWorkflowStates(teamId) {
|
|
3425
|
-
const states = await this.client.workflowStates({
|
|
3426
|
-
filter: {
|
|
3427
|
-
team: { id: { eq: teamId } }
|
|
3428
|
-
}
|
|
3429
|
-
});
|
|
3430
|
-
const stateList = await states.nodes;
|
|
3431
|
-
this.logActivity("list_workflow_states", "team", teamId, {
|
|
3432
|
-
count: stateList.length
|
|
3433
|
-
}, true);
|
|
3434
|
-
return stateList;
|
|
3435
|
-
}
|
|
3436
|
-
}
|
|
3437
|
-
|
|
3438
|
-
// src/index.ts
|
|
3439
|
-
var linearPlugin = {
|
|
3440
|
-
name: "@elizaos/plugin-linear-ts",
|
|
3441
|
-
description: "Plugin for integrating with Linear issue tracking system",
|
|
3442
|
-
services: [LinearService],
|
|
3443
|
-
actions: [
|
|
3444
|
-
createIssueAction,
|
|
3445
|
-
getIssueAction,
|
|
3446
|
-
updateIssueAction,
|
|
3447
|
-
deleteIssueAction,
|
|
3448
|
-
searchIssuesAction,
|
|
3449
|
-
createCommentAction,
|
|
3450
|
-
listTeamsAction,
|
|
3451
|
-
listProjectsAction,
|
|
3452
|
-
getActivityAction,
|
|
3453
|
-
clearActivityAction
|
|
3454
|
-
],
|
|
3455
|
-
providers: [
|
|
3456
|
-
linearIssuesProvider,
|
|
3457
|
-
linearTeamsProvider,
|
|
3458
|
-
linearProjectsProvider,
|
|
3459
|
-
linearActivityProvider
|
|
3460
|
-
]
|
|
3461
|
-
};
|
|
3462
|
-
export {
|
|
3463
|
-
linearPlugin,
|
|
3464
|
-
LinearService
|
|
3465
|
-
};
|
|
3466
|
-
|
|
3467
|
-
//# debugId=1F6135D155E56E4E64756E2164756E21
|