@almadar/workspace 0.2.5 → 0.2.6
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/account.d.ts +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +91 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/backends/local.d.ts +1 -0
- package/dist/internal/backends/memory.d.ts +1 -0
- package/dist/internal/types.d.ts +2 -0
- package/dist/types.d.ts +70 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* `src/internal/`.
|
|
8
8
|
*/
|
|
9
9
|
export { openWorkspace } from './open-workspace.js';
|
|
10
|
-
export
|
|
10
|
+
export { openAccount } from './account.js';
|
|
11
|
+
export type { WorkspaceService, WorkspaceObserver, WorkspaceWriteEvent, OpenWorkspaceOptions, RestoreBackend, GitHubConfig, GitStatusInfo, FileTreeNode, AccountService, AccountConfig, ProviderCredential, AccountIdentity, OpenAccountOptions, } from './types.js';
|
|
11
12
|
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';
|
|
12
13
|
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, } from './workspace-index/types.js';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import fs from 'fs';
|
|
|
3
3
|
import { execFile } from 'child_process';
|
|
4
4
|
import { randomBytes, createHash } from 'crypto';
|
|
5
5
|
import { EmbeddingClient } from '@almadar/llm';
|
|
6
|
+
import os from 'os';
|
|
6
7
|
|
|
7
8
|
// src/open-workspace.ts
|
|
8
9
|
var LocalBackend = class {
|
|
@@ -46,6 +47,9 @@ var LocalBackend = class {
|
|
|
46
47
|
await fs.promises.mkdir(path2.dirname(dstAbs), { recursive: true });
|
|
47
48
|
await fs.promises.rename(srcAbs, dstAbs);
|
|
48
49
|
}
|
|
50
|
+
async chmod(absPath, mode) {
|
|
51
|
+
await fs.promises.chmod(absPath, mode);
|
|
52
|
+
}
|
|
49
53
|
};
|
|
50
54
|
|
|
51
55
|
// src/internal/backends/memory.ts
|
|
@@ -144,6 +148,8 @@ var MemoryBackend = class {
|
|
|
144
148
|
this.dirs.add(newDir);
|
|
145
149
|
}
|
|
146
150
|
}
|
|
151
|
+
async chmod() {
|
|
152
|
+
}
|
|
147
153
|
// Test helpers
|
|
148
154
|
getAll() {
|
|
149
155
|
return new Map(this.files);
|
|
@@ -732,8 +738,8 @@ function tokenizeSpec(spec) {
|
|
|
732
738
|
for (const p of pages) {
|
|
733
739
|
const obj = asJsonObject2(p);
|
|
734
740
|
if (!obj) continue;
|
|
735
|
-
const
|
|
736
|
-
if (typeof
|
|
741
|
+
const path10 = obj["path"];
|
|
742
|
+
if (typeof path10 === "string") pushTokens(tokens, path10);
|
|
737
743
|
}
|
|
738
744
|
}
|
|
739
745
|
const ruleOverlay = asJsonObject2(params["ruleOverlay"]);
|
|
@@ -2225,7 +2231,89 @@ async function resolveLifecycle(backend, opts) {
|
|
|
2225
2231
|
const workDir = mintSessionDir(opts.root, opts.userId);
|
|
2226
2232
|
return { workDir, appId: opts.appId };
|
|
2227
2233
|
}
|
|
2234
|
+
var ACCOUNT_DIR = ".almadar";
|
|
2235
|
+
var CONFIG_FILE = "config.json";
|
|
2236
|
+
var CREDENTIALS_FILE = "credentials.json";
|
|
2237
|
+
var ACCOUNT_FILE = "account.json";
|
|
2238
|
+
var SECRET_MODE = 384;
|
|
2239
|
+
var DEFAULT_CONFIG = {
|
|
2240
|
+
schemaVersion: 1,
|
|
2241
|
+
defaultProvider: "deepseek",
|
|
2242
|
+
defaultModel: "deepseek-v4-flash",
|
|
2243
|
+
autonomy: "balanced",
|
|
2244
|
+
source: "local"
|
|
2245
|
+
};
|
|
2246
|
+
async function openAccount(opts = {}) {
|
|
2247
|
+
const home = opts.home ?? os.homedir();
|
|
2248
|
+
const root = path2.join(home, ACCOUNT_DIR);
|
|
2249
|
+
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2250
|
+
const file = (name) => path2.join(root, name);
|
|
2251
|
+
async function readJson(name) {
|
|
2252
|
+
const p = file(name);
|
|
2253
|
+
if (!backend.exists(p)) return null;
|
|
2254
|
+
const raw = await backend.readFile(p);
|
|
2255
|
+
if (raw.trim().length === 0) return null;
|
|
2256
|
+
return JSON.parse(raw);
|
|
2257
|
+
}
|
|
2258
|
+
async function getConfig() {
|
|
2259
|
+
const stored = await readJson(CONFIG_FILE);
|
|
2260
|
+
return stored ? { ...DEFAULT_CONFIG, ...stored } : { ...DEFAULT_CONFIG };
|
|
2261
|
+
}
|
|
2262
|
+
async function setConfig(patch) {
|
|
2263
|
+
const next = { ...await getConfig(), ...patch };
|
|
2264
|
+
await backend.writeFile(file(CONFIG_FILE), JSON.stringify(next, null, 2));
|
|
2265
|
+
}
|
|
2266
|
+
async function readCredentials() {
|
|
2267
|
+
return await readJson(CREDENTIALS_FILE) ?? {};
|
|
2268
|
+
}
|
|
2269
|
+
async function writeCredentials(creds) {
|
|
2270
|
+
const p = file(CREDENTIALS_FILE);
|
|
2271
|
+
await backend.writeFile(p, JSON.stringify(creds, null, 2));
|
|
2272
|
+
await backend.chmod(p, SECRET_MODE);
|
|
2273
|
+
}
|
|
2274
|
+
return {
|
|
2275
|
+
root,
|
|
2276
|
+
getConfig,
|
|
2277
|
+
setConfig,
|
|
2278
|
+
async getCredential(provider) {
|
|
2279
|
+
return (await readCredentials())[provider] ?? null;
|
|
2280
|
+
},
|
|
2281
|
+
async setCredential(provider, cred) {
|
|
2282
|
+
const creds = await readCredentials();
|
|
2283
|
+
creds[provider] = cred;
|
|
2284
|
+
await writeCredentials(creds);
|
|
2285
|
+
},
|
|
2286
|
+
async listCredentialedProviders() {
|
|
2287
|
+
return Object.keys(await readCredentials());
|
|
2288
|
+
},
|
|
2289
|
+
async readAccount() {
|
|
2290
|
+
return readJson(ACCOUNT_FILE);
|
|
2291
|
+
},
|
|
2292
|
+
async writeAccount(identity) {
|
|
2293
|
+
await backend.writeFile(file(ACCOUNT_FILE), JSON.stringify(identity, null, 2));
|
|
2294
|
+
},
|
|
2295
|
+
async resolveProviderConfig(provider) {
|
|
2296
|
+
const creds = await readCredentials();
|
|
2297
|
+
const cred = creds[provider];
|
|
2298
|
+
if (!cred) return null;
|
|
2299
|
+
const cfg = await getConfig();
|
|
2300
|
+
const override = cfg.providers?.[provider];
|
|
2301
|
+
return {
|
|
2302
|
+
apiKey: cred.apiKey,
|
|
2303
|
+
...override?.baseUrl ? { baseUrl: override.baseUrl } : {},
|
|
2304
|
+
defaultModel: override?.model ?? cfg.defaultModel
|
|
2305
|
+
};
|
|
2306
|
+
},
|
|
2307
|
+
async isConfigured() {
|
|
2308
|
+
const cfg = await getConfig();
|
|
2309
|
+
if (!cfg.setupCompletedAt) return false;
|
|
2310
|
+
return Object.keys(await readCredentials()).length > 0;
|
|
2311
|
+
},
|
|
2312
|
+
async dispose() {
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2228
2316
|
|
|
2229
|
-
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, openWorkspace };
|
|
2317
|
+
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, openAccount, openWorkspace };
|
|
2230
2318
|
//# sourceMappingURL=index.js.map
|
|
2231
2319
|
//# sourceMappingURL=index.js.map
|