omics-os 0.0.1 → 1.3.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/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 +462 -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,395 @@
|
|
|
1
|
+
import { chmodSync, closeSync, constants as fsConstants, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync, writeSync, } from "fs";
|
|
2
|
+
import { randomBytes } from "crypto";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
export const CLOUD_ENDPOINT = "https://app.omics-os.com";
|
|
6
|
+
export const CLOUD_API_BASE = `${CLOUD_ENDPOINT}/api/v1`;
|
|
7
|
+
export const CLOUD_STREAM_BASE = "https://stream.omics-os.com/api/v1";
|
|
8
|
+
export const LOCAL_API_BASE = "http://localhost:8000";
|
|
9
|
+
export const CREDENTIALS_PATH = join(homedir(), ".config", "omics-os", "credentials.json");
|
|
10
|
+
const STATIC_ALLOWED_ORIGINS = new Set([
|
|
11
|
+
CLOUD_ENDPOINT,
|
|
12
|
+
"https://stream.omics-os.com",
|
|
13
|
+
"http://localhost:8000",
|
|
14
|
+
"http://127.0.0.1:8000",
|
|
15
|
+
]);
|
|
16
|
+
function isAllowedOrigin(origin) {
|
|
17
|
+
if (STATIC_ALLOWED_ORIGINS.has(origin))
|
|
18
|
+
return true;
|
|
19
|
+
try {
|
|
20
|
+
const url = new URL(origin);
|
|
21
|
+
if (url.protocol === "https:" && url.hostname.endsWith(".omics-os.com"))
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch { }
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
export function apiUrlToEndpoint(apiUrl) {
|
|
28
|
+
const url = new URL(apiUrl);
|
|
29
|
+
return url.origin;
|
|
30
|
+
}
|
|
31
|
+
/** Resolve the API base for CLI OAuth broker calls (start, token, refresh,
|
|
32
|
+
* device, revoke). These are PLATFORM concerns — credentials are platform-wide
|
|
33
|
+
* (single shared Cognito pool) and tenant subdomains gate every non-public path,
|
|
34
|
+
* so an unauthenticated refresh POST to a tenant host is rejected by the tenant
|
|
35
|
+
* gate before it reaches the handler. Always route broker calls to the canonical
|
|
36
|
+
* platform API. Localhost is preserved for local backend development. */
|
|
37
|
+
export function resolveAuthBrokerApiUrl(apiUrl) {
|
|
38
|
+
if (apiUrl) {
|
|
39
|
+
try {
|
|
40
|
+
const { hostname } = new URL(apiUrl);
|
|
41
|
+
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
42
|
+
return apiUrl.replace(/\/+$/, "");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// fall through to platform default
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return CLOUD_API_BASE;
|
|
50
|
+
}
|
|
51
|
+
export function endpointToApiUrl(endpoint) {
|
|
52
|
+
return `${endpoint.replace(/\/+$/, "")}/api/v1`;
|
|
53
|
+
}
|
|
54
|
+
export function isAllowedEndpoint(endpoint) {
|
|
55
|
+
try {
|
|
56
|
+
const url = new URL(endpoint.replace(/\/+$/, ""));
|
|
57
|
+
if (url.username || url.password || url.hash)
|
|
58
|
+
return false;
|
|
59
|
+
return isAllowedOrigin(url.origin);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function validateApiOrigin(apiUrl) {
|
|
66
|
+
try {
|
|
67
|
+
const origin = new URL(apiUrl).origin;
|
|
68
|
+
return { safe: isAllowedOrigin(origin), origin };
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return { safe: false, origin: apiUrl };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function readCredentialFile() {
|
|
75
|
+
return readProfileCredential();
|
|
76
|
+
}
|
|
77
|
+
export function saveStoredCredentials(creds) {
|
|
78
|
+
const profileName = getActiveProfileName();
|
|
79
|
+
const label = profileName === "default" ? "Platform" : profileName;
|
|
80
|
+
saveProfileCredential(profileName, creds, label);
|
|
81
|
+
}
|
|
82
|
+
export function removeStoredCredentials() {
|
|
83
|
+
if (!existsSync(CREDENTIALS_PATH))
|
|
84
|
+
return false;
|
|
85
|
+
const stat = lstatSync(CREDENTIALS_PATH);
|
|
86
|
+
if (!stat.isSymbolicLink()) {
|
|
87
|
+
writeFileSync(CREDENTIALS_PATH, Buffer.alloc(stat.size, 0), { mode: 0o600 });
|
|
88
|
+
}
|
|
89
|
+
unlinkSync(CREDENTIALS_PATH);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
export function parseStoredCredential(data) {
|
|
93
|
+
if (!data || typeof data !== "object")
|
|
94
|
+
return undefined;
|
|
95
|
+
const d = data;
|
|
96
|
+
if (d.auth_mode === "api_key") {
|
|
97
|
+
if (typeof d.api_key !== "string" || !d.api_key.startsWith("omk_"))
|
|
98
|
+
return undefined;
|
|
99
|
+
return {
|
|
100
|
+
auth_mode: "api_key",
|
|
101
|
+
api_key: d.api_key,
|
|
102
|
+
endpoint: stringOrDefault(d.endpoint, CLOUD_ENDPOINT),
|
|
103
|
+
user_id: stringOrUndefined(d.user_id),
|
|
104
|
+
email: stringOrUndefined(d.email),
|
|
105
|
+
org_id: stringOrUndefined(d.org_id),
|
|
106
|
+
tier: stringOrUndefined(d.tier),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (d.auth_mode === "oauth") {
|
|
110
|
+
if (d.credential_type !== "omics_cli")
|
|
111
|
+
return undefined;
|
|
112
|
+
if (typeof d.credential_id !== "string" || d.credential_id.length === 0)
|
|
113
|
+
return undefined;
|
|
114
|
+
if (typeof d.cli_token !== "string" || !d.cli_token.startsWith("omc_"))
|
|
115
|
+
return undefined;
|
|
116
|
+
if (typeof d.refresh_token !== "string" || !d.refresh_token.startsWith("omr_"))
|
|
117
|
+
return undefined;
|
|
118
|
+
if (typeof d.token_expiry !== "string" || d.token_expiry.length === 0)
|
|
119
|
+
return undefined;
|
|
120
|
+
if (typeof d.refresh_expiry !== "string" || d.refresh_expiry.length === 0)
|
|
121
|
+
return undefined;
|
|
122
|
+
return {
|
|
123
|
+
auth_mode: "oauth",
|
|
124
|
+
credential_type: "omics_cli",
|
|
125
|
+
credential_id: d.credential_id,
|
|
126
|
+
cli_token: d.cli_token,
|
|
127
|
+
refresh_token: d.refresh_token,
|
|
128
|
+
token_expiry: d.token_expiry,
|
|
129
|
+
refresh_expiry: d.refresh_expiry,
|
|
130
|
+
endpoint: stringOrDefault(d.endpoint, CLOUD_ENDPOINT),
|
|
131
|
+
user_id: stringOrUndefined(d.user_id),
|
|
132
|
+
email: stringOrUndefined(d.email),
|
|
133
|
+
org_id: stringOrUndefined(d.org_id),
|
|
134
|
+
tier: stringOrUndefined(d.tier),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
export function parseOAuthCredentialResponse(data, endpoint) {
|
|
140
|
+
const source = extractCredentialPayload(data);
|
|
141
|
+
if (!source || typeof source !== "object")
|
|
142
|
+
return undefined;
|
|
143
|
+
const d = source;
|
|
144
|
+
const credential = {
|
|
145
|
+
auth_mode: "oauth",
|
|
146
|
+
credential_type: "omics_cli",
|
|
147
|
+
credential_id: String(d.credential_id ?? ""),
|
|
148
|
+
cli_token: String(d.cli_token ?? ""),
|
|
149
|
+
refresh_token: String(d.refresh_token ?? ""),
|
|
150
|
+
token_expiry: String(d.token_expiry ?? ""),
|
|
151
|
+
refresh_expiry: String(d.refresh_expiry ?? ""),
|
|
152
|
+
endpoint: stringOrDefault(d.endpoint, endpoint),
|
|
153
|
+
user_id: stringOrUndefined(d.user_id),
|
|
154
|
+
email: stringOrUndefined(d.email),
|
|
155
|
+
org_id: stringOrUndefined(d.org_id),
|
|
156
|
+
tier: stringOrUndefined(d.tier),
|
|
157
|
+
};
|
|
158
|
+
return parseStoredCredential(credential);
|
|
159
|
+
}
|
|
160
|
+
function extractCredentialPayload(data) {
|
|
161
|
+
if (!data || typeof data !== "object")
|
|
162
|
+
return data;
|
|
163
|
+
const d = data;
|
|
164
|
+
return d.credential ?? d.credentials ?? data;
|
|
165
|
+
}
|
|
166
|
+
export function readCredentialFileV2() {
|
|
167
|
+
try {
|
|
168
|
+
if (!existsSync(CREDENTIALS_PATH))
|
|
169
|
+
return undefined;
|
|
170
|
+
const raw = JSON.parse(readFileSync(CREDENTIALS_PATH, "utf-8"));
|
|
171
|
+
if (!raw || typeof raw !== "object")
|
|
172
|
+
return undefined;
|
|
173
|
+
const d = raw;
|
|
174
|
+
if (d.version === 2 && typeof d.active_profile === "string" && typeof d.profiles === "object") {
|
|
175
|
+
return raw;
|
|
176
|
+
}
|
|
177
|
+
// V1 auto-migration
|
|
178
|
+
const v1 = parseStoredCredential(raw);
|
|
179
|
+
if (!v1)
|
|
180
|
+
return undefined;
|
|
181
|
+
const profile = {
|
|
182
|
+
endpoint: v1.endpoint ?? CLOUD_ENDPOINT,
|
|
183
|
+
label: "Platform",
|
|
184
|
+
auth_mode: v1.auth_mode,
|
|
185
|
+
...(v1.auth_mode === "oauth" ? {
|
|
186
|
+
credential_type: v1.credential_type,
|
|
187
|
+
credential_id: v1.credential_id,
|
|
188
|
+
cli_token: v1.cli_token,
|
|
189
|
+
refresh_token: v1.refresh_token,
|
|
190
|
+
token_expiry: v1.token_expiry,
|
|
191
|
+
refresh_expiry: v1.refresh_expiry,
|
|
192
|
+
} : {
|
|
193
|
+
api_key: v1.api_key,
|
|
194
|
+
}),
|
|
195
|
+
user_id: v1.user_id,
|
|
196
|
+
email: v1.email,
|
|
197
|
+
org_id: v1.org_id,
|
|
198
|
+
tier: v1.tier,
|
|
199
|
+
};
|
|
200
|
+
const v2 = { version: 2, active_profile: "default", profiles: { default: profile } };
|
|
201
|
+
saveCredentialFileV2(v2);
|
|
202
|
+
return v2;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
export function saveCredentialFileV2(file) {
|
|
209
|
+
const dir = dirname(CREDENTIALS_PATH);
|
|
210
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
211
|
+
chmodSync(dir, 0o700);
|
|
212
|
+
const tmpPath = `${CREDENTIALS_PATH}.tmp.${randomBytes(4).toString("hex")}`;
|
|
213
|
+
const fd = openSync(tmpPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_WRONLY, 0o600);
|
|
214
|
+
try {
|
|
215
|
+
const buf = Buffer.from(JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
216
|
+
writeSync(fd, buf);
|
|
217
|
+
fsyncSync(fd);
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
closeSync(fd);
|
|
221
|
+
}
|
|
222
|
+
renameSync(tmpPath, CREDENTIALS_PATH);
|
|
223
|
+
chmodSync(CREDENTIALS_PATH, 0o600);
|
|
224
|
+
}
|
|
225
|
+
export function getActiveProfileName() {
|
|
226
|
+
const file = readCredentialFileV2();
|
|
227
|
+
return file?.active_profile ?? "default";
|
|
228
|
+
}
|
|
229
|
+
const PROFILE_NAME_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
230
|
+
function isValidProfileName(name) {
|
|
231
|
+
return name === "default" || PROFILE_NAME_RE.test(name);
|
|
232
|
+
}
|
|
233
|
+
export function setActiveProfile(name) {
|
|
234
|
+
const file = readCredentialFileV2();
|
|
235
|
+
if (!file)
|
|
236
|
+
throw new Error("No credentials file found. Run 'omics-os login' first.");
|
|
237
|
+
if (!Object.hasOwn(file.profiles, name))
|
|
238
|
+
throw new Error(`Profile '${name}' not found. Run 'omics-os profiles' to see available profiles.`);
|
|
239
|
+
file.active_profile = name;
|
|
240
|
+
saveCredentialFileV2(file);
|
|
241
|
+
}
|
|
242
|
+
export function listProfiles() {
|
|
243
|
+
const file = readCredentialFileV2();
|
|
244
|
+
if (!file)
|
|
245
|
+
return [];
|
|
246
|
+
return Object.entries(file.profiles).map(([name, p]) => ({
|
|
247
|
+
name,
|
|
248
|
+
endpoint: p.endpoint,
|
|
249
|
+
label: p.label,
|
|
250
|
+
email: p.email,
|
|
251
|
+
active: name === file.active_profile,
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
254
|
+
export function removeProfile(name) {
|
|
255
|
+
const file = readCredentialFileV2();
|
|
256
|
+
if (!file || !Object.hasOwn(file.profiles, name))
|
|
257
|
+
return false;
|
|
258
|
+
if (name === "default")
|
|
259
|
+
throw new Error("Cannot remove the 'default' profile.");
|
|
260
|
+
delete file.profiles[name];
|
|
261
|
+
if (file.active_profile === name) {
|
|
262
|
+
const remaining = Object.keys(file.profiles);
|
|
263
|
+
file.active_profile = remaining.includes("default") ? "default" : (remaining[0] ?? "default");
|
|
264
|
+
}
|
|
265
|
+
saveCredentialFileV2(file);
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
/** Log out of a single profile, preserving siblings — mirrors Python's
|
|
269
|
+
* `_clear_active_profile`. Removes `profiles[target]` (target defaults to the
|
|
270
|
+
* active profile); if survivors remain, repoints `active_profile` to one and
|
|
271
|
+
* writes back; if it was the last profile — or the file is V1/absent — deletes
|
|
272
|
+
* the whole file. A whole-file wipe is reserved for an explicit logout --all. */
|
|
273
|
+
export function clearActiveProfile(profile) {
|
|
274
|
+
const file = readCredentialFileV2();
|
|
275
|
+
// V1 flat file or no file: legacy whole-file removal.
|
|
276
|
+
if (!file)
|
|
277
|
+
return removeStoredCredentials();
|
|
278
|
+
const target = profile ?? file.active_profile;
|
|
279
|
+
if (!Object.hasOwn(file.profiles, target))
|
|
280
|
+
return false;
|
|
281
|
+
delete file.profiles[target];
|
|
282
|
+
const survivors = Object.keys(file.profiles);
|
|
283
|
+
if (survivors.length === 0) {
|
|
284
|
+
// Last profile removed — remove the file entirely.
|
|
285
|
+
return removeStoredCredentials();
|
|
286
|
+
}
|
|
287
|
+
if (file.active_profile === target) {
|
|
288
|
+
file.active_profile = survivors.includes("default") ? "default" : survivors[0];
|
|
289
|
+
}
|
|
290
|
+
saveCredentialFileV2(file);
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
export function saveProfileCredential(profileName, creds, label) {
|
|
294
|
+
if (!isValidProfileName(profileName)) {
|
|
295
|
+
throw new Error(`Invalid profile name '${profileName}'. Must be lowercase alphanumeric with optional hyphens.`);
|
|
296
|
+
}
|
|
297
|
+
let file = readCredentialFileV2();
|
|
298
|
+
if (!file) {
|
|
299
|
+
file = { version: 2, active_profile: "default", profiles: {} };
|
|
300
|
+
}
|
|
301
|
+
const profile = {
|
|
302
|
+
endpoint: creds.endpoint ?? CLOUD_ENDPOINT,
|
|
303
|
+
label,
|
|
304
|
+
auth_mode: creds.auth_mode,
|
|
305
|
+
...(creds.auth_mode === "oauth" ? {
|
|
306
|
+
credential_type: creds.credential_type,
|
|
307
|
+
credential_id: creds.credential_id,
|
|
308
|
+
cli_token: creds.cli_token,
|
|
309
|
+
refresh_token: creds.refresh_token,
|
|
310
|
+
token_expiry: creds.token_expiry,
|
|
311
|
+
refresh_expiry: creds.refresh_expiry,
|
|
312
|
+
} : {
|
|
313
|
+
api_key: creds.api_key,
|
|
314
|
+
}),
|
|
315
|
+
user_id: creds.user_id,
|
|
316
|
+
email: creds.email,
|
|
317
|
+
org_id: creds.org_id,
|
|
318
|
+
tier: creds.tier,
|
|
319
|
+
};
|
|
320
|
+
file.profiles[profileName] = profile;
|
|
321
|
+
saveCredentialFileV2(file);
|
|
322
|
+
}
|
|
323
|
+
/** Propagate a rotated OAuth credential to EVERY profile that shares the same
|
|
324
|
+
* credential_id, except `sourceProfile` (already saved by the caller).
|
|
325
|
+
* Tenant login stores one platform-wide credential under multiple profiles
|
|
326
|
+
* (e.g. "default" + the tenant). Refresh rotates the shared refresh token, so
|
|
327
|
+
* the other profiles must be updated or they keep a burned token. Each profile
|
|
328
|
+
* keeps its OWN endpoint and label — only the rotating token material changes. */
|
|
329
|
+
export function syncRefreshedCredentialAcrossProfiles(credentialId, refreshed, sourceProfile) {
|
|
330
|
+
if (!credentialId)
|
|
331
|
+
return;
|
|
332
|
+
const file = readCredentialFileV2();
|
|
333
|
+
if (!file)
|
|
334
|
+
return;
|
|
335
|
+
let changed = false;
|
|
336
|
+
for (const [name, p] of Object.entries(file.profiles)) {
|
|
337
|
+
if (name === sourceProfile)
|
|
338
|
+
continue;
|
|
339
|
+
if (p.auth_mode !== "oauth" || p.credential_id !== credentialId)
|
|
340
|
+
continue;
|
|
341
|
+
// Update only the token material; preserve this profile's endpoint + label.
|
|
342
|
+
p.cli_token = refreshed.cli_token;
|
|
343
|
+
p.refresh_token = refreshed.refresh_token;
|
|
344
|
+
p.token_expiry = refreshed.token_expiry;
|
|
345
|
+
p.refresh_expiry = refreshed.refresh_expiry;
|
|
346
|
+
changed = true;
|
|
347
|
+
}
|
|
348
|
+
if (changed)
|
|
349
|
+
saveCredentialFileV2(file);
|
|
350
|
+
}
|
|
351
|
+
export function readProfileCredential(profileName) {
|
|
352
|
+
const file = readCredentialFileV2();
|
|
353
|
+
if (!file)
|
|
354
|
+
return undefined;
|
|
355
|
+
const name = profileName ?? file.active_profile;
|
|
356
|
+
if (!Object.hasOwn(file.profiles, name))
|
|
357
|
+
return undefined;
|
|
358
|
+
const profile = file.profiles[name];
|
|
359
|
+
if (!profile)
|
|
360
|
+
return undefined;
|
|
361
|
+
if (profile.auth_mode === "api_key" && profile.api_key) {
|
|
362
|
+
return {
|
|
363
|
+
auth_mode: "api_key",
|
|
364
|
+
api_key: profile.api_key,
|
|
365
|
+
endpoint: profile.endpoint,
|
|
366
|
+
user_id: profile.user_id,
|
|
367
|
+
email: profile.email,
|
|
368
|
+
org_id: profile.org_id,
|
|
369
|
+
tier: profile.tier,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (profile.auth_mode === "oauth" && profile.cli_token && profile.refresh_token) {
|
|
373
|
+
return {
|
|
374
|
+
auth_mode: "oauth",
|
|
375
|
+
credential_type: "omics_cli",
|
|
376
|
+
credential_id: profile.credential_id ?? "",
|
|
377
|
+
cli_token: profile.cli_token,
|
|
378
|
+
refresh_token: profile.refresh_token,
|
|
379
|
+
token_expiry: profile.token_expiry ?? "",
|
|
380
|
+
refresh_expiry: profile.refresh_expiry ?? "",
|
|
381
|
+
endpoint: profile.endpoint,
|
|
382
|
+
user_id: profile.user_id,
|
|
383
|
+
email: profile.email,
|
|
384
|
+
org_id: profile.org_id,
|
|
385
|
+
tier: profile.tier,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return undefined;
|
|
389
|
+
}
|
|
390
|
+
function stringOrDefault(value, fallback) {
|
|
391
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
392
|
+
}
|
|
393
|
+
function stringOrUndefined(value) {
|
|
394
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
395
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Editor — LaTeX generation, file CRUD, compile, download. */
|
|
2
|
+
import type { AppConfig, EditorGenerateResponse, EditorGenerateJobResponse, EditorFileInfo, EditorMetaResponse } from "./types.js";
|
|
3
|
+
/** Start LaTeX generation for a session (async job, returns 202). */
|
|
4
|
+
export declare function editorGenerate(config: AppConfig, sessionId: string, options?: {
|
|
5
|
+
force?: boolean;
|
|
6
|
+
}): Promise<EditorGenerateResponse>;
|
|
7
|
+
/** Poll LaTeX generation job status. */
|
|
8
|
+
export declare function editorPollGenerate(config: AppConfig, sessionId: string, jobId: string): Promise<EditorGenerateJobResponse>;
|
|
9
|
+
/** Get editor project metadata (lightweight — no S3 list). */
|
|
10
|
+
export declare function editorMeta(config: AppConfig, sessionId: string): Promise<EditorMetaResponse>;
|
|
11
|
+
/** List all files in the editor project. */
|
|
12
|
+
export declare function editorListFiles(config: AppConfig, sessionId: string): Promise<EditorFileInfo[]>;
|
|
13
|
+
/** Get (pull) editor file content. Returns raw bytes. */
|
|
14
|
+
export declare function editorPullFile(config: AppConfig, sessionId: string, filePath: string, options?: {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}): Promise<ArrayBuffer>;
|
|
17
|
+
/** Save (push) editor file content. */
|
|
18
|
+
export declare function editorPushFile(config: AppConfig, sessionId: string, filePath: string, content: string | Uint8Array): Promise<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
path: string;
|
|
21
|
+
size: number;
|
|
22
|
+
}>;
|
|
23
|
+
/** Compile LaTeX via the backend proxy. Returns raw PDF bytes. */
|
|
24
|
+
export declare function editorCompile(config: AppConfig, sessionId: string, options?: {
|
|
25
|
+
resources?: Array<{
|
|
26
|
+
path: string;
|
|
27
|
+
content?: string;
|
|
28
|
+
file?: string;
|
|
29
|
+
main?: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
compiler?: string;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}): Promise<ArrayBuffer>;
|
|
34
|
+
/** Download entire editor project as a zip. Returns raw zip bytes. */
|
|
35
|
+
export declare function editorDownload(config: AppConfig, sessionId: string, options?: {
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}): Promise<ArrayBuffer>;
|
|
38
|
+
/** A background compile job, as the server reports it. */
|
|
39
|
+
export interface EditorCompileJob {
|
|
40
|
+
job_id: string;
|
|
41
|
+
status: string;
|
|
42
|
+
}
|
|
43
|
+
/** One poll of a compile job. `pdf_url` is a short-lived signed link. */
|
|
44
|
+
export interface EditorCompileStatus {
|
|
45
|
+
status: string;
|
|
46
|
+
pdf_url?: string;
|
|
47
|
+
error?: string;
|
|
48
|
+
error_code?: string;
|
|
49
|
+
log?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Start compiling the stored editor project (202 + job id). */
|
|
52
|
+
export declare function editorStartCompile(config: AppConfig, sessionId: string, options?: {
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}): Promise<EditorCompileJob>;
|
|
55
|
+
/** Poll a compile job. */
|
|
56
|
+
export declare function editorCompileStatus(config: AppConfig, sessionId: string, jobId: string, options?: {
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}): Promise<EditorCompileStatus>;
|
|
59
|
+
/** Download the finished PDF from its signed link. The link carries its own
|
|
60
|
+
* authorization, so no CLI credential is sent; only an https link on S3 is
|
|
61
|
+
* followed, without redirects, and only PDF bytes are returned. Failure
|
|
62
|
+
* messages never include the link (it is a credential while it lasts). */
|
|
63
|
+
export declare function fetchCompiledPdf(pdfUrl: string, options?: {
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}): Promise<ArrayBuffer>;
|
|
66
|
+
/** Compile the stored editor project and return the PDF: start a job, poll
|
|
67
|
+
* until it finishes, then download the PDF from its signed link. */
|
|
68
|
+
export declare function editorCompileToPdf(config: AppConfig, sessionId: string, options?: {
|
|
69
|
+
intervalMs?: number;
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
onStatus?: (status: string) => void;
|
|
73
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
pdf: ArrayBuffer;
|
|
76
|
+
jobId: string;
|
|
77
|
+
}>;
|