@yeaft/webchat-agent 1.0.412 → 1.0.414

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.
Files changed (53) hide show
  1. package/browser-runtime/browser-install.js +497 -0
  2. package/browser-runtime/cli.js +88 -0
  3. package/browser-runtime/config.js +116 -0
  4. package/browser-runtime/errors.js +8 -0
  5. package/browser-runtime/extension/manifest.json +18 -0
  6. package/browser-runtime/extension/offscreen.html +5 -0
  7. package/browser-runtime/extension/offscreen.js +101 -0
  8. package/browser-runtime/extension/popup.html +5 -0
  9. package/browser-runtime/extension/popup.js +1 -0
  10. package/browser-runtime/extension/service-worker.js +48 -0
  11. package/browser-runtime/extension.js +45 -0
  12. package/browser-runtime/index.js +5 -0
  13. package/browser-runtime/probe.js +427 -0
  14. package/browser-runtime/protocol.js +71 -0
  15. package/browser-runtime/service.js +132 -0
  16. package/browser-runtime/windows-version-job.ps1 +233 -0
  17. package/browser-runtime/windows-version-worker.js +75 -0
  18. package/browser-runtime/windows-version.js +85 -0
  19. package/cli.js +24 -7
  20. package/context.js +1 -0
  21. package/index.js +18 -1
  22. package/llm-config-cli.js +24 -21
  23. package/local-runtime/version.json +1 -1
  24. package/local-runtime/web/app.bundle.js +22 -5
  25. package/local-runtime/web/app.bundle.js.gz +0 -0
  26. package/local-runtime/web/index.html +2 -2
  27. package/local-runtime/web/style.bundle.css +1 -1
  28. package/local-runtime/web/style.bundle.css.gz +0 -0
  29. package/package.json +5 -1
  30. package/service/config.js +23 -2
  31. package/service/index.js +1 -0
  32. package/service/linux.js +3 -2
  33. package/yeaft/config-api.js +138 -192
  34. package/yeaft/config-store.js +192 -0
  35. package/yeaft/config.js +3 -0
  36. package/yeaft/init.js +20 -7
  37. package/yeaft/sessions/feature-flag.js +15 -33
  38. package/yeaft/storage/atomic.js +43 -17
  39. package/yeaft/tools/create-work-item.js +1 -1
  40. package/yeaft/tools/process-runner.js +86 -13
  41. package/yeaft/work-center/bridge.js +3 -2
  42. package/yeaft/work-center/completion-contract.js +6 -0
  43. package/yeaft/work-center/controller.js +2 -1
  44. package/yeaft/work-center/coordinator.js +45 -14
  45. package/yeaft/work-center/durable-model.js +45 -1
  46. package/yeaft/work-center/dynamic-coordination.js +34 -0
  47. package/yeaft/work-center/evidence.js +235 -0
  48. package/yeaft/work-center/mainline-projection.js +4 -1
  49. package/yeaft/work-center/projection.js +45 -4
  50. package/yeaft/work-center/runner.js +82 -7
  51. package/yeaft/work-center/service.js +6 -0
  52. package/yeaft/work-center/store.js +162 -19
  53. package/yeaft/work-center/workflow.js +6 -0
package/cli.js CHANGED
@@ -61,6 +61,14 @@ const SERVICE_COMMANDS = ['install', 'uninstall', 'start', 'stop', 'restart', 's
61
61
 
62
62
  if (command === 'doctor') {
63
63
  await handleDoctorCommand(subArgs);
64
+ } else if (command === 'browser') {
65
+ try {
66
+ const { handleBrowserCommand } = await import('./browser-runtime/cli.js');
67
+ await handleBrowserCommand(subArgs);
68
+ } catch (error) {
69
+ console.error(`Browser Runtime command failed: ${error.code || error.message}`);
70
+ process.exitCode = 1;
71
+ }
64
72
  } else if (command === 'llm') {
65
73
  await handleLlmCommand(subArgs);
66
74
  } else if (command === 'local') {
@@ -137,6 +145,10 @@ function printHelp() {
137
145
  yeaft-agent status [options] Show service status
138
146
  yeaft-agent logs [options] View service logs (follow mode)
139
147
  yeaft-agent doctor Diagnose service configuration
148
+ yeaft-agent browser install Install the pinned Chrome for Testing build
149
+ yeaft-agent browser probe Validate tabCapture → offscreen → WebRTC
150
+ yeaft-agent browser enable|disable Change the Browser Runtime feature flag
151
+ yeaft-agent browser status Show config and managed browser install status
140
152
  yeaft-agent llm <command> Configure local Yeaft LLM providers/models
141
153
  yeaft-agent container <command> Manage a Dockerized yeaft-agent
142
154
  yeaft-agent upgrade [--name <id>] Upgrade and restart the selected service
@@ -153,6 +165,11 @@ function printHelp() {
153
165
  --yeaft-dir <dir> Yeaft data directory for this instance
154
166
  --auto-upgrade Check for updates on startup
155
167
 
168
+ Browser options:
169
+ --executable <path> Explicit compatible Chrome for Testing executable
170
+ --headful Run the Browser Runtime probe with a visible browser
171
+ --name <id> Select the named Agent instance
172
+
156
173
  Environment variables (alternative to flags):
157
174
  YEAFT_AGENT_INSTANCE Deprecated local service instance id override
158
175
  SERVER_URL WebSocket server URL
@@ -174,7 +191,7 @@ function printHelp() {
174
191
  `);
175
192
  }
176
193
 
177
- function printLlmHelp() {
194
+ export function printLlmHelp() {
178
195
  console.log(`
179
196
  Configure local Yeaft LLM providers/models in ~/.yeaft/config.json.
180
197
 
@@ -257,7 +274,7 @@ async function handleLlmCommand(args) {
257
274
  const preset = args[1];
258
275
  if (preset === 'github-copilot') {
259
276
  result = await useGitHubCopilot(current, options);
260
- writeLocalLlmConfig(result.config, configPath);
277
+ writeLocalLlmConfig(result.config, configPath, current);
261
278
  console.log(`Configured GitHub Copilot provider with ${result.discovery.models.length} ${result.discovery.source} models.`);
262
279
  if (result.discovery.warning) console.log(`Warning: ${result.discovery.warning}`);
263
280
  console.log(`Primary model: ${result.config.primaryModel}`);
@@ -266,7 +283,7 @@ async function handleLlmCommand(args) {
266
283
  }
267
284
  if (preset === 'openai-compatible') {
268
285
  result = await useOpenAICompatible(current, options, process.env);
269
- writeLocalLlmConfig(result.config, configPath);
286
+ writeLocalLlmConfig(result.config, configPath, current);
270
287
  console.log(`Configured ${result.provider.name} with ${result.discovery.models.length} live models.`);
271
288
  console.log(`Primary model: ${result.config.primaryModel}`);
272
289
  if (result.config.fastModel) console.log(`Fast model: ${result.config.fastModel}`);
@@ -277,7 +294,7 @@ async function handleLlmCommand(args) {
277
294
 
278
295
  if (subcommand === 'add-provider') {
279
296
  result = addOrUpdateProvider(current, options, process.env);
280
- writeLocalLlmConfig(result.config, configPath);
297
+ writeLocalLlmConfig(result.config, configPath, current);
281
298
  console.log(`${result.replaced ? 'Updated' : 'Added'} provider: ${result.provider.name}`);
282
299
  if (result.config.primaryModel) console.log(`Primary model: ${result.config.primaryModel}`);
283
300
  if (result.config.fastModel) console.log(`Fast model: ${result.config.fastModel}`);
@@ -286,7 +303,7 @@ async function handleLlmCommand(args) {
286
303
 
287
304
  if (subcommand === 'set-model') {
288
305
  result = setLocalModels(current, options);
289
- writeLocalLlmConfig(result.config, configPath);
306
+ writeLocalLlmConfig(result.config, configPath, current);
290
307
  if (result.config.primaryModel) console.log(`Primary model: ${result.config.primaryModel}`);
291
308
  if (result.config.fastModel) console.log(`Fast model: ${result.config.fastModel}`);
292
309
  return;
@@ -294,7 +311,7 @@ async function handleLlmCommand(args) {
294
311
 
295
312
  if (subcommand === 'remove-provider') {
296
313
  result = removeProvider(current, options);
297
- writeLocalLlmConfig(result.config, configPath);
314
+ writeLocalLlmConfig(result.config, configPath, current);
298
315
  console.log(result.removed ? `Removed provider: ${options.name}` : `Provider not found: ${options.name}`);
299
316
  if (result.cleared.length) {
300
317
  console.log(`Cleared ${result.cleared.join(', ')} because it referenced ${options.name}`);
@@ -426,7 +443,7 @@ async function runLlmSetup(current, configPath) {
426
443
  const fastAnswer = (await rl.question('Fast model number or id (optional): ')).trim();
427
444
  const fast = fastAnswer ? (ids[Number(fastAnswer) - 1] || fastAnswer) : null;
428
445
  const result = await useGitHubCopilot(current, { model: primary, fast, allowUnknownModel: false });
429
- writeLocalLlmConfig(result.config, configPath);
446
+ writeLocalLlmConfig(result.config, configPath, current);
430
447
  console.log(`Configured GitHub Copilot with ${result.discovery.models.length} ${result.discovery.source} models.`);
431
448
  if (result.discovery.warning) console.log(`Warning: ${result.discovery.warning}`);
432
449
  console.log(`Primary model: ${result.config.primaryModel}`);
package/context.js CHANGED
@@ -20,6 +20,7 @@ export default {
20
20
  CONFIG: null,
21
21
  managedCliReady: Promise.resolve([]),
22
22
  agentCapabilities: [],
23
+ browserRuntime: null,
23
24
  // Agent 级别的 slash commands 缓存(所有 conversation 共用)
24
25
  slashCommands: [],
25
26
  // Slash command 描述映射: { commandName: description } — 从 plugin commands/*.md 提取
package/index.js CHANGED
@@ -23,6 +23,7 @@ import { connect } from './connection.js';
23
23
  import { loadMcpServers } from './mcp.js';
24
24
  import { SAFE_REMOTE_UPGRADE_CAPABILITY } from './upgrade-command.js';
25
25
  import { loadConfig as loadYeaftConfig } from './yeaft/config.js';
26
+ import { bootBrowserRuntime, shutdownBrowserRuntime } from './browser-runtime/index.js';
26
27
  import {
27
28
  ensureManagedCliTools,
28
29
  prepareManagedCliToolEnvironment,
@@ -104,7 +105,7 @@ const { agentName: AGENT_NAME, instanceId: INSTANCE_ID } = resolveRuntimeIdentit
104
105
  const YEAFT_DIR = process.env.YEAFT_DIR || fileConfig.yeaftDir || getDefaultYeaftDir(INSTANCE_ID);
105
106
  try {
106
107
  if (!existsSync(YEAFT_DIR)) {
107
- mkdirSync(YEAFT_DIR, { recursive: true });
108
+ mkdirSync(YEAFT_DIR, { recursive: true, mode: 0o700 });
108
109
  console.log(`[Agent] Created yeaft dir: ${YEAFT_DIR}`);
109
110
  }
110
111
  } catch (err) {
@@ -356,6 +357,7 @@ function cleanup() {
356
357
  const { shutdownWorkCenter } = await import('./yeaft/work-center/bridge.js');
357
358
  await shutdownWorkCenter();
358
359
  } catch {}
360
+ try { await shutdownBrowserRuntime(); } catch {}
359
361
  if (ctx.ws) ctx.ws.close();
360
362
  });
361
363
  }
@@ -396,6 +398,21 @@ process.on('SIGTERM', async () => {
396
398
  } catch (error) {
397
399
  console.warn(`[Startup] managed rg environment setup failed; using built-in fallback: ${error?.message || error}`);
398
400
  }
401
+ try {
402
+ const runtimeConfig = loadYeaftConfig({ dir: YEAFT_DIR }).browserRuntime;
403
+ ctx.browserRuntime = await bootBrowserRuntime({
404
+ yeaftDir: YEAFT_DIR,
405
+ config: runtimeConfig,
406
+ });
407
+ const probe = ctx.browserRuntime.snapshot().probe;
408
+ if (probe?.ok) {
409
+ console.log(`[BrowserRuntime] ready: capture=${probe.captureMode} build=${probe.actualBuildId || probe.expectedBuildId}`);
410
+ } else if (runtimeConfig?.enabled) {
411
+ console.warn(`[BrowserRuntime] unavailable: ${probe?.code || 'probe_failed'}`);
412
+ }
413
+ } catch (err) {
414
+ console.warn(`[BrowserRuntime] startup probe failed: ${err?.message || err}`);
415
+ }
399
416
  ctx.agentCapabilities = await detectCapabilities();
400
417
  // Prime the models.dev community catalog so the Yeaft engine's *synchronous*
401
418
  // hot path (engine.js / config.js / cli.js all read context-window inline)
package/llm-config-cli.js CHANGED
@@ -1,7 +1,8 @@
1
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
2
- import { dirname, join } from 'path';
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import { join } from 'path';
3
3
  import { homedir } from 'os';
4
4
  import { normalizePluginConfig } from './yeaft/plugins.js';
5
+ import { mutateAgentConfigPath } from './yeaft/config-store.js';
5
6
  import {
6
7
  discoverGitHubCopilotModels,
7
8
  discoverOpenAICompatibleModels,
@@ -40,31 +41,33 @@ export function readLocalLlmConfig(configPath = getDefaultYeaftConfigPath()) {
40
41
  return parsed;
41
42
  }
42
43
 
43
- export function writeLocalLlmConfig(config, configPath = getDefaultYeaftConfigPath()) {
44
- // The CLI exposes this writer publicly, so do not rely on callers having
45
- // already used readLocalLlmConfig(). An existing invalid Plugins policy must
46
- // remain on disk and keep runtime fail-closed until the user repairs it.
47
- const existing = existsSync(configPath) ? readLocalLlmConfig(configPath) : null;
44
+ export function writeLocalLlmConfig(config, configPath = getDefaultYeaftConfigPath(), baseConfig = null) {
48
45
  if (!config || typeof config !== 'object' || Array.isArray(config)
49
46
  || Object.getPrototypeOf(config) !== Object.prototype) {
50
47
  throw new Error(`Invalid config file: expected JSON object at ${configPath}`);
51
48
  }
52
- const next = { ...config };
53
- if (next.plugins === undefined
54
- && Object.prototype.hasOwnProperty.call(existing || {}, 'plugins')) {
55
- // LLM commands change provider/model fields. They must not remove a
56
- // separately-managed Plugin allowlist merely because their payload omits it.
57
- next.plugins = existing.plugins;
58
- }
59
- if (next.plugins !== undefined) {
49
+ if (config.plugins !== undefined) {
60
50
  try {
61
- normalizePluginConfig(next.plugins);
62
- } catch (err) {
63
- throw new Error(`Invalid config file: ${err?.message || err}`);
51
+ normalizePluginConfig(config.plugins);
52
+ } catch (error) {
53
+ throw new Error(`Invalid config file: ${error?.message || error}`);
64
54
  }
65
55
  }
66
- mkdirSync(dirname(configPath), { recursive: true });
67
- writeFileSync(configPath, `${JSON.stringify(next, null, 2)}\n`, 'utf8');
56
+
57
+ mutateAgentConfigPath(configPath, current => {
58
+ const baseline = baseConfig && typeof baseConfig === 'object' && !Array.isArray(baseConfig)
59
+ ? baseConfig
60
+ : {};
61
+ const keys = new Set([...Object.keys(baseline), ...Object.keys(config)]);
62
+ for (const key of keys) {
63
+ if (key === 'plugins' && !Object.prototype.hasOwnProperty.call(config, key)) continue;
64
+ const before = baseline[key];
65
+ const after = config[key];
66
+ if (JSON.stringify(before) === JSON.stringify(after)) continue;
67
+ if (Object.prototype.hasOwnProperty.call(config, key)) current[key] = after;
68
+ else delete current[key];
69
+ }
70
+ });
68
71
  }
69
72
 
70
73
  export function parseModelsCsv(value) {
@@ -313,7 +316,7 @@ export async function tryAutoConfigureGitHubCopilot(configPath = getDefaultYeaft
313
316
  ...options,
314
317
  model: options.model || DEFAULT_GITHUB_COPILOT_MODEL,
315
318
  });
316
- writeLocalLlmConfig(result.config, configPath);
319
+ writeLocalLlmConfig(result.config, configPath, current);
317
320
  return { configured: true, reason: 'configured', ...result };
318
321
  } catch (error) {
319
322
  return {
@@ -1 +1 @@
1
- {"version":"1.0.412"}
1
+ {"version":"1.0.414"}