@workerdeck/server 2.4.0 → 2.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/build/index.mjs +33 -10
- package/build/index.mjs.map +1 -1
- package/package.json +5 -5
package/build/index.mjs
CHANGED
|
@@ -71,12 +71,23 @@ function engineOf(profile) {
|
|
|
71
71
|
function cliConfigDir(env) {
|
|
72
72
|
return env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
function codexHomeDir(env) {
|
|
75
|
+
return env.CODEX_HOME ?? join(homedir(), ".codex");
|
|
76
|
+
}
|
|
77
|
+
function detectDefaultProfiles(env = process.env) {
|
|
78
|
+
const detected = [];
|
|
79
|
+
const claude = cliConfigDir(env);
|
|
80
|
+
if (existsSync(claude)) detected.push({
|
|
77
81
|
name: "default",
|
|
78
|
-
configDir:
|
|
79
|
-
}
|
|
82
|
+
configDir: claude
|
|
83
|
+
});
|
|
84
|
+
const codex = codexHomeDir(env);
|
|
85
|
+
if (existsSync(codex)) detected.push({
|
|
86
|
+
name: "codex",
|
|
87
|
+
engine: "codex",
|
|
88
|
+
codexHome: codex
|
|
89
|
+
});
|
|
90
|
+
return detected;
|
|
80
91
|
}
|
|
81
92
|
function canonicalDir(path) {
|
|
82
93
|
try {
|
|
@@ -2683,6 +2694,12 @@ var ProfileService = class {
|
|
|
2683
2694
|
this.#stored.clear();
|
|
2684
2695
|
for (const p of await this.#opts.store.list()) this.#stored.set(p.name, p);
|
|
2685
2696
|
}
|
|
2697
|
+
async seedStore() {
|
|
2698
|
+
const seed = this.#opts.seed ?? [];
|
|
2699
|
+
if (!this.#opts.store || seed.length === 0 || this.#stored.size > 0) return;
|
|
2700
|
+
for (const p of seed) if (this.validate(p) === null) await this.#opts.store.save(p);
|
|
2701
|
+
await this.refreshStored();
|
|
2702
|
+
}
|
|
2686
2703
|
withManagedFlag(p) {
|
|
2687
2704
|
return this.#declaredByName.has(p.name) ? p : {
|
|
2688
2705
|
...p,
|
|
@@ -2733,14 +2750,17 @@ var ProfileService = class {
|
|
|
2733
2750
|
}
|
|
2734
2751
|
configDirGuard(profile) {
|
|
2735
2752
|
if (isProviderProfile(profile)) return null;
|
|
2753
|
+
const codex = engineOf(profile) === "codex";
|
|
2754
|
+
const dir = codex ? profile.codexHome : profile.configDir;
|
|
2755
|
+
if (codex && !dir) return null;
|
|
2736
2756
|
const roots = this.#opts.allowedConfigDirRoots;
|
|
2737
2757
|
if (!roots || roots.length === 0) return {
|
|
2738
2758
|
status: 403,
|
|
2739
|
-
error: "managed Claude profiles are disabled: set `allowedConfigDirRoots` to the directories they may point at"
|
|
2759
|
+
error: "managed Claude and Codex profiles are disabled: set `allowedConfigDirRoots` to the directories they may point at"
|
|
2740
2760
|
};
|
|
2741
|
-
return
|
|
2761
|
+
return dir && cwdAllowed(dir, roots) ? null : {
|
|
2742
2762
|
status: 403,
|
|
2743
|
-
error: "configDir is outside the allowed roots
|
|
2763
|
+
error: `${codex ? "codexHome" : "configDir"} is outside the allowed roots`
|
|
2744
2764
|
};
|
|
2745
2765
|
}
|
|
2746
2766
|
async saveManaged(incoming) {
|
|
@@ -3008,7 +3028,7 @@ function createSessionFactory(deps) {
|
|
|
3008
3028
|
status: 400,
|
|
3009
3029
|
error: "no profiles are configured on this server"
|
|
3010
3030
|
} : { ok: true };
|
|
3011
|
-
const effective = name ?? (all.length === 1 ? all[0].name :
|
|
3031
|
+
const effective = name ?? (all.length === 1 ? all[0].name : all.find((p) => p.name === "default")?.name);
|
|
3012
3032
|
if (effective === void 0) return {
|
|
3013
3033
|
ok: false,
|
|
3014
3034
|
status: 400,
|
|
@@ -3090,8 +3110,10 @@ function createWorkerServer(options = {}) {
|
|
|
3090
3110
|
const adapterFor = (engine) => options.engines?.[engine ?? "claude"] ?? getEngineAdapter(engine);
|
|
3091
3111
|
const profileDefaultModels = /* @__PURE__ */ new Map();
|
|
3092
3112
|
const profileUsage = new ProfileUsageTracker();
|
|
3113
|
+
const detected = options.profiles ? [] : detectDefaultProfiles();
|
|
3093
3114
|
const profiles = new ProfileService({
|
|
3094
|
-
declared: options.profiles ??
|
|
3115
|
+
declared: options.profiles ?? (options.profileStore ? [] : detected),
|
|
3116
|
+
seed: detected,
|
|
3095
3117
|
store: options.profileStore,
|
|
3096
3118
|
allowedConfigDirRoots: options.allowedConfigDirRoots,
|
|
3097
3119
|
disableBypassPermissions: options.disableBypassPermissions,
|
|
@@ -3412,6 +3434,7 @@ function createWorkerServer(options = {}) {
|
|
|
3412
3434
|
parking,
|
|
3413
3435
|
listen: async (port, host) => {
|
|
3414
3436
|
await profiles.refreshStored();
|
|
3437
|
+
await profiles.seedStore();
|
|
3415
3438
|
await parking.hydrate();
|
|
3416
3439
|
return new Promise((resolve, reject) => {
|
|
3417
3440
|
server.once("error", reject);
|