@7ots/cli 0.1.17 → 0.1.36
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/.env.example +14 -0
- package/README.md +11 -0
- package/brand/logos/base.svg +1 -0
- package/brand/logos/clawpump.png +0 -0
- package/brand/logos/conductors.svg +1 -0
- package/brand/logos/notlogin.svg +12 -0
- package/brand/logos/pumpfun.png +0 -0
- package/brand/logos/solana.png +0 -0
- package/brand/logos/spawnerbot.svg +1 -0
- package/brand/logos/virtuals.png +0 -0
- package/cli/7ots.mjs +61 -1
- package/cli/lib/account.mjs +23 -3
- package/cli/lib/assistant.mjs +92 -14
- package/cli/lib/brain.mjs +84 -11
- package/cli/lib/card-shot.mjs +1 -1
- package/cli/lib/config.mjs +14 -3
- package/cli/lib/desktop-sync.mjs +177 -0
- package/cli/lib/i18n.mjs +9 -0
- package/cli/lib/inferences.mjs +19 -2
- package/cli/lib/integrations.mjs +98 -13
- package/cli/lib/mcp.mjs +1 -1
- package/cli/lib/open.mjs +3 -1
- package/cli/lib/pet-server.mjs +352 -41
- package/cli/lib/prompts.mjs +1 -1
- package/cli/lib/screen.mjs +1 -1
- package/cli/lib/senses/gestures.mjs +121 -0
- package/cli/lib/senses/index.mjs +490 -0
- package/cli/lib/senses/rules.mjs +159 -0
- package/cli/lib/senses/sources/activity.mjs +95 -0
- package/cli/lib/senses/sources/calendar.mjs +75 -0
- package/cli/lib/senses/sources/index.mjs +17 -0
- package/cli/lib/senses/sources/mail.mjs +48 -0
- package/cli/lib/senses/sources/system.mjs +39 -0
- package/cli/lib/senses/util.mjs +41 -0
- package/cli/lib/senses/vendor.mjs +78 -0
- package/cli/lib/stt-local.py +16 -8
- package/cli/lib/stt.mjs +53 -6
- package/cli/lib/tooluse.mjs +56 -0
- package/cli/lib/tts-local.mjs +2 -2
- package/cli/lib/vm.mjs +2 -2
- package/cli/lib/wake-local.py +109 -0
- package/cli/lib/wake.mjs +102 -0
- package/cli/pet/electron/main.cjs +190 -8
- package/cli/pet/pet.html +153 -34
- package/cli/pet/senses.html +342 -0
- package/cli/pet/settings.html +815 -74
- package/dist/7ots.esm.js +373 -146
- package/dist/7ots.esm.js.map +4 -4
- package/dist/7ots.iife.js +373 -146
- package/dist/7ots.iife.js.map +4 -4
- package/llms.txt +27 -0
- package/package.json +5 -2
- package/server/channels/apuchat.mjs +18 -4
- package/server/errors.mjs +90 -0
- package/server/notify.mjs +78 -0
- package/server/server.mjs +84 -14
- package/server/settings.mjs +3 -0
- package/server/site.mjs +401 -0
- package/server/tts.mjs +29 -5
- package/src/avatar/AvatarStage.js +2 -2
- package/src/avatar/three.js +3 -2
- package/src/character/AvatarEditor.js +2 -1
- package/src/character/Character.js +38 -5
- package/src/character/TradingCard.js +2 -0
- package/src/character/beat.js +64 -2
- package/src/character/mods/orc.js +8 -1
- package/src/character/mods.js +104 -10
- package/src/character/motion.js +252 -1
- package/src/character/parts.js +40 -38
- package/src/character/styles.js +40 -38
- package/src/character3d/Character3D.js +26 -5
- package/src/character3d/body.js +14 -12
- package/src/character3d/export.js +693 -0
- package/src/character3d/fx.js +13 -0
- package/src/character3d/index.js +2 -0
- package/src/character3d/materials.js +106 -10
- package/src/character3d/room-themes.js +1184 -0
- package/src/character3d/room.js +487 -0
- package/src/character3d/stage.js +14 -2
- package/src/creator/StepCreator.js +316 -0
- package/src/i18n/index.js +3 -3
- package/src/i18n/messages/character.js +352 -4
- package/src/i18n/messages/creator.js +138 -0
- package/src/i18n/messages/identity.js +89 -1
- package/src/i18n/messages/platform.js +270 -4
- package/src/i18n/messages/server.js +443 -1
- package/src/i18n/messages/widget.js +233 -0
- package/src/identity/random.js +14 -2
- package/src/identity/schema.js +2 -1
- package/src/index.js +9 -2
- package/src/voice/tags.js +22 -0
- package/server/platform/apuchat.mjs +0 -266
- package/server/platform/auth.mjs +0 -319
- package/server/platform/connect.mjs +0 -387
- package/server/platform/crypto.mjs +0 -80
- package/server/platform/db.mjs +0 -275
- package/server/platform/device.mjs +0 -222
- package/server/platform/integrations.mjs +0 -169
- package/server/platform/look.mjs +0 -20
- package/server/platform/mods.mjs +0 -222
- package/server/platform/orquesta.mjs +0 -577
- package/server/platform/profile.mjs +0 -161
- package/server/platform/routes.mjs +0 -542
- package/server/platform/runtime.mjs +0 -242
- package/server/platform/sites.mjs +0 -146
- package/server/platform/store.mjs +0 -456
- package/server/platform/vm.mjs +0 -1057
package/cli/lib/pet-server.mjs
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* POST /tts X-7ots-Token { text } → audio with the configured voice
|
|
11
11
|
* POST /ask X-7ots-Token { text } → { reply, actions } reminders, notes, open a site (assistant.mjs)
|
|
12
12
|
* POST /stt X-7ots-Token raw audio (webm/ogg) → { text } voice control (stt.mjs)
|
|
13
|
+
* POST /log X-7ots-Token { page, msg } → pet.log «audio[page]: msg» (what each page did with its audio)
|
|
13
14
|
* GET /reminders?token=… { reminders, notes }
|
|
14
15
|
* GET /inferences?token=… the brain's history: what was sent (the data it used) and what came back
|
|
15
16
|
* GET /memory?token=… everything it keeps about you: notes, what it saw, what it said, its state
|
|
@@ -20,6 +21,8 @@
|
|
|
20
21
|
* POST /watchers/cancel { id | 'all' }
|
|
21
22
|
* GET /cloud 7ots.com link + the cloud assistant's VM status (integrations.mjs)
|
|
22
23
|
* POST /integrations/test { integration } → { ok, tools? (MCP), text?, error? } (a draft, not saved)
|
|
24
|
+
* GET /byte · /byte/games · /byte/status · POST /byte/play { game } · /byte/stop · /byte/connect the twin ot plays byte arena (7ots.com)
|
|
25
|
+
* GET /wallet the twin ot's wallet on 7ots.com (read only): addresses, balances, payments + tx links
|
|
23
26
|
* GET /orquesta/projects · POST /orquesta/send { projectId, text } · GET /orquesta/prompt?id= your Orquesta agents
|
|
24
27
|
* POST /character/letta write the character sheet into a Letta agent's persona (LETTA_API_KEY)
|
|
25
28
|
* GET /settings?token=… the settings page: brain, what it may see and do, notes, reminders
|
|
@@ -29,9 +32,18 @@
|
|
|
29
32
|
* POST /notes/forget { at | 'all' }
|
|
30
33
|
* POST /conversation/forget drop the conversation memory (turns + summary)
|
|
31
34
|
* POST /quit X-7ots-Token
|
|
35
|
+
* POST /aura X-7ots-Token { name?, music? } → farmea aura (AURA_MOVES): suma al contador de ~/.7ots/aura.json → { name, points, total }
|
|
32
36
|
* POST /dance X-7ots-Token { name?, ms?, music? } → dances (DANCES in motion.js) with music (beat.js or ~/.7ots/music)
|
|
33
37
|
* POST /entrance X-7ots-Token { dance? } → a wrestling-style entrance: walks in, spotlights, pyro, its name, a dance
|
|
34
38
|
* GET /music?token=… { files } your own tracks in ~/.7ots/music · GET /music/<file>?token=… plays one
|
|
39
|
+
* GET /senses?token=…[&preview=1] the camera page (face + gestures → labels; the desktop shell runs it hidden)
|
|
40
|
+
* GET /senses/status · /senses/config what it notices now, rules, gestures, today · what the camera page needs
|
|
41
|
+
* GET /senses/vendor/<file> MediaPipe code and models (no token; downloaded by POST /senses/vendor)
|
|
42
|
+
* POST /senses { events: [{ kind: state|presence|gesture|status, … }] } from the camera page
|
|
43
|
+
* POST /senses/rules { action: add|set|remove|accept|reject|on|off, id?, rule? } · /senses/gestures { map, commands }
|
|
44
|
+
* POST /senses/baseline { baseline|null } · /senses/pause { min | resume } · /senses/forget · /senses/reflect
|
|
45
|
+
* POST /senses/snap { id, image } one camera frame the daemon asked for ({senses:{snap:id}} on /events) when you
|
|
46
|
+
* ask it to look at you; seen by the vision brain, shown as a thumbnail, never stored
|
|
35
47
|
*
|
|
36
48
|
* Only listens on 127.0.0.1 and only answers to Host 127.0.0.1/localhost (no DNS rebinding).
|
|
37
49
|
* The token lives in ~/.7ots/pet.token (0600): other users of the machine can't drive the pet.
|
|
@@ -39,7 +51,7 @@
|
|
|
39
51
|
|
|
40
52
|
import { createServer } from 'node:http';
|
|
41
53
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
42
|
-
import { readFileSync, existsSync, writeFileSync, chmodSync, mkdirSync, symlinkSync, readdirSync, statSync, createReadStream } from 'node:fs';
|
|
54
|
+
import { readFileSync, existsSync, writeFileSync, chmodSync, mkdirSync, rmSync, symlinkSync, readdirSync, statSync, createReadStream } from 'node:fs';
|
|
43
55
|
import { cardShot } from './card-shot.mjs';
|
|
44
56
|
import { join } from 'node:path';
|
|
45
57
|
import { createAssistant, notify, tr } from './assistant.mjs';
|
|
@@ -51,22 +63,26 @@ import { AI_CLIS, createBrain, detectClis, petSystem } from './brain.mjs';
|
|
|
51
63
|
import { CONFIG_DEFAULTS, env, loadConfig, saveConfig, saveKey } from './config.mjs';
|
|
52
64
|
import { loadIdentity } from './identity.mjs';
|
|
53
65
|
import { readJson, writeJson } from './paths.mjs';
|
|
54
|
-
import { sttProvider, transcribe } from './stt.mjs';
|
|
66
|
+
import { sttProvider, transcribe, warmStt } from './stt.mjs';
|
|
67
|
+
import { createWake } from './wake.mjs';
|
|
55
68
|
import { localVoices, synthesizeLocal, warmLocal } from './tts-local.mjs';
|
|
56
69
|
import { createScreenWatcher } from './screen.mjs';
|
|
57
70
|
import { createSiteContext } from './prowl.mjs';
|
|
58
|
-
import {
|
|
71
|
+
import { createSenses } from './senses/index.mjs';
|
|
72
|
+
import { ensureVendor, vendorFile, vendorStatus } from './senses/vendor.mjs';
|
|
73
|
+
import { SEVENOTS_URL, cloudSpeak, community, sync as syncOt, logout as accountLogout, me as accountMe, pull as pullOt, signedIn, startLogin, use as useOt } from './account.mjs';
|
|
59
74
|
import { openUrl } from './open.mjs';
|
|
75
|
+
import { syncDesktop } from './desktop-sync.mjs';
|
|
60
76
|
import { VM_KINDS } from './vm.mjs';
|
|
61
|
-
import { cloudStatus, createExtras, lettaSync, normalizeCharacter, normalizeIntegrations, redact, testCustom } from './integrations.mjs';
|
|
77
|
+
import { cloudByte, cloudPlaza, cloudStatus, cloudWallet, createExtras, lettaSync, normalizeCharacter, normalizeIntegrations, redact, testCustom } from './integrations.mjs';
|
|
62
78
|
import { spawn } from 'node:child_process';
|
|
63
79
|
import { openSync } from 'node:fs';
|
|
64
80
|
import { line } from './lines.mjs';
|
|
65
81
|
import { defineIdentity, GROK_VOICES, OPENAI_VOICES, TTS_MODELS } from '../../src/identity/schema.js';
|
|
66
82
|
import { normalizeMod, normalizeMods, MAX_MODS } from '../../src/character/mods.js';
|
|
67
83
|
import { MOD_CATALOG } from '../../src/character/mods/index.js';
|
|
68
|
-
import { DANCES } from '../../src/character/motion.js';
|
|
69
|
-
import { stripSpeechTags } from '../../src/voice/tags.js';
|
|
84
|
+
import { DANCES, AURA_MOVES, AURA_STYLE, AURA_POINTS } from '../../src/character/motion.js';
|
|
85
|
+
import { stripMarkdown, stripSpeechTags } from '../../src/voice/tags.js';
|
|
70
86
|
|
|
71
87
|
/** Mods importados en este pet (~/.7ots/mods/library.json), normalizados. */
|
|
72
88
|
// scenes between ots on the same desktop (pet/electron/director.cjs plays them)
|
|
@@ -84,6 +100,14 @@ function musicFiles() {
|
|
|
84
100
|
return [];
|
|
85
101
|
}
|
|
86
102
|
}
|
|
103
|
+
/** Tus temas para farmear aura: ~/.7ots/music/aura/*, como «aura/<archivo>». */
|
|
104
|
+
function auraFiles() {
|
|
105
|
+
try {
|
|
106
|
+
return readdirSync(homeFile('music/aura')).filter((f) => MUSIC_FILE.test(f) && !f.startsWith('.') && statSync(homeFile(`music/aura/${f}`)).isFile()).sort().map((f) => `aura/${f}`);
|
|
107
|
+
} catch {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
87
111
|
const modLibrary = () => (readJson(homeFile('mods/library.json')) || []).map(normalizeMod).filter(Boolean);
|
|
88
112
|
import { ensureHome, homeFile, PET_PORT, PKG_ROOT } from './paths.mjs';
|
|
89
113
|
import { applyEvent, loadPet, need, savePet, tick, view } from './pet-core.mjs';
|
|
@@ -127,7 +151,7 @@ export async function postPet(path, body, port = PET_PORT) {
|
|
|
127
151
|
}
|
|
128
152
|
|
|
129
153
|
const VOICE_PROVIDERS = ['elevenlabs', 'openai', 'apuchat', 'grok', 'fish'];
|
|
130
|
-
const SETTABLE_KEYS = ['ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'ORQUESTA_TOKEN', 'ELEVENLABS_API_KEY', 'APUCHAT_VOICE_TOKEN', 'XAI_API_KEY', 'FISH_API_KEY', 'LETTA_API_KEY', 'APUMAIL_TOKEN'];
|
|
154
|
+
const SETTABLE_KEYS = ['ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'ORQUESTA_TOKEN', 'ELEVENLABS_API_KEY', 'APUCHAT_VOICE_TOKEN', 'XAI_API_KEY', 'FISH_API_KEY', 'LETTA_API_KEY', 'APUMAIL_TOKEN', 'SENSES_ICS_URL'];
|
|
131
155
|
// The settings page speaks the human's language: SEVENOTS_LANG, config.lang, the system's, then the ot's.
|
|
132
156
|
const uiLangOf = (c, fallback) => [process.env.SEVENOTS_LANG, c.lang, String(process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || '').slice(0, 2).toLowerCase(), fallback].find((l) => ['en', 'es', 'pt'].includes(l)) || 'en';
|
|
133
157
|
const brainLabel = (b = {}) => (b.kind === 'cli' ? `${b.cli}${b.model ? ` · ${b.model}` : ''}` : b.kind === 'api' ? `${b.provider || 'api'}${b.model ? ` · ${b.model}` : ''}` : b.kind || 'lines');
|
|
@@ -170,7 +194,23 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
170
194
|
};
|
|
171
195
|
let brainImpl = createBrain(config.brain, config.home); // swapped live from the settings page
|
|
172
196
|
const inferences = createInferenceLog();
|
|
197
|
+
/**
|
|
198
|
+
* Text → audio with a provider. apuchat without a token of its own: through the ot on 7ots.com when this computer is
|
|
199
|
+
* signed in (apuchat has no per-account voice tokens; that was the 401 testers hit pasting other keys).
|
|
200
|
+
*/
|
|
201
|
+
const voiceAudio = async (kind, text, voice) => {
|
|
202
|
+
const keys = env();
|
|
203
|
+
if (kind === 'apuchat' && !keys.APUCHAT_VOICE_TOKEN && keys.SEVENOTS_TOKEN && config.account?.otsId) {
|
|
204
|
+
return cloudSpeak(config.account.otsId, { text: stripSpeechTags(text), voiceId: voice.voiceId || '', lang: voice.lang || '' });
|
|
205
|
+
}
|
|
206
|
+
const { synthesize } = await import('../../server/tts.mjs');
|
|
207
|
+
// process.env too: XAI_TTS_VOICE, FISH_VOICE_ID, APUCHAT_VOICE_URL… (the keys still come from env())
|
|
208
|
+
return synthesize({ text, voice, env: { ...process.env, ...keys } });
|
|
209
|
+
};
|
|
173
210
|
if (config.voice.kind === 'local') warmLocal();
|
|
211
|
+
// "oye <name>" opens the pet page's mic (wake.mjs); in your language, not the ot's. Only the host ot listens.
|
|
212
|
+
const wake = createWake({ log, onWake: () => broadcast({ wake: true }), onState: (w) => broadcast({ wakeState: w }) });
|
|
213
|
+
const wakeConf = () => wake.set({ on: !!config.voice.wake && !process.env.SEVENOTS_COMPANION && sttProvider(env()) !== null, name: identity.name, lang: uiLangOf(config, lang) });
|
|
174
214
|
const brain = inferences.wrap(() => brainImpl, () => brainLabel(config.brain)); // every call lands in the history
|
|
175
215
|
const pet = tick(loadPet());
|
|
176
216
|
const clients = new Set();
|
|
@@ -185,6 +225,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
185
225
|
|
|
186
226
|
const broadcast = (msg) => {
|
|
187
227
|
const data = `data: ${JSON.stringify({ state: view(pet), ...msg })}\n\n`;
|
|
228
|
+
if (msg.say) log(`audio: say → ${clients.size} page(s) «${String(msg.say).slice(0, 60)}»${msg.ambient ? ' (ambient)' : ''}`); // to debug a voice heard twice
|
|
188
229
|
for (const res of clients) res.write(data);
|
|
189
230
|
};
|
|
190
231
|
|
|
@@ -209,10 +250,12 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
209
250
|
}
|
|
210
251
|
// Orquesta sign-in in the browser; once in, its integration is on
|
|
211
252
|
let connecting = null;
|
|
212
|
-
|
|
253
|
+
let orquestaLoginAt = 0; // the settings page waits for it to change after "Sign in with Orquesta"
|
|
254
|
+
// local: the token is wanted on this computer (Batuta as the brain), even when 7ots.com could hold it
|
|
255
|
+
function connectOrquesta({ local = false } = {}) {
|
|
213
256
|
return (connecting ||= import('./orquesta.mjs')
|
|
214
257
|
.then(async (o) => {
|
|
215
|
-
if (o.via() !== '7ots') return o.login({ open: openUrl });
|
|
258
|
+
if (local || o.via() !== '7ots') return o.login({ open: openUrl });
|
|
216
259
|
// signed in to 7ots.com: connect it there (once for the ot everywhere); its token stays there
|
|
217
260
|
openUrl(`${SEVENOTS_URL}/app/#ots/${config.account.otsId}/orquesta`);
|
|
218
261
|
for (const end = Date.now() + 10 * 60_000; Date.now() < end; ) {
|
|
@@ -226,6 +269,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
226
269
|
next.integrations = { ...next.integrations, orquesta: { ...next.integrations?.orquesta, on: true } };
|
|
227
270
|
saveConfig(next);
|
|
228
271
|
config = loadConfig();
|
|
272
|
+
orquestaLoginAt = Date.now();
|
|
229
273
|
log(`orquesta: connected${r.organizationName ? ` (${r.organizationName})` : ''}`);
|
|
230
274
|
broadcast({ orquesta: true });
|
|
231
275
|
return r;
|
|
@@ -235,7 +279,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
235
279
|
|
|
236
280
|
async function speak(kind, vars = {}, situation = '', { force = false, gesture = null } = {}) {
|
|
237
281
|
const now = Date.now();
|
|
238
|
-
const quiet = now < chatUntil || (kind === 'hello' && now - lastHello < HELLO_GAP) || (force ? now - lastSpoke < IMPORTANT_GAP[annoy] : pet.asleep || now - lastSpoke < GAP[annoy]);
|
|
282
|
+
const quiet = now < chatUntil || (!force && senses?.quiet()) || (kind === 'hello' && now - lastHello < HELLO_GAP) || (force ? now - lastSpoke < IMPORTANT_GAP[annoy] : pet.asleep || now - lastSpoke < GAP[annoy]);
|
|
239
283
|
if (quiet) {
|
|
240
284
|
broadcast({ gesture });
|
|
241
285
|
return;
|
|
@@ -342,7 +386,8 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
342
386
|
broadcast({});
|
|
343
387
|
}, 60_000);
|
|
344
388
|
|
|
345
|
-
// Sync with its ot on 7ots.com (account.mjs sync): same look, mods, personality and sheet on both sides
|
|
389
|
+
// Sync with its ot on 7ots.com (account.mjs sync): same look, mods, personality and sheet on both sides,
|
|
390
|
+
// and (desktop-sync.mjs) its settings, tamagotchi progress, notes, reminders and watchers.
|
|
346
391
|
let syncing = false;
|
|
347
392
|
let syncSoon = null;
|
|
348
393
|
let syncErr = '';
|
|
@@ -351,9 +396,15 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
351
396
|
syncing = true;
|
|
352
397
|
try {
|
|
353
398
|
const r = await syncOt();
|
|
399
|
+
// the rest of what this pet keeps (settings, progress, notes, reminders, watchers): desktop-sync.mjs
|
|
400
|
+
const d = await syncDesktop({ pet });
|
|
354
401
|
syncErr = '';
|
|
355
402
|
if (r.action === 'push' || r.action === 'pull') log(`sync: ${r.action} 7ots.com`);
|
|
356
|
-
if (
|
|
403
|
+
if (d.action === 'push' || d.action === 'pull') log(`sync: desktop ${d.action} 7ots.com${d.wrote?.length ? ` (${d.wrote.join(', ')})` : ''}`);
|
|
404
|
+
if (d.wrote?.includes('progress')) savePet(pet);
|
|
405
|
+
// its new look/personality, settings or lists, everywhere (progress alone is already live)
|
|
406
|
+
if (r.action === 'pull' || d.wrote?.some((k) => k !== 'progress')) restart();
|
|
407
|
+
else if (d.wrote?.length) broadcast({});
|
|
357
408
|
} catch (e) {
|
|
358
409
|
if (e.message !== syncErr) log(`sync: ${(syncErr = e.message)}`);
|
|
359
410
|
} finally {
|
|
@@ -389,6 +440,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
389
440
|
system: (said) => petSystem(identity, { lang: said || 'auto', role: 'assistant' }),
|
|
390
441
|
// offload to the ot's cloud worker (access.vm): needs this computer signed in to 7ots.com
|
|
391
442
|
cloud: () => (env().SEVENOTS_TOKEN && config.account?.otsId) || null,
|
|
443
|
+
context: () => senses.prompt(),
|
|
392
444
|
say: (text) => {
|
|
393
445
|
lastSpoke = Date.now();
|
|
394
446
|
pet.lastTalk = lastSpoke;
|
|
@@ -441,6 +493,110 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
441
493
|
},
|
|
442
494
|
});
|
|
443
495
|
|
|
496
|
+
// Senses (senses/): camera (face + gestures, from the hidden /senses page), activity, the computer, email,
|
|
497
|
+
// calendar → rules and gesture commands, and a reflector that now and then proposes something.
|
|
498
|
+
async function senseTalk({ text = '', about = '', exact = false, kind = 'senses', important = false, gesture = 'wave' }) {
|
|
499
|
+
const now = Date.now();
|
|
500
|
+
if (now < chatUntil || thinking || asks.size || (pet.asleep && !important)) return false;
|
|
501
|
+
if (now - lastSpoke < (important ? IMPORTANT_GAP : GAP)[annoy]) return false;
|
|
502
|
+
let say = exact ? text : '';
|
|
503
|
+
if (!say && about && brain.kind !== 'lines') {
|
|
504
|
+
thinking = true;
|
|
505
|
+
try {
|
|
506
|
+
say = await brain.think({
|
|
507
|
+
purpose: kind,
|
|
508
|
+
system: petSystem(identity, { lang }),
|
|
509
|
+
messages: [{ role: 'user', content: `${about}\nOne short line to them, in character.${history.length ? `\n(Things you already said: ${history.join(' | ')})` : ''}` }],
|
|
510
|
+
timeoutMs: 30000,
|
|
511
|
+
});
|
|
512
|
+
} catch (e) {
|
|
513
|
+
log(`brain: ${e.message}`);
|
|
514
|
+
}
|
|
515
|
+
thinking = false;
|
|
516
|
+
}
|
|
517
|
+
say = String(say || text || '').trim();
|
|
518
|
+
if (!say || Date.now() < chatUntil) return false;
|
|
519
|
+
lastSpoke = Date.now();
|
|
520
|
+
pet.lastTalk = lastSpoke;
|
|
521
|
+
history.push(say);
|
|
522
|
+
if (history.length > 6) history.shift();
|
|
523
|
+
if (important && config.access.notify !== false) notify(`${identity.name} · 7ots`, say);
|
|
524
|
+
broadcast({ say, gesture, effect: important ? 'exclaim' : null, point: 'user', stir: important && pet.asleep, ambient: !important });
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
async function senseAsk(text) {
|
|
528
|
+
chatUntil = Date.now() + CHAT_QUIET;
|
|
529
|
+
broadcast({ thinking: true, activity: track({ type: 'prompt', text }) });
|
|
530
|
+
const r = (await lookAt(text)) || (await assistant.ask(text));
|
|
531
|
+
lastSpoke = Date.now();
|
|
532
|
+
chatUntil = Date.now() + CHAT_QUIET;
|
|
533
|
+
broadcast({ thinking: false, say: r.reply, photo: r.photo, gesture: r.actions.length ? 'nod' : null, point: r.actions.some((a) => a.type === 'open') ? 'browser' : null });
|
|
534
|
+
}
|
|
535
|
+
// A real look, only when asked ("¿cómo me ves?"): the camera page sends one frame, the vision brain looks at it,
|
|
536
|
+
// the pet shows it as a thumbnail. Kept in memory only; the file the CLI reads is deleted right after.
|
|
537
|
+
const LOOK_RE = /c[oó]mo me ves|m[ií]rame|me (?:est[aá]s )?viendo|qu[eé] (?:me )?ves|me ves\b|look at me|how do i look|can you see me|what do you see|como (?:é que )?(?:voc[eê] )?me v[eê]|olh[ae] pra mim/i;
|
|
538
|
+
const snaps = new Map();
|
|
539
|
+
function snapFrame(ms = 6000) {
|
|
540
|
+
const id = randomBytes(6).toString('hex');
|
|
541
|
+
return new Promise((resolve) => {
|
|
542
|
+
const t = setTimeout(() => (snaps.delete(id), resolve(null)), ms);
|
|
543
|
+
snaps.set(id, (img) => (clearTimeout(t), snaps.delete(id), resolve(img)));
|
|
544
|
+
broadcast({ senses: { snap: id } });
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
async function lookAt(text) {
|
|
548
|
+
if (!brain.vision || !senses.cameraOn() || !LOOK_RE.test(text)) return null;
|
|
549
|
+
const photo = await snapFrame();
|
|
550
|
+
if (!photo) return log('senses look: no frame from the camera page'), null;
|
|
551
|
+
mkdirSync(homeFile('senses'), { recursive: true });
|
|
552
|
+
const f = homeFile(`senses/look-${randomBytes(4).toString('hex')}.jpg`);
|
|
553
|
+
writeFileSync(f, Buffer.from(photo.slice(photo.indexOf(',') + 1), 'base64'), { mode: 0o600 });
|
|
554
|
+
try {
|
|
555
|
+
const reply = await brain.think({
|
|
556
|
+
purpose: 'look',
|
|
557
|
+
system: `${petSystem(identity, { lang: 'auto' })}\n\nYour human asked you to look at them: the image is a frame from their webcam, taken just now. Look at it for real and answer what they asked, warm and specific to what you see (expression, light, posture, what is around). One to three short lines. Never guess identity, age, health or anything sensitive; do not describe other people in it.`,
|
|
558
|
+
messages: [{ role: 'user', content: `${text}${senses.prompt() ? `\n\n${senses.prompt()}` : ''}` }],
|
|
559
|
+
files: [f],
|
|
560
|
+
timeoutMs: 120000,
|
|
561
|
+
});
|
|
562
|
+
return reply ? { reply, actions: [], photo } : null;
|
|
563
|
+
} catch (e) {
|
|
564
|
+
log(`senses look: ${e.message}`);
|
|
565
|
+
return null;
|
|
566
|
+
} finally {
|
|
567
|
+
rmSync(f, { force: true });
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const senses = createSenses({
|
|
571
|
+
config: () => config,
|
|
572
|
+
brain,
|
|
573
|
+
lang,
|
|
574
|
+
log,
|
|
575
|
+
system: () => petSystem(identity, { lang }),
|
|
576
|
+
annoy: () => annoy,
|
|
577
|
+
busy: () => Date.now() < chatUntil || thinking || asks.size > 0 || pet.asleep,
|
|
578
|
+
talk: senseTalk,
|
|
579
|
+
confirm,
|
|
580
|
+
asking: () => asks.size > 0,
|
|
581
|
+
answer: (ok) => {
|
|
582
|
+
const a = [...asks.values()].at(-1);
|
|
583
|
+
if (a) a.done(ok);
|
|
584
|
+
return Boolean(a);
|
|
585
|
+
},
|
|
586
|
+
remind: (r) => assistant.remind(r),
|
|
587
|
+
ask: (text) => senseAsk(String(text).slice(0, 300)).catch((e) => log(`senses ask: ${e.message}`)),
|
|
588
|
+
notify: (text) => config.access.notify !== false && notify(`${identity.name} · 7ots`, text),
|
|
589
|
+
broadcast,
|
|
590
|
+
});
|
|
591
|
+
senses.bind({
|
|
592
|
+
setConfig: (patch) => {
|
|
593
|
+
const next = loadConfig();
|
|
594
|
+
next.senses = { ...next.senses, ...patch };
|
|
595
|
+
saveConfig(next);
|
|
596
|
+
config = loadConfig();
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
|
|
444
600
|
// Home on getorquesta.com: comment on what the project's agent does.
|
|
445
601
|
let stopWatch = () => {};
|
|
446
602
|
if (config.home.kind === 'orquesta' && config.home.projectId && env().ORQUESTA_TOKEN) {
|
|
@@ -466,7 +622,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
466
622
|
|
|
467
623
|
const page = (file = 'pet.html', extra = {}) =>
|
|
468
624
|
readFileSync(join(PKG_ROOT, 'cli', 'pet', file), 'utf8')
|
|
469
|
-
.replace('__BOOT__', JSON.stringify({ token, pid: process.pid, companion: !!process.env.SEVENOTS_COMPANION, identity, otsId: config.account?.otsId || '', voice: config.voice, lang, annoy, brain: brainLabel(config.brain), activity, stt: sttProvider(env()), backdrop: config.pet.backdrop !== false, ...extra }).replace(/</g, '\\u003c'));
|
|
625
|
+
.replace('__BOOT__', JSON.stringify({ token, pid: process.pid, companion: !!process.env.SEVENOTS_COMPANION, identity, otsId: config.account?.otsId || '', voice: config.voice, lang, annoy, brain: brainLabel(config.brain), activity, stt: sttProvider(env()), wake: wake.status(), backdrop: config.pet.backdrop !== false, ...extra }).replace(/</g, '\\u003c'));
|
|
470
626
|
|
|
471
627
|
// Visitors: other ots of the account invited onto this desktop (their look, saved so they come offline too).
|
|
472
628
|
// The desktop shell opens a window for each and stages scenes between them (see electron/director.cjs).
|
|
@@ -506,6 +662,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
506
662
|
spawn(process.execPath, [join(PKG_ROOT, 'cli', '7ots.mjs'), 'pet', '--daemon'], {
|
|
507
663
|
cwd: c.dir, // never pick up a project's .7ots/identity.json
|
|
508
664
|
detached: true,
|
|
665
|
+
windowsHide: true,
|
|
509
666
|
stdio: ['ignore', out, out],
|
|
510
667
|
env: { ...process.env, SEVENOTS_COMPANION: '1', SEVENOTS_HOME: c.dir, SEVENOTS_PET_PORT: String(port + 1), SEVENOTS_PORT_WAIT: '1' },
|
|
511
668
|
}).unref();
|
|
@@ -537,12 +694,32 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
537
694
|
return res.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'no-cache' }).end(readFileSync(f));
|
|
538
695
|
}
|
|
539
696
|
if (req.method === 'GET' && /^\/mods\/[a-f0-9]{16}\.(vrm|glb)$/.test(p)) {
|
|
540
|
-
// 3D models of full-body mods, uploaded from settings (content-addressed, so cacheable)
|
|
697
|
+
// 3D models of full-body mods, uploaded from settings (content-addressed, so cacheable); one that is
|
|
698
|
+
// not here yet (a community mod you only browse) comes from 7ots.com, checked against its name, not kept
|
|
541
699
|
const f = homeFile(p.slice(1));
|
|
700
|
+
let buf = existsSync(f) ? readFileSync(f) : null;
|
|
701
|
+
if (!buf) {
|
|
702
|
+
const r = await fetch(`${SEVENOTS_URL}${p}`, { signal: AbortSignal.timeout(60000) }).catch(() => null);
|
|
703
|
+
const b = r?.ok ? Buffer.from(await r.arrayBuffer()) : null;
|
|
704
|
+
if (b && createHash('sha256').update(b).digest('hex').slice(0, 16) === p.slice(6, 22)) buf = b;
|
|
705
|
+
}
|
|
706
|
+
if (!buf) return res.writeHead(404).end();
|
|
707
|
+
return res.writeHead(200, { 'Content-Type': 'model/gltf-binary', 'Cache-Control': 'max-age=31536000, immutable' }).end(buf);
|
|
708
|
+
}
|
|
709
|
+
// chain and launchpad logos for the wallet page (brand/logos, public files)
|
|
710
|
+
if (req.method === 'GET' && /^\/logos\/[a-z]+\.(svg|png)$/.test(p)) {
|
|
711
|
+
const f = join(PKG_ROOT, 'brand', 'logos', p.slice(7));
|
|
542
712
|
if (!existsSync(f)) return res.writeHead(404).end();
|
|
543
|
-
return res.writeHead(200, { 'Content-Type': '
|
|
713
|
+
return res.writeHead(200, { 'Content-Type': p.endsWith('.svg') ? 'image/svg+xml' : 'image/png', 'Cache-Control': 'max-age=86400' }).end(readFileSync(f));
|
|
544
714
|
}
|
|
545
715
|
if (req.method === 'GET' && p === '/favicon.svg') return res.writeHead(200, { 'Content-Type': 'image/svg+xml', 'Cache-Control': 'max-age=86400' }).end(readFileSync(join(PKG_ROOT, 'brand', 'favicon.svg')));
|
|
716
|
+
// the camera's libraries and models (MediaPipe, pinned by hash in senses/vendor.mjs): public files
|
|
717
|
+
if (req.method === 'GET' && p.startsWith('/senses/vendor/')) {
|
|
718
|
+
const v = vendorFile(p.slice(15));
|
|
719
|
+
if (!v || !existsSync(v.file)) return res.writeHead(404).end();
|
|
720
|
+
res.writeHead(200, { 'Content-Type': v.type, 'Content-Length': statSync(v.file).size, 'Cache-Control': 'max-age=86400' });
|
|
721
|
+
return createReadStream(v.file).pipe(res);
|
|
722
|
+
}
|
|
546
723
|
const authed = okToken(url.searchParams.get('token') || req.headers['x-7ots-token']);
|
|
547
724
|
if (!authed) return json(401, { error: 'token' });
|
|
548
725
|
|
|
@@ -580,10 +757,16 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
580
757
|
}
|
|
581
758
|
}
|
|
582
759
|
if (req.method === 'GET' && p === '/config') return json(200, settingsView());
|
|
760
|
+
if (req.method === 'GET' && p === '/senses') {
|
|
761
|
+
const preview = url.searchParams.get('preview') === '1';
|
|
762
|
+
return res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer', 'X-Frame-Options': 'DENY' }).end(page('senses.html', { senses: senses.pageConfig(), vendor: vendorStatus(), preview, uiLang: uiLangOf(config, lang) }));
|
|
763
|
+
}
|
|
764
|
+
if (req.method === 'GET' && p === '/senses/config') return json(200, { ...senses.pageConfig(), vendor: vendorStatus() });
|
|
765
|
+
if (req.method === 'GET' && p === '/senses/status') return json(200, { ...senses.status(), vendor: vendorStatus(), wantCamera: senses.pageConfig().on && vendorStatus().ready });
|
|
583
766
|
if (req.method === 'GET' && p === '/state') return json(200, { identity, state: view(pet), config: { voice: config.voice, pet: config.pet, brain: config.brain.kind } });
|
|
584
767
|
if (req.method === 'GET' && p === '/events') {
|
|
585
768
|
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
|
|
586
|
-
res.write(`data: ${JSON.stringify({ state: view(pet), ...(viewSet ? { view: viewSet } : {}) })}\n\n`);
|
|
769
|
+
res.write(`data: ${JSON.stringify({ state: view(pet), ...(viewSet ? { view: viewSet } : {}), ...(senses.cameraOn() ? { senses: { camera: 'on' } } : {}) })}\n\n`);
|
|
587
770
|
for (const [id, a] of asks) res.write(`data: ${JSON.stringify({ ask: { id, text: a.text } })}\n\n`); // still waiting for you
|
|
588
771
|
clients.add(res);
|
|
589
772
|
req.on('close', () => clients.delete(res));
|
|
@@ -601,7 +784,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
601
784
|
try {
|
|
602
785
|
name = decodeURIComponent(p.slice(7));
|
|
603
786
|
} catch {}
|
|
604
|
-
if (!musicFiles().includes(name)) return res.writeHead(404).end();
|
|
787
|
+
if (!musicFiles().includes(name) && !auraFiles().includes(name)) return res.writeHead(404).end();
|
|
605
788
|
const f = homeFile(`music/${name}`);
|
|
606
789
|
const type = MUSIC_TYPES[name.split('.').pop().toLowerCase()];
|
|
607
790
|
res.writeHead(200, { 'Content-Type': type, 'Content-Length': statSync(f).size, 'Cache-Control': 'no-cache' });
|
|
@@ -610,11 +793,12 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
610
793
|
if (req.method === 'GET' && p === '/inferences') {
|
|
611
794
|
// this ot's calls plus those of the ots visiting this desktop (the host sees all), each tagged with its ot
|
|
612
795
|
const n = Number(url.searchParams.get('n')) || 100;
|
|
613
|
-
const me = { id: config.account?.otsId || 'local', name: identity.name || 'ot', self: true };
|
|
796
|
+
const me = { id: config.account?.otsId || 'local', name: identity.name || 'ot', character: identity.look?.character || null, self: true };
|
|
614
797
|
const all = [...inferences.list(MAX_INF).map((r) => ({ ...r, ot: me })), ...otherInferences()].sort((a, b) => b.at - a.at);
|
|
615
798
|
const ots = [...new Map(all.map((r) => [r.ot.id, r.ot])).values()];
|
|
616
799
|
const want = url.searchParams.get('ot');
|
|
617
|
-
|
|
800
|
+
const rows = (want ? all.filter((r) => r.ot.id === want) : all).slice(0, n).map(({ ot, ...r }) => ({ ...r, ot: { id: ot.id, name: ot.name } }));
|
|
801
|
+
return json(200, { ots, inferences: rows });
|
|
618
802
|
}
|
|
619
803
|
if (req.method === 'GET' && p === '/memory') return json(200, { notes: assistant.notes, reminders: assistant.reminders, seen: watcher.seen, said: history, conversation: assistant.conversation, activity, pet: view(pet) });
|
|
620
804
|
if (req.method === 'GET' && p === '/account') {
|
|
@@ -635,11 +819,61 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
635
819
|
});
|
|
636
820
|
if (req.method === 'GET' && p === '/reminders') return json(200, { reminders: assistant.reminders, notes: assistant.notes });
|
|
637
821
|
if (req.method === 'GET' && p === '/cloud') return json(200, await cloudStatus(config));
|
|
822
|
+
const bm = /^\/byte(\/(?:games|status|play|stop|connect))?$/.exec(p);
|
|
823
|
+
if (bm && (req.method === 'GET' || req.method === 'POST')) {
|
|
824
|
+
try {
|
|
825
|
+
let body;
|
|
826
|
+
if (req.method === 'POST') {
|
|
827
|
+
let raw = '';
|
|
828
|
+
for await (const c of req) if ((raw += c).length > 4096) break;
|
|
829
|
+
try {
|
|
830
|
+
body = JSON.parse(raw || '{}');
|
|
831
|
+
} catch {
|
|
832
|
+
body = {};
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return json(200, await cloudByte(config, bm[1] || '', { method: req.method, body }));
|
|
836
|
+
} catch (e) {
|
|
837
|
+
return json(e.status === 401 ? 200 : 502, e.status === 401 ? { available: false } : { error: e.message });
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
// the plaza on 7ots.com: how the twin ot takes part; its "share tools" is the same switch as access.prowl here
|
|
841
|
+
if (p === '/plaza/settings' && (req.method === 'GET' || req.method === 'POST')) {
|
|
842
|
+
try {
|
|
843
|
+
let body;
|
|
844
|
+
if (req.method === 'POST') {
|
|
845
|
+
let raw = '';
|
|
846
|
+
for await (const c of req) if ((raw += c).length > 4096) break;
|
|
847
|
+
try {
|
|
848
|
+
body = JSON.parse(raw || '{}');
|
|
849
|
+
} catch {
|
|
850
|
+
body = {};
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
const r = await cloudPlaza(config, { method: req.method, body });
|
|
854
|
+
// once linked, the account is the source of truth (it may have been changed on 7ots.com)
|
|
855
|
+
const tools = r.ot?.tools ?? r.tools;
|
|
856
|
+
if (typeof tools === 'boolean' && tools !== (config.access.prowl === true)) {
|
|
857
|
+
saveConfig({ ...JSON.parse(JSON.stringify(config)), access: { ...config.access, prowl: tools } });
|
|
858
|
+
config = loadConfig();
|
|
859
|
+
}
|
|
860
|
+
return json(200, r);
|
|
861
|
+
} catch (e) {
|
|
862
|
+
return json(502, { error: e.message });
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
if (req.method === 'GET' && p === '/wallet') {
|
|
866
|
+
try {
|
|
867
|
+
return json(200, await cloudWallet(config));
|
|
868
|
+
} catch (e) {
|
|
869
|
+
return json(e.status === 401 ? 200 : 502, e.status === 401 ? { available: false } : { error: e.message });
|
|
870
|
+
}
|
|
871
|
+
}
|
|
638
872
|
if (req.method === 'GET' && (p === '/orquesta/projects' || p === '/orquesta/prompt')) {
|
|
639
873
|
const o = await import('./orquesta.mjs');
|
|
640
874
|
if (!o.via()) return json(200, { connected: false });
|
|
641
875
|
try {
|
|
642
|
-
if (p === '/orquesta/projects') return json(200, { connected: true, projects: await o.agentProjects() });
|
|
876
|
+
if (p === '/orquesta/projects') return json(200, { connected: true, via: o.via(), projects: await o.agentProjects() });
|
|
643
877
|
return json(200, { connected: true, ...(await o.agentTask(String(url.searchParams.get('id') || '').slice(0, 80))) });
|
|
644
878
|
} catch (e) {
|
|
645
879
|
const off = [401, 409].includes(e.status); // no token / not connected on 7ots.com
|
|
@@ -656,7 +890,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
656
890
|
}
|
|
657
891
|
try {
|
|
658
892
|
const t0 = Date.now();
|
|
659
|
-
const { text, provider } = await transcribe({ audio: Buffer.concat(chunks), contentType: req.headers['content-type'], lang:
|
|
893
|
+
const { text, provider } = await transcribe({ audio: Buffer.concat(chunks), contentType: req.headers['content-type'], lang: uiLangOf(config, lang), env: env() }); // your language: detecting it on a short clip lands on Portuguese
|
|
660
894
|
log(`stt: ${provider} ${Date.now() - t0}ms ${n}B → ${text.length} chars`);
|
|
661
895
|
return json(200, { text });
|
|
662
896
|
} catch (e) {
|
|
@@ -682,7 +916,8 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
682
916
|
return json(200, { ok: true, url: `/mods/${name}` });
|
|
683
917
|
}
|
|
684
918
|
let body = '';
|
|
685
|
-
|
|
919
|
+
const max = p === '/senses/snap' ? 400 * 1024 : 64 * 1024; // a camera frame
|
|
920
|
+
for await (const c of req) if ((body += c).length > max) return json(413, { error: 'too large' });
|
|
686
921
|
let data = {};
|
|
687
922
|
try {
|
|
688
923
|
data = body ? JSON.parse(body) : {};
|
|
@@ -695,20 +930,22 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
695
930
|
savePet(pet);
|
|
696
931
|
return json(200, { ok: true, state: view(pet) });
|
|
697
932
|
}
|
|
933
|
+
// what each page did with its audio (say, tts, play, cut, music): pet.log, to debug voices heard twice
|
|
934
|
+
if (p === '/log') {
|
|
935
|
+
log(`audio[${String(data.page || '?').slice(0, 8)}]: ${String(data.msg || '').replace(/\s+/g, ' ').slice(0, 200)}`);
|
|
936
|
+
return json(200, { ok: true });
|
|
937
|
+
}
|
|
698
938
|
if (p === '/tts') {
|
|
699
939
|
const kind = config.voice.kind;
|
|
940
|
+
log(`audio: tts ${kind} «${String(data.text || '').slice(0, 60)}»`);
|
|
700
941
|
if (['none', 'browser'].includes(kind)) return json(501, { error: 'browser voice' });
|
|
942
|
+
data.text = stripMarkdown(data.text);
|
|
701
943
|
try {
|
|
702
944
|
if (kind === 'local') {
|
|
703
945
|
const { audio, contentType } = await synthesizeLocal(stripSpeechTags(data.text).slice(0, 600), { lang });
|
|
704
946
|
return res.writeHead(200, { 'Content-Type': contentType }).end(audio);
|
|
705
947
|
}
|
|
706
|
-
const {
|
|
707
|
-
// the identity's voice id/model belong to its own provider: not sent to another (an ElevenLabs id means nothing to Fish)
|
|
708
|
-
const iv = identity.voice || {};
|
|
709
|
-
const voice = voiceFor(kind);
|
|
710
|
-
// process.env too: XAI_TTS_VOICE, FISH_VOICE_ID, APUCHAT_VOICE_URL… (the keys still come from env())
|
|
711
|
-
const { audio, contentType } = await synthesize({ text: String(data.text || '').slice(0, 600), voice, env: { ...process.env, ...env() } });
|
|
948
|
+
const { audio, contentType } = await voiceAudio(kind, String(data.text || '').slice(0, 600), voiceFor(kind));
|
|
712
949
|
return res.writeHead(200, { 'Content-Type': contentType }).end(audio);
|
|
713
950
|
} catch (e) {
|
|
714
951
|
return json(e.status || 502, { error: e.message });
|
|
@@ -719,28 +956,68 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
719
956
|
const kind = String(data.kind || '');
|
|
720
957
|
if (!VOICE_PROVIDERS.includes(kind)) return json(400, { error: 'kind' });
|
|
721
958
|
try {
|
|
722
|
-
const { synthesize } = await import('../../server/tts.mjs');
|
|
723
959
|
const over = Object.fromEntries(['voiceId', 'model', 'style'].map((f) => [f, String(data[f] ?? '').trim().slice(0, 600)]));
|
|
724
960
|
const text = String(data.text || '').trim().slice(0, 300) || ({ es: `Hola, soy ${identity.name}. ¿Así me quieres oír?`, pt: `Oi, eu sou ${identity.name}. Quer me ouvir assim?` }[lang] || `Hi, I'm ${identity.name}. Is this how you want me to sound?`);
|
|
725
|
-
const { audio, contentType } = await
|
|
961
|
+
const { audio, contentType } = await voiceAudio(kind, text, { ...voiceFor(kind), ...over });
|
|
726
962
|
return res.writeHead(200, { 'Content-Type': contentType }).end(audio);
|
|
727
963
|
} catch (e) {
|
|
728
964
|
return json(e.status || 502, { error: e.message });
|
|
729
965
|
}
|
|
730
966
|
}
|
|
967
|
+
if (p === '/senses') return json(200, senses.ingest(data.events || data));
|
|
968
|
+
if (p === '/senses/vendor') {
|
|
969
|
+
// downloads the camera's models once (~13 MB, from jsDelivr and Google), checked by hash
|
|
970
|
+
if (!vendorStatus().ready && !vendorStatus().busy) ensureVendor(log).catch((e) => log(`senses vendor: ${e.message}`));
|
|
971
|
+
return json(200, vendorStatus());
|
|
972
|
+
}
|
|
973
|
+
if (p === '/senses/baseline') return json(200, { ok: senses.setBaseline(data.baseline ?? null) });
|
|
974
|
+
if (p === '/senses/gestures') return json(200, senses.setGestures(data));
|
|
975
|
+
if (p === '/senses/rules') {
|
|
976
|
+
try {
|
|
977
|
+
const id = String(data.id || '');
|
|
978
|
+
if (data.action === 'add') return json(200, { rule: senses.addRule(data.rule || {}) });
|
|
979
|
+
if (data.action === 'remove') return json(200, { ok: senses.removeRule(id) });
|
|
980
|
+
if (['accept', 'reject', 'on', 'off'].includes(data.action)) return json(200, { rule: senses.setRule(id, { status: ['accept', 'on'].includes(data.action) ? 'active' : 'off' }) });
|
|
981
|
+
if (data.action === 'set') return json(200, { rule: senses.setRule(id, data.rule || {}) });
|
|
982
|
+
return json(400, { error: 'action' });
|
|
983
|
+
} catch (e) {
|
|
984
|
+
return json(400, { error: e.message });
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
if (p === '/senses/forget') return json(200, { ok: senses.forget() });
|
|
988
|
+
if (p === '/senses/pause') {
|
|
989
|
+
if (data.resume) {
|
|
990
|
+
const next = loadConfig();
|
|
991
|
+
next.senses = { ...next.senses, pausedUntil: 0 };
|
|
992
|
+
saveConfig(next);
|
|
993
|
+
config = loadConfig();
|
|
994
|
+
return json(200, { pausedUntil: 0 });
|
|
995
|
+
}
|
|
996
|
+
return json(200, { pausedUntil: senses.pause(data.min) });
|
|
997
|
+
}
|
|
998
|
+
if (p === '/senses/snap') {
|
|
999
|
+
const done = snaps.get(String(data.id || ''));
|
|
1000
|
+
const ok = done && /^data:image\/jpeg;base64,[\w+/=]+$/.test(String(data.image || ''));
|
|
1001
|
+
if (ok) done(data.image);
|
|
1002
|
+
return json(200, { ok: Boolean(ok) });
|
|
1003
|
+
}
|
|
1004
|
+
if (p === '/senses/reflect') return json(200, (await senses.reflect({ force: true })) || { say: '', rule: null });
|
|
731
1005
|
if (p === '/ask') {
|
|
732
1006
|
const text = String(data.text || '').trim().slice(0, 800);
|
|
733
1007
|
if (!text) return json(400, { error: 'text' });
|
|
734
1008
|
chatUntil = Date.now() + CHAT_QUIET;
|
|
735
1009
|
broadcast({ thinking: true, activity: track({ type: 'prompt', text }) });
|
|
736
|
-
const r = await assistant.ask(text);
|
|
1010
|
+
const r = (await lookAt(text)) || (await assistant.ask(text));
|
|
737
1011
|
lastSpoke = Date.now();
|
|
738
1012
|
chatUntil = Date.now() + CHAT_QUIET;
|
|
739
|
-
broadcast({ thinking: false, stir: pet.asleep, say: r.reply, gesture: r.actions.length ? 'nod' : null, point: r.actions.some((a) => a.type === 'open') ? 'browser' : null });
|
|
740
|
-
|
|
1013
|
+
broadcast({ thinking: false, stir: pet.asleep, say: r.reply, photo: r.photo, gesture: r.actions.length ? 'nod' : null, point: r.actions.some((a) => a.type === 'open') ? 'browser' : null });
|
|
1014
|
+
const { photo, ...out } = r; // the frame went to the pet page only
|
|
1015
|
+
return json(200, out);
|
|
741
1016
|
}
|
|
742
1017
|
if (p === '/config') {
|
|
743
1018
|
const bad = applySettings(data);
|
|
1019
|
+
// the "share tools" switch is also the plaza's: tell 7ots.com (it deletes what was sent when it goes off)
|
|
1020
|
+
if (!bad && typeof data?.access?.prowl === 'boolean') cloudPlaza(config, { method: 'POST', body: { tools: data.access.prowl } }).catch(() => {});
|
|
744
1021
|
return bad ? json(400, { error: bad }) : json(200, settingsView());
|
|
745
1022
|
}
|
|
746
1023
|
if (p === '/config/test') {
|
|
@@ -752,7 +1029,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
752
1029
|
broadcast({ say: text, gesture: 'wave' });
|
|
753
1030
|
return json(200, { ok: true, text, ms: Date.now() - t0 });
|
|
754
1031
|
} catch (e) {
|
|
755
|
-
return json(200, { ok: false, error: e.message, ms: Date.now() - t0 });
|
|
1032
|
+
return json(200, { ok: false, error: e.message, ...(e.code ? { code: e.code } : {}), ms: Date.now() - t0 });
|
|
756
1033
|
}
|
|
757
1034
|
}
|
|
758
1035
|
if (p === '/screen/look') return json(200, { seen: config.access.screen ? await watcher.look({ force: true }) : null, enabled: config.access.screen });
|
|
@@ -888,7 +1165,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
888
1165
|
}
|
|
889
1166
|
}
|
|
890
1167
|
if (p === '/orquesta/connect') {
|
|
891
|
-
const r = connectOrquesta();
|
|
1168
|
+
const r = connectOrquesta({ local: data?.local === true });
|
|
892
1169
|
r.catch((e) => log(`orquesta: ${e.message}`));
|
|
893
1170
|
return json(200, { ok: true });
|
|
894
1171
|
}
|
|
@@ -910,7 +1187,10 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
910
1187
|
if (kind === 'elevenlabs') {
|
|
911
1188
|
if (!keys.ELEVENLABS_API_KEY) return json(400, { error: 'key' });
|
|
912
1189
|
const r = await fetch('https://api.elevenlabs.io/v1/voices', { headers: { 'xi-api-key': keys.ELEVENLABS_API_KEY }, signal: AbortSignal.timeout(15000) });
|
|
913
|
-
if (!r.ok)
|
|
1190
|
+
if (!r.ok) {
|
|
1191
|
+
const { providerError } = await import('../../server/tts.mjs');
|
|
1192
|
+
return json(502, { error: providerError('ElevenLabs', r.status, await r.text().catch(() => '')).message });
|
|
1193
|
+
}
|
|
914
1194
|
const j = await r.json();
|
|
915
1195
|
return json(200, { voices: (j.voices || []).map((v) => ({ id: v.voice_id, name: v.name, note: [v.category, v.labels?.accent, v.labels?.gender, v.labels?.age].filter(Boolean).join(' · '), preview: v.preview_url || '' })) });
|
|
916
1196
|
}
|
|
@@ -934,7 +1214,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
|
|
|
934
1214
|
const cur = config.character || {};
|
|
935
1215
|
const KEYS = ['backstory', 'style', 'quirks', 'scenario', 'greeting', 'examples'];
|
|
936
1216
|
const who = { name: identity.name, role: identity.role, tagline: identity.tagline, bio: identity.bio, tone: identity.personality?.tone, traits: identity.personality?.traits, look: (identity.look?.character?.mods || []).map((m) => m.id) };
|
|
937
|
-
const L = ['es', 'en', 'pt'].includes(data.lang) ? data.lang : lang;
|
|
1217
|
+
const L = ['es', 'en', 'pt', 'zh', 'hi'].includes(data.lang) ? data.lang : lang;
|
|
938
1218
|
const LN = { es: 'Spanish (español)', pt: 'Brazilian Portuguese (português)', en: 'English' }[L];
|
|
939
1219
|
const FIELDS = {
|
|
940
1220
|
backstory: 'backstory (4-6 sentences: where it comes from, what it wants, what it fears)',
|
|
@@ -988,6 +1268,22 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
988
1268
|
return json(e.status === 400 ? 400 : 502, { error: e.message });
|
|
989
1269
|
}
|
|
990
1270
|
}
|
|
1271
|
+
if (p === '/aura') {
|
|
1272
|
+
// farmeo de aura: otra cosa que los bailes, con su música (phonk/montagem, o tus temas en ~/.7ots/music/aura) y su contador
|
|
1273
|
+
const file = homeFile('aura.json');
|
|
1274
|
+
const st = { total: 0, count: 0, best: 0, ...readJson(file) };
|
|
1275
|
+
const name = AURA_MOVES.includes(data.name) ? data.name : AURA_MOVES[Math.floor(Math.random() * AURA_MOVES.length)];
|
|
1276
|
+
const points = AURA_POINTS[Math.floor(Math.random() * AURA_POINTS.length)];
|
|
1277
|
+
Object.assign(st, { total: st.total + points, count: st.count + 1, best: Math.max(st.best, points) });
|
|
1278
|
+
writeJson(file, st);
|
|
1279
|
+
const vol = Math.max(0, Math.min(1, Number(config.pet.musicVol ?? 0.5)));
|
|
1280
|
+
const files = auraFiles();
|
|
1281
|
+
const music = data.music === false || config.pet.music === 'off' ? null : files.length ? { file: files[Math.floor(Math.random() * files.length)], vol } : { style: AURA_STYLE[name], vol };
|
|
1282
|
+
const aura = { name, ms: 8000, music, points, total: st.total };
|
|
1283
|
+
broadcast({ aura });
|
|
1284
|
+
log(`aura: ${name} +${points} (${st.total})${music ? ` ♪ ${music.file || music.style}` : ''}`);
|
|
1285
|
+
return json(200, { ok: true, name, points, total: st.total });
|
|
1286
|
+
}
|
|
991
1287
|
if (p === '/dance' || p === '/entrance') {
|
|
992
1288
|
const dance = musicFor(data);
|
|
993
1289
|
if (p === '/dance') broadcast({ dance });
|
|
@@ -1022,12 +1318,13 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1022
1318
|
name: identity.name,
|
|
1023
1319
|
lang,
|
|
1024
1320
|
visitor: !!process.env.SEVENOTS_COMPANION, // a visiting ot: the host's settings rule shared things (scenes)
|
|
1025
|
-
config: { brain: config.brain, pet: { ...config.pet, scenes: sceneConf() }, access: config.access, voice: config.voice, screen: config.screen, memory: config.memory },
|
|
1321
|
+
config: { brain: config.brain, pet: { ...config.pet, scenes: sceneConf() }, access: config.access, voice: config.voice, screen: config.screen, memory: config.memory, senses: config.senses },
|
|
1026
1322
|
brain: brainLabel(config.brain),
|
|
1027
1323
|
clis: detectClis(),
|
|
1028
1324
|
stt: sttProvider(keys),
|
|
1029
1325
|
voice: config.voice,
|
|
1030
|
-
|
|
1326
|
+
wake: wake.status(),
|
|
1327
|
+
voices: { local: localVoices(), keys: { elevenlabs: Boolean(keys.ELEVENLABS_API_KEY), openai: Boolean(keys.OPENAI_API_KEY), apuchat: Boolean(keys.APUCHAT_VOICE_TOKEN), apuchatCloud: Boolean(keys.SEVENOTS_TOKEN && config.account?.otsId), grok: Boolean(keys.XAI_API_KEY), fish: Boolean(keys.FISH_API_KEY) } },
|
|
1031
1328
|
uiLang: uiLangOf(config, lang),
|
|
1032
1329
|
configLang: config.lang || '',
|
|
1033
1330
|
otLook: identity.look?.character || null,
|
|
@@ -1044,6 +1341,7 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1044
1341
|
vision: Boolean(brain.vision),
|
|
1045
1342
|
allClis: Object.keys(AI_CLIS),
|
|
1046
1343
|
keys: Object.fromEntries(SETTABLE_KEYS.map((k) => [k, Boolean(keys[k])])),
|
|
1344
|
+
orquestaLoginAt,
|
|
1047
1345
|
home: { kind: config.home.kind, url: Boolean(config.home.url) },
|
|
1048
1346
|
reminders: assistant.reminders,
|
|
1049
1347
|
notes: assistant.notes,
|
|
@@ -1113,6 +1411,13 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1113
1411
|
const n = Math.round(Number(d.memory.tokens)) || 0;
|
|
1114
1412
|
next.memory.tokens = n <= 0 ? 0 : Math.max(2000, Math.min(200000, n));
|
|
1115
1413
|
}
|
|
1414
|
+
if (d.senses && typeof d.senses === 'object') {
|
|
1415
|
+
const n = d.senses;
|
|
1416
|
+
if (typeof n.arm === 'boolean') next.senses.arm = n.arm;
|
|
1417
|
+
if (typeof n.reflect === 'boolean') next.senses.reflect = n.reflect;
|
|
1418
|
+
if (n.holdMs !== undefined) next.senses.holdMs = Math.max(200, Math.min(3000, Math.round(Number(n.holdMs)) || 600));
|
|
1419
|
+
if (n.fps !== undefined) next.senses.fps = Math.max(1, Math.min(15, Math.round(Number(n.fps)) || 5));
|
|
1420
|
+
}
|
|
1116
1421
|
if (d.screen?.every !== undefined) next.screen.every = Math.max(1, Math.min(60, Math.round(Number(d.screen.every)) || 5));
|
|
1117
1422
|
let reload = false;
|
|
1118
1423
|
if (d.voice) {
|
|
@@ -1121,6 +1426,7 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1121
1426
|
reload = vk !== next.voice.kind;
|
|
1122
1427
|
next.voice = { ...next.voice, kind: vk };
|
|
1123
1428
|
if (d.voice.expressive !== undefined) next.voice.expressive = !!d.voice.expressive;
|
|
1429
|
+
if (d.voice.wake !== undefined) next.voice.wake = !!d.voice.wake;
|
|
1124
1430
|
// each provider's own voice, model and style ({ elevenlabs: { voiceId, model }, openai: { voiceId, model, style } … })
|
|
1125
1431
|
const pv = d.voice.providers;
|
|
1126
1432
|
if (pv && typeof pv === 'object') {
|
|
@@ -1137,7 +1443,7 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1137
1443
|
}
|
|
1138
1444
|
if (d.keys) {
|
|
1139
1445
|
for (const [k, v] of Object.entries(d.keys)) {
|
|
1140
|
-
if (!SETTABLE_KEYS.includes(k) || typeof v !== 'string' || v.length > 400) return 'key';
|
|
1446
|
+
if (!SETTABLE_KEYS.includes(k) || typeof v !== 'string' || v.length > (k === 'SENSES_ICS_URL' ? 2000 : 400)) return 'key';
|
|
1141
1447
|
saveKey(k, v.trim()); // '' removes it
|
|
1142
1448
|
}
|
|
1143
1449
|
}
|
|
@@ -1146,6 +1452,7 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1146
1452
|
annoy = annoyOf(config);
|
|
1147
1453
|
brainImpl = createBrain(config.brain, config.home);
|
|
1148
1454
|
if (config.voice.kind === 'local') warmLocal();
|
|
1455
|
+
wakeConf();
|
|
1149
1456
|
if (reload) setTimeout(() => broadcast({ reload: true }), 100); // the page reads its voice at load
|
|
1150
1457
|
// 2D ↔ 3D: open pet windows switch now (the page, or the desktop shell when it needs the GPU back on).
|
|
1151
1458
|
if ((config.pet.backdrop !== false) !== bdWas) setTimeout(() => broadcast({ backdrop: config.pet.backdrop !== false }), 100);
|
|
@@ -1161,7 +1468,7 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1161
1468
|
// The new one retries the port while this one lets go of it.
|
|
1162
1469
|
stop(() => {
|
|
1163
1470
|
const out = openSync(homeFile('pet.log'), 'a');
|
|
1164
|
-
spawn(process.execPath, [join(PKG_ROOT, 'cli', '7ots.mjs'), 'pet', '--daemon'], { detached: true, stdio: ['ignore', out, out], env: { ...process.env, SEVENOTS_PORT_WAIT: '1' } }).unref();
|
|
1471
|
+
spawn(process.execPath, [join(PKG_ROOT, 'cli', '7ots.mjs'), 'pet', '--daemon'], { detached: true, windowsHide: true, stdio: ['ignore', out, out], env: { ...process.env, SEVENOTS_PORT_WAIT: '1' } }).unref();
|
|
1165
1472
|
});
|
|
1166
1473
|
}
|
|
1167
1474
|
|
|
@@ -1171,6 +1478,8 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1171
1478
|
clearTimeout(syncFirst);
|
|
1172
1479
|
clearTimeout(syncSoon);
|
|
1173
1480
|
assistant.stop();
|
|
1481
|
+
senses.stop();
|
|
1482
|
+
wake.stop();
|
|
1174
1483
|
watchers.stop();
|
|
1175
1484
|
stopWatch();
|
|
1176
1485
|
savePet(pet);
|
|
@@ -1187,6 +1496,8 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
|
|
|
1187
1496
|
server.listen(port, '127.0.0.1', () => {
|
|
1188
1497
|
log(`pet ${identity.name} on http://127.0.0.1:${port}`);
|
|
1189
1498
|
setTimeout(() => onEvent({ type: 'start' }), 1500);
|
|
1499
|
+
wakeConf();
|
|
1500
|
+
if (sttProvider(env()) === 'local') warmStt();
|
|
1190
1501
|
resolve({ port, token, identity, stop, onEvent });
|
|
1191
1502
|
});
|
|
1192
1503
|
});
|