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