@botlearn-course/daemon 0.0.28-beta.3 → 0.0.28-beta.4

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/README.md CHANGED
@@ -155,3 +155,17 @@ major、minor 或 prerelease 时才填写精确 SemVer(例如 `1.0.0` 或 `1.1
155
155
 
156
156
  所有正式版发布到 npm dist-tag `latest`,prerelease 发布到 `next`。CI 会串行化发布并在
157
157
  上传前确认目标版本尚不存在,避免并发任务重复发布同一个版本。
158
+
159
+ ## 托管 Codewhale 代理凭据
160
+
161
+ 托管 `deepseek-tui` 每轮从 activation 的 `DEEPSEEK_BASE_URL` 生成临时
162
+ `[providers.deepseek]` 路由,并用 `api_key_env = "DEEPSEEK_API_KEY"` 显式绑定当轮凭据。
163
+ 子进程不再接收 URL 环境覆盖,避免 Codewhale 0.9.12 将其判定为未绑定的新路由。
164
+ 未启用视觉模型时同样生成该配置;配置随本轮进程清理,凭据不会写入供应商路由或命令行。
165
+ 托管进程固定关闭 Codewhale 自带遥测,BotLearn 原有执行事实记录继续使用既有通道。
166
+ 这些规则由适配器代码拥有,更新 daemon 后生效,无需新增部署配置或数据库迁移。
167
+
168
+ 镜像内的真实二进制回归入口是 `scripts/smoke-codewhale-managed.mjs`:构建 daemon 后,
169
+ 以 `0:2000` 运行并挂载整个包目录,添加 `--network none` 和
170
+ `--add-host model-proxy.test:127.0.0.1`。验证非 localhost 代理、凭据轮换、UID 1001
171
+ 文件写入、会话恢复和第二轮系统提示词更新;模型使用本地确定性替身。
@@ -88,48 +88,61 @@ function courseSkillsSystemContext(systemContext, catalog) {
88
88
  const context = systemContext?.trim();
89
89
  return context ? `${context}\n\n${instruction}` : instruction;
90
90
  }
91
- function createManagedVisionConfig(opts, progressMcpConfig) {
91
+ function createManagedRuntimeConfig(opts, progressMcpConfig) {
92
92
  const model = opts.env?.BOTLEARN_DEEPSEEK_VISION_MODEL?.trim();
93
- if (!model)
93
+ const managedProxy = Boolean(opts.env?.BOTLEARN_AGENT_SERVICE_ACTIVATION_ID?.trim()
94
+ && opts.env?.DEEPSEEK_BASE_URL?.trim());
95
+ if (!model && !managedProxy)
94
96
  return undefined;
95
- if (!VISION_MODEL_PATTERN.test(model)) {
97
+ if (model && !VISION_MODEL_PATTERN.test(model)) {
96
98
  throw new Error("invalid managed DeepSeek vision model");
97
99
  }
98
100
  if (!progressMcpConfig) {
99
- throw new Error("managed DeepSeek vision config requires an ephemeral config directory");
101
+ throw new Error("managed DeepSeek runtime config requires an ephemeral config directory");
100
102
  }
101
103
  const apiKey = opts.env?.DEEPSEEK_API_KEY?.trim();
102
104
  const rawBaseUrl = opts.env?.DEEPSEEK_BASE_URL?.trim();
103
105
  if (!apiKey || !rawBaseUrl) {
104
- throw new Error("managed DeepSeek vision config requires model proxy credentials");
106
+ throw new Error("managed DeepSeek runtime config requires model proxy credentials");
105
107
  }
106
108
  let baseUrl;
107
109
  try {
108
110
  baseUrl = new URL(rawBaseUrl);
109
111
  }
110
112
  catch {
111
- throw new Error("invalid managed DeepSeek vision base URL");
113
+ throw new Error("invalid managed DeepSeek runtime base URL");
112
114
  }
113
115
  if (!["http:", "https:"].includes(baseUrl.protocol)
114
116
  || baseUrl.username
115
117
  || baseUrl.password
116
118
  || baseUrl.search
117
119
  || baseUrl.hash) {
118
- throw new Error("invalid managed DeepSeek vision base URL");
120
+ throw new Error("invalid managed DeepSeek runtime base URL");
119
121
  }
122
+ const providerConfig = managedProxy
123
+ ? [
124
+ "[providers.deepseek]",
125
+ `base_url = ${JSON.stringify(rawBaseUrl)}`,
126
+ 'api_key_env = "DEEPSEEK_API_KEY"',
127
+ "",
128
+ ]
129
+ : [];
120
130
  baseUrl.pathname = `${baseUrl.pathname.replace(/\/+$/, "")}/v1`;
121
131
  const configPath = path.join(progressMcpConfig.dir, "config.toml");
122
132
  const managedRuntime = Boolean(process.env.BOTLEARN_RUNTIME_USER?.trim()
123
133
  || process.env.BOTLEARN_RUNTIME_LAUNCH_MODE?.trim());
124
134
  writeFileSync(configPath, [
125
- "[features]",
126
- "vision_model = true",
127
- "",
128
- "[vision_model]",
129
- `model = ${JSON.stringify(model)}`,
130
- `api_key = ${JSON.stringify(apiKey)}`,
131
- `base_url = ${JSON.stringify(baseUrl.toString())}`,
132
- "",
135
+ ...providerConfig,
136
+ ...(model ? [
137
+ "[features]",
138
+ "vision_model = true",
139
+ "",
140
+ "[vision_model]",
141
+ `model = ${JSON.stringify(model)}`,
142
+ `api_key = ${JSON.stringify(apiKey)}`,
143
+ `base_url = ${JSON.stringify(baseUrl.toString())}`,
144
+ "",
145
+ ] : []),
133
146
  ].join("\n"), { mode: managedRuntime ? 0o640 : 0o600 });
134
147
  if (managedRuntime)
135
148
  chmodSync(configPath, 0o640);
@@ -474,7 +487,7 @@ export class DeepseekTuiAdapter {
474
487
  const baseUrl = `http://127.0.0.1:${port}`;
475
488
  let courseSkillsMcpServer;
476
489
  let progressMcpConfig;
477
- let visionConfigPath;
490
+ let runtimeConfigPath;
478
491
  try {
479
492
  courseSkillsMcpServer = opts.skillProvider
480
493
  ? await startCourseSkillsMcpServer({
@@ -484,6 +497,7 @@ export class DeepseekTuiAdapter {
484
497
  : undefined;
485
498
  progressMcpConfig =
486
499
  this.progressPromptInjectionEnabled || courseSkillsMcpServer
500
+ || (managedActivationId && opts.env?.DEEPSEEK_BASE_URL?.trim())
487
501
  ? createProgressMcpConfig({
488
502
  ...(courseSkillsMcpServer
489
503
  ? { courseSkillsSocketPath: courseSkillsMcpServer.socketPath }
@@ -493,7 +507,7 @@ export class DeepseekTuiAdapter {
493
507
  if (opts.skillProvider && progressMcpConfig) {
494
508
  prepareRuntimeSkillsHome(progressMcpConfig.dir, Boolean(this.managedActivationId(opts)));
495
509
  }
496
- visionConfigPath = createManagedVisionConfig(opts, progressMcpConfig);
510
+ runtimeConfigPath = createManagedRuntimeConfig(opts, progressMcpConfig);
497
511
  }
498
512
  catch (error) {
499
513
  cleanupDeepseekResources({ progressMcpConfig, courseSkillsMcpServer });
@@ -515,7 +529,7 @@ export class DeepseekTuiAdapter {
515
529
  try {
516
530
  child = this.spawnFn(launch.binary, launch.args, {
517
531
  cwd: opts.cwd,
518
- env: this.spawnEnv(opts, progressMcpConfig?.path, visionConfigPath, progressMcpConfig && opts.skillProvider
532
+ env: this.spawnEnv(opts, progressMcpConfig?.path, runtimeConfigPath, progressMcpConfig && opts.skillProvider
519
533
  ? path.join(progressMcpConfig.dir, RUNTIME_SKILLS_RELATIVE_PATH)
520
534
  : undefined),
521
535
  ...launch.identity,
@@ -575,7 +589,7 @@ export class DeepseekTuiAdapter {
575
589
  * pins the durable RuntimeThreadStore to the RuntimeSession workspace even though
576
590
  * the credential-bearing server process is still reclaimed after every activation.
577
591
  */
578
- spawnEnv(opts, progressMcpConfigPath, visionConfigPath, skillsDir) {
592
+ spawnEnv(opts, progressMcpConfigPath, runtimeConfigPath, skillsDir) {
579
593
  const env = {
580
594
  ...runtimeChildEnv(opts.env ?? process.env),
581
595
  FORCE_COLOR: "0",
@@ -588,10 +602,17 @@ export class DeepseekTuiAdapter {
588
602
  // DEEPSEEK_SKILLS_DIR。profile 同时隔离 Course Skill,避免写入学员工作区。
589
603
  env.HOME = path.dirname(path.dirname(skillsDir));
590
604
  }
591
- if (visionConfigPath)
592
- env.DEEPSEEK_CONFIG_PATH = visionConfigPath;
605
+ if (runtimeConfigPath)
606
+ env.DEEPSEEK_CONFIG_PATH = runtimeConfigPath;
593
607
  if (this.managedActivationId(opts)) {
594
608
  env.DEEPSEEK_RUNTIME_DIR = this.prepareManagedRuntimeDir(opts);
609
+ env.CODEWHALE_TELEMETRY = "false";
610
+ if (runtimeConfigPath) {
611
+ // Codewhale treats an environment URL as a new route, even when it
612
+ // equals the file URL, and refuses that route's bound credentials.
613
+ delete env.DEEPSEEK_BASE_URL;
614
+ delete env.CODEWHALE_BASE_URL;
615
+ }
595
616
  }
596
617
  return env;
597
618
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botlearn-course/daemon",
3
- "version": "0.0.28-beta.3",
3
+ "version": "0.0.28-beta.4",
4
4
  "description": "Lightweight BotLearn Course daemon: run course tasks on your own machine with your own agent runtime (BYOA).",
5
5
  "type": "module",
6
6
  "bin": {