omics-os 0.0.1 → 1.3.1
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/LICENSE +664 -0
- package/README.md +384 -4
- package/package.json +34 -12
- package/packages/cli/dist/index.js +154 -0
- package/packages/cloud-client/dist/agents.d.ts +20 -0
- package/packages/cloud-client/dist/agents.js +69 -0
- package/packages/cloud-client/dist/apiClient.d.ts +44 -0
- package/packages/cloud-client/dist/apiClient.js +368 -0
- package/packages/cloud-client/dist/auth.d.ts +76 -0
- package/packages/cloud-client/dist/auth.js +463 -0
- package/packages/cloud-client/dist/biovault/approval.d.ts +40 -0
- package/packages/cloud-client/dist/biovault/approval.js +38 -0
- package/packages/cloud-client/dist/biovault/assurance.d.ts +10 -0
- package/packages/cloud-client/dist/biovault/assurance.js +14 -0
- package/packages/cloud-client/dist/biovault/client.d.ts +76 -0
- package/packages/cloud-client/dist/biovault/client.js +212 -0
- package/packages/cloud-client/dist/biovault/compat.d.ts +29 -0
- package/packages/cloud-client/dist/biovault/compat.js +90 -0
- package/packages/cloud-client/dist/biovault/entries.d.ts +143 -0
- package/packages/cloud-client/dist/biovault/entries.js +359 -0
- package/packages/cloud-client/dist/biovault/errors.d.ts +18 -0
- package/packages/cloud-client/dist/biovault/errors.js +90 -0
- package/packages/cloud-client/dist/biovault/fields.d.ts +7 -0
- package/packages/cloud-client/dist/biovault/fields.js +42 -0
- package/packages/cloud-client/dist/biovault/identity.d.ts +10 -0
- package/packages/cloud-client/dist/biovault/identity.js +43 -0
- package/packages/cloud-client/dist/biovault/index.d.ts +15 -0
- package/packages/cloud-client/dist/biovault/index.js +16 -0
- package/packages/cloud-client/dist/biovault/instructionMatch.d.ts +32 -0
- package/packages/cloud-client/dist/biovault/instructionMatch.js +118 -0
- package/packages/cloud-client/dist/biovault/pending.d.ts +41 -0
- package/packages/cloud-client/dist/biovault/pending.js +208 -0
- package/packages/cloud-client/dist/biovault/preCommit.d.ts +10 -0
- package/packages/cloud-client/dist/biovault/preCommit.js +10 -0
- package/packages/cloud-client/dist/biovault/provenance.d.ts +45 -0
- package/packages/cloud-client/dist/biovault/provenance.js +55 -0
- package/packages/cloud-client/dist/biovault/vendor/packageDeliveryV1.generated.d.ts +3981 -0
- package/packages/cloud-client/dist/biovault/vendor/packageDeliveryV1.generated.js +3632 -0
- package/packages/cloud-client/dist/biovault/vendor/runV1.generated.d.ts +2326 -0
- package/packages/cloud-client/dist/biovault/vendor/runV1.generated.js +491 -0
- package/packages/cloud-client/dist/biovault/wireShape.d.ts +25 -0
- package/packages/cloud-client/dist/biovault/wireShape.js +88 -0
- package/packages/cloud-client/dist/bootstrap.d.ts +4 -0
- package/packages/cloud-client/dist/bootstrap.js +19 -0
- package/packages/cloud-client/dist/config.d.ts +44 -0
- package/packages/cloud-client/dist/config.js +309 -0
- package/packages/cloud-client/dist/credentials.d.ts +96 -0
- package/packages/cloud-client/dist/credentials.js +395 -0
- package/packages/cloud-client/dist/editor.d.ts +77 -0
- package/packages/cloud-client/dist/editor.js +278 -0
- package/packages/cloud-client/dist/errors.d.ts +27 -0
- package/packages/cloud-client/dist/errors.js +102 -0
- package/packages/cloud-client/dist/exports.d.ts +19 -0
- package/packages/cloud-client/dist/exports.js +85 -0
- package/packages/cloud-client/dist/featureFlags.d.ts +10 -0
- package/packages/cloud-client/dist/featureFlags.js +36 -0
- package/packages/cloud-client/dist/files.d.ts +35 -0
- package/packages/cloud-client/dist/files.js +109 -0
- package/packages/cloud-client/dist/index.d.ts +29 -0
- package/packages/cloud-client/dist/index.js +22 -0
- package/packages/cloud-client/dist/multipartUpload.d.ts +99 -0
- package/packages/cloud-client/dist/multipartUpload.js +624 -0
- package/packages/cloud-client/dist/projects.d.ts +42 -0
- package/packages/cloud-client/dist/projects.js +119 -0
- package/packages/cloud-client/dist/resources.d.ts +8 -0
- package/packages/cloud-client/dist/resources.js +26 -0
- package/packages/cloud-client/dist/sessions.d.ts +67 -0
- package/packages/cloud-client/dist/sessions.js +187 -0
- package/packages/cloud-client/dist/templates.d.ts +4 -0
- package/packages/cloud-client/dist/templates.js +12 -0
- package/packages/cloud-client/dist/types.d.ts +431 -0
- package/packages/cloud-client/dist/types.js +94 -0
- package/packages/cloud-client/dist/uploads.d.ts +93 -0
- package/packages/cloud-client/dist/uploads.js +61 -0
- package/packages/cloud-client/dist/vault.d.ts +20 -0
- package/packages/cloud-client/dist/vault.js +43 -0
- package/packages/cloud-client/dist/vectorSearch.d.ts +3 -0
- package/packages/cloud-client/dist/vectorSearch.js +12 -0
- package/packages/tui/dist/lobster.mjs +273 -0
- package/skills/omics-os-cloud/SKILL.md +24 -0
- package/skills/omics-os-lobster/SKILL.md +24 -0
- package/bin/omics-os.js +0 -5
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** File management — upload, download, list, delete, load into session. */
|
|
2
|
+
import { freshAuthHeaders } from "./config.js";
|
|
3
|
+
import { apiFetch, describeErrorBody, readErrorBody, retryAfterMs } from "./apiClient.js";
|
|
4
|
+
import { ApiError, AuthError, NetworkError, RateLimitError } from "./types.js";
|
|
5
|
+
/** List files in a session workspace. */
|
|
6
|
+
export async function listFiles(config, sessionId, directory) {
|
|
7
|
+
const params = directory ? `?directory=${encodeURIComponent(directory)}` : "";
|
|
8
|
+
const data = await apiFetch(config, `/sessions/${sessionId}/files${params}`);
|
|
9
|
+
return data.files ?? [];
|
|
10
|
+
}
|
|
11
|
+
/** Upload a file to the session workspace (multipart/form-data with streaming). */
|
|
12
|
+
export async function uploadFile(config, sessionId, file, filename, options) {
|
|
13
|
+
const url = `${config.apiUrl}/sessions/${sessionId}/files/upload`;
|
|
14
|
+
const auth = await freshAuthHeaders(config);
|
|
15
|
+
const formData = new FormData();
|
|
16
|
+
const blob = file instanceof Blob ? file : new Blob([file]);
|
|
17
|
+
formData.append("file", blob, filename);
|
|
18
|
+
if (options?.description) {
|
|
19
|
+
formData.append("description", options.description);
|
|
20
|
+
}
|
|
21
|
+
const resp = await fetch(url, {
|
|
22
|
+
redirect: "error",
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { ...auth },
|
|
25
|
+
body: formData,
|
|
26
|
+
signal: options?.signal,
|
|
27
|
+
});
|
|
28
|
+
if (resp.status === 401) {
|
|
29
|
+
throw new AuthError(`/sessions/${sessionId}/files/upload`);
|
|
30
|
+
}
|
|
31
|
+
if (!resp.ok) {
|
|
32
|
+
// Same reading as every other call: code, sub-code and Retry-After kept,
|
|
33
|
+
// never "[object Object]". Upload is a mutation, so it is never retried here.
|
|
34
|
+
const path = `/sessions/${sessionId}/files/upload`;
|
|
35
|
+
const errBody = await readErrorBody(resp);
|
|
36
|
+
const { detail, code, error, subcode } = describeErrorBody(errBody);
|
|
37
|
+
const wait = retryAfterMs(resp.headers.get("retry-after"));
|
|
38
|
+
if (resp.status === 429) {
|
|
39
|
+
throw new RateLimitError(path, wait, detail, errBody, code, { error, subcode });
|
|
40
|
+
}
|
|
41
|
+
throw new ApiError(path, resp.status, resp.statusText, detail, errBody, code, wait, {
|
|
42
|
+
error,
|
|
43
|
+
subcode,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return (await resp.json());
|
|
47
|
+
}
|
|
48
|
+
/** Download a file from the session workspace. Returns the raw response body. */
|
|
49
|
+
export async function downloadFile(config, sessionId, filePath, options) {
|
|
50
|
+
const url = `${config.apiUrl}/sessions/${sessionId}/files/${encodeURIComponent(filePath)}/download${options?.inline ? "?inline=true" : ""}`;
|
|
51
|
+
const auth = await freshAuthHeaders(config);
|
|
52
|
+
const resp = await fetch(url, {
|
|
53
|
+
redirect: "error",
|
|
54
|
+
headers: { ...auth },
|
|
55
|
+
signal: options?.signal,
|
|
56
|
+
});
|
|
57
|
+
if (resp.status === 401) {
|
|
58
|
+
throw new AuthError(`/sessions/${sessionId}/files/${filePath}/download`);
|
|
59
|
+
}
|
|
60
|
+
if (!resp.ok) {
|
|
61
|
+
throw new ApiError(`/sessions/${sessionId}/files/${filePath}/download`, resp.status, resp.statusText);
|
|
62
|
+
}
|
|
63
|
+
if (!resp.body) {
|
|
64
|
+
throw new NetworkError(`/sessions/${sessionId}/files/${filePath}/download`, new Error("No response body"));
|
|
65
|
+
}
|
|
66
|
+
return resp.body;
|
|
67
|
+
}
|
|
68
|
+
/** Delete a file from the session workspace. */
|
|
69
|
+
export async function deleteFile(config, sessionId, filePath) {
|
|
70
|
+
await apiFetch(config, `/sessions/${sessionId}/files/${encodeURIComponent(filePath)}`, { method: "DELETE" });
|
|
71
|
+
}
|
|
72
|
+
/** Get workspace file metadata (optimized for large datasets). */
|
|
73
|
+
export async function getWorkspaceMetadata(config, sessionId, directory) {
|
|
74
|
+
const params = directory ? `?directory=${encodeURIComponent(directory)}` : "";
|
|
75
|
+
const data = await apiFetch(config, `/sessions/${sessionId}/workspace/files/metadata${params}`);
|
|
76
|
+
return data.files ?? [];
|
|
77
|
+
}
|
|
78
|
+
/** Load an uploaded file into the active session for agent processing. */
|
|
79
|
+
export async function loadFileIntoSession(config, sessionId, filePath) {
|
|
80
|
+
return apiFetch(config, `/sessions/${sessionId}/data/load`, { method: "POST", body: { file_path: filePath } });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Download a session file for saving to disk: the body as a stream and its
|
|
84
|
+
* Content-Length when sent. Asks the stream host first (no CloudFront time
|
|
85
|
+
* limit on long transfers); a 403 there, as when that host requires the
|
|
86
|
+
* CloudFront origin header, falls back to the API host.
|
|
87
|
+
*/
|
|
88
|
+
export async function downloadFileForSave(config, sessionId, filePath, options) {
|
|
89
|
+
const path = `/sessions/${sessionId}/files/${encodeURIComponent(filePath)}/download`;
|
|
90
|
+
const bases = config.streamApiUrl && config.streamApiUrl !== config.apiUrl
|
|
91
|
+
? [config.streamApiUrl, config.apiUrl] : [config.apiUrl];
|
|
92
|
+
for (const [i, base] of bases.entries()) {
|
|
93
|
+
const auth = await freshAuthHeaders(config);
|
|
94
|
+
const resp = await fetch(`${base}${path}`, { redirect: "error", headers: { ...auth }, signal: options?.signal });
|
|
95
|
+
if (resp.status === 403 && i < bases.length - 1) {
|
|
96
|
+
await resp.body?.cancel().catch(() => { });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (resp.status === 401)
|
|
100
|
+
throw new AuthError(path);
|
|
101
|
+
if (!resp.ok)
|
|
102
|
+
throw new ApiError(path, resp.status, resp.statusText);
|
|
103
|
+
if (!resp.body)
|
|
104
|
+
throw new NetworkError(path, new Error("No response body"));
|
|
105
|
+
const length = Number(resp.headers.get("content-length"));
|
|
106
|
+
return { body: resp.body, size: Number.isSafeInteger(length) && resp.headers.has("content-length") ? length : null };
|
|
107
|
+
}
|
|
108
|
+
throw new NetworkError(path);
|
|
109
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * as biovault from "./biovault/index.js";
|
|
2
|
+
export type { AuthType, TokenSource, AppConfig, StoredCredentials, Session, SessionCreateRequest, SessionCreateResponse, SeedWarning, Message, AgentSummary, AgentDetail, AgentsListResponse, FeatureFlags, ApiRequestOptions, FileInfo, FileListResponse, FileUploadResponse, WorkspaceFileMetadata, ExportType, ExportRequest, ExportJobResponse, ExportResult, VaultSearchResult, VaultEvidence, VaultEvidenceResponse, VaultJobCreate, VaultJob, VaultJobResponse, VaultJobListResponse, VaultExportRequest, VaultExportResponse, EditorGenerateResponse, EditorGenerateResult, EditorGenerateJobResponse, EditorFileInfo, EditorFileListResponse, EditorMetaResponse, PromptTemplate, Resource, RuntimeInfo, BootstrapData, Project, Dataset, DatasetFile, VectorCollection, VectorSearchRequest, VectorSearchMatch, VectorSearchResponse, MeOrganizationResponse, } from "./types.js";
|
|
3
|
+
export { ApiError, AuthError, NOT_LOGGED_IN_MESSAGE, TenantAccessDeniedError, StoredCredentialOriginError, RateLimitError, NetworkError, UnreadableResponseError, UnknownOutcomeError, } from "./types.js";
|
|
4
|
+
export { readApiError, formatError, chatRefusalMessage, refusalWaitSeconds } from "./errors.js";
|
|
5
|
+
export { readStoredCredentials, readStoredCredentialsAsync, resolveConfig, authHeaders, freshAuthHeaders, streamUrl, validateApiOrigin, envApiKey, API_KEY_ENV, } from "./config.js";
|
|
6
|
+
export { CREDENTIALS_PATH, CLOUD_ENDPOINT, CLOUD_API_BASE, CLOUD_STREAM_BASE, LOCAL_API_BASE, apiUrlToEndpoint, endpointToApiUrl, resolveAuthBrokerApiUrl, readCredentialFile, readProfileCredential, readCredentialFileV2, saveStoredCredentials, saveProfileCredential, saveCredentialFileV2, syncRefreshedCredentialAcrossProfiles, removeStoredCredentials, removeProfile, clearActiveProfile, parseStoredCredential, getActiveProfileName, setActiveProfile, listProfiles as listCredentialProfiles, } from "./credentials.js";
|
|
7
|
+
export type { ApiKeyCredential, OAuthCredential, OmicsCredential, CredentialFileV2, CredentialProfile, } from "./credentials.js";
|
|
8
|
+
export { loginWithApiKey, runBrowserLogin, runDeviceLogin, exchangeCliAuthCode, verifyCurrentCredential, logoutStoredCredential, createCliAuthCallbackServer, } from "./auth.js";
|
|
9
|
+
export type { AuthVerifyResponse, BrowserLoginOptions, DeviceLoginOptions, DeviceStartResponse, } from "./auth.js";
|
|
10
|
+
export { apiFetch, apiStream, streamRefusal, setRequestObserver, } from "./apiClient.js";
|
|
11
|
+
export type { RequestTrace } from "./apiClient.js";
|
|
12
|
+
export { isUuidSessionId, createSession, seedWarningMessage, SESSION_OPEN_TIMEOUT_MS, SessionOpenTimeoutError, listSessions, resolveSessionId, archiveSession, deleteSession, shareSession, getSession, getSessionMessages, cancelSession, } from "./sessions.js";
|
|
13
|
+
export type { CancelSessionResult, SessionMessageItem, SessionMessagesResponse } from "./sessions.js";
|
|
14
|
+
export { listAgents, getAgentInfo, downloadAgent, } from "./agents.js";
|
|
15
|
+
export { fetchFeatureFlags, getCachedFlags, isFeatureEnabled, resetFlagsCache, } from "./featureFlags.js";
|
|
16
|
+
export { listFiles, uploadFile, downloadFile, downloadFileForSave, deleteFile, getWorkspaceMetadata, loadFileIntoSession, } from "./files.js";
|
|
17
|
+
export { startUpload, signUploadParts, getUpload, completeUpload, abortUpload, uploadErrorCode, uploadsUnavailable, MAX_SIGN_BATCH, } from "./uploads.js";
|
|
18
|
+
export { uploadProjectFile, fingerprintFile, hashRange, createLimiter, UploadFailure, PartPutError, DEFAULT_UPLOAD_CONCURRENCY, MAX_UPLOAD_CONCURRENCY, } from "./multipartUpload.js";
|
|
19
|
+
export type { Limiter, UploadProgress, UploadFileOptions, UploadFileResult, UploadFailureReason, } from "./multipartUpload.js";
|
|
20
|
+
export type { UploadState, UploadStartRequest, UploadStartResponse, SignedPart, UploadedPart, UploadStatus, UploadCompleteResponse, UploadErrorCode, ResumeTrust, } from "./uploads.js";
|
|
21
|
+
export { startExport, pollExportStatus, downloadExport, waitForExport, } from "./exports.js";
|
|
22
|
+
export { vaultSearch, getEvidence, vaultAsk, getJobStatus, listVaultJobs, cancelVaultJob, vaultExport, } from "./vault.js";
|
|
23
|
+
export { editorGenerate, editorPollGenerate, editorMeta, editorListFiles, editorPullFile, editorPushFile, editorCompile, editorStartCompile, editorCompileStatus, editorCompileToPdf, fetchCompiledPdf, editorDownload, } from "./editor.js";
|
|
24
|
+
export type { EditorCompileJob, EditorCompileStatus } from "./editor.js";
|
|
25
|
+
export { fetchTemplates, } from "./templates.js";
|
|
26
|
+
export { fetchResources, filterResources, resetResourcesCache, } from "./resources.js";
|
|
27
|
+
export { fetchBootstrap, } from "./bootstrap.js";
|
|
28
|
+
export { listProjects, getProject, createProject, uploadProjectRefusal, pushFile, listDatasetFiles, downloadProjectDataFile, downloadProjectDataLink, PROJECT_DATA_LINK_BYTES, } from "./projects.js";
|
|
29
|
+
export { vectorSearch, } from "./vectorSearch.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @omicsos/cloud-client — Omics-OS Cloud API SDK
|
|
2
|
+
export * as biovault from "./biovault/index.js";
|
|
3
|
+
export { ApiError, AuthError, NOT_LOGGED_IN_MESSAGE, TenantAccessDeniedError, StoredCredentialOriginError, RateLimitError, NetworkError, UnreadableResponseError, UnknownOutcomeError, } from "./types.js";
|
|
4
|
+
export { readApiError, formatError, chatRefusalMessage, refusalWaitSeconds } from "./errors.js";
|
|
5
|
+
export { readStoredCredentials, readStoredCredentialsAsync, resolveConfig, authHeaders, freshAuthHeaders, streamUrl, validateApiOrigin, envApiKey, API_KEY_ENV, } from "./config.js";
|
|
6
|
+
export { CREDENTIALS_PATH, CLOUD_ENDPOINT, CLOUD_API_BASE, CLOUD_STREAM_BASE, LOCAL_API_BASE, apiUrlToEndpoint, endpointToApiUrl, resolveAuthBrokerApiUrl, readCredentialFile, readProfileCredential, readCredentialFileV2, saveStoredCredentials, saveProfileCredential, saveCredentialFileV2, syncRefreshedCredentialAcrossProfiles, removeStoredCredentials, removeProfile, clearActiveProfile, parseStoredCredential, getActiveProfileName, setActiveProfile, listProfiles as listCredentialProfiles, } from "./credentials.js";
|
|
7
|
+
export { loginWithApiKey, runBrowserLogin, runDeviceLogin, exchangeCliAuthCode, verifyCurrentCredential, logoutStoredCredential, createCliAuthCallbackServer, } from "./auth.js";
|
|
8
|
+
export { apiFetch, apiStream, streamRefusal, setRequestObserver, } from "./apiClient.js";
|
|
9
|
+
export { isUuidSessionId, createSession, seedWarningMessage, SESSION_OPEN_TIMEOUT_MS, SessionOpenTimeoutError, listSessions, resolveSessionId, archiveSession, deleteSession, shareSession, getSession, getSessionMessages, cancelSession, } from "./sessions.js";
|
|
10
|
+
export { listAgents, getAgentInfo, downloadAgent, } from "./agents.js";
|
|
11
|
+
export { fetchFeatureFlags, getCachedFlags, isFeatureEnabled, resetFlagsCache, } from "./featureFlags.js";
|
|
12
|
+
export { listFiles, uploadFile, downloadFile, downloadFileForSave, deleteFile, getWorkspaceMetadata, loadFileIntoSession, } from "./files.js";
|
|
13
|
+
export { startUpload, signUploadParts, getUpload, completeUpload, abortUpload, uploadErrorCode, uploadsUnavailable, MAX_SIGN_BATCH, } from "./uploads.js";
|
|
14
|
+
export { uploadProjectFile, fingerprintFile, hashRange, createLimiter, UploadFailure, PartPutError, DEFAULT_UPLOAD_CONCURRENCY, MAX_UPLOAD_CONCURRENCY, } from "./multipartUpload.js";
|
|
15
|
+
export { startExport, pollExportStatus, downloadExport, waitForExport, } from "./exports.js";
|
|
16
|
+
export { vaultSearch, getEvidence, vaultAsk, getJobStatus, listVaultJobs, cancelVaultJob, vaultExport, } from "./vault.js";
|
|
17
|
+
export { editorGenerate, editorPollGenerate, editorMeta, editorListFiles, editorPullFile, editorPushFile, editorCompile, editorStartCompile, editorCompileStatus, editorCompileToPdf, fetchCompiledPdf, editorDownload, } from "./editor.js";
|
|
18
|
+
export { fetchTemplates, } from "./templates.js";
|
|
19
|
+
export { fetchResources, filterResources, resetResourcesCache, } from "./resources.js";
|
|
20
|
+
export { fetchBootstrap, } from "./bootstrap.js";
|
|
21
|
+
export { listProjects, getProject, createProject, uploadProjectRefusal, pushFile, listDatasetFiles, downloadProjectDataFile, downloadProjectDataLink, PROJECT_DATA_LINK_BYTES, } from "./projects.js";
|
|
22
|
+
export { vectorSearch, } from "./vectorSearch.js";
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resumable upload of one local file into a project's data, at its relative path.
|
|
3
|
+
*
|
|
4
|
+
* The bytes go straight to presigned S3 part URLs with node:http(s) and a
|
|
5
|
+
* stream pipeline, so memory stays bounded whatever the file size (fetch with a
|
|
6
|
+
* stream body buffers the whole file). Each part is read twice: once to hash
|
|
7
|
+
* it (S3 checks the SHA-256 the URL is signed for), once to send it.
|
|
8
|
+
*
|
|
9
|
+
* Resume state lives on the server: start (C1) finds the open upload for the
|
|
10
|
+
* same project, path, size and fingerprint, and status (C3) lists the parts S3
|
|
11
|
+
* holds. Listed parts are trusted on that match (as DNAnexus and tus do), unless
|
|
12
|
+
* the mtime stored with the upload differs from the file's: then each listed part
|
|
13
|
+
* is re-hashed and compared first. A file whose size or mtime changes during the
|
|
14
|
+
* run is not completed.
|
|
15
|
+
*
|
|
16
|
+
* One path holds one current file: a different file already there is refused
|
|
17
|
+
* (file_exists) unless `replace`, and the server's other refusals of one file
|
|
18
|
+
* come back as an UploadFailure with the server's words.
|
|
19
|
+
*/
|
|
20
|
+
import type { AppConfig } from "./types.js";
|
|
21
|
+
import { type ResumeTrust } from "./uploads.js";
|
|
22
|
+
export declare const DEFAULT_UPLOAD_CONCURRENCY = 4;
|
|
23
|
+
export declare const MAX_UPLOAD_CONCURRENCY = 16;
|
|
24
|
+
export type UploadFailureReason = "file_changed" | "not_regular" | "empty" | "part_failed" | "server" | "expired" | "file_exists" | "upload_in_progress" | "quota_exceeded" | "upload_too_large" | "invalid_path" | "not_current" | "complete_conflict";
|
|
25
|
+
/** A file could not be uploaded. The message is fit to show; `reason` is for scripts. */
|
|
26
|
+
export declare class UploadFailure extends Error {
|
|
27
|
+
readonly reason: UploadFailureReason;
|
|
28
|
+
/** On not_current: the version this upload created, kept as a noncurrent version. */
|
|
29
|
+
readonly versionId?: string;
|
|
30
|
+
constructor(reason: UploadFailureReason, message: string, options?: {
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
versionId?: string;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** S3 refused a part PUT. */
|
|
36
|
+
export declare class PartPutError extends Error {
|
|
37
|
+
readonly status: number;
|
|
38
|
+
readonly s3Code: string | undefined;
|
|
39
|
+
constructor(status: number, s3Code: string | undefined, message: string);
|
|
40
|
+
}
|
|
41
|
+
/** Limits how many part PUTs run at once, shared by every file of one command. */
|
|
42
|
+
export interface Limiter {
|
|
43
|
+
run<T>(task: () => Promise<T>): Promise<T>;
|
|
44
|
+
}
|
|
45
|
+
export declare function createLimiter(size: number): Limiter;
|
|
46
|
+
export interface UploadProgress {
|
|
47
|
+
/** "verify": re-hashing parts already on the server; "send": sending parts. */
|
|
48
|
+
phase: "verify" | "send";
|
|
49
|
+
bytes: number;
|
|
50
|
+
total: number;
|
|
51
|
+
}
|
|
52
|
+
export interface UploadFileOptions {
|
|
53
|
+
projectId: string;
|
|
54
|
+
/** Local path of the file. */
|
|
55
|
+
path: string;
|
|
56
|
+
/** POSIX path relative to the folder or file the user named. */
|
|
57
|
+
relativePath: string;
|
|
58
|
+
/** Parts sent at once by this file (1–16, default 4). */
|
|
59
|
+
concurrency?: number;
|
|
60
|
+
/** Shared limit on part PUTs across files; defaults to one of `concurrency`. */
|
|
61
|
+
limiter?: Limiter;
|
|
62
|
+
/**
|
|
63
|
+
* Overwrite a different file already at this path, or cancel this user's own unfinished upload of
|
|
64
|
+
* an earlier version of the file. Sent to the server only once it reports one (file_exists,
|
|
65
|
+
* upload_in_progress), so a file already in the project (same path, size and fingerprint) is still skipped.
|
|
66
|
+
*/
|
|
67
|
+
replace?: boolean;
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
70
|
+
/** Tests: first retry wait (doubles each time, capped at 60 s). */
|
|
71
|
+
retryBaseMs?: number;
|
|
72
|
+
/** Tests: attempts per part before giving up. */
|
|
73
|
+
maxAttempts?: number;
|
|
74
|
+
/** Tests: a part PUT socket idle this long is dropped and retried. */
|
|
75
|
+
idleTimeoutMs?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface UploadFileResult {
|
|
78
|
+
/** sent: new upload; resumed: earlier parts reused; skipped: already in the project. */
|
|
79
|
+
outcome: "sent" | "resumed" | "skipped";
|
|
80
|
+
/** The file's path in the project. */
|
|
81
|
+
relativePath: string;
|
|
82
|
+
/** The project file's version (absent when the server returns none). */
|
|
83
|
+
versionId?: string;
|
|
84
|
+
sizeBytes: number;
|
|
85
|
+
partsSent: number;
|
|
86
|
+
partsReused: number;
|
|
87
|
+
/** "fingerprint" when skipped on path, size and fingerprint rather than a hash checked by the server. */
|
|
88
|
+
match?: string;
|
|
89
|
+
/** The file was sent again from the start, once: its unfinished upload expired, or a conflicting write raced its completion. */
|
|
90
|
+
restarted?: "expired" | "complete_conflict";
|
|
91
|
+
/** What the server recorded about reused parts (only when it returns it). */
|
|
92
|
+
resumeTrust?: ResumeTrust;
|
|
93
|
+
}
|
|
94
|
+
/** Hex SHA-256 over the first and last 8 MiB and the size (the whole file and the size up to 16 MiB). */
|
|
95
|
+
export declare function fingerprintFile(path: string, size: number, signal?: AbortSignal): Promise<string>;
|
|
96
|
+
/** Base64 SHA-256 of one byte range, the form S3 uses for x-amz-checksum-sha256. */
|
|
97
|
+
export declare function hashRange(path: string, start: number, end: number, signal?: AbortSignal, onBytes?: (n: number) => void): Promise<string>;
|
|
98
|
+
/** Upload one file; resumes an earlier upload of the same file when the server still holds it. */
|
|
99
|
+
export declare function uploadProjectFile(config: AppConfig, options: UploadFileOptions): Promise<UploadFileResult>;
|