odant-work 1.0.103 → 1.0.105
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/$server/$folder/$class/$ai/handlers/pages/form/system/ai/$handler/class.js +15 -12
- package/$server/$folder/$class/$module/$mcp/handlers/pages/form/system/mcp/$handler/class.js +17 -24
- package/$server/$folder/$class/$module/$provider/handlers/pages/form/system/ai/$handler/class.js +15 -12
- package/$server/$folder/$class/$structure/$project/class.js +39 -5
- package/$server/$folder/$class/$structure/$project/handlers/pages/form/system/modules/$handler/class.js +40 -25
- package/$server/$folder/$class/$structure/$project/handlers/pages/form/system/requisites/$handler/class.js +1 -0
- package/$server/$folder/$class/$structure/$server/handlers/pages/form/system/license/$handler/class.js +13 -12
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/agent/$handler/class.js +11 -1
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/messengers/$handler/class.js +11 -1
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/profile/$handler/class.js +1 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/requisites/$handler/class.js +3 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/settings/$handler/class.js +261 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/skills/$handler/class.js +11 -1
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/tokens/$handler/class.js +2 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/users/$handler/class.js +1 -0
- package/$server/$folder/$class/$structure/class.js +15 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +17 -4
- package/$server/$folder/$class/$structure/handlers/pages/form/system/agent/$handler/class.js +19 -40
- package/$server/$folder/$class/$structure/handlers/pages/form/system/database/$handler/class.js +1 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/system/messengers/$handler/class.js +1 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/system/skills/$handler/class.js +276 -179
- package/$server/$folder/$class/$structure/handlers/pages/form/system/staff/$handler/class.js +1 -0
- package/$server/$folder/$class/ai/system.md +2 -2
- package/$server/$folder/$class/class.js +5 -1
- package/$server/$folder/$class/handlers/pages/form/system/requisites/$handler/class.js +39 -45
- package/$server/$folder/$file/$html/handlers/preview/$handler/preview.js +7 -0
- package/$server/$folder/$file/$image/handlers/preview/$handler/preview.js +11 -0
- package/$server/$folder/$file/$md/handlers/preview/$handler/preview.js +29 -8
- package/$server/$folder/$file/$office/handlers/preview/$handler/preview.js +6 -0
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +34 -2
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/feed.js +14 -11
- package/$server/$folder/$file/$task/handlers/preview/$handler/preview.js +1 -0
- package/$server/$folder/$file/$txt/handlers/preview/$handler/preview.js +9 -0
- package/$server/$folder/$file/$video/handlers/preview/$handler/preview.js +15 -0
- package/$server/$folder/handlers/pages/form/$handler/class.js +187 -3
- package/$server/$folder/handlers/pages/form/folder/$handler/class.js +3 -114
- package/$server/$folder/lib/explorer/explorer.js +63 -0
- package/$server/$folder/lib/folder-browser/folder-browser.js +793 -0
- package/$server/$folder/lib/folder-browser/readme.md +5 -0
- package/$server/$folder/lib/tree/tree.js +61 -20
- package/AGENTS.md +2 -2
- package/MODULES/$domain/handlers/pages/form/system/mcp/$handler/class.js +10 -21
- package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/engine/$handler/class.js +1 -0
- package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/models/$handler/class.js +5 -10
- package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/training/$handler/class.js +1 -0
- package/MODULES//320/243/321/207/321/221/321/202 /320/270 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/321/213/Register/OPERATIONS//320/240/320/265/320/260/320/273/320/270/320/267/320/260/321/206/320/270/321/217//320/237/320/276/320/272/321/203/320/277/320/260/321/202/320/265/320/273/321/216/$operation/print//320/241/321/207/321/221/321/202 /320/275/320/260 /320/276/320/277/320/273/320/260/321/202/321/203.html" +5 -1
- package/MODULES//320/243/321/207/321/221/321/202 /320/270 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/321/213/Register/OPERATIONS//320/240/320/265/320/260/320/273/320/270/320/267/320/260/321/206/320/270/321/217//320/237/320/276/320/272/321/203/320/277/320/260/321/202/320/265/320/273/321/216/$operation/print//320/242/320/276/320/262/320/260/321/200/320/275/320/260/321/217 /320/275/320/260/320/272/320/273/320/260/320/264/320/275/320/260/321/217.html" +1 -1
- package/NODES/$node/handlers/pages/form/network/$handler/class.js +552 -36
- package/oda/components/icon/icon.js +20 -7
- package/oda/components/layouts/editor-form/editor-form.js +54 -9
- package/package.json +1 -1
- package/sources/client.js +24 -0
- package/sources/data/print.js +27 -3
- package/sources/host/websocket.js +28 -1
- package/sources/modules/agent/index.js +25 -6
- package/sources/modules/agent/permissions.js +4 -2
- package/sources/modules/agent/scope.js +72 -5
- package/sources/modules/agent/session.js +59 -6
- package/sources/modules/agent/tools/work/classes.js +16 -1
- package/sources/modules/license/index.js +120 -0
- package/sources/modules/nodes/registry.js +57 -7
- package/sources/modules/trainer/local-engine.js +22 -9
- package/sources/modules/user-profile/user-profile.js +0 -129
- package/sources/modules/user-profile/user-tokens.js +381 -86
- package/sources/server/access/gateway.js +32 -5
- package/sources/server/class/base-template.js +18 -18
- package/sources/server/class.js +9 -0
- package/sources/server/folder.js +5 -1
- package/sources/server/handler.js +6 -0
- package/sources/server/node.js +16 -0
- package/sources/server/server.js +14 -5
- package/sources/server/user.js +3 -0
|
@@ -17,6 +17,7 @@ import path from 'node:path';
|
|
|
17
17
|
import crypto from 'node:crypto';
|
|
18
18
|
import { serverKeys, fingerprint } from '../nodes/identity.js';
|
|
19
19
|
import { serverId } from '../../host/server-id.js';
|
|
20
|
+
import { PUBLIC_ORIGIN } from '../../host/config.js';
|
|
20
21
|
import {
|
|
21
22
|
ensurePackageManifest,
|
|
22
23
|
loadAutoUpdateState,
|
|
@@ -975,6 +976,120 @@ export function calculateLicenseQuote({
|
|
|
975
976
|
};
|
|
976
977
|
}
|
|
977
978
|
|
|
979
|
+
function resolvePublishOrigin(explicit = '') {
|
|
980
|
+
const raw = String(explicit || PUBLIC_ORIGIN || '').trim();
|
|
981
|
+
if (!raw)
|
|
982
|
+
return '';
|
|
983
|
+
try {
|
|
984
|
+
const u = new URL(raw);
|
|
985
|
+
if (u.protocol !== 'https:' && u.protocol !== 'http:')
|
|
986
|
+
return '';
|
|
987
|
+
const h = u.hostname.toLowerCase();
|
|
988
|
+
if (!h || h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '0.0.0.0' || h.endsWith('.local') || h.startsWith('127.'))
|
|
989
|
+
return '';
|
|
990
|
+
return u.origin;
|
|
991
|
+
}
|
|
992
|
+
catch {
|
|
993
|
+
return '';
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function resolveSelfServerName() {
|
|
998
|
+
const lbl = String(globalThis.WORK?.label || globalThis.WORK?.DATA?.label || '').trim();
|
|
999
|
+
return lbl && lbl !== 'WORK' ? lbl : 'Сервер WORK';
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Поиск серверов WORK в каталоге центра поддержки и лицензирования (work.odant.org).
|
|
1004
|
+
*/
|
|
1005
|
+
export async function discoverNetworkServers({
|
|
1006
|
+
query = '',
|
|
1007
|
+
hubUrl = '',
|
|
1008
|
+
systemDir = SYSTEM_DIR,
|
|
1009
|
+
licensePath = LICENSE_FILE,
|
|
1010
|
+
trustedPublicKey = '',
|
|
1011
|
+
fetchImpl = globalThis.fetch,
|
|
1012
|
+
} = {}) {
|
|
1013
|
+
const sysDir = systemDir || (licensePath ? path.dirname(licensePath) : SYSTEM_DIR);
|
|
1014
|
+
const tokenBinding = loadOwnerTokenBinding(sysDir);
|
|
1015
|
+
const lic = loadLocalLicense(licensePath || path.join(sysDir, 'license.json'), { systemDir: sysDir, trustedPublicKey });
|
|
1016
|
+
const hw = getHardwareIdentity();
|
|
1017
|
+
const baseUrl = String(hubUrl || tokenBinding?.hubUrl || lic.hubUrl || DEFAULT_LICENSE_HUB_URL).replace(/\/+$/, '');
|
|
1018
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
1019
|
+
if (tokenBinding?.token)
|
|
1020
|
+
headers.Authorization = `Bearer ${tokenBinding.token}`;
|
|
1021
|
+
|
|
1022
|
+
const res = await fetchImpl(`${baseUrl}/api/network/servers`, {
|
|
1023
|
+
method: 'POST',
|
|
1024
|
+
headers,
|
|
1025
|
+
body: JSON.stringify({
|
|
1026
|
+
query: String(query || '').trim(),
|
|
1027
|
+
token: tokenBinding?.token || '',
|
|
1028
|
+
licenseId: lic.unlicensed ? '' : lic.licenseId,
|
|
1029
|
+
nodeFingerprint: hw.nodeFingerprint,
|
|
1030
|
+
hwid: hw.hwid,
|
|
1031
|
+
}),
|
|
1032
|
+
});
|
|
1033
|
+
if (!res.ok) {
|
|
1034
|
+
const text = await res.text().catch(() => '');
|
|
1035
|
+
throw new Error(`Сервер поддержки (${baseUrl}) ответил HTTP ${res.status}: ${text.slice(0, 200)}`);
|
|
1036
|
+
}
|
|
1037
|
+
const data = await res.json();
|
|
1038
|
+
return {
|
|
1039
|
+
hubUrl: baseUrl,
|
|
1040
|
+
publicOrigin: resolvePublishOrigin(),
|
|
1041
|
+
servers: Array.isArray(data?.servers) ? data.servers : [],
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Обновить статус публикации сервера WORK в каталоге work.odant.org.
|
|
1047
|
+
*/
|
|
1048
|
+
export async function publishNetworkServer({
|
|
1049
|
+
discoverable = true,
|
|
1050
|
+
publicOrigin = '',
|
|
1051
|
+
serverName = '',
|
|
1052
|
+
hubUrl = '',
|
|
1053
|
+
systemDir = SYSTEM_DIR,
|
|
1054
|
+
licensePath = LICENSE_FILE,
|
|
1055
|
+
trustedPublicKey = '',
|
|
1056
|
+
fetchImpl = globalThis.fetch,
|
|
1057
|
+
} = {}) {
|
|
1058
|
+
const sysDir = systemDir || (licensePath ? path.dirname(licensePath) : SYSTEM_DIR);
|
|
1059
|
+
const tokenBinding = loadOwnerTokenBinding(sysDir);
|
|
1060
|
+
const lic = loadLocalLicense(licensePath || path.join(sysDir, 'license.json'), { systemDir: sysDir, trustedPublicKey });
|
|
1061
|
+
const hw = getHardwareIdentity();
|
|
1062
|
+
const baseUrl = String(hubUrl || tokenBinding?.hubUrl || lic.hubUrl || DEFAULT_LICENSE_HUB_URL).replace(/\/+$/, '');
|
|
1063
|
+
const effectiveOrigin = resolvePublishOrigin(publicOrigin);
|
|
1064
|
+
if (discoverable && !effectiveOrigin) {
|
|
1065
|
+
throw new Error('Укажите публичный адрес сервера (PUBLIC_ORIGIN, не localhost) для публикации в каталоге');
|
|
1066
|
+
}
|
|
1067
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
1068
|
+
if (tokenBinding?.token)
|
|
1069
|
+
headers.Authorization = `Bearer ${tokenBinding.token}`;
|
|
1070
|
+
|
|
1071
|
+
const res = await fetchImpl(`${baseUrl}/api/network/publish`, {
|
|
1072
|
+
method: 'POST',
|
|
1073
|
+
headers,
|
|
1074
|
+
body: JSON.stringify({
|
|
1075
|
+
token: tokenBinding?.token || '',
|
|
1076
|
+
licenseId: lic.unlicensed ? '' : lic.licenseId,
|
|
1077
|
+
hwid: hw.hwid,
|
|
1078
|
+
nodeFingerprint: hw.nodeFingerprint,
|
|
1079
|
+
nodePublicKey: hw.nodePublicKey,
|
|
1080
|
+
serverId: hw.serverId,
|
|
1081
|
+
publicOrigin: effectiveOrigin,
|
|
1082
|
+
serverName: String(serverName || resolveSelfServerName()),
|
|
1083
|
+
discoverable: Boolean(discoverable),
|
|
1084
|
+
}),
|
|
1085
|
+
});
|
|
1086
|
+
if (!res.ok) {
|
|
1087
|
+
const text = await res.text().catch(() => '');
|
|
1088
|
+
throw new Error(`Сервер поддержки (${baseUrl}) отклонил публикацию (HTTP ${res.status}): ${text.slice(0, 200)}`);
|
|
1089
|
+
}
|
|
1090
|
+
return res.json();
|
|
1091
|
+
}
|
|
1092
|
+
|
|
978
1093
|
/**
|
|
979
1094
|
* Привязать токен владельца (owk1...) к локальному WORK и сразу скачать файлы лицензий из личного кабинета в #system.
|
|
980
1095
|
*/
|
|
@@ -1001,6 +1116,8 @@ export async function bindOwnerTokenAndSync({
|
|
|
1001
1116
|
nodeFingerprint: hw.nodeFingerprint,
|
|
1002
1117
|
nodePublicKey: hw.nodePublicKey,
|
|
1003
1118
|
serverId: hw.serverId,
|
|
1119
|
+
publicOrigin: resolvePublishOrigin(),
|
|
1120
|
+
serverName: resolveSelfServerName(),
|
|
1004
1121
|
}),
|
|
1005
1122
|
});
|
|
1006
1123
|
|
|
@@ -1091,6 +1208,9 @@ export async function syncWithLicenseHub({ hubUrl, licensePath, systemDir, token
|
|
|
1091
1208
|
hwid: hw.hwid,
|
|
1092
1209
|
nodeFingerprint: hw.nodeFingerprint,
|
|
1093
1210
|
nodePublicKey: hw.nodePublicKey,
|
|
1211
|
+
serverId: hw.serverId,
|
|
1212
|
+
publicOrigin: resolvePublishOrigin(),
|
|
1213
|
+
serverName: resolveSelfServerName(),
|
|
1094
1214
|
customer: lic.customer,
|
|
1095
1215
|
}),
|
|
1096
1216
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* ROLES — роли удалённого сервера: в локальном классе узла на них назначаются наши
|
|
6
6
|
* представители (`#security.CUSTOMERS: [uid]` — представитель по закупкам у этого узла).
|
|
7
7
|
*/
|
|
8
|
-
import { fingerprint, PROTOCOL, wellKnown } from './identity.js';
|
|
8
|
+
import { fingerprint, PROTOCOL, wellKnown, serverKeys } from './identity.js';
|
|
9
9
|
import { serverId } from '../../host/server-id.js';
|
|
10
10
|
import { guardedRequest } from '../../host/net-guard.js';
|
|
11
11
|
|
|
@@ -136,24 +136,32 @@ function rolesFrom(card) {
|
|
|
136
136
|
* @param {object} params {origin, fingerprint (подтверждение), label?, announce?}
|
|
137
137
|
*/
|
|
138
138
|
export async function addNode(root, params = {}) {
|
|
139
|
-
const
|
|
139
|
+
const opts = (params.post && typeof params.post === 'object' && !Buffer.isBuffer(params.post))
|
|
140
|
+
? { ...params.post, ...params }
|
|
141
|
+
: params;
|
|
142
|
+
const card = await fetchCard(opts.origin, { trusted: true }); // адрес от администратора (LAN легальна)
|
|
140
143
|
if (card.id.toUpperCase() === serverId)
|
|
141
144
|
throw new Error('Это наш собственный сервер');
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
const wantFp = String(opts.fingerprint || '').trim().toUpperCase();
|
|
146
|
+
if (!wantFp || wantFp !== card.fingerprint)
|
|
147
|
+
return {
|
|
148
|
+
confirm: true,
|
|
149
|
+
fingerprintMismatch: Boolean(wantFp && wantFp !== card.fingerprint),
|
|
150
|
+
card: { id: card.id, label: card.label, origin: card.origin, fingerprint: card.fingerprint, roles: card.roles },
|
|
151
|
+
};
|
|
144
152
|
const existing = await findNode(card.id);
|
|
145
153
|
if (existing)
|
|
146
154
|
throw new Error('Узел уже в реестре: ' + existing.item.path);
|
|
147
155
|
const { safeNodeName } = await import('../../server/safe-node-name.js');
|
|
148
|
-
const id = safeNodeName(
|
|
156
|
+
const id = safeNodeName(opts.label || new URL(card.origin).host) || card.id;
|
|
149
157
|
const data = {
|
|
150
|
-
label:
|
|
158
|
+
label: opts.label || card.label || id,
|
|
151
159
|
host_id: card.id.toUpperCase(),
|
|
152
160
|
origin: card.origin,
|
|
153
161
|
publicKey: card.publicKey,
|
|
154
162
|
fingerprint: card.fingerprint,
|
|
155
163
|
status: 'active',
|
|
156
|
-
announce: !!
|
|
164
|
+
announce: !!opts.announce,
|
|
157
165
|
added: Date.now(),
|
|
158
166
|
remote: { label: card.label, roles: card.roles || [], peers: card.peers || [], at: Date.now() },
|
|
159
167
|
ROLES: rolesFrom(card),
|
|
@@ -165,6 +173,48 @@ export async function addNode(root, params = {}) {
|
|
|
165
173
|
return { added: (root.path || '') + '/' + id, fingerprint: card.fingerprint };
|
|
166
174
|
}
|
|
167
175
|
|
|
176
|
+
export async function discoverHubNodes(params = {}) {
|
|
177
|
+
const { discoverNetworkServers } = await import('../license/index.js');
|
|
178
|
+
const query = String(params.query || params.q || params.post?.query || '').trim();
|
|
179
|
+
const res = await discoverNetworkServers({ query });
|
|
180
|
+
const known = await listNodes();
|
|
181
|
+
const byId = new Map(known.map(n => [String(n.host_id || '').toUpperCase(), n]));
|
|
182
|
+
const byFp = new Map(known.map(n => [String(n.fingerprint || '').toUpperCase(), n]));
|
|
183
|
+
const selfFp = fingerprint(serverKeys().publicKey);
|
|
184
|
+
const selfRow = (res.servers || []).find(s =>
|
|
185
|
+
(s.serverId && s.serverId.toUpperCase() === serverId)
|
|
186
|
+
|| (s.fingerprint && s.fingerprint.toUpperCase() === selfFp)
|
|
187
|
+
) || null;
|
|
188
|
+
const items = (res.servers || [])
|
|
189
|
+
.filter(s => !(s.serverId && s.serverId.toUpperCase() === serverId) && !(s.fingerprint && s.fingerprint.toUpperCase() === selfFp))
|
|
190
|
+
.map(s => {
|
|
191
|
+
const matched = (s.serverId && byId.get(s.serverId.toUpperCase())) || (s.fingerprint && byFp.get(s.fingerprint.toUpperCase())) || null;
|
|
192
|
+
return {
|
|
193
|
+
...s,
|
|
194
|
+
connected: Boolean(matched),
|
|
195
|
+
nodePath: matched?.item?.path || '',
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
return {
|
|
199
|
+
hubUrl: res.hubUrl,
|
|
200
|
+
publicOrigin: res.publicOrigin || '',
|
|
201
|
+
selfServerId: serverId,
|
|
202
|
+
selfFingerprint: selfFp,
|
|
203
|
+
selfPublished: Boolean(selfRow?.discoverable),
|
|
204
|
+
items,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function publishHubNode(params = {}) {
|
|
209
|
+
const body = (params.post && typeof params.post === 'object' && !Buffer.isBuffer(params.post)) ? params.post : params;
|
|
210
|
+
const { publishNetworkServer } = await import('../license/index.js');
|
|
211
|
+
return publishNetworkServer({
|
|
212
|
+
discoverable: body.discoverable !== false && body.discoverable !== 'false',
|
|
213
|
+
publicOrigin: body.publicOrigin || '',
|
|
214
|
+
serverName: body.serverName || '',
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
168
218
|
/**
|
|
169
219
|
* Обновить карточку узла. Смена ключа не принимается молча: узел блокируется (key_changed)
|
|
170
220
|
* до решения администратора.
|
|
@@ -152,6 +152,13 @@ function runtimeVenvPython(rootDir = process.cwd()) {
|
|
|
152
152
|
: path.join(rt, 'venv', 'bin', 'python');
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
function isValidRuntimeVenv(rootDir = process.cwd()) {
|
|
156
|
+
const rt = runtimeRoot(rootDir);
|
|
157
|
+
const venvDir = path.join(rt, 'venv');
|
|
158
|
+
const venvPy = runtimeVenvPython(rootDir);
|
|
159
|
+
return fs.existsSync(venvPy) && fs.existsSync(path.join(venvDir, 'pyvenv.cfg'));
|
|
160
|
+
}
|
|
161
|
+
|
|
155
162
|
function venvPythonCandidates(rootDir = process.cwd()) {
|
|
156
163
|
const rel = os.platform() === 'win32'
|
|
157
164
|
? ['.venv/Scripts/python.exe', 'venv/Scripts/python.exe', 'MODULES/Модели/Local/.venv/Scripts/python.exe', 'MODELS/Local/.venv/Scripts/python.exe']
|
|
@@ -1311,13 +1318,17 @@ async function ensureUvBinary(rootDir = process.cwd()) {
|
|
|
1311
1318
|
export async function ensureLocalPythonRuntime(rootDir = process.cwd()) {
|
|
1312
1319
|
const existing = await resolvePythonCommandAsync(rootDir);
|
|
1313
1320
|
const venvPy = runtimeVenvPython(rootDir);
|
|
1314
|
-
if (existing &&
|
|
1321
|
+
if (existing && isValidRuntimeVenv(rootDir) && await probePython(venvPy, []))
|
|
1315
1322
|
return { ok: true, python: venvPy, uv: fs.existsSync(path.join(runtimeRoot(rootDir), 'uv', 'uv.exe')) ? path.join(runtimeRoot(rootDir), 'uv', 'uv.exe') : '' };
|
|
1316
1323
|
|
|
1317
1324
|
const rt = runtimeRoot(rootDir);
|
|
1318
1325
|
const pyDir = path.join(rt, 'python');
|
|
1319
1326
|
const venvDir = path.join(rt, 'venv');
|
|
1320
1327
|
fs.mkdirSync(rt, { recursive: true });
|
|
1328
|
+
if (fs.existsSync(venvDir) && !isValidRuntimeVenv(rootDir)) {
|
|
1329
|
+
try { fs.rmSync(venvDir, { recursive: true, force: true }); }
|
|
1330
|
+
catch { /* ignore */ }
|
|
1331
|
+
}
|
|
1321
1332
|
const { env: proxyEnv } = buildProxyEnv(rootDir);
|
|
1322
1333
|
|
|
1323
1334
|
let uv = '';
|
|
@@ -1351,24 +1362,26 @@ export async function ensureLocalPythonRuntime(rootDir = process.cwd()) {
|
|
|
1351
1362
|
let venvOk = false;
|
|
1352
1363
|
if (managedOk) {
|
|
1353
1364
|
const env = { ...proxyEnv, UV_PYTHON_INSTALL_DIR: pyDir };
|
|
1354
|
-
const venvRes = await runSpawnCapture(uv, ['venv', venvDir, '--python', '3.11', '--python-preference', 'only-managed', '--seed', '--
|
|
1355
|
-
venvOk = venvRes.ok
|
|
1365
|
+
const venvRes = await runSpawnCapture(uv, ['venv', venvDir, '--python', '3.11', '--python-preference', 'only-managed', '--seed', '--clear'], 180000, env);
|
|
1366
|
+
venvOk = venvRes.ok && isValidRuntimeVenv(rootDir);
|
|
1356
1367
|
if (!venvOk && !existing)
|
|
1357
1368
|
throw new Error('uv venv: ' + (venvRes.err || venvRes.out || `код ${venvRes.code}`));
|
|
1358
1369
|
}
|
|
1359
1370
|
if (!venvOk && existing) {
|
|
1360
1371
|
const realExe = (await execText(existing.cmd, [...existing.args, '-c', 'import sys; print(sys.executable)'], 5000)).trim() || existing.cmd;
|
|
1361
|
-
const venvRes = await runSpawnCapture(uv, ['venv', venvDir, '--python', realExe, '--seed', '--
|
|
1362
|
-
if (!venvRes.ok
|
|
1372
|
+
const venvRes = await runSpawnCapture(uv, ['venv', venvDir, '--python', realExe, '--seed', '--clear'], 180000, proxyEnv);
|
|
1373
|
+
if ((!venvRes.ok || !isValidRuntimeVenv(rootDir)))
|
|
1363
1374
|
throw new Error('uv venv: ' + (venvRes.err || venvRes.out || `код ${venvRes.code}`));
|
|
1364
1375
|
}
|
|
1376
|
+
if (!isValidRuntimeVenv(rootDir))
|
|
1377
|
+
throw makePythonMissingError('Не удалось создать изолированное окружение Python (#runtime/venv)');
|
|
1365
1378
|
resetPythonCache();
|
|
1366
1379
|
return { ok: true, python: venvPy, uv };
|
|
1367
1380
|
}
|
|
1368
1381
|
|
|
1369
1382
|
if (existing) {
|
|
1370
1383
|
const mk = await runSpawnCapture(existing.cmd, [...existing.args, '-m', 'venv', venvDir], 120000, proxyEnv);
|
|
1371
|
-
if (mk.ok &&
|
|
1384
|
+
if (mk.ok && isValidRuntimeVenv(rootDir)) {
|
|
1372
1385
|
resetPythonCache();
|
|
1373
1386
|
return { ok: true, python: venvPy, uv: '' };
|
|
1374
1387
|
}
|
|
@@ -1475,7 +1488,7 @@ export async function installLocalPythonDeps(packages = [], { rootDir = process.
|
|
|
1475
1488
|
// Всегда разворачиваем изолированный #runtime/venv, чтобы не зависеть от системного Python и прав администратора
|
|
1476
1489
|
let uv = '';
|
|
1477
1490
|
const venvPy = runtimeVenvPython(rootDir);
|
|
1478
|
-
if (!
|
|
1491
|
+
if (!isValidRuntimeVenv(rootDir) || !(await probePython(venvPy, []))) {
|
|
1479
1492
|
try {
|
|
1480
1493
|
_pythonProvisionState = {
|
|
1481
1494
|
active: true,
|
|
@@ -1581,9 +1594,9 @@ export async function installLocalPythonDeps(packages = [], { rootDir = process.
|
|
|
1581
1594
|
};
|
|
1582
1595
|
|
|
1583
1596
|
try {
|
|
1584
|
-
if (uv &&
|
|
1597
|
+
if (uv && isValidRuntimeVenv(rootDir)) {
|
|
1585
1598
|
const ovrArgs = fs.existsSync(ovrFile) ? ['--override', ovrFile] : [];
|
|
1586
|
-
return await runSpawnCapture(uv, ['pip', 'install', '--python', venvPy, '--upgrade',
|
|
1599
|
+
return await runSpawnCapture(uv, ['pip', 'install', '--python', venvPy, '--upgrade', ...ovrArgs, ...indexArgs, ...installList], 900000, proxyEnv, onLine);
|
|
1587
1600
|
}
|
|
1588
1601
|
const pipIndexArgs = useRocm ? ['--extra-index-url', AMD_ROCM_GFX1151_WHL_INDEX] : indexArgs;
|
|
1589
1602
|
return await runSpawnCapture(py.cmd, [...py.args, '-m', 'pip', 'install', '--upgrade', '--progress-bar', 'off', ...pipIndexArgs, ...installList], 900000, proxyEnv, onLine);
|
|
@@ -49,49 +49,6 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
49
49
|
border-radius: 8px;
|
|
50
50
|
padding: 6px 8px;
|
|
51
51
|
}
|
|
52
|
-
.settings-card {
|
|
53
|
-
gap: 10px;
|
|
54
|
-
border: 1px solid var(--border-color, #cbd5e1);
|
|
55
|
-
border-radius: 10px;
|
|
56
|
-
padding: 12px 14px;
|
|
57
|
-
background: var(--content-background, #fff);
|
|
58
|
-
box-sizing: border-box;
|
|
59
|
-
}
|
|
60
|
-
.settings-title {
|
|
61
|
-
font-weight: 600;
|
|
62
|
-
font-size: 15px;
|
|
63
|
-
}
|
|
64
|
-
.settings-field {
|
|
65
|
-
gap: 4px;
|
|
66
|
-
font-size: 14px;
|
|
67
|
-
}
|
|
68
|
-
.settings-field select {
|
|
69
|
-
border: 1px solid gray;
|
|
70
|
-
padding: 8px;
|
|
71
|
-
border-radius: 8px;
|
|
72
|
-
font-size: 14px;
|
|
73
|
-
width: 100%;
|
|
74
|
-
box-sizing: border-box;
|
|
75
|
-
background: inherit;
|
|
76
|
-
color: inherit;
|
|
77
|
-
}
|
|
78
|
-
.settings-toggle {
|
|
79
|
-
gap: 8px;
|
|
80
|
-
align-items: center;
|
|
81
|
-
font-size: 14px;
|
|
82
|
-
cursor: pointer;
|
|
83
|
-
}
|
|
84
|
-
.settings-toggle input {
|
|
85
|
-
width: 18px;
|
|
86
|
-
height: 18px;
|
|
87
|
-
margin: 0;
|
|
88
|
-
flex-shrink: 0;
|
|
89
|
-
cursor: pointer;
|
|
90
|
-
}
|
|
91
|
-
.settings-hint {
|
|
92
|
-
font-size: 12px;
|
|
93
|
-
color: #10b981;
|
|
94
|
-
}
|
|
95
52
|
</style>
|
|
96
53
|
<div no-flex vertical class="profile-wrap">
|
|
97
54
|
<div ~if="pendingInvite?.valid" style="padding:10px 12px;border-radius:8px;border:1px solid #10b981;background:rgba(16,185,129,0.1);font-size:small;line-height:1.4;text-align:center;">
|
|
@@ -113,21 +70,6 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
113
70
|
</div>
|
|
114
71
|
<div flex style="text-align: center;" ~html="state.legend"></div>
|
|
115
72
|
<div flex style="text-align: center;" :error="!!error" @tap="fill_code">{{text}}</div>
|
|
116
|
-
<div class="settings-card" vertical ~if="!isOtherUser && isLogin">
|
|
117
|
-
<div class="settings-title">Личные настройки</div>
|
|
118
|
-
<label class="settings-field" vertical>
|
|
119
|
-
<span>Главная модель ИИ</span>
|
|
120
|
-
<select :value="settingModel" @change="_onSettingModelChange($event)">
|
|
121
|
-
<option value="">По умолчанию системы</option>
|
|
122
|
-
<option ~for="m in chatModels" :value="m.path" :selected="m.path === settingModel">{{m.label}}</option>
|
|
123
|
-
</select>
|
|
124
|
-
</label>
|
|
125
|
-
<label class="settings-toggle" horizontal>
|
|
126
|
-
<input type="checkbox" :checked="settingChatSound" @change="_onSettingChatSoundChange($event)">
|
|
127
|
-
<span>Звуковой щелчок по завершении ответа в открытом чате</span>
|
|
128
|
-
</label>
|
|
129
|
-
<div class="settings-hint" ~if="settingsStatus">{{settingsStatus}}</div>
|
|
130
|
-
</div>
|
|
131
73
|
</div>
|
|
132
74
|
`,
|
|
133
75
|
$item: {
|
|
@@ -139,10 +81,6 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
139
81
|
error: null,
|
|
140
82
|
text: '',
|
|
141
83
|
isLoggingIn: false,
|
|
142
|
-
chatModels: [],
|
|
143
|
-
settingModel: '',
|
|
144
|
-
settingChatSound: true,
|
|
145
|
-
settingsStatus: '',
|
|
146
84
|
get isOtherUser() {
|
|
147
85
|
return Boolean(this.$item?.id && WORK?.uid && this.$item.id !== WORK.uid);
|
|
148
86
|
},
|
|
@@ -268,7 +206,6 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
268
206
|
attached() {
|
|
269
207
|
this._syncFromItem(this.$item);
|
|
270
208
|
this._loadPendingInvite();
|
|
271
|
-
this._loadSettingsAndModels();
|
|
272
209
|
this._onAuthState = () => {
|
|
273
210
|
if (this.isOtherUser)
|
|
274
211
|
return;
|
|
@@ -280,84 +217,18 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
280
217
|
else if (this.isLogin) {
|
|
281
218
|
this.error = null;
|
|
282
219
|
this.text = '';
|
|
283
|
-
this._loadSettingsAndModels();
|
|
284
220
|
}
|
|
285
221
|
this.isLogin = undefined;
|
|
286
222
|
this.render?.();
|
|
287
223
|
};
|
|
288
|
-
this._onUserSettings = () => {
|
|
289
|
-
if (this.isOtherUser)
|
|
290
|
-
return;
|
|
291
|
-
this._applyLocalUserSettings();
|
|
292
|
-
};
|
|
293
224
|
WORK.authEvents?.addEventListener?.('auth', this._onAuthState);
|
|
294
225
|
WORK.authEvents?.addEventListener?.('login-state', this._onAuthState);
|
|
295
|
-
WORK.authEvents?.addEventListener?.('user-settings', this._onUserSettings);
|
|
296
226
|
},
|
|
297
227
|
detached() {
|
|
298
228
|
if (this._onAuthState) {
|
|
299
229
|
WORK.authEvents?.removeEventListener?.('auth', this._onAuthState);
|
|
300
230
|
WORK.authEvents?.removeEventListener?.('login-state', this._onAuthState);
|
|
301
231
|
}
|
|
302
|
-
if (this._onUserSettings) {
|
|
303
|
-
WORK.authEvents?.removeEventListener?.('user-settings', this._onUserSettings);
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
_applyLocalUserSettings() {
|
|
307
|
-
const s = WORK.userSettings || this.$item?.DATA?.settings || {};
|
|
308
|
-
this.settingModel = typeof s.aiModel === 'string' ? s.aiModel : '';
|
|
309
|
-
this.settingChatSound = s.chatSound !== false;
|
|
310
|
-
},
|
|
311
|
-
async _loadSettingsAndModels() {
|
|
312
|
-
if (this.isOtherUser || !this.isLogin)
|
|
313
|
-
return;
|
|
314
|
-
this._applyLocalUserSettings();
|
|
315
|
-
try {
|
|
316
|
-
if (typeof WORK.loadUserSettings === 'function') {
|
|
317
|
-
await WORK.loadUserSettings();
|
|
318
|
-
this._applyLocalUserSettings();
|
|
319
|
-
}
|
|
320
|
-
if (typeof WORK.fetch === 'function') {
|
|
321
|
-
const list = await WORK.fetch('/', 'agent_chat_models').catch(() => []);
|
|
322
|
-
if (Array.isArray(list))
|
|
323
|
-
this.chatModels = list;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
catch { /* ignore */ }
|
|
327
|
-
},
|
|
328
|
-
async _saveProfileSetting(patch) {
|
|
329
|
-
this.settingsStatus = '';
|
|
330
|
-
try {
|
|
331
|
-
if (typeof WORK.saveUserSettings === 'function')
|
|
332
|
-
await WORK.saveUserSettings(patch);
|
|
333
|
-
if (patch && 'aiModel' in patch && patch.aiModel && typeof BroadcastChannel !== 'undefined') {
|
|
334
|
-
try { new BroadcastChannel('work-user-ai-model').postMessage({ model: patch.aiModel }); } catch {}
|
|
335
|
-
}
|
|
336
|
-
this._applyLocalUserSettings();
|
|
337
|
-
this.settingsStatus = 'Сохранено';
|
|
338
|
-
clearTimeout(this._settingsTimer);
|
|
339
|
-
this._settingsTimer = setTimeout(() => { this.settingsStatus = ''; }, 2000);
|
|
340
|
-
}
|
|
341
|
-
catch (err) {
|
|
342
|
-
this.settingsStatus = err?.message || 'Ошибка сохранения';
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
_onSettingModelChange(e) {
|
|
346
|
-
const val = String(e?.target?.value || '');
|
|
347
|
-
this.settingModel = val;
|
|
348
|
-
if (!val && typeof localStorage !== 'undefined') {
|
|
349
|
-
try {
|
|
350
|
-
const uid = WORK.uid || this.$item?.id || 'default';
|
|
351
|
-
localStorage.removeItem(`work.user.ai:${uid}:model`);
|
|
352
|
-
localStorage.removeItem('work.user.ai:default:model');
|
|
353
|
-
} catch {}
|
|
354
|
-
}
|
|
355
|
-
this._saveProfileSetting({ aiModel: val });
|
|
356
|
-
},
|
|
357
|
-
_onSettingChatSoundChange(e) {
|
|
358
|
-
const checked = Boolean(e?.target?.checked);
|
|
359
|
-
this.settingChatSound = checked;
|
|
360
|
-
this._saveProfileSetting({ chatSound: checked });
|
|
361
232
|
},
|
|
362
233
|
async _syncFromItem(item) {
|
|
363
234
|
if (item?.id && WORK?.uid && item.id !== WORK.uid) {
|