@sjawhar/pi-legion 19.8.0 → 19.9.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/legion.js +81 -87
- package/package.json +1 -1
package/dist/legion.js
CHANGED
|
@@ -16649,6 +16649,7 @@ function isPictureType(mime) {
|
|
|
16649
16649
|
}
|
|
16650
16650
|
|
|
16651
16651
|
// ../contracts/src/subject.ts
|
|
16652
|
+
var AGENT_TOPIC_PREFIX = "notifications.agent.";
|
|
16652
16653
|
var ROLE_TOPIC_PREFIX = "notifications.role.";
|
|
16653
16654
|
var LEGION_NOTICE_TOPIC_PREFIX = "notifications.legion.";
|
|
16654
16655
|
function legionControllerNoticeSubject(project) {
|
|
@@ -16663,6 +16664,7 @@ function dispatchIssueSubject(issueKey, type) {
|
|
|
16663
16664
|
function dispatchDocumentSubject(project, slug, type) {
|
|
16664
16665
|
return `${DISPATCH_DOCUMENT_TOPIC_PREFIX}${project}.${slug}.${type}`;
|
|
16665
16666
|
}
|
|
16667
|
+
var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
|
|
16666
16668
|
|
|
16667
16669
|
// ../contracts/src/legion-roles.ts
|
|
16668
16670
|
var LEGION_ROLES = [
|
|
@@ -25179,8 +25181,34 @@ function sessionEnvoySettings(file, env, options) {
|
|
|
25179
25181
|
});
|
|
25180
25182
|
}
|
|
25181
25183
|
|
|
25184
|
+
// ../envoy-client/src/stream-topics.ts
|
|
25185
|
+
var EXCEPTION_TOPIC_PREFIX = "notifications.envoy.exceptions.";
|
|
25186
|
+
var STREAM_SUBJECT_PREFIXES = [
|
|
25187
|
+
AGENT_TOPIC_PREFIX,
|
|
25188
|
+
DISPATCH_TOPIC_PREFIX,
|
|
25189
|
+
"notifications.github.",
|
|
25190
|
+
"notifications.slack.",
|
|
25191
|
+
LEGION_NOTICE_TOPIC_PREFIX,
|
|
25192
|
+
GHOSTWISPR_TOPIC_PREFIX,
|
|
25193
|
+
"notifications.whatsapp.",
|
|
25194
|
+
"notifications.team.",
|
|
25195
|
+
`${EXCEPTION_TOPIC_PREFIX}${AGENT_TOPIC_PREFIX}`,
|
|
25196
|
+
`${EXCEPTION_TOPIC_PREFIX}notifications.team.`
|
|
25197
|
+
];
|
|
25198
|
+
function streamStores(topic) {
|
|
25199
|
+
return STREAM_SUBJECT_PREFIXES.some((prefix) => topic.length > prefix.length && topic.startsWith(prefix));
|
|
25200
|
+
}
|
|
25201
|
+
function streamDeliversNothing(topic) {
|
|
25202
|
+
return topic.startsWith("notifications.") && !topic.startsWith(ROLE_TOPIC_PREFIX) && !streamStores(topic);
|
|
25203
|
+
}
|
|
25204
|
+
var PRIVATE_STREAM_SUBJECTS = [
|
|
25205
|
+
`${AGENT_TOPIC_PREFIX}>`,
|
|
25206
|
+
`${LEGION_NOTICE_TOPIC_PREFIX}>`,
|
|
25207
|
+
`${EXCEPTION_TOPIC_PREFIX}${AGENT_TOPIC_PREFIX}>`,
|
|
25208
|
+
`${EXCEPTION_TOPIC_PREFIX}notifications.team.>`
|
|
25209
|
+
];
|
|
25210
|
+
|
|
25182
25211
|
// ../envoy-client/src/transport.ts
|
|
25183
|
-
var REPLAY_TIMEOUT_MS = 1e4;
|
|
25184
25212
|
var SessionStateSchema = _enum2(["live", "unresponsive", "gone"]);
|
|
25185
25213
|
var UNRESPONSIVE_RULE = "An unresponsive session is not dead: it keeps its role claims and its issue claims, and a " + "message sent to it is stored until it answers. Start no replacement for it and take no claim " + `from it until it is gone, or until ${ISSUE_CLAIM_UNRESPONSIVE_GRACE_MS / 60000} minutes ` + "have passed since its last_seen, the time of its last registration.";
|
|
25186
25214
|
var WireStateSchema = SessionStateSchema.default("live");
|
|
@@ -25192,16 +25220,13 @@ var InterestWireSchema = object({
|
|
|
25192
25220
|
updated_at: number2().int().optional(),
|
|
25193
25221
|
warnings: array(string2()).optional()
|
|
25194
25222
|
});
|
|
25195
|
-
var DeliveryAnswerWireSchema =
|
|
25196
|
-
|
|
25197
|
-
|
|
25198
|
-
|
|
25199
|
-
|
|
25200
|
-
|
|
25201
|
-
|
|
25202
|
-
}),
|
|
25203
|
-
object({ mode: literal("core"), reason: string2() })
|
|
25204
|
-
]);
|
|
25223
|
+
var DeliveryAnswerWireSchema = object({
|
|
25224
|
+
mode: literal("consumer"),
|
|
25225
|
+
subject: string2().min(1),
|
|
25226
|
+
stream_id: string2(),
|
|
25227
|
+
gap: boolean2(),
|
|
25228
|
+
consumer_start: number2().int().nonnegative().optional()
|
|
25229
|
+
});
|
|
25205
25230
|
var SessionWireSchema = object({
|
|
25206
25231
|
session_id: string2(),
|
|
25207
25232
|
machine_id: string2(),
|
|
@@ -25216,7 +25241,8 @@ var SessionWireSchema = object({
|
|
|
25216
25241
|
last_seen: number2().int().optional(),
|
|
25217
25242
|
state: WireStateSchema,
|
|
25218
25243
|
plugin: string2().optional(),
|
|
25219
|
-
plugin_version: string2().optional()
|
|
25244
|
+
plugin_version: string2().optional(),
|
|
25245
|
+
delivery: string2().optional()
|
|
25220
25246
|
});
|
|
25221
25247
|
var RoleWireSchema = object({
|
|
25222
25248
|
role: string2(),
|
|
@@ -25236,13 +25262,13 @@ var RoleHeldWireSchema = object({
|
|
|
25236
25262
|
var ErrorWireSchema = object({
|
|
25237
25263
|
error: string2(),
|
|
25238
25264
|
code: string2().optional(),
|
|
25265
|
+
reason: string2().optional(),
|
|
25239
25266
|
expected: array(string2()).optional(),
|
|
25240
25267
|
state: SessionStateSchema.optional(),
|
|
25241
25268
|
holder: string2().optional(),
|
|
25242
25269
|
holder_state: SessionStateSchema.optional(),
|
|
25243
25270
|
last_seen: number2().int().optional(),
|
|
25244
|
-
claim_released: boolean2().optional()
|
|
25245
|
-
unresponsive: array(string2()).optional()
|
|
25271
|
+
claim_released: boolean2().optional()
|
|
25246
25272
|
});
|
|
25247
25273
|
var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
25248
25274
|
recipient: string2().optional(),
|
|
@@ -25250,46 +25276,30 @@ var EnvelopeResponseSchema = EnvelopeSchema.extend({
|
|
|
25250
25276
|
holder_state: SessionStateSchema.optional(),
|
|
25251
25277
|
recipient_state: SessionStateSchema.optional(),
|
|
25252
25278
|
last_seen: number2().int().optional(),
|
|
25253
|
-
unresponsive: array(string2()).optional(),
|
|
25254
25279
|
duplicate: boolean2().optional()
|
|
25255
25280
|
});
|
|
25256
25281
|
var PublishResponseSchema = EnvelopeResponseSchema.extend({
|
|
25257
25282
|
kept: boolean2().optional(),
|
|
25258
25283
|
kept_reason: _enum2(["unclaimed", "holder_lapsed"]).optional()
|
|
25259
25284
|
});
|
|
25260
|
-
var
|
|
25261
|
-
|
|
25262
|
-
|
|
25263
|
-
|
|
25264
|
-
|
|
25265
|
-
last_seq: number2().int().nonnegative()
|
|
25266
|
-
}),
|
|
25267
|
-
subjects: array(object({
|
|
25268
|
-
subject: string2(),
|
|
25269
|
-
messages: array(object({
|
|
25270
|
-
seq: number2().int().positive(),
|
|
25271
|
-
subject: string2(),
|
|
25272
|
-
time: string2(),
|
|
25273
|
-
data: string2()
|
|
25274
|
-
})),
|
|
25275
|
-
next_after: number2().int().nonnegative(),
|
|
25276
|
-
more: boolean2(),
|
|
25277
|
-
refused: string2().optional()
|
|
25278
|
-
}))
|
|
25279
|
-
});
|
|
25280
|
-
var DELIVERY_NOT_ANSWERED = "not_answered";
|
|
25281
|
-
var DELIVERY_UNREADABLE = "unreadable_answer";
|
|
25285
|
+
var DeliveryRefusalSchema = object({
|
|
25286
|
+
mode: string2(),
|
|
25287
|
+
reason: string2().optional()
|
|
25288
|
+
});
|
|
25289
|
+
var DELIVERY_UNREADABLE = "answered a delivery field this build cannot read";
|
|
25282
25290
|
function parseSubscribeAnswer(body) {
|
|
25283
25291
|
const interest = InterestWireSchema.parse(body);
|
|
25284
25292
|
const raw = typeof body === "object" && body !== null && "delivery" in body ? body.delivery : undefined;
|
|
25285
25293
|
if (raw === undefined || raw === null) {
|
|
25286
|
-
|
|
25294
|
+
throw new Error(`the listener answered no delivery for ${interest.session_id}: it predates session consumers, and a session receives only what its own consumer holds`);
|
|
25287
25295
|
}
|
|
25288
25296
|
const delivery = DeliveryAnswerWireSchema.safeParse(raw);
|
|
25289
|
-
|
|
25290
|
-
|
|
25291
|
-
|
|
25292
|
-
|
|
25297
|
+
if (!delivery.success) {
|
|
25298
|
+
const named = DeliveryRefusalSchema.safeParse(raw);
|
|
25299
|
+
const said = named.success ? `answered delivery mode ${named.data.mode}${named.data.reason === undefined ? "" : ` (${named.data.reason})`}` : DELIVERY_UNREADABLE;
|
|
25300
|
+
throw new Error(`the listener gave ${interest.session_id} no consumer: it ${said}, and a session receives only what its own consumer holds`);
|
|
25301
|
+
}
|
|
25302
|
+
return { ...interest, delivery: delivery.data };
|
|
25293
25303
|
}
|
|
25294
25304
|
function expandSubscriptionTopics(topics) {
|
|
25295
25305
|
const expanded = new Set;
|
|
@@ -25303,27 +25313,20 @@ function expandSubscriptionTopics(topics) {
|
|
|
25303
25313
|
if (segments.length < 2 || segments.some((segment) => segment.length === 0)) {
|
|
25304
25314
|
throw new TypeError(`cannot expand Envoy wildcard topic "${topic}": its concrete base must have at least two non-empty segments`);
|
|
25305
25315
|
}
|
|
25306
|
-
|
|
25316
|
+
if (!streamDeliversNothing(base))
|
|
25317
|
+
expanded.add(base);
|
|
25307
25318
|
expanded.add(topic);
|
|
25308
25319
|
}
|
|
25309
25320
|
return [...expanded];
|
|
25310
25321
|
}
|
|
25311
25322
|
function refusalStateText(parsed) {
|
|
25312
|
-
const sentences = [];
|
|
25313
25323
|
const state = parsed.holder_state ?? parsed.state;
|
|
25314
|
-
if (state
|
|
25315
|
-
const who = parsed.holder === undefined ? "That session" : `Holder ${parsed.holder}`;
|
|
25316
|
-
const seen = parsed.last_seen === undefined || parsed.last_seen <= 0 ? "" : `, last seen ${new Date(parsed.last_seen).toISOString()}`;
|
|
25317
|
-
sentences.push(`${who} is ${state}${seen}.`);
|
|
25318
|
-
}
|
|
25319
|
-
const stored = parsed.unresponsive ?? [];
|
|
25320
|
-
if (stored.length > 0) {
|
|
25321
|
-
const one = stored.length === 1;
|
|
25322
|
-
sentences.push(`Envoy stored the message for ${stored.join(", ")}.`, `${one ? "That session" : "Those sessions"} stopped answering, so ${one ? "it" : "they"} did not fail this send.`);
|
|
25323
|
-
}
|
|
25324
|
-
if (sentences.length === 0)
|
|
25324
|
+
if (state === undefined)
|
|
25325
25325
|
return "";
|
|
25326
|
-
|
|
25326
|
+
const who = parsed.holder === undefined ? "That session" : `Holder ${parsed.holder}`;
|
|
25327
|
+
const seen = parsed.last_seen === undefined || parsed.last_seen <= 0 ? "" : `, last seen ${new Date(parsed.last_seen).toISOString()}`;
|
|
25328
|
+
const sentences = [`${who} is ${state}${seen}.`];
|
|
25329
|
+
if (state === "unresponsive")
|
|
25327
25330
|
sentences.push(UNRESPONSIVE_RULE);
|
|
25328
25331
|
return ` ${sentences.join(" ")}`;
|
|
25329
25332
|
}
|
|
@@ -25333,11 +25336,11 @@ class EnvoyApiError extends Error {
|
|
|
25333
25336
|
name = "EnvoyApiError";
|
|
25334
25337
|
expected;
|
|
25335
25338
|
code;
|
|
25339
|
+
reason;
|
|
25336
25340
|
holder;
|
|
25337
25341
|
sessionState;
|
|
25338
25342
|
lastSeen;
|
|
25339
25343
|
claimReleased;
|
|
25340
|
-
unresponsive;
|
|
25341
25344
|
constructor(details) {
|
|
25342
25345
|
let parsed;
|
|
25343
25346
|
try {
|
|
@@ -25345,15 +25348,15 @@ class EnvoyApiError extends Error {
|
|
|
25345
25348
|
if (result.success)
|
|
25346
25349
|
parsed = result.data;
|
|
25347
25350
|
} catch {}
|
|
25348
|
-
super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}: ${details.responseBody}` : `${parsed.error}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
|
|
25351
|
+
super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}: ${details.responseBody}` : `${parsed.error}${parsed.reason === undefined ? "" : ` (reason: ${parsed.reason})`}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
|
|
25349
25352
|
this.details = details;
|
|
25350
25353
|
this.expected = parsed?.expected;
|
|
25351
25354
|
this.code = parsed?.code;
|
|
25355
|
+
this.reason = parsed?.reason;
|
|
25352
25356
|
this.holder = parsed?.holder;
|
|
25353
25357
|
this.sessionState = parsed?.holder_state ?? parsed?.state;
|
|
25354
25358
|
this.lastSeen = parsed?.last_seen;
|
|
25355
25359
|
this.claimReleased = parsed?.claim_released;
|
|
25356
|
-
this.unresponsive = parsed?.unresponsive;
|
|
25357
25360
|
}
|
|
25358
25361
|
}
|
|
25359
25362
|
var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
|
|
@@ -25463,23 +25466,24 @@ function createEnvoyClient(config) {
|
|
|
25463
25466
|
headers: { "Content-Type": "application/json" },
|
|
25464
25467
|
body: JSON.stringify(body)
|
|
25465
25468
|
}, options);
|
|
25469
|
+
const subscribeBody = (input) => ({
|
|
25470
|
+
session_id: input.sessionID,
|
|
25471
|
+
dir: input.directory,
|
|
25472
|
+
topics: expandSubscriptionTopics(input.topics),
|
|
25473
|
+
port: input.port,
|
|
25474
|
+
title: input.title,
|
|
25475
|
+
...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
|
|
25476
|
+
driving: input.driving,
|
|
25477
|
+
...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
|
|
25478
|
+
delivery: input.delivery,
|
|
25479
|
+
...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
|
|
25480
|
+
host: machineID(),
|
|
25481
|
+
...input.place === undefined ? {} : { tmux_place: input.place },
|
|
25482
|
+
plugin: input.plugin.name,
|
|
25483
|
+
plugin_version: input.plugin.version
|
|
25484
|
+
});
|
|
25466
25485
|
return {
|
|
25467
|
-
subscribe: async (input) => parseSubscribeAnswer(JSON.parse(await post("/v1/interests/subscribe", {
|
|
25468
|
-
session_id: input.sessionID,
|
|
25469
|
-
dir: input.directory,
|
|
25470
|
-
topics: expandSubscriptionTopics(input.topics),
|
|
25471
|
-
port: input.port,
|
|
25472
|
-
title: input.title,
|
|
25473
|
-
...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
|
|
25474
|
-
driving: input.driving,
|
|
25475
|
-
...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
|
|
25476
|
-
...input.delivery === undefined ? {} : { delivery: input.delivery },
|
|
25477
|
-
...input.clientInstanceID === undefined ? {} : { client_instance_id: input.clientInstanceID },
|
|
25478
|
-
host: machineID(),
|
|
25479
|
-
...input.place === undefined ? {} : { tmux_place: input.place },
|
|
25480
|
-
plugin: input.plugin.name,
|
|
25481
|
-
plugin_version: input.plugin.version
|
|
25482
|
-
}, { actingSession: input.sessionID }))),
|
|
25486
|
+
subscribe: async (input) => parseSubscribeAnswer(JSON.parse(await post("/v1/interests/subscribe", subscribeBody(input), { actingSession: input.sessionID }))),
|
|
25483
25487
|
unsubscribe: async (input) => {
|
|
25484
25488
|
await post("/v1/interests/unsubscribe", {
|
|
25485
25489
|
session_id: input.sessionID,
|
|
@@ -25538,7 +25542,6 @@ function createEnvoyClient(config) {
|
|
|
25538
25542
|
envelope: response,
|
|
25539
25543
|
...response.holder === undefined ? {} : { holder: response.holder },
|
|
25540
25544
|
...response.holder_state === undefined ? {} : { holderState: response.holder_state },
|
|
25541
|
-
unresponsive: response.unresponsive ?? [],
|
|
25542
25545
|
...response.kept === undefined ? {} : { kept: response.kept },
|
|
25543
25546
|
...response.kept_reason === undefined ? {} : { keptReason: response.kept_reason }
|
|
25544
25547
|
};
|
|
@@ -25587,16 +25590,7 @@ function createEnvoyClient(config) {
|
|
|
25587
25590
|
search.set("include", input.include);
|
|
25588
25591
|
const query = search.size === 0 ? "" : `?${search.toString()}`;
|
|
25589
25592
|
return SessionWireSchema.array().parse(JSON.parse(await request(`/v1/sessions${query}`, {})));
|
|
25590
|
-
}
|
|
25591
|
-
replay: async (input) => ReplayWireSchema.parse(JSON.parse(await post("/v1/replay", {
|
|
25592
|
-
session_id: input.sessionID,
|
|
25593
|
-
subjects: input.subjects.map((cursor) => cursor.after === undefined ? { subject: cursor.subject } : { subject: cursor.subject, after: cursor.after }),
|
|
25594
|
-
...input.maxMessages === undefined ? {} : { max_messages: input.maxMessages }
|
|
25595
|
-
}, {
|
|
25596
|
-
timeoutMs: input.timeoutMs ?? REPLAY_TIMEOUT_MS,
|
|
25597
|
-
retry: false,
|
|
25598
|
-
actingSession: input.sessionID
|
|
25599
|
-
})))
|
|
25593
|
+
}
|
|
25600
25594
|
};
|
|
25601
25595
|
}
|
|
25602
25596
|
function waitForRetry(delayMs) {
|
|
@@ -28482,7 +28476,7 @@ import { logger as logger3 } from "@oh-my-pi/pi-utils";
|
|
|
28482
28476
|
// package.json
|
|
28483
28477
|
var package_default = {
|
|
28484
28478
|
name: "@sjawhar/pi-legion",
|
|
28485
|
-
version: "19.
|
|
28479
|
+
version: "19.9.0",
|
|
28486
28480
|
license: "Apache-2.0",
|
|
28487
28481
|
type: "module",
|
|
28488
28482
|
omp: {
|