@7ots/cli 0.1.19 → 0.1.37
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/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 +59 -1
- package/cli/lib/account.mjs +23 -3
- package/cli/lib/assistant.mjs +88 -13
- package/cli/lib/brain.mjs +76 -8
- 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 +61 -6
- package/cli/lib/pet-server.mjs +316 -41
- package/cli/lib/prompts.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/vm.mjs +1 -1
- package/cli/lib/wake-local.py +109 -0
- package/cli/lib/wake.mjs +102 -0
- package/cli/pet/electron/main.cjs +145 -16
- package/cli/pet/pet.html +127 -27
- package/cli/pet/senses.html +342 -0
- package/cli/pet/settings.html +787 -86
- package/dist/7ots.esm.js +374 -146
- package/dist/7ots.esm.js.map +4 -4
- package/dist/7ots.iife.js +374 -146
- package/dist/7ots.iife.js.map +4 -4
- package/llms.txt +27 -0
- package/package.json +5 -2
- package/server/channels/apuchat.mjs +2 -0
- package/server/errors.mjs +90 -0
- package/server/notify.mjs +78 -0
- package/server/server.mjs +68 -12
- 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 +1 -1
- 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 +162 -0
- 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 +9 -3
- 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 +255 -1
- 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 +10 -2
- package/src/voice/tags.js +22 -0
- package/server/platform/apuchat.mjs +0 -266
- package/server/platform/auth.mjs +0 -337
- package/server/platform/byte.mjs +0 -291
- package/server/platform/connect.mjs +0 -391
- package/server/platform/crypto.mjs +0 -80
- package/server/platform/db.mjs +0 -293
- package/server/platform/device.mjs +0 -247
- 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 -611
- package/server/platform/profile.mjs +0 -182
- package/server/platform/routes.mjs +0 -589
- package/server/platform/runtime.mjs +0 -286
- package/server/platform/sites.mjs +0 -146
- package/server/platform/stage3d.mjs +0 -82
- package/server/platform/store.mjs +0 -469
- package/server/platform/vm.mjs +0 -1057
- package/server/platform/wallet.mjs +0 -255
|
@@ -1,589 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rutas de la plataforma 7ots.com (PLATFORM=true).
|
|
3
|
-
*
|
|
4
|
-
* Públicas, una API de agente por ots (el widget las llama igual que /api/agent/*):
|
|
5
|
-
* GET /api/o/:id/config · /embed.js · /identity · /identity.vcf · /portrait.svg · /3d (cualquier origen)
|
|
6
|
-
* POST /api/o/:id/chat · /tts · /identity/call · /contact/* (solo desde sus dominios)
|
|
7
|
-
*
|
|
8
|
-
* Dashboard (sesión de /auth/*; escrituras con X-7ots-Admin: 1 y mismo origen):
|
|
9
|
-
* GET /api/platform/me
|
|
10
|
-
* GET /api/platform/ots POST (crear)
|
|
11
|
-
* GET /api/platform/ots/:id PATCH { name, status, domains } · DELETE
|
|
12
|
-
* POST /api/platform/ots/:id/duplicate
|
|
13
|
-
* GET /api/platform/ots/:id/conversations[?before] GET|DELETE …/conversations/:cid
|
|
14
|
-
* GET /api/platform/ots/:id/usage
|
|
15
|
-
* * /api/platform/ots/:id/admin/* misma forma que /api/agent/admin/* (el backoffice
|
|
16
|
-
* edita un ots con ?ots=<id>)
|
|
17
|
-
* * /api/mods, /api/platform/mods/*, /api/device/mods/* community mods (mods.mjs)
|
|
18
|
-
* GET /api/platform/sites POST { kind, url, name, guide } · POST …/:id/verify · DELETE …/:id (sites.mjs)
|
|
19
|
-
* GET /api/platform/device/:code · POST { approve } GET /api/platform/devices · DELETE …/:id
|
|
20
|
-
*
|
|
21
|
-
* GET /api/platform/ots/:id/vm POST …/vm/enroll · DELETE …/vm (vm.mjs)
|
|
22
|
-
* GET /api/platform/ots/:id/byte · POST …/byte/connect|play|stop · DELETE …/byte (byte.mjs)
|
|
23
|
-
* GET /api/platform/ots/:id/wallet POST …/wallet/payments/:pid/approve|decline|refresh (wallet.mjs)
|
|
24
|
-
*
|
|
25
|
-
* Desktop pet signed in with `7ots login` (Authorization: Bearer 7d_…): /api/device/* — see device.mjs
|
|
26
|
-
* (…/ots/:id/vm[/jobs…]: the offload channel to the ot's worker, vm.mjs)
|
|
27
|
-
* Worker on the ot's own server (Authorization: Bearer 7vm_…): /api/vm/* — see vm.mjs
|
|
28
|
-
* apuchat identity and Orquesta tasks (…/apuchat/*, …/orquesta/*, /auth/apuchat|orquesta): see connect.mjs
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import { createReadStream, existsSync, statSync } from 'node:fs';
|
|
32
|
-
import { join } from 'node:path';
|
|
33
|
-
import { MEET_AVATARS, MEET_SCENES, OPENAI_VOICES, GROK_VOICES, defineIdentity, identityPrompt, publicIdentity, toVCard } from '../identity.mjs';
|
|
34
|
-
import { errorText, reqT, requestLocale } from '../i18n.mjs';
|
|
35
|
-
import { dataDir, monthOf } from './db.mjs';
|
|
36
|
-
import { randomIdentity, cleanSeed } from '../../src/identity/random.js';
|
|
37
|
-
import { currentAccount } from './auth.mjs';
|
|
38
|
-
import {
|
|
39
|
-
OTS_KEYS, MAX_OTS_PER_ACCOUNT, accountUsage, addUsage, cleanDomains, countOts, createOts, withFreeLook, lookTaken, deleteConversation, deleteOts, duplicateOts,
|
|
40
|
-
getConversation, getOts, getOwnOts, listConversations, listOts, logTurn, originAllowed, publicAccount, updateOts, usageByOts, usageHistory,
|
|
41
|
-
} from './store.mjs';
|
|
42
|
-
import { freeMessages, freeTts, otsChannels, otsEnv, otsLlmInfo, otsStep, otsSynthesize, otsTtsProvider, platformLlmEnv, stopOtsChannels } from './runtime.mjs';
|
|
43
|
-
import { createConnect } from './connect.mjs';
|
|
44
|
-
import { createDevice, deviceFromBearer } from './device.mjs';
|
|
45
|
-
import { createVm } from './vm.mjs';
|
|
46
|
-
import { createSites } from './sites.mjs';
|
|
47
|
-
import { portraitOf, profilePage } from './profile.mjs';
|
|
48
|
-
import { stage3dHeaders, stage3dPage } from './stage3d.mjs';
|
|
49
|
-
import { orquestaAccountView, orquestaUrl } from './orquesta.mjs';
|
|
50
|
-
import { createMods } from './mods.mjs';
|
|
51
|
-
import { createWallet } from './wallet.mjs';
|
|
52
|
-
import { createByte } from './byte.mjs';
|
|
53
|
-
import '../../src/i18n/messages/platform.js';
|
|
54
|
-
|
|
55
|
-
const penv = process.env;
|
|
56
|
-
const OTS_RATE = () => Number(penv.PLATFORM_OTS_RATE_PER_MIN || 120);
|
|
57
|
-
const OTS_DAILY = () => Number(penv.PLATFORM_OTS_DAILY_LIMIT || 1000);
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @param {object} deps helpers HTTP de server.mjs
|
|
61
|
-
*/
|
|
62
|
-
export function createPlatform({ send, readJson, rateLimit, callLimit, originOf, embedScript, bundleVersion, relay, sendApumail, startApuchat }) {
|
|
63
|
-
const selfOrigins = (req) => new Set([originOf(req), penv.PLATFORM_URL && new URL(penv.PLATFORM_URL).origin].filter(Boolean));
|
|
64
|
-
|
|
65
|
-
// ───────────────────────────── API pública de cada ots ─────────────────────────────
|
|
66
|
-
|
|
67
|
-
const otsBuckets = new Map();
|
|
68
|
-
function otsRate(id) {
|
|
69
|
-
const now = Date.now();
|
|
70
|
-
const rate = OTS_RATE();
|
|
71
|
-
const b = otsBuckets.get(id) || { tokens: rate, at: now };
|
|
72
|
-
b.tokens = Math.min(rate, b.tokens + ((now - b.at) / 60000) * rate);
|
|
73
|
-
b.at = now;
|
|
74
|
-
if (b.tokens < 1) return false;
|
|
75
|
-
b.tokens -= 1;
|
|
76
|
-
otsBuckets.set(id, b);
|
|
77
|
-
if (otsBuckets.size > 10000) otsBuckets.clear();
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Paid calls (chat, voice) per ot and day: Origin can be forged by scripts, so this caps what anyone can spend. */
|
|
82
|
-
const otsDays = new Map(); // ots.id → { day, n }
|
|
83
|
-
function otsDaily(id) {
|
|
84
|
-
const day = new Date().toISOString().slice(0, 10);
|
|
85
|
-
const d = otsDays.get(id);
|
|
86
|
-
const cur = d?.day === day ? d : { day, n: 0 };
|
|
87
|
-
if (cur.n >= OTS_DAILY()) return false;
|
|
88
|
-
cur.n += 1;
|
|
89
|
-
otsDays.set(id, cur);
|
|
90
|
-
if (otsDays.size > 20000) otsDays.clear();
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// An ot whose account connected Orquesta lends it its voice (Settings → Identity → Face & voice
|
|
95
|
-
// there): Orquesta's origin — and meet, where that agent talks on calls (it announces
|
|
96
|
-
// `[voice]7ots:<id>`) — may use /tts without being typed into the ot's domains. Only /tts —
|
|
97
|
-
// the brain stays Orquesta's, so /chat still needs the domain.
|
|
98
|
-
const ORQUESTA_VOICE_HOSTS = ['meet.apuchat.com'];
|
|
99
|
-
function orquestaVoice(ots, origin, path) {
|
|
100
|
-
if (path !== '/tts') return false;
|
|
101
|
-
try {
|
|
102
|
-
const u = new URL(origin);
|
|
103
|
-
const o = new URL(orquestaUrl());
|
|
104
|
-
const hosts = [o.hostname, `www.${o.hostname}`, ...ORQUESTA_VOICE_HOSTS];
|
|
105
|
-
if (u.protocol !== 'https:' || !hosts.includes(u.hostname)) return false;
|
|
106
|
-
} catch {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
return orquestaAccountView(ots.accountId).connected;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function otsCors(req, res, ots, path) {
|
|
113
|
-
const origin = req.headers.origin;
|
|
114
|
-
if (!origin) return false; // el widget siempre manda Origin; sin él no se sirve la IA
|
|
115
|
-
// From 7ots.com itself only the owner's preview (with their session) may use the ot.
|
|
116
|
-
const self = selfOrigins(req).has(origin);
|
|
117
|
-
if (self ? currentAccount(req)?.id !== ots.accountId : !originAllowed(ots, origin) && !orquestaVoice(ots, origin, path)) return false;
|
|
118
|
-
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
119
|
-
res.setHeader('Vary', 'Origin');
|
|
120
|
-
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
121
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, X-Site-Key, Accept, Accept-Language');
|
|
122
|
-
res.setHeader('Access-Control-Max-Age', '600');
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async function publicApi(req, res, id, path) {
|
|
127
|
-
const t = reqT(req);
|
|
128
|
-
const ots = getOts(id);
|
|
129
|
-
const open = ['/config', '/embed.js', '/identity', '/identity.vcf', '/traits.json', '/portrait.svg', '/3d'].includes(path);
|
|
130
|
-
if (open) {
|
|
131
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
132
|
-
if (req.method === 'OPTIONS') return send(res, 204);
|
|
133
|
-
if (req.method !== 'GET' && req.method !== 'HEAD') return send(res, 405, { error: t('server.http.methodNotAllowed') });
|
|
134
|
-
if (!ots) return send(res, 404, { error: t('platform.api.notFound') });
|
|
135
|
-
if (path === '/config') return send(res, 200, ots.widget);
|
|
136
|
-
if (path === '/embed.js') {
|
|
137
|
-
res.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'no-cache' });
|
|
138
|
-
if (ots.status !== 'on') return res.end('/* 7ots: ots en pausa */');
|
|
139
|
-
return res.end(embedScript(ots.widget, await bundleVersion(), `/api/o/${ots.id}`));
|
|
140
|
-
}
|
|
141
|
-
if (path === '/3d') {
|
|
142
|
-
res.writeHead(200, stage3dHeaders());
|
|
143
|
-
return res.end(req.method === 'HEAD' ? undefined : stage3dPage());
|
|
144
|
-
}
|
|
145
|
-
if (path === '/traits.json') return send(res, 200, traitsMeta(ots, `${originOf(req)}/api/o/${ots.id}`));
|
|
146
|
-
const card = publicIdentity(ots.identity, otsChannels(ots).live());
|
|
147
|
-
if (path === '/portrait.svg') {
|
|
148
|
-
const pic = portraitOf(card);
|
|
149
|
-
if (pic.redirect) {
|
|
150
|
-
res.writeHead(302, { Location: pic.redirect, 'Cache-Control': 'public, max-age=300' });
|
|
151
|
-
return res.end();
|
|
152
|
-
}
|
|
153
|
-
res.writeHead(200, {
|
|
154
|
-
'Content-Type': 'image/svg+xml; charset=utf-8',
|
|
155
|
-
'Cache-Control': 'public, max-age=300',
|
|
156
|
-
'X-Content-Type-Options': 'nosniff',
|
|
157
|
-
// Opened directly as a document, it still runs nothing.
|
|
158
|
-
'Content-Security-Policy': "default-src 'none'; style-src 'unsafe-inline'",
|
|
159
|
-
});
|
|
160
|
-
return res.end(pic.svg);
|
|
161
|
-
}
|
|
162
|
-
if (path === '/identity.vcf') {
|
|
163
|
-
res.writeHead(200, { 'Content-Type': 'text/vcard; charset=utf-8', 'Content-Disposition': `inline; filename="${card.id}.vcf"`, 'Cache-Control': 'no-cache' });
|
|
164
|
-
return res.end(toVCard(card, { baseUrl: `${originOf(req)}/api/o/${ots.id}/identity.vcf` }));
|
|
165
|
-
}
|
|
166
|
-
// A person opening the link sees the ot's card; agents and the card itself (Accept: */* or JSON) get the JSON.
|
|
167
|
-
res.setHeader('Vary', 'Accept');
|
|
168
|
-
if (/text\/html/.test(req.headers.accept || '') && !/[?&]format=json\b/.test(req.url)) {
|
|
169
|
-
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-cache' });
|
|
170
|
-
const ep = `${originOf(req)}/api/o/${ots.id}`;
|
|
171
|
-
return res.end(profilePage(card, traitsMeta(ots, ep), ep, requestLocale(req)));
|
|
172
|
-
}
|
|
173
|
-
return send(res, 200, card);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (!ots) return send(res, 404, { error: t('platform.api.notFound') });
|
|
177
|
-
if (!otsCors(req, res, ots, path)) return send(res, 403, { error: t('platform.api.originNotAllowed') });
|
|
178
|
-
if (req.method === 'OPTIONS') return send(res, 204);
|
|
179
|
-
if (req.method !== 'POST') return send(res, 405, { error: t('server.http.methodNotAllowed') });
|
|
180
|
-
if (ots.status !== 'on') return send(res, 403, { error: t('platform.api.paused') });
|
|
181
|
-
if (!rateLimit(req)) return send(res, 429, { error: t('server.http.rateLimited') });
|
|
182
|
-
if (!otsRate(ots.id)) return send(res, 429, { error: t('platform.api.otsRateLimited') });
|
|
183
|
-
if ((path === '/chat' || path === '/tts') && !otsDaily(ots.id)) return send(res, 429, { error: t('platform.api.otsDailyLimit') });
|
|
184
|
-
|
|
185
|
-
if (path === '/chat') {
|
|
186
|
-
const { system, messages, tools = [], session } = await readJson(req, 1024 * 1024);
|
|
187
|
-
if (typeof system !== 'string' || !Array.isArray(messages) || !messages.length || !Array.isArray(tools)) return send(res, 400, { error: t('server.http.badRequest') });
|
|
188
|
-
if (messages.length > 300 || tools.length > 128 || system.length > 30000) return send(res, 413, { error: t('server.http.tooLarge') });
|
|
189
|
-
const pre = [ots.settings.SERVER_INSTRUCTIONS, identityPrompt(ots.identity)].filter(Boolean).join('\n\n');
|
|
190
|
-
let out;
|
|
191
|
-
try {
|
|
192
|
-
out = await otsStep(ots, { system: `${pre}\n\n${system}`, messages, tools, locale: requestLocale(req) });
|
|
193
|
-
} catch (e) {
|
|
194
|
-
// Sin cupo: el visitante ve un aviso normal en el chat, no un error.
|
|
195
|
-
if (e.status !== 402) throw e;
|
|
196
|
-
out = { text: errorText(e, t), toolCalls: [], finishReason: 'quota', provider: '7ots' };
|
|
197
|
-
}
|
|
198
|
-
const last = messages[messages.length - 1];
|
|
199
|
-
const key = typeof session === 'string' && /^[\w-]{8,64}$/.test(session) ? session : null;
|
|
200
|
-
if (key) {
|
|
201
|
-
const seen = last?.role === 'user' ? visibleTurn(last.content) : { text: '', page: '' };
|
|
202
|
-
const { created } = logTurn(ots, { key, page: seen.page, origin: req.headers.origin || '', user: seen.text, reply: out.text || '' });
|
|
203
|
-
if (created) addUsage(ots, 'conversation');
|
|
204
|
-
}
|
|
205
|
-
return send(res, 200, out);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (path === '/tts') {
|
|
209
|
-
const { text } = await readJson(req, 16 * 1024);
|
|
210
|
-
const { audio, contentType } = await otsSynthesize(ots, { text });
|
|
211
|
-
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': audio.length, 'Cache-Control': 'no-store' });
|
|
212
|
-
return res.end(audio);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (path === '/identity/call') {
|
|
216
|
-
if (!callLimit(req)) return send(res, 429, { error: t('server.http.callLimited') });
|
|
217
|
-
const { motivo } = await readJson(req, 4 * 1024);
|
|
218
|
-
const call = await otsChannels(ots).openCall({ reason: String(motivo || '').slice(0, 200) });
|
|
219
|
-
addUsage(ots, 'call');
|
|
220
|
-
return send(res, 200, { call_url: call.call_url, expires_at: call.expires_at });
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const { env } = otsEnv(ots);
|
|
224
|
-
if (path === '/contact/apumail') return send(res, 200, await sendApumail(await readJson(req, 128 * 1024), env));
|
|
225
|
-
if (path === '/contact/apuchat') return send(res, 200, await startApuchat(await readJson(req, 128 * 1024), env));
|
|
226
|
-
if (path === '/contact/apuchat/send') return send(res, 200, await relay.relaySend(await readJson(req, 16 * 1024)));
|
|
227
|
-
if (path === '/contact/apuchat/wait') return send(res, 200, await relay.relayWait(await readJson(req, 4 * 1024)));
|
|
228
|
-
if (path === '/contact/apuchat/end') return send(res, 200, await relay.relayEnd(await readJson(req, 4 * 1024)));
|
|
229
|
-
send(res, 404, { error: t('server.http.unknownRoute') });
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// ───────────────────────────── dashboard ─────────────────────────────
|
|
233
|
-
|
|
234
|
-
function otsSummary(ots, usage = {}) {
|
|
235
|
-
const llm = otsLlmInfo(ots);
|
|
236
|
-
return {
|
|
237
|
-
id: ots.id,
|
|
238
|
-
name: ots.name,
|
|
239
|
-
status: ots.status,
|
|
240
|
-
domains: ots.domains,
|
|
241
|
-
identity: { name: ots.identity.name, role: ots.identity.role, look: ots.identity.look },
|
|
242
|
-
llm: `${llm.name}:${llm.model}`,
|
|
243
|
-
platformLlm: llm.platform,
|
|
244
|
-
tts: otsTtsProvider(ots),
|
|
245
|
-
usage,
|
|
246
|
-
createdAt: ots.createdAt,
|
|
247
|
-
updatedAt: ots.updatedAt,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** Vista de ajustes con la forma de serverView() (el backoffice la pinta igual). */
|
|
252
|
-
function serverViewOf(ots) {
|
|
253
|
-
const values = {};
|
|
254
|
-
const secrets = {};
|
|
255
|
-
for (const [k, meta] of Object.entries(OTS_KEYS)) {
|
|
256
|
-
if (meta.managed) continue;
|
|
257
|
-
if (meta.secret) secrets[k] = { set: !!ots.secrets[k], source: ots.secrets[k] ? 'backoffice' : null, restart: false };
|
|
258
|
-
else values[k] = { value: ots.settings[k] ?? '', source: ots.settings[k] != null ? 'backoffice' : null, restart: false };
|
|
259
|
-
}
|
|
260
|
-
return { values, secrets };
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function statusOf(ots) {
|
|
264
|
-
const ch = otsChannels(ots);
|
|
265
|
-
const { env, platformLlm, platformTts } = otsEnv(ots);
|
|
266
|
-
const llm = otsLlmInfo(ots);
|
|
267
|
-
return {
|
|
268
|
-
llm: `${llm.name}:${llm.model}`,
|
|
269
|
-
tts: otsTtsProvider(ots),
|
|
270
|
-
platform: { llm: platformLlm, tts: platformTts },
|
|
271
|
-
channels: ch.status(),
|
|
272
|
-
live: ch.live(),
|
|
273
|
-
contact: {
|
|
274
|
-
apumail: !!(env.APUMAIL_INBOX && env.APUMAIL_INBOX_TOKEN && env.APUMAIL_TO),
|
|
275
|
-
apuchatOperator: !!(env.APUCHAT_NOTIFIER_IDENTITY_KEY && env.APUCHAT_OPERATOR_HANDLE),
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** Guarda un ots y arranca/para sus canales según haga falta. */
|
|
281
|
-
async function save(ots, patch) {
|
|
282
|
-
const next = updateOts(ots.id, patch);
|
|
283
|
-
if (next.status !== 'on') await stopOtsChannels(next.id);
|
|
284
|
-
else otsChannels(next); // reinicia solo si cambió su configuración de canales
|
|
285
|
-
return next;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
async function adminApi(req, res, ots, route) {
|
|
289
|
-
const t = reqT(req);
|
|
290
|
-
if (route === '/session' && req.method === 'GET') return send(res, 200, { authed: true, mode: 'platform' });
|
|
291
|
-
if (route === '/login' || route === '/logout') return send(res, 400, { error: t('platform.api.login') });
|
|
292
|
-
if (route === '/state' && req.method === 'GET') {
|
|
293
|
-
return send(res, 200, {
|
|
294
|
-
ots: otsSummary(ots),
|
|
295
|
-
identity: ots.identity,
|
|
296
|
-
widget: ots.widget,
|
|
297
|
-
server: serverViewOf(ots),
|
|
298
|
-
status: statusOf(ots),
|
|
299
|
-
options: { meetAvatars: MEET_AVATARS, meetScenes: MEET_SCENES, openaiVoices: OPENAI_VOICES, grokVoices: GROK_VOICES },
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
if (route === '/identity' && req.method === 'PUT') {
|
|
303
|
-
const identity = defineIdentity(await readJson(req, 256 * 1024), ots.identity);
|
|
304
|
-
return send(res, 200, { identity: (await save(ots, { identity })).identity });
|
|
305
|
-
}
|
|
306
|
-
if (route === '/widget' && req.method === 'PUT') {
|
|
307
|
-
const w = await readJson(req, 256 * 1024);
|
|
308
|
-
if (!w || typeof w !== 'object' || Array.isArray(w)) return send(res, 400, { error: t('server.admin.invalidWidget') });
|
|
309
|
-
return send(res, 200, { widget: (await save(ots, { widget: sanitizeWidget(w) })).widget });
|
|
310
|
-
}
|
|
311
|
-
if (route === '/server' && req.method === 'PUT') {
|
|
312
|
-
const { values = {}, secrets = {} } = await readJson(req, 256 * 1024);
|
|
313
|
-
const settings = { ...ots.settings };
|
|
314
|
-
const sec = { ...ots.secrets };
|
|
315
|
-
const changed = [];
|
|
316
|
-
for (const [k, v] of Object.entries(values || {})) {
|
|
317
|
-
const meta = OTS_KEYS[k];
|
|
318
|
-
if (!meta || meta.secret || meta.managed) continue;
|
|
319
|
-
const before = settings[k];
|
|
320
|
-
if (v === null || v === '') delete settings[k];
|
|
321
|
-
else settings[k] = String(v).slice(0, 20000);
|
|
322
|
-
if (before !== settings[k]) changed.push(k);
|
|
323
|
-
}
|
|
324
|
-
for (const [k, v] of Object.entries(secrets || {})) {
|
|
325
|
-
const meta = OTS_KEYS[k];
|
|
326
|
-
if (!meta?.secret || v === '') continue;
|
|
327
|
-
const before = sec[k];
|
|
328
|
-
if (v === null) delete sec[k];
|
|
329
|
-
else sec[k] = String(v).trim().slice(0, 4000);
|
|
330
|
-
if (before !== sec[k]) changed.push(k);
|
|
331
|
-
}
|
|
332
|
-
// A key typed in the backoffice is not the identity the dashboard made: forget what it knew about it.
|
|
333
|
-
if (changed.includes('APUCHAT_AGENT_IDENTITY_KEY')) for (const k of ['APUCHAT_AGENT_CALLSIGN', 'APUCHAT_AGENT_FREE', 'APUCHAT_AGENT_OWNER']) delete settings[k];
|
|
334
|
-
const next = await save(ots, { settings, secrets: sec });
|
|
335
|
-
return send(res, 200, { changed, channels: changed.some((k) => OTS_KEYS[k].channels), restart: [], server: serverViewOf(next), status: statusOf(next) });
|
|
336
|
-
}
|
|
337
|
-
if (route === '/test/llm' && req.method === 'POST') {
|
|
338
|
-
const t0 = Date.now();
|
|
339
|
-
try {
|
|
340
|
-
const out = await otsStep(ots, { system: t('server.admin.testSystem'), messages: [{ role: 'user', content: t('server.admin.testPrompt') }], tools: [], locale: requestLocale(req) });
|
|
341
|
-
const llm = otsLlmInfo(ots);
|
|
342
|
-
return send(res, 200, { ok: true, text: out.text, ms: Date.now() - t0, llm: `${llm.name}:${llm.model}` });
|
|
343
|
-
} catch (e) {
|
|
344
|
-
return send(res, 200, { ok: false, error: errorText(e, t).slice(0, 300), ms: Date.now() - t0 });
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (route === '/test/tts' && req.method === 'POST') {
|
|
348
|
-
const { text, voice } = await readJson(req, 16 * 1024);
|
|
349
|
-
const { audio, contentType } = await otsSynthesize(ots, { text: String(text || t('server.admin.ttsSample')).slice(0, 300), voice: voice || ots.identity.voice });
|
|
350
|
-
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': audio.length, 'Cache-Control': 'no-store' });
|
|
351
|
-
return res.end(audio);
|
|
352
|
-
}
|
|
353
|
-
if (route === '/status' && req.method === 'GET') return send(res, 200, statusOf(ots));
|
|
354
|
-
send(res, 404, { error: t('server.admin.unknownRoute') });
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
async function dashboardApi(req, res, path) {
|
|
358
|
-
const t = reqT(req);
|
|
359
|
-
const origin = req.headers.origin;
|
|
360
|
-
if (origin && !selfOrigins(req).has(origin)) return send(res, 403, { error: t('server.admin.sameOrigin') });
|
|
361
|
-
res.setHeader('X-Frame-Options', 'DENY');
|
|
362
|
-
if (req.method !== 'GET' && req.method !== 'HEAD' && req.headers['x-7ots-admin'] !== '1') return send(res, 403, { error: t('server.admin.missingHeader') });
|
|
363
|
-
const account = currentAccount(req);
|
|
364
|
-
if (!account) return send(res, 401, { error: t('platform.api.login') });
|
|
365
|
-
|
|
366
|
-
if (path === '/me' && req.method === 'GET') {
|
|
367
|
-
return send(res, 200, {
|
|
368
|
-
account: publicAccount(account),
|
|
369
|
-
limits: { maxOts: MAX_OTS_PER_ACCOUNT(), freeMessages: freeMessages(), freeTts: freeTts(), platformLlm: !!platformLlmEnv() },
|
|
370
|
-
usage: { month: monthOf(), llm_platform: accountUsage(account.id, 'llm_platform'), tts_platform: accountUsage(account.id, 'tts_platform') },
|
|
371
|
-
integrations: connect.integrations(account),
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
if ((await connect.account(req, res, account, path)) !== false) return;
|
|
375
|
-
if (await device.dashboard(req, res, account, path)) return;
|
|
376
|
-
if (await sites(req, res, account, path)) return;
|
|
377
|
-
if ((path === '/mods' || path.startsWith('/mods/')) && (await mods.accountApi(req, res, account, path.slice('/mods'.length)))) return;
|
|
378
|
-
|
|
379
|
-
if (path === '/ots' && req.method === 'GET') {
|
|
380
|
-
const usage = usageByOts(account.id);
|
|
381
|
-
return send(res, 200, { ots: listOts(account.id).map((o) => otsSummary(o, usage[o.id] || {})) });
|
|
382
|
-
}
|
|
383
|
-
if (path === '/ots' && req.method === 'POST') {
|
|
384
|
-
if (countOts(account.id) >= MAX_OTS_PER_ACCOUNT()) return send(res, 403, { error: t('platform.api.tooManyOts', { max: MAX_OTS_PER_ACCOUNT() }) });
|
|
385
|
-
const { name, language, seed, otName, apuchat, character, kind, material } = await readJson(req, 64 * 1024);
|
|
386
|
-
const lang = ['es', 'en', 'pt'].includes(language) ? language : requestLocale(req);
|
|
387
|
-
// From the 7ots.com hero: the same ot the visitor just rolled (seed + optional name).
|
|
388
|
-
const rolled = cleanSeed(seed) ? randomIdentity(cleanSeed(seed), { lang, name: String(otName || '').trim().slice(0, 40) || undefined }) : null;
|
|
389
|
-
const identity = rolled ? { ...STARTER[lang], ...rolled } : { language: lang, voice: { lang: { es: 'es-ES', en: 'en-US', pt: 'pt-BR' }[lang] }, ...STARTER[lang] };
|
|
390
|
-
// …and the face as they left it in the landing editor (defineIdentity normalizes it).
|
|
391
|
-
// Each ot is unique: a face chosen in the editor must be free (409 otherwise); without one, it gets a free face.
|
|
392
|
-
const chosen = character && typeof character === 'object' && !Array.isArray(character);
|
|
393
|
-
let ots = createOts(account.id, { name, identity: chosen ? { ...identity, look: { ...identity.look, kind: kind === 'plush' ? 'plush' : 'character', material, character } } : withFreeLook(identity, cleanSeed(seed) || null) });
|
|
394
|
-
// "Free apuchat identity" box: best effort, the ot is created anyway.
|
|
395
|
-
let apuchatError = null;
|
|
396
|
-
if (apuchat === true) {
|
|
397
|
-
try {
|
|
398
|
-
ots = await connect.freeIdentity(account, ots);
|
|
399
|
-
} catch (e) {
|
|
400
|
-
apuchatError = errorText(e, t);
|
|
401
|
-
if (!e.i18n) console.warn('[7ots] apuchat identity on create:', e.message);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return send(res, 201, { ots: otsSummary(ots), ...(apuchat === true ? { apuchat: ots.settings.APUCHAT_AGENT_CALLSIGN || null, apuchatError } : {}) });
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const m = path.match(/^\/ots\/([a-z0-9_]{4,40})(\/.*)?$/);
|
|
408
|
-
if (!m) return send(res, 404, { error: t('server.http.unknownRoute') });
|
|
409
|
-
const ots = getOwnOts(account.id, m[1]);
|
|
410
|
-
if (!ots) return send(res, 404, { error: t('platform.api.notFound') });
|
|
411
|
-
const sub = m[2] || '';
|
|
412
|
-
|
|
413
|
-
if (sub.startsWith('/admin/')) return adminApi(req, res, ots, sub.slice('/admin'.length));
|
|
414
|
-
if (await connect.ots(req, res, account, ots, sub)) return;
|
|
415
|
-
if (await vm.dashboard(req, res, account, ots, sub)) return;
|
|
416
|
-
if (await wallet(req, res, account, ots, sub)) return;
|
|
417
|
-
if (await byte(req, res, ots, sub)) return;
|
|
418
|
-
|
|
419
|
-
if (sub === '' && req.method === 'GET') return send(res, 200, { ots: otsSummary(ots, usageByOts(account.id)[ots.id] || {}) });
|
|
420
|
-
if (sub === '' && req.method === 'PATCH') {
|
|
421
|
-
const body = await readJson(req, 16 * 1024);
|
|
422
|
-
const patch = {};
|
|
423
|
-
if (typeof body.name === 'string') patch.name = body.name;
|
|
424
|
-
if (body.status === 'on' || body.status === 'off') patch.status = body.status;
|
|
425
|
-
if (body.domains !== undefined) {
|
|
426
|
-
const list = Array.isArray(body.domains) ? body.domains : String(body.domains).split(/[\s,]+/).filter(Boolean);
|
|
427
|
-
patch.domains = cleanDomains(list);
|
|
428
|
-
if (patch.domains.length < list.length) return send(res, 400, { error: t('platform.api.badDomains') });
|
|
429
|
-
}
|
|
430
|
-
return send(res, 200, { ots: otsSummary(await save(ots, patch)) });
|
|
431
|
-
}
|
|
432
|
-
if (sub === '' && req.method === 'DELETE') {
|
|
433
|
-
await stopOtsChannels(ots.id);
|
|
434
|
-
await connect.release(account, ots);
|
|
435
|
-
await vm.releaseOts(ots.id); // its 7ots server (Orquesta VM) goes too; ots_vms cascades with the ot
|
|
436
|
-
deleteOts(ots.id);
|
|
437
|
-
return send(res, 200, { ok: true });
|
|
438
|
-
}
|
|
439
|
-
if (sub === '/duplicate' && req.method === 'POST') {
|
|
440
|
-
if (countOts(account.id) >= MAX_OTS_PER_ACCOUNT()) return send(res, 403, { error: t('platform.api.tooManyOts', { max: MAX_OTS_PER_ACCOUNT() }) });
|
|
441
|
-
return send(res, 201, { ots: otsSummary(duplicateOts(account.id, ots)) });
|
|
442
|
-
}
|
|
443
|
-
if (sub === '/usage' && req.method === 'GET') return send(res, 200, { months: usageHistory(ots.id) });
|
|
444
|
-
if (sub === '/conversations' && req.method === 'GET') {
|
|
445
|
-
const url = new URL(req.url, 'http://x');
|
|
446
|
-
return send(res, 200, { conversations: listConversations(ots.id, { before: url.searchParams.get('before'), limit: url.searchParams.get('limit') }) });
|
|
447
|
-
}
|
|
448
|
-
const c = sub.match(/^\/conversations\/(c_[A-Za-z0-9_-]{10,40})$/);
|
|
449
|
-
if (c && req.method === 'GET') {
|
|
450
|
-
const conv = getConversation(ots.id, c[1]);
|
|
451
|
-
return conv ? send(res, 200, { conversation: conv }) : send(res, 404, { error: t('server.http.notFound') });
|
|
452
|
-
}
|
|
453
|
-
if (c && req.method === 'DELETE') return send(res, 200, { ok: deleteConversation(ots.id, c[1]) });
|
|
454
|
-
send(res, 404, { error: t('server.http.unknownRoute') });
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const connect = createConnect({ send, readJson, originOf, save });
|
|
458
|
-
const device = createDevice({ send, readJson, rateLimit, base: (req) => (penv.PLATFORM_URL || originOf(req)).replace(/\/+$/, ''), summary: (o) => otsSummary(o), save });
|
|
459
|
-
const sites = createSites({ send, readJson });
|
|
460
|
-
const mods = createMods({ send, readJson });
|
|
461
|
-
const wallet = createWallet({ send, readJson });
|
|
462
|
-
const byte = createByte({ send, readJson });
|
|
463
|
-
const vm = createVm({ send, readJson, rateLimit, base: (req) => (penv.PLATFORM_URL || originOf(req)).replace(/\/+$/, '') });
|
|
464
|
-
|
|
465
|
-
/** @returns {Promise<boolean>} true si atendió la ruta */
|
|
466
|
-
return async function handle(req, res, url) {
|
|
467
|
-
const p = url.pathname;
|
|
468
|
-
if (await connect.auth(req, res, url)) return true;
|
|
469
|
-
// models of mods (uploaded by a pet when it syncs): public, content-addressed, immutable
|
|
470
|
-
const mf = /^\/mods\/([a-f0-9]{16})\.(glb|vrm)$/.exec(p);
|
|
471
|
-
if (mf && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
472
|
-
const file = join(dataDir(), 'mods', `${mf[1]}.${mf[2]}`);
|
|
473
|
-
if (!existsSync(file)) return send(res, 404, { error: 'not found' }), true;
|
|
474
|
-
res.writeHead(200, { 'Content-Type': 'model/gltf-binary', 'Content-Length': statSync(file).size, 'Cache-Control': 'public, max-age=31536000, immutable', 'Access-Control-Allow-Origin': '*' });
|
|
475
|
-
if (req.method === 'HEAD') return res.end(), true;
|
|
476
|
-
createReadStream(file).pipe(res);
|
|
477
|
-
return true;
|
|
478
|
-
}
|
|
479
|
-
const m = p.match(/^\/api\/o\/([a-z0-9_]{4,40})(\/.*)$/);
|
|
480
|
-
if (m) {
|
|
481
|
-
await publicApi(req, res, m[1], m[2]);
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
// The landing asks before sending the visitor to sign in: each ot is unique, a repeated face can't be created.
|
|
485
|
-
if (p === '/api/look/free' && req.method === 'POST') {
|
|
486
|
-
const { character, characters } = await readJson(req, 256 * 1024);
|
|
487
|
-
const isObj = (c) => c && typeof c === 'object' && !Array.isArray(c);
|
|
488
|
-
const free = (c) => (isObj(c) ? !lookTaken({ look: { kind: 'character', character: c } }) : false);
|
|
489
|
-
// en lote (las sugerencias al azar del editor): { characters: [...] } → { free: [bool…] }
|
|
490
|
-
if (Array.isArray(characters)) send(res, 200, { free: characters.slice(0, 32).map(free) });
|
|
491
|
-
else send(res, 200, { free: free(character) });
|
|
492
|
-
return true;
|
|
493
|
-
}
|
|
494
|
-
const dv = p.match(/^\/api\/device\/ots\/([a-z0-9_]{4,40})\/vm(\/.*)?$/);
|
|
495
|
-
if (dv) {
|
|
496
|
-
const who = deviceFromBearer(req);
|
|
497
|
-
if (!who) send(res, 401, { error: 'login' });
|
|
498
|
-
else await vm.device(req, res, who, dv[1], dv[2] || '');
|
|
499
|
-
return true;
|
|
500
|
-
}
|
|
501
|
-
// community mods: public listing, and the same signed-in api for the pet (bearer) as for the dashboard
|
|
502
|
-
if (p === '/api/mods' || p.startsWith('/api/mods/')) {
|
|
503
|
-
if (!(await mods.publicApi(req, res, p.slice('/api/mods'.length)))) send(res, 404, { error: 'not found' });
|
|
504
|
-
return true;
|
|
505
|
-
}
|
|
506
|
-
if (p === '/api/device/mods' || p.startsWith('/api/device/mods/')) {
|
|
507
|
-
const who = deviceFromBearer(req);
|
|
508
|
-
if (!who) send(res, 401, { error: 'login' });
|
|
509
|
-
else if (!(await mods.accountApi(req, res, who.account, p.slice('/api/device/mods'.length)))) send(res, 404, { error: 'not found' });
|
|
510
|
-
return true;
|
|
511
|
-
}
|
|
512
|
-
if (p.startsWith('/api/vm/')) {
|
|
513
|
-
await vm.worker(req, res, p.slice('/api/vm'.length));
|
|
514
|
-
return true;
|
|
515
|
-
}
|
|
516
|
-
if (p.startsWith('/api/device/')) {
|
|
517
|
-
if (!(await device.api(req, res, p.slice('/api/device'.length)))) send(res, 404, { error: reqT(req)('server.http.unknownRoute') });
|
|
518
|
-
return true;
|
|
519
|
-
}
|
|
520
|
-
if (p.startsWith('/api/platform/')) {
|
|
521
|
-
await dashboardApi(req, res, p.slice('/api/platform'.length));
|
|
522
|
-
return true;
|
|
523
|
-
}
|
|
524
|
-
return false;
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/** Rol y tono de partida de un ots nuevo, en su idioma (los defectos del esquema son en español). */
|
|
529
|
-
const STARTER = {
|
|
530
|
-
es: { role: 'asistente virtual', personality: { tone: 'cercano y claro' } },
|
|
531
|
-
en: { role: 'virtual assistant', personality: { tone: 'friendly and clear' } },
|
|
532
|
-
pt: { role: 'assistente virtual', personality: { tone: 'próximo e claro' } },
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Lo que de verdad escribió el visitante en un mensaje del widget: sin el <page_context> ni el
|
|
537
|
-
* <user_state> que añade AgentBrain. Los eventos proactivos (<evento_del_sistema>) y los
|
|
538
|
-
* resultados de herramientas (contenido no textual) no son texto del visitante.
|
|
539
|
-
*/
|
|
540
|
-
function visibleTurn(content) {
|
|
541
|
-
if (typeof content !== 'string') return { text: '', page: '' };
|
|
542
|
-
const page = /<page_context>[\s\S]*?^URL: (\S+)/m.exec(content)?.[1] || '';
|
|
543
|
-
if (content.includes('<evento_del_sistema>')) return { text: '', page };
|
|
544
|
-
const text = content
|
|
545
|
-
.replace(/<page_context>[\s\S]*?<\/page_context>/g, '')
|
|
546
|
-
.replace(/<user_state>[\s\S]*?<\/user_state>/g, '')
|
|
547
|
-
.trim();
|
|
548
|
-
return { text, page: page.slice(0, 500) };
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
/** Igual que settings.mjs: solo datos y nada que tenga que fijar el servidor. */
|
|
552
|
-
function sanitizeWidget(w) {
|
|
553
|
-
const out = JSON.parse(JSON.stringify(w));
|
|
554
|
-
for (const k of ['endpoint', 'llm', 'auth', 'templates', 'actions', 'identity']) delete out[k];
|
|
555
|
-
return out;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* The ot's unique traits as NFT-style metadata (ERC-721 / Metaplex shape). The face fingerprint is
|
|
560
|
-
* what makes an ot unique (UNIQUE index); the permanent apuchat @handle is its unique name. When
|
|
561
|
-
* minting ships, the token will be these traits: whoever holds it holds the ot.
|
|
562
|
-
*/
|
|
563
|
-
function traitsMeta(ots, ep) {
|
|
564
|
-
const look = ots.identity?.look || {};
|
|
565
|
-
const ch = look.character || {};
|
|
566
|
-
const handle = ots.settings?.APUCHAT_AGENT_CALLSIGN && ots.settings.APUCHAT_AGENT_FREE !== '1' ? ots.settings.APUCHAT_AGENT_CALLSIGN : null;
|
|
567
|
-
const attr = (trait_type, value) => (value == null || value === '' ? null : { trait_type, value });
|
|
568
|
-
return {
|
|
569
|
-
name: ots.identity?.name || ots.name,
|
|
570
|
-
description: ots.identity?.tagline || ots.identity?.role || '',
|
|
571
|
-
external_url: `${ep}/identity`,
|
|
572
|
-
fingerprint: ots.lookPrint || null,
|
|
573
|
-
handle,
|
|
574
|
-
minted: false,
|
|
575
|
-
attributes: [
|
|
576
|
-
attr('Kind', look.kind),
|
|
577
|
-
attr('Material', look.kind === 'plush' ? look.material : null),
|
|
578
|
-
attr('Body', ch.body?.shape),
|
|
579
|
-
attr('Body color', ch.body?.color),
|
|
580
|
-
attr('Pattern', ch.body?.pattern && ch.body.pattern !== 'none' ? ch.body.pattern : null),
|
|
581
|
-
attr('Finish', ch.finish),
|
|
582
|
-
attr('Eyes', ch.eyes?.type),
|
|
583
|
-
attr('Brows', ch.brows?.type),
|
|
584
|
-
attr('Mouth', ch.mouth?.type),
|
|
585
|
-
attr('Cheeks', ch.cheeks?.type),
|
|
586
|
-
attr('Accessories', Array.isArray(ch.accessories) ? ch.accessories.map((a) => a?.id).filter(Boolean).join(', ') || 'none' : null),
|
|
587
|
-
].filter(Boolean),
|
|
588
|
-
};
|
|
589
|
-
}
|