spur-board 0.170.0 → 0.170.2
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/{chunk-BLaWsiXP.mjs → chunk-BbohDnMm.mjs} +1 -1
- package/dist/{chunk-Chj2wumn.mjs → chunk-BebxFmW0.mjs} +1 -1
- package/dist/{chunk-DI3BTuEX.mjs → chunk-DEHqpoRe.mjs} +2 -2
- package/dist/cli.mjs +3 -3
- package/dist/client.mjs +1 -1
- package/dist/daemon.mjs +519 -63
- package/dist/mcp.mjs +3 -3
- package/dist/web/assets/{index-xzNCT6Bb.js → index-CGVxiJUl.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/skills/spur-board/references/how-board-works-waits.md +3 -1
package/dist/daemon.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as prApprovalPairSchema, A as skillReloadFilesSchema, At as defaultAddressee, B as entityRefSchema, Bt as COLUMN_IDS, C as SPACE_IDS, D as messageRefSchema, Dt as columnTurnTimings, E as interactionRefSchema, Et as boardWideSpurProject, F as AdapterError, Ft as resolveWebOrigin, G as trackerSourceId, Gt as TODO_GROUP_COLUMN_IDS, H as prSourceId, Ht as ITEM_KINDS, I as MIRROR_FAILURES, It as slackConfigured, J as REVIEW_STATES, K as PR_STATES, Kt as VIAS, L as MIRROR_FAILURE_CODES, Lt as BLOCK_TYPES, M as EVENT_KINDS, Mt as plainHttpAllowed, N as GATE_REASONS, Nt as readyMirrorOf, O as userIdSchema, Ot as configBindings, P as eventPayloadSchemas, Pt as requiredSecretKeys, Q as parseRingMarker, R as batchSchema, Rt as COLUMNS, St as DEFAULT_SLACK_COMMAND, T as inboundEventSchema, Tt as approvalRuleOf, U as sessionTransitionSchema, Ut as SLACK_BOT_SCOPES, V as mirrorSourceId, Vt as DISPATCHER_MODES, W as sourceCursorSchema, Wt as TASK_HOLDS, X as SESSION_STATUSES, Y as SESSION_HEALTH_STATES, Z as isExternalAuthor, _ as defaultBranchViewSchema, _t as ok, a as doctorReportSchema, at as ticketFactsSchema, b as renderHttpProblem, bt as DEFAULT_LINK, c as requestHashOf, ct as actorIdSchema, d as tokenRequestStatusSchema, dt as parseActorId, et as prFactsSchema, f as BOARD_TICK_MS, ft as parseRef$1, g as OPERATIONS, h as roleCanUseOperation, i as SPUR_MIN_VERSION, it as sessionFactsSchema, j as sortSkillFiles, jt as externalQuietAfterMs, kt as configSchema, l as tokenRequestResultSchema, lt as encodeActorId, m as buildCatalogSnapshot, mt as err, n as SLACK_OFF_FIX, nt as prReviewRuleSchema, ot as JIRA_PROJECT_KEY, pt as ERRORS, q as REVIEW_DECISIONS, qt as isTodoGroupColumn, r as SLACK_PARTLY_FIX, rt as ringMarker, s as TOKEN_REQUEST_LIMITS, st as REF_NUMBER, t as assertNever, tt as prRefSchema, u as tokenRequestSchema, ut as errorCodeOf, v as inboxNoSessionSchema, vt as successEnvelopeSchema, w as conversationRefSchema, wt as RESERVED_PROJECT, y as turnHandedSchema, z as defaultBranchFactSchema, zt as COLUMN_GROUPS } from "./chunk-
|
|
1
|
+
import { $ as prApprovalPairSchema, A as skillReloadFilesSchema, At as defaultAddressee, B as entityRefSchema, Bt as COLUMN_IDS, C as SPACE_IDS, D as messageRefSchema, Dt as columnTurnTimings, E as interactionRefSchema, Et as boardWideSpurProject, F as AdapterError, Ft as resolveWebOrigin, G as trackerSourceId, Gt as TODO_GROUP_COLUMN_IDS, H as prSourceId, Ht as ITEM_KINDS, I as MIRROR_FAILURES, It as slackConfigured, J as REVIEW_STATES, K as PR_STATES, Kt as VIAS, L as MIRROR_FAILURE_CODES, Lt as BLOCK_TYPES, M as EVENT_KINDS, Mt as plainHttpAllowed, N as GATE_REASONS, Nt as readyMirrorOf, O as userIdSchema, Ot as configBindings, P as eventPayloadSchemas, Pt as requiredSecretKeys, Q as parseRingMarker, R as batchSchema, Rt as COLUMNS, St as DEFAULT_SLACK_COMMAND, T as inboundEventSchema, Tt as approvalRuleOf, U as sessionTransitionSchema, Ut as SLACK_BOT_SCOPES, V as mirrorSourceId, Vt as DISPATCHER_MODES, W as sourceCursorSchema, Wt as TASK_HOLDS, X as SESSION_STATUSES, Y as SESSION_HEALTH_STATES, Z as isExternalAuthor, _ as defaultBranchViewSchema, _t as ok, a as doctorReportSchema, at as ticketFactsSchema, b as renderHttpProblem, bt as DEFAULT_LINK, c as requestHashOf, ct as actorIdSchema, d as tokenRequestStatusSchema, dt as parseActorId, et as prFactsSchema, f as BOARD_TICK_MS, ft as parseRef$1, g as OPERATIONS, h as roleCanUseOperation, i as SPUR_MIN_VERSION, it as sessionFactsSchema, j as sortSkillFiles, jt as externalQuietAfterMs, kt as configSchema, l as tokenRequestResultSchema, lt as encodeActorId, m as buildCatalogSnapshot, mt as err, n as SLACK_OFF_FIX, nt as prReviewRuleSchema, ot as JIRA_PROJECT_KEY, pt as ERRORS, q as REVIEW_DECISIONS, qt as isTodoGroupColumn, r as SLACK_PARTLY_FIX, rt as ringMarker, s as TOKEN_REQUEST_LIMITS, st as REF_NUMBER, t as assertNever, tt as prRefSchema, u as tokenRequestSchema, ut as errorCodeOf, v as inboxNoSessionSchema, vt as successEnvelopeSchema, w as conversationRefSchema, wt as RESERVED_PROJECT, y as turnHandedSchema, z as defaultBranchFactSchema, zt as COLUMN_GROUPS } from "./chunk-BebxFmW0.mjs";
|
|
2
2
|
import { t as apiBaseUrl } from "./chunk-Bzb7aI8R.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -19,7 +19,7 @@ import { PassThrough } from "node:stream";
|
|
|
19
19
|
import { pino } from "pino";
|
|
20
20
|
import { WebAPIHTTPError, WebAPIPlatformError, WebAPIRateLimitedError, WebClient } from "@slack/web-api";
|
|
21
21
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
22
|
-
import { SocketModeClient } from "@slack/socket-mode";
|
|
22
|
+
import { LogLevel, SocketModeClient, UnrecoverableSocketModeStartError } from "@slack/socket-mode";
|
|
23
23
|
// \0rolldown/runtime.js
|
|
24
24
|
var __create = Object.create;
|
|
25
25
|
var __defProp = Object.defineProperty;
|
|
@@ -21054,6 +21054,41 @@ async function conversationsForRecovery(trx, gateway, now) {
|
|
|
21054
21054
|
since: rows[0] === void 0 ? now : new Date(rows[0].created_at)
|
|
21055
21055
|
};
|
|
21056
21056
|
}
|
|
21057
|
+
// ../core/src/app/transport-connection.ts
|
|
21058
|
+
const KEY_PREFIX = "transport_connection:";
|
|
21059
|
+
/** The last connection event of one gateway: `up` at its connect, `down` at its drop. */
|
|
21060
|
+
const connectionSchema = z.strictObject({
|
|
21061
|
+
state: z.enum(["up", "down"]),
|
|
21062
|
+
at: z.iso.datetime()
|
|
21063
|
+
});
|
|
21064
|
+
/** Stores the gateway's last connection event; `at` becomes ISO-8601 UTC. */
|
|
21065
|
+
async function writeConnection(trx, gateway, state, at) {
|
|
21066
|
+
const value = JSON.stringify({
|
|
21067
|
+
state,
|
|
21068
|
+
at: at.toISOString()
|
|
21069
|
+
});
|
|
21070
|
+
await trx.insertInto("meta").values({
|
|
21071
|
+
key: `${KEY_PREFIX}${gateway}`,
|
|
21072
|
+
value
|
|
21073
|
+
}).onConflict((oc) => oc.column("key").doUpdateSet({ value })).execute();
|
|
21074
|
+
}
|
|
21075
|
+
/** Each gateway's connection record; a malformed value reads as no record. */
|
|
21076
|
+
async function readConnections(db) {
|
|
21077
|
+
const rows = await db.selectFrom("meta").select(["key", "value"]).where("key", "like", `${KEY_PREFIX}%`).execute();
|
|
21078
|
+
const records = /* @__PURE__ */ new Map();
|
|
21079
|
+
for (const row of rows) {
|
|
21080
|
+
if (!row.key.startsWith(KEY_PREFIX)) continue;
|
|
21081
|
+
let parsed;
|
|
21082
|
+
try {
|
|
21083
|
+
parsed = JSON.parse(row.value);
|
|
21084
|
+
} catch {
|
|
21085
|
+
continue;
|
|
21086
|
+
}
|
|
21087
|
+
const record = connectionSchema.safeParse(parsed);
|
|
21088
|
+
if (record.success) records.set(row.key.slice(21), record.data);
|
|
21089
|
+
}
|
|
21090
|
+
return records;
|
|
21091
|
+
}
|
|
21057
21092
|
// ../core/src/app/sender.ts
|
|
21058
21093
|
/**
|
|
21059
21094
|
* Spur refused a doorbell for good (a permanent 4xx): the sender stops ringing and ends the ring
|
|
@@ -21250,6 +21285,8 @@ function createSender(options) {
|
|
|
21250
21285
|
let downSince;
|
|
21251
21286
|
/** Set once this outage's down rows were written; reset on `up`. */
|
|
21252
21287
|
let downRecorded = false;
|
|
21288
|
+
/** This run's connection state, read by `status.get` without waiting for a tick. */
|
|
21289
|
+
const live = /* @__PURE__ */ new Map();
|
|
21253
21290
|
/** The last tick started; a new tick runs after it, so two ticks never interleave. */
|
|
21254
21291
|
let ticking = Promise.resolve();
|
|
21255
21292
|
/** Sets the comments of `rows` that carry one to `superseded`. */
|
|
@@ -21702,20 +21739,31 @@ function createSender(options) {
|
|
|
21702
21739
|
return run;
|
|
21703
21740
|
},
|
|
21704
21741
|
recordConnection(state, at) {
|
|
21742
|
+
if (gateway !== void 0 && (state === "up" || live.get(gatewayKind)?.state !== "down")) live.set(gatewayKind, {
|
|
21743
|
+
state,
|
|
21744
|
+
at: at.toISOString()
|
|
21745
|
+
});
|
|
21705
21746
|
const run = ticking.then(async () => {
|
|
21706
21747
|
if (state === "down") {
|
|
21707
|
-
downSince
|
|
21748
|
+
if (downSince !== void 0) return;
|
|
21749
|
+
downSince = at.getTime();
|
|
21750
|
+
if (gateway === void 0) return;
|
|
21751
|
+
await scanTransaction(store, options.config, (trx) => writeConnection(trx, gatewayKind, "down", at));
|
|
21708
21752
|
return;
|
|
21709
21753
|
}
|
|
21710
21754
|
downSince = void 0;
|
|
21711
21755
|
downRecorded = false;
|
|
21712
21756
|
if (gateway === void 0) return;
|
|
21713
21757
|
await scanTransaction(store, options.config, async (trx) => {
|
|
21758
|
+
await writeConnection(trx, gatewayKind, "up", at);
|
|
21714
21759
|
if ((await trx.deleteFrom("transport_health").where("gateway", "=", gatewayKind).where("reason", "=", "down").returning("space").execute()).length > 0) await syncTransportItem(trx, gatewayKind, at);
|
|
21715
21760
|
});
|
|
21716
21761
|
});
|
|
21717
21762
|
ticking = run.catch(() => void 0);
|
|
21718
21763
|
return run;
|
|
21764
|
+
},
|
|
21765
|
+
liveConnections() {
|
|
21766
|
+
return live;
|
|
21719
21767
|
}
|
|
21720
21768
|
};
|
|
21721
21769
|
}
|
|
@@ -22189,6 +22237,16 @@ function sourceHealth(source) {
|
|
|
22189
22237
|
};
|
|
22190
22238
|
}
|
|
22191
22239
|
/**
|
|
22240
|
+
* A gateway's last good time: the read time while this daemon run's connection is up, even when
|
|
22241
|
+
* a delivery failure makes its row failing; its drop time while this run's connection is down;
|
|
22242
|
+
* before this run has connection state, the stored record of an earlier run (its last connect or
|
|
22243
|
+
* drop); null when it was never up.
|
|
22244
|
+
*/
|
|
22245
|
+
function gatewayLastGoodAt(live, stored, now) {
|
|
22246
|
+
if (live !== void 0) return live.state === "up" ? new Date(now).toISOString() : live.at;
|
|
22247
|
+
return stored?.at ?? null;
|
|
22248
|
+
}
|
|
22249
|
+
/**
|
|
22192
22250
|
* One health row per service: the daemon, each gateway (board-wide), then github,
|
|
22193
22251
|
* github-project, spur and jira rolled up from the given sources only.
|
|
22194
22252
|
*/
|
|
@@ -22205,17 +22263,18 @@ function services(input) {
|
|
|
22205
22263
|
}];
|
|
22206
22264
|
for (const gateway of input.transport) {
|
|
22207
22265
|
const ended = input.outageEnds.get(gateway.gateway);
|
|
22266
|
+
const lastGoodAt = gatewayLastGoodAt(input.liveConnections.get(gateway.gateway), input.connections.get(gateway.gateway), now);
|
|
22208
22267
|
rows.push(gateway.state === "down" ? {
|
|
22209
22268
|
service: gateway.gateway,
|
|
22210
22269
|
state: "failing",
|
|
22211
22270
|
since: gateway.since,
|
|
22212
|
-
lastGoodAt
|
|
22271
|
+
lastGoodAt,
|
|
22213
22272
|
reason: gateway.reason
|
|
22214
22273
|
} : {
|
|
22215
22274
|
service: gateway.gateway,
|
|
22216
22275
|
state: "healthy",
|
|
22217
22276
|
since: ended !== void 0 && Date.parse(ended) > Date.parse(daemon.startedAt) ? ended : daemon.startedAt,
|
|
22218
|
-
lastGoodAt
|
|
22277
|
+
lastGoodAt,
|
|
22219
22278
|
reason: null
|
|
22220
22279
|
});
|
|
22221
22280
|
}
|
|
@@ -22533,6 +22592,8 @@ async function getStatus(deps, options = {}) {
|
|
|
22533
22592
|
daemon,
|
|
22534
22593
|
transport,
|
|
22535
22594
|
outageEnds: await readOutageEnds(store.db),
|
|
22595
|
+
connections: await readConnections(store.db),
|
|
22596
|
+
liveConnections: deps.liveConnections ?? /* @__PURE__ */ new Map(),
|
|
22536
22597
|
sources
|
|
22537
22598
|
}),
|
|
22538
22599
|
transport,
|
|
@@ -24797,7 +24858,8 @@ function createOperationRegistry(deps) {
|
|
|
24797
24858
|
},
|
|
24798
24859
|
healthySince: deps.healthySince,
|
|
24799
24860
|
budgetWaits: deps.budgetWaits?.(),
|
|
24800
|
-
host: deps.hostMetrics?.()
|
|
24861
|
+
host: deps.hostMetrics?.(),
|
|
24862
|
+
liveConnections: deps.liveConnections?.()
|
|
24801
24863
|
}, {
|
|
24802
24864
|
project: input.project,
|
|
24803
24865
|
visibleProjects: visibleProjects(config, actor),
|
|
@@ -28082,6 +28144,9 @@ function deniedReference(error) {
|
|
|
28082
28144
|
function deniedBranchRule(error) {
|
|
28083
28145
|
return (error.type === "FORBIDDEN" || error.type === "NOT_FOUND") && error.path?.[2] === "baseRef";
|
|
28084
28146
|
}
|
|
28147
|
+
function deniedSuites(error) {
|
|
28148
|
+
return (error.type === "FORBIDDEN" || error.type === "NOT_FOUND") && error.path?.[2] === "statusCheckRollup" && error.path[3] === "commit";
|
|
28149
|
+
}
|
|
28085
28150
|
const graphEnvelopeWire = z.object({
|
|
28086
28151
|
errors: z.array(graphErrorWire).optional(),
|
|
28087
28152
|
data: z.unknown()
|
|
@@ -28115,9 +28180,9 @@ const BRANCH_RULE_FIELDS = "refUpdateRule { pattern requiredApprovingReviewCount
|
|
|
28115
28180
|
const prFields = (number, closing = false, reviewRule = false) => `id number url title updatedAt mergedAt closedAt state isDraft mergeable mergeStateStatus
|
|
28116
28181
|
author { login } headRefName headRefOid${reviewRule ? `\n reviewDecision baseRef { ${BRANCH_RULE_FIELDS} }` : ""}
|
|
28117
28182
|
statusCheckRollup { contexts(first: 100) { nodes {
|
|
28118
|
-
... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt workflowRun { workflow { id } } app { id } } isRequired(pullRequestNumber: ${String(number)}) }
|
|
28183
|
+
... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt id workflowRun { event runNumber runAttempt workflow { id } } app { id } } isRequired(pullRequestNumber: ${String(number)}) }
|
|
28119
28184
|
... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: ${String(number)}) }
|
|
28120
|
-
} pageInfo { hasNextPage endCursor } } }
|
|
28185
|
+
} pageInfo { hasNextPage endCursor } } commit { checkSuites(first: 100) { nodes { id status createdAt workflowRun { event runNumber runAttempt workflow { id } } } pageInfo { hasNextPage } } } }
|
|
28121
28186
|
reviews(first: 100) { nodes { ${REVIEW_FIELDS} } pageInfo { hasNextPage endCursor } }
|
|
28122
28187
|
comments(last: 100) { ${COMMENT_FIELDS} }
|
|
28123
28188
|
reviewThreads(first: 100) { nodes { ${THREAD_FIELDS} } pageInfo { hasNextPage endCursor } }
|
|
@@ -28145,7 +28210,7 @@ function detailQuery(numbers, closing = false, reviewRule = false) {
|
|
|
28145
28210
|
function pageQuery(connection, bootstrap = false) {
|
|
28146
28211
|
if (connection === "comments") return `query PrPage($owner: String!, $repo: String!, $number: Int!, $before: String!) { rateLimit { cost limit remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { comments(last: 100, before: $before) { ${COMMENT_FIELDS} } } } }`;
|
|
28147
28212
|
if (connection === "pullRequests") return `query DiscoveryPage($owner: String!, $repo: String!, $after: String!) { rateLimit { cost limit remaining resetAt } repository(owner: $owner, name: $repo) { pullRequests(first: 100, after: $after, states: [${discoveryStates(bootstrap)}], orderBy: {field: UPDATED_AT, direction: DESC}) { ${DISCOVERY_FIELDS} } } }`;
|
|
28148
|
-
return `query PrPage($owner: String!, $repo: String!, $number: Int!, $after: String!) { rateLimit { cost limit remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { ${connection === "closingIssuesReferences" ? `closingIssuesReferences(first: 100, after: $after) { ${CLOSING_FIELDS} }` : connection === "contexts" ? `statusCheckRollup { contexts(first: 100, after: $after) { nodes { ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt workflowRun { workflow { id } } app { id } } isRequired(pullRequestNumber: $number) } ... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: $number) } } pageInfo { hasNextPage endCursor } } }` : `${connection}(first: 100, after: $after) { nodes { ${connection === "reviews" ? REVIEW_FIELDS : connection === "reviewThreads" ? THREAD_FIELDS : REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }`} } } }`;
|
|
28213
|
+
return `query PrPage($owner: String!, $repo: String!, $number: Int!, $after: String!) { rateLimit { cost limit remaining resetAt } repository(owner: $owner, name: $repo) { pullRequest(number: $number) { ${connection === "closingIssuesReferences" ? `closingIssuesReferences(first: 100, after: $after) { ${CLOSING_FIELDS} }` : connection === "contexts" ? `statusCheckRollup { contexts(first: 100, after: $after) { nodes { ... on CheckRun { __typename name status conclusion startedAt completedAt checkSuite { createdAt id workflowRun { event runNumber runAttempt workflow { id } } app { id } } isRequired(pullRequestNumber: $number) } ... on StatusContext { __typename context state createdAt isRequired(pullRequestNumber: $number) } } pageInfo { hasNextPage endCursor } } }` : `${connection}(first: 100, after: $after) { nodes { ${connection === "reviews" ? REVIEW_FIELDS : connection === "reviewThreads" ? THREAD_FIELDS : REVIEWER_FIELDS} } pageInfo { hasNextPage endCursor } }`} } } }`;
|
|
28149
28214
|
}
|
|
28150
28215
|
const TREE_FIELDS = "tree { entries { name type mode oid } }";
|
|
28151
28216
|
function commitsQuery() {
|
|
@@ -28251,6 +28316,12 @@ var GithubClient = class {
|
|
|
28251
28316
|
}
|
|
28252
28317
|
};
|
|
28253
28318
|
// ../adapters/src/github/checks.ts
|
|
28319
|
+
const workflowRunWire = z.object({
|
|
28320
|
+
event: z.string().nullish(),
|
|
28321
|
+
runNumber: z.number().int().nullish(),
|
|
28322
|
+
runAttempt: z.number().int().nullish(),
|
|
28323
|
+
workflow: z.object({ id: z.string().min(1) })
|
|
28324
|
+
});
|
|
28254
28325
|
const checkRunWire = z.object({
|
|
28255
28326
|
__typename: z.literal("CheckRun"),
|
|
28256
28327
|
name: z.string(),
|
|
@@ -28260,7 +28331,8 @@ const checkRunWire = z.object({
|
|
|
28260
28331
|
completedAt: z.string().nullable(),
|
|
28261
28332
|
checkSuite: z.object({
|
|
28262
28333
|
createdAt: z.string(),
|
|
28263
|
-
|
|
28334
|
+
id: z.string().nullish(),
|
|
28335
|
+
workflowRun: workflowRunWire.nullish(),
|
|
28264
28336
|
app: z.object({ id: z.string().min(1) }).nullish()
|
|
28265
28337
|
}).nullish(),
|
|
28266
28338
|
isRequired: z.boolean().nullish()
|
|
@@ -28326,6 +28398,78 @@ function latestContexts(nodes) {
|
|
|
28326
28398
|
}
|
|
28327
28399
|
return [...latest.entries()].sort(([a, x], [b, y]) => contextName(x).localeCompare(contextName(y)) || a.localeCompare(b)).map(([, node]) => node);
|
|
28328
28400
|
}
|
|
28401
|
+
/**
|
|
28402
|
+
* The head commit's check suites, read in the PR detail query. Actions creates a suite for each
|
|
28403
|
+
* workflow run when the run starts, before its jobs create check runs. A denied suite arrives as
|
|
28404
|
+
* a null node; a denied list or commit, or a list without nodes, arrives as null.
|
|
28405
|
+
*/
|
|
28406
|
+
const suiteListWire = z.object({ checkSuites: z.object({
|
|
28407
|
+
nodes: z.array(z.object({
|
|
28408
|
+
id: z.string().nullish(),
|
|
28409
|
+
status: z.string(),
|
|
28410
|
+
createdAt: z.string(),
|
|
28411
|
+
workflowRun: workflowRunWire.nullable()
|
|
28412
|
+
}).nullable()).nullable(),
|
|
28413
|
+
pageInfo: z.object({ hasNextPage: z.boolean() })
|
|
28414
|
+
}).nullable() }).nullish();
|
|
28415
|
+
/**
|
|
28416
|
+
* What decides a required check run that reads skipped, as `latestContexts` keeps it. Of the
|
|
28417
|
+
* head's suites of its workflow and trigger event, from the suite list and the check runs and
|
|
28418
|
+
* joined by node id, only the newest decides, by creation time, then the workflow run's number
|
|
28419
|
+
* and attempt: its run of the same check (see `checkKey`) counts, finished or not; without one
|
|
28420
|
+
* the check is `pending` until that suite completes, then the skip stands. Older suites never
|
|
28421
|
+
* decide, and a run of another event, such as a manual dispatch, is not one of them. A missing,
|
|
28422
|
+
* denied or truncated suite list, a null suite in it, a missing event, a time that does not
|
|
28423
|
+
* parse, or a newest place the run number and attempt cannot break, decides nothing.
|
|
28424
|
+
*/
|
|
28425
|
+
function skipDecision(node, nodes, commit) {
|
|
28426
|
+
if (node.__typename !== "CheckRun" || node.isRequired !== true) return void 0;
|
|
28427
|
+
if (checkState(node) !== "skipped") return void 0;
|
|
28428
|
+
const run = node.checkSuite?.workflowRun;
|
|
28429
|
+
const event = run?.event;
|
|
28430
|
+
const list = commit?.checkSuites;
|
|
28431
|
+
if (!run || !event || !list?.nodes || list.pageInfo.hasNextPage) return void 0;
|
|
28432
|
+
if (list.nodes.some((suite) => suite === null)) return void 0;
|
|
28433
|
+
const ofRun = (wire) => wire?.workflow.id === run.workflow.id && wire.event === event;
|
|
28434
|
+
const suites = [];
|
|
28435
|
+
const byId = /* @__PURE__ */ new Map();
|
|
28436
|
+
const add = (createdAt, id, wire, status) => {
|
|
28437
|
+
const known = id == null ? void 0 : byId.get(id);
|
|
28438
|
+
if (known !== void 0) {
|
|
28439
|
+
known.status ??= status;
|
|
28440
|
+
known.number ??= wire.runNumber ?? null;
|
|
28441
|
+
known.attempt ??= wire.runAttempt ?? null;
|
|
28442
|
+
return;
|
|
28443
|
+
}
|
|
28444
|
+
const suite = {
|
|
28445
|
+
at: Date.parse(createdAt),
|
|
28446
|
+
id: id ?? null,
|
|
28447
|
+
number: wire.runNumber ?? null,
|
|
28448
|
+
attempt: wire.runAttempt ?? null,
|
|
28449
|
+
status
|
|
28450
|
+
};
|
|
28451
|
+
suites.push(suite);
|
|
28452
|
+
if (suite.id !== null) byId.set(suite.id, suite);
|
|
28453
|
+
};
|
|
28454
|
+
for (const suite of list.nodes) if (suite !== null && ofRun(suite.workflowRun)) add(suite.createdAt, suite.id, suite.workflowRun, suite.status);
|
|
28455
|
+
for (const other of nodes) if (other.__typename === "CheckRun" && other.checkSuite && ofRun(other.checkSuite.workflowRun)) add(other.checkSuite.createdAt, other.checkSuite.id, other.checkSuite.workflowRun);
|
|
28456
|
+
if (suites.some((suite) => Number.isNaN(suite.at))) return void 0;
|
|
28457
|
+
const order = (a, b) => (a.number ?? 0) - (b.number ?? 0) || (a.attempt ?? 0) - (b.attempt ?? 0);
|
|
28458
|
+
suites.sort((a, b) => a.at - b.at || order(a, b));
|
|
28459
|
+
const newest = suites.at(-1);
|
|
28460
|
+
if (newest === void 0) return void 0;
|
|
28461
|
+
const tied = suites.filter((suite) => suite.at === newest.at);
|
|
28462
|
+
if (tied.length > 1) {
|
|
28463
|
+
if (tied.some((suite) => suite.number === null || suite.attempt === null)) return void 0;
|
|
28464
|
+
const next = tied.at(-2);
|
|
28465
|
+
if (next !== void 0 && order(next, newest) === 0) return void 0;
|
|
28466
|
+
}
|
|
28467
|
+
const key = checkKey(node);
|
|
28468
|
+
const [decider] = latestContexts(nodes.filter((other) => other.__typename === "CheckRun" && newest.id !== null && other.checkSuite?.id === newest.id && checkKey(other) === key));
|
|
28469
|
+
if (decider !== void 0) return decider;
|
|
28470
|
+
if (newest.status === void 0 || newest.status === "COMPLETED") return void 0;
|
|
28471
|
+
return "pending";
|
|
28472
|
+
}
|
|
28329
28473
|
// ../adapters/src/github/discovery.ts
|
|
28330
28474
|
const timestamp$1 = z.string().min(1).refine((value) => !Number.isNaN(Date.parse(value)));
|
|
28331
28475
|
const discoveryNodeWire = z.object({
|
|
@@ -28631,7 +28775,10 @@ const prWire = z.object({
|
|
|
28631
28775
|
author: actor,
|
|
28632
28776
|
headRefName: z.string(),
|
|
28633
28777
|
headRefOid: z.string(),
|
|
28634
|
-
statusCheckRollup: z.object({
|
|
28778
|
+
statusCheckRollup: z.object({
|
|
28779
|
+
contexts: nodes(contextWire),
|
|
28780
|
+
commit: suiteListWire
|
|
28781
|
+
}).nullish(),
|
|
28635
28782
|
reviews: nodes(reviewWire),
|
|
28636
28783
|
comments: nodes(commentWire),
|
|
28637
28784
|
reviewThreads: nodes(threadWire),
|
|
@@ -28690,12 +28837,22 @@ function closingRefs(wire) {
|
|
|
28690
28837
|
number: node.number
|
|
28691
28838
|
}] : []);
|
|
28692
28839
|
}
|
|
28693
|
-
function latestChecks(nodes) {
|
|
28840
|
+
function latestChecks(nodes, commit) {
|
|
28841
|
+
const visible = (node) => ({
|
|
28842
|
+
state: checkState(node),
|
|
28843
|
+
completedAt: node.__typename === "StatusContext" ? null : node.completedAt
|
|
28844
|
+
});
|
|
28845
|
+
const shown = (node) => {
|
|
28846
|
+
const decided = skipDecision(node, nodes, commit);
|
|
28847
|
+
return decided === "pending" ? {
|
|
28848
|
+
state: "pending",
|
|
28849
|
+
completedAt: null
|
|
28850
|
+
} : visible(decided ?? node);
|
|
28851
|
+
};
|
|
28694
28852
|
const values = latestContexts(nodes).map((node) => ({
|
|
28695
28853
|
check: {
|
|
28696
28854
|
name: contextName(node),
|
|
28697
|
-
|
|
28698
|
-
completedAt: node.__typename === "StatusContext" ? null : node.completedAt
|
|
28855
|
+
...shown(node)
|
|
28699
28856
|
},
|
|
28700
28857
|
required: node.isRequired === true
|
|
28701
28858
|
}));
|
|
@@ -28866,7 +29023,7 @@ function reviewThread(node) {
|
|
|
28866
29023
|
*/
|
|
28867
29024
|
function normalizePr(repo, value, rule, feedbackComplete, held = []) {
|
|
28868
29025
|
const wire = parseWire(prWire, value, "Malformed GitHub PR response");
|
|
28869
|
-
const checks = latestChecks(wire.statusCheckRollup?.contexts.nodes ?? []);
|
|
29026
|
+
const checks = latestChecks(wire.statusCheckRollup?.contexts.nodes ?? [], wire.statusCheckRollup?.commit);
|
|
28870
29027
|
const state = wire.state === "MERGED" ? "merged" : wire.state === "CLOSED" ? "closed" : "open";
|
|
28871
29028
|
const mergeable = wire.mergeable === "MERGEABLE" ? "mergeable" : wire.mergeable === "CONFLICTING" ? "conflicting" : "unknown";
|
|
28872
29029
|
const rawMerge = wire.mergeStateStatus.toLowerCase();
|
|
@@ -29018,7 +29175,7 @@ const prPagingWire = z.looseObject({
|
|
|
29018
29175
|
comments: backPagingWire,
|
|
29019
29176
|
reviewThreads: pagingWire,
|
|
29020
29177
|
reviewRequests: pagingWire,
|
|
29021
|
-
statusCheckRollup: z.
|
|
29178
|
+
statusCheckRollup: z.looseObject({ contexts: pagingWire }).nullish(),
|
|
29022
29179
|
closingIssuesReferences: pagingWire.nullish()
|
|
29023
29180
|
});
|
|
29024
29181
|
const aliasWire = z.object({ pullRequest: prPagingWire.nullish() }).nullish();
|
|
@@ -29316,7 +29473,8 @@ function malformed(acc, error, ref) {
|
|
|
29316
29473
|
}
|
|
29317
29474
|
async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
|
|
29318
29475
|
const ruleDenied = scopedErrors.some(deniedBranchRule);
|
|
29319
|
-
const
|
|
29476
|
+
const suitesDenied = scopedErrors.some(deniedSuites);
|
|
29477
|
+
const errors = withoutDeniedReferences(scopedErrors).filter((entry) => !deniedBranchRule(entry) && !deniedSuites(entry));
|
|
29320
29478
|
requireCheckAccess(errors);
|
|
29321
29479
|
const error = errors[0];
|
|
29322
29480
|
if (error !== void 0) {
|
|
@@ -29359,12 +29517,17 @@ async function processPr(scope, acc, number, alias, data, scopedErrors, ref) {
|
|
|
29359
29517
|
return;
|
|
29360
29518
|
}
|
|
29361
29519
|
const feedback = await readFeedback(scope, number, full.pr.comments, entryFor(scope.feedbackCursors, scope.repo, number), entryFor(scope.continuations, scope.repo, number), report);
|
|
29520
|
+
const rollup = full.pr.statusCheckRollup;
|
|
29362
29521
|
const pr = {
|
|
29363
29522
|
...full.pr,
|
|
29364
29523
|
comments: {
|
|
29365
29524
|
...full.pr.comments,
|
|
29366
29525
|
nodes: feedback.nodes
|
|
29367
|
-
}
|
|
29526
|
+
},
|
|
29527
|
+
...suitesDenied && rollup ? { statusCheckRollup: {
|
|
29528
|
+
...rollup,
|
|
29529
|
+
commit: null
|
|
29530
|
+
} } : {}
|
|
29368
29531
|
};
|
|
29369
29532
|
const facts = content(() => normalizePr(ref?.repo ?? scope.repo, pr, scope.keys, feedback.complete, feedback.held));
|
|
29370
29533
|
if (facts instanceof AdapterError) {
|
|
@@ -32815,13 +32978,316 @@ async function rootFor(client, channel, threadTs) {
|
|
|
32815
32978
|
if (root === void 0) throw new Error("Slack thread root unavailable");
|
|
32816
32979
|
return root;
|
|
32817
32980
|
}
|
|
32818
|
-
/**
|
|
32981
|
+
/**
|
|
32982
|
+
* The wait before reconnect attempt `attempt` (1-based): equal jitter over a ceiling that doubles
|
|
32983
|
+
* from `baseDelayMs` up to `maxDelayMs`.
|
|
32984
|
+
*/
|
|
32985
|
+
function reconnectDelay(attempt, options, random) {
|
|
32986
|
+
const ceiling = Math.min(options.maxDelayMs, options.baseDelayMs * 2 ** (attempt - 1));
|
|
32987
|
+
return Math.round(ceiling / 2 + random() * ceiling / 2);
|
|
32988
|
+
}
|
|
32989
|
+
const closeFrameLine = /^WebSocket close frame received \(code: (\d+), reason: (.*)\)$/s;
|
|
32990
|
+
const socketErrorLine = /^WebSocket error occurred: (.*)$/s;
|
|
32991
|
+
const carriedLines = [
|
|
32992
|
+
/^Failed to retrieve a new WSS URL/,
|
|
32993
|
+
/^http request failed/,
|
|
32994
|
+
/^WebSocket error! /
|
|
32995
|
+
];
|
|
32996
|
+
/**
|
|
32997
|
+
* The logger one SDK client gets. Debug and info lines never leave it (they carry payloads and
|
|
32998
|
+
* the WSS URL); it records the close frame and socket error into `record`, and forwards every
|
|
32999
|
+
* other warn and error line as its string arguments joined by a space.
|
|
33000
|
+
*/
|
|
33001
|
+
function createSdkLogger(record, forward) {
|
|
33002
|
+
const detailOf = (args) => args.filter((arg) => typeof arg === "string").join(" ");
|
|
33003
|
+
function line(level, args) {
|
|
33004
|
+
const detail = detailOf(args);
|
|
33005
|
+
if (level === "error") {
|
|
33006
|
+
const socketError = socketErrorLine.exec(detail);
|
|
33007
|
+
if (socketError !== null) {
|
|
33008
|
+
if (socketError[1] !== void 0 && socketError[1].length > 0) record.socketError = socketError[1];
|
|
33009
|
+
return;
|
|
33010
|
+
}
|
|
33011
|
+
}
|
|
33012
|
+
if (carriedLines.some((pattern) => pattern.test(detail))) return;
|
|
33013
|
+
forward(level, detail);
|
|
33014
|
+
}
|
|
33015
|
+
return {
|
|
33016
|
+
debug(...args) {
|
|
33017
|
+
const frame = closeFrameLine.exec(detailOf(args));
|
|
33018
|
+
if (frame === null) return;
|
|
33019
|
+
record.closeCode = Number(frame[1]);
|
|
33020
|
+
if (frame[2] === void 0 || frame[2] === "") delete record.closeReason;
|
|
33021
|
+
else record.closeReason = frame[2];
|
|
33022
|
+
},
|
|
33023
|
+
info() {},
|
|
33024
|
+
warn(...args) {
|
|
33025
|
+
line("warn", args);
|
|
33026
|
+
},
|
|
33027
|
+
error(...args) {
|
|
33028
|
+
line("error", args);
|
|
33029
|
+
},
|
|
33030
|
+
getLevel: () => LogLevel.INFO,
|
|
33031
|
+
setLevel() {},
|
|
33032
|
+
setName() {}
|
|
33033
|
+
};
|
|
33034
|
+
}
|
|
33035
|
+
/** The `reason` of a Socket Mode `disconnect` message, else undefined. */
|
|
33036
|
+
function disconnectReasonOf(data) {
|
|
33037
|
+
if (typeof data !== "string" || !data.includes("\"disconnect\"")) return void 0;
|
|
33038
|
+
try {
|
|
33039
|
+
const message = fieldsOf(JSON.parse(data));
|
|
33040
|
+
return textOf(message?.type) === "disconnect" ? textOf(message?.reason) : void 0;
|
|
33041
|
+
} catch {
|
|
33042
|
+
return;
|
|
33043
|
+
}
|
|
33044
|
+
}
|
|
33045
|
+
function unrecoverable(err) {
|
|
33046
|
+
const codes = Object.values(UnrecoverableSocketModeStartError);
|
|
33047
|
+
return err instanceof WebAPIPlatformError && codes.includes(err.data.error);
|
|
33048
|
+
}
|
|
33049
|
+
/** Slack's `disconnect` reasons that ask for a new connection while the old one still serves. */
|
|
33050
|
+
const refreshReasons = ["refresh_requested", "warning"];
|
|
33051
|
+
/**
|
|
33052
|
+
* An SDK client that hands a refresh `disconnect` to the gateway. With its reconnect off the SDK
|
|
33053
|
+
* would close the socket at once; this client keeps it open when `onRefresh` takes the notice.
|
|
33054
|
+
*/
|
|
33055
|
+
var RefreshingClient = class extends SocketModeClient {
|
|
33056
|
+
onRefresh = () => false;
|
|
33057
|
+
async onWebSocketMessage(...args) {
|
|
33058
|
+
const [data, isBinary] = args;
|
|
33059
|
+
const reason = isBinary ? void 0 : disconnectReasonOf(data);
|
|
33060
|
+
if (reason !== void 0 && refreshReasons.includes(reason) && this.onRefresh(reason)) return;
|
|
33061
|
+
await super.onWebSocketMessage(...args);
|
|
33062
|
+
}
|
|
33063
|
+
};
|
|
33064
|
+
/**
|
|
33065
|
+
* The gateway owns transport reconnects: every drop after an `up` schedules attempts with
|
|
33066
|
+
* jittered backoff until `stop()`, each on a fresh SDK client with its reconnect turned off. A
|
|
33067
|
+
* refresh `disconnect` opens the replacement at once while the old socket keeps serving; the old
|
|
33068
|
+
* one closes after the replacement's hello. This layer also owns sink-before-ack ordering.
|
|
33069
|
+
*/
|
|
32819
33070
|
function createSocket(api, config, botIdentity) {
|
|
32820
|
-
|
|
33071
|
+
const baseDelayMs = config.reconnect?.baseDelayMs ?? 1e3;
|
|
33072
|
+
const maxDelayMs = config.reconnect?.maxDelayMs ?? 6e4;
|
|
33073
|
+
const helloTimeoutMs = config.reconnect?.helloTimeoutMs ?? 3e4;
|
|
33074
|
+
let started = false;
|
|
33075
|
+
let current;
|
|
33076
|
+
let replacement;
|
|
33077
|
+
let retiring;
|
|
33078
|
+
let supervisor;
|
|
33079
|
+
let halt = new AbortController();
|
|
32821
33080
|
let sink;
|
|
32822
33081
|
let stopping = false;
|
|
32823
|
-
let connected = false;
|
|
32824
33082
|
const pending = /* @__PURE__ */ new Set();
|
|
33083
|
+
function log(level, fields, msg) {
|
|
33084
|
+
try {
|
|
33085
|
+
config.onLog?.(level, fields, msg);
|
|
33086
|
+
} catch {}
|
|
33087
|
+
}
|
|
33088
|
+
function connectionEvent(state) {
|
|
33089
|
+
track(emit({
|
|
33090
|
+
kind: "connection",
|
|
33091
|
+
state,
|
|
33092
|
+
dedupeKey: `slack:connection:${randomUUID()}`
|
|
33093
|
+
}), "connection");
|
|
33094
|
+
}
|
|
33095
|
+
/**
|
|
33096
|
+
* One connection attempt on a fresh client; `number` is 0 for the first start. A handover
|
|
33097
|
+
* attempt names the up attempt it `replaces` and the reason Slack gave.
|
|
33098
|
+
*/
|
|
33099
|
+
function connect(appToken, number, replaces) {
|
|
33100
|
+
const record = {};
|
|
33101
|
+
let disconnectReason;
|
|
33102
|
+
const outcome = Promise.withResolvers();
|
|
33103
|
+
const ended = Promise.withResolvers();
|
|
33104
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
33105
|
+
let closing = Promise.resolve();
|
|
33106
|
+
let disconnecting;
|
|
33107
|
+
let state = "connecting";
|
|
33108
|
+
const quiet = () => state !== "connecting" && state !== "up";
|
|
33109
|
+
const client = new RefreshingClient({
|
|
33110
|
+
appToken,
|
|
33111
|
+
autoReconnectEnabled: false,
|
|
33112
|
+
logger: createSdkLogger(record, (level, detail) => {
|
|
33113
|
+
if (!quiet()) log(level, { detail }, "slack socket-mode sdk");
|
|
33114
|
+
}),
|
|
33115
|
+
clientOptions: {
|
|
33116
|
+
retryConfig: { retries: 0 },
|
|
33117
|
+
rejectRateLimitedCalls: true,
|
|
33118
|
+
timeout: config.requestTimeoutMs ?? 1e4,
|
|
33119
|
+
...config.apiUrl === void 0 ? {} : { slackApiUrl: config.apiUrl }
|
|
33120
|
+
}
|
|
33121
|
+
});
|
|
33122
|
+
const disconnect = () => disconnecting ??= client.disconnect();
|
|
33123
|
+
const socketFields = () => ({
|
|
33124
|
+
...disconnectReason === void 0 ? {} : { disconnectReason },
|
|
33125
|
+
closeCode: record.closeCode ?? 1006,
|
|
33126
|
+
...record.closeReason === void 0 ? {} : { closeReason: record.closeReason },
|
|
33127
|
+
...record.socketError === void 0 ? {} : { socketError: record.socketError }
|
|
33128
|
+
});
|
|
33129
|
+
function fail(fields, err) {
|
|
33130
|
+
if (state !== "connecting") return;
|
|
33131
|
+
state = "failed";
|
|
33132
|
+
clearTimeout(helloTimer);
|
|
33133
|
+
log(unrecoverable(err) ? "error" : "warn", {
|
|
33134
|
+
attempt: number,
|
|
33135
|
+
...fields,
|
|
33136
|
+
...err === void 0 ? {} : { err }
|
|
33137
|
+
}, "slack socket attempt failed");
|
|
33138
|
+
outcome.resolve("failed");
|
|
33139
|
+
}
|
|
33140
|
+
const attempt = {
|
|
33141
|
+
outcome: outcome.promise,
|
|
33142
|
+
ended: ended.promise,
|
|
33143
|
+
abandon() {
|
|
33144
|
+
if (state === "connecting") {
|
|
33145
|
+
clearTimeout(helloTimer);
|
|
33146
|
+
outcome.resolve("abandoned");
|
|
33147
|
+
}
|
|
33148
|
+
if (state === "connecting" || state === "up" || state === "retired") {
|
|
33149
|
+
state = "abandoned";
|
|
33150
|
+
closing = disconnect();
|
|
33151
|
+
}
|
|
33152
|
+
ended.resolve(void 0);
|
|
33153
|
+
},
|
|
33154
|
+
retire(next) {
|
|
33155
|
+
if (state !== "up") return false;
|
|
33156
|
+
state = "retired";
|
|
33157
|
+
ended.resolve(next);
|
|
33158
|
+
closing = (async () => {
|
|
33159
|
+
while (inFlight.size > 0) await Promise.allSettled([...inFlight]);
|
|
33160
|
+
await disconnect();
|
|
33161
|
+
})();
|
|
33162
|
+
return true;
|
|
33163
|
+
},
|
|
33164
|
+
closed: () => closing
|
|
33165
|
+
};
|
|
33166
|
+
const helloTimer = setTimeout(() => {
|
|
33167
|
+
fail({ failure: "hello_timeout" });
|
|
33168
|
+
closing = disconnect();
|
|
33169
|
+
}, helloTimeoutMs);
|
|
33170
|
+
client.onRefresh = (reason) => {
|
|
33171
|
+
if (state !== "up" || stopping) return false;
|
|
33172
|
+
disconnectReason = reason;
|
|
33173
|
+
handover(appToken, attempt, reason);
|
|
33174
|
+
return true;
|
|
33175
|
+
};
|
|
33176
|
+
client.on("ws_message", (data) => {
|
|
33177
|
+
disconnectReason = disconnectReasonOf(data) ?? disconnectReason;
|
|
33178
|
+
});
|
|
33179
|
+
client.on("connected", () => {
|
|
33180
|
+
if (state !== "connecting") return;
|
|
33181
|
+
state = "up";
|
|
33182
|
+
clearTimeout(helloTimer);
|
|
33183
|
+
const old = replaces?.attempt;
|
|
33184
|
+
if (old?.retire(attempt) === true) {
|
|
33185
|
+
current = attempt;
|
|
33186
|
+
replacement = void 0;
|
|
33187
|
+
retiring = old;
|
|
33188
|
+
old.closed().then(() => {
|
|
33189
|
+
if (retiring === old) retiring = void 0;
|
|
33190
|
+
});
|
|
33191
|
+
log("info", { disconnectReason: replaces?.reason }, "slack socket refreshed");
|
|
33192
|
+
} else {
|
|
33193
|
+
log("info", { attempt: number }, "slack socket up");
|
|
33194
|
+
connectionEvent("up");
|
|
33195
|
+
}
|
|
33196
|
+
outcome.resolve("up");
|
|
33197
|
+
});
|
|
33198
|
+
client.on("disconnected", () => {
|
|
33199
|
+
if (state === "connecting") {
|
|
33200
|
+
fail({
|
|
33201
|
+
failure: "closed_before_hello",
|
|
33202
|
+
...socketFields()
|
|
33203
|
+
});
|
|
33204
|
+
return;
|
|
33205
|
+
}
|
|
33206
|
+
if (state !== "up") return;
|
|
33207
|
+
log("warn", socketFields(), "slack socket down");
|
|
33208
|
+
state = "down";
|
|
33209
|
+
connectionEvent("down");
|
|
33210
|
+
ended.resolve(void 0);
|
|
33211
|
+
});
|
|
33212
|
+
client.on("slack_event", (envelope) => {
|
|
33213
|
+
if (state !== "up" && state !== "retired") return;
|
|
33214
|
+
const work = handle(envelope);
|
|
33215
|
+
inFlight.add(work);
|
|
33216
|
+
work.catch(() => void 0).finally(() => inFlight.delete(work));
|
|
33217
|
+
track(work, "envelope");
|
|
33218
|
+
});
|
|
33219
|
+
client.start().catch((err) => {
|
|
33220
|
+
fail({ failure: "connections_open" }, err);
|
|
33221
|
+
});
|
|
33222
|
+
return attempt;
|
|
33223
|
+
}
|
|
33224
|
+
/**
|
|
33225
|
+
* Opens the replacement of the up attempt `old` at once; `old` keeps serving until the
|
|
33226
|
+
* replacement's hello. A replacement that fails leaves `old` serving, and its drop then runs
|
|
33227
|
+
* the usual backoff. A refresh notice while a replacement is connecting or closing is ignored:
|
|
33228
|
+
* `old` serves until Slack closes it, then the usual loop runs.
|
|
33229
|
+
*/
|
|
33230
|
+
function handover(appToken, old, reason) {
|
|
33231
|
+
if (replacement !== void 0) return;
|
|
33232
|
+
log("info", { disconnectReason: reason }, "slack socket refreshing");
|
|
33233
|
+
const next = connect(appToken, 1, {
|
|
33234
|
+
attempt: old,
|
|
33235
|
+
reason
|
|
33236
|
+
});
|
|
33237
|
+
replacement = next;
|
|
33238
|
+
next.outcome.then(async (outcome) => {
|
|
33239
|
+
if (outcome === "up") return;
|
|
33240
|
+
await next.closed();
|
|
33241
|
+
if (replacement === next) replacement = void 0;
|
|
33242
|
+
});
|
|
33243
|
+
}
|
|
33244
|
+
/** Reconnects after every drop until stop; stopping is its only exit. */
|
|
33245
|
+
async function supervise(appToken, first) {
|
|
33246
|
+
let serving = first;
|
|
33247
|
+
let attempt = 0;
|
|
33248
|
+
for (;;) {
|
|
33249
|
+
const handedTo = await serving.ended;
|
|
33250
|
+
if (stopping) return;
|
|
33251
|
+
if (handedTo !== void 0) {
|
|
33252
|
+
serving = handedTo;
|
|
33253
|
+
continue;
|
|
33254
|
+
}
|
|
33255
|
+
let next = replacement;
|
|
33256
|
+
replacement = void 0;
|
|
33257
|
+
if (next !== void 0) attempt = 1;
|
|
33258
|
+
for (;;) {
|
|
33259
|
+
if (next === void 0) {
|
|
33260
|
+
attempt += 1;
|
|
33261
|
+
const delayMs = reconnectDelay(attempt, {
|
|
33262
|
+
baseDelayMs,
|
|
33263
|
+
maxDelayMs
|
|
33264
|
+
}, Math.random);
|
|
33265
|
+
log("info", {
|
|
33266
|
+
attempt,
|
|
33267
|
+
delayMs
|
|
33268
|
+
}, "slack socket reconnecting");
|
|
33269
|
+
try {
|
|
33270
|
+
await setTimeout$1(delayMs, void 0, {
|
|
33271
|
+
signal: halt.signal,
|
|
33272
|
+
ref: false
|
|
33273
|
+
});
|
|
33274
|
+
} catch {
|
|
33275
|
+
return;
|
|
33276
|
+
}
|
|
33277
|
+
if (halt.signal.aborted) return;
|
|
33278
|
+
next = connect(appToken, attempt);
|
|
33279
|
+
}
|
|
33280
|
+
current = next;
|
|
33281
|
+
if (await next.outcome === "up") {
|
|
33282
|
+
attempt = 0;
|
|
33283
|
+
serving = next;
|
|
33284
|
+
break;
|
|
33285
|
+
}
|
|
33286
|
+
await next.closed();
|
|
33287
|
+
next = void 0;
|
|
33288
|
+
}
|
|
33289
|
+
}
|
|
33290
|
+
}
|
|
32825
33291
|
function track(work, kind) {
|
|
32826
33292
|
pending.add(work);
|
|
32827
33293
|
work.catch((err) => config.onError?.(err, kind)).finally(() => pending.delete(work)).catch(() => {});
|
|
@@ -32872,58 +33338,43 @@ function createSocket(api, config, botIdentity) {
|
|
|
32872
33338
|
}
|
|
32873
33339
|
return {
|
|
32874
33340
|
async start(nextSink) {
|
|
32875
|
-
if (
|
|
33341
|
+
if (started) throw new Error("Slack gateway already started");
|
|
32876
33342
|
sink = nextSink;
|
|
32877
33343
|
stopping = false;
|
|
32878
|
-
|
|
33344
|
+
const appToken = config.appToken;
|
|
33345
|
+
if (appToken === void 0) return;
|
|
32879
33346
|
await botIdentity();
|
|
32880
|
-
|
|
32881
|
-
|
|
32882
|
-
|
|
32883
|
-
|
|
32884
|
-
|
|
32885
|
-
|
|
32886
|
-
|
|
32887
|
-
|
|
32888
|
-
}
|
|
32889
|
-
});
|
|
32890
|
-
socket = client;
|
|
32891
|
-
client.on("connected", () => {
|
|
32892
|
-
connected = true;
|
|
32893
|
-
track(emit({
|
|
32894
|
-
kind: "connection",
|
|
32895
|
-
state: "up",
|
|
32896
|
-
dedupeKey: `slack:connection:${randomUUID()}`
|
|
32897
|
-
}), "connection");
|
|
32898
|
-
});
|
|
32899
|
-
client.on("close", () => {
|
|
32900
|
-
if (!connected || stopping) return;
|
|
32901
|
-
connected = false;
|
|
32902
|
-
track(emit({
|
|
32903
|
-
kind: "connection",
|
|
32904
|
-
state: "down",
|
|
32905
|
-
dedupeKey: `slack:connection:${randomUUID()}`
|
|
32906
|
-
}), "connection");
|
|
32907
|
-
});
|
|
32908
|
-
client.on("slack_event", (envelope) => {
|
|
32909
|
-
track(handle(envelope), "envelope");
|
|
32910
|
-
});
|
|
32911
|
-
try {
|
|
32912
|
-
await client.start();
|
|
32913
|
-
} catch {
|
|
32914
|
-
socket = void 0;
|
|
33347
|
+
started = true;
|
|
33348
|
+
halt = new AbortController();
|
|
33349
|
+
const first = connect(appToken, 0);
|
|
33350
|
+
current = first;
|
|
33351
|
+
if (await first.outcome !== "up") {
|
|
33352
|
+
await first.closed();
|
|
33353
|
+
started = false;
|
|
33354
|
+
current = void 0;
|
|
32915
33355
|
sink = void 0;
|
|
32916
33356
|
throw new Error("Slack Socket Mode start failed");
|
|
32917
33357
|
}
|
|
33358
|
+
supervisor = supervise(appToken, first);
|
|
32918
33359
|
},
|
|
32919
33360
|
async stop() {
|
|
32920
33361
|
stopping = true;
|
|
32921
|
-
|
|
32922
|
-
|
|
32923
|
-
|
|
33362
|
+
halt.abort();
|
|
33363
|
+
const attempts = [
|
|
33364
|
+
current,
|
|
33365
|
+
replacement,
|
|
33366
|
+
retiring
|
|
33367
|
+
].filter((attempt) => attempt !== void 0);
|
|
33368
|
+
current = void 0;
|
|
33369
|
+
replacement = void 0;
|
|
33370
|
+
retiring = void 0;
|
|
33371
|
+
for (const attempt of attempts) attempt.abandon();
|
|
33372
|
+
await Promise.all(attempts.map((attempt) => attempt.closed()));
|
|
33373
|
+
await supervisor;
|
|
33374
|
+
supervisor = void 0;
|
|
32924
33375
|
while (pending.size > 0) await Promise.allSettled([...pending]);
|
|
32925
33376
|
sink = void 0;
|
|
32926
|
-
|
|
33377
|
+
started = false;
|
|
32927
33378
|
}
|
|
32928
33379
|
};
|
|
32929
33380
|
}
|
|
@@ -34364,7 +34815,8 @@ function createOutboxModule(ctx, gateway, options = {}) {
|
|
|
34364
34815
|
});
|
|
34365
34816
|
updating = Promise.all([updating, update]).then(() => void 0);
|
|
34366
34817
|
return update;
|
|
34367
|
-
}
|
|
34818
|
+
},
|
|
34819
|
+
liveConnections: () => sender.liveConnections()
|
|
34368
34820
|
};
|
|
34369
34821
|
}
|
|
34370
34822
|
// ../daemon/src/systemd.ts
|
|
@@ -34491,6 +34943,9 @@ function createDaemonModules(ctxFor, ports = {}) {
|
|
|
34491
34943
|
now: () => ctx.clock.now(),
|
|
34492
34944
|
onError: (err, work) => {
|
|
34493
34945
|
ctx.log.error({ err }, work === "connection" ? "slack connection event failed" : "slack envelope failed");
|
|
34946
|
+
},
|
|
34947
|
+
onLog: (level, fields, msg) => {
|
|
34948
|
+
ctx.log[level](fields, msg);
|
|
34494
34949
|
}
|
|
34495
34950
|
}));
|
|
34496
34951
|
const hostCtx = ctxFor("host-metrics");
|
|
@@ -34512,6 +34967,7 @@ function createDaemonModules(ctxFor, ports = {}) {
|
|
|
34512
34967
|
reapplyInbound: () => inbound?.reapply,
|
|
34513
34968
|
prPoller: () => boardModules.pollPr,
|
|
34514
34969
|
budgetWaits: () => boardModules.budgetWaits(),
|
|
34970
|
+
liveConnections: () => outbox.liveConnections(),
|
|
34515
34971
|
...ports.productVersion === void 0 ? {} : { productVersion: ports.productVersion },
|
|
34516
34972
|
lastDispatchAt: () => lastDispatchAt,
|
|
34517
34973
|
webOrigin: () => webPort === void 0 ? void 0 : resolveWebOrigin(board.config.web, webPort)
|