@andorra-labs/code 0.1.15 → 0.1.17
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/src/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +15 -10
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +4 -1
- package/dist/src/agent-mcp.js +46 -10
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +22 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +89 -0
- package/dist/src/app-server/workspace.js +457 -11
- package/dist/src/app-server.d.ts +465 -32
- package/dist/src/app-server.js +3308 -517
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +347 -0
- package/dist/src/bridge/control.d.ts +68 -0
- package/dist/src/bridge/control.js +233 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +129 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +540 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +28 -17
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/claude-provider.js +3 -1
- package/dist/src/cli.js +202 -38
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/coding-tools.js +15 -15
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +19 -14
- package/dist/src/commands.d.ts +14 -1
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/completion.js +82 -5
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +202 -77
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +22 -0
- package/dist/src/default-graph.js +1 -1
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +349 -0
- package/dist/src/github-app/client.js +810 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/github-names.d.ts +8 -0
- package/dist/src/github-names.js +8 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +13 -4
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +46 -0
- package/dist/src/graph-preview.js +55 -0
- package/dist/src/graph-provider-portability.js +34 -11
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +88 -10
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +11 -9
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +201 -40
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +3 -1
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +26 -5
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +28 -20
- package/dist/src/graphs.d.ts +34 -1
- package/dist/src/graphs.js +162 -17
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +30 -1
- package/dist/src/membership.js +48 -8
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +7 -1
- package/dist/src/model-metadata.js +39 -17
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.js +3 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +40 -2
- package/dist/src/providers.js +93 -23
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +87 -0
- package/dist/src/pull-request-logs.js +183 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +369 -8
- package/dist/src/pull-requests.js +524 -55
- package/dist/src/react-runtime.js +38 -5
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +379 -90
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +17 -0
- package/dist/src/run-control.js +47 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +9 -1
- package/dist/src/runtime.js +24 -4
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +11 -1
- package/dist/src/sessions.js +17 -4
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +17 -0
- package/dist/src/telemetry/emitter.js +76 -5
- package/dist/src/telemetry/schema.d.ts +47 -2
- package/dist/src/telemetry/schema.js +120 -5
- package/dist/src/telemetry/surface.d.ts +3 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/telemetry/uploader.d.ts +6 -1
- package/dist/src/telemetry/uploader.js +22 -3
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +7 -0
- package/dist/src/test-edit-guard.js +49 -1
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/tools.js +59 -9
- package/dist/src/transcript.js +8 -2
- package/dist/src/types.d.ts +7 -0
- package/dist/src/usage-analytics.js +18 -10
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { AUTH_DEPLOYMENT } from '../auth/deployment.js';
|
|
3
|
+
import { GITHUB_OWNER, GITHUB_REPO } from '../github-names.js';
|
|
4
|
+
import { AuthError } from '../auth/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The engine's client for the account API's GitHub App routes (`design/specs/github-app.md`): the
|
|
7
|
+
* connection status, connecting and disconnecting, the engine's subscriptions, the inbox pull, and the
|
|
8
|
+
* agent's bot writes (which the service makes with an installation token it never hands out). Every call
|
|
9
|
+
* carries the Andorra sign-in's access token, as `src/membership.ts` and `src/bug-report.ts` do.
|
|
10
|
+
*/
|
|
11
|
+
export const GITHUB_COVERAGE_STATES = [
|
|
12
|
+
'covered', 'signed-out', 'not-connected', 'not-installed', 'not-covered', 'suspended', 'permissions-pending',
|
|
13
|
+
'limit', 'pending', 'disabled', 'unavailable',
|
|
14
|
+
];
|
|
15
|
+
/** The reasons the service itself gives for a PR it does not cover. Anything else it says reads as `not-covered`. */
|
|
16
|
+
const SERVICE_REASONS = new Set(['not-connected', 'not-covered', 'suspended', 'permissions-pending', 'limit', 'pending']);
|
|
17
|
+
export const NOTICE_KINDS = ['state', 'head', 'review', 'comment', 'thread', 'checks', 'coverage', 'request'];
|
|
18
|
+
/** Where a `request` notice's comment is: the PR's conversation, a review thread, or a review's own text. */
|
|
19
|
+
export const MENTION_COMMENT_KINDS = ['issue', 'review_comment', 'review'];
|
|
20
|
+
export class GitHubAppError extends Error {
|
|
21
|
+
code;
|
|
22
|
+
retryAfterMs;
|
|
23
|
+
constructor(code, message, retryAfterMs) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.retryAfterMs = retryAfterMs;
|
|
27
|
+
this.name = 'GitHubAppError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const REQUEST_TIMEOUT_MS = 20_000;
|
|
31
|
+
/** A bot write with no answer in this long is of unknown fate (the service's Lambda stops at 20 seconds). */
|
|
32
|
+
export const WRITE_BUDGET_MS = 25_000;
|
|
33
|
+
/** At most this many requests for one write, all with its one `requestId`; a 401's refreshed token is one more. */
|
|
34
|
+
export const WRITE_ATTEMPTS = 3;
|
|
35
|
+
const WRITE_RETRY_MS = [1_000, 2_000];
|
|
36
|
+
const ULID = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
37
|
+
const THREAD_ID = /^PRRT_[A-Za-z0-9_-]{1,120}$/;
|
|
38
|
+
const ANSWER_LIMIT = 1024 * 1024;
|
|
39
|
+
const LOOPBACK = new Set(['127.0.0.1', 'localhost', '[::1]']);
|
|
40
|
+
const ENGINE_ID = /^[A-Za-z0-9_-]{22}$/;
|
|
41
|
+
const CURSOR = /^[A-Za-z0-9._~-]{1,128}$/;
|
|
42
|
+
const NOTICE_ID = /^[A-Za-z0-9._~-]{1,64}$/;
|
|
43
|
+
const OWNER = GITHUB_OWNER;
|
|
44
|
+
const REPO = GITHUB_REPO;
|
|
45
|
+
/** Logins as the service writes them (`LOGIN` in `infra/andorra-auth/github_app.py`): an Enterprise Managed User's
|
|
46
|
+
* `name_shortcode` and its longer length included. */
|
|
47
|
+
const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9_-]{0,62})(?:\[bot\])?$/;
|
|
48
|
+
/** A person's login: never a bot's. */
|
|
49
|
+
const USER_LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9_-]{0,62})$/;
|
|
50
|
+
const SHA = /^[0-9a-f]{40}$/i;
|
|
51
|
+
/** Each comment kind's fragment in the comment's URL. */
|
|
52
|
+
const COMMENT_FRAGMENTS = {
|
|
53
|
+
issue: /^issuecomment-[0-9]{1,20}$/, review_comment: /^discussion_r[0-9]{1,20}$/, review: /^pullrequestreview-[0-9]{1,20}$/,
|
|
54
|
+
};
|
|
55
|
+
const COMMENT_PREFIXES = { IC: 'issue', PRRC: 'review_comment', PRR: 'review' };
|
|
56
|
+
const COMMENT_TYPES = { IssueComment: 'issue', PullRequestReviewComment: 'review_comment', PullRequestReview: 'review' };
|
|
57
|
+
/**
|
|
58
|
+
* The kind of comment a node id names, as the service reads it (`comment_kind` in `github_app.py`): the current
|
|
59
|
+
* form by its prefix (`IC_`, `PRRC_`, `PRR_`), or a legacy id, base64 of `<length>:<Type><number>`. Undefined
|
|
60
|
+
* for any other node, or anything else.
|
|
61
|
+
*/
|
|
62
|
+
export function commentKindOf(id) {
|
|
63
|
+
if (typeof id !== 'string')
|
|
64
|
+
return undefined;
|
|
65
|
+
const current = /^(IC|PRRC|PRR)_[A-Za-z0-9_-]{1,120}$/.exec(id);
|
|
66
|
+
if (current)
|
|
67
|
+
return COMMENT_PREFIXES[current[1]];
|
|
68
|
+
if (!/^[A-Za-z0-9+/]{4,200}={0,2}$/.test(id))
|
|
69
|
+
return undefined;
|
|
70
|
+
const bytes = Buffer.from(id, 'base64');
|
|
71
|
+
// Only a canonical encoding, as Python's strict decoder takes it.
|
|
72
|
+
if (bytes.toString('base64') !== id)
|
|
73
|
+
return undefined;
|
|
74
|
+
const legacy = /^[0-9]{1,4}:(IssueComment|PullRequestReviewComment|PullRequestReview)[0-9]{1,20}$/.exec(bytes.toString('latin1'));
|
|
75
|
+
return legacy ? COMMENT_TYPES[legacy[1]] : undefined;
|
|
76
|
+
}
|
|
77
|
+
/** Any comment a `react` may name: a node id of one of the three kinds. */
|
|
78
|
+
export const isMentionCommentId = (value) => commentKindOf(value) !== undefined;
|
|
79
|
+
const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?Z$/;
|
|
80
|
+
export const isEngineId = (value) => typeof value === 'string' && ENGINE_ID.test(value);
|
|
81
|
+
export const isCursor = (value) => typeof value === 'string' && CURSOR.test(value);
|
|
82
|
+
/**
|
|
83
|
+
* Where the account API is, and which token to send. Production always uses the stamped API and the
|
|
84
|
+
* signed-in account's token. Only with `ANDORRA_TEST_MODE=1`, and only with both `ANDORRA_TEST_ACCOUNT_API`
|
|
85
|
+
* (a staging stack over `https:`, or a fake on a loopback `http:` origin) and `ANDORRA_TEST_ACCOUNT_TOKEN`,
|
|
86
|
+
* do the GitHub App routes go elsewhere, and then always with the test token: the signed-in account's token
|
|
87
|
+
* is never sent anywhere but the production API, and a test token never to it. Either variable alone is
|
|
88
|
+
* ignored.
|
|
89
|
+
*/
|
|
90
|
+
export function accountApiTarget(env = process.env) {
|
|
91
|
+
const production = { baseUrl: AUTH_DEPLOYMENT.apiBaseUrl, loopback: false };
|
|
92
|
+
const token = env.ANDORRA_TEST_ACCOUNT_TOKEN?.trim();
|
|
93
|
+
if (env.ANDORRA_TEST_MODE !== '1' || !env.ANDORRA_TEST_ACCOUNT_API || !token)
|
|
94
|
+
return production;
|
|
95
|
+
let url;
|
|
96
|
+
try {
|
|
97
|
+
url = new URL(env.ANDORRA_TEST_ACCOUNT_API);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return production;
|
|
101
|
+
}
|
|
102
|
+
const loopback = url.protocol === 'http:' && LOOPBACK.has(url.hostname);
|
|
103
|
+
if ((url.protocol !== 'https:' && !loopback) || url.username || url.password || url.search || url.hash)
|
|
104
|
+
return production;
|
|
105
|
+
return { baseUrl: url.href.replace(/\/+$/, ''), token, loopback };
|
|
106
|
+
}
|
|
107
|
+
function baseOf(deps) {
|
|
108
|
+
let url;
|
|
109
|
+
try {
|
|
110
|
+
url = new URL(deps.apiBaseUrl());
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
throw new GitHubAppError('unavailable', 'The Andorra account service is not configured in this build.');
|
|
114
|
+
}
|
|
115
|
+
const loopback = deps.allowLoopbackHttp === true && url.protocol === 'http:' && LOOPBACK.has(url.hostname);
|
|
116
|
+
if ((url.protocol !== 'https:' && !loopback) || url.username || url.password || url.search || url.hash) {
|
|
117
|
+
throw new GitHubAppError('unavailable', 'The Andorra account service is not configured in this build.');
|
|
118
|
+
}
|
|
119
|
+
return url.href.replace(/\/+$/, '');
|
|
120
|
+
}
|
|
121
|
+
async function boundedText(response, limit = ANSWER_LIMIT) {
|
|
122
|
+
const reader = response.body?.getReader();
|
|
123
|
+
if (!reader)
|
|
124
|
+
return '';
|
|
125
|
+
const chunks = [];
|
|
126
|
+
let size = 0;
|
|
127
|
+
try {
|
|
128
|
+
for (;;) {
|
|
129
|
+
const { done, value } = await reader.read();
|
|
130
|
+
if (done)
|
|
131
|
+
break;
|
|
132
|
+
size += value.byteLength;
|
|
133
|
+
if (size > limit)
|
|
134
|
+
return undefined;
|
|
135
|
+
chunks.push(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
await reader.cancel().catch(() => { });
|
|
140
|
+
reader.releaseLock();
|
|
141
|
+
}
|
|
142
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
143
|
+
}
|
|
144
|
+
function retryAfterMs(response) {
|
|
145
|
+
const header = response.headers.get('retry-after');
|
|
146
|
+
if (header === null)
|
|
147
|
+
return undefined;
|
|
148
|
+
const seconds = Number(header);
|
|
149
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
150
|
+
return Math.min(seconds, 3600) * 1000;
|
|
151
|
+
const at = Date.parse(header);
|
|
152
|
+
return Number.isFinite(at) ? Math.max(0, Math.min(at - Date.now(), 3_600_000)) : undefined;
|
|
153
|
+
}
|
|
154
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
155
|
+
const positive = (value) => Number.isSafeInteger(value) && value > 0;
|
|
156
|
+
export function parseNotice(value) {
|
|
157
|
+
if (!isRecord(value) || typeof value.id !== 'string' || !NOTICE_ID.test(value.id))
|
|
158
|
+
return undefined;
|
|
159
|
+
if (typeof value.kind !== 'string' || !NOTICE_KINDS.includes(value.kind))
|
|
160
|
+
return undefined;
|
|
161
|
+
const notice = { id: value.id, kind: value.kind };
|
|
162
|
+
if (typeof value.at === 'string' && ISO.test(value.at) && Number.isFinite(Date.parse(value.at)))
|
|
163
|
+
notice.at = value.at;
|
|
164
|
+
if (notice.kind === 'coverage')
|
|
165
|
+
return notice;
|
|
166
|
+
if (notice.kind === 'request')
|
|
167
|
+
return parseRequest(value, notice);
|
|
168
|
+
// Every other kind names one PR: by repository id and number, with owner and name for display.
|
|
169
|
+
if (!positive(value.number) || value.number > 999_999_999)
|
|
170
|
+
return undefined;
|
|
171
|
+
notice.number = value.number;
|
|
172
|
+
if (positive(value.repoId))
|
|
173
|
+
notice.repoId = value.repoId;
|
|
174
|
+
if (typeof value.owner === 'string' && OWNER.test(value.owner))
|
|
175
|
+
notice.owner = value.owner;
|
|
176
|
+
if (typeof value.repo === 'string' && REPO.test(value.repo))
|
|
177
|
+
notice.repo = value.repo;
|
|
178
|
+
if (notice.repoId === undefined && (notice.owner === undefined || notice.repo === undefined))
|
|
179
|
+
return undefined;
|
|
180
|
+
if (typeof value.action === 'string' && /^[a-z_]{1,40}$/.test(value.action))
|
|
181
|
+
notice.action = value.action;
|
|
182
|
+
if (typeof value.actor === 'string' && LOGIN.test(value.actor))
|
|
183
|
+
notice.actor = value.actor;
|
|
184
|
+
if (typeof value.actorType === 'string' && /^[A-Za-z]{1,20}$/.test(value.actorType))
|
|
185
|
+
notice.actorType = value.actorType;
|
|
186
|
+
if (typeof value.headSha === 'string' && SHA.test(value.headSha))
|
|
187
|
+
notice.headSha = value.headSha.toLowerCase();
|
|
188
|
+
return notice;
|
|
189
|
+
}
|
|
190
|
+
/** A notice `parseNotice` read as a `request`, with every field it requires. */
|
|
191
|
+
export const isMentionNotice = (notice) => notice.kind === 'request' && notice.owner !== undefined && notice.repo !== undefined && notice.repoId !== undefined && notice.number !== undefined
|
|
192
|
+
&& notice.actor !== undefined && notice.actorType === 'User' && notice.commentId !== undefined && notice.commentKind !== undefined && notice.commentUrl !== undefined;
|
|
193
|
+
/**
|
|
194
|
+
* A `request` notice (phase 3, a comment that mentioned the bot) is read strictly: every field the receiver
|
|
195
|
+
* writes must be there and well formed, or the notice is dropped, since it can wake a task. It carries the
|
|
196
|
+
* comment's node id and URL, never its text, and no other field of it is read: a stray `body` or `text` never
|
|
197
|
+
* reaches the engine. The actor is a person (`actorType` `User`, no `[bot]` login), and the comment's URL is on
|
|
198
|
+
* the notice's own PR, with the fragment its kind has.
|
|
199
|
+
*/
|
|
200
|
+
function parseRequest(value, base) {
|
|
201
|
+
const { owner, repo, repoId, number, actor, actorType, commentId, commentKind, commentUrl, commentAt } = value;
|
|
202
|
+
if (typeof owner !== 'string' || !OWNER.test(owner) || typeof repo !== 'string' || !REPO.test(repo))
|
|
203
|
+
return undefined;
|
|
204
|
+
if (!positive(repoId) || !positive(number) || number > 999_999_999)
|
|
205
|
+
return undefined;
|
|
206
|
+
if (typeof actor !== 'string' || !USER_LOGIN.test(actor) || actorType !== 'User')
|
|
207
|
+
return undefined;
|
|
208
|
+
if (typeof commentKind !== 'string' || !MENTION_COMMENT_KINDS.includes(commentKind))
|
|
209
|
+
return undefined;
|
|
210
|
+
if (typeof commentId !== 'string' || commentKindOf(commentId) !== commentKind)
|
|
211
|
+
return undefined;
|
|
212
|
+
if (typeof commentUrl !== 'string' || commentUrl.length > 512)
|
|
213
|
+
return undefined;
|
|
214
|
+
const page = /^https:\/\/github\.com\/([A-Za-z0-9_.-]{1,100})\/([A-Za-z0-9_.-]{1,100})\/pull\/([0-9]{1,9})#([^#?\s]+)$/.exec(commentUrl);
|
|
215
|
+
if (!page || page[1].toLowerCase() !== owner.toLowerCase() || page[2].toLowerCase() !== repo.toLowerCase()
|
|
216
|
+
|| Number(page[3]) !== number || !COMMENT_FRAGMENTS[commentKind].test(page[4]))
|
|
217
|
+
return undefined;
|
|
218
|
+
// Optional, for notices from a receiver that predates it; when it is there, it must be a time.
|
|
219
|
+
if (commentAt !== undefined && (typeof commentAt !== 'string' || !ISO.test(commentAt) || !Number.isFinite(Date.parse(commentAt))))
|
|
220
|
+
return undefined;
|
|
221
|
+
return {
|
|
222
|
+
id: base.id, kind: 'request', ...(base.at === undefined ? {} : { at: base.at }),
|
|
223
|
+
owner, repo, repoId: repoId, number: number, actor, actorType: 'User',
|
|
224
|
+
commentId, commentKind: commentKind, commentUrl, ...(commentAt === undefined ? {} : { commentAt: commentAt }),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function parseStatus(value) {
|
|
228
|
+
const enabled = value.enabled === true;
|
|
229
|
+
const status = { enabled, allowed: enabled && value.allowed !== false, connection: null, installations: [] };
|
|
230
|
+
if (typeof value.bot === 'string' && LOGIN.test(value.bot))
|
|
231
|
+
status.bot = value.bot;
|
|
232
|
+
if (typeof value.installUrl === 'string' && value.installUrl.startsWith('https://github.com/') && value.installUrl.length <= 512)
|
|
233
|
+
status.installUrl = value.installUrl;
|
|
234
|
+
const connection = value.connection;
|
|
235
|
+
if (isRecord(connection) && typeof connection.login === 'string' && LOGIN.test(connection.login) && positive(connection.githubUserId)) {
|
|
236
|
+
status.connection = { login: connection.login, githubUserId: connection.githubUserId,
|
|
237
|
+
...(typeof connection.linkedAt === 'string' && connection.linkedAt.length <= 40 ? { linkedAt: connection.linkedAt } : {}) };
|
|
238
|
+
}
|
|
239
|
+
if (Array.isArray(value.installations)) {
|
|
240
|
+
for (const entry of value.installations.slice(0, 100)) {
|
|
241
|
+
if (!isRecord(entry) || !positive(entry.id) || typeof entry.account !== 'string' || !OWNER.test(entry.account))
|
|
242
|
+
continue;
|
|
243
|
+
status.installations.push({
|
|
244
|
+
id: entry.id, account: entry.account, type: entry.type === 'Organization' ? 'Organization' : 'User',
|
|
245
|
+
selection: entry.selection === 'all' ? 'all' : 'selected', suspended: entry.suspended === true, permissionsPending: entry.permissionsPending === true,
|
|
246
|
+
...(typeof entry.manageUrl === 'string' && entry.manageUrl.startsWith('https://github.com/') && entry.manageUrl.length <= 512 ? { manageUrl: entry.manageUrl } : {}),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return status;
|
|
251
|
+
}
|
|
252
|
+
function parseCoverage(value) {
|
|
253
|
+
if (!isRecord(value) || typeof value.owner !== 'string' || typeof value.repo !== 'string' || !positive(value.number))
|
|
254
|
+
return undefined;
|
|
255
|
+
const entry = { owner: value.owner, repo: value.repo, number: value.number, covered: value.covered === true };
|
|
256
|
+
if (positive(value.repoId))
|
|
257
|
+
entry.repoId = value.repoId;
|
|
258
|
+
if (!entry.covered)
|
|
259
|
+
entry.reason = typeof value.reason === 'string' && SERVICE_REASONS.has(value.reason) ? value.reason : 'not-covered';
|
|
260
|
+
return entry;
|
|
261
|
+
}
|
|
262
|
+
const BOT_WRITE_ACTIONS = new Set(['reply', 'resolve', 'unresolve', 'comment', 'react']);
|
|
263
|
+
/** The service's own limit on a bot write's body. */
|
|
264
|
+
export const BOT_BODY_BYTES = 16_384;
|
|
265
|
+
/** The first field of a bot write the service would refuse (`400 bad_request`), checked as it checks them; undefined when none. */
|
|
266
|
+
export function botWriteProblem(request) {
|
|
267
|
+
if (typeof request.requestId !== 'string' || !ULID.test(request.requestId))
|
|
268
|
+
return 'requestId';
|
|
269
|
+
if (typeof request.owner !== 'string' || !OWNER.test(request.owner))
|
|
270
|
+
return 'owner';
|
|
271
|
+
if (typeof request.repo !== 'string' || !REPO.test(request.repo))
|
|
272
|
+
return 'repo';
|
|
273
|
+
if (!positive(request.number) || request.number >= 1_000_000_000)
|
|
274
|
+
return 'number';
|
|
275
|
+
if (!BOT_WRITE_ACTIONS.has(request.action))
|
|
276
|
+
return 'action';
|
|
277
|
+
const onThread = request.action === 'reply' || request.action === 'resolve' || request.action === 'unresolve';
|
|
278
|
+
if (onThread ? typeof request.threadId !== 'string' || !THREAD_ID.test(request.threadId) : request.threadId !== undefined)
|
|
279
|
+
return 'threadId';
|
|
280
|
+
// A reaction names the comment it is on, and carries no text of its own.
|
|
281
|
+
if (request.action === 'react' ? !isMentionCommentId(request.commentId) : request.commentId !== undefined)
|
|
282
|
+
return 'commentId';
|
|
283
|
+
const needsBody = request.action === 'reply' || request.action === 'comment';
|
|
284
|
+
if (needsBody ? typeof request.body !== 'string' || request.body.trim() === '' || Buffer.byteLength(request.body, 'utf8') > BOT_BODY_BYTES : request.body !== undefined)
|
|
285
|
+
return 'body';
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Codes Node's fetch gives a failure before any byte of the request left the machine: a refused connection,
|
|
290
|
+
* a name that did not resolve, an unreachable network, a connect timeout, a TLS handshake that failed. Any
|
|
291
|
+
* other failure may have come after the request was sent.
|
|
292
|
+
*/
|
|
293
|
+
const NOT_SENT = new Set([
|
|
294
|
+
'ECONNREFUSED', 'ENOTFOUND', 'EAI_AGAIN', 'EAI_NONAME', 'EAI_FAIL', 'EHOSTUNREACH', 'ENETUNREACH', 'UND_ERR_CONNECT_TIMEOUT',
|
|
295
|
+
// The TLS handshake, which ends before the request is written: the certificate checks, the name check, the
|
|
296
|
+
// handshake's own timeout and the protocol it could not agree. An SSL error later in the stream (a bad record
|
|
297
|
+
// MAC, a decryption failure) may come after the request left, so it is not here.
|
|
298
|
+
'CERT_HAS_EXPIRED', 'CERT_NOT_YET_VALID', 'CERT_REVOKED', 'CERT_UNTRUSTED', 'CERT_REJECTED', 'CERT_SIGNATURE_FAILURE',
|
|
299
|
+
'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN', 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'UNABLE_TO_GET_ISSUER_CERT',
|
|
300
|
+
'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'ERR_TLS_CERT_ALTNAME_INVALID', 'ERR_TLS_HANDSHAKE_TIMEOUT',
|
|
301
|
+
'ERR_SSL_WRONG_VERSION_NUMBER', 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE', 'ERR_SSL_TLSV1_ALERT_PROTOCOL_VERSION',
|
|
302
|
+
'ERR_SSL_UNSUPPORTED_PROTOCOL', 'ERR_SSL_NO_PROTOCOLS_AVAILABLE', 'ERR_SSL_TLSV1_ALERT_UNKNOWN_CA',
|
|
303
|
+
'ERR_SSL_SSLV3_ALERT_BAD_CERTIFICATE', 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR', 'ERR_SSL_PACKET_LENGTH_TOO_LONG',
|
|
304
|
+
]);
|
|
305
|
+
export function failedBeforeSending(error) {
|
|
306
|
+
let cause = error;
|
|
307
|
+
for (let depth = 0; depth < 4 && typeof cause === 'object' && cause !== null; depth++) {
|
|
308
|
+
const code = cause.code;
|
|
309
|
+
if (typeof code === 'string' && NOT_SENT.has(code))
|
|
310
|
+
return true;
|
|
311
|
+
cause = cause.cause;
|
|
312
|
+
}
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
/** What one answer of `POST /v1/github/writes` means (design/specs/github-app.md, "Answers, and what the engine does with each"). */
|
|
316
|
+
function writeVerdict(status, answer) {
|
|
317
|
+
const error = typeof answer?.error === 'string' ? answer.error : undefined;
|
|
318
|
+
const notWritten = (reason, settled) => ({ outcome: { kind: 'not-written', reason }, settled });
|
|
319
|
+
const unknown = (detail, settled, retry = false) => ({ outcome: { kind: 'unknown', detail }, settled, retry });
|
|
320
|
+
if (status >= 200 && status < 300) {
|
|
321
|
+
if (answer?.ok === true && typeof answer.as === 'string' && LOGIN.test(answer.as)) {
|
|
322
|
+
const url = typeof answer.url === 'string' && answer.url.length <= 2048 && /^https:\/\/github\.com\/[^\s]*$/.test(answer.url) ? answer.url : undefined;
|
|
323
|
+
return { outcome: { kind: 'written', as: answer.as, ...(url === undefined ? {} : { url }) }, settled: true };
|
|
324
|
+
}
|
|
325
|
+
if (answer?.enabled === false)
|
|
326
|
+
return notWritten('disabled', false);
|
|
327
|
+
return unknown('Andorra\'s service answered something this version does not understand', false);
|
|
328
|
+
}
|
|
329
|
+
// The service says outright that nothing was written: GitHub refused it, or the service failed before it.
|
|
330
|
+
if (answer?.written === false)
|
|
331
|
+
return notWritten(error === 'github' ? 'github-refused' : 'unavailable', true);
|
|
332
|
+
if (status === 400) {
|
|
333
|
+
const field = typeof answer?.field === 'string' && /^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(answer.field) ? answer.field : undefined;
|
|
334
|
+
// The same body is refused the same way on every attempt, so an earlier one was refused too.
|
|
335
|
+
return { outcome: { kind: 'refused', reason: 'bad-request', ...(field === undefined ? {} : { field }) }, settled: true };
|
|
336
|
+
}
|
|
337
|
+
if (status === 403)
|
|
338
|
+
return error === 'not_covered' ? notWritten('not-covered', true) : notWritten(error === 'not_allowed' ? 'not-allowed' : 'forbidden', false);
|
|
339
|
+
if (status === 404)
|
|
340
|
+
return error === 'not_found' ? { outcome: { kind: 'refused', reason: 'not-found' }, settled: true } : notWritten('no-route', false);
|
|
341
|
+
// The service's own limits answer `rate_limited`; API Gateway's throttle answers a 429 of its own, before the route.
|
|
342
|
+
if (status === 429)
|
|
343
|
+
return notWritten('rate-limited', error === 'rate_limited');
|
|
344
|
+
if (status === 503 && error === 'late')
|
|
345
|
+
return notWritten('late', true);
|
|
346
|
+
if (status === 502 && error === 'github') {
|
|
347
|
+
const github = answer?.status;
|
|
348
|
+
if (github === 403 || github === 404 || github === 422)
|
|
349
|
+
return notWritten('github-refused', true);
|
|
350
|
+
return unknown(`GitHub's answer to the bot was not seen (${typeof github === 'number' && github > 0 ? `HTTP ${github}` : 'no answer'})`, true);
|
|
351
|
+
}
|
|
352
|
+
if (status === 503 && error === 'in_progress')
|
|
353
|
+
return unknown('Andorra\'s service was still finishing the write', false, true);
|
|
354
|
+
if (status >= 500)
|
|
355
|
+
return unknown(`Andorra's service failed (HTTP ${status})`, false, true);
|
|
356
|
+
return unknown(`Andorra's service answered HTTP ${status}`, false);
|
|
357
|
+
}
|
|
358
|
+
/** The opening of the review marker that only the service writes; it is refused in every body (R1). */
|
|
359
|
+
export const REVIEW_MARKER_OPENING = /<!--\s*andorra-review/i;
|
|
360
|
+
const REVIEW_BODY_BYTES = 16_384;
|
|
361
|
+
const REVIEW_COMMENT_BYTES = 4_096;
|
|
362
|
+
const REVIEW_COMMENTS = 30;
|
|
363
|
+
const REVIEW_PATH_BYTES = 1_024;
|
|
364
|
+
const REVIEW_REQUEST_BYTES = 163_840;
|
|
365
|
+
const REVIEW_ID = /^PRR_[A-Za-z0-9_-]{1,120}$/;
|
|
366
|
+
function reviewPathProblem(path) {
|
|
367
|
+
if (typeof path !== 'string' || path === '' || Buffer.byteLength(path, 'utf8') > REVIEW_PATH_BYTES)
|
|
368
|
+
return true;
|
|
369
|
+
if (path.startsWith('/') || path.includes('\0') || path.includes('\\'))
|
|
370
|
+
return true;
|
|
371
|
+
return path.split('/').some(segment => segment === '..');
|
|
372
|
+
}
|
|
373
|
+
/** Text the service takes: not blank to Python's `strip()` (which also strips U+001C to U+001F and U+0085), within `limit` bytes, without the marker. */
|
|
374
|
+
const reviewText = (value, limit) => typeof value === 'string' && !/^[\s\x1c-\x1f\x85]*$/.test(value) && Buffer.byteLength(value, 'utf8') <= limit && !REVIEW_MARKER_OPENING.test(value);
|
|
375
|
+
/** The first field of a `review-check` or `review` the service would refuse (`400 bad_request`), checked as it checks them. */
|
|
376
|
+
export function reviewWriteProblem(request, action) {
|
|
377
|
+
if (typeof request.requestId !== 'string' || !ULID.test(request.requestId))
|
|
378
|
+
return 'requestId';
|
|
379
|
+
if (typeof request.owner !== 'string' || !OWNER.test(request.owner))
|
|
380
|
+
return 'owner';
|
|
381
|
+
if (typeof request.repo !== 'string' || !REPO.test(request.repo))
|
|
382
|
+
return 'repo';
|
|
383
|
+
if (!positive(request.number) || request.number >= 1_000_000_000)
|
|
384
|
+
return 'number';
|
|
385
|
+
if (action === 'review-check')
|
|
386
|
+
return undefined;
|
|
387
|
+
const review = request;
|
|
388
|
+
if (typeof review.commitId !== 'string' || !/^[0-9a-f]{40}$/.test(review.commitId))
|
|
389
|
+
return 'commitId';
|
|
390
|
+
if (typeof review.loop !== 'string' || !ULID.test(review.loop))
|
|
391
|
+
return 'loop';
|
|
392
|
+
if (!positive(review.rounds) || review.rounds > 10)
|
|
393
|
+
return 'rounds';
|
|
394
|
+
if (!positive(review.round) || review.round > review.rounds)
|
|
395
|
+
return 'round';
|
|
396
|
+
if (typeof review.body === 'string' && REVIEW_MARKER_OPENING.test(review.body))
|
|
397
|
+
return 'marker';
|
|
398
|
+
if (!reviewText(review.body, REVIEW_BODY_BYTES))
|
|
399
|
+
return 'body';
|
|
400
|
+
if (!Array.isArray(review.comments) || review.comments.length > REVIEW_COMMENTS)
|
|
401
|
+
return 'comments';
|
|
402
|
+
for (const comment of review.comments) {
|
|
403
|
+
if (!isRecord(comment) || reviewPathProblem(comment.path))
|
|
404
|
+
return 'comments';
|
|
405
|
+
if (!positive(comment.line) || (comment.side !== 'LEFT' && comment.side !== 'RIGHT'))
|
|
406
|
+
return 'comments';
|
|
407
|
+
if (comment.startLine !== undefined && (!positive(comment.startLine) || comment.startLine >= comment.line || (comment.startSide !== 'LEFT' && comment.startSide !== 'RIGHT')))
|
|
408
|
+
return 'comments';
|
|
409
|
+
if (comment.startLine === undefined && comment.startSide !== undefined)
|
|
410
|
+
return 'comments';
|
|
411
|
+
if (typeof comment.body === 'string' && REVIEW_MARKER_OPENING.test(comment.body))
|
|
412
|
+
return 'marker';
|
|
413
|
+
if (!reviewText(comment.body, REVIEW_COMMENT_BYTES))
|
|
414
|
+
return 'comments';
|
|
415
|
+
}
|
|
416
|
+
return undefined;
|
|
417
|
+
}
|
|
418
|
+
/** What one answer of `POST /v1/github/writes` means for `review` and `review-check`. */
|
|
419
|
+
export function reviewVerdict(action, status, answer, retryAfter) {
|
|
420
|
+
const error = typeof answer?.error === 'string' ? answer.error : undefined;
|
|
421
|
+
if (status >= 200 && status < 300) {
|
|
422
|
+
if (answer?.enabled === false)
|
|
423
|
+
return { kind: 'service-off' };
|
|
424
|
+
if (answer?.ok !== true)
|
|
425
|
+
return { kind: 'unknown', detail: 'Andorra\'s service answered something this version does not understand' };
|
|
426
|
+
if (action === 'review-check')
|
|
427
|
+
return { kind: 'ok' };
|
|
428
|
+
// A bare `ok` without the review's id is not proof of a post: the marker check decides.
|
|
429
|
+
if (typeof answer.reviewId !== 'string' || !REVIEW_ID.test(answer.reviewId) || typeof answer.as !== 'string' || !LOGIN.test(answer.as)) {
|
|
430
|
+
return { kind: 'unknown', detail: 'Andorra\'s service answered ok without the review\'s id' };
|
|
431
|
+
}
|
|
432
|
+
const url = typeof answer.url === 'string' && answer.url.length <= 2048 && /^https:\/\/github\.com\/[^\s]*$/.test(answer.url) ? answer.url : undefined;
|
|
433
|
+
const comments = Number.isSafeInteger(answer.comments) && answer.comments >= 0 ? answer.comments : undefined;
|
|
434
|
+
return { kind: 'posted', reviewId: answer.reviewId, as: answer.as, ...(url === undefined ? {} : { url }), ...(comments === undefined ? {} : { comments }) };
|
|
435
|
+
}
|
|
436
|
+
if (status === 400) {
|
|
437
|
+
const field = typeof answer?.field === 'string' && /^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(answer.field) ? answer.field : undefined;
|
|
438
|
+
return { kind: 'bad-request', ...(field === undefined ? {} : { field }) };
|
|
439
|
+
}
|
|
440
|
+
if (status === 403)
|
|
441
|
+
return error === 'plan' ? { kind: 'plan' } : { kind: 'not-covered', error: error !== undefined && /^[a-z_]{1,40}$/.test(error) ? error : 'forbidden' };
|
|
442
|
+
if (status === 404)
|
|
443
|
+
return { kind: 'not-found' };
|
|
444
|
+
if (status === 409) {
|
|
445
|
+
if (error === 'stale_head')
|
|
446
|
+
return { kind: 'stale-head', ...(typeof answer?.head === 'string' && /^[0-9a-f]{40}$/.test(answer.head) ? { head: answer.head } : {}) };
|
|
447
|
+
if (error === 'closed')
|
|
448
|
+
return { kind: 'closed', merged: answer?.merged === true };
|
|
449
|
+
if (error === 'loop_taken')
|
|
450
|
+
return { kind: 'loop-taken' };
|
|
451
|
+
return { kind: 'unknown', detail: `Andorra's service answered HTTP 409 (${error ?? 'no reason'})` };
|
|
452
|
+
}
|
|
453
|
+
if (status === 429) {
|
|
454
|
+
// API Gateway's own throttle answers before the route, with no `rate_limited`: nothing was posted either.
|
|
455
|
+
if (error !== 'rate_limited')
|
|
456
|
+
return { kind: 'unavailable', detail: 'Andorra\'s service is throttling requests' };
|
|
457
|
+
return { kind: 'rate-limited', ...(retryAfter === undefined ? {} : { retryAfterMs: retryAfter }) };
|
|
458
|
+
}
|
|
459
|
+
if (status === 502 && error === 'github') {
|
|
460
|
+
const github = typeof answer?.status === 'number' ? answer.status : 0;
|
|
461
|
+
if (answer?.written !== false)
|
|
462
|
+
return { kind: 'unknown', detail: `GitHub's answer to the bot was not seen (${github > 0 ? `HTTP ${github}` : 'no answer'})` };
|
|
463
|
+
if (github === 422 || github === 403 || github === 404)
|
|
464
|
+
return { kind: 'github-refused', status: github };
|
|
465
|
+
return { kind: 'unavailable', detail: `GitHub failed (${github > 0 ? `HTTP ${github}` : 'no answer'}) and nothing was posted` };
|
|
466
|
+
}
|
|
467
|
+
if (status === 503 && error === 'late')
|
|
468
|
+
return { kind: 'unavailable', detail: 'Andorra\'s service did not start the review in time' };
|
|
469
|
+
if (status === 503 && error === 'in_progress')
|
|
470
|
+
return { kind: 'in-progress' };
|
|
471
|
+
if (answer?.written === false)
|
|
472
|
+
return { kind: 'unavailable', detail: `Andorra's service failed (HTTP ${status}) before posting` };
|
|
473
|
+
return { kind: 'unknown', detail: `Andorra's service answered HTTP ${status}` };
|
|
474
|
+
}
|
|
475
|
+
export function createGitHubAppClient(deps) {
|
|
476
|
+
async function token(signal) {
|
|
477
|
+
let value;
|
|
478
|
+
try {
|
|
479
|
+
value = await deps.accessToken(signal);
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
signal?.throwIfAborted();
|
|
483
|
+
if (error instanceof AuthError && (error.code === 'login_required' || error.code === 'invalid_token'))
|
|
484
|
+
throw new GitHubAppError('signed-out', 'Sign in to Andorra first.');
|
|
485
|
+
throw new GitHubAppError('unavailable', 'The Andorra sign-in could not be read just now.');
|
|
486
|
+
}
|
|
487
|
+
if (!value)
|
|
488
|
+
throw new GitHubAppError('signed-out', 'Sign in to Andorra first.');
|
|
489
|
+
return value;
|
|
490
|
+
}
|
|
491
|
+
/** `emptyOk`: a 2xx with an empty body is a success with nothing to say (a DELETE may answer so). */
|
|
492
|
+
async function call(method, path, body, signal, emptyOk = false) {
|
|
493
|
+
const base = baseOf(deps);
|
|
494
|
+
let bearer = await token(signal);
|
|
495
|
+
for (let attempt = 0;; attempt++) {
|
|
496
|
+
const bounded = signal ? AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]) : AbortSignal.timeout(REQUEST_TIMEOUT_MS);
|
|
497
|
+
let response;
|
|
498
|
+
try {
|
|
499
|
+
response = await deps.fetch(`${base}${path}`, {
|
|
500
|
+
method, redirect: 'error', signal: bounded,
|
|
501
|
+
headers: { Authorization: `Bearer ${bearer}`, ...(body === undefined ? {} : { 'Content-Type': 'application/json' }) },
|
|
502
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
signal?.throwIfAborted();
|
|
507
|
+
throw new GitHubAppError('unavailable', 'The Andorra account service could not be reached.');
|
|
508
|
+
}
|
|
509
|
+
if (response.status === 401) {
|
|
510
|
+
await response.body?.cancel().catch(() => { });
|
|
511
|
+
// A token another process refreshed meanwhile gets one more try; the same token refused twice is a failure.
|
|
512
|
+
const again = attempt === 0 ? await token(signal) : bearer;
|
|
513
|
+
if (again !== bearer) {
|
|
514
|
+
bearer = again;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
throw new GitHubAppError('unauthorized', 'The Andorra account service refused the sign-in.');
|
|
518
|
+
}
|
|
519
|
+
// An oversize, unreadable, empty or non-object body is no answer at all: never `{}`, which would read as
|
|
520
|
+
// `enabled` missing and could be taken for the kill switch.
|
|
521
|
+
const text = await boundedText(response).catch(() => undefined);
|
|
522
|
+
let value;
|
|
523
|
+
try {
|
|
524
|
+
value = text ? JSON.parse(text) : undefined;
|
|
525
|
+
}
|
|
526
|
+
catch {
|
|
527
|
+
value = undefined;
|
|
528
|
+
}
|
|
529
|
+
const answer = isRecord(value) ? value : response.status === 204 || (emptyOk && text === '') ? {} : undefined;
|
|
530
|
+
if (response.status === 429)
|
|
531
|
+
throw new GitHubAppError('rate-limited', 'The Andorra account service asked to wait.', retryAfterMs(response) ?? 10_000);
|
|
532
|
+
if (response.status === 403) {
|
|
533
|
+
if (answer?.error === 'not_allowed')
|
|
534
|
+
throw new GitHubAppError('not-allowed', 'This Andorra account is not in the GitHub App\'s preview.');
|
|
535
|
+
throw new GitHubAppError('forbidden', 'The Andorra account service refused the request.');
|
|
536
|
+
}
|
|
537
|
+
if (response.status === 404)
|
|
538
|
+
throw new GitHubAppError('not-found', 'The Andorra account service does not offer the GitHub App here.');
|
|
539
|
+
if (response.status === 400 || response.status === 413)
|
|
540
|
+
throw new GitHubAppError('invalid-request', 'The Andorra account service refused the request as malformed.');
|
|
541
|
+
if (response.status >= 500 || response.status < 200 || response.status >= 300)
|
|
542
|
+
throw new GitHubAppError('unavailable', `The Andorra account service failed (HTTP ${response.status}).`);
|
|
543
|
+
if (!answer)
|
|
544
|
+
throw new GitHubAppError('invalid-answer', 'The Andorra account service answered something this version does not understand.');
|
|
545
|
+
return answer;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
async status(signal) {
|
|
550
|
+
const answer = await call('GET', '/github', undefined, signal);
|
|
551
|
+
if (typeof answer.enabled !== 'boolean')
|
|
552
|
+
throw new GitHubAppError('invalid-answer', 'The GitHub App status carried no enabled flag.');
|
|
553
|
+
return parseStatus(answer);
|
|
554
|
+
},
|
|
555
|
+
async connect(mode, signal) {
|
|
556
|
+
const answer = await call('POST', '/github/connect', { mode }, signal);
|
|
557
|
+
if (answer.enabled === false)
|
|
558
|
+
return { enabled: false };
|
|
559
|
+
const url = answer.url;
|
|
560
|
+
// The desktop opens this in a browser: only GitHub's own pages are accepted.
|
|
561
|
+
if (typeof url !== 'string' || url.length > 4096 || !/^https:\/\/github\.com\/(?:apps\/[A-Za-z0-9-]+\/installations\/new|login\/oauth\/authorize)\?/.test(url)) {
|
|
562
|
+
throw new GitHubAppError('invalid-answer', 'The Andorra account service answered a connect link this version does not open.');
|
|
563
|
+
}
|
|
564
|
+
return { enabled: true, url };
|
|
565
|
+
},
|
|
566
|
+
async disconnect(signal) {
|
|
567
|
+
const answer = await call('DELETE', '/github/connection', undefined, signal, true);
|
|
568
|
+
return { enabled: answer.enabled !== false };
|
|
569
|
+
},
|
|
570
|
+
async subscribe(engine, pullRequests, signal) {
|
|
571
|
+
if (!isEngineId(engine))
|
|
572
|
+
throw new GitHubAppError('invalid-request', 'The engine id is malformed.');
|
|
573
|
+
const answer = await call('PUT', '/github/subscriptions', { engine, pullRequests }, signal);
|
|
574
|
+
if (answer.enabled === false)
|
|
575
|
+
return { enabled: false };
|
|
576
|
+
if (!Array.isArray(answer.coverage))
|
|
577
|
+
throw new GitHubAppError('invalid-answer', 'The subscription answer carried no coverage.');
|
|
578
|
+
const coverage = answer.coverage.slice(0, 200).map(parseCoverage).filter((entry) => entry !== undefined);
|
|
579
|
+
const renewBy = typeof answer.renewBy === 'string' && Number.isFinite(Date.parse(answer.renewBy)) ? answer.renewBy : undefined;
|
|
580
|
+
return { enabled: true, coverage, ...(renewBy === undefined ? {} : { renewBy }) };
|
|
581
|
+
},
|
|
582
|
+
async events(engine, after, signal) {
|
|
583
|
+
if (!isEngineId(engine))
|
|
584
|
+
throw new GitHubAppError('invalid-request', 'The engine id is malformed.');
|
|
585
|
+
const query = new URLSearchParams({ engine, ...(after !== undefined && isCursor(after) ? { after } : {}) });
|
|
586
|
+
const answer = await call('GET', `/github/events?${query.toString()}`, undefined, signal);
|
|
587
|
+
// Only an explicit `enabled: false` is the kill switch; an answer without the flag is a failed pull.
|
|
588
|
+
if (typeof answer.enabled !== 'boolean')
|
|
589
|
+
throw new GitHubAppError('invalid-answer', 'The inbox answer carried no enabled flag.');
|
|
590
|
+
if (answer.enabled === false)
|
|
591
|
+
return { enabled: false };
|
|
592
|
+
if (!Array.isArray(answer.events))
|
|
593
|
+
throw new GitHubAppError('invalid-answer', 'The inbox answer carried no events.');
|
|
594
|
+
const events = answer.events.slice(0, 500).map(parseNotice).filter((notice) => notice !== undefined);
|
|
595
|
+
return {
|
|
596
|
+
enabled: true, events, more: answer.more === true, reset: answer.reset === true,
|
|
597
|
+
...(isCursor(answer.cursor) ? { cursor: answer.cursor } : {}),
|
|
598
|
+
};
|
|
599
|
+
},
|
|
600
|
+
async write(request, signal) {
|
|
601
|
+
const problem = botWriteProblem(request);
|
|
602
|
+
if (problem !== undefined)
|
|
603
|
+
return { kind: 'refused', reason: 'bad-request', field: problem };
|
|
604
|
+
let base;
|
|
605
|
+
try {
|
|
606
|
+
base = baseOf(deps);
|
|
607
|
+
}
|
|
608
|
+
catch {
|
|
609
|
+
return { kind: 'not-written', reason: 'unavailable' };
|
|
610
|
+
}
|
|
611
|
+
let bearer;
|
|
612
|
+
try {
|
|
613
|
+
bearer = await token(signal);
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
signal?.throwIfAborted();
|
|
617
|
+
return { kind: 'not-written', reason: error instanceof GitHubAppError && error.code === 'signed-out' ? 'signed-out' : 'unavailable' };
|
|
618
|
+
}
|
|
619
|
+
signal?.throwIfAborted();
|
|
620
|
+
// Only the fields the service takes; the body goes in the JSON body, never in the URL.
|
|
621
|
+
const payload = JSON.stringify({
|
|
622
|
+
requestId: request.requestId, owner: request.owner, repo: request.repo, number: request.number, action: request.action,
|
|
623
|
+
...(request.threadId === undefined ? {} : { threadId: request.threadId }), ...(request.body === undefined ? {} : { body: request.body }),
|
|
624
|
+
...(request.commentId === undefined ? {} : { commentId: request.commentId }),
|
|
625
|
+
});
|
|
626
|
+
const budgetMs = deps.writeBudgetMs ?? WRITE_BUDGET_MS;
|
|
627
|
+
const deadline = Date.now() + budgetMs;
|
|
628
|
+
const budget = AbortSignal.timeout(budgetMs);
|
|
629
|
+
const bounded = signal ? AbortSignal.any([signal, budget]) : budget;
|
|
630
|
+
const late = `no answer from Andorra's service within ${Number((budgetMs / 1000).toFixed(2))} seconds`;
|
|
631
|
+
/** Why an earlier attempt's fate is unknown; from then on only a settled answer decides. */
|
|
632
|
+
let uncertain;
|
|
633
|
+
let refreshed = false;
|
|
634
|
+
const pause = async (made) => {
|
|
635
|
+
if (made >= WRITE_ATTEMPTS)
|
|
636
|
+
return false;
|
|
637
|
+
const wait = WRITE_RETRY_MS[Math.min(made - 1, WRITE_RETRY_MS.length - 1)];
|
|
638
|
+
if (Date.now() + wait >= deadline)
|
|
639
|
+
return false;
|
|
640
|
+
try {
|
|
641
|
+
await (deps.sleep ?? ((ms, abort) => delay(ms, undefined, { signal: abort })))(wait, bounded);
|
|
642
|
+
}
|
|
643
|
+
catch {
|
|
644
|
+
signal?.throwIfAborted();
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
return !budget.aborted;
|
|
648
|
+
};
|
|
649
|
+
for (let made = 1; made <= WRITE_ATTEMPTS; made++) {
|
|
650
|
+
let response;
|
|
651
|
+
try {
|
|
652
|
+
response = await deps.fetch(`${base}/github/writes`, {
|
|
653
|
+
method: 'POST', redirect: 'error', signal: bounded,
|
|
654
|
+
headers: { Authorization: `Bearer ${bearer}`, 'Content-Type': 'application/json' }, body: payload,
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
catch (error) {
|
|
658
|
+
signal?.throwIfAborted();
|
|
659
|
+
if (budget.aborted)
|
|
660
|
+
return { kind: 'unknown', detail: uncertain ?? late };
|
|
661
|
+
if (!failedBeforeSending(error))
|
|
662
|
+
uncertain ??= 'the connection to Andorra\'s service failed after the write was sent';
|
|
663
|
+
// Nothing left this machine, and no earlier attempt may have written: the service was not reached at all.
|
|
664
|
+
else if (uncertain === undefined)
|
|
665
|
+
return { kind: 'not-written', reason: 'unavailable' };
|
|
666
|
+
if (!await pause(made))
|
|
667
|
+
return { kind: 'unknown', detail: uncertain };
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (response.status === 401) {
|
|
671
|
+
await response.body?.cancel().catch(() => { });
|
|
672
|
+
if (!refreshed) {
|
|
673
|
+
refreshed = true;
|
|
674
|
+
// A token another process refreshed meanwhile gets one more try, which does not count as an attempt.
|
|
675
|
+
const again = await token(signal).catch(() => { signal?.throwIfAborted(); return bearer; });
|
|
676
|
+
if (again !== bearer) {
|
|
677
|
+
bearer = again;
|
|
678
|
+
made--;
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
// The sign-in is checked before anything else, so this attempt wrote nothing; an earlier one may have.
|
|
683
|
+
return uncertain === undefined ? { kind: 'not-written', reason: 'unauthorized' } : { kind: 'unknown', detail: uncertain };
|
|
684
|
+
}
|
|
685
|
+
const text = await boundedText(response).catch(() => undefined);
|
|
686
|
+
let value;
|
|
687
|
+
try {
|
|
688
|
+
value = text ? JSON.parse(text) : undefined;
|
|
689
|
+
}
|
|
690
|
+
catch {
|
|
691
|
+
value = undefined;
|
|
692
|
+
}
|
|
693
|
+
signal?.throwIfAborted();
|
|
694
|
+
const verdict = writeVerdict(response.status, isRecord(value) ? value : undefined);
|
|
695
|
+
if (uncertain === undefined || verdict.settled) {
|
|
696
|
+
if (verdict.outcome.kind !== 'unknown' || !verdict.retry)
|
|
697
|
+
return verdict.outcome;
|
|
698
|
+
uncertain = verdict.outcome.detail;
|
|
699
|
+
}
|
|
700
|
+
else if (!verdict.retry)
|
|
701
|
+
return { kind: 'unknown', detail: uncertain };
|
|
702
|
+
// Asked again with the same requestId: the service replays what the first attempt did, or makes the write once.
|
|
703
|
+
if (!await pause(made))
|
|
704
|
+
return { kind: 'unknown', detail: uncertain };
|
|
705
|
+
}
|
|
706
|
+
return { kind: 'unknown', detail: uncertain ?? late };
|
|
707
|
+
},
|
|
708
|
+
reviewCheck(request, signal) {
|
|
709
|
+
return reviewCall('review-check', request, signal);
|
|
710
|
+
},
|
|
711
|
+
review(request, signal) {
|
|
712
|
+
return reviewCall('review', request, signal);
|
|
713
|
+
},
|
|
714
|
+
};
|
|
715
|
+
/** One request for `review-check` or `review`; a 401 gets one refreshed token, which is not a second attempt. */
|
|
716
|
+
async function reviewCall(action, request, signal) {
|
|
717
|
+
const problem = reviewWriteProblem(request, action);
|
|
718
|
+
if (problem !== undefined)
|
|
719
|
+
return { kind: 'bad-request', field: problem };
|
|
720
|
+
let base;
|
|
721
|
+
try {
|
|
722
|
+
base = baseOf(deps);
|
|
723
|
+
}
|
|
724
|
+
catch {
|
|
725
|
+
return { kind: 'unavailable', detail: 'Andorra\'s account API is not configured' };
|
|
726
|
+
}
|
|
727
|
+
let bearer;
|
|
728
|
+
try {
|
|
729
|
+
bearer = await token(signal);
|
|
730
|
+
}
|
|
731
|
+
catch (error) {
|
|
732
|
+
signal?.throwIfAborted();
|
|
733
|
+
return error instanceof GitHubAppError && error.code === 'signed-out' ? { kind: 'signed-out' } : { kind: 'unavailable', detail: 'the Andorra sign-in could not be read just now' };
|
|
734
|
+
}
|
|
735
|
+
const review = action === 'review' ? request : undefined;
|
|
736
|
+
// Only the fields the service takes; every text goes in the JSON body, never in the URL.
|
|
737
|
+
const payload = JSON.stringify({
|
|
738
|
+
requestId: request.requestId, owner: request.owner, repo: request.repo, number: request.number, action,
|
|
739
|
+
...(review === undefined ? {} : {
|
|
740
|
+
commitId: review.commitId, loop: review.loop, round: review.round, rounds: review.rounds, body: review.body,
|
|
741
|
+
comments: review.comments.map(comment => ({ path: comment.path, line: comment.line, side: comment.side,
|
|
742
|
+
...(comment.startLine === undefined ? {} : { startLine: comment.startLine, startSide: comment.startSide }), body: comment.body })),
|
|
743
|
+
}),
|
|
744
|
+
});
|
|
745
|
+
if (Buffer.byteLength(payload, 'utf8') > REVIEW_REQUEST_BYTES)
|
|
746
|
+
return { kind: 'bad-request', field: 'size' };
|
|
747
|
+
const budgetMs = deps.writeBudgetMs ?? WRITE_BUDGET_MS;
|
|
748
|
+
const budget = AbortSignal.timeout(budgetMs);
|
|
749
|
+
const bounded = signal ? AbortSignal.any([signal, budget]) : budget;
|
|
750
|
+
for (let refreshed = false;;) {
|
|
751
|
+
let response;
|
|
752
|
+
try {
|
|
753
|
+
response = await deps.fetch(`${base}/github/writes`, {
|
|
754
|
+
method: 'POST', redirect: 'error', signal: bounded,
|
|
755
|
+
headers: { Authorization: `Bearer ${bearer}`, 'Content-Type': 'application/json' }, body: payload,
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
catch (error) {
|
|
759
|
+
signal?.throwIfAborted();
|
|
760
|
+
if (budget.aborted)
|
|
761
|
+
return { kind: 'unknown', detail: `no answer from Andorra's service within ${Number((budgetMs / 1000).toFixed(2))} seconds` };
|
|
762
|
+
// Nothing left this machine: the service was not reached, so nothing can have been posted.
|
|
763
|
+
if (failedBeforeSending(error))
|
|
764
|
+
return { kind: 'unavailable', detail: 'Andorra\'s service could not be reached' };
|
|
765
|
+
return { kind: 'unknown', detail: 'the connection to Andorra\'s service failed after the request was sent' };
|
|
766
|
+
}
|
|
767
|
+
if (response.status === 401) {
|
|
768
|
+
await response.body?.cancel().catch(() => { });
|
|
769
|
+
if (!refreshed) {
|
|
770
|
+
refreshed = true;
|
|
771
|
+
const again = await token(signal).catch(() => { signal?.throwIfAborted(); return bearer; });
|
|
772
|
+
if (again !== bearer) {
|
|
773
|
+
bearer = again;
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// The sign-in is checked before anything else, so nothing was posted.
|
|
778
|
+
return { kind: 'signed-out' };
|
|
779
|
+
}
|
|
780
|
+
const text = await boundedText(response).catch(() => undefined);
|
|
781
|
+
let value;
|
|
782
|
+
try {
|
|
783
|
+
value = text ? JSON.parse(text) : undefined;
|
|
784
|
+
}
|
|
785
|
+
catch {
|
|
786
|
+
value = undefined;
|
|
787
|
+
}
|
|
788
|
+
signal?.throwIfAborted();
|
|
789
|
+
return reviewVerdict(action, response.status, isRecord(value) ? value : undefined, retryAfterMs(response));
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
/** The shipped client: the stamped account API and the signed-in account, or the test-mode override (see accountApiTarget). */
|
|
794
|
+
export function defaultGitHubAppClient(env = process.env) {
|
|
795
|
+
const target = accountApiTarget(env);
|
|
796
|
+
return createGitHubAppClient({
|
|
797
|
+
accessToken: async (signal) => {
|
|
798
|
+
// An overridden API always gets the test token; the sign-in's token goes only to the production API.
|
|
799
|
+
if (target.token !== undefined)
|
|
800
|
+
return target.token;
|
|
801
|
+
if (target.baseUrl !== AUTH_DEPLOYMENT.apiBaseUrl)
|
|
802
|
+
throw new GitHubAppError('unavailable', 'The test account API needs ANDORRA_TEST_ACCOUNT_TOKEN.');
|
|
803
|
+
const { getAccessToken, AUTH_REFRESH_BUDGET_MS } = await import('../auth/index.js');
|
|
804
|
+
return getAccessToken(signal ? AbortSignal.any([signal, AbortSignal.timeout(AUTH_REFRESH_BUDGET_MS)]) : AbortSignal.timeout(AUTH_REFRESH_BUDGET_MS));
|
|
805
|
+
},
|
|
806
|
+
apiBaseUrl: () => target.baseUrl,
|
|
807
|
+
fetch: (...args) => globalThis.fetch(...args),
|
|
808
|
+
allowLoopbackHttp: target.loopback,
|
|
809
|
+
});
|
|
810
|
+
}
|