ai_co_discuss 0.4.37 → 0.4.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai_co_discuss",
3
- "version": "0.4.37",
3
+ "version": "0.4.38",
4
4
  "bin": {
5
5
  "codiscuss": "runner/codiscuss.mjs"
6
6
  },
@@ -25,6 +25,7 @@ import { apply_login, cancel_login, LOGIN_METHODS, login_progress, login_status,
25
25
  import { create_os_user, install_shared_runtime, instance_key_file, place_instance_key, read_os_users, remove_os_user, run_as_user, shared_cli_state, shared_executables, shared_paths,
26
26
  start_instance_as_user } from './os_users.mjs';
27
27
  import { install_workflows, shipped_workflows } from './discussion_skills.mjs';
28
+ import { list_workflows, workflows_home } from './workflows.mjs';
28
29
  import { hosted_prompt, import_skill, library_root, list_library, remove_library_skill, save_hosted_prompt } from './skill_library.mjs';
29
30
  import { local_status } from './discussion_local.mjs';
30
31
  import { autostart_enabled, launcher_path, set_autostart } from './launcher.mjs';
@@ -413,6 +414,16 @@ export function save_owner_prompt(key, text, original, home = homedir()) {
413
414
  return owner_prompts(home);
414
415
  }
415
416
 
417
+ /**
418
+ * The workflows in a service home's library, and the shipped workflows it lacks:
419
+ * { workflows: [{ id, label, description, cards, disabled?, error? }], missing: [id] }.
420
+ */
421
+ export function account_workflows(home) {
422
+ const workflows = existsSync(workflows_home(home)) ? list_workflows(home).map(({ directory: _directory, unavailable: _unavailable, ...item }) => item) : [];
423
+ const installed = new Set(workflows.map(item => item.id));
424
+ return { workflows, missing: shipped_workflows().map(item => item.name).filter(name => !installed.has(name)) };
425
+ }
426
+
416
427
  function owner_skills(data, { install = [], remove = [] } = {}) {
417
428
  return owner_env('skills', { remove }, library_folders(data, install));
418
429
  }
@@ -539,7 +550,7 @@ function cookie(request, name) {
539
550
  */
540
551
  export function create_panel({ data, key, port, ops = {}, sessions = new Set() }) {
541
552
  const op = { list_accounts, add_account, reset_password, set_account_disabled, remove_account, run_instance, create_os_user, remove_os_user,
542
- login_status, apply_login, logout, start_login, login_progress, submit_login, cancel_login, install_runtime, prepare_account, account_env, account_skills, owner_env, owner_skills, owner_prompts, save_owner_prompt, shared_cli_state,
553
+ login_status, apply_login, logout, start_login, login_progress, submit_login, cancel_login, install_runtime, prepare_account, account_env, account_skills, account_workflows, owner_env, owner_skills, owner_prompts, save_owner_prompt, shared_cli_state,
543
554
  save_api_key, list_keys, remove_key, use_shared_programs, service_overview, run_owner_service, latest_version, begin_update,
544
555
  autostart_enabled, set_autostart, entry_overview, start_entry, stop_entry, protect_account, start_verified, hand_over: () => {}, ...ops };
545
556
  const hosts = new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
@@ -590,6 +601,9 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
590
601
  if (method === 'POST' && name === 'env' && action === 'skills') return op.owner_skills(data, { install: body.install || [], remove: body.remove || [] });
591
602
  if (method === 'GET' && name === 'prompts') return op.owner_prompts();
592
603
  if (method === 'POST' && name === 'prompts') return op.save_owner_prompt(String(body.key || ''), body.text, body.original);
604
+ if (method === 'GET' && name === 'workflows') return op.account_workflows(data);
605
+ // Only the shipped workflows the owner's library lacks: an existing one, edited or not, is kept.
606
+ if (method === 'POST' && name === 'workflows' && action === 'install') { install_workflows(data, op.account_workflows(data).missing); return op.account_workflows(data); }
593
607
  if (method === 'GET' && name === 'keys') return op.list_keys(data);
594
608
  if (method === 'POST' && name === 'keys' && action === 'remove') { op.remove_key(data, String(body.ref || '')); return { ok: true }; }
595
609
  if (method === 'POST' && name === 'keys') return op.save_api_key(data, { base_url: body.base_url, api_key: body.api_key });
@@ -638,6 +652,9 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
638
652
  if (method === 'POST' && action === 'env' && extra === 'skills') return op.account_skills(data, name, { install: body.install || [], remove: body.remove || [] });
639
653
  if (method === 'POST' && action === 'env' && extra === 'prompt') return op.account_env(data, name, 'prompt', { prompt: String(body.text ?? '') });
640
654
  const service = instance_home(data, name);
655
+ if (method === 'GET' && action === 'workflows') return op.account_workflows(service);
656
+ // Set up again (safe to repeat): it installs the shipped workflows the account lacks and keeps the rest.
657
+ if (method === 'POST' && action === 'workflows' && extra === 'install') { await op.prepare_account(data, name); return op.account_workflows(service); }
641
658
  if (method === 'GET' && action === 'keys') return op.list_keys(service);
642
659
  if (method === 'POST' && action === 'keys' && extra === 'remove') { op.remove_key(service, String(body.ref || '')); return { ok: true }; }
643
660
  if (method === 'POST' && action === 'keys') return op.save_api_key(service, { base_url: body.base_url, api_key: body.api_key, managed: true });