@dual-os/linear-api 0.0.0-stage → 6.0.4

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.
Files changed (78) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +36 -2
  3. package/Runner.js +5771 -0
  4. package/Runner.js.map +63 -0
  5. package/bundle-inventory.json +1 -0
  6. package/dist/_virtual/_rolldown/runtime.js +10 -0
  7. package/dist/_virtual/_rolldown/runtime.js.map +9 -0
  8. package/dist/auth.d.ts +51 -0
  9. package/dist/auth.d.ts.map +1 -0
  10. package/dist/auth.js +19 -0
  11. package/dist/auth.js.map +9 -0
  12. package/dist/channel/internal/webhook.d.ts +96 -0
  13. package/dist/channel/internal/webhook.d.ts.map +1 -0
  14. package/dist/channel/internal/webhook.js +20 -0
  15. package/dist/channel/internal/webhook.js.map +9 -0
  16. package/dist/channel/linear-app-client.d.ts +54 -0
  17. package/dist/channel/linear-app-client.d.ts.map +1 -0
  18. package/dist/channel/linear-app-client.js +14 -0
  19. package/dist/channel/linear-app-client.js.map +9 -0
  20. package/dist/channel/linear-app-definition.d.ts +171 -0
  21. package/dist/channel/linear-app-definition.d.ts.map +1 -0
  22. package/dist/channel/linear-app-definition.js +18 -0
  23. package/dist/channel/linear-app-definition.js.map +9 -0
  24. package/dist/channel/linear-app.d.ts +65 -0
  25. package/dist/channel/linear-app.d.ts.map +1 -0
  26. package/dist/channel/linear-app.js +15 -0
  27. package/dist/channel/linear-app.js.map +9 -0
  28. package/dist/generated/http.d.ts +81 -0
  29. package/dist/generated/http.d.ts.map +1 -0
  30. package/dist/generated/http.js +66 -0
  31. package/dist/generated/http.js.map +9 -0
  32. package/dist/generated/operations.d.ts +14326 -0
  33. package/dist/generated/operations.d.ts.map +1 -0
  34. package/dist/generated/operations.js +3640 -0
  35. package/dist/generated/operations.js.map +9 -0
  36. package/dist/generated/plugin.d.ts +989 -0
  37. package/dist/generated/plugin.d.ts.map +1 -0
  38. package/dist/generated/plugin.js +20 -0
  39. package/dist/generated/plugin.js.map +9 -0
  40. package/dist/plugin.d.ts +4278 -0
  41. package/dist/plugin.d.ts.map +1 -0
  42. package/dist/plugin.js +33 -0
  43. package/dist/plugin.js.map +10 -0
  44. package/dist/triggers.d.ts +211 -0
  45. package/dist/triggers.d.ts.map +1 -0
  46. package/dist/triggers.js +19 -0
  47. package/dist/triggers.js.map +9 -0
  48. package/dual-plugin.json +1 -0
  49. package/licenses/@dual-os_sdk@0.8.1/LICENSE +4 -0
  50. package/licenses/@effect_platform-node-shared@4.1.2/LICENSE +21 -0
  51. package/licenses/@effect_platform-node@4.1.2/LICENSE +21 -0
  52. package/licenses/effect@4.1.2/LICENSE +21 -0
  53. package/package.json +1 -6
  54. package/plugin-15tbf6dq.js +79 -0
  55. package/plugin-15tbf6dq.js.map +10 -0
  56. package/plugin-2jdfj02n.js +18 -0
  57. package/plugin-2jdfj02n.js.map +10 -0
  58. package/plugin-5bqv66ke.js +14513 -0
  59. package/plugin-5bqv66ke.js.map +10 -0
  60. package/plugin-9w5999vc.js +81 -0
  61. package/plugin-9w5999vc.js.map +10 -0
  62. package/plugin-bcdkw9ac.js +3615 -0
  63. package/plugin-bcdkw9ac.js.map +10 -0
  64. package/plugin-d4a2ytg0.js +19311 -0
  65. package/plugin-d4a2ytg0.js.map +159 -0
  66. package/plugin-dbxxf9k5.js +64 -0
  67. package/plugin-dbxxf9k5.js.map +10 -0
  68. package/plugin-e503g25g.js +204 -0
  69. package/plugin-e503g25g.js.map +10 -0
  70. package/plugin-s3mapcpn.js +138 -0
  71. package/plugin-s3mapcpn.js.map +10 -0
  72. package/plugin-srg9rdjf.js +244 -0
  73. package/plugin-srg9rdjf.js.map +10 -0
  74. package/plugin-v0kgp19h.js +1257 -0
  75. package/plugin-v0kgp19h.js.map +17 -0
  76. package/plugin-xv11dhcc.js +274 -0
  77. package/plugin-xv11dhcc.js.map +10 -0
  78. package/plugin.json +46 -0
@@ -0,0 +1,64 @@
1
+ // @bun
2
+ import {
3
+ __exportAll2
4
+ } from "./plugin-2jdfj02n.js";
5
+ import {
6
+ Http_exports,
7
+ File2,
8
+ FileFromBase642,
9
+ FileFromBase64Url2,
10
+ Base64FromFile2,
11
+ Base64UrlFromFile2,
12
+ FileFromDataUri2,
13
+ DataUriFromFile2,
14
+ DateTimeFromUnixSeconds2,
15
+ UnixSecondsFromDateTime2,
16
+ DateTimeFromRfc28222,
17
+ Rfc2822FromDateTime2,
18
+ decoded2,
19
+ path2,
20
+ literal2,
21
+ segments2,
22
+ params2,
23
+ form2,
24
+ continuation2,
25
+ preauthenticated2
26
+ } from "./plugin-v0kgp19h.js";
27
+ import {
28
+ auth_exports2
29
+ } from "./plugin-9w5999vc.js";
30
+
31
+ // dist/generated/http.js
32
+ var http_exports = /* @__PURE__ */ __exportAll2({
33
+ Base64FromFile: () => Base64FromFile2,
34
+ Base64UrlFromFile: () => Base64UrlFromFile2,
35
+ DataUriFromFile: () => DataUriFromFile2,
36
+ DateTimeFromRfc2822: () => DateTimeFromRfc28222,
37
+ DateTimeFromUnixSeconds: () => DateTimeFromUnixSeconds2,
38
+ File: () => File2,
39
+ FileFromBase64: () => FileFromBase642,
40
+ FileFromBase64Url: () => FileFromBase64Url2,
41
+ FileFromDataUri: () => FileFromDataUri2,
42
+ Http: () => http_exports,
43
+ Rfc2822FromDateTime: () => Rfc2822FromDateTime2,
44
+ UnixSecondsFromDateTime: () => UnixSecondsFromDateTime2,
45
+ continuation: () => continuation2,
46
+ decoded: () => decoded2,
47
+ endpoint: () => endpoint2,
48
+ execute: () => execute2,
49
+ form: () => form2,
50
+ googleUpload: () => googleUpload2,
51
+ graphql: () => graphql2,
52
+ literal: () => literal2,
53
+ mcp: () => mcp2,
54
+ params: () => params2,
55
+ path: () => path2,
56
+ preauthenticated: () => preauthenticated2,
57
+ segments: () => segments2,
58
+ variants: () => variants2
59
+ });
60
+ var { endpoint: endpoint2, execute: execute2, googleUpload: googleUpload2, graphql: graphql2, mcp: mcp2, variants: variants2 } = Http_exports.make(auth_exports2);
61
+ export { http_exports, endpoint2, execute2, googleUpload2, graphql2, mcp2, variants2 };
62
+
63
+ //# debugId=408C6208F824AFC164756E2164756E21
64
+ //# sourceMappingURL=plugin-dbxxf9k5.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../bundle-input/dist/generated/http.js"],
4
+ "sourcesContent": [
5
+ "import { __exportAll } from \"../_virtual/_rolldown/runtime.js\";\nimport { auth_exports } from \"../auth.js\";\nimport \"./http.js\";\nimport { Http } from \"@dual-os/sdk\";\nimport { Base64FromFile, Base64UrlFromFile, DataUriFromFile, DateTimeFromRfc2822, DateTimeFromUnixSeconds, File, FileFromBase64, FileFromBase64Url, FileFromDataUri, Rfc2822FromDateTime, UnixSecondsFromDateTime, continuation, decoded, form, literal, params, path, preauthenticated, segments } from \"@dual-os/sdk/Http\";\n//#region src/generated/http.ts\nvar http_exports = /* @__PURE__ */ __exportAll({\n\tBase64FromFile: () => Base64FromFile,\n\tBase64UrlFromFile: () => Base64UrlFromFile,\n\tDataUriFromFile: () => DataUriFromFile,\n\tDateTimeFromRfc2822: () => DateTimeFromRfc2822,\n\tDateTimeFromUnixSeconds: () => DateTimeFromUnixSeconds,\n\tFile: () => File,\n\tFileFromBase64: () => FileFromBase64,\n\tFileFromBase64Url: () => FileFromBase64Url,\n\tFileFromDataUri: () => FileFromDataUri,\n\tHttp: () => http_exports,\n\tRfc2822FromDateTime: () => Rfc2822FromDateTime,\n\tUnixSecondsFromDateTime: () => UnixSecondsFromDateTime,\n\tcontinuation: () => continuation,\n\tdecoded: () => decoded,\n\tendpoint: () => endpoint,\n\texecute: () => execute,\n\tform: () => form,\n\tgoogleUpload: () => googleUpload,\n\tgraphql: () => graphql,\n\tliteral: () => literal,\n\tmcp: () => mcp,\n\tparams: () => params,\n\tpath: () => path,\n\tpreauthenticated: () => preauthenticated,\n\tsegments: () => segments,\n\tvariants: () => variants\n});\nconst { endpoint, execute, googleUpload, graphql, mcp, variants } = Http.make(auth_exports);\n//#endregion\nexport { Base64FromFile, Base64UrlFromFile, DataUriFromFile, DateTimeFromRfc2822, DateTimeFromUnixSeconds, File, FileFromBase64, FileFromBase64Url, FileFromDataUri, http_exports as Http, Rfc2822FromDateTime, UnixSecondsFromDateTime, continuation, decoded, endpoint, execute, form, googleUpload, graphql, literal, mcp, params, path, preauthenticated, segments, variants };\n\n//# sourceMappingURL=http.js.map"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAI,+BAA+B,aAAY;AAAA,EAC9C,gBAAgB,MAAM;AAAA,EACtB,mBAAmB,MAAM;AAAA,EACzB,iBAAiB,MAAM;AAAA,EACvB,qBAAqB,MAAM;AAAA,EAC3B,yBAAyB,MAAM;AAAA,EAC/B,MAAM,MAAM;AAAA,EACZ,gBAAgB,MAAM;AAAA,EACtB,mBAAmB,MAAM;AAAA,EACzB,iBAAiB,MAAM;AAAA,EACvB,MAAM,MAAM;AAAA,EACZ,qBAAqB,MAAM;AAAA,EAC3B,yBAAyB,MAAM;AAAA,EAC/B,cAAc,MAAM;AAAA,EACpB,SAAS,MAAM;AAAA,EACf,UAAU,MAAM;AAAA,EAChB,SAAS,MAAM;AAAA,EACf,MAAM,MAAM;AAAA,EACZ,cAAc,MAAM;AAAA,EACpB,SAAS,MAAM;AAAA,EACf,SAAS,MAAM;AAAA,EACf,KAAK,MAAM;AAAA,EACX,QAAQ,MAAM;AAAA,EACd,MAAM,MAAM;AAAA,EACZ,kBAAkB,MAAM;AAAA,EACxB,UAAU,MAAM;AAAA,EAChB,UAAU,MAAM;AACjB,CAAC;AACD,MAAQ,qBAAU,mBAAS,6BAAc,mBAAS,WAAK,wBAAa,aAAK,KAAK,aAAY;",
8
+ "debugId": "408C6208F824AFC164756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,204 @@
1
+ // @bun
2
+ import {
3
+ pipe,
4
+ isNullish,
5
+ isNotNullish,
6
+ some,
7
+ match,
8
+ getOrElse,
9
+ orElse,
10
+ fromNullishOr,
11
+ map,
12
+ filter,
13
+ toEntries,
14
+ isReadonlyArrayNonEmpty,
15
+ head,
16
+ findFirst,
17
+ contains,
18
+ empty2,
19
+ of,
20
+ map3,
21
+ filter2,
22
+ dedupe,
23
+ currentTimeMillis,
24
+ between,
25
+ toLowerCase,
26
+ slice,
27
+ isEmpty,
28
+ isNonEmpty,
29
+ startsWith,
30
+ mapError,
31
+ fn,
32
+ formatIso,
33
+ decodeEffect,
34
+ optionalKey,
35
+ Literal,
36
+ String3,
37
+ Struct,
38
+ Literals,
39
+ NullOr,
40
+ Finite,
41
+ fromJsonString,
42
+ DateTimeUtcFromString,
43
+ AgentChannel_exports,
44
+ Trigger_exports
45
+ } from "./plugin-d4a2ytg0.js";
46
+
47
+ // dist/channel/internal/webhook.js
48
+ var maxText = 65536;
49
+ var maxSkewMs = 60000;
50
+ var Signed = fromJsonString(Struct({ webhookTimestamp: Finite }));
51
+ var Envelope = fromJsonString(Struct({
52
+ action: optionalKey(String3),
53
+ organizationId: optionalKey(String3),
54
+ type: String3
55
+ }));
56
+ var Prompt = Struct({
57
+ agentSessionId: AgentChannel_exports.Key,
58
+ content: Struct({ body: optionalKey(NullOr(String3)) }),
59
+ createdAt: DateTimeUtcFromString,
60
+ id: AgentChannel_exports.Key,
61
+ signal: optionalKey(NullOr(String3)),
62
+ sourceCommentId: optionalKey(NullOr(AgentChannel_exports.Key)),
63
+ userId: AgentChannel_exports.Key
64
+ });
65
+ var SessionEvent = fromJsonString(Struct({
66
+ action: Literals(["created", "prompted"]),
67
+ agentActivity: optionalKey(NullOr(Prompt)),
68
+ agentSession: Struct({
69
+ appUserId: AgentChannel_exports.Key,
70
+ commentId: optionalKey(NullOr(AgentChannel_exports.Key)),
71
+ sourceCommentId: optionalKey(NullOr(AgentChannel_exports.Key)),
72
+ createdAt: DateTimeUtcFromString,
73
+ creatorId: optionalKey(NullOr(AgentChannel_exports.Key)),
74
+ id: AgentChannel_exports.Key,
75
+ issue: optionalKey(NullOr(Struct({
76
+ id: AgentChannel_exports.Key,
77
+ identifier: String3,
78
+ teamId: optionalKey(NullOr(AgentChannel_exports.Key)),
79
+ title: String3
80
+ }))),
81
+ issueId: optionalKey(NullOr(AgentChannel_exports.Key)),
82
+ organizationId: AgentChannel_exports.Key
83
+ }),
84
+ appUserId: AgentChannel_exports.Key,
85
+ organizationId: AgentChannel_exports.Key,
86
+ promptContext: optionalKey(NullOr(String3)),
87
+ type: Literal("AgentSessionEvent")
88
+ }));
89
+ function unauthorized() {
90
+ return AgentChannel_exports.HandlerError.make({ code: "unauthorized" });
91
+ }
92
+ function rejected() {
93
+ return AgentChannel_exports.HandlerError.make({ code: "rejected" });
94
+ }
95
+ var verifyWebhook2 = fn("LinearAppWebhook.verify")(function* (request, signingSecret) {
96
+ const signatures = pipe(toEntries(request.headers), filter2((entry) => toLowerCase(entry[0]) === "linear-signature"), map3((entry) => entry[1]));
97
+ if (request.method !== "POST" || signatures.length !== 1)
98
+ return yield* unauthorized();
99
+ if (!(yield* Trigger_exports.verifyHmac({
100
+ algorithm: "sha256",
101
+ encoding: "hex",
102
+ message: request.body,
103
+ secret: signingSecret,
104
+ signature: signatures
105
+ })))
106
+ return yield* unauthorized();
107
+ const sent = (yield* pipe(request.body, decodeEffect(Signed), mapError(unauthorized))).webhookTimestamp;
108
+ const now = yield* currentTimeMillis;
109
+ if (!between(sent, {
110
+ maximum: now + maxSkewMs,
111
+ minimum: now - maxSkewMs
112
+ }))
113
+ return yield* unauthorized();
114
+ return { verified: true };
115
+ });
116
+ function commentKey2(commentId) {
117
+ return `comment/${commentId}`;
118
+ }
119
+ function commentOf2(messageKey) {
120
+ return pipe(some(messageKey), filter(startsWith("comment/")), map(slice(8)));
121
+ }
122
+ function destination(sessionId, issueId) {
123
+ return {
124
+ conversationKey: getOrElse(issueId, () => sessionId),
125
+ kind: "group",
126
+ threadKey: sessionId
127
+ };
128
+ }
129
+ function issueOf2(target) {
130
+ return pipe(some(target.conversationKey), filter((key) => key !== target.threadKey));
131
+ }
132
+ function sessionStarted(webhook, identity, issueId) {
133
+ const session = webhook.agentSession;
134
+ const senderKey = session.creatorId ?? webhook.agentActivity?.userId ?? undefined;
135
+ if (senderKey === undefined || senderKey === identity.appUserId)
136
+ return empty2();
137
+ const text = pipe([webhook.promptContext ?? "", webhook.agentActivity?.content.body ?? ""], findFirst(isNonEmpty), orElse(() => map(fromNullishOr(session.issue), (issue) => `${issue.identifier}: ${issue.title}`)), getOrElse(() => "Linear Agent Session started"), slice(0, maxText));
138
+ return of({
139
+ content: { text },
140
+ conversation: destination(session.id, issueId),
141
+ eventKey: `session/${session.id}`,
142
+ kind: "message",
143
+ messageKey: match(fromNullishOr(session.sourceCommentId ?? session.commentId), {
144
+ onNone: () => `session/${session.id}`,
145
+ onSome: commentKey2
146
+ }),
147
+ respond: true,
148
+ senderKey,
149
+ timestamp: formatIso(session.createdAt)
150
+ });
151
+ }
152
+ function prompted(prompt, identity, issueId) {
153
+ if (prompt.userId === identity.appUserId)
154
+ return empty2();
155
+ const shared = {
156
+ conversation: destination(prompt.agentSessionId, issueId),
157
+ eventKey: `activity/${prompt.id}`,
158
+ senderKey: prompt.userId,
159
+ timestamp: formatIso(prompt.createdAt)
160
+ };
161
+ if (prompt.signal === "stop")
162
+ return of({
163
+ ...shared,
164
+ kind: "stop"
165
+ });
166
+ const text = slice(0, maxText)(prompt.content.body ?? "");
167
+ if (isEmpty(text))
168
+ return empty2();
169
+ return of({
170
+ ...shared,
171
+ content: { text },
172
+ kind: "message",
173
+ messageKey: match(fromNullishOr(prompt.sourceCommentId), {
174
+ onNone: () => `activity/${prompt.id}`,
175
+ onSome: commentKey2
176
+ }),
177
+ respond: true
178
+ });
179
+ }
180
+ var webhookEvents2 = fn("LinearAppWebhook.events")(function* (body, identity, teams) {
181
+ const envelope = yield* pipe(body, decodeEffect(Envelope), mapError(rejected));
182
+ if ((envelope.organizationId ?? identity.organizationId) !== identity.organizationId)
183
+ return yield* unauthorized();
184
+ if (envelope.type !== "AgentSessionEvent" || envelope.action !== "created" && envelope.action !== "prompted")
185
+ return empty2();
186
+ const webhook = yield* pipe(body, decodeEffect(SessionEvent), mapError(rejected));
187
+ const session = webhook.agentSession;
188
+ if (webhook.organizationId !== identity.organizationId || session.organizationId !== identity.organizationId || webhook.appUserId !== identity.appUserId || session.appUserId !== identity.appUserId)
189
+ return yield* unauthorized();
190
+ const issueIds = dedupe(filter2([session.issue?.id, session.issueId], isNotNullish));
191
+ if (issueIds.length > 1 || isNotNullish(webhook.agentActivity) && webhook.agentActivity.agentSessionId !== session.id)
192
+ return yield* rejected();
193
+ if (isReadonlyArrayNonEmpty(teams) && !contains(teams, session.issue?.teamId ?? ""))
194
+ return empty2();
195
+ if (webhook.action === "created")
196
+ return sessionStarted(webhook, identity, head(issueIds));
197
+ if (isNullish(webhook.agentActivity))
198
+ return yield* rejected();
199
+ return prompted(webhook.agentActivity, identity, head(issueIds));
200
+ });
201
+ export { verifyWebhook2, commentKey2, commentOf2, issueOf2, webhookEvents2 };
202
+
203
+ //# debugId=031E412E053A8C9664756E2164756E21
204
+ //# sourceMappingURL=plugin-e503g25g.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../bundle-input/dist/channel/internal/webhook.js"],
4
+ "sourcesContent": [
5
+ "import { Array, Clock, DateTime, Effect, Number, Option, Predicate, Record, Schema, String, pipe } from \"effect\";\nimport { AgentChannel, Trigger } from \"@dual-os/sdk\";\n//#region src/channel/internal/webhook.ts\n/** The longest message text the contract accepts; a longer prompt context is cut. */\nconst maxText = 65536;\n/** Linear's guide refuses a delivery dated more than a minute away from now, against replays. */\nconst maxSkewMs = 6e4;\nconst Signed = Schema.fromJsonString(Schema.Struct({ webhookTimestamp: Schema.Finite }));\nconst Envelope = Schema.fromJsonString(Schema.Struct({\n\taction: Schema.optionalKey(Schema.String),\n\torganizationId: Schema.optionalKey(Schema.String),\n\ttype: Schema.String\n}));\nconst Prompt = Schema.Struct({\n\tagentSessionId: AgentChannel.Key,\n\tcontent: Schema.Struct({ body: Schema.optionalKey(Schema.NullOr(Schema.String)) }),\n\tcreatedAt: Schema.DateTimeUtcFromString,\n\tid: AgentChannel.Key,\n\t/** `stop` when the user stops the session. */\n\tsignal: Schema.optionalKey(Schema.NullOr(Schema.String)),\n\t/** The comment the user prompted with, when they replied in the session's comment thread. */\n\tsourceCommentId: Schema.optionalKey(Schema.NullOr(AgentChannel.Key)),\n\tuserId: AgentChannel.Key\n});\nconst SessionEvent = Schema.fromJsonString(Schema.Struct({\n\taction: Schema.Literals([\"created\", \"prompted\"]),\n\tagentActivity: Schema.optionalKey(Schema.NullOr(Prompt)),\n\tagentSession: Schema.Struct({\n\t\tappUserId: AgentChannel.Key,\n\t\t/** The root comment of the session's own thread. */\n\t\tcommentId: Schema.optionalKey(Schema.NullOr(AgentChannel.Key)),\n\t\t/** The originating mention, when the session starts in a different thread. */\n\t\tsourceCommentId: Schema.optionalKey(Schema.NullOr(AgentChannel.Key)),\n\t\tcreatedAt: Schema.DateTimeUtcFromString,\n\t\tcreatorId: Schema.optionalKey(Schema.NullOr(AgentChannel.Key)),\n\t\tid: AgentChannel.Key,\n\t\tissue: Schema.optionalKey(Schema.NullOr(Schema.Struct({\n\t\t\tid: AgentChannel.Key,\n\t\t\tidentifier: Schema.String,\n\t\t\tteamId: Schema.optionalKey(Schema.NullOr(AgentChannel.Key)),\n\t\t\ttitle: Schema.String\n\t\t}))),\n\t\tissueId: Schema.optionalKey(Schema.NullOr(AgentChannel.Key)),\n\t\torganizationId: AgentChannel.Key\n\t}),\n\tappUserId: AgentChannel.Key,\n\torganizationId: AgentChannel.Key,\n\t/** Linear's summary of the issue, its comments and guidance, sent when a session starts. */\n\tpromptContext: Schema.optionalKey(Schema.NullOr(Schema.String)),\n\ttype: Schema.Literal(\"AgentSessionEvent\")\n}));\nfunction unauthorized() {\n\treturn AgentChannel.HandlerError.make({ code: \"unauthorized\" });\n}\nfunction rejected() {\n\treturn AgentChannel.HandlerError.make({ code: \"rejected\" });\n}\n/** Linear signs the raw body in `Linear-Signature` and dates it in `webhookTimestamp`. */\nconst verifyWebhook = Effect.fn(\"LinearAppWebhook.verify\")(function* (request, signingSecret) {\n\tconst signatures = pipe(Record.toEntries(request.headers), Array.filter((entry) => String.toLowerCase(entry[0]) === \"linear-signature\"), Array.map((entry) => entry[1]));\n\tif (request.method !== \"POST\" || signatures.length !== 1) return yield* unauthorized();\n\tif (!(yield* Trigger.verifyHmac({\n\t\talgorithm: \"sha256\",\n\t\tencoding: \"hex\",\n\t\tmessage: request.body,\n\t\tsecret: signingSecret,\n\t\tsignature: signatures\n\t}))) return yield* unauthorized();\n\tconst sent = (yield* pipe(request.body, Schema.decodeEffect(Signed), Effect.mapError(unauthorized))).webhookTimestamp;\n\tconst now = yield* Clock.currentTimeMillis;\n\tif (!Number.between(sent, {\n\t\tmaximum: now + maxSkewMs,\n\t\tminimum: now - maxSkewMs\n\t})) return yield* unauthorized();\n\treturn { verified: true };\n});\n/** A provider message key: the comment a user wrote, else the session or prompt it started. */\nfunction commentKey(commentId) {\n\treturn `comment/${commentId}`;\n}\n/** The Linear comment a message key names, if it names one. */\nfunction commentOf(messageKey) {\n\treturn pipe(Option.some(messageKey), Option.filter(String.startsWith(\"comment/\")), Option.map(String.slice(8)));\n}\n/** A session's conversation is its issue; a session outside an issue is its own conversation. */\nfunction destination(sessionId, issueId) {\n\treturn {\n\t\tconversationKey: Option.getOrElse(issueId, () => sessionId),\n\t\tkind: \"group\",\n\t\tthreadKey: sessionId\n\t};\n}\n/** The issue a destination names, or none for a session outside an issue. */\nfunction issueOf(target) {\n\treturn pipe(Option.some(target.conversationKey), Option.filter((key) => key !== target.threadKey));\n}\nfunction sessionStarted(webhook, identity, issueId) {\n\tconst session = webhook.agentSession;\n\tconst senderKey = session.creatorId ?? webhook.agentActivity?.userId ?? void 0;\n\tif (senderKey === void 0 || senderKey === identity.appUserId) return Array.empty();\n\tconst text = pipe([webhook.promptContext ?? \"\", webhook.agentActivity?.content.body ?? \"\"], Array.findFirst(String.isNonEmpty), Option.orElse(() => Option.map(Option.fromNullishOr(session.issue), (issue) => `${issue.identifier}: ${issue.title}`)), Option.getOrElse(() => \"Linear Agent Session started\"), String.slice(0, maxText));\n\treturn Array.of({\n\t\tcontent: { text },\n\t\tconversation: destination(session.id, issueId),\n\t\teventKey: `session/${session.id}`,\n\t\tkind: \"message\",\n\t\tmessageKey: Option.match(Option.fromNullishOr(session.sourceCommentId ?? session.commentId), {\n\t\t\tonNone: () => `session/${session.id}`,\n\t\t\tonSome: commentKey\n\t\t}),\n\t\trespond: true,\n\t\tsenderKey,\n\t\ttimestamp: DateTime.formatIso(session.createdAt)\n\t});\n}\nfunction prompted(prompt, identity, issueId) {\n\tif (prompt.userId === identity.appUserId) return Array.empty();\n\tconst shared = {\n\t\tconversation: destination(prompt.agentSessionId, issueId),\n\t\teventKey: `activity/${prompt.id}`,\n\t\tsenderKey: prompt.userId,\n\t\ttimestamp: DateTime.formatIso(prompt.createdAt)\n\t};\n\tif (prompt.signal === \"stop\") return Array.of({\n\t\t...shared,\n\t\tkind: \"stop\"\n\t});\n\tconst text = String.slice(0, maxText)(prompt.content.body ?? \"\");\n\tif (String.isEmpty(text)) return Array.empty();\n\treturn Array.of({\n\t\t...shared,\n\t\tcontent: { text },\n\t\tkind: \"message\",\n\t\tmessageKey: Option.match(Option.fromNullishOr(prompt.sourceCommentId), {\n\t\t\tonNone: () => `activity/${prompt.id}`,\n\t\t\tonSome: commentKey\n\t\t}),\n\t\trespond: true\n\t});\n}\n/** The events of one verified webhook: a session start, a prompt or a stop; nothing for the rest. */\nconst webhookEvents = Effect.fn(\"LinearAppWebhook.events\")(function* (body, identity, teams) {\n\tconst envelope = yield* pipe(body, Schema.decodeEffect(Envelope), Effect.mapError(rejected));\n\tif ((envelope.organizationId ?? identity.organizationId) !== identity.organizationId) return yield* unauthorized();\n\tif (envelope.type !== \"AgentSessionEvent\" || envelope.action !== \"created\" && envelope.action !== \"prompted\") return Array.empty();\n\tconst webhook = yield* pipe(body, Schema.decodeEffect(SessionEvent), Effect.mapError(rejected));\n\tconst session = webhook.agentSession;\n\tif (webhook.organizationId !== identity.organizationId || session.organizationId !== identity.organizationId || webhook.appUserId !== identity.appUserId || session.appUserId !== identity.appUserId) return yield* unauthorized();\n\tconst issueIds = Array.dedupe(Array.filter([session.issue?.id, session.issueId], Predicate.isNotNullish));\n\tif (issueIds.length > 1 || Predicate.isNotNullish(webhook.agentActivity) && webhook.agentActivity.agentSessionId !== session.id) return yield* rejected();\n\tif (Array.isReadonlyArrayNonEmpty(teams) && !Array.contains(teams, session.issue?.teamId ?? \"\")) return Array.empty();\n\tif (webhook.action === \"created\") return sessionStarted(webhook, identity, Array.head(issueIds));\n\tif (Predicate.isNullish(webhook.agentActivity)) return yield* rejected();\n\treturn prompted(webhook.agentActivity, identity, Array.head(issueIds));\n});\n//#endregion\nexport { commentKey, commentOf, issueOf, verifyWebhook, webhookEvents };\n\n//# sourceMappingURL=webhook.js.map"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAM,UAAU;AAEhB,IAAM,YAAY;AAClB,IAAM,SAAS,eAAsB,OAAc,EAAE,kBAAkB,OAAc,CAAC,CAAC;AACvF,IAAM,WAAW,eAAsB,OAAc;AAAA,EACpD,QAAQ,YAAmB,OAAa;AAAA,EACxC,gBAAgB,YAAmB,OAAa;AAAA,EAChD,MAAM;AACP,CAAC,CAAC;AACF,IAAM,SAAS,OAAc;AAAA,EAC5B,gBAAgB,qBAAa;AAAA,EAC7B,SAAS,OAAc,EAAE,MAAM,YAAmB,OAAc,OAAa,CAAC,EAAE,CAAC;AAAA,EACjF,WAAW;AAAA,EACX,IAAI,qBAAa;AAAA,EAEjB,QAAQ,YAAmB,OAAc,OAAa,CAAC;AAAA,EAEvD,iBAAiB,YAAmB,OAAc,qBAAa,GAAG,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,IAAI,UAAoB,QAAQ,aAAa;AAAA,IAAG,OAAO,OAAO,SAAS;AAAA,EACvE,OAAO,SAAS,QAAQ,eAAe,UAAU,KAAW,QAAQ,CAAC;AAAA,CACrE;",
8
+ "debugId": "031E412E053A8C9664756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,138 @@
1
+ // @bun
2
+ import {
3
+ match,
4
+ fromNullishOr,
5
+ fromUndefinedOr,
6
+ map3,
7
+ some2,
8
+ currentTimeMillis,
9
+ between,
10
+ capitalize,
11
+ fn,
12
+ decodeUnknownEffect,
13
+ optionalKey,
14
+ Unknown,
15
+ String3,
16
+ Struct,
17
+ Record,
18
+ StructWithRest,
19
+ ArraySchema,
20
+ Literals,
21
+ Finite,
22
+ Uint8Array2,
23
+ Uint8ArrayFromHex,
24
+ TaggedError2,
25
+ Action_exports,
26
+ Trigger_exports
27
+ } from "./plugin-d4a2ytg0.js";
28
+ import {
29
+ mutation_webhookCreate2,
30
+ mutation_webhookDelete2
31
+ } from "./plugin-5bqv66ke.js";
32
+
33
+ // dist/triggers.js
34
+ var LinearSignatureError = class extends TaggedError2()("LinearSignatureError", {}) {
35
+ };
36
+ var Event = StructWithRest(Struct({
37
+ action: optionalKey(String3),
38
+ createdAt: optionalKey(String3),
39
+ data: optionalKey(Unknown),
40
+ organizationId: optionalKey(String3),
41
+ type: optionalKey(String3),
42
+ updatedFrom: optionalKey(Unknown),
43
+ url: optionalKey(String3),
44
+ webhookId: optionalKey(String3),
45
+ webhookTimestamp: optionalKey(Finite)
46
+ }), [Record(String3, Unknown)]);
47
+ var Delivery = Struct({ body: Event });
48
+ var SignedDelivery = Struct({
49
+ body: Struct({ webhookTimestamp: optionalKey(Finite) }),
50
+ headers: Struct({ "linear-signature": Uint8ArrayFromHex }),
51
+ rawBody: Uint8Array2
52
+ });
53
+ var triggers2 = [Trigger_exports.webhook("event", {
54
+ description: "Triggers when Linear events occur (issues, comments, labels, projects, and more)",
55
+ name: "Linear event",
56
+ config: Struct({
57
+ resources: ArraySchema(Literals([
58
+ "issue",
59
+ "comment",
60
+ "issueLabel",
61
+ "project",
62
+ "cycle",
63
+ "reaction",
64
+ "projectUpdate",
65
+ "document",
66
+ "initiative",
67
+ "customerNeed"
68
+ ])),
69
+ teamId: String3
70
+ }),
71
+ output: Event,
72
+ state: Struct({
73
+ secret: optionalKey(String3),
74
+ webhookId: String3
75
+ })
76
+ })];
77
+ var handlers2 = { event: {
78
+ activate: fn("Linear.event.activate")(function* (input, context) {
79
+ const created = yield* mutation_webhookCreate2.run({ payload: { input: {
80
+ resourceTypes: map3(input.config.resources, capitalize),
81
+ teamId: input.config.teamId,
82
+ url: input.webhookUrl,
83
+ ...match(fromUndefinedOr(context.auth.current.value.signingSecret), {
84
+ onNone: () => ({}),
85
+ onSome: (secret) => ({ secret })
86
+ })
87
+ } } }, context);
88
+ if (!created.success)
89
+ return yield* Action_exports.ActionHandlerError.make({ message: "Linear did not register the webhook" });
90
+ return { state: {
91
+ webhookId: created.webhook.id,
92
+ ...match(fromNullishOr(created.webhook.secret), {
93
+ onNone: () => ({}),
94
+ onSome: (secret) => ({ secret })
95
+ })
96
+ } };
97
+ }),
98
+ deactivate: fn("Linear.event.deactivate")(function* (input, context) {
99
+ if (input.state === undefined)
100
+ return;
101
+ if (!(yield* mutation_webhookDelete2.run({ payload: { id: input.state.webhookId } }, context)).success)
102
+ return yield* Action_exports.ActionHandlerError.make({ message: "Linear did not delete the webhook" });
103
+ }),
104
+ parse: fn("Linear.event.parse")(function* (input) {
105
+ const delivery = yield* decodeUnknownEffect(Delivery)({ body: input.request.body });
106
+ const matches = some2(input.config.resources, (resource) => capitalize(resource) === delivery.body.type);
107
+ const key = yield* Trigger_exports.bodyDigest(input.request.rawBody ?? "");
108
+ return {
109
+ events: matches ? [{
110
+ key,
111
+ payload: delivery.body
112
+ }] : [],
113
+ state: input.state
114
+ };
115
+ }),
116
+ verify: fn("Linear.event.verify")(function* (input, context) {
117
+ const secret = input.state?.secret ?? context.auth.current.value.signingSecret;
118
+ if (secret === undefined)
119
+ return yield* LinearSignatureError.make({});
120
+ const headers = input.request.headers ?? {};
121
+ const delivery = yield* decodeUnknownEffect(SignedDelivery)({
122
+ ...input.request,
123
+ headers
124
+ });
125
+ const signed = yield* Trigger_exports.verifyHmacSha256(secret, delivery.rawBody, delivery.headers["linear-signature"]);
126
+ const now = yield* currentTimeMillis;
127
+ const fresh = delivery.body.webhookTimestamp === undefined || between(delivery.body.webhookTimestamp, {
128
+ maximum: now + 60000,
129
+ minimum: now - 60000
130
+ });
131
+ if (!signed || !fresh)
132
+ return yield* LinearSignatureError.make({});
133
+ })
134
+ } };
135
+ export { triggers2, handlers2 };
136
+
137
+ //# debugId=15AFE37A5253660164756E2164756E21
138
+ //# sourceMappingURL=plugin-s3mapcpn.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../bundle-input/dist/triggers.js"],
4
+ "sourcesContent": [
5
+ "import { mutation_webhookCreate, mutation_webhookDelete } from \"./generated/operations.js\";\nimport { Array, Clock, Effect, Number, Option, Schema, String } from \"effect\";\nimport { Action, Trigger } from \"@dual-os/sdk\";\n//#region src/triggers.ts\nvar LinearSignatureError = class extends Schema.TaggedError()(\"LinearSignatureError\", {}) {};\nconst Event = Schema.StructWithRest(Schema.Struct({\n\taction: Schema.optionalKey(Schema.String),\n\tcreatedAt: Schema.optionalKey(Schema.String),\n\tdata: Schema.optionalKey(Schema.Unknown),\n\torganizationId: Schema.optionalKey(Schema.String),\n\ttype: Schema.optionalKey(Schema.String),\n\tupdatedFrom: Schema.optionalKey(Schema.Unknown),\n\turl: Schema.optionalKey(Schema.String),\n\twebhookId: Schema.optionalKey(Schema.String),\n\twebhookTimestamp: Schema.optionalKey(Schema.Finite)\n}), [Schema.Record(Schema.String, Schema.Unknown)]);\nconst Delivery = Schema.Struct({ body: Event });\nconst SignedDelivery = Schema.Struct({\n\tbody: Schema.Struct({ webhookTimestamp: Schema.optionalKey(Schema.Finite) }),\n\theaders: Schema.Struct({ \"linear-signature\": Schema.Uint8ArrayFromHex }),\n\trawBody: Schema.Uint8Array\n});\nconst triggers = [Trigger.webhook(\"event\", {\n\tdescription: \"Triggers when Linear events occur (issues, comments, labels, projects, and more)\",\n\tname: \"Linear event\",\n\tconfig: Schema.Struct({\n\t\tresources: Schema.Array(Schema.Literals([\n\t\t\t\"issue\",\n\t\t\t\"comment\",\n\t\t\t\"issueLabel\",\n\t\t\t\"project\",\n\t\t\t\"cycle\",\n\t\t\t\"reaction\",\n\t\t\t\"projectUpdate\",\n\t\t\t\"document\",\n\t\t\t\"initiative\",\n\t\t\t\"customerNeed\"\n\t\t])),\n\t\tteamId: Schema.String\n\t}),\n\toutput: Event,\n\tstate: Schema.Struct({\n\t\tsecret: Schema.optionalKey(Schema.String),\n\t\twebhookId: Schema.String\n\t})\n})];\nconst handlers = { event: {\n\tactivate: Effect.fn(\"Linear.event.activate\")(function* (input, context) {\n\t\tconst created = yield* mutation_webhookCreate.run({ payload: { input: {\n\t\t\tresourceTypes: Array.map(input.config.resources, String.capitalize),\n\t\t\tteamId: input.config.teamId,\n\t\t\turl: input.webhookUrl,\n\t\t\t...Option.match(Option.fromUndefinedOr(context.auth.current.value.signingSecret), {\n\t\t\t\tonNone: () => ({}),\n\t\t\t\tonSome: (secret) => ({ secret })\n\t\t\t})\n\t\t} } }, context);\n\t\tif (!created.success) return yield* Action.ActionHandlerError.make({ message: \"Linear did not register the webhook\" });\n\t\treturn { state: {\n\t\t\twebhookId: created.webhook.id,\n\t\t\t...Option.match(Option.fromNullishOr(created.webhook.secret), {\n\t\t\t\tonNone: () => ({}),\n\t\t\t\tonSome: (secret) => ({ secret })\n\t\t\t})\n\t\t} };\n\t}),\n\tdeactivate: Effect.fn(\"Linear.event.deactivate\")(function* (input, context) {\n\t\tif (input.state === void 0) return;\n\t\tif (!(yield* mutation_webhookDelete.run({ payload: { id: input.state.webhookId } }, context)).success) return yield* Action.ActionHandlerError.make({ message: \"Linear did not delete the webhook\" });\n\t}),\n\tparse: Effect.fn(\"Linear.event.parse\")(function* (input) {\n\t\tconst delivery = yield* Schema.decodeUnknownEffect(Delivery)({ body: input.request.body });\n\t\tconst matches = Array.some(input.config.resources, (resource) => String.capitalize(resource) === delivery.body.type);\n\t\tconst key = yield* Trigger.bodyDigest(input.request.rawBody ?? \"\");\n\t\treturn {\n\t\t\tevents: matches ? [{\n\t\t\t\tkey,\n\t\t\t\tpayload: delivery.body\n\t\t\t}] : [],\n\t\t\tstate: input.state\n\t\t};\n\t}),\n\tverify: Effect.fn(\"Linear.event.verify\")(function* (input, context) {\n\t\tconst secret = input.state?.secret ?? context.auth.current.value.signingSecret;\n\t\tif (secret === void 0) return yield* LinearSignatureError.make({});\n\t\tconst headers = input.request.headers ?? {};\n\t\tconst delivery = yield* Schema.decodeUnknownEffect(SignedDelivery)({\n\t\t\t...input.request,\n\t\t\theaders\n\t\t});\n\t\tconst signed = yield* Trigger.verifyHmacSha256(secret, delivery.rawBody, delivery.headers[\"linear-signature\"]);\n\t\tconst now = yield* Clock.currentTimeMillis;\n\t\tconst fresh = delivery.body.webhookTimestamp === void 0 || Number.between(delivery.body.webhookTimestamp, {\n\t\t\tmaximum: now + 6e4,\n\t\t\tminimum: now - 6e4\n\t\t});\n\t\tif (!signed || !fresh) return yield* LinearSignatureError.make({});\n\t})\n} };\n//#endregion\nexport { handlers, triggers };\n\n//# sourceMappingURL=triggers.js.map"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAI,uBAAuB,cAAc,aAAmB,EAAE,wBAAwB,CAAC,CAAC,EAAE;AAAC;AAC3F,IAAM,QAAQ,eAAsB,OAAc;AAAA,EACjD,QAAQ,YAAmB,OAAa;AAAA,EACxC,WAAW,YAAmB,OAAa;AAAA,EAC3C,MAAM,YAAmB,OAAc;AAAA,EACvC,gBAAgB,YAAmB,OAAa;AAAA,EAChD,MAAM,YAAmB,OAAa;AAAA,EACtC,aAAa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