@opengeni/worker-bundle 0.20.3 → 0.22.1-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 +17 -4
- 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.d.ts +4 -0
- 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 +9 -10
- 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-BJSDRSIP.js → activities-control-DKG22ONJ.js} +2646 -551
- 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 -12701
- 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/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 +147 -49
- package/src/activities/incident-telemetry-authority.ts +327 -0
- package/src/activities/incident-telemetry-preflight.ts +317 -0
- package/src/activities/knowledge-source-sync.ts +178 -37
- 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 +102 -142
- 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-BJSDRSIP.js.map +0 -1
- package/dist/activities-turn-J5YO7XXX.js +0 -17243
- package/dist/activities-turn-J5YO7XXX.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,163 @@
|
|
|
1
|
+
import { environmentsEncryptionKeyBytes, type Settings } from "@opengeni/config";
|
|
2
|
+
import type {
|
|
3
|
+
ConnectionCredentialsPort,
|
|
4
|
+
GitCredentials,
|
|
5
|
+
GitCredentialsRequest,
|
|
6
|
+
} from "@opengeni/contracts";
|
|
7
|
+
import { prReviewRegistrationIdFromCredentialBinding } from "@opengeni/core";
|
|
8
|
+
import { decryptVariableSetValue, resolvePrReviewGitCredential, type Database } from "@opengeni/db";
|
|
9
|
+
import {
|
|
10
|
+
createGitHubAppInstallationTokenWithExpiry,
|
|
11
|
+
createGitHubAppInstallationTokenWithSigningSettings,
|
|
12
|
+
} from "@opengeni/github";
|
|
13
|
+
|
|
14
|
+
/** Standalone credential broker for PR Review plus the existing GitHub App path.
|
|
15
|
+
* Embedded hosts keep precedence by supplying their own connectionCredentials. */
|
|
16
|
+
export function createStandaloneConnectionCredentialsPort(
|
|
17
|
+
settings: Settings,
|
|
18
|
+
db: Database,
|
|
19
|
+
): ConnectionCredentialsPort {
|
|
20
|
+
return {
|
|
21
|
+
gitCredentials: async (request) => await resolveStandaloneGitCredentials(settings, db, request),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function resolveStandaloneGitCredentials(
|
|
26
|
+
settings: Settings,
|
|
27
|
+
db: Database,
|
|
28
|
+
request: GitCredentialsRequest,
|
|
29
|
+
): Promise<GitCredentials> {
|
|
30
|
+
const provider = request.provider ?? "github";
|
|
31
|
+
const registrationId = request.credentialBindingId
|
|
32
|
+
? prReviewRegistrationIdFromCredentialBinding(request.credentialBindingId)
|
|
33
|
+
: null;
|
|
34
|
+
if (!registrationId) {
|
|
35
|
+
if (provider !== "github") {
|
|
36
|
+
throw new Error(`${provider} Git credentials require an explicit PR Review or host binding`);
|
|
37
|
+
}
|
|
38
|
+
if (request.purpose === "identity") {
|
|
39
|
+
return { workspaceId: request.workspaceId };
|
|
40
|
+
}
|
|
41
|
+
const minted = await createGitHubAppInstallationTokenWithExpiry(settings, {
|
|
42
|
+
installationId: request.installationId,
|
|
43
|
+
repositoryIds: request.repositoryIds,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
token: minted.token,
|
|
47
|
+
workspaceId: request.workspaceId,
|
|
48
|
+
...(minted.expiresAt ? { expiresAt: minted.expiresAt } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const authority = await resolvePrReviewGitCredential(db, {
|
|
53
|
+
accountId: request.accountId,
|
|
54
|
+
workspaceId: request.workspaceId,
|
|
55
|
+
registrationId,
|
|
56
|
+
provider,
|
|
57
|
+
sessionId: request.sessionId,
|
|
58
|
+
rootSessionId: request.rootSessionId,
|
|
59
|
+
turnId: request.turnId,
|
|
60
|
+
attemptId: request.attemptId,
|
|
61
|
+
executionGeneration: request.executionGeneration,
|
|
62
|
+
repositoryRefs: (request.repositoryRefs ?? []).map((reference) => ({
|
|
63
|
+
uri: reference.uri,
|
|
64
|
+
...(reference.expectedCommitSha !== undefined
|
|
65
|
+
? { expectedCommitSha: reference.expectedCommitSha }
|
|
66
|
+
: {}),
|
|
67
|
+
...(reference.repositoryId !== undefined ? { repositoryId: reference.repositoryId } : {}),
|
|
68
|
+
...(reference.installationId !== undefined
|
|
69
|
+
? { installationId: reference.installationId }
|
|
70
|
+
: {}),
|
|
71
|
+
...(reference.projectId !== undefined ? { projectId: reference.projectId } : {}),
|
|
72
|
+
})),
|
|
73
|
+
});
|
|
74
|
+
const echoes = {
|
|
75
|
+
workspaceId: request.workspaceId,
|
|
76
|
+
...(request.credentialBindingId ? { credentialBindingId: request.credentialBindingId } : {}),
|
|
77
|
+
provider,
|
|
78
|
+
...(request.providerHost ? { providerHost: request.providerHost } : {}),
|
|
79
|
+
};
|
|
80
|
+
if (request.purpose === "identity") {
|
|
81
|
+
return authority.credentialKind === "github_app"
|
|
82
|
+
? {
|
|
83
|
+
...echoes,
|
|
84
|
+
identity: {
|
|
85
|
+
name: "pr-review[bot]",
|
|
86
|
+
email: `${authority.appId ?? "pr-review"}+pr-review[bot]@users.noreply.github.com`,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
: echoes;
|
|
90
|
+
}
|
|
91
|
+
if (authority.credentialKind === "github_app") {
|
|
92
|
+
assertGitHubMintMatchesRepositoryRefs(request);
|
|
93
|
+
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
94
|
+
if (!encryptionKey || !authority.appId || !authority.credentialEncrypted) {
|
|
95
|
+
throw new Error("PR Review GitHub App credential is unavailable");
|
|
96
|
+
}
|
|
97
|
+
const minted = await createGitHubAppInstallationTokenWithSigningSettings(
|
|
98
|
+
{
|
|
99
|
+
githubAppId: authority.appId,
|
|
100
|
+
githubAppPrivateKey: decryptVariableSetValue(encryptionKey, authority.credentialEncrypted),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
installationId: request.installationId,
|
|
104
|
+
repositoryIds: request.repositoryIds,
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
return {
|
|
108
|
+
...echoes,
|
|
109
|
+
token: minted.token,
|
|
110
|
+
...(minted.expiresAt ? { expiresAt: minted.expiresAt } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (authority.expiresAt && Date.parse(authority.expiresAt) <= Date.now()) {
|
|
114
|
+
throw new Error(`PR Review ${provider} provider credential has expired`);
|
|
115
|
+
}
|
|
116
|
+
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
117
|
+
if (!encryptionKey || !authority.credentialEncrypted) {
|
|
118
|
+
throw new Error(`PR Review ${provider} provider credential is unavailable`);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
...echoes,
|
|
122
|
+
token: decryptVariableSetValue(encryptionKey, authority.credentialEncrypted),
|
|
123
|
+
...(authority.expiresAt ? { expiresAt: authority.expiresAt } : {}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function assertGitHubMintMatchesRepositoryRefs(request: GitCredentialsRequest): void {
|
|
128
|
+
const refs = request.repositoryRefs ?? [];
|
|
129
|
+
const repositoryIds = refs.map((reference) => positiveInteger(reference.repositoryId));
|
|
130
|
+
const installationIds = refs.map((reference) => positiveInteger(reference.installationId));
|
|
131
|
+
if (
|
|
132
|
+
repositoryIds.some((value) => value === null) ||
|
|
133
|
+
installationIds.some((value) => value === null)
|
|
134
|
+
) {
|
|
135
|
+
throw new Error("PR Review GitHub credential request lacks exact repository authority");
|
|
136
|
+
}
|
|
137
|
+
const exactRepositoryIds = [...new Set(repositoryIds as number[])].sort(
|
|
138
|
+
(left, right) => left - right,
|
|
139
|
+
);
|
|
140
|
+
const requestedRepositoryIds = [...new Set(request.repositoryIds)].sort(
|
|
141
|
+
(left, right) => left - right,
|
|
142
|
+
);
|
|
143
|
+
const exactInstallationIds = [...new Set(installationIds as number[])];
|
|
144
|
+
if (
|
|
145
|
+
exactInstallationIds.length !== 1 ||
|
|
146
|
+
exactInstallationIds[0] !== request.installationId ||
|
|
147
|
+
exactRepositoryIds.length !== request.repositoryIds.length ||
|
|
148
|
+
exactRepositoryIds.some((value, index) => value !== requestedRepositoryIds[index])
|
|
149
|
+
) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
"PR Review GitHub token mint authority does not match its repository resources",
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function positiveInteger(value: unknown): number | null {
|
|
157
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value > 0) return value;
|
|
158
|
+
if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
159
|
+
const parsed = Number(value);
|
|
160
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { ObjectStorage } from "@opengeni/storage";
|
|
2
|
+
import {
|
|
3
|
+
parseWorkspaceArchiveObjectRef,
|
|
4
|
+
workspaceArchiveObjectKey,
|
|
5
|
+
type WorkspaceArchiveDescriptor,
|
|
6
|
+
type WorkspaceArchiveObjectRef,
|
|
7
|
+
} from "@opengeni/contracts";
|
|
8
|
+
|
|
9
|
+
export class WorkspaceArchiveObjectStorageRequiredError extends Error {
|
|
10
|
+
readonly code = "workspace_archive_object_storage_required" as const;
|
|
11
|
+
|
|
12
|
+
constructor(backend: string) {
|
|
13
|
+
super(`${backend} workspace archives require object storage`);
|
|
14
|
+
this.name = "WorkspaceArchiveObjectStorageRequiredError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function collectWorkspaceArchiveObjectKeys(
|
|
19
|
+
resumeState: Record<string, unknown> | null | undefined,
|
|
20
|
+
): Set<string> {
|
|
21
|
+
const sessionState =
|
|
22
|
+
resumeState?.sessionState && typeof resumeState.sessionState === "object"
|
|
23
|
+
? (resumeState.sessionState as Record<string, unknown>)
|
|
24
|
+
: null;
|
|
25
|
+
const keys = new Set<string>();
|
|
26
|
+
for (const value of [sessionState?.workspaceArchiveRef, sessionState?.workspaceArchivePrevRef]) {
|
|
27
|
+
const ref = parseWorkspaceArchiveObjectRef(value);
|
|
28
|
+
if (ref) keys.add(ref.key);
|
|
29
|
+
}
|
|
30
|
+
return keys;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function putTarWorkspaceArchiveObject(input: {
|
|
34
|
+
objectStorage: ObjectStorage;
|
|
35
|
+
accountId: string;
|
|
36
|
+
workspaceId: string;
|
|
37
|
+
sandboxGroupId: string;
|
|
38
|
+
archive: { bytes: Uint8Array; descriptor: WorkspaceArchiveDescriptor };
|
|
39
|
+
}): Promise<WorkspaceArchiveObjectRef> {
|
|
40
|
+
if (input.archive.descriptor.version !== 1) {
|
|
41
|
+
throw new Error("Object-storage workspace archives are portable tar only");
|
|
42
|
+
}
|
|
43
|
+
const key = workspaceArchiveObjectKey({
|
|
44
|
+
accountId: input.accountId,
|
|
45
|
+
workspaceId: input.workspaceId,
|
|
46
|
+
sandboxGroupId: input.sandboxGroupId,
|
|
47
|
+
revision: input.archive.descriptor.revision,
|
|
48
|
+
});
|
|
49
|
+
await input.objectStorage.putObject({
|
|
50
|
+
key,
|
|
51
|
+
contentType: "application/x-tar",
|
|
52
|
+
body: input.archive.bytes,
|
|
53
|
+
sha256: input.archive.descriptor.archiveSha256,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
schema: "sandbox_archive_object_v1",
|
|
57
|
+
key,
|
|
58
|
+
sha256: input.archive.descriptor.archiveSha256,
|
|
59
|
+
bytes: input.archive.descriptor.archiveBytes,
|
|
60
|
+
backend: input.objectStorage.backend,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function putVersion1TarArchiveOrInline(input: {
|
|
65
|
+
backend: string;
|
|
66
|
+
objectStorage?: ObjectStorage | null | undefined;
|
|
67
|
+
accountId: string;
|
|
68
|
+
workspaceId: string;
|
|
69
|
+
sandboxGroupId: string;
|
|
70
|
+
archive: {
|
|
71
|
+
bytes: Uint8Array;
|
|
72
|
+
descriptor: WorkspaceArchiveDescriptor;
|
|
73
|
+
base64: string;
|
|
74
|
+
};
|
|
75
|
+
metrics?: {
|
|
76
|
+
onWorkspaceArchiveObject?: (input: {
|
|
77
|
+
outcome: "put" | "put_failed" | "deleted_unpublished";
|
|
78
|
+
backend: string;
|
|
79
|
+
}) => void;
|
|
80
|
+
};
|
|
81
|
+
}): Promise<{
|
|
82
|
+
workspaceArchive?: string;
|
|
83
|
+
workspaceArchiveRef?: WorkspaceArchiveObjectRef;
|
|
84
|
+
}> {
|
|
85
|
+
if (input.archive.descriptor.version !== 1) {
|
|
86
|
+
return { workspaceArchive: input.archive.base64 };
|
|
87
|
+
}
|
|
88
|
+
if (input.backend === "opensandbox" && !input.objectStorage) {
|
|
89
|
+
throw new WorkspaceArchiveObjectStorageRequiredError("opensandbox");
|
|
90
|
+
}
|
|
91
|
+
if (!input.objectStorage) {
|
|
92
|
+
return { workspaceArchive: input.archive.base64 };
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const workspaceArchiveRef = await putTarWorkspaceArchiveObject({
|
|
96
|
+
objectStorage: input.objectStorage,
|
|
97
|
+
accountId: input.accountId,
|
|
98
|
+
workspaceId: input.workspaceId,
|
|
99
|
+
sandboxGroupId: input.sandboxGroupId,
|
|
100
|
+
archive: { bytes: input.archive.bytes, descriptor: input.archive.descriptor },
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
input.metrics?.onWorkspaceArchiveObject?.({
|
|
104
|
+
outcome: "put",
|
|
105
|
+
backend: input.objectStorage.backend,
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
/* metrics must not affect persist */
|
|
109
|
+
}
|
|
110
|
+
console.info("workspace archive object put", {
|
|
111
|
+
key: workspaceArchiveRef.key,
|
|
112
|
+
bytes: workspaceArchiveRef.bytes,
|
|
113
|
+
sha256: workspaceArchiveRef.sha256,
|
|
114
|
+
});
|
|
115
|
+
return { workspaceArchiveRef };
|
|
116
|
+
} catch (error) {
|
|
117
|
+
try {
|
|
118
|
+
input.metrics?.onWorkspaceArchiveObject?.({
|
|
119
|
+
outcome: "put_failed",
|
|
120
|
+
backend: input.objectStorage.backend,
|
|
121
|
+
});
|
|
122
|
+
} catch {
|
|
123
|
+
/* metrics must not affect persist */
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function deleteUnpublishedWorkspaceArchiveObject(
|
|
130
|
+
objectStorage: ObjectStorage | null | undefined,
|
|
131
|
+
ref: WorkspaceArchiveObjectRef | undefined,
|
|
132
|
+
metrics?: {
|
|
133
|
+
onWorkspaceArchiveObject?: (input: { outcome: "deleted_unpublished"; backend: string }) => void;
|
|
134
|
+
},
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
if (!objectStorage || !ref) return;
|
|
137
|
+
try {
|
|
138
|
+
await objectStorage.deleteObject(ref.key);
|
|
139
|
+
try {
|
|
140
|
+
metrics?.onWorkspaceArchiveObject?.({
|
|
141
|
+
outcome: "deleted_unpublished",
|
|
142
|
+
backend: objectStorage.backend,
|
|
143
|
+
});
|
|
144
|
+
} catch {
|
|
145
|
+
/* metrics must not affect persist */
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
console.error("unpublished workspace archive object delete failed", { key: ref.key });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function deleteWorkspaceArchiveObjectKeys(
|
|
153
|
+
objectStorage: ObjectStorage,
|
|
154
|
+
keys: Iterable<string>,
|
|
155
|
+
): Promise<void> {
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
await objectStorage.deleteObject(key);
|
|
158
|
+
}
|
|
159
|
+
}
|