@dual-os/linear-api 0.0.0-stage → 6.0.5
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 +29 -0
- package/README.md +36 -2
- package/Runner.js +5537 -0
- package/Runner.js.map +59 -0
- package/bundle-inventory.json +1 -0
- package/dist/_virtual/_rolldown/runtime.js +10 -0
- package/dist/_virtual/_rolldown/runtime.js.map +9 -0
- package/dist/auth.d.ts +51 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +19 -0
- package/dist/auth.js.map +9 -0
- package/dist/channel/internal/webhook.d.ts +96 -0
- package/dist/channel/internal/webhook.d.ts.map +1 -0
- package/dist/channel/internal/webhook.js +20 -0
- package/dist/channel/internal/webhook.js.map +9 -0
- package/dist/channel/linear-app-client.d.ts +54 -0
- package/dist/channel/linear-app-client.d.ts.map +1 -0
- package/dist/channel/linear-app-client.js +14 -0
- package/dist/channel/linear-app-client.js.map +9 -0
- package/dist/channel/linear-app-definition.d.ts +171 -0
- package/dist/channel/linear-app-definition.d.ts.map +1 -0
- package/dist/channel/linear-app-definition.js +18 -0
- package/dist/channel/linear-app-definition.js.map +9 -0
- package/dist/channel/linear-app.d.ts +65 -0
- package/dist/channel/linear-app.d.ts.map +1 -0
- package/dist/channel/linear-app.js +15 -0
- package/dist/channel/linear-app.js.map +9 -0
- package/dist/generated/http.d.ts +81 -0
- package/dist/generated/http.d.ts.map +1 -0
- package/dist/generated/http.js +66 -0
- package/dist/generated/http.js.map +9 -0
- package/dist/generated/operations.d.ts +14326 -0
- package/dist/generated/operations.d.ts.map +1 -0
- package/dist/generated/operations.js +3640 -0
- package/dist/generated/operations.js.map +9 -0
- package/dist/generated/plugin.d.ts +989 -0
- package/dist/generated/plugin.d.ts.map +1 -0
- package/dist/generated/plugin.js +20 -0
- package/dist/generated/plugin.js.map +9 -0
- package/dist/plugin.d.ts +4278 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +33 -0
- package/dist/plugin.js.map +10 -0
- package/dist/triggers.d.ts +211 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js +19 -0
- package/dist/triggers.js.map +9 -0
- package/dual-plugin.json +1 -0
- package/licenses/@dual-os_sdk@0.9.0/LICENSE +4 -0
- package/licenses/@effect_platform-node-shared@4.1.2/LICENSE +21 -0
- package/licenses/@effect_platform-node@4.1.2/LICENSE +21 -0
- package/licenses/effect@4.1.2/LICENSE +21 -0
- package/package.json +1 -6
- package/plugin-03c4ezxj.js +244 -0
- package/plugin-03c4ezxj.js.map +10 -0
- package/plugin-0pkez622.js +1257 -0
- package/plugin-0pkez622.js.map +17 -0
- package/plugin-292sech3.js +64 -0
- package/plugin-292sech3.js.map +10 -0
- package/plugin-2jdfj02n.js +18 -0
- package/plugin-2jdfj02n.js.map +10 -0
- package/plugin-5d2kw2pq.js +274 -0
- package/plugin-5d2kw2pq.js.map +10 -0
- package/plugin-9vdeenc2.js +19263 -0
- package/plugin-9vdeenc2.js.map +158 -0
- package/plugin-aaq7c99y.js +79 -0
- package/plugin-aaq7c99y.js.map +10 -0
- package/plugin-acwx0zjc.js +3615 -0
- package/plugin-acwx0zjc.js.map +10 -0
- package/plugin-c5xtmfce.js +81 -0
- package/plugin-c5xtmfce.js.map +10 -0
- package/plugin-evq9z31a.js +14513 -0
- package/plugin-evq9z31a.js.map +10 -0
- package/plugin-jgac4d6v.js +138 -0
- package/plugin-jgac4d6v.js.map +10 -0
- package/plugin-pbx41zqr.js +204 -0
- package/plugin-pbx41zqr.js.map +10 -0
- package/plugin.json +46 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
pipe,
|
|
4
|
+
match,
|
|
5
|
+
getOrElse,
|
|
6
|
+
orElse,
|
|
7
|
+
fromUndefinedOr,
|
|
8
|
+
map,
|
|
9
|
+
flatMap,
|
|
10
|
+
liftPredicate,
|
|
11
|
+
contains,
|
|
12
|
+
map3,
|
|
13
|
+
join,
|
|
14
|
+
provide,
|
|
15
|
+
slice,
|
|
16
|
+
isNonEmpty,
|
|
17
|
+
startsWith,
|
|
18
|
+
succeed4,
|
|
19
|
+
fail5,
|
|
20
|
+
fromOption2,
|
|
21
|
+
as,
|
|
22
|
+
mapError,
|
|
23
|
+
timeoutOrElse,
|
|
24
|
+
fn,
|
|
25
|
+
formatIso,
|
|
26
|
+
value2,
|
|
27
|
+
discriminatorsExhaustive,
|
|
28
|
+
layer2,
|
|
29
|
+
AgentChannel_exports,
|
|
30
|
+
Trigger_exports,
|
|
31
|
+
Plugin_exports
|
|
32
|
+
} from "./plugin-9vdeenc2.js";
|
|
33
|
+
import {
|
|
34
|
+
linearChannelBinding2
|
|
35
|
+
} from "./plugin-aaq7c99y.js";
|
|
36
|
+
import {
|
|
37
|
+
verifyWebhook2,
|
|
38
|
+
commentKey2,
|
|
39
|
+
commentOf2,
|
|
40
|
+
issueOf2,
|
|
41
|
+
webhookEvents2
|
|
42
|
+
} from "./plugin-pbx41zqr.js";
|
|
43
|
+
import {
|
|
44
|
+
LinearAppClient2
|
|
45
|
+
} from "./plugin-03c4ezxj.js";
|
|
46
|
+
|
|
47
|
+
// dist/channel/linear-app.js
|
|
48
|
+
var emoji = {
|
|
49
|
+
confused: "confused",
|
|
50
|
+
eyes: "eyes",
|
|
51
|
+
heart: "heart",
|
|
52
|
+
hooray: "tada",
|
|
53
|
+
laugh: "laughing",
|
|
54
|
+
rocket: "rocket",
|
|
55
|
+
thumbs_down: "-1",
|
|
56
|
+
thumbs_up: "+1"
|
|
57
|
+
};
|
|
58
|
+
var outcomeText = {
|
|
59
|
+
awaiting_input: "Waiting for your reply.",
|
|
60
|
+
completed: "Done.",
|
|
61
|
+
failed: "The work could not be finished."
|
|
62
|
+
};
|
|
63
|
+
var outcomeType = {
|
|
64
|
+
awaiting_input: "elicitation",
|
|
65
|
+
completed: "response",
|
|
66
|
+
failed: "error"
|
|
67
|
+
};
|
|
68
|
+
var stepStatus = {
|
|
69
|
+
completed: "completed",
|
|
70
|
+
failed: "canceled",
|
|
71
|
+
in_progress: "inProgress",
|
|
72
|
+
pending: "pending"
|
|
73
|
+
};
|
|
74
|
+
function rejected() {
|
|
75
|
+
return AgentChannel_exports.HandlerError.make({ code: "rejected" });
|
|
76
|
+
}
|
|
77
|
+
function unauthorized() {
|
|
78
|
+
return AgentChannel_exports.HandlerError.make({ code: "unauthorized" });
|
|
79
|
+
}
|
|
80
|
+
function installationKey(auth) {
|
|
81
|
+
return `${auth.organizationId}/${auth.appUserId}`;
|
|
82
|
+
}
|
|
83
|
+
function sameInstallation(state, auth) {
|
|
84
|
+
return state.organizationId === auth.organizationId && state.appUserId === auth.appUserId;
|
|
85
|
+
}
|
|
86
|
+
var stableId = fn("LinearApp.stableId")(function* (...parts) {
|
|
87
|
+
const hex = yield* Trigger_exports.bodyDigest(join(parts, `
|
|
88
|
+
`));
|
|
89
|
+
function part(start, end) {
|
|
90
|
+
return slice(start, end)(hex);
|
|
91
|
+
}
|
|
92
|
+
return `${part(0, 8)}-${part(8, 12)}-4${part(13, 16)}-8${part(17, 20)}-${part(20, 32)}`;
|
|
93
|
+
});
|
|
94
|
+
function checkAccess(identity, context) {
|
|
95
|
+
if (identity.conversation.kind === "group" && identity.conversation.threadKey !== undefined && (context.deploymentSettings.access === "open" || contains(context.deploymentSettings.allowedSenderKeys, identity.senderKey)))
|
|
96
|
+
return succeed4({ decision: "allow" });
|
|
97
|
+
return succeed4({ decision: "deny" });
|
|
98
|
+
}
|
|
99
|
+
function verify(request, context) {
|
|
100
|
+
return verifyWebhook2(request, context.auth.value.signingSecret);
|
|
101
|
+
}
|
|
102
|
+
function stepContent(item) {
|
|
103
|
+
const note = fromUndefinedOr(item.note);
|
|
104
|
+
if (item.state === "failed")
|
|
105
|
+
return match(note, {
|
|
106
|
+
onNone: () => `${item.title} (failed)`,
|
|
107
|
+
onSome: (reason) => `${item.title} (failed: ${reason})`
|
|
108
|
+
});
|
|
109
|
+
return match(note, {
|
|
110
|
+
onNone: () => item.title,
|
|
111
|
+
onSome: (detail) => `${item.title}: ${detail}`
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
var deliver = fn("LinearApp.deliver")(function* (command, context) {
|
|
115
|
+
const client = yield* LinearAppClient2;
|
|
116
|
+
const auth = context.auth.value;
|
|
117
|
+
const sessionId = command.destination.threadKey;
|
|
118
|
+
if (command.destination.kind !== "group" || sessionId === undefined)
|
|
119
|
+
return yield* rejected();
|
|
120
|
+
const activity = fn("LinearApp.activity")(function* (part, content, ephemeral, options) {
|
|
121
|
+
const id = yield* stableId("activity", command.deliveryKey, part);
|
|
122
|
+
yield* client.createActivity(auth.accessToken, {
|
|
123
|
+
agentSessionId: sessionId,
|
|
124
|
+
content,
|
|
125
|
+
ephemeral,
|
|
126
|
+
id,
|
|
127
|
+
options
|
|
128
|
+
});
|
|
129
|
+
return id;
|
|
130
|
+
});
|
|
131
|
+
const reaction = fn("LinearApp.reaction")(function* (operation) {
|
|
132
|
+
if (operation.target.kind === "message")
|
|
133
|
+
return yield* rejected();
|
|
134
|
+
const comment = flatMap(fromUndefinedOr(command.activationMessageKey), commentOf2);
|
|
135
|
+
const target = yield* pipe(map(comment, (commentId) => ({ commentId })), orElse(() => map(issueOf2(command.destination), (issueId) => ({ issueId }))), fromOption2, mapError(rejected));
|
|
136
|
+
const id = yield* stableId("reaction", auth.appUserId, getOrElse(comment, () => command.destination.conversationKey), operation.reaction);
|
|
137
|
+
yield* client.setReaction(auth.accessToken, {
|
|
138
|
+
active: operation.active,
|
|
139
|
+
emoji: emoji[operation.reaction],
|
|
140
|
+
id,
|
|
141
|
+
target
|
|
142
|
+
});
|
|
143
|
+
return id;
|
|
144
|
+
});
|
|
145
|
+
const providerDeliveryKey = yield* pipe(value2(command.operation), discriminatorsExhaustive("kind")({
|
|
146
|
+
create_message: (operation) => activity(`message/${operation.messageKey}`, {
|
|
147
|
+
body: operation.text,
|
|
148
|
+
type: "thought"
|
|
149
|
+
}, false, []),
|
|
150
|
+
delete_message: () => fail5(rejected()),
|
|
151
|
+
present_outcome: (operation) => activity("outcome", {
|
|
152
|
+
body: pipe(liftPredicate(operation.text, isNonEmpty), getOrElse(() => outcomeText[operation.outcome])),
|
|
153
|
+
type: outcomeType[operation.outcome]
|
|
154
|
+
}, false, operation.options ?? []),
|
|
155
|
+
render_plan: (operation) => as(client.setPlan(auth.accessToken, sessionId, map3(operation.plan.items, (item) => ({
|
|
156
|
+
content: stepContent(item),
|
|
157
|
+
status: stepStatus[item.state]
|
|
158
|
+
}))), `plan/${sessionId}`),
|
|
159
|
+
set_activity: (operation) => pipe(value2(operation.activity), discriminatorsExhaustive("kind")({
|
|
160
|
+
idle: () => activity("idle", {
|
|
161
|
+
body: "Work has ended.",
|
|
162
|
+
type: "response"
|
|
163
|
+
}, false, []),
|
|
164
|
+
working: (working) => activity("activity", {
|
|
165
|
+
body: working.text ?? "Working on it\u2026",
|
|
166
|
+
type: "thought"
|
|
167
|
+
}, true, [])
|
|
168
|
+
})),
|
|
169
|
+
set_reaction: reaction,
|
|
170
|
+
update_message: () => fail5(rejected())
|
|
171
|
+
}));
|
|
172
|
+
return {
|
|
173
|
+
deliveryKey: command.deliveryKey,
|
|
174
|
+
kind: "deliver",
|
|
175
|
+
operationKey: command.operationKey,
|
|
176
|
+
providerDeliveryKey,
|
|
177
|
+
status: "succeeded"
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
var readContext = fn("LinearApp.readContext")(function* (command, auth) {
|
|
181
|
+
const client = yield* LinearAppClient2;
|
|
182
|
+
const comments = yield* match(issueOf2(command.destination), {
|
|
183
|
+
onNone: () => succeed4([]),
|
|
184
|
+
onSome: (issueId) => client.issueComments(auth.accessToken, issueId, command.limit)
|
|
185
|
+
});
|
|
186
|
+
return AgentChannel_exports.contextResult(command.operationKey, map3(comments, (comment) => ({
|
|
187
|
+
messageKey: commentKey2(comment.id),
|
|
188
|
+
own: comment.user.id === auth.appUserId,
|
|
189
|
+
senderKey: comment.user.id,
|
|
190
|
+
...match(liftPredicate(comment.user.name, isNonEmpty), {
|
|
191
|
+
onNone: () => ({}),
|
|
192
|
+
onSome: (name) => ({ senderName: slice(0, 256)(name) })
|
|
193
|
+
}),
|
|
194
|
+
text: slice(0, 65536)(comment.body),
|
|
195
|
+
timestamp: formatIso(comment.createdAt)
|
|
196
|
+
})));
|
|
197
|
+
});
|
|
198
|
+
var receive = fn("LinearApp.receive")(function* (command, context) {
|
|
199
|
+
const auth = context.auth.value;
|
|
200
|
+
const events = yield* webhookEvents2(command.request.body, auth, context.deploymentSettings.teamIds);
|
|
201
|
+
for (const event of events)
|
|
202
|
+
if (event.kind === "message" && startsWith("session/")(event.eventKey)) {
|
|
203
|
+
const access = yield* checkAccess(event, context);
|
|
204
|
+
const sessionId = event.conversation.threadKey;
|
|
205
|
+
if (access.decision === "allow" && sessionId !== undefined) {
|
|
206
|
+
const client = yield* LinearAppClient2;
|
|
207
|
+
const id = yield* stableId("acknowledgement", installationKey(auth), sessionId);
|
|
208
|
+
yield* pipe(client.createActivity(auth.accessToken, {
|
|
209
|
+
agentSessionId: sessionId,
|
|
210
|
+
content: {
|
|
211
|
+
body: "Received your request.",
|
|
212
|
+
type: "thought"
|
|
213
|
+
},
|
|
214
|
+
ephemeral: true,
|
|
215
|
+
id,
|
|
216
|
+
options: []
|
|
217
|
+
}), timeoutOrElse({
|
|
218
|
+
duration: "3 seconds",
|
|
219
|
+
orElse: () => fail5(AgentChannel_exports.HandlerError.make({ code: "unavailable" }))
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
events,
|
|
225
|
+
kind: "receive",
|
|
226
|
+
operationKey: command.operationKey,
|
|
227
|
+
response: {
|
|
228
|
+
body: "",
|
|
229
|
+
status: 200
|
|
230
|
+
},
|
|
231
|
+
verified: true
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
var execute = fn("LinearApp.execute")(function* (command, context) {
|
|
235
|
+
const auth = context.auth.value;
|
|
236
|
+
if (command.kind === "activate") {
|
|
237
|
+
if (command.state !== undefined && !sameInstallation(command.state, auth))
|
|
238
|
+
return yield* unauthorized();
|
|
239
|
+
const viewer = yield* (yield* LinearAppClient2).viewer(auth.accessToken);
|
|
240
|
+
if (viewer.appUserId !== auth.appUserId || viewer.organizationId !== auth.organizationId)
|
|
241
|
+
return yield* unauthorized();
|
|
242
|
+
return {
|
|
243
|
+
installationKey: installationKey(auth),
|
|
244
|
+
kind: "activate",
|
|
245
|
+
operationKey: command.operationKey,
|
|
246
|
+
state: {
|
|
247
|
+
appUserId: auth.appUserId,
|
|
248
|
+
ingressUrl: command.ingressUrl,
|
|
249
|
+
organizationId: auth.organizationId
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (command.installationKey !== installationKey(auth) || !sameInstallation(command.state, auth))
|
|
254
|
+
return yield* unauthorized();
|
|
255
|
+
return yield* pipe(value2(command), discriminatorsExhaustive("kind")({
|
|
256
|
+
deactivate: (deactivate) => succeed4({
|
|
257
|
+
kind: "deactivate",
|
|
258
|
+
operationKey: deactivate.operationKey
|
|
259
|
+
}),
|
|
260
|
+
deliver: (delivery) => deliver(delivery, context),
|
|
261
|
+
read_asset: () => fail5(rejected()),
|
|
262
|
+
read_context: (read) => readContext(read, auth),
|
|
263
|
+
receive: (incoming) => receive(incoming, context)
|
|
264
|
+
}));
|
|
265
|
+
});
|
|
266
|
+
var linearChannelLayer2 = Plugin_exports.toLayer(linearChannelBinding2, (handlers) => handlers.channel("agent-session", {
|
|
267
|
+
checkAccess,
|
|
268
|
+
execute,
|
|
269
|
+
verify
|
|
270
|
+
})).pipe(provide(LinearAppClient2.layer), provide(layer2));
|
|
271
|
+
export { linearChannelLayer2 };
|
|
272
|
+
|
|
273
|
+
//# debugId=80ACCF818D422E7F64756E2164756E21
|
|
274
|
+
//# sourceMappingURL=plugin-5d2kw2pq.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../bundle-input/dist/channel/linear-app.js"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { linearChannelBinding } from \"./linear-app-definition.js\";\nimport { commentKey, commentOf, issueOf, verifyWebhook, webhookEvents } from \"./internal/webhook.js\";\nimport { LinearAppClient } from \"./linear-app-client.js\";\nimport { Array, DateTime, Effect, Layer, Match, Option, String, pipe } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { AgentChannel, Plugin, Trigger } from \"@dual-os/sdk\";\n//#region src/channel/linear-app.ts\n/** Linear's emoji name for each portable reaction. */\nconst emoji = {\n\tconfused: \"confused\",\n\teyes: \"eyes\",\n\theart: \"heart\",\n\thooray: \"tada\",\n\tlaugh: \"laughing\",\n\trocket: \"rocket\",\n\tthumbs_down: \"-1\",\n\tthumbs_up: \"+1\"\n};\n/** Linear requires a body, so an outcome sent without text says what happened. */\nconst outcomeText = {\n\tawaiting_input: \"Waiting for your reply.\",\n\tcompleted: \"Done.\",\n\tfailed: \"The work could not be finished.\"\n};\nconst outcomeType = {\n\tawaiting_input: \"elicitation\",\n\tcompleted: \"response\",\n\tfailed: \"error\"\n};\n/** Linear has no failed plan step: a failed item is canceled and says so. */\nconst stepStatus = {\n\tcompleted: \"completed\",\n\tfailed: \"canceled\",\n\tin_progress: \"inProgress\",\n\tpending: \"pending\"\n};\nfunction rejected() {\n\treturn AgentChannel.HandlerError.make({ code: \"rejected\" });\n}\nfunction unauthorized() {\n\treturn AgentChannel.HandlerError.make({ code: \"unauthorized\" });\n}\nfunction installationKey(auth) {\n\treturn `${auth.organizationId}/${auth.appUserId}`;\n}\nfunction sameInstallation(state, auth) {\n\treturn state.organizationId === auth.organizationId && state.appUserId === auth.appUserId;\n}\n/** A UUID v4 that the same parts always give, so a retried request reuses its Linear ID. */\nconst stableId = Effect.fn(\"LinearApp.stableId\")(function* (...parts) {\n\tconst hex = yield* Trigger.bodyDigest(Array.join(parts, \"\\n\"));\n\tfunction part(start, end) {\n\t\treturn String.slice(start, end)(hex);\n\t}\n\treturn `${part(0, 8)}-${part(8, 12)}-4${part(13, 16)}-8${part(17, 20)}-${part(20, 32)}`;\n});\nfunction checkAccess(identity, context) {\n\tif (identity.conversation.kind === \"group\" && identity.conversation.threadKey !== void 0 && (context.deploymentSettings.access === \"open\" || Array.contains(context.deploymentSettings.allowedSenderKeys, identity.senderKey))) return Effect.succeed({ decision: \"allow\" });\n\treturn Effect.succeed({ decision: \"deny\" });\n}\nfunction verify(request, context) {\n\treturn verifyWebhook(request, context.auth.value.signingSecret);\n}\nfunction stepContent(item) {\n\tconst note = Option.fromUndefinedOr(item.note);\n\tif (item.state === \"failed\") return Option.match(note, {\n\t\tonNone: () => `${item.title} (failed)`,\n\t\tonSome: (reason) => `${item.title} (failed: ${reason})`\n\t});\n\treturn Option.match(note, {\n\t\tonNone: () => item.title,\n\t\tonSome: (detail) => `${item.title}: ${detail}`\n\t});\n}\n/** Send one operation to the session the destination's thread names; IDs make retries safe. */\nconst deliver = Effect.fn(\"LinearApp.deliver\")(function* (command, context) {\n\tconst client = yield* LinearAppClient;\n\tconst auth = context.auth.value;\n\tconst sessionId = command.destination.threadKey;\n\tif (command.destination.kind !== \"group\" || sessionId === void 0) return yield* rejected();\n\tconst activity = Effect.fn(\"LinearApp.activity\")(function* (part, content, ephemeral, options) {\n\t\tconst id = yield* stableId(\"activity\", command.deliveryKey, part);\n\t\tyield* client.createActivity(auth.accessToken, {\n\t\t\tagentSessionId: sessionId,\n\t\t\tcontent,\n\t\t\tephemeral,\n\t\t\tid,\n\t\t\toptions\n\t\t});\n\t\treturn id;\n\t});\n\tconst reaction = Effect.fn(\"LinearApp.reaction\")(function* (operation) {\n\t\tif (operation.target.kind === \"message\") return yield* rejected();\n\t\tconst comment = Option.flatMap(Option.fromUndefinedOr(command.activationMessageKey), commentOf);\n\t\tconst target = yield* pipe(Option.map(comment, (commentId) => ({ commentId })), Option.orElse(() => Option.map(issueOf(command.destination), (issueId) => ({ issueId }))), Effect.fromOption, Effect.mapError(rejected));\n\t\tconst id = yield* stableId(\"reaction\", auth.appUserId, Option.getOrElse(comment, () => command.destination.conversationKey), operation.reaction);\n\t\tyield* client.setReaction(auth.accessToken, {\n\t\t\tactive: operation.active,\n\t\t\temoji: emoji[operation.reaction],\n\t\t\tid,\n\t\t\ttarget\n\t\t});\n\t\treturn id;\n\t});\n\tconst providerDeliveryKey = yield* pipe(Match.value(command.operation), Match.discriminatorsExhaustive(\"kind\")({\n\t\tcreate_message: (operation) => activity(`message/${operation.messageKey}`, {\n\t\t\tbody: operation.text,\n\t\t\ttype: \"thought\"\n\t\t}, false, []),\n\t\tdelete_message: () => Effect.fail(rejected()),\n\t\tpresent_outcome: (operation) => activity(\"outcome\", {\n\t\t\tbody: pipe(Option.liftPredicate(operation.text, String.isNonEmpty), Option.getOrElse(() => outcomeText[operation.outcome])),\n\t\t\ttype: outcomeType[operation.outcome]\n\t\t}, false, operation.options ?? []),\n\t\trender_plan: (operation) => Effect.as(client.setPlan(auth.accessToken, sessionId, Array.map(operation.plan.items, (item) => ({\n\t\t\tcontent: stepContent(item),\n\t\t\tstatus: stepStatus[item.state]\n\t\t}))), `plan/${sessionId}`),\n\t\tset_activity: (operation) => pipe(Match.value(operation.activity), Match.discriminatorsExhaustive(\"kind\")({\n\t\t\tidle: () => activity(\"idle\", {\n\t\t\t\tbody: \"Work has ended.\",\n\t\t\t\ttype: \"response\"\n\t\t\t}, false, []),\n\t\t\tworking: (working) => activity(\"activity\", {\n\t\t\t\tbody: working.text ?? \"Working on it…\",\n\t\t\t\ttype: \"thought\"\n\t\t\t}, true, [])\n\t\t})),\n\t\tset_reaction: reaction,\n\t\tupdate_message: () => Effect.fail(rejected())\n\t}));\n\treturn {\n\t\tdeliveryKey: command.deliveryKey,\n\t\tkind: \"deliver\",\n\t\toperationKey: command.operationKey,\n\t\tproviderDeliveryKey,\n\t\tstatus: \"succeeded\"\n\t};\n});\nconst readContext = Effect.fn(\"LinearApp.readContext\")(function* (command, auth) {\n\tconst client = yield* LinearAppClient;\n\tconst comments = yield* Option.match(issueOf(command.destination), {\n\t\tonNone: () => Effect.succeed([]),\n\t\tonSome: (issueId) => client.issueComments(auth.accessToken, issueId, command.limit)\n\t});\n\treturn AgentChannel.contextResult(command.operationKey, Array.map(comments, (comment) => ({\n\t\tmessageKey: commentKey(comment.id),\n\t\town: comment.user.id === auth.appUserId,\n\t\tsenderKey: comment.user.id,\n\t\t...Option.match(Option.liftPredicate(comment.user.name, String.isNonEmpty), {\n\t\t\tonNone: () => ({}),\n\t\t\tonSome: (name) => ({ senderName: String.slice(0, 256)(name) })\n\t\t}),\n\t\ttext: String.slice(0, 65536)(comment.body),\n\t\ttimestamp: DateTime.formatIso(comment.createdAt)\n\t})));\n});\n/** Acknowledge allowed session starts before Run promotion or worker scheduling. */\nconst receive = Effect.fn(\"LinearApp.receive\")(function* (command, context) {\n\tconst auth = context.auth.value;\n\tconst events = yield* webhookEvents(command.request.body, auth, context.deploymentSettings.teamIds);\n\tfor (const event of events) if (event.kind === \"message\" && String.startsWith(\"session/\")(event.eventKey)) {\n\t\tconst access = yield* checkAccess(event, context);\n\t\tconst sessionId = event.conversation.threadKey;\n\t\tif (access.decision === \"allow\" && sessionId !== void 0) {\n\t\t\tconst client = yield* LinearAppClient;\n\t\t\tconst id = yield* stableId(\"acknowledgement\", installationKey(auth), sessionId);\n\t\t\tyield* pipe(client.createActivity(auth.accessToken, {\n\t\t\t\tagentSessionId: sessionId,\n\t\t\t\tcontent: {\n\t\t\t\t\tbody: \"Received your request.\",\n\t\t\t\t\ttype: \"thought\"\n\t\t\t\t},\n\t\t\t\tephemeral: true,\n\t\t\t\tid,\n\t\t\t\toptions: []\n\t\t\t}), Effect.timeoutOrElse({\n\t\t\t\tduration: \"3 seconds\",\n\t\t\t\torElse: () => Effect.fail(AgentChannel.HandlerError.make({ code: \"unavailable\" }))\n\t\t\t}));\n\t\t}\n\t}\n\treturn {\n\t\tevents,\n\t\tkind: \"receive\",\n\t\toperationKey: command.operationKey,\n\t\tresponse: {\n\t\t\tbody: \"\",\n\t\t\tstatus: 200\n\t\t},\n\t\tverified: true\n\t};\n});\nconst execute = Effect.fn(\"LinearApp.execute\")(function* (command, context) {\n\tconst auth = context.auth.value;\n\tif (command.kind === \"activate\") {\n\t\tif (command.state !== void 0 && !sameInstallation(command.state, auth)) return yield* unauthorized();\n\t\tconst viewer = yield* (yield* LinearAppClient).viewer(auth.accessToken);\n\t\tif (viewer.appUserId !== auth.appUserId || viewer.organizationId !== auth.organizationId) return yield* unauthorized();\n\t\treturn {\n\t\t\tinstallationKey: installationKey(auth),\n\t\t\tkind: \"activate\",\n\t\t\toperationKey: command.operationKey,\n\t\t\tstate: {\n\t\t\t\tappUserId: auth.appUserId,\n\t\t\t\tingressUrl: command.ingressUrl,\n\t\t\t\torganizationId: auth.organizationId\n\t\t\t}\n\t\t};\n\t}\n\tif (command.installationKey !== installationKey(auth) || !sameInstallation(command.state, auth)) return yield* unauthorized();\n\treturn yield* pipe(Match.value(command), Match.discriminatorsExhaustive(\"kind\")({\n\t\tdeactivate: (deactivate) => Effect.succeed({\n\t\t\tkind: \"deactivate\",\n\t\t\toperationKey: deactivate.operationKey\n\t\t}),\n\t\tdeliver: (delivery) => deliver(delivery, context),\n\t\tread_asset: () => Effect.fail(rejected()),\n\t\tread_context: (read) => readContext(read, auth),\n\t\treceive: (incoming) => receive(incoming, context)\n\t}));\n});\nconst linearChannelLayer = Plugin.toLayer(linearChannelBinding, (handlers) => handlers.channel(\"agent-session\", {\n\tcheckAccess,\n\texecute,\n\tverify\n})).pipe(Layer.provide(LinearAppClient.layer), Layer.provide(FetchHttpClient.layer));\n//#endregion\nexport { linearChannelLayer };\n\n//# sourceMappingURL=linear-app.js.map"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAM,QAAQ;AAA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