@opengeni/worker-bundle 0.20.1 → 0.22.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-turn/admission.d.ts +52 -0
- package/dist/activities/agent-turn/agent-build.d.ts +89 -0
- package/dist/activities/agent-turn/claim.d.ts +67 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +40 -0
- package/dist/activities/agent-turn/codex.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +88 -0
- package/dist/activities/agent-turn/credential-leases.d.ts +56 -0
- package/dist/activities/agent-turn/errors.d.ts +253 -0
- package/dist/activities/agent-turn/failure-settlement.d.ts +33 -0
- package/dist/activities/agent-turn/file-resources.d.ts +37 -0
- package/dist/activities/agent-turn/finalization.d.ts +42 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +105 -0
- package/dist/activities/agent-turn/governance-model.d.ts +66 -0
- package/dist/activities/agent-turn/history-sink.d.ts +52 -0
- package/dist/activities/agent-turn/history.d.ts +63 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +145 -0
- package/dist/activities/agent-turn/model-usage.d.ts +218 -0
- package/dist/activities/agent-turn/quiescence.d.ts +135 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +84 -0
- package/dist/activities/agent-turn/run.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-establish.d.ts +93 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +89 -0
- package/dist/activities/agent-turn/sandbox-route.d.ts +151 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +44 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +107 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +142 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +127 -0
- package/dist/activities/agent-turn/tool-result-spill.d.ts +59 -0
- package/dist/activities/agent-turn/turn-context.d.ts +144 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +2 -0
- package/dist/activities/agent-turn.d.ts +12 -954
- package/dist/activities/automations.d.ts +16 -0
- package/dist/activities/common.d.ts +1 -1
- package/dist/activities/connector-attachments.d.ts +13 -0
- package/dist/activities/documents.d.ts +1 -0
- package/dist/activities/environment.d.ts +26 -15
- package/dist/activities/generated-images.d.ts +1 -1
- package/dist/activities/git-credential-renewal.d.ts +3 -1
- package/dist/activities/goals.d.ts +4 -1
- package/dist/activities/google-drive-provider.d.ts +29 -0
- package/dist/activities/google-drive-publication.d.ts +66 -0
- package/dist/activities/image-generation-references.d.ts +2 -0
- package/dist/activities/incident-telemetry-authority.d.ts +52 -0
- package/dist/activities/incident-telemetry-preflight.d.ts +71 -0
- package/dist/activities/knowledge-source-sync-driver.d.ts +21 -0
- package/dist/activities/knowledge-source-sync.d.ts +33 -1
- package/dist/activities/mcp-credentials.d.ts +9 -3
- package/dist/activities/open-suffix-resume.d.ts +77 -0
- package/dist/activities/packs.d.ts +3 -11
- package/dist/activities/parent-wake.d.ts +19 -0
- package/dist/activities/retained-screenshot-reaper.d.ts +1 -1
- package/dist/activities/retained-screenshots.d.ts +1 -1
- package/dist/activities/rig-verification.d.ts +1 -1
- package/dist/activities/run-input.d.ts +16 -7
- package/dist/activities/sandbox-images.d.ts +1 -14
- package/dist/activities/sandbox-lease.d.ts +21 -3
- package/dist/activities/scheduled-tasks.d.ts +47 -0
- package/dist/activities/types.d.ts +23 -2
- package/dist/activities/video-media-validation.d.ts +1 -1
- package/dist/activities/video-output-retention.d.ts +1 -2
- package/dist/activities/xai-auth.d.ts +3 -0
- package/dist/{activities-control-SMKF2OBE.js → activities-control-DKG22ONJ.js} +2946 -549
- package/dist/activities-control-DKG22ONJ.js.map +1 -0
- package/dist/activities-control.d.ts +6 -2
- package/dist/activities-turn-4IMC3MAA.js +21326 -0
- package/dist/activities-turn-4IMC3MAA.js.map +1 -0
- package/dist/activities.d.ts +7 -3
- package/dist/artifact-materializer-entry.js +41 -22
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/{chunk-N5TJIFCE.js → chunk-CE7TPKBS.js} +468 -1
- package/dist/chunk-CE7TPKBS.js.map +1 -0
- package/dist/chunk-CNYGVRKF.js +4698 -0
- package/dist/chunk-CNYGVRKF.js.map +1 -0
- package/dist/connection-provider-use.d.ts +18 -0
- package/dist/editable-artifact-materializer.d.ts +4 -3
- package/dist/github-rest-mcp.d.ts +26 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/knowledge-source-sync-activity-policy.d.ts +2 -0
- package/dist/model-context-contributions.d.ts +8 -4
- package/dist/observability-metrics.d.ts +63 -4
- package/dist/opensandbox-kubernetes-inventory.d.ts +21 -0
- package/dist/personal-github-git-credentials.d.ts +9 -0
- package/dist/pr-review-credentials.d.ts +6 -0
- package/dist/sandbox-archive-storage.d.ts +45 -0
- package/dist/sandbox-resume.d.ts +65 -6
- package/dist/sandbox-routing.d.ts +38 -2
- package/dist/scheduled-alert-occurrence.d.ts +33 -0
- package/dist/workflow-bundle.js +87 -28
- package/dist/workflows/activities.d.ts +1 -0
- package/dist/workflows/automations.d.ts +6 -0
- package/dist/workflows/document-index.d.ts +1 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +17 -17
- package/src/activities/agent-turn/admission.ts +292 -0
- package/src/activities/agent-turn/agent-build.ts +802 -0
- package/src/activities/agent-turn/claim.ts +590 -0
- package/src/activities/agent-turn/codex-capacity.ts +720 -0
- package/src/activities/agent-turn/codex.ts +94 -0
- package/src/activities/agent-turn/compaction-prep.ts +722 -0
- package/src/activities/agent-turn/credential-leases.ts +240 -0
- package/src/activities/agent-turn/errors.ts +1068 -0
- package/src/activities/agent-turn/failure-settlement.ts +1436 -0
- package/src/activities/agent-turn/file-resources.ts +227 -0
- package/src/activities/agent-turn/finalization.ts +754 -0
- package/src/activities/agent-turn/github-repository-bindings.ts +300 -0
- package/src/activities/agent-turn/governance-model.ts +465 -0
- package/src/activities/agent-turn/history-sink.ts +139 -0
- package/src/activities/agent-turn/history.ts +200 -0
- package/src/activities/agent-turn/media-artifacts.ts +359 -0
- package/src/activities/agent-turn/model-usage.ts +823 -0
- package/src/activities/agent-turn/quiescence.ts +353 -0
- package/src/activities/agent-turn/run-credentials.ts +761 -0
- package/src/activities/agent-turn/run.ts +1530 -0
- package/src/activities/agent-turn/sandbox-establish.ts +1207 -0
- package/src/activities/agent-turn/sandbox-provision.ts +569 -0
- package/src/activities/agent-turn/sandbox-route.ts +358 -0
- package/src/activities/agent-turn/sandbox-runtime.ts +731 -0
- package/src/activities/agent-turn/stream-attempt.ts +1670 -0
- package/src/activities/agent-turn/tool-environment.ts +729 -0
- package/src/activities/agent-turn/tool-policy.ts +216 -0
- package/src/activities/agent-turn/tool-result-spill.ts +265 -0
- package/src/activities/agent-turn/turn-context.ts +281 -0
- package/src/activities/agent-turn/xai-capacity.ts +229 -0
- package/src/activities/agent-turn.ts +12 -12575
- package/src/activities/api-integrations.ts +3 -0
- package/src/activities/automations.ts +214 -0
- package/src/activities/codemode-dispatcher.ts +12 -1
- package/src/activities/common.ts +1 -5
- package/src/activities/connector-attachments.ts +168 -0
- package/src/activities/context-compaction.ts +18 -0
- package/src/activities/documents.ts +6 -4
- package/src/activities/environment.ts +151 -55
- package/src/activities/generated-images.ts +26 -11
- package/src/activities/git-credential-renewal.ts +13 -3
- package/src/activities/goals.ts +85 -19
- package/src/activities/google-drive-provider.ts +178 -0
- package/src/activities/google-drive-publication.ts +938 -0
- package/src/activities/image-generation-references.ts +11 -2
- package/src/activities/incident-telemetry-authority.ts +327 -0
- package/src/activities/incident-telemetry-preflight.ts +317 -0
- package/src/activities/knowledge-source-sync-driver.ts +23 -0
- package/src/activities/knowledge-source-sync.ts +556 -40
- package/src/activities/mcp-credentials.ts +191 -17
- package/src/activities/open-suffix-resume.ts +422 -0
- package/src/activities/packs.ts +12 -60
- package/src/activities/parent-wake.ts +64 -14
- package/src/activities/retained-screenshot-reaper.ts +6 -3
- package/src/activities/retained-screenshots.ts +15 -47
- package/src/activities/rig-verification.ts +1 -1
- package/src/activities/run-input.ts +128 -136
- package/src/activities/sandbox-images.ts +7 -166
- package/src/activities/sandbox-lease.ts +406 -15
- package/src/activities/scheduled-tasks.ts +2103 -411
- package/src/activities/session-state.ts +10 -2
- package/src/activities/types.ts +32 -2
- package/src/activities/video-media-validation.ts +3 -3
- package/src/activities/video-output-retention.ts +2 -57
- package/src/activities/xai-auth.ts +8 -0
- package/src/activities-control.ts +2 -0
- package/src/activities.ts +3 -0
- package/src/activity-services.ts +13 -4
- package/src/connection-provider-use.ts +36 -0
- package/src/editable-artifact-materializer-subprocess.ts +25 -14
- package/src/editable-artifact-materializer.ts +29 -18
- package/src/github-rest-mcp.ts +713 -0
- package/src/http.ts +16 -6
- package/src/index.ts +40 -5
- package/src/knowledge-source-sync-activity-policy.ts +2 -0
- package/src/model-context-contributions.ts +33 -10
- package/src/observability-metrics.ts +357 -0
- package/src/opensandbox-kubernetes-inventory.ts +292 -0
- package/src/personal-github-git-credentials.ts +331 -0
- package/src/pr-review-credentials.ts +163 -0
- package/src/sandbox-archive-storage.ts +159 -0
- package/src/sandbox-resume.ts +449 -63
- package/src/sandbox-routing.ts +314 -16
- package/src/scheduled-alert-occurrence.ts +176 -0
- package/src/workflows/activities.ts +18 -2
- package/src/workflows/automations.ts +11 -0
- package/src/workflows/session.ts +13 -3
- package/src/workflows.ts +1 -0
- package/dist/activities-control-SMKF2OBE.js.map +0 -1
- package/dist/activities-turn-IDS3WEHA.js +0 -16532
- package/dist/activities-turn-IDS3WEHA.js.map +0 -1
- package/dist/chunk-N5TJIFCE.js.map +0 -1
- package/dist/chunk-P6Z2SLAA.js +0 -3092
- package/dist/chunk-P6Z2SLAA.js.map +0 -1
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
import type { Settings } from "@opengeni/config";
|
|
2
|
+
import {
|
|
3
|
+
mergeToolRefs,
|
|
4
|
+
type McpPersonalConnectionDelegation,
|
|
5
|
+
type ResourceRef,
|
|
6
|
+
type ToolRef,
|
|
7
|
+
} from "@opengeni/contracts";
|
|
8
|
+
import {
|
|
9
|
+
isPersonalGitHubConnection,
|
|
10
|
+
PersonalGitHubConnectionMetadata,
|
|
11
|
+
} from "@opengeni/contracts/personal-github";
|
|
12
|
+
import { personalGitHubRepositoryResources } from "@opengeni/core";
|
|
13
|
+
import {
|
|
14
|
+
beginConnectorActionExecution,
|
|
15
|
+
completeConnectorActionExecution,
|
|
16
|
+
getConnectionMetadata,
|
|
17
|
+
getPersonalGitHubRepositorySelectionState,
|
|
18
|
+
hasAuditableGitHubInstallationAuthority,
|
|
19
|
+
listGitHubInstallationAccessForWorkspace,
|
|
20
|
+
prepareConnectorActionApproval,
|
|
21
|
+
resolveAcceptedConnectionUse,
|
|
22
|
+
type Database,
|
|
23
|
+
type ResolveConnectionCredentialInput,
|
|
24
|
+
type ResolveConnectionCredentialResult,
|
|
25
|
+
type SessionTurnForExecution,
|
|
26
|
+
} from "@opengeni/db";
|
|
27
|
+
import {
|
|
28
|
+
AttemptToolApprovalRequiredError,
|
|
29
|
+
type AttemptToolAuthorization,
|
|
30
|
+
} from "@opengeni/codemode";
|
|
31
|
+
import { createGitHubAppInstallationTokenWithExpiry, githubAppBotIdentity } from "@opengeni/github";
|
|
32
|
+
import {
|
|
33
|
+
type AttemptConnectorActionBinding,
|
|
34
|
+
type LocalMcpServerRegistration,
|
|
35
|
+
prefixedMcpToolName,
|
|
36
|
+
} from "@opengeni/runtime";
|
|
37
|
+
import {
|
|
38
|
+
GITHUB_REST_API_ORIGIN,
|
|
39
|
+
GITHUB_REST_MCP_APP_SERVER_ID,
|
|
40
|
+
GITHUB_REST_MCP_PERSONAL_SERVER_ID,
|
|
41
|
+
GITHUB_REST_READ_TOOL_NAMES,
|
|
42
|
+
GITHUB_REST_TOOL_NAMES,
|
|
43
|
+
GitHubRestAuthorityError,
|
|
44
|
+
githubRestConnectorActionOutcome,
|
|
45
|
+
GitHubRestMcpServer,
|
|
46
|
+
GitHubRestMutationNotExecutedError,
|
|
47
|
+
type GitHubRestRepository,
|
|
48
|
+
} from "@opengeni/runtime/github-rest-mcp";
|
|
49
|
+
|
|
50
|
+
const PERSONAL_GITHUB_DELEGATION_SERVER_ID = "github:personal";
|
|
51
|
+
const INTERNAL_GITHUB_MCP_TIMEOUT_MS = 20_000;
|
|
52
|
+
|
|
53
|
+
type ResolveCredential = (
|
|
54
|
+
request: ResolveConnectionCredentialInput,
|
|
55
|
+
) => Promise<ResolveConnectionCredentialResult>;
|
|
56
|
+
|
|
57
|
+
export type GitHubRestMcpRuntime = {
|
|
58
|
+
settings: Settings;
|
|
59
|
+
tools: ToolRef[];
|
|
60
|
+
localMcpServers: LocalMcpServerRegistration[];
|
|
61
|
+
connectorBindings: AttemptConnectorActionBinding[];
|
|
62
|
+
authorizeCodemodeCall: AttemptToolAuthorization | null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export async function buildGitHubRestMcpForTurn(input: {
|
|
66
|
+
db: Database;
|
|
67
|
+
settings: Settings;
|
|
68
|
+
accountId: string;
|
|
69
|
+
workspaceId: string;
|
|
70
|
+
sessionId: string;
|
|
71
|
+
attemptId: string;
|
|
72
|
+
turn: SessionTurnForExecution;
|
|
73
|
+
resources: ResourceRef[];
|
|
74
|
+
tools: ToolRef[];
|
|
75
|
+
resolveCredential: ResolveCredential;
|
|
76
|
+
}): Promise<GitHubRestMcpRuntime> {
|
|
77
|
+
if (!input.settings.githubRestMcpEnabled) {
|
|
78
|
+
return {
|
|
79
|
+
settings: input.settings,
|
|
80
|
+
tools: input.tools,
|
|
81
|
+
localMcpServers: [],
|
|
82
|
+
connectorBindings: [],
|
|
83
|
+
authorizeCodemodeCall: null,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const appRepositories = appRepositoryAuthority(input.resources);
|
|
88
|
+
const personalRepositories = personalRepositoryAuthority(
|
|
89
|
+
input.resources,
|
|
90
|
+
input.turn.personalConnectionDelegations,
|
|
91
|
+
);
|
|
92
|
+
if (appRepositories.length === 0 && personalRepositories.length === 0) {
|
|
93
|
+
return {
|
|
94
|
+
settings: input.settings,
|
|
95
|
+
tools: input.tools,
|
|
96
|
+
localMcpServers: [],
|
|
97
|
+
connectorBindings: [],
|
|
98
|
+
authorizeCodemodeCall: null,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const configuredIds = new Set(input.settings.mcpServers.map((server) => server.id));
|
|
102
|
+
for (const id of [GITHUB_REST_MCP_APP_SERVER_ID, GITHUB_REST_MCP_PERSONAL_SERVER_ID]) {
|
|
103
|
+
if (configuredIds.has(id)) {
|
|
104
|
+
throw new GitHubRestAuthorityError(
|
|
105
|
+
`Reserved GitHub MCP server id is already configured: ${id}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const configs: Settings["mcpServers"] = [];
|
|
111
|
+
const localMcpServers: LocalMcpServerRegistration[] = [];
|
|
112
|
+
const toolRefs: ToolRef[] = [];
|
|
113
|
+
const connectorBindings: AttemptConnectorActionBinding[] = [];
|
|
114
|
+
const codemodeActions = createCodemodeActionLifecycle(input, connectorBindings);
|
|
115
|
+
|
|
116
|
+
if (appRepositories.length > 0) {
|
|
117
|
+
const appResolver = workspaceAppAuthorityResolver(input, appRepositories);
|
|
118
|
+
localMcpServers.push({
|
|
119
|
+
id: GITHUB_REST_MCP_APP_SERVER_ID,
|
|
120
|
+
server: new GitHubRestMcpServer({
|
|
121
|
+
serverId: GITHUB_REST_MCP_APP_SERVER_ID,
|
|
122
|
+
authorityKind: "workspace_app",
|
|
123
|
+
repositories: appRepositories,
|
|
124
|
+
resolveAuthority: appResolver,
|
|
125
|
+
completeCodemodeAction: codemodeActions.complete,
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
configs.push(internalMcpConfig(GITHUB_REST_MCP_APP_SERVER_ID, "GitHub — OpenGeni bot"));
|
|
129
|
+
toolRefs.push({ kind: "mcp", id: GITHUB_REST_MCP_APP_SERVER_ID });
|
|
130
|
+
connectorBindings.push(
|
|
131
|
+
...githubConnectorBindings(GITHUB_REST_MCP_APP_SERVER_ID, appRepositories),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (personalRepositories.length > 0) {
|
|
136
|
+
localMcpServers.push({
|
|
137
|
+
id: GITHUB_REST_MCP_PERSONAL_SERVER_ID,
|
|
138
|
+
server: new GitHubRestMcpServer({
|
|
139
|
+
serverId: GITHUB_REST_MCP_PERSONAL_SERVER_ID,
|
|
140
|
+
authorityKind: "personal_oauth",
|
|
141
|
+
repositories: personalRepositories,
|
|
142
|
+
resolveAuthority: personalAuthorityResolver(input),
|
|
143
|
+
completeCodemodeAction: codemodeActions.complete,
|
|
144
|
+
}),
|
|
145
|
+
});
|
|
146
|
+
configs.push(internalMcpConfig(GITHUB_REST_MCP_PERSONAL_SERVER_ID, "GitHub — My account"));
|
|
147
|
+
toolRefs.push({ kind: "mcp", id: GITHUB_REST_MCP_PERSONAL_SERVER_ID });
|
|
148
|
+
connectorBindings.push(
|
|
149
|
+
...githubConnectorBindings(GITHUB_REST_MCP_PERSONAL_SERVER_ID, personalRepositories),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
settings: {
|
|
155
|
+
...input.settings,
|
|
156
|
+
mcpServers: [...input.settings.mcpServers, ...configs],
|
|
157
|
+
},
|
|
158
|
+
tools: mergeToolRefs(input.tools, toolRefs),
|
|
159
|
+
localMcpServers,
|
|
160
|
+
connectorBindings,
|
|
161
|
+
authorizeCodemodeCall: codemodeActions.authorize,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function createCodemodeActionLifecycle(
|
|
166
|
+
input: {
|
|
167
|
+
db: Database;
|
|
168
|
+
accountId: string;
|
|
169
|
+
workspaceId: string;
|
|
170
|
+
sessionId: string;
|
|
171
|
+
attemptId: string;
|
|
172
|
+
turn: SessionTurnForExecution;
|
|
173
|
+
},
|
|
174
|
+
bindings: AttemptConnectorActionBinding[],
|
|
175
|
+
): {
|
|
176
|
+
authorize: AttemptToolAuthorization;
|
|
177
|
+
complete: NonNullable<
|
|
178
|
+
ConstructorParameters<typeof GitHubRestMcpServer>[0]["completeCodemodeAction"]
|
|
179
|
+
>;
|
|
180
|
+
} {
|
|
181
|
+
const identity = {
|
|
182
|
+
accountId: input.accountId,
|
|
183
|
+
workspaceId: input.workspaceId,
|
|
184
|
+
sessionId: input.sessionId,
|
|
185
|
+
turnId: input.turn.id,
|
|
186
|
+
attemptId: input.attemptId,
|
|
187
|
+
executionGeneration: input.turn.executionGeneration,
|
|
188
|
+
initiator: input.turn.initiator,
|
|
189
|
+
};
|
|
190
|
+
const executing = new Map<string, string>();
|
|
191
|
+
return {
|
|
192
|
+
authorize: async ({ call, entry }) => {
|
|
193
|
+
if (call.caller.kind !== "codemode") return;
|
|
194
|
+
const binding = bindings.find((candidate) => candidate.modelName === entry.modelName);
|
|
195
|
+
if (!binding) return;
|
|
196
|
+
const invocation = binding.call(call.operationId, call.arguments);
|
|
197
|
+
const policy = await prepareConnectorActionApproval(input.db, identity, invocation);
|
|
198
|
+
if (policy.managed && policy.decision === "ask") {
|
|
199
|
+
throw new AttemptToolApprovalRequiredError();
|
|
200
|
+
}
|
|
201
|
+
if (policy.managed && policy.decision === "block") {
|
|
202
|
+
throw new GitHubRestMutationNotExecutedError(
|
|
203
|
+
"GitHub connector action is blocked by policy",
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
const admission = await beginConnectorActionExecution(input.db, identity, invocation);
|
|
207
|
+
if (!admission.allowed) {
|
|
208
|
+
if (admission.reason === "approval_required") {
|
|
209
|
+
throw new AttemptToolApprovalRequiredError();
|
|
210
|
+
}
|
|
211
|
+
throw new GitHubRestMutationNotExecutedError(
|
|
212
|
+
`GitHub connector action was not executed: ${admission.reason}`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
if (admission.managed) executing.set(call.operationId, admission.requestId);
|
|
216
|
+
},
|
|
217
|
+
complete: async ({ operationId, outcome }) => {
|
|
218
|
+
const requestId = executing.get(operationId);
|
|
219
|
+
if (!requestId) return;
|
|
220
|
+
executing.delete(operationId);
|
|
221
|
+
await completeConnectorActionExecution(input.db, {
|
|
222
|
+
accountId: input.accountId,
|
|
223
|
+
workspaceId: input.workspaceId,
|
|
224
|
+
requestId,
|
|
225
|
+
attemptId: input.attemptId,
|
|
226
|
+
outcome,
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function internalMcpConfig(id: string, name: string): Settings["mcpServers"][number] {
|
|
233
|
+
return {
|
|
234
|
+
id,
|
|
235
|
+
name,
|
|
236
|
+
url: `${GITHUB_REST_API_ORIGIN}/`,
|
|
237
|
+
allowedTools: [...GITHUB_REST_TOOL_NAMES],
|
|
238
|
+
timeoutMs: INTERNAL_GITHUB_MCP_TIMEOUT_MS,
|
|
239
|
+
cacheToolsList: true,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function appRepositoryAuthority(resources: ResourceRef[]): GitHubRestRepository[] {
|
|
244
|
+
return resources.flatMap((resource) => {
|
|
245
|
+
if (resource.kind !== "repository" || resource.connectionType === "github_personal") {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
const hasAppIdentity =
|
|
249
|
+
resource.githubInstallationId !== undefined ||
|
|
250
|
+
resource.installationId !== undefined ||
|
|
251
|
+
resource.githubRepositoryId !== undefined;
|
|
252
|
+
if (!hasAppIdentity) return [];
|
|
253
|
+
if (resource.provider !== undefined && resource.provider !== "github") {
|
|
254
|
+
throw new GitHubRestAuthorityError("GitHub App repository provider is invalid");
|
|
255
|
+
}
|
|
256
|
+
const installationId = positiveSafeInteger(
|
|
257
|
+
resource.githubInstallationId ?? resource.installationId,
|
|
258
|
+
);
|
|
259
|
+
const repositoryId = positiveSafeInteger(resource.githubRepositoryId ?? resource.repositoryId);
|
|
260
|
+
const fullName = canonicalGitHubFullName(resource.uri);
|
|
261
|
+
if (!installationId || !repositoryId || !fullName) {
|
|
262
|
+
throw new GitHubRestAuthorityError("GitHub App repository authority is incomplete");
|
|
263
|
+
}
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
repositoryId: String(repositoryId),
|
|
267
|
+
fullName,
|
|
268
|
+
canonicalUrl: `https://github.com/${fullName}`,
|
|
269
|
+
defaultRef: resource.ref,
|
|
270
|
+
access: resource.access === "read" ? "read" : "write",
|
|
271
|
+
authorityKind: "workspace_app" as const,
|
|
272
|
+
connectionId: `github-app:${installationId}`,
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function personalRepositoryAuthority(
|
|
279
|
+
resources: ResourceRef[],
|
|
280
|
+
delegations: McpPersonalConnectionDelegation[],
|
|
281
|
+
): GitHubRestRepository[] {
|
|
282
|
+
const personalResources = personalGitHubRepositoryResources(resources);
|
|
283
|
+
if (personalResources.length === 0) return [];
|
|
284
|
+
const delegation = exactPersonalDelegation(delegations);
|
|
285
|
+
const snapshot = delegation.personalGitHubRepositorySelection!;
|
|
286
|
+
const acceptedById = new Map(
|
|
287
|
+
snapshot.repositories.map((repository) => [repository.repositoryId, repository]),
|
|
288
|
+
);
|
|
289
|
+
return personalResources.map((resource) => {
|
|
290
|
+
const accepted = acceptedById.get(resource.repositoryId);
|
|
291
|
+
const fullName = canonicalGitHubFullName(resource.uri);
|
|
292
|
+
if (
|
|
293
|
+
!accepted ||
|
|
294
|
+
!fullName ||
|
|
295
|
+
accepted.fullName !== fullName ||
|
|
296
|
+
accepted.canonicalUrl !== resource.uri ||
|
|
297
|
+
accepted.ref !== resource.ref ||
|
|
298
|
+
accepted.access !== resource.access
|
|
299
|
+
) {
|
|
300
|
+
throw new GitHubRestAuthorityError(
|
|
301
|
+
"Personal GitHub repository does not match the accepted selection",
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
repositoryId: resource.repositoryId,
|
|
306
|
+
fullName,
|
|
307
|
+
canonicalUrl: resource.uri,
|
|
308
|
+
defaultRef: resource.ref,
|
|
309
|
+
access: resource.access,
|
|
310
|
+
authorityKind: "personal_oauth" as const,
|
|
311
|
+
connectionId: delegation.connectionId,
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function workspaceAppAuthorityResolver(
|
|
317
|
+
input: {
|
|
318
|
+
db: Database;
|
|
319
|
+
settings: Settings;
|
|
320
|
+
accountId: string;
|
|
321
|
+
workspaceId: string;
|
|
322
|
+
},
|
|
323
|
+
repositories: GitHubRestRepository[],
|
|
324
|
+
): ConstructorParameters<typeof GitHubRestMcpServer>[0]["resolveAuthority"] {
|
|
325
|
+
const installationByRepository = new Map(
|
|
326
|
+
repositories.map((repository) => [
|
|
327
|
+
repositoryKey(repository),
|
|
328
|
+
Number(repository.connectionId.slice("github-app:".length)),
|
|
329
|
+
]),
|
|
330
|
+
);
|
|
331
|
+
const tokenCache = new Map<string, { token: string; expiresAt: number }>();
|
|
332
|
+
const validate = async (repository: GitHubRestRepository): Promise<number> => {
|
|
333
|
+
const installationId = installationByRepository.get(repositoryKey(repository));
|
|
334
|
+
const repositoryId = Number(repository.repositoryId);
|
|
335
|
+
if (!installationId || !Number.isSafeInteger(repositoryId)) {
|
|
336
|
+
throw new GitHubRestAuthorityError("GitHub App repository binding changed");
|
|
337
|
+
}
|
|
338
|
+
const installations = await listGitHubInstallationAccessForWorkspace(
|
|
339
|
+
input.db,
|
|
340
|
+
input.workspaceId,
|
|
341
|
+
);
|
|
342
|
+
const installation = installations.find(
|
|
343
|
+
(candidate) => candidate.installationId === installationId,
|
|
344
|
+
);
|
|
345
|
+
if (
|
|
346
|
+
!installation ||
|
|
347
|
+
installation.accountId !== input.accountId ||
|
|
348
|
+
!hasAuditableGitHubInstallationAuthority(installation) ||
|
|
349
|
+
!installation.repositoryIds.includes(repositoryId)
|
|
350
|
+
) {
|
|
351
|
+
throw new GitHubRestAuthorityError("GitHub App repository authority is no longer current");
|
|
352
|
+
}
|
|
353
|
+
return installationId;
|
|
354
|
+
};
|
|
355
|
+
return async ({ toolName, repository, forceRefresh }) => {
|
|
356
|
+
const installationId = await validate(repository);
|
|
357
|
+
const repositoryId = Number(repository.repositoryId);
|
|
358
|
+
const identity = githubAppBotIdentity(input.settings);
|
|
359
|
+
if (!identity) throw new GitHubRestAuthorityError("GitHub App identity is unavailable");
|
|
360
|
+
if (toolName === "repositories_list") {
|
|
361
|
+
return {
|
|
362
|
+
headers: {},
|
|
363
|
+
connectionId: repository.connectionId,
|
|
364
|
+
actor: { kind: "workspace_app", login: identity.name },
|
|
365
|
+
authorizeProviderRequest: async () => {
|
|
366
|
+
try {
|
|
367
|
+
await validate(repository);
|
|
368
|
+
return true;
|
|
369
|
+
} catch {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const cacheKey = repositoryKey(repository);
|
|
376
|
+
let cached = tokenCache.get(cacheKey);
|
|
377
|
+
if (forceRefresh || !cached || cached.expiresAt <= Date.now() + 60_000) {
|
|
378
|
+
const minted = await createGitHubAppInstallationTokenWithExpiry(input.settings, {
|
|
379
|
+
installationId,
|
|
380
|
+
repositoryIds: [repositoryId],
|
|
381
|
+
});
|
|
382
|
+
const parsedExpiry = minted.expiresAt ? Date.parse(minted.expiresAt) : Number.NaN;
|
|
383
|
+
cached = {
|
|
384
|
+
token: minted.token,
|
|
385
|
+
// An absent or malformed expiry must shorten the cache lifetime rather
|
|
386
|
+
// than turning NaN into an indefinitely reusable credential.
|
|
387
|
+
expiresAt: Number.isFinite(parsedExpiry) ? parsedExpiry : Date.now() + 5 * 60_000,
|
|
388
|
+
};
|
|
389
|
+
tokenCache.set(cacheKey, cached);
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
headers: { authorization: `Bearer ${cached.token}` },
|
|
393
|
+
connectionId: repository.connectionId,
|
|
394
|
+
actor: { kind: "workspace_app", login: identity.name },
|
|
395
|
+
authorizeProviderRequest: async () => {
|
|
396
|
+
try {
|
|
397
|
+
await validate(repository);
|
|
398
|
+
return true;
|
|
399
|
+
} catch {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function personalAuthorityResolver(input: {
|
|
408
|
+
db: Database;
|
|
409
|
+
accountId: string;
|
|
410
|
+
workspaceId: string;
|
|
411
|
+
sessionId: string;
|
|
412
|
+
attemptId: string;
|
|
413
|
+
turn: SessionTurnForExecution;
|
|
414
|
+
resolveCredential: ResolveCredential;
|
|
415
|
+
}): ConstructorParameters<typeof GitHubRestMcpServer>[0]["resolveAuthority"] {
|
|
416
|
+
return async ({ toolName, destinationUrl, repository, forceRefresh }) => {
|
|
417
|
+
const current = await validatePersonalRepository(
|
|
418
|
+
input,
|
|
419
|
+
repository,
|
|
420
|
+
toolName === "repositories_list",
|
|
421
|
+
);
|
|
422
|
+
if (toolName === "repositories_list") {
|
|
423
|
+
return {
|
|
424
|
+
headers: {},
|
|
425
|
+
connectionId: repository.connectionId,
|
|
426
|
+
actor: { kind: "personal_oauth", login: current.login },
|
|
427
|
+
authorizeProviderRequest: async () => {
|
|
428
|
+
try {
|
|
429
|
+
await validatePersonalRepository(input, repository, true);
|
|
430
|
+
return true;
|
|
431
|
+
} catch {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
const resolution = await input.resolveCredential({
|
|
438
|
+
workspaceId: input.workspaceId,
|
|
439
|
+
subjectId: current.delegation.ownerSubjectId,
|
|
440
|
+
serverId: PERSONAL_GITHUB_DELEGATION_SERVER_ID,
|
|
441
|
+
toolName,
|
|
442
|
+
connectionRef: {
|
|
443
|
+
connectionId: current.delegation.connectionId,
|
|
444
|
+
provider: "github",
|
|
445
|
+
providerDomain: "github.com",
|
|
446
|
+
kind: "oauth2",
|
|
447
|
+
scopes: ["repo"],
|
|
448
|
+
subjectScope: "subject",
|
|
449
|
+
},
|
|
450
|
+
destinationUrl,
|
|
451
|
+
credentialTarget: "http_api",
|
|
452
|
+
forceRefresh,
|
|
453
|
+
});
|
|
454
|
+
if (resolution.status !== "ok" || resolution.connectionId !== repository.connectionId) {
|
|
455
|
+
throw new GitHubRestAuthorityError("Personal GitHub credential is unavailable");
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
headers: githubAuthorizationHeaders(resolution.headers),
|
|
459
|
+
connectionId: resolution.connectionId,
|
|
460
|
+
actor: { kind: "personal_oauth", login: current.login },
|
|
461
|
+
authorizeProviderRequest: async () => {
|
|
462
|
+
if (resolution.authorizeProviderRequest && !(await resolution.authorizeProviderRequest())) {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
await validatePersonalRepository(input, repository, false);
|
|
467
|
+
return true;
|
|
468
|
+
} catch {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async function validatePersonalRepository(
|
|
477
|
+
input: {
|
|
478
|
+
db: Database;
|
|
479
|
+
accountId: string;
|
|
480
|
+
workspaceId: string;
|
|
481
|
+
turn: SessionTurnForExecution;
|
|
482
|
+
sessionId: string;
|
|
483
|
+
attemptId: string;
|
|
484
|
+
},
|
|
485
|
+
repository: GitHubRestRepository,
|
|
486
|
+
validateAcceptedUse: boolean,
|
|
487
|
+
) {
|
|
488
|
+
const delegation = exactPersonalDelegation(input.turn.personalConnectionDelegations);
|
|
489
|
+
if (delegation.connectionId !== repository.connectionId || !delegation.originWorkspaceId) {
|
|
490
|
+
throw new GitHubRestAuthorityError("Personal GitHub delegation changed");
|
|
491
|
+
}
|
|
492
|
+
const snapshot = delegation.personalGitHubRepositorySelection!;
|
|
493
|
+
const accepted = snapshot.repositories.find(
|
|
494
|
+
(candidate) => candidate.repositoryId === repository.repositoryId,
|
|
495
|
+
);
|
|
496
|
+
if (
|
|
497
|
+
!accepted ||
|
|
498
|
+
accepted.fullName !== repository.fullName ||
|
|
499
|
+
accepted.canonicalUrl !== repository.canonicalUrl ||
|
|
500
|
+
accepted.ref !== repository.defaultRef ||
|
|
501
|
+
accepted.access !== repository.access
|
|
502
|
+
) {
|
|
503
|
+
throw new GitHubRestAuthorityError("Personal GitHub repository exceeds accepted authority");
|
|
504
|
+
}
|
|
505
|
+
const acceptedUse = validateAcceptedUse
|
|
506
|
+
? await resolveAcceptedConnectionUse(input.db, {
|
|
507
|
+
accountId: input.accountId,
|
|
508
|
+
workspaceId: input.workspaceId,
|
|
509
|
+
sessionId: input.sessionId,
|
|
510
|
+
turnId: input.turn.id,
|
|
511
|
+
attemptId: input.attemptId,
|
|
512
|
+
executionGeneration: input.turn.executionGeneration,
|
|
513
|
+
physicalRequestId: crypto.randomUUID(),
|
|
514
|
+
usePhase: "credential_resolution",
|
|
515
|
+
serverId: PERSONAL_GITHUB_DELEGATION_SERVER_ID,
|
|
516
|
+
connectionId: delegation.connectionId,
|
|
517
|
+
providerDomain: "github.com",
|
|
518
|
+
connectionKind: "oauth2",
|
|
519
|
+
subjectScope: "subject",
|
|
520
|
+
ownerSubjectId: delegation.ownerSubjectId,
|
|
521
|
+
})
|
|
522
|
+
: null;
|
|
523
|
+
if (
|
|
524
|
+
acceptedUse &&
|
|
525
|
+
(acceptedUse.status !== "authorized" ||
|
|
526
|
+
acceptedUse.originWorkspaceId !== delegation.originWorkspaceId ||
|
|
527
|
+
acceptedUse.attribution.connectionId !== delegation.connectionId ||
|
|
528
|
+
acceptedUse.attribution.connectionGeneration !== snapshot.connectionAuthorityGeneration ||
|
|
529
|
+
acceptedUse.attribution.ownerSubjectId !== delegation.ownerSubjectId)
|
|
530
|
+
) {
|
|
531
|
+
throw new GitHubRestAuthorityError("Personal GitHub connection authority changed");
|
|
532
|
+
}
|
|
533
|
+
const connection = await getConnectionMetadata(
|
|
534
|
+
input.db,
|
|
535
|
+
delegation.originWorkspaceId,
|
|
536
|
+
delegation.connectionId,
|
|
537
|
+
delegation.ownerSubjectId,
|
|
538
|
+
);
|
|
539
|
+
if (
|
|
540
|
+
!connection ||
|
|
541
|
+
connection.accountId !== input.accountId ||
|
|
542
|
+
connection.workspaceId !== delegation.originWorkspaceId ||
|
|
543
|
+
connection.subjectId !== delegation.ownerSubjectId ||
|
|
544
|
+
connection.status !== "active" ||
|
|
545
|
+
connection.grantedScopes.length !== 1 ||
|
|
546
|
+
connection.grantedScopes[0] !== "repo" ||
|
|
547
|
+
!isPersonalGitHubConnection(connection)
|
|
548
|
+
) {
|
|
549
|
+
throw new GitHubRestAuthorityError("Personal GitHub connection is unavailable");
|
|
550
|
+
}
|
|
551
|
+
const metadata = PersonalGitHubConnectionMetadata.parse(connection.metadata);
|
|
552
|
+
const current = await getPersonalGitHubRepositorySelectionState(input.db, {
|
|
553
|
+
accountId: input.accountId,
|
|
554
|
+
originWorkspaceId: delegation.originWorkspaceId,
|
|
555
|
+
subjectId: delegation.ownerSubjectId,
|
|
556
|
+
connectionId: delegation.connectionId,
|
|
557
|
+
});
|
|
558
|
+
const currentRepository = current?.repositories.find(
|
|
559
|
+
(candidate) => candidate.repositoryId === repository.repositoryId,
|
|
560
|
+
);
|
|
561
|
+
if (
|
|
562
|
+
!current ||
|
|
563
|
+
!currentRepository ||
|
|
564
|
+
current.connectionAuthorityGeneration !== snapshot.connectionAuthorityGeneration ||
|
|
565
|
+
current.selectionGeneration !== snapshot.selectionGeneration ||
|
|
566
|
+
current.credentialBindingId !== snapshot.credentialBindingId ||
|
|
567
|
+
current.credentialBindingId !== metadata.credentialBindingId ||
|
|
568
|
+
current.providerPrincipalId !== metadata.providerPrincipalId ||
|
|
569
|
+
metadata.githubUserId !== metadata.providerPrincipalId ||
|
|
570
|
+
currentRepository.fullName !== accepted.fullName ||
|
|
571
|
+
currentRepository.canonicalUrl !== accepted.canonicalUrl ||
|
|
572
|
+
currentRepository.selectionGeneration !== accepted.selectionGeneration ||
|
|
573
|
+
currentRepository.disabled ||
|
|
574
|
+
!canRead(currentRepository.permissions) ||
|
|
575
|
+
(accepted.access === "write" &&
|
|
576
|
+
(currentRepository.selectedAccess !== "write" ||
|
|
577
|
+
currentRepository.archived ||
|
|
578
|
+
!canWrite(currentRepository.permissions)))
|
|
579
|
+
) {
|
|
580
|
+
throw new GitHubRestAuthorityError("Personal GitHub repository authority changed");
|
|
581
|
+
}
|
|
582
|
+
return { delegation, login: metadata.githubLogin };
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function exactPersonalDelegation(
|
|
586
|
+
delegations: McpPersonalConnectionDelegation[],
|
|
587
|
+
): McpPersonalConnectionDelegation {
|
|
588
|
+
const matches = delegations.filter(
|
|
589
|
+
(delegation) =>
|
|
590
|
+
delegation.serverId === PERSONAL_GITHUB_DELEGATION_SERVER_ID &&
|
|
591
|
+
delegation.connectionType === "github_personal",
|
|
592
|
+
);
|
|
593
|
+
const delegation = matches[0];
|
|
594
|
+
if (
|
|
595
|
+
matches.length !== 1 ||
|
|
596
|
+
!delegation ||
|
|
597
|
+
delegation.providerDomain !== "github.com" ||
|
|
598
|
+
delegation.kind !== "oauth2" ||
|
|
599
|
+
!delegation.originWorkspaceId ||
|
|
600
|
+
!delegation.userDelegation ||
|
|
601
|
+
!delegation.personalGitHubRepositorySelection
|
|
602
|
+
) {
|
|
603
|
+
throw new GitHubRestAuthorityError("Personal GitHub delegation is unavailable");
|
|
604
|
+
}
|
|
605
|
+
return delegation;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function githubConnectorBindings(
|
|
609
|
+
serverId: string,
|
|
610
|
+
repositories: GitHubRestRepository[],
|
|
611
|
+
): AttemptConnectorActionBinding[] {
|
|
612
|
+
const byName = new Map(
|
|
613
|
+
repositories.map((repository) => [repository.fullName.toLowerCase(), repository]),
|
|
614
|
+
);
|
|
615
|
+
return GITHUB_REST_TOOL_NAMES.filter((toolName) => toolName !== "repositories_list").map(
|
|
616
|
+
(toolName) => ({
|
|
617
|
+
modelName: prefixedMcpToolName(serverId, toolName),
|
|
618
|
+
resultOutcome: githubRestConnectorActionOutcome,
|
|
619
|
+
call: (approvalId, arguments_) => {
|
|
620
|
+
const args = objectRecord(arguments_);
|
|
621
|
+
const repository =
|
|
622
|
+
typeof args.repository === "string" ? byName.get(args.repository.toLowerCase()) : null;
|
|
623
|
+
if (!repository) {
|
|
624
|
+
throw new GitHubRestAuthorityError(
|
|
625
|
+
"GitHub action repository does not match an accepted resource",
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
approvalId,
|
|
630
|
+
connectionId: repository.connectionId,
|
|
631
|
+
serverId,
|
|
632
|
+
toolName,
|
|
633
|
+
arguments: arguments_,
|
|
634
|
+
...(GITHUB_REST_READ_TOOL_NAMES.includes(
|
|
635
|
+
toolName as (typeof GITHUB_REST_READ_TOOL_NAMES)[number],
|
|
636
|
+
)
|
|
637
|
+
? {}
|
|
638
|
+
: { approvalMode: "connector_write" as const }),
|
|
639
|
+
};
|
|
640
|
+
},
|
|
641
|
+
}),
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function canonicalGitHubFullName(uri: string): string | null {
|
|
646
|
+
try {
|
|
647
|
+
const url = new URL(uri);
|
|
648
|
+
const path = url.pathname.replace(/^\/+|\/+$/gu, "");
|
|
649
|
+
if (
|
|
650
|
+
url.protocol !== "https:" ||
|
|
651
|
+
url.hostname !== "github.com" ||
|
|
652
|
+
url.port ||
|
|
653
|
+
url.username ||
|
|
654
|
+
url.password ||
|
|
655
|
+
url.search ||
|
|
656
|
+
url.hash ||
|
|
657
|
+
path.endsWith(".git") ||
|
|
658
|
+
!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(path)
|
|
659
|
+
) {
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
return path;
|
|
663
|
+
} catch {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function positiveSafeInteger(value: unknown): number | null {
|
|
669
|
+
const number = typeof value === "string" && /^\d+$/u.test(value) ? Number(value) : value;
|
|
670
|
+
return typeof number === "number" && Number.isSafeInteger(number) && number > 0 ? number : null;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function repositoryKey(repository: GitHubRestRepository): string {
|
|
674
|
+
return `${repository.connectionId}\0${repository.repositoryId}`;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function githubAuthorizationHeaders(headers: Record<string, string>): Record<string, string> {
|
|
678
|
+
const authorization = new Headers(headers).get("authorization");
|
|
679
|
+
if (
|
|
680
|
+
!authorization ||
|
|
681
|
+
!/^Bearer [^\u0000-\u0020\u007f]+$/u.test(authorization) ||
|
|
682
|
+
authorization.length > 16_384
|
|
683
|
+
) {
|
|
684
|
+
throw new GitHubRestAuthorityError("Personal GitHub authorization header is unavailable");
|
|
685
|
+
}
|
|
686
|
+
return { authorization };
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function objectRecord(value: unknown): Record<string, unknown> {
|
|
690
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
691
|
+
? (value as Record<string, unknown>)
|
|
692
|
+
: {};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function canRead(permissions: {
|
|
696
|
+
pull: boolean;
|
|
697
|
+
triage: boolean;
|
|
698
|
+
push: boolean;
|
|
699
|
+
maintain: boolean;
|
|
700
|
+
admin: boolean;
|
|
701
|
+
}): boolean {
|
|
702
|
+
return (
|
|
703
|
+
permissions.pull ||
|
|
704
|
+
permissions.triage ||
|
|
705
|
+
permissions.push ||
|
|
706
|
+
permissions.maintain ||
|
|
707
|
+
permissions.admin
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
function canWrite(permissions: { push: boolean; maintain: boolean; admin: boolean }): boolean {
|
|
712
|
+
return permissions.push || permissions.maintain || permissions.admin;
|
|
713
|
+
}
|