@yusho/server 0.0.0-stage → 0.1.16

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 (115) hide show
  1. package/README.md +135 -2
  2. package/app/appguide.mjs +33 -0
  3. package/app/asr.mjs +82 -0
  4. package/app/assets/agents/claude-192.webp +0 -0
  5. package/app/assets/agents/claude-96.webp +0 -0
  6. package/app/assets/agents/codex-192.webp +0 -0
  7. package/app/assets/agents/codex-96.webp +0 -0
  8. package/app/assets/agents/default-192.webp +0 -0
  9. package/app/assets/agents/default-96.webp +0 -0
  10. package/app/assets/agents/dsh-192.webp +0 -0
  11. package/app/assets/agents/dsh-96.webp +0 -0
  12. package/app/assets/brand/logo.webp +0 -0
  13. package/app/assets/lib/THIRD-PARTY.txt +1 -0
  14. package/app/assets/lib/jsqr.js +10102 -0
  15. package/app/assets/linux/alpine-arm64.tar.gz +0 -0
  16. package/app/assets/linux/alpine-x64.tar.gz +0 -0
  17. package/app/assets/live/claude.livliv +0 -0
  18. package/app/assets/live/dafeiyu.livliv +0 -0
  19. package/app/assets/live/gpt.livliv +0 -0
  20. package/app/assets/live/sho.livliv +0 -0
  21. package/app/assets/live//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
  22. package/app/assets/livliv/LICENSE +202 -0
  23. package/app/assets/livliv/NOTICE +7 -0
  24. package/app/assets/livliv/player.mjs +15 -0
  25. package/app/assets/looks/claude.webp +0 -0
  26. package/app/assets/looks/dafeiyu.webp +0 -0
  27. package/app/assets/looks/gpt.webp +0 -0
  28. package/app/assets/looks//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
  29. package/app/assets/sho/avatar.webp +0 -0
  30. package/app/assets/sho/done.webp +0 -0
  31. package/app/assets/sho/eat.webp +0 -0
  32. package/app/assets/sho/idle-blink.webp +0 -0
  33. package/app/assets/sho/idle.webp +0 -0
  34. package/app/assets/sho/listen.webp +0 -0
  35. package/app/assets/sho/need.webp +0 -0
  36. package/app/assets/sho/work.webp +0 -0
  37. package/app/companion.mjs +519 -0
  38. package/app/diag.mjs +51 -0
  39. package/app/index.html +497 -0
  40. package/app/judge.mjs +103 -0
  41. package/app/lanxfer.mjs +157 -0
  42. package/app/launcher.mjs +2711 -0
  43. package/app/linux.mjs +97 -0
  44. package/app/livliv-pack.mjs +12 -0
  45. package/app/memory.mjs +53 -0
  46. package/app/net.mjs +717 -0
  47. package/app/office.mjs +172 -0
  48. package/app/p2plink.mjs +134 -0
  49. package/app/pcupdate.mjs +55 -0
  50. package/app/plans.mjs +126 -0
  51. package/app/plugins.mjs +79 -0
  52. package/app/realtime.mjs +67 -0
  53. package/app/skills/app-icon/SKILL.md +31 -0
  54. package/app/skills/daily-brief/SKILL.md +29 -0
  55. package/app/skills/expense-review/SKILL.md +28 -0
  56. package/app/skills/make-app/SKILL.md +92 -0
  57. package/app/skills/make-skin/SKILL.md +51 -0
  58. package/app/skills/meeting-notes/SKILL.md +23 -0
  59. package/app/skills/reading-notes/SKILL.md +25 -0
  60. package/app/skills/sho-stickers/SKILL.md +34 -0
  61. package/app/skills/sho-stickers/stickers/eat.webp +0 -0
  62. package/app/skills/sho-stickers/stickers/got-it.webp +0 -0
  63. package/app/skills/sho-stickers/stickers/hi.webp +0 -0
  64. package/app/skills/sho-stickers/stickers/huh.webp +0 -0
  65. package/app/skills/sho-stickers/stickers/on-it.webp +0 -0
  66. package/app/skills/sho-stickers/stickers/yay.webp +0 -0
  67. package/app/skills/sho-stickers/stickers.json +12 -0
  68. package/app/skills/study-plan/SKILL.md +30 -0
  69. package/app/skills/trip-planner/SKILL.md +29 -0
  70. package/app/skills/weekly-report/SKILL.md +30 -0
  71. package/app/skills/workout-plan/SKILL.md +30 -0
  72. package/app/skills/writing-polish/SKILL.md +33 -0
  73. package/app/skills.mjs +173 -0
  74. package/app/skins.mjs +40 -0
  75. package/app/social.mjs +1067 -0
  76. package/app/storage.mjs +143 -0
  77. package/app/tts.mjs +68 -0
  78. package/app/ttslocal.mjs +77 -0
  79. package/app/voices.mjs +102 -0
  80. package/backup.mjs +109 -0
  81. package/bin/yusho.mjs +141 -0
  82. package/connector/lib/api.mjs +14 -0
  83. package/connector/lib/autostart.mjs +40 -0
  84. package/connector/lib/client.js +165 -0
  85. package/connector/lib/connector.mjs +468 -0
  86. package/connector/lib/dsh-acp.mjs +129 -0
  87. package/connector/lib/dsh-headless.patch.yml +4 -0
  88. package/connector/lib/dsh-plugin.mjs +80 -0
  89. package/connector/lib/lanfile.mjs +151 -0
  90. package/connector/lib/nostr.mjs +53 -0
  91. package/connector/lib/page.html +121 -0
  92. package/connector/lib/qr.mjs +4 -0
  93. package/connector/lib/service.mjs +54 -0
  94. package/node_modules/@local/shoal-mobile/lib/index.js +485 -0
  95. package/node_modules/@local/shoal-mobile/lib/polyfill.js +82 -0
  96. package/node_modules/@local/shoal-mobile/lib/session-context.js +34 -0
  97. package/node_modules/@local/shoal-mobile/lib/shell.js +60 -0
  98. package/node_modules/@local/shoal-mobile/lib/web-startup.js +33 -0
  99. package/node_modules/@local/shoal-mobile/package.json +24 -0
  100. package/node_modules/@local/yusho-pc/lib/client.js +9100 -0
  101. package/node_modules/@local/yusho-pc/lib/index.js +3 -0
  102. package/node_modules/@local/yusho-pc/package.json +28 -0
  103. package/node_modules/@local/yusho-web-login/brand/icon-192.webp +0 -0
  104. package/node_modules/@local/yusho-web-login/brand/logo-dark.svg +25 -0
  105. package/node_modules/@local/yusho-web-login/brand.mjs +8 -0
  106. package/node_modules/@local/yusho-web-login/dsh-web-login.mjs +974 -0
  107. package/node_modules/@local/yusho-web-login/lib/client.js +607 -0
  108. package/node_modules/@local/yusho-web-login/login-page.mjs +609 -0
  109. package/node_modules/@local/yusho-web-login/login-store.mjs +708 -0
  110. package/node_modules/@local/yusho-web-login/package.json +25 -0
  111. package/node_modules/@local/yusho-web-login/whale-scene.mjs +509 -0
  112. package/node_modules/@local/yusho-web-login/yusho-scene.mjs +227 -0
  113. package/package.json +38 -4
  114. package/pc.patch.yml +83 -0
  115. package/run.mjs +136 -0
package/app/linux.mjs ADDED
@@ -0,0 +1,97 @@
1
+ // 内置 Linux:proot + Alpine。手机上不能直接执行下载来的程序(安卓 10 起只许执行 App 自带的库文件),
2
+ // 所以 proot 当作 libproot.so 装在 App 的库目录里;Alpine 里的程序都由 proot 的加载器去跑,不受这个限制。
3
+ //
4
+ // 第一次用时:解开随 App 带的 Alpine 基础系统(约 4 MB),再从国内镜像装 bash、git、node、python(约 40 MB)。
5
+ // App 的工作目录按原路径挂进 Linux,所以助理的文件工具和命令行看到的是同一批文件。
6
+ import fs from 'node:fs'
7
+ import path from 'node:path'
8
+ import { spawn } from 'node:child_process'
9
+
10
+ const MIRRORS = ['https://mirrors.tuna.tsinghua.edu.cn/alpine', 'https://mirrors.aliyun.com/alpine', 'https://mirrors.ustc.edu.cn/alpine', 'https://dl-cdn.alpinelinux.org/alpine']
11
+ const BRANCH = 'v3.22'
12
+ export const BASE_PKGS = ['bash', 'coreutils', 'git', 'nodejs', 'npm', 'python3', 'py3-pip', 'curl', 'tar', 'xz', 'zip', 'unzip', 'jq', 'ca-certificates']
13
+ const PATH_IN = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
14
+
15
+ export function createLinux({ appDir, workspace, kernelDir, log = () => {} }) {
16
+ const LX = path.join(appDir, 'linux'), ROOT = path.join(LX, 'rootfs'), TMP = path.join(LX, 'tmp'), STATE = path.join(LX, 'state.json')
17
+ const native = process.env.SHOAL_NATIVE_DIR || ''
18
+ const proot = path.join(native, 'libproot.so'), loader = path.join(native, 'libprootloader.so')
19
+ const arch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null
20
+ const supported = () => process.platform !== 'win32' && !!native && !!arch && fs.existsSync(proot)
21
+ const readState = () => { try { return JSON.parse(fs.readFileSync(STATE, 'utf8')) } catch { return {} } }
22
+ const writeState = (s) => { fs.mkdirSync(LX, { recursive: true }); fs.writeFileSync(STATE, JSON.stringify({ ...readState(), ...s })) }
23
+ let phase = null, lastErr = null, logTail = [], busy = null
24
+ const note = (line) => { logTail.push(String(line).slice(0, 300)); if (logTail.length > 40) logTail = logTail.slice(-40) }
25
+
26
+ /** 在 Linux 里跑一条命令。返回子进程(调用方自己收输出、管超时) */
27
+ function spawnIn(command, { cwd = workspace, env = {}, shell = '/bin/bash', binds = [] } = {}) {
28
+ const inner = fs.existsSync(path.join(ROOT, shell.slice(1))) ? shell : '/bin/sh'
29
+ const roots = [workspace, ...binds], wd = cwd && roots.some((r) => cwd === r || cwd.startsWith(r + path.sep)) ? cwd : workspace
30
+ fs.mkdirSync(TMP, { recursive: true })
31
+ const args = ['-0', '--link2symlink', '--kill-on-exit', '-r', ROOT, '-b', '/dev', '-b', '/proc', '-b', '/sys', '-b', '/dev/urandom:/dev/random', '-b', workspace, ...binds.flatMap((d) => ['-b', d]), '-b', TMP + ':/tmp', '-w', wd, inner, '-c', 'unset LD_LIBRARY_PATH PROOT_LOADER PROOT_LOADER_32 PROOT_TMP_DIR; ' + command]
32
+ // proot 是 Termux 编的:要从 App 的库目录找 libtalloc.so;进了 Linux 以后把这些变量清掉,免得 Alpine 的程序去加载安卓的库
33
+ return spawn(proot, args, { cwd: LX, env: { PATH: PATH_IN, HOME: '/root', LANG: 'C.UTF-8', TERM: 'dumb', LD_LIBRARY_PATH: native, PROOT_LOADER: loader, PROOT_LOADER_32: path.join(native, 'libprootloader32.so'), PROOT_TMP_DIR: TMP, ...env }, stdio: ['pipe', 'pipe', 'pipe'] })
34
+ }
35
+ /** 跑完一条命令,拿到全部输出(安装、状态检查用) */
36
+ function exec(command, opts = {}) {
37
+ return new Promise((ok) => {
38
+ let out = '', p
39
+ try { p = spawnIn(command, opts) } catch (e) { return ok({ code: -1, out: String(e?.message ?? e) }) }
40
+ const t = setTimeout(() => p.kill('SIGKILL'), opts.timeoutMs ?? 600_000)
41
+ p.stdout.on('data', (d) => { out += d; if (opts.onLine) String(d).split('\n').filter(Boolean).forEach(opts.onLine) })
42
+ p.stderr.on('data', (d) => { out += d; if (opts.onLine) String(d).split('\n').filter(Boolean).forEach(opts.onLine) })
43
+ p.stdin.end()
44
+ p.on('error', (e) => { clearTimeout(t); ok({ code: -1, out: out + String(e?.message ?? e) }) })
45
+ p.on('close', (code) => { clearTimeout(t); ok({ code, out }) })
46
+ })
47
+ }
48
+ const run0 = (cmd, args) => new Promise((ok, no) => { const p = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] }); let e = ''; p.stderr.on('data', (d) => (e += d)); p.on('error', no); p.on('close', (c) => (c === 0 ? ok() : no(new Error(cmd + ' 退出码 ' + c + ':' + e.slice(-300))))) })
49
+
50
+ async function extractBase() {
51
+ phase = 'extracting'; note('解开 Alpine 基础系统…')
52
+ const tgz = path.join(kernelDir, 'assets', 'linux', 'alpine-' + arch + '.tar.gz')
53
+ if (!fs.existsSync(tgz)) throw new Error('安装包里没有这个手机能用的 Linux 系统(' + arch + ')')
54
+ fs.rmSync(ROOT, { recursive: true, force: true }); fs.mkdirSync(ROOT, { recursive: true })
55
+ await run0(fs.existsSync('/system/bin/tar') ? '/system/bin/tar' : 'tar', ['-xzf', tgz, '-C', ROOT])
56
+ fs.writeFileSync(path.join(ROOT, 'etc/resolv.conf'), 'nameserver 223.5.5.5\nnameserver 119.29.29.29\nnameserver 8.8.8.8\n')
57
+ fs.writeFileSync(path.join(ROOT, 'etc/profile.d/yusho.sh'), 'export PS1="\\w $ "\nexport PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple\nexport npm_config_registry=https://registry.npmmirror.com\n')
58
+ writeState({ base: Date.now() })
59
+ }
60
+ async function installPkgs(pkgs) {
61
+ phase = 'installing'
62
+ for (const m of MIRRORS) {
63
+ fs.writeFileSync(path.join(ROOT, 'etc/apk/repositories'), m + '/' + BRANCH + '/main\n' + m + '/' + BRANCH + '/community\n')
64
+ note('从 ' + m.replace(/^https:\/\//, '').split('/')[0] + ' 装:' + pkgs.join(' '))
65
+ const r = await exec('apk update -q && apk add --no-progress ' + pkgs.join(' '), { shell: '/bin/sh', onLine: note })
66
+ if (r.code === 0) { writeState({ pkgs: [...new Set([...(readState().pkgs ?? []), ...pkgs])], mirror: m }); return }
67
+ note('这个镜像没装成,换下一个')
68
+ }
69
+ throw new Error('几个镜像都没装成,看看网络')
70
+ }
71
+ const ready = () => fs.existsSync(path.join(ROOT, 'bin/bash')) && !!readState().pkgs?.includes('bash')
72
+ /** 准备好 Linux(没装就装)。同一时间只装一次,别的调用等着 */
73
+ function ensure() {
74
+ if (!supported()) return Promise.reject(new Error('这台设备上用不了内置 Linux'))
75
+ if (ready()) return Promise.resolve()
76
+ if (busy) return busy
77
+ lastErr = null
78
+ busy = (async () => {
79
+ try { if (!fs.existsSync(path.join(ROOT, 'etc/alpine-release'))) await extractBase(); await installPkgs(BASE_PKGS); phase = null; note('装好了') }
80
+ catch (e) { lastErr = e.message; phase = null; note('没装成:' + e.message); throw e }
81
+ finally { busy = null }
82
+ })()
83
+ return busy
84
+ }
85
+ /** 只要基础系统(解压用的 tar 之类):不装软件包、不用联网 */
86
+ async function ensureBase() {
87
+ if (!supported()) throw new Error('这台设备上用不了内置 Linux')
88
+ if (fs.existsSync(path.join(ROOT, 'etc/alpine-release'))) return
89
+ if (busy) { await busy.catch(() => {}); if (fs.existsSync(path.join(ROOT, 'etc/alpine-release'))) return }
90
+ try { await extractBase() } finally { phase = null }
91
+ }
92
+ function dirSize(d) { let n = 0; const walk = (p) => { let st; try { st = fs.lstatSync(p) } catch { return } if (st.isDirectory()) { for (const f of fs.readdirSync(p)) walk(path.join(p, f)) } else n += st.size }; walk(d); return n }
93
+ const status = () => ({ supported: supported(), ready: ready(), phase, error: lastErr, pkgs: readState().pkgs ?? [], mirror: readState().mirror ?? null, log: logTail.slice(-12), arch })
94
+ async function add(pkgs) { const list = pkgs.filter((p) => /^[a-z0-9][a-z0-9.+_-]{0,60}$/.test(p)); if (!list.length) throw new Error('包名不对'); await ensure(); await installPkgs(list); phase = null }
95
+ function reset() { if (busy) throw new Error('正在装,等装完再重置'); fs.rmSync(LX, { recursive: true, force: true }); logTail = []; lastErr = null }
96
+ return { supported, ready, ensure, ensureBase, status, spawnIn, exec, add, reset, size: () => (fs.existsSync(ROOT) ? dirSize(ROOT) : 0), root: ROOT }
97
+ }
@@ -0,0 +1,12 @@
1
+ // 把 LivLiv 官方播放器(Apache-2.0,原样,不改代码)打成一个文件放进 App:assets/livliv/player.mjs
2
+ // 用法:node livliv-pack.mjs [播放器 dist 目录];许可文件一起拷过去
3
+ import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ const here = path.dirname(fileURLToPath(import.meta.url))
7
+ const src = process.argv[2] || 'D:/A-Claude-1/C-1019-1/livliv-kit/player'
8
+ const out = path.join(here, 'assets', 'livliv'); fs.mkdirSync(out, { recursive: true })
9
+ const esbuild = await import('./yusho-ui/node_modules/esbuild/lib/main.js').then((m) => m.default ?? m)
10
+ await esbuild.build({ entryPoints: [path.join(src, 'dist', 'index.js')], bundle: true, format: 'esm', minify: true, target: 'chrome90', outfile: path.join(out, 'player.mjs'), legalComments: 'inline', logLevel: 'error' })
11
+ for (const f of ['LICENSE', 'NOTICE']) fs.copyFileSync(path.join(src, f), path.join(out, f))
12
+ console.log('好了:', (fs.statSync(path.join(out, 'player.mjs')).size / 1024).toFixed(0) + ' KB')
package/app/memory.mjs ADDED
@@ -0,0 +1,53 @@
1
+ // 记忆:助理想记住关于你的事(喜好、习惯、常用的说法、重要的人和日子),先列出来问你,你点“记住”才算数。
2
+ // 记住的会附在每一轮的话前面(两边的助理都能用);你可以在“助理 → 记忆”里看、删。
3
+ // 存在 App 目录的 memory.json:{ items: [{ id, text, at, from, status: 'pending' | 'kept' }] }
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+ import { randomBytes } from 'node:crypto'
7
+
8
+ const MAX_KEPT = 80, MAX_PENDING = 20
9
+
10
+ export function createMemory({ dir }) {
11
+ const file = path.join(dir, 'memory.json')
12
+ let items = []; try { items = JSON.parse(fs.readFileSync(file, 'utf8')).items ?? [] } catch {}
13
+ const save = () => fs.writeFileSync(file, JSON.stringify({ items }))
14
+ const norm = (t) => String(t ?? '').replace(/\s+/g, ' ').trim()
15
+
16
+ /** 助理提议记住几条:和已有的重复的跳过;返回真正新加的条数 */
17
+ function propose(texts, from = 'work') {
18
+ const have = new Set(items.map((x) => norm(x.text)))
19
+ const add = (texts ?? []).map(norm).filter((t) => t && t.length <= 200 && !have.has(t)).slice(0, 5)
20
+ for (const text of add) items.push({ id: 'm' + Date.now().toString(36) + randomBytes(2).toString('hex'), text, at: Date.now(), from, status: 'pending' })
21
+ // 等确认的太多了:最早的先丢掉(没确认的不算数)
22
+ const pend = items.filter((x) => x.status === 'pending')
23
+ if (pend.length > MAX_PENDING) { const drop = new Set(pend.slice(0, pend.length - MAX_PENDING).map((x) => x.id)); items = items.filter((x) => !drop.has(x.id)) }
24
+ save(); return add.length
25
+ }
26
+ function answer(ids, keep) {
27
+ const set = new Set(ids)
28
+ if (keep) for (const x of items) { if (set.has(x.id) && x.status === 'pending') { x.status = 'kept'; x.keptAt = Date.now() } }
29
+ else items = items.filter((x) => !(set.has(x.id) && x.status === 'pending'))
30
+ const kept = items.filter((x) => x.status === 'kept')
31
+ if (kept.length > MAX_KEPT) { const drop = new Set(kept.slice(0, kept.length - MAX_KEPT).map((x) => x.id)); items = items.filter((x) => !drop.has(x.id)) }
32
+ save()
33
+ }
34
+ function remove(id) { items = items.filter((x) => x.id !== id); save() }
35
+ // ── 发生过的事(每天一条小结):每天第一次打开时,把前一天两边的对话压成几句话。最近几天的小结附在每一轮前面,
36
+ // 隔几天再聊、换了话题、会话被压缩过,她也接得上。存在 episodes.json:[{ date, text, at }],最多留 60 天
37
+ const efile = path.join(dir, 'episodes.json')
38
+ let episodes = []; try { episodes = JSON.parse(fs.readFileSync(efile, 'utf8')) } catch {}
39
+ const saveEp = () => fs.writeFileSync(efile, JSON.stringify(episodes.slice(-60)))
40
+ const hasEpisode = (date) => episodes.some((e) => e.date === date)
41
+ function addEpisode(date, text) { if (!text || hasEpisode(date)) return; episodes.push({ date, text: norm(text).slice(0, 400), at: Date.now() }); episodes.sort((a, b) => a.date.localeCompare(b.date)); saveEp() }
42
+ const recentEpisodes = (n = 3) => episodes.slice(-n)
43
+ /** 附在用户的话前面:记住的事 + 最近几天发生过的事(都没有就空) */
44
+ function note() {
45
+ const kept = items.filter((x) => x.status === 'kept'), ep = recentEpisodes(3)
46
+ return (kept.length ? '[App 附注,不是用户说的话:你记得的关于用户的事(用户本人确认过的),用得上就自然地用,不要逐条复述:\n' + kept.map((x) => '- ' + x.text).join('\n') + ']\n\n' : '')
47
+ + (ep.length ? '[App 附注,不是用户说的话:最近几天和用户之间发生过的事(你自己的记录,接话时用得上就用,不要复述):\n' + ep.map((e) => '- ' + e.date + ':' + e.text).join('\n') + ']\n\n' : '')
48
+ }
49
+ const keptTexts = () => items.filter((x) => x.status !== 'gone').map((x) => x.text)
50
+ const view = () => ({ pending: items.filter((x) => x.status === 'pending'), kept: items.filter((x) => x.status === 'kept').slice().reverse(), episodes: episodes.slice(-14).reverse() })
51
+ function removeEpisode(date) { episodes = episodes.filter((e) => e.date !== date); saveEp() }
52
+ return { propose, answer, remove, note, view, hasEpisode, addEpisode, removeEpisode, keptTexts }
53
+ }