@almadar/workspace 0.4.1 → 0.6.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/__tests__/account-auth-token.test.d.ts +1 -0
- package/dist/__tests__/open-create-false.test.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/dist/open-workspace.d.ts +3 -0
- package/dist/types.d.ts +33 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export { openWorkspace } from './open-workspace.js';
|
|
|
10
10
|
export { listWorkspaces } from './list-workspaces.js';
|
|
11
11
|
export { deleteWorkspace } from './delete-workspace.js';
|
|
12
12
|
export { openAccount } from './account.js';
|
|
13
|
-
export type { WorkspaceService, WorkspaceObserver, WorkspaceWriteEvent, WorkspaceWatchEvent, OpenWorkspaceOptions, ListWorkspacesOptions, WorkspaceSummary, RestoreBackend, GitHubConfig, GitStatusInfo, FileTreeNode, AccountService, AccountConfig, ProviderCredential, AccountIdentity, OpenAccountOptions, } from './types.js';
|
|
13
|
+
export type { WorkspaceService, WorkspaceObserver, WorkspaceWriteEvent, WorkspaceWatchEvent, OpenWorkspaceOptions, ListWorkspacesOptions, WorkspaceSummary, RestoreBackend, GitHubConfig, GitStatusInfo, FileTreeNode, AccountService, AccountConfig, ProviderCredential, AuthToken, AccountIdentity, OpenAccountOptions, } from './types.js';
|
|
14
14
|
export type { WorkspaceIndex, EmbedderPort, ResolveResult, ResolveOptions, TraitRefEmit, WorkspaceIndexStats, OrbitalIndexEntry, ExtraTraitIdentity, RetrievalResult, RetrievalOptions, RecentlyEditedOptions, EventEdge, EntityBinding, RuleBinding, RecencyEntry, IntentMaps, ComposedMaps, BM25Document, BM25Table, BM25Options, WorkspaceIndexManifest, } from './workspace-index/types.js';
|
|
15
15
|
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, } from './workspace-index/types.js';
|
package/dist/index.js
CHANGED
|
@@ -2183,13 +2183,18 @@ function openWorkspaceCacheKey(opts) {
|
|
|
2183
2183
|
return `${backendTag}:${opts.userId}:${opts.appId}`;
|
|
2184
2184
|
}
|
|
2185
2185
|
async function openWorkspace(opts) {
|
|
2186
|
+
if (opts.create === false) {
|
|
2187
|
+
return openWorkspaceInternal(opts);
|
|
2188
|
+
}
|
|
2186
2189
|
const key = openWorkspaceCacheKey(opts);
|
|
2187
2190
|
if (key !== null) {
|
|
2188
2191
|
const cached = openWorkspaceInFlight.get(key);
|
|
2189
2192
|
if (cached) return cached;
|
|
2190
2193
|
const pending = (async () => {
|
|
2191
2194
|
try {
|
|
2192
|
-
|
|
2195
|
+
const ws = await openWorkspaceInternal(opts);
|
|
2196
|
+
if (ws === null) throw new Error("openWorkspace: null resolution without create:false");
|
|
2197
|
+
return ws;
|
|
2193
2198
|
} catch (err) {
|
|
2194
2199
|
openWorkspaceInFlight.delete(key);
|
|
2195
2200
|
throw err;
|
|
@@ -2204,6 +2209,7 @@ async function openWorkspaceInternal(opts) {
|
|
|
2204
2209
|
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2205
2210
|
const sinks = new SinkManager();
|
|
2206
2211
|
const resolved = await resolveLifecycle(backend, opts);
|
|
2212
|
+
if (resolved === null) return null;
|
|
2207
2213
|
const bare = opts.bare === true && opts.adopt !== void 0;
|
|
2208
2214
|
if (!bare) {
|
|
2209
2215
|
await ensureSkeleton(backend, resolved.workDir);
|
|
@@ -2246,6 +2252,7 @@ async function openWorkspaceInternal(opts) {
|
|
|
2246
2252
|
return service;
|
|
2247
2253
|
}
|
|
2248
2254
|
async function resolveLifecycle(backend, opts) {
|
|
2255
|
+
const noCreate = opts.create === false;
|
|
2249
2256
|
if (opts.adopt) {
|
|
2250
2257
|
const workDir2 = path2.resolve(opts.adopt);
|
|
2251
2258
|
const marker = readAppMarker(backend, workDir2);
|
|
@@ -2263,14 +2270,20 @@ async function resolveLifecycle(backend, opts) {
|
|
|
2263
2270
|
if (opts.appId && opts.restore) {
|
|
2264
2271
|
const workDir2 = mintSessionDir(opts.root, opts.userId);
|
|
2265
2272
|
await backend.mkdir(workDir2, { recursive: true });
|
|
2266
|
-
await restoreWorkspace(backend, workDir2, opts.restore);
|
|
2273
|
+
const result = await restoreWorkspace(backend, workDir2, opts.restore);
|
|
2274
|
+
if (noCreate && result.filesRestored === 0) {
|
|
2275
|
+
await backend.rm(workDir2, { recursive: true });
|
|
2276
|
+
return null;
|
|
2277
|
+
}
|
|
2267
2278
|
return { workDir: workDir2, appId: opts.appId };
|
|
2268
2279
|
}
|
|
2269
2280
|
if (opts.appId && opts.github && opts.github.repoUrl) {
|
|
2281
|
+
if (noCreate) return null;
|
|
2270
2282
|
const workDir2 = mintSessionDir(opts.root, opts.userId);
|
|
2271
2283
|
await backend.mkdir(workDir2, { recursive: true });
|
|
2272
2284
|
return { workDir: workDir2, appId: opts.appId };
|
|
2273
2285
|
}
|
|
2286
|
+
if (noCreate) return null;
|
|
2274
2287
|
const workDir = mintSessionDir(opts.root, opts.userId);
|
|
2275
2288
|
return { workDir, appId: opts.appId };
|
|
2276
2289
|
}
|
|
@@ -2325,6 +2338,7 @@ var ACCOUNT_DIR = ".almadar";
|
|
|
2325
2338
|
var CONFIG_FILE = "config.json";
|
|
2326
2339
|
var CREDENTIALS_FILE = "credentials.json";
|
|
2327
2340
|
var ACCOUNT_FILE = "account.json";
|
|
2341
|
+
var AUTH_FILE = "auth.json";
|
|
2328
2342
|
var SECRET_MODE = 384;
|
|
2329
2343
|
var DEFAULT_CONFIG = {
|
|
2330
2344
|
schemaVersion: 1,
|
|
@@ -2382,6 +2396,18 @@ async function openAccount(opts = {}) {
|
|
|
2382
2396
|
async writeAccount(identity) {
|
|
2383
2397
|
await backend.writeFile(file(ACCOUNT_FILE), JSON.stringify(identity, null, 2));
|
|
2384
2398
|
},
|
|
2399
|
+
async getAuthToken() {
|
|
2400
|
+
return readJson(AUTH_FILE);
|
|
2401
|
+
},
|
|
2402
|
+
async setAuthToken(token) {
|
|
2403
|
+
const p = file(AUTH_FILE);
|
|
2404
|
+
await backend.writeFile(p, JSON.stringify(token, null, 2));
|
|
2405
|
+
await backend.chmod(p, SECRET_MODE);
|
|
2406
|
+
},
|
|
2407
|
+
async clearAuthToken() {
|
|
2408
|
+
const p = file(AUTH_FILE);
|
|
2409
|
+
if (backend.exists(p)) await backend.rm(p);
|
|
2410
|
+
},
|
|
2385
2411
|
async resolveProviderConfig(provider) {
|
|
2386
2412
|
const creds = await readCredentials();
|
|
2387
2413
|
const cred = creds[provider];
|
|
@@ -2397,7 +2423,8 @@ async function openAccount(opts = {}) {
|
|
|
2397
2423
|
async isConfigured() {
|
|
2398
2424
|
const cfg = await getConfig();
|
|
2399
2425
|
if (!cfg.setupCompletedAt) return false;
|
|
2400
|
-
|
|
2426
|
+
if (Object.keys(await readCredentials()).length > 0) return true;
|
|
2427
|
+
return await readJson(AUTH_FILE) !== null;
|
|
2401
2428
|
},
|
|
2402
2429
|
async dispose() {
|
|
2403
2430
|
}
|