@sjawhar/pi-legion-envoy 1.51.2 → 1.53.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/dist/envoy.js +107 -20
- package/dist/legion.js +49 -3
- package/package.json +1 -1
package/dist/envoy.js
CHANGED
|
@@ -29726,6 +29726,24 @@ var AskEditedEventPayloadSchema = object({
|
|
|
29726
29726
|
}),
|
|
29727
29727
|
edited_by: object({ kind: string2(), id: string2() }).passthrough()
|
|
29728
29728
|
});
|
|
29729
|
+
var CommentMentionSchema = object({
|
|
29730
|
+
target: string2(),
|
|
29731
|
+
delivery: _enum2(DELIVERY_CAPABILITIES),
|
|
29732
|
+
session_id: string2().nullable()
|
|
29733
|
+
});
|
|
29734
|
+
var CommentDeliverySchema = object({
|
|
29735
|
+
comment_id: string2(),
|
|
29736
|
+
target: string2(),
|
|
29737
|
+
attempt: number2().int().positive(),
|
|
29738
|
+
delivery: _enum2(DELIVERY_CAPABILITIES),
|
|
29739
|
+
session_id: string2().nullable(),
|
|
29740
|
+
envelope_id: string2().nullable(),
|
|
29741
|
+
state: _enum2(["pending", "sent", "failed"]),
|
|
29742
|
+
error: string2().nullable(),
|
|
29743
|
+
resolve_error: string2().nullable(),
|
|
29744
|
+
reply_id: string2().nullable(),
|
|
29745
|
+
created_at: string2()
|
|
29746
|
+
});
|
|
29729
29747
|
var CommentEventPayloadSchema = object({
|
|
29730
29748
|
id: string2().optional(),
|
|
29731
29749
|
artifact_name: string2().optional(),
|
|
@@ -29741,7 +29759,9 @@ var CommentEventPayloadSchema = object({
|
|
|
29741
29759
|
anchor: object({ block_id: string2().nullable().optional(), quote: string2().optional() }).nullish(),
|
|
29742
29760
|
suggestion: object({ replace_with: string2().optional() }).nullish(),
|
|
29743
29761
|
author: object({ kind: string2(), id: string2() }).optional(),
|
|
29744
|
-
created_at: string2().optional()
|
|
29762
|
+
created_at: string2().optional(),
|
|
29763
|
+
mentions: array(CommentMentionSchema).optional(),
|
|
29764
|
+
deliveries: array(CommentDeliverySchema).optional()
|
|
29745
29765
|
});
|
|
29746
29766
|
var MessageEventPayloadSchema = object({
|
|
29747
29767
|
id: string2().optional(),
|
|
@@ -29751,8 +29771,9 @@ var MessageEventPayloadSchema = object({
|
|
|
29751
29771
|
reply_body: string2().optional(),
|
|
29752
29772
|
author: object({ kind: string2(), id: string2() }).optional()
|
|
29753
29773
|
});
|
|
29774
|
+
var DispatchTargetedResourceIDSchema = uuid2();
|
|
29754
29775
|
var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
|
|
29755
|
-
id:
|
|
29776
|
+
id: DispatchTargetedResourceIDSchema,
|
|
29756
29777
|
issue_key: string2().nullable(),
|
|
29757
29778
|
author: object({ kind: string2(), id: string2() }),
|
|
29758
29779
|
body: string2(),
|
|
@@ -29761,6 +29782,31 @@ var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
|
|
|
29761
29782
|
deliveries: array(unknown()),
|
|
29762
29783
|
created_at: string2()
|
|
29763
29784
|
});
|
|
29785
|
+
var DispatchTargetedCommentPayloadSchema = CommentEventPayloadSchema.extend({
|
|
29786
|
+
id: DispatchTargetedResourceIDSchema,
|
|
29787
|
+
issue_key: string2().nullable(),
|
|
29788
|
+
artifact_id: string2().nullable(),
|
|
29789
|
+
author: object({ kind: string2(), id: string2() }),
|
|
29790
|
+
body: string2(),
|
|
29791
|
+
reply_to: string2().nullable(),
|
|
29792
|
+
ask_id: string2().nullable(),
|
|
29793
|
+
mentions: array(CommentMentionSchema),
|
|
29794
|
+
deliveries: array(CommentDeliverySchema),
|
|
29795
|
+
created_at: string2(),
|
|
29796
|
+
artifact_name: string2()
|
|
29797
|
+
});
|
|
29798
|
+
var DispatchTargetedMessageDeliverySchema = object({
|
|
29799
|
+
attempt: number2().int().positive(),
|
|
29800
|
+
mode: _enum2(DELIVERY_CAPABILITIES)
|
|
29801
|
+
});
|
|
29802
|
+
var DispatchTargetedCommentDeliverySchema = DispatchTargetedMessageDeliverySchema.extend({
|
|
29803
|
+
comment_id: DispatchTargetedResourceIDSchema,
|
|
29804
|
+
target: string2()
|
|
29805
|
+
});
|
|
29806
|
+
var DispatchTargetedDeliverySchema = union([
|
|
29807
|
+
DispatchTargetedCommentDeliverySchema,
|
|
29808
|
+
DispatchTargetedMessageDeliverySchema
|
|
29809
|
+
]);
|
|
29764
29810
|
var MessageDeliveryEventPayloadSchema = object({
|
|
29765
29811
|
message_id: string2().optional(),
|
|
29766
29812
|
attempt: number2().int().positive().optional(),
|
|
@@ -31327,13 +31373,18 @@ var TolerantInboundEnvelopeSchema = object({
|
|
|
31327
31373
|
source: InboundEnvelopeSchema.shape.source.optional().catch(undefined),
|
|
31328
31374
|
sender: object(tolerantShape(InboundSenderSchema.shape)).optional().catch(undefined)
|
|
31329
31375
|
}).passthrough();
|
|
31376
|
+
function dispatchReplyPath(resource, id) {
|
|
31377
|
+
const collection = resource === "message" ? "messages" : "comments";
|
|
31378
|
+
return `/api/v1/${collection}/${encodeURIComponent(id)}/reply`;
|
|
31379
|
+
}
|
|
31330
31380
|
async function postDeliveryReply(config, sessionId, delivery, result) {
|
|
31331
|
-
const response = await fetch(`${config.url}
|
|
31381
|
+
const response = await fetch(`${config.url}${dispatchReplyPath(delivery.resource, delivery.id)}`, {
|
|
31332
31382
|
method: "POST",
|
|
31333
31383
|
headers: { Authorization: `Bearer ${config.token}`, "Content-Type": "application/json" },
|
|
31334
31384
|
body: JSON.stringify({
|
|
31335
31385
|
actor: { kind: "session", id: sessionId },
|
|
31336
31386
|
attempt: delivery.attempt,
|
|
31387
|
+
...delivery.replyFields,
|
|
31337
31388
|
...result
|
|
31338
31389
|
})
|
|
31339
31390
|
});
|
|
@@ -31352,21 +31403,32 @@ function rememberBounded(seen, key, limit) {
|
|
|
31352
31403
|
seen.delete(oldest.value);
|
|
31353
31404
|
}
|
|
31354
31405
|
}
|
|
31355
|
-
|
|
31356
|
-
|
|
31357
|
-
|
|
31358
|
-
});
|
|
31406
|
+
function isCommentTargetedDelivery(delivery) {
|
|
31407
|
+
return "comment_id" in delivery;
|
|
31408
|
+
}
|
|
31359
31409
|
var DispatchTargetedFrameSchema = object({
|
|
31360
31410
|
event: DispatchEventSchema,
|
|
31361
|
-
delivery:
|
|
31362
|
-
}).
|
|
31411
|
+
delivery: DispatchTargetedDeliverySchema
|
|
31412
|
+
}).superRefine(({ event, delivery }, context) => {
|
|
31413
|
+
if (event.type === "message.created" && !isCommentTargetedDelivery(delivery) && DispatchTargetedMessagePayloadSchema.safeParse(event.payload).success) {
|
|
31414
|
+
return;
|
|
31415
|
+
}
|
|
31416
|
+
if (event.type === "comment.created" && isCommentTargetedDelivery(delivery) && DispatchTargetedCommentPayloadSchema.safeParse(event.payload).success) {
|
|
31417
|
+
return;
|
|
31418
|
+
}
|
|
31419
|
+
context.addIssue({
|
|
31420
|
+
code: "custom",
|
|
31421
|
+
message: event.type === "comment.created" ? "targeted delivery requires a complete comment.created event" : "targeted delivery requires a complete message.created event"
|
|
31422
|
+
});
|
|
31423
|
+
});
|
|
31363
31424
|
var RecoverableDispatchDeliveryFailureSchema = object({
|
|
31364
31425
|
event: object({
|
|
31426
|
+
type: _enum2(["message.created", "comment.created"]),
|
|
31365
31427
|
issue_key: string2().nullable(),
|
|
31366
31428
|
payload: object({ id: string2(), body: string2().optional() }).passthrough()
|
|
31367
31429
|
}).passthrough(),
|
|
31368
|
-
delivery:
|
|
31369
|
-
});
|
|
31430
|
+
delivery: DispatchTargetedDeliverySchema
|
|
31431
|
+
}).refine(({ event, delivery }) => event.type === "comment.created" ? isCommentTargetedDelivery(delivery) : !isCommentTargetedDelivery(delivery) && DispatchTargetedResourceIDSchema.safeParse(event.payload.id).success, { message: "delivery resource must match its event type" });
|
|
31370
31432
|
function senderLabel(envelope) {
|
|
31371
31433
|
const sender = envelope.source_session ?? envelope.source ?? "unknown";
|
|
31372
31434
|
return envelope.sender?.title === undefined ? sender : `${sender} (${envelope.sender.title})`;
|
|
@@ -31511,12 +31573,19 @@ function parseDispatchFrame(rawPayload) {
|
|
|
31511
31573
|
}
|
|
31512
31574
|
const recoverable = RecoverableDispatchDeliveryFailureSchema.safeParse(value);
|
|
31513
31575
|
if (recoverable.success) {
|
|
31576
|
+
const delivery = recoverable.data.delivery;
|
|
31577
|
+
const commentDelivery = isCommentTargetedDelivery(delivery);
|
|
31578
|
+
const resource = commentDelivery ? "comment" : "message";
|
|
31579
|
+
const id = commentDelivery ? delivery.comment_id : recoverable.data.event.payload.id;
|
|
31514
31580
|
return {
|
|
31515
31581
|
raw: value,
|
|
31516
31582
|
rejectedDelivery: {
|
|
31517
|
-
|
|
31518
|
-
|
|
31519
|
-
|
|
31583
|
+
resource,
|
|
31584
|
+
id,
|
|
31585
|
+
attempt: delivery.attempt,
|
|
31586
|
+
mode: delivery.mode,
|
|
31587
|
+
replyPath: dispatchReplyPath(resource, id),
|
|
31588
|
+
replyFields: commentDelivery ? { target: delivery.target } : {},
|
|
31520
31589
|
issueKey: recoverable.data.event.issue_key,
|
|
31521
31590
|
body: recoverable.data.event.payload.body ?? ""
|
|
31522
31591
|
},
|
|
@@ -31633,15 +31702,18 @@ function renderInbound(raw, sessionID, subject) {
|
|
|
31633
31702
|
}
|
|
31634
31703
|
dispatchReply = dispatchCommentReplyWith(frame.event, topic, commentPayload);
|
|
31635
31704
|
if (frame.event.type === "message.created") {
|
|
31636
|
-
const message =
|
|
31637
|
-
const requested =
|
|
31638
|
-
if (message.success && requested.success &&
|
|
31705
|
+
const message = DispatchTargetedMessagePayloadSchema.safeParse(frame.event.payload);
|
|
31706
|
+
const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
|
|
31707
|
+
if (message.success && requested.success && !isCommentTargetedDelivery(requested.data)) {
|
|
31639
31708
|
delivery = {
|
|
31709
|
+
resource: "message",
|
|
31710
|
+
id: message.data.id,
|
|
31640
31711
|
attempt: requested.data.attempt,
|
|
31641
31712
|
mode: requested.data.mode,
|
|
31642
|
-
|
|
31713
|
+
replyPath: dispatchReplyPath("message", message.data.id),
|
|
31714
|
+
replyFields: {},
|
|
31643
31715
|
issueKey: frame.event.issue_key,
|
|
31644
|
-
body: message.data.body
|
|
31716
|
+
body: message.data.body
|
|
31645
31717
|
};
|
|
31646
31718
|
if (frame.event.issue_key !== null) {
|
|
31647
31719
|
dispatchReply = {
|
|
@@ -31650,6 +31722,21 @@ function renderInbound(raw, sessionID, subject) {
|
|
|
31650
31722
|
};
|
|
31651
31723
|
}
|
|
31652
31724
|
}
|
|
31725
|
+
} else if (frame.event.type === "comment.created") {
|
|
31726
|
+
const comment = DispatchTargetedCommentPayloadSchema.safeParse(frame.event.payload);
|
|
31727
|
+
const requested = DispatchTargetedDeliverySchema.safeParse(frame.delivery);
|
|
31728
|
+
if (comment.success && requested.success && isCommentTargetedDelivery(requested.data)) {
|
|
31729
|
+
delivery = {
|
|
31730
|
+
resource: "comment",
|
|
31731
|
+
id: requested.data.comment_id,
|
|
31732
|
+
attempt: requested.data.attempt,
|
|
31733
|
+
mode: requested.data.mode,
|
|
31734
|
+
replyPath: dispatchReplyPath("comment", requested.data.comment_id),
|
|
31735
|
+
replyFields: { target: requested.data.target },
|
|
31736
|
+
issueKey: frame.event.issue_key,
|
|
31737
|
+
body: comment.data.body
|
|
31738
|
+
};
|
|
31739
|
+
}
|
|
31653
31740
|
}
|
|
31654
31741
|
dispatchEvent = {
|
|
31655
31742
|
owner: dispatchOwner(frame.event, topic),
|
|
@@ -34470,7 +34557,7 @@ function envoyExtension(pi) {
|
|
|
34470
34557
|
}
|
|
34471
34558
|
try {
|
|
34472
34559
|
if (rendered.rejectedDelivery !== undefined) {
|
|
34473
|
-
console.warn(`[envoy] rejecting malformed Dispatch targeted delivery ${rendered.rejectedDelivery.
|
|
34560
|
+
console.warn(`[envoy] rejecting malformed Dispatch targeted delivery ${rendered.rejectedDelivery.id}`);
|
|
34474
34561
|
await postDispatchReply(rendered.rejectedDelivery, {
|
|
34475
34562
|
error: "Invalid Dispatch targeted delivery frame"
|
|
34476
34563
|
});
|
package/dist/legion.js
CHANGED
|
@@ -16145,7 +16145,7 @@ import { logger } from "@oh-my-pi/pi-utils";
|
|
|
16145
16145
|
// package.json
|
|
16146
16146
|
var package_default = {
|
|
16147
16147
|
name: "@sjawhar/pi-legion-envoy",
|
|
16148
|
-
version: "1.
|
|
16148
|
+
version: "1.53.0",
|
|
16149
16149
|
type: "module",
|
|
16150
16150
|
omp: {
|
|
16151
16151
|
extensions: [
|
|
@@ -29045,6 +29045,24 @@ var AskEditedEventPayloadSchema = object({
|
|
|
29045
29045
|
}),
|
|
29046
29046
|
edited_by: object({ kind: string2(), id: string2() }).passthrough()
|
|
29047
29047
|
});
|
|
29048
|
+
var CommentMentionSchema = object({
|
|
29049
|
+
target: string2(),
|
|
29050
|
+
delivery: _enum2(DELIVERY_CAPABILITIES),
|
|
29051
|
+
session_id: string2().nullable()
|
|
29052
|
+
});
|
|
29053
|
+
var CommentDeliverySchema = object({
|
|
29054
|
+
comment_id: string2(),
|
|
29055
|
+
target: string2(),
|
|
29056
|
+
attempt: number2().int().positive(),
|
|
29057
|
+
delivery: _enum2(DELIVERY_CAPABILITIES),
|
|
29058
|
+
session_id: string2().nullable(),
|
|
29059
|
+
envelope_id: string2().nullable(),
|
|
29060
|
+
state: _enum2(["pending", "sent", "failed"]),
|
|
29061
|
+
error: string2().nullable(),
|
|
29062
|
+
resolve_error: string2().nullable(),
|
|
29063
|
+
reply_id: string2().nullable(),
|
|
29064
|
+
created_at: string2()
|
|
29065
|
+
});
|
|
29048
29066
|
var CommentEventPayloadSchema = object({
|
|
29049
29067
|
id: string2().optional(),
|
|
29050
29068
|
artifact_name: string2().optional(),
|
|
@@ -29060,7 +29078,9 @@ var CommentEventPayloadSchema = object({
|
|
|
29060
29078
|
anchor: object({ block_id: string2().nullable().optional(), quote: string2().optional() }).nullish(),
|
|
29061
29079
|
suggestion: object({ replace_with: string2().optional() }).nullish(),
|
|
29062
29080
|
author: object({ kind: string2(), id: string2() }).optional(),
|
|
29063
|
-
created_at: string2().optional()
|
|
29081
|
+
created_at: string2().optional(),
|
|
29082
|
+
mentions: array(CommentMentionSchema).optional(),
|
|
29083
|
+
deliveries: array(CommentDeliverySchema).optional()
|
|
29064
29084
|
});
|
|
29065
29085
|
var MessageEventPayloadSchema = object({
|
|
29066
29086
|
id: string2().optional(),
|
|
@@ -29070,8 +29090,9 @@ var MessageEventPayloadSchema = object({
|
|
|
29070
29090
|
reply_body: string2().optional(),
|
|
29071
29091
|
author: object({ kind: string2(), id: string2() }).optional()
|
|
29072
29092
|
});
|
|
29093
|
+
var DispatchTargetedResourceIDSchema = uuid2();
|
|
29073
29094
|
var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
|
|
29074
|
-
id:
|
|
29095
|
+
id: DispatchTargetedResourceIDSchema,
|
|
29075
29096
|
issue_key: string2().nullable(),
|
|
29076
29097
|
author: object({ kind: string2(), id: string2() }),
|
|
29077
29098
|
body: string2(),
|
|
@@ -29080,6 +29101,31 @@ var DispatchTargetedMessagePayloadSchema = MessageEventPayloadSchema.extend({
|
|
|
29080
29101
|
deliveries: array(unknown()),
|
|
29081
29102
|
created_at: string2()
|
|
29082
29103
|
});
|
|
29104
|
+
var DispatchTargetedCommentPayloadSchema = CommentEventPayloadSchema.extend({
|
|
29105
|
+
id: DispatchTargetedResourceIDSchema,
|
|
29106
|
+
issue_key: string2().nullable(),
|
|
29107
|
+
artifact_id: string2().nullable(),
|
|
29108
|
+
author: object({ kind: string2(), id: string2() }),
|
|
29109
|
+
body: string2(),
|
|
29110
|
+
reply_to: string2().nullable(),
|
|
29111
|
+
ask_id: string2().nullable(),
|
|
29112
|
+
mentions: array(CommentMentionSchema),
|
|
29113
|
+
deliveries: array(CommentDeliverySchema),
|
|
29114
|
+
created_at: string2(),
|
|
29115
|
+
artifact_name: string2()
|
|
29116
|
+
});
|
|
29117
|
+
var DispatchTargetedMessageDeliverySchema = object({
|
|
29118
|
+
attempt: number2().int().positive(),
|
|
29119
|
+
mode: _enum2(DELIVERY_CAPABILITIES)
|
|
29120
|
+
});
|
|
29121
|
+
var DispatchTargetedCommentDeliverySchema = DispatchTargetedMessageDeliverySchema.extend({
|
|
29122
|
+
comment_id: DispatchTargetedResourceIDSchema,
|
|
29123
|
+
target: string2()
|
|
29124
|
+
});
|
|
29125
|
+
var DispatchTargetedDeliverySchema = union([
|
|
29126
|
+
DispatchTargetedCommentDeliverySchema,
|
|
29127
|
+
DispatchTargetedMessageDeliverySchema
|
|
29128
|
+
]);
|
|
29083
29129
|
var MessageDeliveryEventPayloadSchema = object({
|
|
29084
29130
|
message_id: string2().optional(),
|
|
29085
29131
|
attempt: number2().int().positive().optional(),
|