@moxxy/factorix-plugin-sdk 0.0.0-stage → 0.2.0
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 +224 -2
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/migrations.d.ts +19 -0
- package/migrations.js +69 -0
- package/node.d.ts +7 -0
- package/node.js +29 -0
- package/package.json +30 -4
- package/plugin.d.ts +184 -0
- package/plugin.js +288 -0
- package/signing.d.ts +10 -0
- package/signing.js +38 -0
- package/testing.d.ts +53 -0
- package/testing.js +189 -0
- package/types.d.ts +418 -0
- package/types.js +1 -0
package/types.d.ts
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
export declare const PROTOCOL = 1;
|
|
2
|
+
/**
|
|
3
|
+
* What a plugin may ask of Factorix beyond its own connections and settings. An organization's admin sees them when
|
|
4
|
+
* turning the plugin on, and Factorix answers only what that admin allowed.
|
|
5
|
+
*
|
|
6
|
+
* - `activity:read`: what happened on tickets, through `factorix().activity`.
|
|
7
|
+
* - `agents:run`: the organization's agents, and runs of them with no ticket and no repository, through `agents`, `startRun`, and `getRun`.
|
|
8
|
+
* - `members:read`: the people and agents of the organization, through `members`.
|
|
9
|
+
* - `tickets:write`: the organization's projects, and tickets the plugin creates in them, through `projects`, `createTicket`, and `getTicket`.
|
|
10
|
+
* - `workflows:blocks`: blocks and triggers in the organization's workflows, what each block is given when it runs, and starting the workflows built on a trigger through `fireTrigger`. `definePlugin` adds it for a plugin with `blocks` or `triggers`.
|
|
11
|
+
*/
|
|
12
|
+
export type Permission = 'activity:read' | 'agents:run' | 'members:read' | 'tickets:write' | 'workflows:blocks';
|
|
13
|
+
export interface Field {
|
|
14
|
+
key: string;
|
|
15
|
+
label: string;
|
|
16
|
+
/** A secret field is stored encrypted by Factorix and reaches the plugin under `secrets`. */
|
|
17
|
+
type: 'text' | 'url' | 'secret';
|
|
18
|
+
required?: boolean;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
hint?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface Manifest {
|
|
23
|
+
protocol: number;
|
|
24
|
+
name: string;
|
|
25
|
+
version: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
provides: 'tracker'[];
|
|
28
|
+
permissions: Permission[];
|
|
29
|
+
connection: {
|
|
30
|
+
fields: Field[];
|
|
31
|
+
};
|
|
32
|
+
settings: {
|
|
33
|
+
fields: Field[];
|
|
34
|
+
};
|
|
35
|
+
pages: {
|
|
36
|
+
key: string;
|
|
37
|
+
label: string;
|
|
38
|
+
path: string;
|
|
39
|
+
placement: 'sidebar' | 'settings';
|
|
40
|
+
}[];
|
|
41
|
+
blocks: ManifestBlock[];
|
|
42
|
+
triggers: ManifestTrigger[];
|
|
43
|
+
}
|
|
44
|
+
export interface BlockField {
|
|
45
|
+
key: string;
|
|
46
|
+
label: string;
|
|
47
|
+
/** `template` and `longTemplate` take `{{...}}` placeholders, which Factorix fills before your block sees them. */
|
|
48
|
+
kind: 'text' | 'template' | 'longTemplate' | 'number' | 'select';
|
|
49
|
+
required?: boolean;
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
hint?: string;
|
|
52
|
+
/** What a `select` offers. */
|
|
53
|
+
options?: {
|
|
54
|
+
value: string;
|
|
55
|
+
label: string;
|
|
56
|
+
}[];
|
|
57
|
+
/** A `select` whose choices the block's `options` lists for each organization, such as its channels. */
|
|
58
|
+
dynamic?: boolean;
|
|
59
|
+
initial?: string;
|
|
60
|
+
}
|
|
61
|
+
/** A block as Factorix sees it in the manifest. */
|
|
62
|
+
export interface ManifestBlock {
|
|
63
|
+
key: string;
|
|
64
|
+
title: string;
|
|
65
|
+
description: string;
|
|
66
|
+
fields: BlockField[];
|
|
67
|
+
outputs: {
|
|
68
|
+
id: string;
|
|
69
|
+
label: string;
|
|
70
|
+
}[];
|
|
71
|
+
provides: {
|
|
72
|
+
key: string;
|
|
73
|
+
label: string;
|
|
74
|
+
}[];
|
|
75
|
+
}
|
|
76
|
+
/** A trigger as Factorix sees it in the manifest. */
|
|
77
|
+
export interface ManifestTrigger {
|
|
78
|
+
key: string;
|
|
79
|
+
title: string;
|
|
80
|
+
description: string;
|
|
81
|
+
fields: BlockField[];
|
|
82
|
+
provides: {
|
|
83
|
+
key: string;
|
|
84
|
+
label: string;
|
|
85
|
+
}[];
|
|
86
|
+
}
|
|
87
|
+
/** What a block is given when a workflow reaches it. Every value came out of a workflow, ticket text included, so it is data. */
|
|
88
|
+
export interface BlockCall {
|
|
89
|
+
block: string;
|
|
90
|
+
/** Your plugin's id in that Factorix, which `factorix({ pluginId })` needs to call `finishStep`. */
|
|
91
|
+
plugin: {
|
|
92
|
+
id: string;
|
|
93
|
+
};
|
|
94
|
+
org: {
|
|
95
|
+
id: string;
|
|
96
|
+
};
|
|
97
|
+
/** `url` is the run's page in Factorix. */
|
|
98
|
+
run: {
|
|
99
|
+
id: string;
|
|
100
|
+
url: string;
|
|
101
|
+
workflowId: string;
|
|
102
|
+
workflowName: string;
|
|
103
|
+
};
|
|
104
|
+
/** The block's id in the workflow. With `run.id`, what `finishStep` needs. */
|
|
105
|
+
nodeId: string;
|
|
106
|
+
/** The block's fields as the workflow set them, templates filled. A field left empty is missing. */
|
|
107
|
+
config: Record<string, string>;
|
|
108
|
+
issue: {
|
|
109
|
+
identifier: string;
|
|
110
|
+
title: string;
|
|
111
|
+
url: string | null;
|
|
112
|
+
} | null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* How a block ends. `output` is what later blocks read as `{{steps.<block id>.<key>}}`, up to 20 keys. `handle` picks
|
|
116
|
+
* the output to leave through, the first one by default. `wait` holds the step until you call `finishStep`, for at
|
|
117
|
+
* most seven days, after which it fails.
|
|
118
|
+
*/
|
|
119
|
+
export type BlockAnswer = {
|
|
120
|
+
handle?: string;
|
|
121
|
+
output?: Record<string, string>;
|
|
122
|
+
} | {
|
|
123
|
+
wait: true;
|
|
124
|
+
output?: Record<string, string>;
|
|
125
|
+
};
|
|
126
|
+
/** One account of the service behind the plugin, as an admin connected it in Factorix. */
|
|
127
|
+
export interface Connection {
|
|
128
|
+
id: string;
|
|
129
|
+
config: Record<string, string>;
|
|
130
|
+
secrets: Record<string, string>;
|
|
131
|
+
}
|
|
132
|
+
/** Who opened a page, as Factorix signed it. */
|
|
133
|
+
export interface PageContext {
|
|
134
|
+
exp: number;
|
|
135
|
+
page: string;
|
|
136
|
+
/** Your plugin's id in that Factorix, which `factorix({ pluginId })` needs. */
|
|
137
|
+
plugin: {
|
|
138
|
+
id: string;
|
|
139
|
+
};
|
|
140
|
+
org: {
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
};
|
|
144
|
+
account: {
|
|
145
|
+
id: string;
|
|
146
|
+
name: string;
|
|
147
|
+
role: string;
|
|
148
|
+
};
|
|
149
|
+
/** What the organization set for the plugin, without the secret fields. */
|
|
150
|
+
settings: Record<string, string>;
|
|
151
|
+
}
|
|
152
|
+
export type StateType = 'triage' | 'backlog' | 'unstarted' | 'started' | 'completed' | 'canceled';
|
|
153
|
+
export interface Team {
|
|
154
|
+
id: string;
|
|
155
|
+
/** The prefix of issue identifiers, as in ABC-12. */
|
|
156
|
+
key: string;
|
|
157
|
+
name: string;
|
|
158
|
+
}
|
|
159
|
+
export interface Project {
|
|
160
|
+
id: string;
|
|
161
|
+
name: string;
|
|
162
|
+
url: string | null;
|
|
163
|
+
}
|
|
164
|
+
export interface State {
|
|
165
|
+
id: string;
|
|
166
|
+
name: string;
|
|
167
|
+
type: StateType;
|
|
168
|
+
position: number;
|
|
169
|
+
}
|
|
170
|
+
export interface Label {
|
|
171
|
+
id: string;
|
|
172
|
+
name: string;
|
|
173
|
+
/** Factorix assigns agents through labels in a group named Agent. A tracker with flat labels can fake the group. */
|
|
174
|
+
parentId: string | null;
|
|
175
|
+
isGroup?: boolean;
|
|
176
|
+
}
|
|
177
|
+
export interface Issue {
|
|
178
|
+
id: string;
|
|
179
|
+
identifier: string;
|
|
180
|
+
title: string;
|
|
181
|
+
/** Markdown. */
|
|
182
|
+
description: string | null;
|
|
183
|
+
url: string | null;
|
|
184
|
+
/** 0 for none, then 1 (most urgent) to 4. */
|
|
185
|
+
priority: number;
|
|
186
|
+
teamId: string;
|
|
187
|
+
projectId: string | null;
|
|
188
|
+
stateId: string;
|
|
189
|
+
stateName: string;
|
|
190
|
+
stateType: StateType;
|
|
191
|
+
assigneeId: string | null;
|
|
192
|
+
assigneeName: string | null;
|
|
193
|
+
creatorId: string | null;
|
|
194
|
+
creatorName: string | null;
|
|
195
|
+
labels: Label[];
|
|
196
|
+
createdAt: string | null;
|
|
197
|
+
updatedAt: string;
|
|
198
|
+
archivedAt: string | null;
|
|
199
|
+
}
|
|
200
|
+
export interface Comment {
|
|
201
|
+
id: string;
|
|
202
|
+
issueId: string;
|
|
203
|
+
/** Markdown. */
|
|
204
|
+
body: string;
|
|
205
|
+
authorId: string | null;
|
|
206
|
+
authorName: string | null;
|
|
207
|
+
createdAt: string;
|
|
208
|
+
}
|
|
209
|
+
export interface Resource {
|
|
210
|
+
kind: 'document' | 'link';
|
|
211
|
+
title: string;
|
|
212
|
+
url: string;
|
|
213
|
+
subtitle: string | null;
|
|
214
|
+
content: string | null;
|
|
215
|
+
}
|
|
216
|
+
export interface Page<T> {
|
|
217
|
+
nodes: T[];
|
|
218
|
+
nextCursor: string | null;
|
|
219
|
+
}
|
|
220
|
+
export interface IssueQuery {
|
|
221
|
+
teamId: string;
|
|
222
|
+
projectId?: string | null;
|
|
223
|
+
/** Only issues that changed after this moment. */
|
|
224
|
+
updatedAfter?: string;
|
|
225
|
+
/** Leaves out issues that closed before this moment. Open issues always come back. */
|
|
226
|
+
closedSince?: string;
|
|
227
|
+
cursor?: string | null;
|
|
228
|
+
limit?: number;
|
|
229
|
+
}
|
|
230
|
+
export interface NewIssue {
|
|
231
|
+
teamId: string;
|
|
232
|
+
projectId?: string | null;
|
|
233
|
+
title: string;
|
|
234
|
+
description?: string;
|
|
235
|
+
priority?: number;
|
|
236
|
+
stateId?: string;
|
|
237
|
+
labelIds?: string[];
|
|
238
|
+
creatorName?: string;
|
|
239
|
+
}
|
|
240
|
+
/** What Factorix asks of a tracker. Ids are yours and opaque to Factorix. */
|
|
241
|
+
export interface Tracker {
|
|
242
|
+
viewer(): Promise<{
|
|
243
|
+
id: string;
|
|
244
|
+
name: string;
|
|
245
|
+
email: string | null;
|
|
246
|
+
}>;
|
|
247
|
+
listTeams(): Promise<Team[]>;
|
|
248
|
+
listWorkflowStates(teamId: string): Promise<State[]>;
|
|
249
|
+
listLabels(teamId: string): Promise<Label[]>;
|
|
250
|
+
/** Ordered by when issues last changed, oldest first, so a sync can stop and pick up again. */
|
|
251
|
+
listIssues(query: IssueQuery): Promise<Page<Issue>>;
|
|
252
|
+
getIssue(id: string): Promise<Issue | null>;
|
|
253
|
+
listComments(issueId: string): Promise<Comment[]>;
|
|
254
|
+
createIssue(input: NewIssue): Promise<Issue>;
|
|
255
|
+
updateIssueState(issueId: string, stateId: string): Promise<void>;
|
|
256
|
+
updateIssueLabels(issueId: string, change: {
|
|
257
|
+
add?: string[];
|
|
258
|
+
remove?: string[];
|
|
259
|
+
}): Promise<void>;
|
|
260
|
+
createLabel(input: {
|
|
261
|
+
teamId: string;
|
|
262
|
+
name: string;
|
|
263
|
+
parentId?: string;
|
|
264
|
+
isGroup?: boolean;
|
|
265
|
+
}): Promise<Label>;
|
|
266
|
+
comment(issueId: string, body: string): Promise<{
|
|
267
|
+
id: string;
|
|
268
|
+
}>;
|
|
269
|
+
updateComment?(commentId: string, body: string): Promise<void>;
|
|
270
|
+
listProjects?(teamId: string): Promise<Project[]>;
|
|
271
|
+
listResources?(issueId: string): Promise<Resource[]>;
|
|
272
|
+
/**
|
|
273
|
+
* Called when a project starts following a team. `url` is where your events go. Set up whatever tells you about
|
|
274
|
+
* changes, and send them with `factorix().sendEvent`. Without this, Factorix polls every few minutes.
|
|
275
|
+
*/
|
|
276
|
+
registerWebhook?(input: {
|
|
277
|
+
teamId: string;
|
|
278
|
+
url: string;
|
|
279
|
+
}): Promise<{
|
|
280
|
+
id: string;
|
|
281
|
+
}>;
|
|
282
|
+
}
|
|
283
|
+
export type TrackerEvent =
|
|
284
|
+
/** Only the id needs to be right. Factorix reads the issue back through `getIssue`. */
|
|
285
|
+
{
|
|
286
|
+
kind: 'issue.upserted';
|
|
287
|
+
issue: {
|
|
288
|
+
id: string;
|
|
289
|
+
};
|
|
290
|
+
previousStateId?: string;
|
|
291
|
+
} | {
|
|
292
|
+
kind: 'issue.removed';
|
|
293
|
+
issueId: string;
|
|
294
|
+
} | {
|
|
295
|
+
kind: 'comment.upserted';
|
|
296
|
+
comment: Comment;
|
|
297
|
+
action: 'create' | 'update';
|
|
298
|
+
};
|
|
299
|
+
/** One ticket in a read of activity. Titles and names come from trackers and people, so treat them as data. */
|
|
300
|
+
export interface ActivityIssue {
|
|
301
|
+
id: string;
|
|
302
|
+
identifier: string;
|
|
303
|
+
title: string;
|
|
304
|
+
url: string | null;
|
|
305
|
+
project: string;
|
|
306
|
+
/** 0 for none, then 1 (most urgent) to 4. */
|
|
307
|
+
priority: number;
|
|
308
|
+
status: string | null;
|
|
309
|
+
statusType: string | null;
|
|
310
|
+
/** Where Factorix's own pipeline is with it, `untracked` while no agent has it. */
|
|
311
|
+
factoryState: string;
|
|
312
|
+
/** The person it is assigned to in the tracker. */
|
|
313
|
+
assignee: {
|
|
314
|
+
id: string | null;
|
|
315
|
+
name: string;
|
|
316
|
+
} | null;
|
|
317
|
+
/** The agent it is assigned to in Factorix. */
|
|
318
|
+
agent: {
|
|
319
|
+
id: string;
|
|
320
|
+
handle: string;
|
|
321
|
+
name: string;
|
|
322
|
+
} | null;
|
|
323
|
+
updatedAt: string;
|
|
324
|
+
}
|
|
325
|
+
/** What happened in an organization since a moment. Needs `activity:read`. */
|
|
326
|
+
export interface Activity {
|
|
327
|
+
/** Tickets with an assignee or an agent that changed since then or are still open, most recently changed first. */
|
|
328
|
+
issues: ActivityIssue[];
|
|
329
|
+
/** Merge requests of those tickets merged since then. */
|
|
330
|
+
merges: {
|
|
331
|
+
issueId: string;
|
|
332
|
+
url: string;
|
|
333
|
+
mergedAt: string;
|
|
334
|
+
}[];
|
|
335
|
+
/** What agents reported when their runs on those tickets succeeded since then. */
|
|
336
|
+
reports: {
|
|
337
|
+
issueId: string;
|
|
338
|
+
agent: string;
|
|
339
|
+
phase: string;
|
|
340
|
+
summary: string;
|
|
341
|
+
finishedAt: string;
|
|
342
|
+
}[];
|
|
343
|
+
/** True when more tickets matched than one answer holds. */
|
|
344
|
+
truncated: boolean;
|
|
345
|
+
}
|
|
346
|
+
export interface Agent {
|
|
347
|
+
id: string;
|
|
348
|
+
handle: string;
|
|
349
|
+
name: string;
|
|
350
|
+
/** `active`, or `disabled` for one that cannot run. */
|
|
351
|
+
status: string;
|
|
352
|
+
runtime: string;
|
|
353
|
+
model: string | null;
|
|
354
|
+
}
|
|
355
|
+
export interface RunRequest {
|
|
356
|
+
agentId: string;
|
|
357
|
+
/** Everything the agent gets. Mark the data in it as data, since the agent follows what the prompt asks. */
|
|
358
|
+
prompt: string;
|
|
359
|
+
/**
|
|
360
|
+
* The JSON Schema of the answer, an object. Claude and Codex both have to be able to fill it, so give every object
|
|
361
|
+
* `additionalProperties: false` and list every property under `required`. Without one the answer is `{ answer: string }`.
|
|
362
|
+
*/
|
|
363
|
+
outputSchema?: Record<string, unknown>;
|
|
364
|
+
}
|
|
365
|
+
/** A run your plugin started. Needs `agents:run`. */
|
|
366
|
+
export interface Run {
|
|
367
|
+
id: string;
|
|
368
|
+
/** `queued` and `running` on the way, then `succeeded`, `failed`, or `cancelled`. */
|
|
369
|
+
state: string;
|
|
370
|
+
/** True once the run succeeded, failed, or was cancelled. */
|
|
371
|
+
finished: boolean;
|
|
372
|
+
agentId: string;
|
|
373
|
+
/** The agent's answer in the shape the plugin asked for, once the run succeeded. */
|
|
374
|
+
output: unknown;
|
|
375
|
+
error: string | null;
|
|
376
|
+
/** The run's page in Factorix. */
|
|
377
|
+
url: string;
|
|
378
|
+
createdAt: string;
|
|
379
|
+
finishedAt: string | null;
|
|
380
|
+
}
|
|
381
|
+
/** A person or an agent of the organization. Needs `members:read`. */
|
|
382
|
+
export interface Member {
|
|
383
|
+
id: string;
|
|
384
|
+
kind: 'person' | 'agent';
|
|
385
|
+
name: string;
|
|
386
|
+
handle: string;
|
|
387
|
+
/** `admin` or `member`. */
|
|
388
|
+
role: string;
|
|
389
|
+
/** `active`, or `disabled` for one that cannot sign in or run. */
|
|
390
|
+
status: string;
|
|
391
|
+
}
|
|
392
|
+
/** A project a ticket can be created in. Needs `tickets:write`. */
|
|
393
|
+
export interface TicketProject {
|
|
394
|
+
id: string;
|
|
395
|
+
name: string;
|
|
396
|
+
}
|
|
397
|
+
export interface TicketRequest {
|
|
398
|
+
projectId: string;
|
|
399
|
+
title: string;
|
|
400
|
+
/** Markdown. */
|
|
401
|
+
description?: string;
|
|
402
|
+
/** 0 for none, then 1 (most urgent) to 4. */
|
|
403
|
+
priority?: number;
|
|
404
|
+
/** Hands the new ticket to this agent, as assigning it in Factorix does. */
|
|
405
|
+
agentId?: string;
|
|
406
|
+
}
|
|
407
|
+
/** A ticket your plugin created. Needs `tickets:write`. */
|
|
408
|
+
export interface Ticket {
|
|
409
|
+
id: string;
|
|
410
|
+
identifier: string;
|
|
411
|
+
title: string;
|
|
412
|
+
/** The ticket in its tracker. */
|
|
413
|
+
url: string | null;
|
|
414
|
+
status: string | null;
|
|
415
|
+
statusType: string | null;
|
|
416
|
+
/** True once its status is completed or canceled. */
|
|
417
|
+
closed: boolean;
|
|
418
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PROTOCOL = 1;
|